Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3364 from nyalldawson/expression_dep
Clean QgsExpression for 3.0
  • Loading branch information
nyalldawson committed Aug 10, 2016
2 parents 56400b1 + b2cfb19 commit 0a2dd93
Show file tree
Hide file tree
Showing 35 changed files with 187 additions and 1,395 deletions.
47 changes: 47 additions & 0 deletions doc/api_break.dox
Expand Up @@ -23,6 +23,7 @@ This page tries to maintain a list with incompatible changes that happened in pr
<table>
<caption id="renamed_classes">Renamed classes</caption>
<tr><th>API 2.x <th>API 3.X
<tr><td>QgsAttributeAction <td>QgsActionManager
<tr><td>QgsColorButtonV2 <td>QgsColorButton
<tr><td>QgsSymbolLayerV2 <td>QgsSymbolLayer
<tr><td>QgsSymbolLayerV2AbstractMetadata <td>QgsSymbolLayerAbstractMetadata
Expand Down Expand Up @@ -127,6 +128,15 @@ corresponding counterparts in QgsUnitTypes should be used instead.</li>
<li>fileMenu() has been removed, use projectMenu() instead.
</ul>

\subsection qgis_api_break_3_0_QgsActionManager QgsActionManager

<ul>
<li>doAction() no longer accepts a substitution map. Use expression context variables instead.</li>
<li>The doAction() variant which takes a QgsFeature along has been removed. Use the expression context
variant instead.</li>
<li>expandAction() has been removed. Use QgsExpression::replaceExpressionText() instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsAtlasComposition QgsAtlasComposition

<ul>
Expand All @@ -145,6 +155,15 @@ corresponding counterparts in QgsUnitTypes should be used instead.</li>
<li>GenericDataSourceURI has been renamed to GenericDataSourceUri</li>
</ul>

\subsection qgis_api_break_3_0_QgsComposerLabel QgsComposerLabel

<ul>
<li>setExpressionContext() has been removed. Setup the composition using an atlas and with
expression variables in the composer label item instead.</li>
<li>setSubstitutions has been removed. Use expression context variables in the composer
label item instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsComposerLegend QgsComposerLegend

<ul>
Expand Down Expand Up @@ -243,6 +262,13 @@ be returned in place of a null pointer.</li>
<li>updateCRSCache() has been renamed to updateCrsCache</li>
</ul>

\subsection qgis_api_break_3_0_QgsDataDefined QgsDataDefined

<ul>
<li>expressionParams(), setExpressionParams() and insertExpressionParam() have been removed.
QgsExpressionContext variables should be used in their place.</li>
</ul>

\subsection qgis_api_break_3_0_QgsDataDefinedSymbolDialog QgsDataDefinedSymbolDialog

<ul>
Expand Down Expand Up @@ -290,6 +316,27 @@ place of a null pointer.</li>
<li>The ct member has been removed. Use coordinateTransform() and setCoordinateTransform() instead.
</ul>

\subsection qgis_api_break_3_0_QgsExpression QgsExpression

<ul>
<li>prepare( const QgsFields &fields ) has been removed. Use prepare( const QgsExpressionContext *context ) instead.</li>
<li>The evaluate methods which accept feature parameters have been removed. Use the version which takes a QgsExpressionContext
argument instead.</li>
<li>isValid( const QString& text, const QgsFields& fields, QString &errorMessage ) has been removed, use the QgsExpressionContext
version instead.</li>
<li>setCurrentRowNumber, currentRowNumber, scale, setScale, setSpecialColumn, unsetSpecialColumn, specialColumn, hasSpecialColumn have been
removed. Use QgsExpressionContext variables instead.</li>
<li>The replaceExpressionText version which accepts a QgsFeature argument has been removed. Use the QgsExpressionContext
version instead.</li>
<li>QgsExpression::Function::func has been modified to use a QgsExpressionContext argument rather than a QgsFeature.</li>
<li>QgsExpression::Function::usesgeometry() has been renamed to usesGeometry()</li>
<li>QgsExpression::Function::helptext() has been renamed to helpText()</li>
<li>The QgsExpression::Node::eval and prepare versions which take a QgsFeature has been removed, use the QgsExpressionContext versions instead.</li>
<li>QgsExpression::Interval has been removed. Use QgsInterval instead.</li>
<li>replaceExpressionText() no longer accepts a substitution map parameter. Use expression context variables instead.</li>
<li>helptext() has been renamed to helpText()</li>
</ul>

\subsection qgis_api_break_3_0_QgsFeature QgsFeature

<ul>
Expand Down
24 changes: 24 additions & 0 deletions doc/qgis3_user_changes.dox
@@ -0,0 +1,24 @@
/*! \page qgis3_user_changes QGIS 3.0 User Changes

\tableofcontents

Notes regarding user related changes for QGIS 3.0 which should be included in the release notes.

\section qgis3_user_changes_expressions Expressions

QGIS 3.0 brings some changes to the expression engine, which may require existing projects to
be updated so that any expressions in use have the following changes:
<ul>
<li>$rownum has been replaced by \@row_number</li>
<li>$scale has been replaced by \@map_scale</li>
<li>$map has been replaced by \@map_id</li>
<li>$numpages has been replaced by \@layout_numpages</li>
<li>$page has been replaced by \@layout_page</li>
<li>$feature has been replaced by \@atlas_featurenumber</li>
<li>$atlasfeatureid has been replaced by \@atlas_featureid</li>
<li>$atlasfeature has been replaced by \@atlas_feature</li>
<li>$atlasgeometry has been replaced by \@atlas_geometry</li>
<li>$numfeatures has been replaced by \@atlas_totalfeatures</li>
</ul>

*/
5 changes: 4 additions & 1 deletion python/core/__init__.py
Expand Up @@ -72,7 +72,10 @@ def __init__(self, func, name, args, group, helptext='', usesgeometry=True, refe
self.function = func
self.expandargs = expandargs

def func(self, values, feature, parent):
def func(self, values, context, parent):
feature = None
if context:
feature = context.feature()
try:
if self.expandargs:
values.append(feature)
Expand Down
10 changes: 0 additions & 10 deletions python/core/composer/qgscomposerlabel.sip
Expand Up @@ -28,16 +28,6 @@ class QgsComposerLabel : QgsComposerItem
/** Returns the text as it appears on screen (with replaced data field) */
QString displayText() const;

/** Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions.
* @deprecated use atlas features and setSubstitutions() instead
*/
void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer, const QMap<QString, QVariant>& substitutions = QMap<QString, QVariant>() ) /Deprecated/;

/** Sets the list of local variable substitutions for evaluating expressions in label text.
* @note added in QGIS 2.12
*/
void setSubstitutions( const QMap<QString, QVariant>& substitutions = QMap<QString, QVariant>() );

QFont font() const;
void setFont( const QFont& f );
/** Accessor for the vertical alignment of the label
Expand Down
1 change: 0 additions & 1 deletion python/core/core.sip
Expand Up @@ -23,7 +23,6 @@
%Include qgsaction.sip
%Include qgsactionmanager.sip
%Include qgsaggregatecalculator.sip
%Include qgsattributeaction.sip
%Include qgsattributetableconfig.sip
%Include qgsbrowsermodel.sip
%Include qgsclipper.sip
Expand Down
36 changes: 1 addition & 35 deletions python/core/qgsactionmanager.sip
Expand Up @@ -75,24 +75,10 @@ class QgsActionManager
* @param index action index
* @param feature feature to run action for
* @param context expression context to evalute expressions under
* @param substitutionMap deprecated - kept for compatibility with projects, will be removed for 3.0
*/
// TODO QGIS 3.0 remove substition map - force use of expression variables
void doAction( int index,
const QgsFeature& feature,
const QgsExpressionContext& context,
const QMap<QString, QVariant> *substitutionMap = nullptr );


/** Does the action using the expression builder to expand it
* and getting values from the passed feature attribute map.
* substitutionMap is used to pass custom substitutions, to replace
* each key in the map with the associated value
* @note available in python bindings as doActionFeatureWithSubstitution
*/
void doAction( int index,
const QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap ) /PyName=doActionFeatureWithSubstitution/;
const QgsExpressionContext& context );

//! Removes all actions
void clearActions();
Expand All @@ -103,26 +89,6 @@ class QgsActionManager
//! Return the layer
QgsVectorLayer* layer() const;

/** Expands the given action, replacing all %'s with the value as
* given.
* @deprecated use QgsExpression::replaceExpressionText() instead
*/
QString expandAction( QString action, const QMap<int, QVariant> &attributes, uint defaultValueIndex ) /Deprecated/;

/** Expands the given action using the expression builder
* This function currently replaces each expression between [% and %]
* placeholders in the action with the result of its evaluation on
* the feature passed as argument.
*
* Additional substitutions can be passed through the substitutionMap
* parameter
* @deprecated use QgsExpression::replaceExpressionText() instead
*/
QString expandAction( const QString& action,
QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap = 0 ) /Deprecated/;


//! Writes the actions out in XML format
bool writeXml( QDomNode& layer_node, QDomDocument& doc ) const;

Expand Down
146 changes: 0 additions & 146 deletions python/core/qgsattributeaction.sip

This file was deleted.

6 changes: 0 additions & 6 deletions python/core/qgsdatadefined.sip
Expand Up @@ -110,12 +110,6 @@ class QgsDataDefined
*/
QString expressionOrField() const;

//! @note not available in python bindings
//QMap<QString, QVariant> expressionParams() const;
//! @note not available in python bindings
//void setExpressionParams( QMap<QString, QVariant> params );
void insertExpressionParam( const QString& key, const QVariant& param );

/** Prepares the expression using a vector layer
* @param layer vector layer
* @returns true if expression was successfully prepared
Expand Down

0 comments on commit 0a2dd93

Please sign in to comment.