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::Double )
return false;
165 if ( v.type() == QVariant::String ) {
bool ok; v.toString().toInt( &ok );
return ok; }
170 if ( v.type() == QVariant::Double || v.type() == QVariant::Int )
return true;
171 if ( v.type() == QVariant::String ) {
bool ok; v.toString().toDouble( &ok );
return ok; }
177 return v.type() == QVariant::DateTime || v.type() == QVariant::Date ||
178 v.type() == QVariant::Time;
188 if ( v.type() == QVariant::String )
195 inline bool isNull(
const QVariant& v ) {
return v.isNull(); }
200 #define ENSURE_NO_EVAL_ERROR { if (parent->hasEvalError()) return QVariant(); }
201 #define SET_EVAL_ERROR(x) { parent->setEvalErrorString(x); return QVariant(); }
209 "=",
"<>",
"<=",
">=",
"<",
">",
"~",
"LIKE",
"NOT LIKE",
"ILIKE",
"NOT ILIKE",
"IS",
"IS NOT",
210 "+",
"-",
"*",
"/",
"%",
"^",
225 return value.toString();
231 double x = value.toDouble( &ok );
243 qint64 x = value.toLongLong( &ok );
257 QDateTime d = value.toDateTime();
271 QDate d = value.toDate();
285 QTime t = value.toTime();
303 if ( inter.isValid() )
327 if ( value.isNull() )
330 if ( value.type() == QVariant::Int )
331 return value.toInt() != 0 ?
True :
False;
334 double x = value.toDouble( &ok );
348 return QVariant( sqrt( x ) );
354 return QVariant( fabs( val ) );
360 return QVariant( sin( x ) );
365 return QVariant( cos( x ) );
370 return QVariant( tan( x ) );
375 return QVariant( asin( x ) );
380 return QVariant( acos( x ) );
385 return QVariant( atan( x ) );
391 return QVariant( atan2( y, x ) );
396 return QVariant( exp( x ) );
403 return QVariant( log( x ) );
410 return QVariant( log10( x ) );
416 if ( x <= 0 || b <= 0 )
418 return QVariant( log( x ) / log( b ) );
428 double f = ( double )rand() / RAND_MAX;
429 return QVariant( min + f * ( max - min ) ) ;
439 return QVariant( min + ( rand() % (
int )( max - min + 1 ) ) );
450 if ( domainMin >= domainMax )
457 if ( val >= domainMax )
461 else if ( val <= domainMin )
467 double m = ( rangeMax - rangeMin ) / ( domainMax - domainMin );
468 double c = rangeMin - ( domainMin * m );
471 return QVariant( m * val + c );
483 if ( domainMin >= domainMax )
495 if ( val >= domainMax )
499 else if ( val <= domainMin )
505 return QVariant((( rangeMax - rangeMin ) / pow( domainMax - domainMin, exponent ) ) * pow( val - domainMin, exponent ) + rangeMin );
514 for (
int i = 1; i < values.length(); ++i )
517 if ( testVal > maxVal )
523 return QVariant( maxVal );
532 for (
int i = 1; i < values.length(); ++i )
535 if ( testVal < minVal )
541 return QVariant( minVal );
551 if ( testValue <= minValue )
553 return QVariant( minValue );
555 else if ( testValue >= maxValue )
557 return QVariant( maxValue );
561 return QVariant( testValue );
568 return QVariant( floor( x ) );
574 return QVariant( ceil( x ) );
579 return QVariant(
getIntValue( values.at( 0 ), parent ) );
597 foreach (
const QVariant &value, values )
599 if ( value.isNull() )
608 return QVariant( str.toLower() );
613 return QVariant( str.toUpper() );
618 QStringList elems = str.split(
" " );
619 for (
int i = 0; i < elems.size(); i++ )
621 if ( elems[i].
size() > 1 )
622 elems[i] = elems[i].left( 1 ).toUpper() + elems[i].mid( 1 ).toLower();
624 return QVariant( elems.join(
" " ) );
630 return QVariant( str.trimmed() );
635 if ( values.length() == 2 || values.length() == 3 )
640 if ( !str.isEmpty() && wrap != 0 )
643 QString delimiterstr;
644 if ( values.length() == 3 ) delimiterstr =
getStringValue( values.at( 2 ), parent );
645 if ( delimiterstr.isEmpty() ) delimiterstr =
" ";
646 int delimiterlength = delimiterstr.length();
648 QStringList lines = str.split(
"\n" );
649 int strlength, strcurrent, strhit, lasthit;
651 for (
int i = 0; i < lines.size(); i++ )
653 strlength = lines[i].length();
658 while ( strcurrent < strlength )
665 strhit = lines[i].lastIndexOf( delimiterstr, strcurrent + wrap );
666 if ( strhit == lasthit || strhit == -1 )
669 strhit = lines[i].indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
675 strhit = lines[i].indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
679 newstr.append( lines[i].midRef( strcurrent , strhit - strcurrent ) );
680 newstr.append(
"\n" );
681 strcurrent = strhit + delimiterlength;
685 newstr.append( lines[i].midRef( strcurrent ) );
686 strcurrent = strlength;
689 if ( i < lines.size() - 1 ) newstr.append(
"\n" );
692 return QVariant( newstr );
702 return QVariant( str.length() );
709 return QVariant( str.replace( before, after ) );
717 QRegExp re( regexp );
723 return QVariant( str.replace( re, after ) );
731 QRegExp re( regexp );
737 return QVariant( str.contains( re ) ? 1 : 0 );
745 QRegExp re( regexp );
754 if ( re.captureCount() > 0 )
757 return QVariant( re.capturedTexts()[1] );
761 return QVariant(
"" );
767 return QUuid::createUuid().toString();
775 return QVariant( str.mid( from -1, len ) );
786 return f ? QVariant((
int )f->
id() ) : QVariant();
792 foreach (
const QVariant &value, values )
802 return string.indexOf( QRegExp(
getStringValue( values.at( 1 ), parent ) ) );
809 return string.right( pos );
816 return string.left( pos );
822 int length =
getIntValue( values.at( 1 ), parent );
824 return string.leftJustified( length, fill.at( 0 ), true );
830 int length =
getIntValue( values.at( 1 ), parent );
832 return string.rightJustified( length, fill.at( 0 ), true );
838 for (
int n = 1; n < values.length(); n++ )
848 return QVariant( QDateTime::currentDateTime() );
853 return QVariant(
getDateValue( values.at( 0 ), parent ) );
858 return QVariant(
getTimeValue( values.at( 0 ), parent ) );
863 return QVariant::fromValue(
getInterval( values.at( 0 ), parent ) );
870 int seconds = d2.secsTo( d1 );
876 QVariant value = values.at( 0 );
880 return QVariant( inter.
days() );
885 return QVariant( d1.date().day() );
891 QVariant value = values.at( 0 );
895 return QVariant( inter.
years() );
900 return QVariant( d1.date().year() );
906 QVariant value = values.at( 0 );
910 return QVariant( inter.
months() );
915 return QVariant( d1.date().month() );
921 QVariant value = values.at( 0 );
925 return QVariant( inter.
weeks() );
930 return QVariant( d1.date().weekNumber() );
936 QVariant value = values.at( 0 );
940 return QVariant( inter.
hours() );
945 return QVariant( d1.time().hour() );
951 QVariant value = values.at( 0 );
955 return QVariant( inter.
minutes() );
960 return QVariant( d1.time().minute() );
966 QVariant value = values.at( 0 );
970 return QVariant( inter.
seconds() );
975 return QVariant( d1.time().second() );
980 #define ENSURE_GEOM_TYPE(f, g, geomtype) if (!f) return QVariant(); \
981 QgsGeometry* g = f->geometry(); \
982 if (!g || g->type() != geomtype) return QVariant();
988 if ( g->isMultipart() )
990 return g->asMultiPoint()[ 0 ].x();
994 return g->asPoint().x();
1000 if ( g->isMultipart() )
1002 return g->asMultiPoint()[ 0 ].y();
1006 return g->asPoint().y();
1016 idx += polyline.count();
1018 if ( idx < 0 || idx >= polyline.count() )
1023 return QVariant( QPointF( polyline[idx].x(), polyline[idx].y() ) );
1028 QVariant v =
pointAt( values, f, parent );
1029 if ( v.type() == QVariant::PointF )
1030 return QVariant( v.toPointF().x() );
1036 QVariant v =
pointAt( values, f, parent );
1037 if ( v.type() == QVariant::PointF )
1038 return QVariant( v.toPointF().y() );
1046 return QVariant::fromValue( *geom );
1055 return QVariant::fromValue( *geom );
1065 return QVariant::fromValue( *geom );
1095 return QVariant::fromValue( *geomBounds );
1189 if ( values.length() < 2 || values.length() > 3 )
1195 if ( values.length() == 3 )
1200 return QVariant::fromValue( *geom );
1208 return QVariant::fromValue( *geom );
1216 return QVariant::fromValue( *geom );
1225 return QVariant::fromValue( *geom );
1232 return QVariant( fGeom.
distance( sGeom ) );
1240 return QVariant::fromValue( *geom );
1249 return QVariant::fromValue( *geom );
1258 return QVariant::fromValue( *geom );
1265 return QVariant( wkt );
1271 if ( values.length() == 2 )
1274 double scaler = pow( 10.0,
getIntValue( values.at( 1 ), parent ) );
1275 return QVariant( qRound( number * scaler ) / scaler );
1278 if ( values.length() == 1 )
1280 double number =
getIntValue( values.at( 0 ), parent );
1281 return QVariant( qRound( number ) ).toInt();
1297 return QVariant( parent->
scale() );
1303 int places =
getIntValue( values.at( 1 ), parent );
1304 return QString(
"%L1" ).arg( value, 0,
'f', places );
1311 return dt.toString( format );
1317 int green =
getIntValue( values.at( 1 ), parent );
1319 QColor color = QColor( red, green, blue );
1320 if ( ! color.isValid() )
1323 color = QColor( 0, 0, 0 );
1326 return QString(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
1332 int green =
getIntValue( values.at( 1 ), parent );
1334 int alpha =
getIntValue( values.at( 3 ), parent );
1335 QColor color = QColor( red, green, blue, alpha );
1336 if ( ! color.isValid() )
1339 color = QColor( 0, 0, 0 );
1351 return QColor( 0, 0, 0 ).name();
1354 QColor color = mRamp->color( value );
1361 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1363 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1365 double lightness =
getIntValue( values.at( 2 ), parent ) / 100.0;
1367 QColor color = QColor::fromHslF( hue, saturation, lightness );
1369 if ( ! color.isValid() )
1372 color = QColor( 0, 0, 0 );
1375 return QString(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
1381 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1383 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1385 double lightness =
getIntValue( values.at( 2 ), parent ) / 100.0;
1387 double alpha =
getIntValue( values.at( 3 ), parent ) / 255.0;
1389 QColor color = QColor::fromHslF( hue, saturation, lightness, alpha );
1390 if ( ! color.isValid() )
1392 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( lightness ).arg( alpha ) );
1393 color = QColor( 0, 0, 0 );
1401 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1403 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1405 double value =
getIntValue( values.at( 2 ), parent ) / 100.0;
1407 QColor color = QColor::fromHsvF( hue, saturation, value );
1409 if ( ! color.isValid() )
1412 color = QColor( 0, 0, 0 );
1415 return QString(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
1421 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1423 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1425 double value =
getIntValue( values.at( 2 ), parent ) / 100.0;
1427 double alpha =
getIntValue( values.at( 3 ), parent ) / 255.0;
1429 QColor color = QColor::fromHsvF( hue, saturation, value, alpha );
1430 if ( ! color.isValid() )
1432 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( value ).arg( alpha ) );
1433 color = QColor( 0, 0, 0 );
1441 double cyan =
getIntValue( values.at( 0 ), parent ) / 100.0;
1443 double magenta =
getIntValue( values.at( 1 ), parent ) / 100.0;
1445 double yellow =
getIntValue( values.at( 2 ), parent ) / 100.0;
1447 double black =
getIntValue( values.at( 3 ), parent ) / 100.0;
1449 QColor color = QColor::fromCmykF( cyan, magenta, yellow, black );
1451 if ( ! color.isValid() )
1454 color = QColor( 0, 0, 0 );
1457 return QString(
"%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );
1463 double cyan =
getIntValue( values.at( 0 ), parent ) / 100.0;
1465 double magenta =
getIntValue( values.at( 1 ), parent ) / 100.0;
1467 double yellow =
getIntValue( values.at( 2 ), parent ) / 100.0;
1469 double black =
getIntValue( values.at( 3 ), parent ) / 100.0;
1471 double alpha =
getIntValue( values.at( 4 ), parent ) / 255.0;
1473 QColor color = QColor::fromCmykF( cyan, magenta, yellow, black, alpha );
1474 if ( ! color.isValid() )
1476 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4:%5' to color" ).arg( cyan ).arg( magenta ).arg( yellow ).arg( black ).arg( alpha ) );
1477 color = QColor( 0, 0, 0 );
1524 <<
"abs" <<
"sqrt" <<
"cos" <<
"sin" <<
"tan"
1525 <<
"asin" <<
"acos" <<
"atan" <<
"atan2"
1526 <<
"exp" <<
"ln" <<
"log10" <<
"log"
1527 <<
"round" <<
"rand" <<
"randf" <<
"max" <<
"min" <<
"clamp"
1528 <<
"scale_linear" <<
"scale_exp" <<
"floor" <<
"ceil"
1529 <<
"toint" <<
"toreal" <<
"tostring"
1530 <<
"todatetime" <<
"todate" <<
"totime" <<
"tointerval"
1531 <<
"coalesce" <<
"regexp_match" <<
"$now" <<
"age" <<
"year"
1532 <<
"month" <<
"week" <<
"day" <<
"hour"
1533 <<
"minute" <<
"second" <<
"lower" <<
"upper"
1534 <<
"title" <<
"length" <<
"replace" <<
"trim" <<
"wordwrap"
1535 <<
"regexp_replace" <<
"regexp_substr"
1536 <<
"substr" <<
"concat" <<
"strpos" <<
"left"
1537 <<
"right" <<
"rpad" <<
"lpad"
1538 <<
"format_number" <<
"format_date"
1539 <<
"color_rgb" <<
"color_rgba" <<
"ramp_color"
1540 <<
"color_hsl" <<
"color_hsla" <<
"color_hsv" <<
"color_hsva"
1541 <<
"color_cymk" <<
"color_cymka"
1542 <<
"xat" <<
"yat" <<
"$area"
1543 <<
"$length" <<
"$perimeter" <<
"$x" <<
"$y"
1544 <<
"$rownum" <<
"$id" <<
"$scale" <<
"_specialcol_";
1711 static bool initialized =
false;
1719 lst <<
"$page" <<
"$feature" <<
"$numpages" <<
"$numfeatures" <<
"$atlasfeatureid" <<
"$atlasgeometry" <<
"$map";
1720 foreach ( QString c, lst )
1741 QList<Function*> defs;
1751 return QString(
"\"%1\"" ).arg( name.replace(
"\"",
"\"\"" ) );
1756 text.replace(
"'",
"''" );
1757 text.replace(
'\\',
"\\\\" );
1758 text.replace(
'\n',
"\\n" );
1759 text.replace(
'\t',
"\\t" );
1760 return QString(
"'%1'" ).arg( text );
1771 for (
int i = 0; i < count; i++ )
1773 if ( QString::compare( name,
Functions()[i]->name(), Qt::CaseInsensitive ) == 0 )
1806 return QStringList();
1810 for (
int i = 0; i < columns.count(); i++ )
1812 QString col = columns.at( i );
1813 for (
int j = i + 1; j < columns.count(); j++ )
1815 if ( QString::compare( col, columns[j], Qt::CaseInsensitive ) == 0 )
1818 columns.removeAt( j-- );
1900 const QMap<QString, QVariant> *substitutionMap )
1902 QString expr_action;
1904 QMap<QString, QVariant> savedValues;
1905 if ( substitutionMap )
1908 for ( QMap<QString, QVariant>::const_iterator sit = substitutionMap->begin(); sit != substitutionMap->end(); ++sit )
1911 if ( !oldValue.isNull() )
1912 savedValues.insert( sit.key(), oldValue );
1920 while ( index < action.size() )
1922 QRegExp rx = QRegExp(
"\\[%([^\\]]+)%\\]" );
1924 int pos = rx.indexIn( action, index );
1929 index = pos + rx.matchedLength();
1930 QString to_replace = rx.cap( 1 ).trimmed();
1937 expr_action += action.mid( start, index - start );
1953 expr_action += action.mid( start, index - start );
1957 QgsDebugMsg(
"Expression result is: " + result.toString() );
1958 expr_action += action.mid( start, pos - start ) + result.toString();
1961 expr_action += action.mid( index );
1964 for ( QMap<QString, QVariant>::const_iterator sit = savedValues.begin(); sit != savedValues.end(); ++sit )
1978 QString msg;
bool first =
true;
1981 if ( !first ) msg +=
", ";
else first =
false;
1992 QVariant val = mOperand->eval( parent, f );
2013 Q_ASSERT( 0 &&
"unknown unary operation" );
2020 return mOperand->prepare( parent, fields );
2025 return QString(
"%1 %2" ).arg(
UnaryOperatorText[mOp] ).arg( mOperand->dump() );
2032 QVariant vL = mOpLeft->eval( parent, f );
2034 QVariant vR = mOpRight->eval( parent, f );
2051 if ( mOp ==
boDiv && iR == 0 )
return QVariant();
2052 return QVariant( computeInt( iL, iR ) );
2063 return QVariant( computeDateTimeFromInterval( dL, &iL ) );
2070 if ( mOp ==
boDiv && fR == 0 )
2072 return QVariant( computeDouble( fL, fR ) );
2082 return QVariant( pow( fL, fR ) );
2121 int diff = QString::compare( sL, sR );
2144 equal = QString::compare( sL, sR ) == 0;
2167 QString esc_regexp = QRegExp::escape( regexp );
2169 esc_regexp.replace(
"%",
".*" );
2170 esc_regexp.replace(
"_",
"." );
2171 matches = QRegExp( esc_regexp, mOp ==
boLike || mOp ==
boNotLike ? Qt::CaseSensitive : Qt::CaseInsensitive ).exactMatch( str );
2175 matches = QRegExp( regexp ).indexIn( str ) != -1;
2193 return QVariant( sL + sR );
2206 case boEQ:
return diff == 0;
2207 case boNE:
return diff != 0;
2208 case boLT:
return diff < 0;
2209 case boGT:
return diff > 0;
2210 case boLE:
return diff <= 0;
2211 case boGE:
return diff >= 0;
2212 default: Q_ASSERT(
false );
return false;
2222 case boMul:
return x*y;
2223 case boDiv:
return x/y;
2224 case boMod:
return x%y;
2225 default: Q_ASSERT(
false );
return 0;
2235 default: Q_ASSERT(
false );
return QDateTime();
2245 case boMul:
return x*y;
2246 case boDiv:
return x/y;
2247 case boMod:
return fmod( x,y );
2248 default: Q_ASSERT(
false );
return 0;
2255 bool resL = mOpLeft->prepare( parent, fields );
2256 bool resR = mOpRight->prepare( parent, fields );
2257 return resL && resR;
2301 Q_ASSERT( 0 &&
"unexpected binary operator" );
2311 fmt += lOp && lOp->
precedence() < precedence() ?
"(%1)" :
"%1";
2313 fmt += rOp && rOp->
precedence() < precedence() ?
"(%3)" :
"%3";
2315 return fmt.arg( mOpLeft->dump() ).arg(
BinaryOperatorText[mOp] ).arg( mOpRight->dump() );
2322 if ( mList->count() == 0 )
2324 QVariant v1 = mNode->eval( parent, f );
2329 bool listHasNull =
false;
2331 foreach (
Node* n, mList->list() )
2333 QVariant v2 = n->
eval( parent, f );
2351 equal = QString::compare( s1, s2 ) == 0;
2368 bool res = mNode->prepare( parent, fields );
2369 foreach (
Node* n, mList->list() )
2371 res = res && n->
prepare( parent, fields );
2378 return QString(
"%1 IN (%2)" ).arg( mNode->dump() ).arg( mList->dump() );
2388 QVariantList argValues;
2391 foreach (
Node* n, mArgs->list() )
2393 QVariant v = n->
eval( parent, f );
2395 if (
isNull( v ) && fd->
name() !=
"coalesce" )
2397 argValues.append( v );
2402 QVariant res = fd->
func( argValues, f, parent );
2414 foreach (
Node* n, mArgs->list() )
2416 res = res && n->
prepare( parent, fields );
2428 return QString(
"%1(%2)" ).arg( fd->
name() ).arg( mArgs ? mArgs->dump() : QString() );
2446 if ( mValue.isNull() )
2449 switch ( mValue.type() )
2451 case QVariant::Int:
return QString::number( mValue.toInt() );
2452 case QVariant::Double:
return QString::number( mValue.toDouble() );
2453 case QVariant::String:
return quotedString( mValue.toString() );
2454 default:
return QObject::tr(
"[unsupported type;%1; value:%2]" ).arg( mValue.typeName() ).arg( mValue.toString() );
2469 return QVariant(
"[" + mName +
"]" );
2474 for (
int i = 0; i < fields.
count(); ++i )
2476 if ( QString::compare( fields[i].name(), mName, Qt::CaseInsensitive ) == 0 )
2489 return QRegExp(
"^[A-Za-z_\x80-\xff][A-Za-z0-9_\x80-\xff]*$" ).exactMatch( mName ) ? mName :
quotedColumnRef( mName );
2496 foreach (
WhenThen* cond, mConditions )
2511 QVariant vElse = mElseExp->eval( parent, f );
2523 foreach (
WhenThen* cond, mConditions )
2527 if ( !res )
return false;
2531 return mElseExp->prepare( parent, fields );
2538 QString msg = QString(
"CASE" );
2539 foreach (
WhenThen* cond, mConditions )
2544 msg += QString(
" ELSE %1" ).arg( mElseExp->dump() );
2545 msg += QString(
" END" );
2552 foreach (
WhenThen* cond, mConditions )
2558 lst += mElseExp->referencedColumns();
2565 foreach (
WhenThen* cond, mConditions )
2572 if ( mElseExp && mElseExp->needsGeometry() )
2605 return gGroups.value( name, name );
QgsFeatureId id() const
Get the feature id for this feature.
static QVariant fcnDifference(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnCombine(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
Class for parsing and evaluation of expressions (formerly called "search strings").
static int functionIndex(QString name)
static QVariant fcnAge(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnColorHsv(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QStringList referencedColumns() const =0
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
virtual bool prepare(QgsExpression *parent, const QgsFields &fields)
static QVariant fcnCeil(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual bool prepare(QgsExpression *parent, const QgsFields &fields)
static QVariant fcnLog10(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnDistance(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QgsExpression::Interval fromString(QString string)
virtual bool needsGeometry() const
static QVariant fcnFeatureId(const QVariantList &, const QgsFeature *f, QgsExpression *)
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
static QVariant fcnAsin(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnMin(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnTrim(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnLeft(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static bool unregisterFunction(QString name)
static QString quotedColumnRef(QString name)
return quoted column reference (in double quotes)
static QVariant fcnLog(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnYat(const QVariantList &values, const QgsFeature *f, QgsExpression *parent)
static QVariant fcnMinute(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnRight(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QgsGeometry * combine(QgsGeometry *geometry)
Returns a geometry representing all the points in this geometry and other (a union geometry operation...
static QVariant fcnYMax(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnReplace(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
void initGeomCalculator()
static QVariant fcnTouches(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool compare(double diff)
A abstract base class for defining QgsExpression functions.
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
double yMaximum() const
Get the y maximum value (top side of rectangle)
static QVariant fcnGeomLength(const QVariantList &, const QgsFeature *f, QgsExpression *parent)
static QVariant fcnScale(const QVariantList &, const QgsFeature *, QgsExpression *parent)
double computeDouble(double x, double y)
virtual QString dump() const =0
static QDate getDateValue(const QVariant &value, QgsExpression *parent)
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
static QVariant fcnFloor(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QString helptext(QString name)
static QVariant fcnXMin(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
static QVariant fcnFormatDate(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnToTime(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnSqrt(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnIntersects(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnNow(const QVariantList &, const QgsFeature *, QgsExpression *)
QVariant fcnRampColor(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool crosses(const QgsGeometry *geometry) const
Test for if geometry crosses another (uses GEOS)
Container of fields for a vector layer.
static QVariant fcnSin(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnContains(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnToInt(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual bool prepare(QgsExpression *parent, const QgsFields &fields)=0
QgsExpression::Node * parseExpression(const QString &str, QString &parserErrorMsg)
static QVariant fcnToDateTime(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QString group(QString group)
static QTime getTimeValue(const QVariant &value, QgsExpression *parent)
QString dump() const
Return the expression string that represents this QgsExpression.
bool isDoubleSafe(const QVariant &v)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
static QVariant fcnStrpos(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnYMin(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static TVL getTVLValue(const QVariant &value, QgsExpression *parent)
int currentRowNumber()
Return the number used for $rownum special column.
virtual bool prepare(QgsExpression *parent, const QgsFields &fields)
static QVariant fcnBuffer(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static bool isValid(const QString &text, const QgsFields &fields, QString &errorMessage)
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f)
QgsGeometry * difference(QgsGeometry *geometry)
Returns a geometry representing the points making up this geometry that do not make up other...
static QVariant fcnYear(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual bool prepare(QgsExpression *parent, const QgsFields &fields)
static QVariant fcnFormatString(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
int computeInt(int x, int y)
static QVariant fcnToString(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnCrosses(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnToInterval(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QgsGeometry * centroid()
Returns the center of mass of a geometry.
static QVariant fcnTan(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QgsGeometry getGeometry(const QVariant &value, QgsExpression *parent)
#define ENSURE_NO_EVAL_ERROR
QString mParserErrorString
static QVariant fcnLower(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QString encodeColor(QColor color)
static QVariant fcnAbs(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnCos(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnCoalesce(const QVariantList &values, const QgsFeature *, QgsExpression *)
static QVariant fcnCentroid(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static const QStringList & BuiltinFunctions()
virtual bool prepare(QgsExpression *parent, const QgsFields &fields)
double ANALYSIS_EXPORT max(double x, double y)
returns the maximum of two doubles or the first argument if both are equal
static const QList< Function * > & Functions()
static QVariant fcnToReal(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static bool isFunctionName(QString name)
static QVariant fcnIntersection(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QHash< QString, QString > gFunctionHelpTexts
static int functionCount()
Returns the number of functions defined in the parser.
virtual bool prepare(QgsExpression *parent, const QgsFields &fields)
void acceptVisitor(Visitor &v) const
entry function for the visitor pattern
bool contains(const QgsPoint *p) const
Test for containment of a point (uses GEOS)
static QVariant fcnLPad(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant pointAt(const QVariantList &values, const QgsFeature *f, QgsExpression *parent)
QgsDistanceArea * geomCalculator()
Return calculator used for distance and area calculations (used by internal functions) ...
QString exportToWkt() const
Exports the geometry to mWkt.
static QVariant fcnOverlaps(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnHour(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
const QgsVectorColorRampV2 * colorRampRef(QString name) const
return a const pointer to a symbol (doesn't create new instance)
QgsGeometry * buffer(double distance, int segments)
Returns a buffer region around this geometry having the given width and with a specified number of se...
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
double measurePerimeter(QgsGeometry *geometry)
measures perimeter of polygon
double measure(QgsGeometry *geometry)
general measurement (line distance or polygon area)
static bool registerFunction(Function *function)
static QVariant fcnAtan2(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QgsGeometry * convexHull()
Returns the smallest convex polygon that contains all the points in the geometry. ...
static QVariant fncColorHsla(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QgsGeometry * geometryFromGML(const QString &xmlString)
static method that creates geometry from GML
#define SET_EVAL_ERROR(x)
bool overlaps(const QgsGeometry *geometry) const
Test for if geometry overlaps another (uses GEOS)
static QHash< QString, QString > gGroups
static QgsStyleV2 * defaultStyle()
return default application-wide style
virtual QVariant func(const QVariantList &values, const QgsFeature *f, QgsExpression *parent)=0
bool operator==(const QgsExpression::Interval &other) const
static bool hasSpecialColumn(const QString &name)
Check whether a special column exists.
static QVariant fcnGeomPerimeter(const QVariantList &, const QgsFeature *f, QgsExpression *parent)
QStringList referencedColumns()
Get list of columns referenced by the expression.
static QVariant fcnY(const QVariantList &, const QgsFeature *f, QgsExpression *)
static QVariant fcnRndF(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QString dump() const
virtual QString dump() const
QDateTime computeDateTimeFromInterval(QDateTime d, QgsExpression::Interval *i)
int count() const
Return number of items.
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f)
static QVariant fcnGeomToWKT(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnSpecialColumn(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f)
static QList< Function * > gmFunctions
static QVariant fcnWordwrap(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QString dump() const
static QVariant fcnLength(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QString name()
The name of the function.
virtual QString dump() const
static QVariant tvl2variant(TVL v)
#define ENSURE_GEOM_TYPE(f, g, geomtype)
static QVariant fcnMonth(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnTitle(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f)
bool isIntervalSafe(const QVariant &v)
QgsGeometry * intersection(QgsGeometry *geometry)
Returns a geometry representing the points shared by this geometry and other.
virtual QString dump() const
static QVariant fcnRPad(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f)
static int getIntValue(const QVariant &value, QgsExpression *parent)
static QVariant fcnToDate(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fncColorRgba(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnBbox(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnBoundsWidth(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnGeomArea(const QVariantList &, const QgsFeature *f, QgsExpression *parent)
static QVariant fcnAcos(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual bool prepare(QgsExpression *parent, const QgsFields &fields)
bool needsGeometry()
Returns true if the expression uses feature geometry for some computation.
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f)=0
static QString getStringValue(const QVariant &value, QgsExpression *)
static QVariant fcnWithin(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnGeometry(const QVariantList &, const QgsFeature *f, QgsExpression *)
void setEvalErrorString(QString str)
Set evaluation error (used internally by evaluation functions)
static double getDoubleValue(const QVariant &value, QgsExpression *parent)
virtual QStringList referencedColumns() const
QgsGeometry * symDifference(QgsGeometry *geometry)
Returns a Geometry representing the points making up this Geometry that do not make up other...
static QVariant fcnGeomFromGML(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
General purpose distance and area calculator.
QgsRectangle boundingBox()
Returns the bounding box of this feature.
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f)
static QVariant fcnBounds(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnWeek(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnRegexpReplace(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool isIntSafe(const QVariant &v)
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
static QVariant fcnConcat(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool isDateTimeSafe(const QVariant &v)
static const char * UnaryOperatorText[]
static QgsExpression::Interval invalidInterVal()
static QVariant fcnXat(const QVariantList &values, const QgsFeature *f, QgsExpression *parent)
static QVariant fcnUpper(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnLinearScale(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QString dump() const
static QVariant fncColorHsva(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QList< Function * > specialColumns()
Returns a list of special Column definitions.
static QVariant fcnDay(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
int params()
The number of parameters this function takes.
static QVariant fcnX(const QVariantList &, const QgsFeature *f, QgsExpression *)
static QVariant fcnClamp(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool within(const QgsGeometry *geometry) const
Test for if geometry is within another (uses GEOS)
static QVariant fcnRegexpMatch(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnSubstr(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnFormatNumber(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnXMax(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
support for visitor pattern - algorithms dealing with the expressions may be implemented without modi...
static QString quotedString(QString text)
return quoted string (in single quotes)
static QgsGeometry * fromRect(const QgsRectangle &rect)
construct geometry from a rectangle
static QVariant fcnExpScale(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnPi(const QVariantList &values, const QgsFeature *f, QgsExpression *parent)
virtual bool needsGeometry() const =0
static QVariant fcnSeconds(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QgsGeometry * fromWkt(QString wkt)
static method that creates geometry from Wkt
void setGeomCalculator(const QgsDistanceArea &calc)
Sets the geometry calculator used in evaluation of expressions,.
static QStringList gmBuiltinFunctions
static QVariant fcnColorHsl(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool disjoint(const QgsGeometry *geometry) const
Test for if geometry is disjoint of another (uses GEOS)
static QVariant fncColorCmyka(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnUuid(const QVariantList &, const QgsFeature *, QgsExpression *)
bool touches(const QgsGeometry *geometry) const
Test for if geometry touch another (uses GEOS)
static QVariant fcnMax(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant specialColumn(const QString &name)
Return the value of the given special column or a null QVariant if undefined.
static QVariant fcnRowNumber(const QVariantList &, const QgsFeature *, QgsExpression *parent)
static void initFunctionHelp()
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
static QVariant fcnConvexHull(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnRnd(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnColorRgb(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QString dump() const
void setValid(bool valid)
static void setSpecialColumn(const QString &name, QVariant value)
Assign a special column.
double ANALYSIS_EXPORT min(double x, double y)
returns the minimum of two doubles or the first argument if both are equal
static QVariant fcnGeomFromWKT(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnColorCmyk(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f)
static QVariant fcnExp(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnAtan(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
double width() const
Width of the rectangle.
bool intersects(const QgsRectangle &r) const
Test for intersection with a rectangle (uses GEOS)
Represents a vector layer which manages a vector based data sets.
static QVariant fcnBoundsHeight(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QString parserErrorString() const
Returns parser error.
double xMinimum() const
Get the x minimum value (left side of rectangle)
QString evalErrorString() const
Returns evaluation error.
virtual void accept(Visitor &v) const =0
virtual QString dump() const
static QVariant fcnSymDifference(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool isNull(const QVariant &v)
static QVariant fcnLn(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnRegexpSubstr(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=0)
This function currently replaces each expression between [% and %] in the string with the result of i...
static QVariant fcnDisjoint(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
double height() const
Height of the rectangle.
static QgsExpression::Interval getInterval(const QVariant &value, QgsExpression *parent, bool report_error=false)
static QDateTime getDateTimeValue(const QVariant &value, QgsExpression *parent)
static QVariant fcnRound(const QVariantList &values, const QgsFeature *f, QgsExpression *parent)
double distance(QgsGeometry &geom)
static void unsetSpecialColumn(const QString &name)
Unset a special column.
static const char * BinaryOperatorText[]
static QMap< QString, QVariant > gmSpecialColumns