19 #include <QDomDocument>
54 QRegExp rx(
"([-+]?\\d?\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
58 while (( pos = rx.indexIn(
string, pos ) ) != -1 )
61 pos += rx.matchedLength();
64 QMap<int, QStringList> map;
65 map.insert( 1, QStringList() <<
"second" <<
"seconds" <<
QObject::tr(
"second|seconds",
"list of words separated by | which reference years" ).split(
"|" ) );
66 map.insert( 0 + MINUTE, QStringList() <<
"minute" <<
"minutes" <<
QObject::tr(
"minute|minutes",
"list of words separated by | which reference minutes" ).split(
"|" ) );
67 map.insert( 0 + HOUR, QStringList() <<
"hour" <<
"hours" <<
QObject::tr(
"hour|hours",
"list of words separated by | which reference minutes hours" ).split(
"|" ) );
68 map.insert( 0 + DAY, QStringList() <<
"day" <<
"days" <<
QObject::tr(
"day|days",
"list of words separated by | which reference days" ).split(
"|" ) );
69 map.insert( 0 + WEEKS, QStringList() <<
"week" <<
"weeks" <<
QObject::tr(
"week|weeks",
"wordlist separated by | which reference weeks" ).split(
"|" ) );
70 map.insert( 0 + MONTHS, QStringList() <<
"month" <<
"months" <<
QObject::tr(
"month|months",
"list of words separated by | which reference months" ).split(
"|" ) );
71 map.insert( 0 + YEARS, QStringList() <<
"year" <<
"years" <<
QObject::tr(
"year|years",
"list of words separated by | which reference years" ).split(
"|" ) );
73 foreach ( QString match, list )
75 QStringList split = match.split( QRegExp(
"\\s+" ) );
77 double value = split.at( 0 ).toDouble( &ok );
84 foreach (
int duration, map.keys() )
86 foreach ( QString name, map[duration] )
88 if ( match.contains( name, Qt::CaseInsensitive ) )
97 seconds += value * duration;
112 return ( mSeconds == other.mSeconds );
146 case False:
return 0;
154 #define TVL_True QVariant(1)
155 #define TVL_False QVariant(0)
156 #define TVL_Unknown QVariant()
163 if ( v.type() == QVariant::Int )
return true;
164 if ( v.type() == QVariant::UInt )
return true;
165 if ( v.type() == QVariant::LongLong )
return true;
166 if ( v.type() == QVariant::ULongLong )
return true;
167 if ( v.type() == QVariant::Double )
return false;
168 if ( v.type() == QVariant::String ) {
bool ok; v.toString().toInt( &ok );
return ok; }
173 if ( v.type() == QVariant::Double )
return true;
174 if ( v.type() == QVariant::Int )
return true;
175 if ( v.type() == QVariant::UInt )
return true;
176 if ( v.type() == QVariant::LongLong )
return true;
177 if ( v.type() == QVariant::ULongLong )
return true;
178 if ( v.type() == QVariant::String ) {
bool ok; v.toString().toDouble( &ok );
return ok; }
184 return v.type() == QVariant::DateTime || v.type() == QVariant::Date ||
185 v.type() == QVariant::Time;
195 if ( v.type() == QVariant::String )
202 inline bool isNull(
const QVariant& v ) {
return v.isNull(); }
207 #define ENSURE_NO_EVAL_ERROR { if (parent->hasEvalError()) return QVariant(); }
208 #define SET_EVAL_ERROR(x) { parent->setEvalErrorString(x); return QVariant(); }
217 "=",
"<>",
"<=",
">=",
"<",
">",
"~",
"LIKE",
"NOT LIKE",
"ILIKE",
"NOT ILIKE",
"IS",
"IS NOT",
218 "+",
"-",
"*",
"/",
"//",
"%",
"^",
234 return value.toString();
240 double x = value.toDouble( &ok );
252 qint64 x = value.toLongLong( &ok );
266 QDateTime d = value.toDateTime();
280 QDate d = value.toDate();
294 QTime t = value.toTime();
312 if ( inter.isValid() )
354 if ( value.isNull() )
357 if ( value.type() == QVariant::Int )
358 return value.toInt() != 0 ?
True :
False;
361 double x = value.toDouble( &ok );
375 return QVariant( sqrt( x ) );
381 return QVariant( fabs( val ) );
387 return QVariant( sin( x ) );
392 return QVariant( cos( x ) );
397 return QVariant( tan( x ) );
402 return QVariant( asin( x ) );
407 return QVariant( acos( x ) );
412 return QVariant( atan( x ) );
418 return QVariant( atan2( y, x ) );
423 return QVariant( exp( x ) );
430 return QVariant( log( x ) );
437 return QVariant( log10( x ) );
443 if ( x <= 0 || b <= 0 )
445 return QVariant( log( x ) / log( b ) );
455 double f = ( double )qrand() / RAND_MAX;
456 return QVariant( min + f * ( max - min ) );
466 return QVariant( min + ( qrand() % (
int )( max - min + 1 ) ) );
477 if ( domainMin >= domainMax )
484 if ( val >= domainMax )
488 else if ( val <= domainMin )
494 double m = ( rangeMax - rangeMin ) / ( domainMax - domainMin );
495 double c = rangeMin - ( domainMin * m );
498 return QVariant( m * val + c );
510 if ( domainMin >= domainMax )
522 if ( val >= domainMax )
526 else if ( val <= domainMin )
532 return QVariant((( rangeMax - rangeMin ) / pow( domainMax - domainMin, exponent ) ) * pow( val - domainMin, exponent ) + rangeMin );
541 for (
int i = 1; i < values.length(); ++i )
544 if ( testVal > maxVal )
550 return QVariant( maxVal );
559 for (
int i = 1; i < values.length(); ++i )
562 if ( testVal < minVal )
568 return QVariant( minVal );
578 if ( testValue <= minValue )
580 return QVariant( minValue );
582 else if ( testValue >= maxValue )
584 return QVariant( maxValue );
588 return QVariant( testValue );
595 return QVariant( floor( x ) );
601 return QVariant( ceil( x ) );
606 return QVariant(
getIntValue( values.at( 0 ), parent ) );
624 foreach (
const QVariant &value, values )
626 if ( value.isNull() )
635 return QVariant( str.toLower() );
640 return QVariant( str.toUpper() );
645 QStringList elems = str.split(
" " );
646 for (
int i = 0; i < elems.size(); i++ )
648 if ( elems[i].
size() > 1 )
649 elems[i] = elems[i].left( 1 ).toUpper() + elems[i].mid( 1 ).toLower();
651 return QVariant( elems.join(
" " ) );
657 return QVariant( str.trimmed() );
662 if ( values.length() == 2 || values.length() == 3 )
667 if ( !str.isEmpty() && wrap != 0 )
670 QString delimiterstr;
671 if ( values.length() == 3 ) delimiterstr =
getStringValue( values.at( 2 ), parent );
672 if ( delimiterstr.isEmpty() ) delimiterstr =
" ";
673 int delimiterlength = delimiterstr.length();
675 QStringList lines = str.split(
"\n" );
676 int strlength, strcurrent, strhit, lasthit;
678 for (
int i = 0; i < lines.size(); i++ )
680 strlength = lines[i].length();
685 while ( strcurrent < strlength )
692 strhit = lines[i].lastIndexOf( delimiterstr, strcurrent + wrap );
693 if ( strhit == lasthit || strhit == -1 )
696 strhit = lines[i].indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
702 strhit = lines[i].indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
706 newstr.append( lines[i].midRef( strcurrent, strhit - strcurrent ) );
707 newstr.append(
"\n" );
708 strcurrent = strhit + delimiterlength;
712 newstr.append( lines[i].midRef( strcurrent ) );
713 strcurrent = strlength;
716 if ( i < lines.size() - 1 ) newstr.append(
"\n" );
719 return QVariant( newstr );
729 return QVariant( str.length() );
736 return QVariant( str.replace( before, after ) );
744 QRegExp re( regexp );
750 return QVariant( str.replace( re, after ) );
758 QRegExp re( regexp );
764 return QVariant( str.contains( re ) ? 1 : 0 );
772 QRegExp re( regexp );
780 ( void )re.indexIn( str );
781 if ( re.captureCount() > 0 )
784 return QVariant( re.capturedTexts()[1] );
788 return QVariant(
"" );
794 return QUuid::createUuid().toString();
802 return QVariant( str.mid( from -1, len ) );
813 return f ? QVariant((
int )f->
id() ) : QVariant();
818 return f ? QVariant::fromValue( *f ) : QVariant();
830 foreach (
const QVariant &value, values )
840 return string.indexOf( QRegExp(
getStringValue( values.at( 1 ), parent ) ) );
847 return string.right( pos );
854 return string.left( pos );
860 int length =
getIntValue( values.at( 1 ), parent );
862 return string.leftJustified( length, fill.at( 0 ), true );
868 int length =
getIntValue( values.at( 1 ), parent );
870 return string.rightJustified( length, fill.at( 0 ), true );
876 for (
int n = 1; n < values.length(); n++ )
886 return QVariant( QDateTime::currentDateTime() );
891 return QVariant(
getDateValue( values.at( 0 ), parent ) );
896 return QVariant(
getTimeValue( values.at( 0 ), parent ) );
901 return QVariant::fromValue(
getInterval( values.at( 0 ), parent ) );
908 int seconds = d2.secsTo( d1 );
914 QVariant value = values.at( 0 );
918 return QVariant( inter.
days() );
923 return QVariant( d1.date().day() );
929 QVariant value = values.at( 0 );
933 return QVariant( inter.
years() );
938 return QVariant( d1.date().year() );
944 QVariant value = values.at( 0 );
948 return QVariant( inter.
months() );
953 return QVariant( d1.date().month() );
959 QVariant value = values.at( 0 );
963 return QVariant( inter.
weeks() );
968 return QVariant( d1.date().weekNumber() );
974 QVariant value = values.at( 0 );
978 return QVariant( inter.
hours() );
983 return QVariant( d1.time().hour() );
989 QVariant value = values.at( 0 );
993 return QVariant( inter.
minutes() );
998 return QVariant( d1.time().minute() );
1004 QVariant value = values.at( 0 );
1008 return QVariant( inter.
seconds() );
1013 return QVariant( d1.time().second() );
1018 #define ENSURE_GEOM_TYPE(f, g, geomtype) if (!f) return QVariant(); \
1019 QgsGeometry* g = f->geometry(); \
1020 if (!g || g->type() != geomtype) return QVariant();
1026 if ( g->isMultipart() )
1028 return g->asMultiPoint()[ 0 ].x();
1032 return g->asPoint().x();
1038 if ( g->isMultipart() )
1040 return g->asMultiPoint()[ 0 ].y();
1044 return g->asPoint().y();
1054 idx += polyline.count();
1056 if ( idx < 0 || idx >= polyline.count() )
1061 return QVariant( QPointF( polyline[idx].x(), polyline[idx].y() ) );
1066 QVariant v =
pointAt( values, f, parent );
1067 if ( v.type() == QVariant::PointF )
1068 return QVariant( v.toPointF().x() );
1074 QVariant v =
pointAt( values, f, parent );
1075 if ( v.type() == QVariant::PointF )
1076 return QVariant( v.toPointF().y() );
1084 return QVariant::fromValue( *geom );
1093 return QVariant::fromValue( *geom );
1103 return QVariant::fromValue( *geom );
1133 return QVariant::fromValue( *geomBounds );
1227 if ( values.length() < 2 || values.length() > 3 )
1233 if ( values.length() == 3 )
1238 return QVariant::fromValue( *geom );
1246 return QVariant::fromValue( *geom );
1254 return QVariant::fromValue( *geom );
1263 return QVariant::fromValue( *geom );
1270 return QVariant( fGeom.
distance( sGeom ) );
1278 return QVariant::fromValue( *geom );
1287 return QVariant::fromValue( *geom );
1296 return QVariant::fromValue( *geom );
1301 if ( values.length() < 1 || values.length() > 2 )
1306 if ( values.length() == 2 )
1309 return QVariant( wkt );
1315 if ( values.length() == 2 )
1318 double scaler = pow( 10.0,
getIntValue( values.at( 1 ), parent ) );
1319 return QVariant( qRound( number * scaler ) / scaler );
1322 if ( values.length() == 1 )
1324 double number =
getIntValue( values.at( 0 ), parent );
1325 return QVariant( qRound( number ) ).toInt();
1341 return QVariant( parent->
scale() );
1347 int places =
getIntValue( values.at( 1 ), parent );
1348 return QString(
"%L1" ).arg( value, 0,
'f', places );
1355 return dt.toString( format );
1361 int green =
getIntValue( values.at( 1 ), parent );
1363 QColor color = QColor( red, green, blue );
1364 if ( ! color.isValid() )
1367 color = QColor( 0, 0, 0 );
1370 return QString(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
1377 QVariant value = node->
eval( parent, f );
1379 if ( value.toBool() )
1381 node =
getNode( values.at( 1 ), parent );
1383 value = node->
eval( parent, f );
1388 node =
getNode( values.at( 2 ), parent );
1390 value = node->
eval( parent, f );
1399 int green =
getIntValue( values.at( 1 ), parent );
1401 int alpha =
getIntValue( values.at( 3 ), parent );
1402 QColor color = QColor( red, green, blue, alpha );
1403 if ( ! color.isValid() )
1406 color = QColor( 0, 0, 0 );
1418 return QColor( 0, 0, 0 ).name();
1421 QColor color = mRamp->color( value );
1428 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1430 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1432 double lightness =
getIntValue( values.at( 2 ), parent ) / 100.0;
1434 QColor color = QColor::fromHslF( hue, saturation, lightness );
1436 if ( ! color.isValid() )
1439 color = QColor( 0, 0, 0 );
1442 return QString(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
1448 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1450 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1452 double lightness =
getIntValue( values.at( 2 ), parent ) / 100.0;
1454 double alpha =
getIntValue( values.at( 3 ), parent ) / 255.0;
1456 QColor color = QColor::fromHslF( hue, saturation, lightness, alpha );
1457 if ( ! color.isValid() )
1459 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( lightness ).arg( alpha ) );
1460 color = QColor( 0, 0, 0 );
1468 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1470 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1472 double value =
getIntValue( values.at( 2 ), parent ) / 100.0;
1474 QColor color = QColor::fromHsvF( hue, saturation, value );
1476 if ( ! color.isValid() )
1479 color = QColor( 0, 0, 0 );
1482 return QString(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
1488 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1490 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1492 double value =
getIntValue( values.at( 2 ), parent ) / 100.0;
1494 double alpha =
getIntValue( values.at( 3 ), parent ) / 255.0;
1496 QColor color = QColor::fromHsvF( hue, saturation, value, alpha );
1497 if ( ! color.isValid() )
1499 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( value ).arg( alpha ) );
1500 color = QColor( 0, 0, 0 );
1508 double cyan =
getIntValue( values.at( 0 ), parent ) / 100.0;
1510 double magenta =
getIntValue( values.at( 1 ), parent ) / 100.0;
1512 double yellow =
getIntValue( values.at( 2 ), parent ) / 100.0;
1514 double black =
getIntValue( values.at( 3 ), parent ) / 100.0;
1516 QColor color = QColor::fromCmykF( cyan, magenta, yellow, black );
1518 if ( ! color.isValid() )
1521 color = QColor( 0, 0, 0 );
1524 return QString(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
1530 double cyan =
getIntValue( values.at( 0 ), parent ) / 100.0;
1532 double magenta =
getIntValue( values.at( 1 ), parent ) / 100.0;
1534 double yellow =
getIntValue( values.at( 2 ), parent ) / 100.0;
1536 double black =
getIntValue( values.at( 3 ), parent ) / 100.0;
1538 double alpha =
getIntValue( values.at( 4 ), parent ) / 255.0;
1540 QColor color = QColor::fromCmykF( cyan, magenta, yellow, black, alpha );
1541 if ( ! color.isValid() )
1543 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4:%5' to color" ).arg( cyan ).arg( magenta ).arg( yellow ).arg( black ).arg( alpha ) );
1544 color = QColor( 0, 0, 0 );
1560 return QVariant::fromValue( *geom );
1571 if ( ! s.createFromOgcWmsCrs( sAuthId ) )
1572 return QVariant::fromValue( fGeom );
1575 return QVariant::fromValue( fGeom );
1579 return QVariant::fromValue( fGeom );
1591 if ( layersByName.size() > 0 )
1604 int attributeId = vl->fieldNameIndex( attribute );
1605 if ( attributeId == -1 )
1610 const QVariant& attVal = values.at( 2 );
1621 if ( fet.
attribute( attributeId ) == attVal )
1623 return QVariant::fromValue( fet );
1665 <<
"abs" <<
"sqrt" <<
"cos" <<
"sin" <<
"tan"
1666 <<
"asin" <<
"acos" <<
"atan" <<
"atan2"
1667 <<
"exp" <<
"ln" <<
"log10" <<
"log"
1668 <<
"round" <<
"rand" <<
"randf" <<
"max" <<
"min" <<
"clamp"
1669 <<
"scale_linear" <<
"scale_exp" <<
"floor" <<
"ceil"
1670 <<
"toint" <<
"toreal" <<
"tostring"
1671 <<
"todatetime" <<
"todate" <<
"totime" <<
"tointerval"
1672 <<
"coalesce" <<
"regexp_match" <<
"$now" <<
"age" <<
"year"
1673 <<
"month" <<
"week" <<
"day" <<
"hour"
1674 <<
"minute" <<
"second" <<
"lower" <<
"upper"
1675 <<
"title" <<
"length" <<
"replace" <<
"trim" <<
"wordwrap"
1676 <<
"regexp_replace" <<
"regexp_substr"
1677 <<
"substr" <<
"concat" <<
"strpos" <<
"left"
1678 <<
"right" <<
"rpad" <<
"lpad"
1679 <<
"format_number" <<
"format_date"
1680 <<
"color_rgb" <<
"color_rgba" <<
"ramp_color"
1681 <<
"color_hsl" <<
"color_hsla" <<
"color_hsv" <<
"color_hsva"
1682 <<
"color_cymk" <<
"color_cymka"
1683 <<
"xat" <<
"yat" <<
"$area"
1684 <<
"$length" <<
"$perimeter" <<
"$x" <<
"$y"
1685 <<
"$rownum" <<
"$id" <<
"$scale" <<
"_specialcol_";
1864 static bool initialized =
false;
1872 QList< QPair<QString, QString> > lst;
1873 lst << qMakePair( QString(
"$page" ), QString(
"Composer" ) );
1874 lst << qMakePair( QString(
"$feature" ), QString(
"Atlas" ) );
1875 lst << qMakePair( QString(
"$numpages" ), QString(
"Composer" ) );
1876 lst << qMakePair( QString(
"$numfeatures" ), QString(
"Atlas" ) );
1877 lst << qMakePair( QString(
"$atlasfeatureid" ), QString(
"Atlas" ) );
1878 lst << qMakePair( QString(
"$atlasgeometry" ), QString(
"Atlas" ) );
1879 lst << qMakePair( QString(
"$atlasfeature" ), QString(
"Atlas" ) );
1880 lst << qMakePair( QString(
"$map" ), QString(
"Composer" ) );
1882 QList< QPair<QString, QString> >::const_iterator it = lst.constBegin();
1883 for ( ; it != lst.constEnd(); ++it )
1907 QList<Function*> defs;
1919 return QString(
"\"%1\"" ).arg( name.replace(
"\"",
"\"\"" ) );
1924 text.replace(
"'",
"''" );
1925 text.replace(
'\\',
"\\\\" );
1926 text.replace(
'\n',
"\\n" );
1927 text.replace(
'\t',
"\\t" );
1928 return QString(
"'%1'" ).arg( text );
1939 for (
int i = 0; i < count; i++ )
1941 if ( QString::compare( name,
Functions()[i]->name(), Qt::CaseInsensitive ) == 0 )
1974 return QStringList();
1979 for (
int i = 0; i < columns.count(); i++ )
1981 QString col = columns.at( i );
1982 for (
int j = i + 1; j < columns.count(); j++ )
1984 if ( QString::compare( col, columns[j], Qt::CaseInsensitive ) == 0 )
1987 columns.removeAt( j-- );
2069 const QMap<QString, QVariant> *substitutionMap,
const QgsDistanceArea *distanceArea )
2071 QString expr_action;
2073 QMap<QString, QVariant> savedValues;
2074 if ( substitutionMap )
2077 for ( QMap<QString, QVariant>::const_iterator sit = substitutionMap->begin(); sit != substitutionMap->end(); ++sit )
2080 if ( !oldValue.isNull() )
2081 savedValues.insert( sit.key(), oldValue );
2089 while ( index < action.size() )
2091 QRegExp rx = QRegExp(
"\\[%([^\\]]+)%\\]" );
2093 int pos = rx.indexIn( action, index );
2098 index = pos + rx.matchedLength();
2099 QString to_replace = rx.cap( 1 ).trimmed();
2106 expr_action += action.mid( start, index - start );
2128 expr_action += action.mid( start, index - start );
2132 QgsDebugMsg(
"Expression result is: " + result.toString() );
2133 expr_action += action.mid( start, pos - start ) + result.toString();
2136 expr_action += action.mid( index );
2139 for ( QMap<QString, QVariant>::const_iterator sit = savedValues.begin(); sit != savedValues.end(); ++sit )
2151 double convertedValue = text.toDouble( &ok );
2154 return convertedValue;
2160 convertedValue = result.toDouble( &ok );
2163 return fallbackValue;
2165 return convertedValue;
2174 QString msg;
bool first =
true;
2177 if ( !first ) msg +=
", ";
else first =
false;
2188 QVariant val = mOperand->eval( parent, f );
2209 Q_ASSERT( 0 &&
"unknown unary operation" );
2216 return mOperand->prepare( parent, fields );
2221 return QString(
"%1 %2" ).arg(
UnaryOperatorText[mOp] ).arg( mOperand->dump() );
2228 QVariant vL = mOpLeft->eval( parent, f );
2230 QVariant vR = mOpRight->eval( parent, f );
2236 if ( vL.type() == QVariant::String && vR.type() == QVariant::String )
2240 return QVariant( sL + sR );
2256 if ( mOp ==
boMod && iR == 0 )
2259 return QVariant( computeInt( iL, iR ) );
2270 return QVariant( computeDateTimeFromInterval( dL, &iL ) );
2277 if (( mOp ==
boDiv || mOp ==
boMod ) && fR == 0. )
2279 return QVariant( computeDouble( fL, fR ) );
2289 return QVariant( qFloor( fL / fR ) );
2298 return QVariant( pow( fL, fR ) );
2337 int diff = QString::compare( sL, sR );
2360 equal = QString::compare( sL, sR ) == 0;
2383 QString esc_regexp = QRegExp::escape( regexp );
2385 esc_regexp.replace(
"%",
".*" );
2386 esc_regexp.replace(
"_",
"." );
2387 matches = QRegExp( esc_regexp, mOp ==
boLike || mOp ==
boNotLike ? Qt::CaseSensitive : Qt::CaseInsensitive ).exactMatch( str );
2391 matches = QRegExp( regexp ).indexIn( str ) != -1;
2409 return QVariant( sL + sR );
2422 case boEQ:
return diff == 0;
2423 case boNE:
return diff != 0;
2424 case boLT:
return diff < 0;
2425 case boGT:
return diff > 0;
2426 case boLE:
return diff <= 0;
2427 case boGE:
return diff >= 0;
2428 default: Q_ASSERT(
false );
return false;
2438 case boMul:
return x*y;
2439 case boDiv:
return x/y;
2440 case boMod:
return x%y;
2441 default: Q_ASSERT(
false );
return 0;
2451 default: Q_ASSERT(
false );
return QDateTime();
2461 case boMul:
return x*y;
2462 case boDiv:
return x/y;
2463 case boMod:
return fmod( x,y );
2464 default: Q_ASSERT(
false );
return 0;
2471 bool resL = mOpLeft->prepare( parent, fields );
2472 bool resR = mOpRight->prepare( parent, fields );
2473 return resL && resR;
2518 Q_ASSERT( 0 &&
"unexpected binary operator" );
2528 fmt += lOp && lOp->
precedence() < precedence() ?
"(%1)" :
"%1";
2530 fmt += rOp && rOp->
precedence() <= precedence() ?
"(%3)" :
"%3";
2532 return fmt.arg( mOpLeft->dump() ).arg(
BinaryOperatorText[mOp] ).arg( mOpRight->dump() );
2539 if ( mList->count() == 0 )
2541 QVariant v1 = mNode->eval( parent, f );
2546 bool listHasNull =
false;
2548 foreach (
Node* n, mList->list() )
2550 QVariant v2 = n->
eval( parent, f );
2568 equal = QString::compare( s1, s2 ) == 0;
2585 bool res = mNode->prepare( parent, fields );
2586 foreach (
Node* n, mList->list() )
2588 res = res && n->
prepare( parent, fields );
2595 return QString(
"%1 IN (%2)" ).arg( mNode->dump() ).arg( mList->dump() );
2605 QVariantList argValues;
2608 foreach (
Node* n, mArgs->list() )
2614 v = QVariant::fromValue( n );
2618 v = n->
eval( parent, f );
2620 if (
isNull( v ) && fd->
name() !=
"coalesce" )
2623 argValues.append( v );
2628 QVariant res = fd->
func( argValues, f, parent );
2640 foreach (
Node* n, mArgs->list() )
2642 res = res && n->
prepare( parent, fields );
2654 return QString(
"%1(%2)" ).arg( fd->
name() ).arg( mArgs ? mArgs->dump() : QString() );
2665 return functionColumns;
2668 foreach (
Node* n, mArgs->list() )
2674 return functionColumns.toSet().toList();
2692 if ( mValue.isNull() )
2695 switch ( mValue.type() )
2697 case QVariant::Int:
return QString::number( mValue.toInt() );
2698 case QVariant::Double:
return QString::number( mValue.toDouble() );
2699 case QVariant::String:
return quotedString( mValue.toString() );
2700 default:
return QObject::tr(
"[unsupported type;%1; value:%2]" ).arg( mValue.typeName() ).arg( mValue.toString() );
2715 return QVariant(
"[" + mName +
"]" );
2720 for (
int i = 0; i < fields.
count(); ++i )
2722 if ( QString::compare( fields[i].name(), mName, Qt::CaseInsensitive ) == 0 )
2735 return QRegExp(
"^[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*$" ).exactMatch( mName ) ? mName :
quotedColumnRef( mName );
2742 foreach (
WhenThen* cond, mConditions )
2757 QVariant vElse = mElseExp->eval( parent, f );
2769 foreach (
WhenThen* cond, mConditions )
2773 if ( !res )
return false;
2777 return mElseExp->prepare( parent, fields );
2784 QString msg = QString(
"CASE" );
2785 foreach (
WhenThen* cond, mConditions )
2790 msg += QString(
" ELSE %1" ).arg( mElseExp->dump() );
2791 msg += QString(
" END" );
2798 foreach (
WhenThen* cond, mConditions )
2804 lst += mElseExp->referencedColumns();
2811 foreach (
WhenThen* cond, mConditions )
2818 if ( mElseExp && mElseExp->needsGeometry() )
2851 return gGroups.value( name, name );