Skip to content

Commit ea33122

Browse files
committedDec 12, 2014
expression: more comments and test to avoid differences between operators declaration and text values
1 parent d84af0d commit ea33122

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed
 

‎src/core/qgsexpression.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ inline bool isNull( const QVariant& v ) { return v.isNull(); }
212212

213213
const char* QgsExpression::BinaryOperatorText[] =
214214
{
215+
// this must correspond (number and order of element) to the declaration of the enum BinaryOperator
215216
"OR", "AND",
216217
"=", "<>", "<=", ">=", "<", ">", "~", "LIKE", "NOT LIKE", "ILIKE", "NOT ILIKE", "IS", "IS NOT",
217218
"+", "-", "*", "/", "//", "%", "^",
@@ -220,6 +221,7 @@ const char* QgsExpression::BinaryOperatorText[] =
220221

221222
const char* QgsExpression::UnaryOperatorText[] =
222223
{
224+
// this must correspond (number and order of element) to the declaration of the enum UnaryOperator
223225
"NOT", "-"
224226
};
225227

‎src/core/qgsexpression.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,20 @@ class CORE_EXPORT QgsExpression
210210
*/
211211
static double evaluateToDouble( const QString& text, const double fallbackValue );
212212

213+
/**
214+
* @brief list of unary operators
215+
* @note if any change is made here, the definition of QgsExpression::UnaryOperatorText[] must be adapted.
216+
*/
213217
enum UnaryOperator
214218
{
215219
uoNot,
216220
uoMinus,
217221
};
222+
223+
/**
224+
* @brief list of binary operators
225+
* @note if any change is made here, the definition of QgsExpression::BinaryOperatorText[] must be adapted.
226+
*/
218227
enum BinaryOperator
219228
{
220229
// logical

‎tests/src/core/testqgsexpression.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ class TestQgsExpression: public QObject
468468

469469
void eval_precedence()
470470
{
471+
QCOMPARE(QgsExpression::BinaryOperatorText[QgsExpression::boDiv],"/");
472+
QCOMPARE(QgsExpression::BinaryOperatorText[QgsExpression::boConcat],"||");
473+
471474
QgsExpression e0( "1+2*3" );
472475
QCOMPARE( e0.evaluate().toInt(), 7 );
473476

0 commit comments

Comments
 (0)
Please sign in to comment.