mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Add an isField test for QgsExpression
Checks whether expression consists of solely a field reference
This commit is contained in:
parent
ffeb61d549
commit
d4319621a5
@ -72,6 +72,11 @@ class QgsExpression
|
||||
//! @note added in 2.2
|
||||
static bool hasSpecialColumn( const QString& name );
|
||||
|
||||
/** Checks whether an expression consists only of a single field reference
|
||||
* @note added in 2.9
|
||||
*/
|
||||
bool isField() const;
|
||||
|
||||
static bool isValid( const QString& text, const QgsFields& fields, QString &errorMessage );
|
||||
|
||||
void setScale( double scale );
|
||||
|
@ -155,6 +155,11 @@ class CORE_EXPORT QgsExpression
|
||||
//! @note added in 2.2
|
||||
static bool hasSpecialColumn( const QString& name );
|
||||
|
||||
/** Checks whether an expression consists only of a single field reference
|
||||
* @note added in 2.9
|
||||
*/
|
||||
bool isField() const { return rootNode() && dynamic_cast<const NodeColumnRef*>( rootNode() ) ;}
|
||||
|
||||
static bool isValid( const QString& text, const QgsFields& fields, QString &errorMessage );
|
||||
|
||||
void setScale( double scale ) { mScale = scale; }
|
||||
|
@ -1099,6 +1099,16 @@ class TestQgsExpression: public QObject
|
||||
QCOMPARE( QgsExpression::evaluateToDouble( QString( "a" ), 9.0 ), 9.0 );
|
||||
QCOMPARE( QgsExpression::evaluateToDouble( QString(), 9.0 ), 9.0 );
|
||||
}
|
||||
|
||||
void eval_isField()
|
||||
{
|
||||
QCOMPARE( QgsExpression( "" ).isField(), false );
|
||||
QCOMPARE( QgsExpression( "42" ).isField(), false );
|
||||
QCOMPARE( QgsExpression( "foo" ).isField(), true );
|
||||
QCOMPARE( QgsExpression( "\"foo bar\"" ).isField(), true );
|
||||
QCOMPARE( QgsExpression( "sqrt(foo)" ).isField(), false );
|
||||
QCOMPARE( QgsExpression( "foo + bar" ).isField(), false );
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN( TestQgsExpression )
|
||||
|
Loading…
x
Reference in New Issue
Block a user