Skip to content

Commit a0360a6

Browse files
committedAug 10, 2016
Remove substitution map from QgsExpression::replaceExpressionText
Since expression context variables should now be used instead. Also remove all the deprecated methods which relied on this API.
1 parent c39088b commit a0360a6

12 files changed

+27
-280
lines changed
 

‎doc/api_break.dox

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ corresponding counterparts in QgsUnitTypes should be used instead.</li>
128128
<li>fileMenu() has been removed, use projectMenu() instead.
129129
</ul>
130130

131+
\subsection qgis_api_break_3_0_QgsActionManager QgsActionManager
132+
133+
<ul>
134+
<li>doAction() no longer accepts a substitution map. Use expression context variables instead.</li>
135+
<li>The doAction() variant which takes a QgsFeature along has been removed. Use the expression context
136+
variant instead.</li>
137+
<li>expandAction() has been removed. Use QgsExpression::replaceExpressionText() instead.</li>
138+
</ul>
139+
131140
\subsection qgis_api_break_3_0_QgsAtlasComposition QgsAtlasComposition
132141

133142
<ul>
@@ -146,6 +155,15 @@ corresponding counterparts in QgsUnitTypes should be used instead.</li>
146155
<li>GenericDataSourceURI has been renamed to GenericDataSourceUri</li>
147156
</ul>
148157

158+
\subsection qgis_api_break_3_0_QgsComposerLabel QgsComposerLabel
159+
160+
<ul>
161+
<li>setExpressionContext() has been removed. Setup the composition using an atlas and with
162+
expression variables in the composer label item instead.</li>
163+
<li>setSubstitutions has been removed. Use expression context variables in the composer
164+
label item instead.</li>
165+
</ul>
166+
149167
\subsection qgis_api_break_3_0_QgsComposerLegend QgsComposerLegend
150168

151169
<ul>
@@ -313,6 +331,7 @@ version instead.</li>
313331
<li>QgsExpression::Function::func has been modified to use a QgsExpressionContext argument rather than a QgsFeature.</li>
314332
<li>The QgsExpression::Node::eval and prepare versions which take a QgsFeature has been removed, use the QgsExpressionContext versions instead.</li>
315333
<li>QgsExpression::Interval has been removed. Use QgsInterval instead.</li>
334+
<li>replaceExpressionText() no longer accepts a substitution map parameter. Use expression context variables instead.</li>
316335
</ul>
317336

318337
\subsection qgis_api_break_3_0_QgsFeature QgsFeature

‎python/core/composer/qgscomposerlabel.sip

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ class QgsComposerLabel : QgsComposerItem
2828
/** Returns the text as it appears on screen (with replaced data field) */
2929
QString displayText() const;
3030

31-
/** Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions.
32-
* @deprecated use atlas features and setSubstitutions() instead
33-
*/
34-
void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, const QMap<QString, QVariant>& substitutions = QMap<QString, QVariant>() ) /Deprecated/;
35-
36-
/** Sets the list of local variable substitutions for evaluating expressions in label text.
37-
* @note added in QGIS 2.12
38-
*/
39-
void setSubstitutions( const QMap<QString, QVariant>& substitutions = QMap<QString, QVariant>() );
40-
4131
QFont font() const;
4232
void setFont( const QFont& f );
4333
/** Accessor for the vertical alignment of the label

‎python/core/qgsactionmanager.sip

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,10 @@ class QgsActionManager
7575
* @param index action index
7676
* @param feature feature to run action for
7777
* @param context expression context to evalute expressions under
78-
* @param substitutionMap deprecated - kept for compatibility with projects, will be removed for 3.0
7978
*/
80-
// TODO QGIS 3.0 remove substition map - force use of expression variables
8179
void doAction( int index,
8280
const QgsFeature& feature,
83-
const QgsExpressionContext& context,
84-
const QMap<QString, QVariant> *substitutionMap = nullptr );
85-
86-
87-
/** Does the action using the expression builder to expand it
88-
* and getting values from the passed feature attribute map.
89-
* substitutionMap is used to pass custom substitutions, to replace
90-
* each key in the map with the associated value
91-
* @note available in python bindings as doActionFeatureWithSubstitution
92-
*/
93-
void doAction( int index,
94-
const QgsFeature &feat,
95-
const QMap<QString, QVariant> *substitutionMap ) /PyName=doActionFeatureWithSubstitution/;
81+
const QgsExpressionContext& context );
9682

9783
//! Removes all actions
9884
void clearActions();
@@ -103,26 +89,6 @@ class QgsActionManager
10389
//! Return the layer
10490
QgsVectorLayer* layer() const;
10591

106-
/** Expands the given action, replacing all %'s with the value as
107-
* given.
108-
* @deprecated use QgsExpression::replaceExpressionText() instead
109-
*/
110-
QString expandAction( QString action, const QMap<int, QVariant> &attributes, uint defaultValueIndex ) /Deprecated/;
111-
112-
/** Expands the given action using the expression builder
113-
* This function currently replaces each expression between [% and %]
114-
* placeholders in the action with the result of its evaluation on
115-
* the feature passed as argument.
116-
*
117-
* Additional substitutions can be passed through the substitutionMap
118-
* parameter
119-
* @deprecated use QgsExpression::replaceExpressionText() instead
120-
*/
121-
QString expandAction( const QString& action,
122-
QgsFeature &feat,
123-
const QMap<QString, QVariant> *substitutionMap = 0 ) /Deprecated/;
124-
125-
12692
//! Writes the actions out in XML format
12793
bool writeXml( QDomNode& layer_node, QDomDocument& doc ) const;
12894

‎python/core/qgsexpression.sip

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,11 @@ class QgsExpression
140140
* Additional substitutions can be passed through the substitutionMap parameter
141141
* @param action
142142
* @param context expression context
143-
* @param substitutionMap
144143
* @param distanceArea optional QgsDistanceArea. If specified, the QgsDistanceArea is used for distance
145144
* and area conversion
146145
* @note added in QGIS 2.12
147146
*/
148147
static QString replaceExpressionText( const QString &action, const QgsExpressionContext* context,
149-
const QMap<QString, QVariant> *substitutionMap = 0,
150148
const QgsDistanceArea* distanceArea = 0 );
151149

152150
/** Attempts to evaluate a text string as an expression to a resultant double

‎src/app/qgsmaptoolfeatureaction.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,6 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
138138
if ( layer->actions()->defaultAction() >= 0 )
139139
{
140140
// define custom substitutions: layer id and clicked coords
141-
142-
// TODO QGIS 3.0 - remove these deprecated global expression variables!
143-
QMap<QString, QVariant> substitutionMap;
144-
substitutionMap.insert( "$layerid", layer->id() );
145-
point = toLayerCoordinates( layer, point );
146-
substitutionMap.insert( "$clickx", point.x() );
147-
substitutionMap.insert( "$clicky", point.y() );
148-
149141
QgsExpressionContext context;
150142
context << QgsExpressionContextUtils::globalScope()
151143
<< QgsExpressionContextUtils::projectScope()
@@ -156,7 +148,7 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
156148
context << actionScope;
157149

158150
int actionIdx = layer->actions()->defaultAction();
159-
layer->actions()->doAction( actionIdx, feat, context, &substitutionMap );
151+
layer->actions()->doAction( actionIdx, feat, context );
160152
}
161153
else
162154
{

‎src/core/composer/qgscomposerhtml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void QgsComposerHtml::loadHtml( const bool useCache, const QgsExpressionContext
179179
//evaluate expressions
180180
if ( mEvaluateExpressions )
181181
{
182-
loadedHtml = QgsExpression::replaceExpressionText( loadedHtml, evalContext, nullptr, mDistanceArea );
182+
loadedHtml = QgsExpression::replaceExpressionText( loadedHtml, evalContext, mDistanceArea );
183183
}
184184

185185
mLoaded = false;

‎src/core/composer/qgscomposerlabel.cpp

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -240,38 +240,6 @@ void QgsComposerLabel::setHtmlState( int state )
240240
}
241241
}
242242

243-
void QgsComposerLabel::setExpressionContext( QgsFeature *feature, QgsVectorLayer* layer, const QMap<QString, QVariant>& substitutions )
244-
{
245-
mExpressionFeature.reset( feature ? new QgsFeature( *feature ) : nullptr );
246-
mExpressionLayer = layer;
247-
mSubstitutions = substitutions;
248-
249-
//setup distance area conversion
250-
if ( layer )
251-
{
252-
mDistanceArea->setSourceCrs( layer->crs().srsid() );
253-
}
254-
else if ( mComposition )
255-
{
256-
//set to composition's mapsettings' crs
257-
mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
258-
}
259-
if ( mComposition )
260-
{
261-
mDistanceArea->setEllipsoidalMode( mComposition->mapSettings().hasCrsTransformEnabled() );
262-
}
263-
mDistanceArea->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
264-
contentChanged();
265-
266-
// Force label to redraw -- fixes label printing for labels with blend modes when used with atlas
267-
update();
268-
}
269-
270-
void QgsComposerLabel::setSubstitutions( const QMap<QString, QVariant>& substitutions )
271-
{
272-
mSubstitutions = substitutions;
273-
}
274-
275243
void QgsComposerLabel::refreshExpressionContext()
276244
{
277245
mExpressionLayer = nullptr;
@@ -307,7 +275,6 @@ QString QgsComposerLabel::displayText() const
307275
{
308276
QString displayText = mText;
309277
replaceDateText( displayText );
310-
QMap<QString, QVariant> subs = mSubstitutions;
311278

312279
QScopedPointer<QgsExpressionContext> context( createExpressionContext() );
313280
//overwrite layer/feature if they have been set via setExpressionContext
@@ -317,7 +284,7 @@ QString QgsComposerLabel::displayText() const
317284
if ( mExpressionLayer )
318285
context->setFields( mExpressionLayer->fields() );
319286

320-
return QgsExpression::replaceExpressionText( displayText, context.data(), &subs, mDistanceArea );
287+
return QgsExpression::replaceExpressionText( displayText, context.data(), mDistanceArea );
321288
}
322289

323290
void QgsComposerLabel::replaceDateText( QString& text ) const

‎src/core/composer/qgscomposerlabel.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
5353
/** Returns the text as it appears on screen (with replaced data field) */
5454
QString displayText() const;
5555

56-
/** Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions.
57-
* @deprecated use atlas features and setSubstitutions() instead
58-
*/
59-
Q_DECL_DEPRECATED void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, const QMap<QString, QVariant>& substitutions = ( QMap<QString, QVariant>() ) );
60-
61-
/** Sets the list of local variable substitutions for evaluating expressions in label text.
62-
* @note added in QGIS 2.12
63-
*/
64-
void setSubstitutions( const QMap<QString, QVariant>& substitutions = ( QMap<QString, QVariant>() ) );
65-
6656
QFont font() const;
6757
void setFont( const QFont& f );
6858
/** Accessor for the vertical alignment of the label
@@ -213,7 +203,6 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
213203

214204
QScopedPointer<QgsFeature> mExpressionFeature;
215205
QgsVectorLayer* mExpressionLayer;
216-
QMap<QString, QVariant> mSubstitutions;
217206
QgsDistanceArea* mDistanceArea;
218207

219208
QgsWebPage* mWebPage;

0 commit comments

Comments
 (0)
Please sign in to comment.