Skip to content

Commit

Permalink
Add support for modulo operator (%) in rule based rendering. See ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Santilli authored and jef-n committed May 26, 2011
1 parent 7c8ded1 commit c2757d3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qgssearchstringlexer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ string "'"{str_char}*"'"
"||" { return CONCAT; }
[+-/*^] { return yytext[0]; }
[+-/*^%] { return yytext[0]; }
[()] { return yytext[0]; }
Expand Down
1 change: 1 addition & 0 deletions src/core/qgssearchstringparser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgssearchtreenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/core/qgssearchtreenode.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CORE_EXPORT QgsSearchTreeNode
opPLUS,
opMINUS,
opMUL,
opMOD,
opDIV,
opPOW,
opSQRT,
Expand Down

0 comments on commit c2757d3

Please sign in to comment.