Deprecate QgsExpression special column methods

This commit is contained in:
Nyall Dawson 2015-09-07 19:19:24 +10:00
parent 05c2e4de84
commit 97096e2d6b
4 changed files with 38 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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