Skip to content
Permalink
Browse files
Add support for modulo operator (%) in rule based rendering. See ticket
  • Loading branch information
Sandro Santilli authored and mach0 committed Dec 18, 2011
1 parent cab91b5 commit ccbd7aaf859a1cc3e9c2068a47a36166c88c3219
Showing with 8 additions and 1 deletion.
  1. +1 −1 src/core/qgssearchstringlexer.ll
  2. +1 −0 src/core/qgssearchstringparser.yy
  3. +5 −0 src/core/qgssearchtreenode.cpp
  4. +1 −0 src/core/qgssearchtreenode.h
@@ -109,7 +109,7 @@ string "'"{str_char}*"'"
"||" { return CONCAT; }
[+-/*^] { return yytext[0]; }
[+-/*^%] { return yytext[0]; }
[()] { return yytext[0]; }
@@ -171,6 +171,7 @@ scalar_exp:
}
| scalar_exp '^' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opPOW, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '*' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opMUL, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '%' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opMOD, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '/' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opDIV, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '+' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opPLUS, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '-' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opMINUS,$1, $3); joinTmpNodes($$,$1,$3); }
@@ -268,6 +268,7 @@ QString QgsSearchTreeNode::makeSearchString()
case opPLUS: str += "+"; break;
case opMINUS: str += "-"; break;
case opMUL: str += "*"; break;
case opMOD: str += "%"; break;
case opDIV: str += "/"; break;
case opPOW: str += "^"; break;

@@ -776,6 +777,10 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, Q
return QgsSearchTreeValue( val1 - val2 );
case opMUL:
return QgsSearchTreeValue( val1 * val2 );
case opMOD:
// NOTE: we _might_ support float operators, like postgresql does
// see 83c94a886c059 commit in postgresql git repo for more info
return QgsSearchTreeValue( int(val1) % int(val2) );
case opDIV:
if ( val2 == 0 )
return QgsSearchTreeValue( 2, "" ); // division by zero
@@ -66,6 +66,7 @@ class CORE_EXPORT QgsSearchTreeNode
opPLUS,
opMINUS,
opMUL,
opMOD,
opDIV,
opPOW,
opSQRT,

0 comments on commit ccbd7aa

Please sign in to comment.