|
31 | 31 | #include "qgslogger.h"
|
32 | 32 | #include "qgsapplication.h"
|
33 | 33 | #include "qgssettings.h"
|
| 34 | +#include "qgsfeatureiterator.h" |
| 35 | +#include "qgsvectorlayer.h" |
34 | 36 |
|
35 | 37 | #include <QColorDialog>
|
36 | 38 | #include <QPainter>
|
@@ -247,6 +249,19 @@ QgsSymbolSelectorWidget::QgsSymbolSelectorWidget( QgsSymbol *symbol, QgsStyle *s
|
247 | 249 | layersTree->setModel( model );
|
248 | 250 | layersTree->setHeaderHidden( true );
|
249 | 251 |
|
| 252 | + //get first feature from layer for previews |
| 253 | + if ( mVectorLayer ) |
| 254 | + { |
| 255 | + QgsFeatureIterator it = mVectorLayer->getFeatures( QgsFeatureRequest().setLimit( 1 ) ); |
| 256 | + it.nextFeature( mPreviewFeature ); |
| 257 | + mPreviewExpressionContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mVectorLayer ) ); |
| 258 | + mPreviewExpressionContext.setFeature( mPreviewFeature ); |
| 259 | + } |
| 260 | + else |
| 261 | + { |
| 262 | + mPreviewExpressionContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( nullptr ) ); |
| 263 | + } |
| 264 | + |
250 | 265 | QItemSelectionModel *selModel = layersTree->selectionModel();
|
251 | 266 | connect( selModel, &QItemSelectionModel::currentChanged, this, &QgsSymbolSelectorWidget::layerChanged );
|
252 | 267 |
|
@@ -285,6 +300,15 @@ void QgsSymbolSelectorWidget::setContext( const QgsSymbolWidgetContext &context
|
285 | 300 | {
|
286 | 301 | mContext = context;
|
287 | 302 |
|
| 303 | + if ( mContext.expressionContext() ) |
| 304 | + { |
| 305 | + mPreviewExpressionContext = *mContext.expressionContext(); |
| 306 | + if ( mVectorLayer ) |
| 307 | + mPreviewExpressionContext.appendScope( QgsExpressionContextUtils::layerScope( mVectorLayer ) ); |
| 308 | + |
| 309 | + mPreviewExpressionContext.setFeature( mPreviewFeature ); |
| 310 | + } |
| 311 | + |
288 | 312 | QWidget *widget = stackedWidget->currentWidget();
|
289 | 313 | QgsLayerPropertiesWidget *layerProp = dynamic_cast< QgsLayerPropertiesWidget * >( widget );
|
290 | 314 | QgsSymbolsListWidget *listWidget = dynamic_cast< QgsSymbolsListWidget * >( widget );
|
@@ -362,7 +386,7 @@ void QgsSymbolSelectorWidget::updateUi()
|
362 | 386 |
|
363 | 387 | void QgsSymbolSelectorWidget::updatePreview()
|
364 | 388 | {
|
365 |
| - QImage preview = mSymbol->bigSymbolPreviewImage( mContext.expressionContext() ); |
| 389 | + QImage preview = mSymbol->bigSymbolPreviewImage( &mPreviewExpressionContext ); |
366 | 390 | lblPreview->setPixmap( QPixmap::fromImage( preview ) );
|
367 | 391 | // Hope this is a appropriate place
|
368 | 392 | emit symbolModified();
|
|
0 commit comments