Skip to content
Permalink
Browse files

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 0a2dd938138c1ccb71fa2e1ab56c541f2a336d88
Showing with 187 additions and 1,395 deletions.
  1. +47 −0 doc/api_break.dox
  2. +24 −0 doc/qgis3_user_changes.dox
  3. +4 −1 python/core/__init__.py
  4. +0 −10 python/core/composer/qgscomposerlabel.sip
  5. +0 −1 python/core/core.sip
  6. +1 −35 python/core/qgsactionmanager.sip
  7. +0 −146 python/core/qgsattributeaction.sip
  8. +0 −6 python/core/qgsdatadefined.sip
  9. +10 −142 python/core/qgsexpression.sip
  10. +4 −3 python/plugins/processing/algs/qgis/ui/FieldsMappingPanel.py
  11. +2 −2 src/app/qgsattributetabledialog.cpp
  12. +1 −1 src/app/qgsfieldcalculator.cpp
  13. +1 −9 src/app/qgsmaptoolfeatureaction.cpp
  14. +1 −1 src/core/composer/qgscomposerhtml.cpp
  15. +1 −34 src/core/composer/qgscomposerlabel.cpp
  16. +0 −11 src/core/composer/qgscomposerlabel.h
  17. +2 −140 src/core/qgsactionmanager.cpp
  18. +1 −35 src/core/qgsactionmanager.h
  19. +0 −29 src/core/qgsdatadefined.cpp
  20. +0 −6 src/core/qgsdatadefined.h
  21. +0 −2 src/core/qgsdatadefined_p.h
  22. +9 −339 src/core/qgsexpression.cpp
  23. +19 −155 src/core/qgsexpression.h
  24. +4 −14 src/core/qgsexpressionparser.yy
  25. +0 −6 src/core/qgsexpressionprivate.h
  26. +1 −2 src/core/qgspallabeling.cpp
  27. +1 −1 src/core/qgsvectorlayerfeatureiterator.cpp
  28. +2 −9 src/core/qgsvectorlayerlabelprovider.cpp
  29. +0 −6 src/core/symbology-ng/qgssymbollayer.cpp
  30. +5 −12 src/gui/qgsexpressionbuilderwidget.cpp
  31. +1 −1 src/providers/virtual/qgsvirtuallayersqlitemodule.cpp
  32. +0 −10 tests/src/core/testqgscomposerlabel.cpp
  33. +36 −200 tests/src/core/testqgsexpression.cpp
  34. +2 −2 tests/src/python/test_qgsatlascomposition.py
  35. +8 −24 tests/src/python/test_qgscomposerlabel.py
@@ -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
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>

*/
@@ -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)
@@ -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
@@ -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
@@ -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();
@@ -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;

This file was deleted.

@@ -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

0 comments on commit 0a2dd93

Please sign in to comment.
You can’t perform that action at this time.