Skip to content

Commit

Permalink
expression: more comments and test to avoid differences between opera…
Browse files Browse the repository at this point in the history
…tors declaration and text values
  • Loading branch information
3nids committed Dec 12, 2014
1 parent d84af0d commit ea33122
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/qgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ inline bool isNull( const QVariant& v ) { return v.isNull(); }

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

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

Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsexpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,20 @@ class CORE_EXPORT QgsExpression
*/
static double evaluateToDouble( const QString& text, const double fallbackValue );

/**
* @brief list of unary operators
* @note if any change is made here, the definition of QgsExpression::UnaryOperatorText[] must be adapted.
*/
enum UnaryOperator
{
uoNot,
uoMinus,
};

/**
* @brief list of binary operators
* @note if any change is made here, the definition of QgsExpression::BinaryOperatorText[] must be adapted.
*/
enum BinaryOperator
{
// logical
Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ class TestQgsExpression: public QObject

void eval_precedence()
{
QCOMPARE(QgsExpression::BinaryOperatorText[QgsExpression::boDiv],"/");
QCOMPARE(QgsExpression::BinaryOperatorText[QgsExpression::boConcat],"||");

QgsExpression e0( "1+2*3" );
QCOMPARE( e0.evaluate().toInt(), 7 );

Expand Down

0 comments on commit ea33122

Please sign in to comment.