Skip to content

Commit 97096e2

Browse files
committedSep 7, 2015
Deprecate QgsExpression special column methods
1 parent 05c2e4d commit 97096e2

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed
 

‎python/core/qgsexpression.sip

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,18 @@ class QgsExpression
8181
//! Return the number used for $rownum special column
8282
int currentRowNumber() /Deprecated/;
8383

84-
//! Assign a special column
85-
static void setSpecialColumn( const QString& name, QVariant value );
86-
//! Unset a special column
87-
static void unsetSpecialColumn( const QString& name );
88-
//! Return the value of the given special column or a null QVariant if undefined
89-
static QVariant specialColumn( const QString& name );
84+
/** Assign a special column
85+
* @deprecated use global or project QgsExpressionContext variables instead
86+
*/
87+
static void setSpecialColumn( const QString& name, QVariant value ) /Deprecated/;
88+
/** Unset a special column
89+
* @deprecated use global or project QgsExpressionContext variables instead
90+
*/
91+
static void unsetSpecialColumn( const QString& name ) /Deprecated/;
92+
/** Return the value of the given special column or a null QVariant if undefined
93+
* @deprecated use global or project QgsExpressionContext variables instead
94+
*/
95+
static QVariant specialColumn( const QString& name ) /Deprecated/;
9096
//! Check whether a special column exists
9197
//! @note added in 2.2
9298
static bool hasSpecialColumn( const QString& name );

‎src/core/qgsexpression.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,9 @@ static QVariant fncColorCmyka( const QVariantList &values, const QgsExpressionCo
16891689
static QVariant fcnSpecialColumn( const QVariantList& values, const QgsExpressionContext*, QgsExpression* parent )
16901690
{
16911691
QString varName = getStringValue( values.at( 0 ), parent );
1692+
Q_NOWARN_DEPRECATED_PUSH
16921693
return QgsExpression::specialColumn( varName );
1694+
Q_NOWARN_DEPRECATED_POP
16931695
}
16941696

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

23902393
// set the new value
23912394
QgsExpression::setSpecialColumn( sit.key(), sit.value() );
2395+
Q_NOWARN_DEPRECATED_POP
23922396
}
23932397
}
23942398

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

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

24442450
return expr_action;
24452451
}

‎src/core/qgsexpression.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,24 @@ class CORE_EXPORT QgsExpression
168168
//! Return the number used for $rownum special column
169169
Q_DECL_DEPRECATED int currentRowNumber() { return mRowNumber; }
170170

171-
//! Assign a special column
172-
static void setSpecialColumn( const QString& name, QVariant value );
173-
//! Unset a special column
174-
static void unsetSpecialColumn( const QString& name );
175-
//! Return the value of the given special column or a null QVariant if undefined
176-
static QVariant specialColumn( const QString& name );
177-
//! Check whether a special column exists
178-
//! @note added in 2.2
171+
//TODO QGIS 3.0: make the following methods private. They are still required for replaceExpressionText
172+
//but should not be publicly used
173+
/** Assign a special column
174+
* @deprecated use global or project QgsExpressionContext variables instead
175+
*/
176+
Q_DECL_DEPRECATED static void setSpecialColumn( const QString& name, QVariant value );
177+
/** Unset a special column
178+
* @deprecated use global or project QgsExpressionContext variables instead
179+
*/
180+
Q_DECL_DEPRECATED static void unsetSpecialColumn( const QString& name );
181+
/** Return the value of the given special column or a null QVariant if undefined
182+
* @deprecated use global or project QgsExpressionContext variables instead
183+
*/
184+
Q_DECL_DEPRECATED static QVariant specialColumn( const QString& name );
185+
186+
/** Check whether a special column exists
187+
* @note added in 2.2
188+
*/
179189
static bool hasSpecialColumn( const QString& name );
180190

181191
/** Checks whether an expression consists only of a single field reference

‎tests/src/core/testqgsexpression.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ class TestQgsExpression: public QObject
12951295

12961296
void eval_special_columns()
12971297
{
1298+
Q_NOWARN_DEPRECATED_PUSH
12981299
QTest::addColumn<QString>( "string" );
12991300
QTest::addColumn<QVariant>( "result" );
13001301

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

13191320
QgsExpression::unsetSpecialColumn( "$var1" );
1321+
Q_NOWARN_DEPRECATED_POP
13201322
}
13211323

13221324
void expression_from_expression_data()

0 commit comments

Comments
 (0)
Please sign in to comment.