Skip to content
Permalink
Browse files

Deprecate QgsExpression special column methods

  • Loading branch information
nyalldawson committed Sep 7, 2015
1 parent 05c2e4d commit 97096e2d6ba5362f3b735e3f4535ae9b4865f3db
Showing with 38 additions and 14 deletions.
  1. +12 −6 python/core/qgsexpression.sip
  2. +6 −0 src/core/qgsexpression.cpp
  3. +18 −8 src/core/qgsexpression.h
  4. +2 −0 tests/src/core/testqgsexpression.cpp
@@ -81,12 +81,18 @@ class QgsExpression
//! Return the number used for $rownum special column
int currentRowNumber() /Deprecated/;

//! Assign a special column
static void setSpecialColumn( const QString& name, QVariant value );
//! Unset a special column
static void unsetSpecialColumn( const QString& name );
//! Return the value of the given special column or a null QVariant if undefined
static QVariant specialColumn( const QString& name );
/** Assign a special column
* @deprecated use global or project QgsExpressionContext variables instead
*/
static void setSpecialColumn( const QString& name, QVariant value ) /Deprecated/;
/** Unset a special column
* @deprecated use global or project QgsExpressionContext variables instead
*/
static void unsetSpecialColumn( const QString& name ) /Deprecated/;
/** Return the value of the given special column or a null QVariant if undefined
* @deprecated use global or project QgsExpressionContext variables instead
*/
static QVariant specialColumn( const QString& name ) /Deprecated/;
//! Check whether a special column exists
//! @note added in 2.2
static bool hasSpecialColumn( const QString& name );
@@ -1689,7 +1689,9 @@ static QVariant fncColorCmyka( const QVariantList &values, const QgsExpressionCo
static QVariant fcnSpecialColumn( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
{
QString varName = getStringValue( values.at( 0 ), parent );
Q_NOWARN_DEPRECATED_PUSH
return QgsExpression::specialColumn( varName );
Q_NOWARN_DEPRECATED_POP
}

static QVariant fcnGetGeometry( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
@@ -2383,12 +2385,14 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
// variables with a local scope (must be restored after evaluation)
for ( QMap<QString, QVariant>::const_iterator sit = substitutionMap->begin(); sit != substitutionMap->end(); ++sit )
{
Q_NOWARN_DEPRECATED_PUSH
QVariant oldValue = QgsExpression::specialColumn( sit.key() );
if ( !oldValue.isNull() )
savedValues.insert( sit.key(), oldValue );

// set the new value
QgsExpression::setSpecialColumn( sit.key(), sit.value() );
Q_NOWARN_DEPRECATED_POP
}
}

@@ -2436,10 +2440,12 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
expr_action += action.mid( index );

// restore overwritten local values
Q_NOWARN_DEPRECATED_PUSH
for ( QMap<QString, QVariant>::const_iterator sit = savedValues.begin(); sit != savedValues.end(); ++sit )
{
QgsExpression::setSpecialColumn( sit.key(), sit.value() );
}
Q_NOWARN_DEPRECATED_POP

return expr_action;
}
@@ -168,14 +168,24 @@ class CORE_EXPORT QgsExpression
//! Return the number used for $rownum special column
Q_DECL_DEPRECATED int currentRowNumber() { return mRowNumber; }

//! Assign a special column
static void setSpecialColumn( const QString& name, QVariant value );
//! Unset a special column
static void unsetSpecialColumn( const QString& name );
//! Return the value of the given special column or a null QVariant if undefined
static QVariant specialColumn( const QString& name );
//! Check whether a special column exists
//! @note added in 2.2
//TODO QGIS 3.0: make the following methods private. They are still required for replaceExpressionText
//but should not be publicly used
/** Assign a special column
* @deprecated use global or project QgsExpressionContext variables instead
*/
Q_DECL_DEPRECATED static void setSpecialColumn( const QString& name, QVariant value );
/** Unset a special column
* @deprecated use global or project QgsExpressionContext variables instead
*/
Q_DECL_DEPRECATED static void unsetSpecialColumn( const QString& name );
/** Return the value of the given special column or a null QVariant if undefined
* @deprecated use global or project QgsExpressionContext variables instead
*/
Q_DECL_DEPRECATED static QVariant specialColumn( const QString& name );

/** Check whether a special column exists
* @note added in 2.2
*/
static bool hasSpecialColumn( const QString& name );

/** Checks whether an expression consists only of a single field reference
@@ -1295,6 +1295,7 @@ class TestQgsExpression: public QObject

void eval_special_columns()
{
Q_NOWARN_DEPRECATED_PUSH
QTest::addColumn<QString>( "string" );
QTest::addColumn<QVariant>( "result" );

@@ -1317,6 +1318,7 @@ class TestQgsExpression: public QObject
QCOMPARE( v4, QVariant() );

QgsExpression::unsetSpecialColumn( "$var1" );
Q_NOWARN_DEPRECATED_POP
}

void expression_from_expression_data()

0 comments on commit 97096e2

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