Skip to content
Permalink
Browse files

Add support for modulo operator (%) in rule based rendering. See ticket

  • Loading branch information
Sandro Santilli authored and jef-n committed May 26, 2011
1 parent 7c8ded1 commit c2757d31bc3a2d463b7f1e376b62f6046820a2e0
@@ -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;

@@ -781,6 +782,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 c2757d3

Please sign in to comment.
You can’t perform that action at this time.