Skip to content

Commit a7d8519

Browse files
committedAug 22, 2015
Ensure context is available to builders from data defined buttons
1 parent bfc8f56 commit a7d8519

15 files changed

+203
-53
lines changed
 

‎python/core/qgsexpressioncontext.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class QgsExpressionContextUtils
400400
/** Creates a new scope which contains variables and functions relating to a QgsMapLayer.
401401
* For instance, layer name, id and fields.
402402
*/
403-
static QgsExpressionContextScope* layerScope( QgsMapLayer* layer ) /Factory/;
403+
static QgsExpressionContextScope* layerScope( const QgsMapLayer* layer ) /Factory/;
404404

405405
/** Helper function for creating an expression context which contains just a feature and fields
406406
* collection. Generally this method should not be used as the created context does not include

‎python/gui/qgsdatadefinedbutton.sip

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ class QgsDataDefinedButton : QToolButton
168168
*/
169169
void clearCheckedWidgets();
170170

171+
//! Callback function for retrieving the expression context for the button
172+
//typedef QgsExpressionContext( *ExpressionContextCallback )( const void* context );
173+
174+
/** Register callback function for retrieving the expression context for the button
175+
* @param fnGetExpressionContext call back function, will be called when the data defined
176+
* button requires the current expression context
177+
* @param context context for callback function
178+
* @note added in QGIS 2.12
179+
* @note not available in Python bindings
180+
*/
181+
//void registerGetExpressionContextCallback( ExpressionContextCallback fnGetExpressionContext, const void* context );
182+
171183
/**
172184
* Sets an assistant used to define the data defined object properties.
173185
* Ownership of the assistant is transferred to the widget.

‎src/app/composer/qgscomposerhtmlwidget.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,27 @@ QgsComposerItem::DataDefinedProperty QgsComposerHtmlWidget::ddPropertyForWidget(
482482
return QgsComposerItem::NoProperty;
483483
}
484484

485+
static QgsExpressionContext _getExpressionContext( const void* context )
486+
{
487+
const QgsComposerObject* composerObject = ( const QgsComposerObject* ) context;
488+
if ( !composerObject )
489+
{
490+
return QgsExpressionContext();
491+
}
492+
493+
QScopedPointer< QgsExpressionContext > expContext( composerObject->createExpressionContext() );
494+
return QgsExpressionContext( *expContext );
495+
}
496+
485497
void QgsComposerHtmlWidget::populateDataDefinedButtons()
486498
{
487499
QgsVectorLayer* vl = atlasCoverageLayer();
488500

489501
//block signals from data defined buttons
490502
mUrlDDBtn->blockSignals( true );
491503

504+
mUrlDDBtn->registerGetExpressionContextCallback( &_getExpressionContext, mHtml );
505+
492506
//initialise buttons to use atlas coverage layer
493507
mUrlDDBtn->init( vl, mHtml->dataDefinedProperty( QgsComposerItem::SourceUrl ),
494508
QgsDataDefinedButton::AnyType, tr( "url string" ) );

‎src/app/composer/qgscomposeritemwidget.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -550,19 +550,27 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements()
550550
mExcludeFromPrintsCheckBox->blockSignals( false );
551551
}
552552

553+
static QgsExpressionContext _getExpressionContext( const void* context )
554+
{
555+
const QgsComposerObject* composerObject = ( const QgsComposerObject* ) context;
556+
if ( !composerObject )
557+
{
558+
return QgsExpressionContext();
559+
}
560+
561+
QScopedPointer< QgsExpressionContext > expContext( composerObject->createExpressionContext() );
562+
return QgsExpressionContext( *expContext );
563+
}
564+
553565
void QgsComposerItemWidget::populateDataDefinedButtons()
554566
{
555567
QgsVectorLayer* vl = atlasCoverageLayer();
556568

557-
//block signals from data defined buttons
558-
mXPositionDDBtn->blockSignals( true );
559-
mYPositionDDBtn->blockSignals( true );
560-
mWidthDDBtn->blockSignals( true );
561-
mHeightDDBtn->blockSignals( true );
562-
mItemRotationDDBtn->blockSignals( true );
563-
mTransparencyDDBtn->blockSignals( true );
564-
mBlendModeDDBtn->blockSignals( true );
565-
mExcludePrintsDDBtn->blockSignals( true );
569+
Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
570+
{
571+
button->blockSignals( true );
572+
button->registerGetExpressionContextCallback( &_getExpressionContext, mItem );
573+
}
566574

567575
//initialise buttons to use atlas coverage layer
568576
mXPositionDDBtn->init( vl, mItem->dataDefinedProperty( QgsComposerObject::PositionX ),
@@ -583,14 +591,10 @@ void QgsComposerItemWidget::populateDataDefinedButtons()
583591
QgsDataDefinedButton::String, QgsDataDefinedButton::boolDesc() );
584592

585593
//unblock signals from data defined buttons
586-
mXPositionDDBtn->blockSignals( false );
587-
mYPositionDDBtn->blockSignals( false );
588-
mWidthDDBtn->blockSignals( false );
589-
mHeightDDBtn->blockSignals( false );
590-
mItemRotationDDBtn->blockSignals( false );
591-
mTransparencyDDBtn->blockSignals( false );
592-
mBlendModeDDBtn->blockSignals( false );
593-
mExcludePrintsDDBtn->blockSignals( false );
594+
Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
595+
{
596+
button->blockSignals( false );
597+
}
594598
}
595599

596600
QgsComposerObject::DataDefinedProperty QgsComposerItemWidget::ddPropertyForWidget( QgsDataDefinedButton* widget )

‎src/app/composer/qgscomposermapwidget.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,27 @@ QgsComposerMapWidget::~QgsComposerMapWidget()
188188
{
189189
}
190190

191+
static QgsExpressionContext _getExpressionContext( const void* context )
192+
{
193+
const QgsComposerObject* composerObject = ( const QgsComposerObject* ) context;
194+
if ( !composerObject )
195+
{
196+
return QgsExpressionContext();
197+
}
198+
199+
QScopedPointer< QgsExpressionContext > expContext( composerObject->createExpressionContext() );
200+
return QgsExpressionContext( *expContext );
201+
}
202+
191203
void QgsComposerMapWidget::populateDataDefinedButtons()
192204
{
193205
QgsVectorLayer* vl = atlasCoverageLayer();
194206

195-
//block signals from data defined buttons
196-
mScaleDDBtn->blockSignals( true );
197-
mMapRotationDDBtn->blockSignals( true );
198-
mXMinDDBtn->blockSignals( true );
199-
mYMinDDBtn->blockSignals( true );
200-
mXMaxDDBtn->blockSignals( true );
201-
mYMaxDDBtn->blockSignals( true );
202-
mAtlasMarginDDBtn->blockSignals( true );
203-
mStylePresetsDDBtn->blockSignals( true );
204-
mLayersDDBtn->blockSignals( true );
207+
Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
208+
{
209+
button->blockSignals( true );
210+
button->registerGetExpressionContextCallback( &_getExpressionContext, mComposerMap );
211+
}
205212

206213
//initialise buttons to use atlas coverage layer
207214
mScaleDDBtn->init( vl, mComposerMap->dataDefinedProperty( QgsComposerObject::MapScale ),
@@ -223,16 +230,10 @@ void QgsComposerMapWidget::populateDataDefinedButtons()
223230
mLayersDDBtn->init( vl, mComposerMap->dataDefinedProperty( QgsComposerObject::MapLayers ),
224231
QgsDataDefinedButton::String, tr( "list of map layer names separated by | characters" ) );
225232

226-
//unblock signals from data defined buttons
227-
mScaleDDBtn->blockSignals( false );
228-
mMapRotationDDBtn->blockSignals( false );
229-
mXMinDDBtn->blockSignals( false );
230-
mYMinDDBtn->blockSignals( false );
231-
mXMaxDDBtn->blockSignals( false );
232-
mYMaxDDBtn->blockSignals( false );
233-
mAtlasMarginDDBtn->blockSignals( false );
234-
mStylePresetsDDBtn->blockSignals( false );
235-
mLayersDDBtn->blockSignals( false );
233+
Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
234+
{
235+
button->blockSignals( false );
236+
}
236237
}
237238

238239
QgsComposerObject::DataDefinedProperty QgsComposerMapWidget::ddPropertyForWidget( QgsDataDefinedButton* widget )

‎src/app/composer/qgscomposerpicturewidget.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,27 @@ QgsComposerObject::DataDefinedProperty QgsComposerPictureWidget::ddPropertyForWi
609609
return QgsComposerObject::NoProperty;
610610
}
611611

612+
static QgsExpressionContext _getExpressionContext( const void* context )
613+
{
614+
const QgsComposerObject* composerObject = ( const QgsComposerObject* ) context;
615+
if ( !composerObject )
616+
{
617+
return QgsExpressionContext();
618+
}
619+
620+
QScopedPointer< QgsExpressionContext > expContext( composerObject->createExpressionContext() );
621+
return QgsExpressionContext( *expContext );
622+
}
623+
612624
void QgsComposerPictureWidget::populateDataDefinedButtons()
613625
{
614626
QgsVectorLayer* vl = atlasCoverageLayer();
615627

616628
//block signals from data defined buttons
617629
mSourceDDBtn->blockSignals( true );
618630

631+
mSourceDDBtn->registerGetExpressionContextCallback( &_getExpressionContext, mPicture );
632+
619633
//initialise buttons to use atlas coverage layer
620634
mSourceDDBtn->init( vl, mPicture->dataDefinedProperty( QgsComposerObject::PictureSource ),
621635
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::anyStringDesc() );

‎src/app/composer/qgscompositionwidget.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ QgsCompositionWidget::~QgsCompositionWidget()
137137

138138
}
139139

140+
static QgsExpressionContext _getExpressionContext( const void* context )
141+
{
142+
const QgsComposition* composition = ( const QgsComposition* ) context;
143+
if ( !composition )
144+
{
145+
return QgsExpressionContext();
146+
}
147+
148+
QScopedPointer< QgsExpressionContext > expContext( composition->createExpressionContext() );
149+
return QgsExpressionContext( *expContext );
150+
}
151+
140152
void QgsCompositionWidget::populateDataDefinedButtons()
141153
{
142154
if ( !mComposition )
@@ -152,11 +164,11 @@ void QgsCompositionWidget::populateDataDefinedButtons()
152164
vl = atlas->coverageLayer();
153165
}
154166

155-
mPaperSizeDDBtn->blockSignals( true );
156-
mPaperWidthDDBtn->blockSignals( true );
157-
mPaperHeightDDBtn->blockSignals( true );
158-
mNumPagesDDBtn->blockSignals( true );
159-
mPaperOrientationDDBtn->blockSignals( true );
167+
Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
168+
{
169+
button->blockSignals( true );
170+
button->registerGetExpressionContextCallback( &_getExpressionContext, mComposition );
171+
}
160172

161173
mPaperSizeDDBtn->init( vl, mComposition->dataDefinedProperty( QgsComposerObject::PresetPaperSize ),
162174
QgsDataDefinedButton::String, QgsDataDefinedButton::paperSizeDesc() );
@@ -172,11 +184,10 @@ void QgsCompositionWidget::populateDataDefinedButtons()
172184
//initial state of controls - disable related controls when dd buttons are active
173185
mPaperSizeComboBox->setEnabled( !mPaperSizeDDBtn->isActive() );
174186

175-
mPaperSizeDDBtn->blockSignals( false );
176-
mPaperWidthDDBtn->blockSignals( false );
177-
mPaperHeightDDBtn->blockSignals( false );
178-
mNumPagesDDBtn->blockSignals( false );
179-
mPaperOrientationDDBtn->blockSignals( false );
187+
Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
188+
{
189+
button->blockSignals( false );
190+
}
180191
}
181192

182193
void QgsCompositionWidget::variablesChanged()

‎src/app/qgslabelinggui.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,14 +872,33 @@ void QgsLabelingGui::setDataDefinedProperty( const QgsDataDefinedButton* ddBtn,
872872
lyr.setDataDefinedProperty( p, map.value( "active" ).toInt(), map.value( "useexpr" ).toInt(), map.value( "expression" ), map.value( "field" ) );
873873
}
874874

875+
static QgsExpressionContext _getExpressionContext( const void* context )
876+
{
877+
QgsExpressionContext expContext;
878+
expContext << QgsExpressionContextUtils::globalScope()
879+
<< QgsExpressionContextUtils::projectScope();
880+
881+
const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
882+
if ( layer )
883+
expContext << QgsExpressionContextUtils::layerScope( layer );
884+
885+
return expContext;
886+
}
887+
875888
void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )
876889
{
890+
Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
891+
{
892+
button->registerGetExpressionContextCallback( &_getExpressionContext, mLayer );
893+
}
894+
877895
// don't register enable/disable siblings, since visual feedback from data defined buttons should be enough,
878896
// and ability to edit layer-level setting should remain enabled regardless
879897

880898
QString trString = tr( "string " );
881899

882900
// text style
901+
883902
mFontDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::Family ),
884903
QgsDataDefinedButton::String,
885904
trString + tr( "[<b>family</b>|<b>family[foundry]</b>],<br>"

‎src/core/qgsexpressioncontext.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ void QgsExpressionContextUtils::setProjectVariables( const QgsStringMap &variabl
527527
project->writeEntry( "Variables", "/variableValues", variableValues );
528528
}
529529

530-
QgsExpressionContextScope* QgsExpressionContextUtils::layerScope( QgsMapLayer* layer )
530+
QgsExpressionContextScope* QgsExpressionContextUtils::layerScope( const QgsMapLayer* layer )
531531
{
532532
QgsExpressionContextScope* scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) );
533533

@@ -566,11 +566,13 @@ QgsExpressionContextScope* QgsExpressionContextUtils::layerScope( QgsMapLayer* l
566566
scope->addVariable( QgsExpressionContextScope::StaticVariable( "layer_crs", layer->crs().authid(), true ) );
567567
scope->addVariable( QgsExpressionContextScope::StaticVariable( "layer_crsdefinition", layer->crs().toProj4(), true ) );
568568

569-
QgsGeometry* extentGeom = QgsGeometry::fromRect( layer->extent() );
569+
//some methods we want aren't const
570+
QgsMapLayer* nonConstLayer = const_cast< QgsMapLayer* >( layer );
571+
QgsGeometry* extentGeom = QgsGeometry::fromRect( nonConstLayer->extent() );
570572
scope->addVariable( QgsExpressionContextScope::StaticVariable( "layer_extent", QVariant::fromValue( *extentGeom ), true ) );
571573
delete extentGeom;
572574

573-
QgsVectorLayer* vLayer = dynamic_cast< QgsVectorLayer* >( layer );
575+
QgsVectorLayer* vLayer = dynamic_cast< QgsVectorLayer* >( nonConstLayer );
574576
if ( vLayer )
575577
{
576578
scope->addVariable( QgsExpressionContextScope::StaticVariable( "layer_geometrytype", vLayer->type(), true ) );

‎src/core/qgsexpressioncontext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ class CORE_EXPORT QgsExpressionContextUtils
435435
/** Creates a new scope which contains variables and functions relating to a QgsMapLayer.
436436
* For instance, layer name, id and fields.
437437
*/
438-
static QgsExpressionContextScope* layerScope( QgsMapLayer* layer );
438+
static QgsExpressionContextScope* layerScope( const QgsMapLayer *layer );
439439

440440
/** Sets a layer context variable. This variable will be contained within scopes retrieved via
441441
* layerScope().

‎src/gui/qgsdatadefinedbutton.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ QgsDataDefinedButton::QgsDataDefinedButton( QWidget* parent,
4141
DataTypes datatypes,
4242
QString description )
4343
: QToolButton( parent )
44+
, mExpressionContextCallback( 0 )
45+
, mExpressionContextCallbackContext( 0 )
4446
{
4547
// set up static icons
4648
if ( mIconDataDefine.isNull() )
@@ -452,7 +454,9 @@ void QgsDataDefinedButton::showAssistant()
452454

453455
void QgsDataDefinedButton::showExpressionDialog()
454456
{
455-
QgsExpressionBuilderDialog d( const_cast<QgsVectorLayer*>( mVectorLayer ), getExpression() );
457+
QgsExpressionContext context = mExpressionContextCallback ? mExpressionContextCallback( mExpressionContextCallbackContext ) : QgsExpressionContext();
458+
459+
QgsExpressionBuilderDialog d( const_cast<QgsVectorLayer*>( mVectorLayer ), getExpression(), this, "generic", context );
456460
if ( d.exec() == QDialog::Accepted )
457461
{
458462
QString newExp = d.expressionText();
@@ -632,6 +636,12 @@ QList<QWidget*> QgsDataDefinedButton::registeredCheckedWidgets()
632636
return wdgtList;
633637
}
634638

639+
void QgsDataDefinedButton::registerGetExpressionContextCallback( QgsDataDefinedButton::ExpressionContextCallback fnGetExpressionContext, const void *context )
640+
{
641+
mExpressionContextCallback = fnGetExpressionContext;
642+
mExpressionContextCallbackContext = context;
643+
}
644+
635645
void QgsDataDefinedButton::setAssistant( const QString& title, QgsDataDefinedAssistant *assistant )
636646
{
637647
mActionAssistant->setText( title.isEmpty() ? tr( "Assistant..." ) : title );

‎src/gui/qgsdatadefinedbutton.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QPointer>
2222
#include <QToolButton>
2323
#include <QScopedPointer>
24+
#include "qgsexpressioncontext.h"
2425

2526
class QgsVectorLayer;
2627
class QgsDataDefined;
@@ -194,6 +195,18 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
194195
*/
195196
void clearCheckedWidgets() { mCheckedWidgets.clear(); }
196197

198+
//! Callback function for retrieving the expression context for the button
199+
typedef QgsExpressionContext( *ExpressionContextCallback )( const void* context );
200+
201+
/** Register callback function for retrieving the expression context for the button
202+
* @param fnGetExpressionContext call back function, will be called when the data defined
203+
* button requires the current expression context
204+
* @param context context for callback function
205+
* @note added in QGIS 2.12
206+
* @note not available in Python bindings
207+
*/
208+
void registerGetExpressionContextCallback( ExpressionContextCallback fnGetExpressionContext, const void* context );
209+
197210
/**
198211
* Sets an assistant used to define the data defined object properties.
199212
* Ownership of the assistant is transferred to the widget.
@@ -332,6 +345,9 @@ class GUI_EXPORT QgsDataDefinedButton: public QToolButton
332345
static QIcon mIconDataDefineExpressionOn;
333346
static QIcon mIconDataDefineExpressionError;
334347

348+
ExpressionContextCallback mExpressionContextCallback;
349+
const void* mExpressionContextCallbackContext;
350+
335351
private slots:
336352
void aboutToShowMenu();
337353
void menuActionTriggered( QAction* action );

‎src/gui/symbology-ng/qgsrendererv2widget.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,24 @@ QgsDataDefinedValueDialog::QgsDataDefinedValueDialog( const QList<QgsSymbolV2*>&
398398

399399
}
400400

401+
static QgsExpressionContext _getExpressionContext( const void* context )
402+
{
403+
QgsExpressionContext expContext;
404+
expContext << QgsExpressionContextUtils::globalScope()
405+
<< QgsExpressionContextUtils::projectScope();
406+
407+
const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
408+
if ( layer )
409+
expContext << QgsExpressionContextUtils::layerScope( layer );
410+
411+
return expContext;
412+
}
413+
401414
void QgsDataDefinedValueDialog::init( const QString & description )
402415
{
403416
QgsDataDefined dd = symbolDataDefined();
404417
mDDBtn->init( mLayer, &dd, QgsDataDefinedButton::Double, description );
418+
mDDBtn->registerGetExpressionContextCallback( &_getExpressionContext, const_cast< QgsVectorLayer* >( mLayer ) );
405419
mSpinBox->setValue( value( mSymbolList.back() ) );
406420
mSpinBox->setEnabled( !mDDBtn->isActive() );
407421
}

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,28 @@
4747
#include <QSvgRenderer>
4848
#include <QMessageBox>
4949

50+
static QgsExpressionContext _getExpressionContext( const void* context )
51+
{
52+
QgsExpressionContext expContext;
53+
expContext << QgsExpressionContextUtils::globalScope()
54+
<< QgsExpressionContextUtils::projectScope();
55+
56+
const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
57+
if ( layer )
58+
expContext << QgsExpressionContextUtils::layerScope( layer );
59+
60+
return expContext;
61+
}
62+
5063
void QgsSymbolLayerV2Widget::registerDataDefinedButton( QgsDataDefinedButton * button, const QString & propertyName, QgsDataDefinedButton::DataType type, const QString & description )
5164
{
5265
const QgsDataDefined* dd = symbolLayer()->getDataDefinedProperty( propertyName );
5366
button->init( mVectorLayer, dd, type, description );
5467
button->setProperty( "propertyName", propertyName );
5568
connect( button, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedProperty() ) );
5669
connect( button, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty() ) );
70+
71+
button->registerGetExpressionContextCallback( &_getExpressionContext, const_cast< QgsVectorLayer* >( mVectorLayer ) );
5772
}
5873

5974
void QgsSymbolLayerV2Widget::updateDataDefinedProperty()

‎src/gui/symbology-ng/qgssymbolslistwidget.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,28 @@ void QgsSymbolsListWidget::updateSymbolColor()
360360
btnColor->blockSignals( false );
361361
}
362362

363+
static QgsExpressionContext _getExpressionContext( const void* context )
364+
{
365+
QgsExpressionContext expContext;
366+
expContext << QgsExpressionContextUtils::globalScope()
367+
<< QgsExpressionContextUtils::projectScope();
368+
369+
const QgsVectorLayer* layer = ( const QgsVectorLayer* ) context;
370+
if ( layer )
371+
expContext << QgsExpressionContextUtils::layerScope( layer );
372+
373+
return expContext;
374+
}
375+
363376
void QgsSymbolsListWidget::updateSymbolInfo()
364377
{
365378
updateSymbolColor();
366379

380+
Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
381+
{
382+
button->registerGetExpressionContextCallback( &_getExpressionContext, mLayer );
383+
}
384+
367385
if ( mSymbol->type() == QgsSymbolV2::Marker )
368386
{
369387
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( mSymbol );

0 commit comments

Comments
 (0)
Failed to load comments.