19 #include <QDomDocument>
54 QRegExp rx(
"([-+]?\\d?\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
58 while (( pos = rx.
indexIn(
string, pos ) ) != -1 )
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(
"|" ) );
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 )
182 ok = ok && qIsFinite( val ) && !qIsNaN( val );
190 return v.
type() == QVariant::DateTime || v.
type() == QVariant::Date ||
191 v.
type() == QVariant::Time;
201 if ( v.
type() == QVariant::String )
213 #define ENSURE_NO_EVAL_ERROR { if (parent->hasEvalError()) return QVariant(); }
214 #define SET_EVAL_ERROR(x) { parent->setEvalErrorString(x); return QVariant(); }
223 "=",
"<>",
"<=",
">=",
"<",
">",
"~",
"LIKE",
"NOT LIKE",
"ILIKE",
"NOT ILIKE",
"IS",
"IS NOT",
224 "+",
"-",
"*",
"/",
"//",
"%",
"^",
247 if ( !ok || qIsNaN( x ) || !qIsFinite( x ) )
318 if ( inter.isValid() )
363 if ( value.
type() == QVariant::Int )
449 if ( x <= 0 || b <= 0 )
451 return QVariant( log( x ) / log( b ) );
461 double f = ( double )qrand() / RAND_MAX;
462 return QVariant( min + f * ( max - min ) );
472 return QVariant( min + ( qrand() % (
int )( max - min + 1 ) ) );
483 if ( domainMin >= domainMax )
490 if ( val >= domainMax )
494 else if ( val <= domainMin )
500 double m = ( rangeMax - rangeMin ) / ( domainMax - domainMin );
501 double c = rangeMin - ( domainMin * m );
516 if ( domainMin >= domainMax )
528 if ( val >= domainMax )
532 else if ( val <= domainMin )
538 return QVariant((( rangeMax - rangeMin ) / pow( domainMax - domainMin, exponent ) ) * pow( val - domainMin, exponent ) + rangeMin );
547 for (
int i = 1; i < values.length(); ++i )
550 if ( testVal > maxVal )
565 for (
int i = 1; i < values.length(); ++i )
568 if ( testVal < minVal )
584 if ( testValue <= minValue )
588 else if ( testValue >= maxValue )
630 foreach (
const QVariant &value, values )
652 for (
int i = 0; i < elems.size(); i++ )
654 if ( elems[i].size() > 1 )
655 elems[i] = elems[i].left( 1 ).toUpper() + elems[i].
mid( 1 ).toLower();
657 return QVariant( elems.join(
" " ) );
668 if ( values.length() == 2 || values.length() == 3 )
673 if ( !str.
isEmpty() && wrap != 0 )
677 if ( values.length() == 3 ) delimiterstr =
getStringValue( values.at( 2 ), parent );
678 if ( delimiterstr.
isEmpty() ) delimiterstr =
" ";
679 int delimiterlength = delimiterstr.
length();
682 int strlength, strcurrent, strhit, lasthit;
684 for (
int i = 0; i < lines.
size(); i++ )
686 strlength = lines[i].
length();
691 while ( strcurrent < strlength )
698 strhit = lines[i].
lastIndexOf( delimiterstr, strcurrent + wrap );
699 if ( strhit == lasthit || strhit == -1 )
702 strhit = lines[i].
indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
708 strhit = lines[i].
indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
712 newstr.
append( lines[i].midRef( strcurrent, strhit - strcurrent ) );
714 strcurrent = strhit + delimiterlength;
718 newstr.
append( lines[i].midRef( strcurrent ) );
719 strcurrent = strlength;
722 if ( i < lines.
size() - 1 ) newstr.
append(
"\n" );
786 ( void )re.indexIn( str );
787 if ( re.captureCount() > 0 )
790 return QVariant( re.capturedTexts()[1] );
836 foreach (
const QVariant &value, values )
853 return string.right( pos );
860 return string.left( pos );
866 int length =
getIntValue( values.at( 1 ), parent );
874 int length =
getIntValue( values.at( 1 ), parent );
882 for (
int n = 1; n < values.length(); n++ )
914 int seconds = d2.
secsTo( d1 );
1024 #define ENSURE_GEOM_TYPE(f, g, geomtype) if (!f) return QVariant(); \
1025 const QgsGeometry* g = f->constGeometry(); \
1026 if (!g || g->type() != geomtype) return QVariant();
1032 if ( g->isMultipart() )
1034 return g->asMultiPoint()[ 0 ].x();
1038 return g->asPoint().x();
1044 if ( g->isMultipart() )
1046 return g->asMultiPoint()[ 0 ].y();
1050 return g->asPoint().y();
1060 idx += polyline.
count();
1062 if ( idx < 0 || idx >= polyline.
count() )
1073 if ( v.
type() == QVariant::PointF )
1081 if ( v.
type() == QVariant::PointF )
1233 if ( values.length() < 2 || values.length() > 3 )
1239 if ( values.length() == 3 )
1307 if ( values.length() < 1 || values.length() > 2 )
1312 if ( values.length() == 2 )
1321 if ( values.length() == 2 )
1324 double scaler = pow( 10.0,
getIntValue( values.at( 1 ), parent ) );
1325 return QVariant( qRound( number * scaler ) / scaler );
1328 if ( values.length() == 1 )
1330 double number =
getIntValue( values.at( 0 ), parent );
1353 int places =
getIntValue( values.at( 1 ), parent );
1359 return QString(
"%L1" ).
arg( value, 0,
'f', places );
1372 int green =
getIntValue( values.at( 1 ), parent );
1375 if ( ! color.isValid() )
1378 color =
QColor( 0, 0, 0 );
1381 return QString(
"%1,%2,%3" ).
arg( color.red() ).arg( color.green() ).arg( color.blue() );
1392 node =
getNode( values.at( 1 ), parent );
1394 value = node->
eval( parent, f );
1399 node =
getNode( values.at( 2 ), parent );
1401 value = node->
eval( parent, f );
1410 int green =
getIntValue( values.at( 1 ), parent );
1412 int alpha =
getIntValue( values.at( 3 ), parent );
1414 if ( ! color.isValid() )
1417 color =
QColor( 0, 0, 0 );
1432 QColor color = mRamp->color( value );
1439 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1441 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1443 double lightness =
getIntValue( values.at( 2 ), parent ) / 100.0;
1447 if ( ! color.isValid() )
1450 color =
QColor( 0, 0, 0 );
1453 return QString(
"%1,%2,%3" ).
arg( color.red() ).arg( color.green() ).arg( color.blue() );
1459 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1461 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1463 double lightness =
getIntValue( values.at( 2 ), parent ) / 100.0;
1465 double alpha =
getIntValue( values.at( 3 ), parent ) / 255.0;
1468 if ( ! color.isValid() )
1470 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( lightness ).arg( alpha ) );
1471 color =
QColor( 0, 0, 0 );
1479 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1481 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1483 double value =
getIntValue( values.at( 2 ), parent ) / 100.0;
1487 if ( ! color.isValid() )
1490 color =
QColor( 0, 0, 0 );
1493 return QString(
"%1,%2,%3" ).
arg( color.red() ).arg( color.green() ).arg( color.blue() );
1499 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1501 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1503 double value =
getIntValue( values.at( 2 ), parent ) / 100.0;
1505 double alpha =
getIntValue( values.at( 3 ), parent ) / 255.0;
1508 if ( ! color.isValid() )
1510 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( value ).arg( alpha ) );
1511 color =
QColor( 0, 0, 0 );
1519 double cyan =
getIntValue( values.at( 0 ), parent ) / 100.0;
1521 double magenta =
getIntValue( values.at( 1 ), parent ) / 100.0;
1523 double yellow =
getIntValue( values.at( 2 ), parent ) / 100.0;
1525 double black =
getIntValue( values.at( 3 ), parent ) / 100.0;
1529 if ( ! color.isValid() )
1532 color =
QColor( 0, 0, 0 );
1535 return QString(
"%1,%2,%3" ).
arg( color.red() ).arg( color.green() ).arg( color.blue() );
1541 double cyan =
getIntValue( values.at( 0 ), parent ) / 100.0;
1543 double magenta =
getIntValue( values.at( 1 ), parent ) / 100.0;
1545 double yellow =
getIntValue( values.at( 2 ), parent ) / 100.0;
1547 double black =
getIntValue( values.at( 3 ), parent ) / 100.0;
1549 double alpha =
getIntValue( values.at( 4 ), parent ) / 255.0;
1552 if ( ! color.isValid() )
1554 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4:%5' to color" ).arg( cyan ).arg( magenta ).arg( yellow ).arg( black ).arg( alpha ) );
1555 color =
QColor( 0, 0, 0 );
1582 if ( ! s.createFromOgcWmsCrs( sAuthId ) )
1602 if ( layersByName.
size() > 0 )
1615 int attributeId = vl->fieldNameIndex( attribute );
1616 if ( attributeId == -1 )
1621 const QVariant& attVal = values.at( 2 );
1632 if ( fet.
attribute( attributeId ) == attVal )
1676 <<
"abs" <<
"sqrt" <<
"cos" <<
"sin" <<
"tan"
1677 <<
"asin" <<
"acos" <<
"atan" <<
"atan2"
1678 <<
"exp" <<
"ln" <<
"log10" <<
"log"
1679 <<
"round" <<
"rand" <<
"randf" <<
"max" <<
"min" <<
"clamp"
1680 <<
"scale_linear" <<
"scale_exp" <<
"floor" <<
"ceil" <<
"$pi"
1681 <<
"toint" <<
"to_int" <<
"toreal" <<
"to_real" <<
"tostring" <<
"to_string"
1682 <<
"todatetime" <<
"to_datetime" <<
"todate" <<
"to_date"
1683 <<
"totime" <<
"to_time" <<
"tointerval" <<
"to_interval"
1684 <<
"coalesce" <<
"if" <<
"regexp_match" <<
"age" <<
"year"
1685 <<
"month" <<
"week" <<
"day" <<
"hour"
1686 <<
"minute" <<
"second" <<
"lower" <<
"upper"
1687 <<
"title" <<
"length" <<
"replace" <<
"trim" <<
"wordwrap"
1688 <<
"regexp_replace" <<
"regexp_substr"
1689 <<
"substr" <<
"concat" <<
"strpos" <<
"left"
1690 <<
"right" <<
"rpad" <<
"lpad" <<
"format"
1691 <<
"format_number" <<
"format_date"
1692 <<
"color_rgb" <<
"color_rgba" <<
"ramp_color"
1693 <<
"color_hsl" <<
"color_hsla" <<
"color_hsv" <<
"color_hsva"
1694 <<
"color_cymk" <<
"color_cymka"
1695 <<
"xat" <<
"yat" <<
"$area"
1696 <<
"$length" <<
"$perimeter" <<
"$x" <<
"$y"
1697 <<
"x_at" <<
"xat" <<
"y_at" <<
"yat" <<
"x_min" <<
"xmin" <<
"x_max" <<
"xmax"
1698 <<
"y_min" <<
"ymin" <<
"y_max" <<
"ymax" <<
"geom_from_wkt" <<
"geomFromWKT"
1699 <<
"geom_from_gml" <<
"geomFromGML" <<
"intersects_bbox" <<
"bbox"
1700 <<
"disjoint" <<
"intersects" <<
"touches" <<
"crosses" <<
"contains"
1701 <<
"overlaps" <<
"within" <<
"buffer" <<
"centroid" <<
"bounds"
1702 <<
"bounds_width" <<
"bounds_height" <<
"convex_hull" <<
"difference"
1703 <<
"distance" <<
"intersection" <<
"sym_difference" <<
"combine"
1704 <<
"union" <<
"geom_to_wkt" <<
"geomToWKT" <<
"geometry"
1705 <<
"transform" <<
"get_feature" <<
"getFeature"
1707 <<
"$rownum" <<
"$id" <<
"$scale" <<
"_specialcol_";
1886 static bool initialized =
false;
1897 lst << qMakePair(
QString(
"$numpages" ),
QString(
"Composer" ) );
1898 lst << qMakePair(
QString(
"$numfeatures" ),
QString(
"Atlas" ) );
1899 lst << qMakePair(
QString(
"$atlasfeatureid" ),
QString(
"Atlas" ) );
1900 lst << qMakePair(
QString(
"$atlasgeometry" ),
QString(
"Atlas" ) );
1901 lst << qMakePair(
QString(
"$atlasfeature" ),
QString(
"Atlas" ) );
1905 for ( ; it != lst.
constEnd(); ++it )
1961 for (
int i = 0; i < count; i++ )
2006 for (
int i = 0; i < columns.
count(); i++ )
2009 for (
int j = i + 1; j < columns.
count(); j++ )
2101 if ( substitutionMap )
2107 if ( !oldValue.
isNull() )
2108 savedValues.
insert( sit.key(), oldValue );
2116 while ( index < action.
size() )
2120 int pos = rx.
indexIn( action, index );
2133 expr_action += action.
mid( start, index - start );
2155 expr_action += action.
mid( start, index - start );
2160 expr_action += action.
mid( start, pos - start ) + result.
toString();
2163 expr_action += action.
mid( index );
2178 double convertedValue = text.
toDouble( &ok );
2181 return convertedValue;
2187 convertedValue = result.
toDouble( &ok );
2190 return fallbackValue;
2192 return convertedValue;
2201 QString msg;
bool first =
true;
2204 if ( !first ) msg +=
", ";
else first =
false;
2215 QVariant val = mOperand->eval( parent, f );
2236 Q_ASSERT( 0 &&
"unknown unary operation" );
2243 return mOperand->prepare( parent, fields );
2255 QVariant vL = mOpLeft->eval( parent, f );
2257 QVariant vR = mOpRight->eval( parent, f );
2263 if ( vL.
type() == QVariant::String && vR.
type() == QVariant::String )
2283 if ( mOp ==
boMod && iR == 0 )
2286 return QVariant( computeInt( iL, iR ) );
2297 return QVariant( computeDateTimeFromInterval( dL, &iL ) );
2304 if (( mOp ==
boDiv || mOp ==
boMod ) && fR == 0. )
2306 return QVariant( computeDouble( fL, fR ) );
2316 return QVariant( qFloor( fL / fR ) );
2412 esc_regexp.
replace(
"%",
".*" );
2413 esc_regexp.
replace(
"_",
"." );
2449 case boEQ:
return diff == 0;
2450 case boNE:
return diff != 0;
2451 case boLT:
return diff < 0;
2452 case boGT:
return diff > 0;
2453 case boLE:
return diff <= 0;
2454 case boGE:
return diff >= 0;
2455 default: Q_ASSERT(
false );
return false;
2465 case boMul:
return x*y;
2466 case boDiv:
return x/y;
2467 case boMod:
return x%y;
2468 default: Q_ASSERT(
false );
return 0;
2478 default: Q_ASSERT(
false );
return QDateTime();
2488 case boMul:
return x*y;
2489 case boDiv:
return x/y;
2490 case boMod:
return fmod( x,y );
2491 default: Q_ASSERT(
false );
return 0;
2498 bool resL = mOpLeft->prepare( parent, fields );
2499 bool resR = mOpRight->prepare( parent, fields );
2500 return resL && resR;
2545 Q_ASSERT( 0 &&
"unexpected binary operator" );
2581 Q_ASSERT( 0 &&
"unexpected binary operator" );
2591 if ( leftAssociative() )
2593 fmt += lOp && ( lOp->
precedence() < precedence() ) ?
"(%1)" :
"%1";
2595 fmt += rOp && ( rOp->
precedence() <= precedence() ) ?
"(%3)" :
"%3";
2599 fmt += lOp && ( lOp->
precedence() <= precedence() ) ?
"(%1)" :
"%1";
2601 fmt += rOp && ( rOp->
precedence() < precedence() ) ?
"(%3)" :
"%3";
2611 if ( mList->count() == 0 )
2613 QVariant v1 = mNode->eval( parent, f );
2618 bool listHasNull =
false;
2620 foreach (
Node* n, mList->list() )
2657 bool res = mNode->prepare( parent, fields );
2658 foreach (
Node* n, mList->list() )
2660 res = res && n->
prepare( parent, fields );
2667 return QString(
"%1 %2 IN (%3)" ).
arg( mNode->dump() ).arg( mNotIn ?
"NOT" :
"" ).
arg( mList->dump() );
2677 QVariantList argValues;
2680 foreach (
Node* n, mArgs->list() )
2690 v = n->
eval( parent, f );
2695 argValues.append( v );
2712 foreach (
Node* n, mArgs->list() )
2714 res = res && n->
prepare( parent, fields );
2737 return functionColumns;
2740 foreach (
Node* n, mArgs->list() )
2746 return functionColumns.
toSet().toList();
2764 if ( mValue.isNull() )
2767 switch ( mValue.type() )
2771 case QVariant::String:
return quotedString( mValue.toString() );
2772 default:
return QObject::tr(
"[unsupported type;%1; value:%2]" ).
arg( mValue.typeName() ).arg( mValue.toString() );
2787 return QVariant(
"[" + mName +
"]" );
2792 for (
int i = 0; i < fields.
count(); ++i )
2794 if (
QString::compare( fields[i].name(), mName, Qt::CaseInsensitive ) == 0 )
2814 foreach (
WhenThen* cond, mConditions )
2829 QVariant vElse = mElseExp->eval( parent, f );
2841 foreach (
WhenThen* cond, mConditions )
2845 if ( !res )
return false;
2849 return mElseExp->prepare( parent, fields );
2857 foreach (
WhenThen* cond, mConditions )
2862 msg +=
QString(
" ELSE %1" ).
arg( mElseExp->dump() );
2870 foreach (
WhenThen* cond, mConditions )
2876 lst += mElseExp->referencedColumns();
2883 foreach (
WhenThen* cond, mConditions )
2890 if ( mElseExp && mElseExp->needsGeometry() )
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f) override
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)
bool canConvert(Type t) const
Class for parsing and evaluation of expressions (formerly called "search strings").
qlonglong toLongLong(bool *ok) const
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.
Wrapper for iterator of features from vector data provider or vector layer.
static QVariant fcnCeil(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QString toString(Qt::DateFormat format) const
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)
QColor fromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a)
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
static QVariant fcnFeatureId(const QVariantList &, const QgsFeature *f, QgsExpression *)
QString cap(int nth) const
QString & append(QChar ch)
iterator insert(const Key &key, const T &value)
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
virtual QString dump() const override
static QVariant fcnAsin(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
iterator erase(iterator pos)
QStringList referencedColumns() const
Get list of columns referenced by the expression.
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)
QgsGeometry * convexHull() const
Returns the smallest convex polygon that contains all the points in the geometry. ...
static bool unregisterFunction(QString name)
bool contains(const Key &key) const
static QString quotedColumnRef(QString name)
return quoted column reference (in double quotes)
static QVariant fcnLog(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual bool handlesNull() const
QgsGeometry * symDifference(const QgsGeometry *geometry) const
Returns a Geometry representing the points making up this Geometry that do not make up other...
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)
bool lazyEval()
True if this function should use lazy evaluation.
virtual bool prepare(QgsExpression *parent, const QgsFields &fields) override
QgsGeometry * difference(const QgsGeometry *geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...
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.
double distance(const QgsGeometry &geom) const
Returns the minimum distanace between this geometry and another geometry, using GEOS.
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)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QDateTime toDateTime() const
virtual QString dump() const =0
static QDate getDateValue(const QVariant &value, QgsExpression *parent)
static QVariant fcnFloor(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f) override
QString escape(const QString &str)
static QString helptext(QString name)
static QVariant fcnXMin(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnFormatDate(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnIf(const QVariantList &values, const QgsFeature *f, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f) override
const T & at(int i) const
QgsExpression()
Used by QgsOgcUtils to create an empty.
QgsRectangle boundingBox() const
Returns the bounding box of this feature.
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)
A geometry is the spatial representation of a feature.
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)
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f) override
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.
double toDouble(bool *ok) const
static QVariant fcnBuffer(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static bool isValid(const QString &text, const QgsFields &fields, QString &errorMessage)
int weekNumber(int *yearNumber) const
QString tr(const char *sourceText, const char *disambiguation, int n)
static QVariant fcnYear(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnFormatString(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
int computeInt(int x, int y)
virtual bool prepare(QgsExpression *parent, const QgsFields &fields) override
virtual QString dump() const override
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)
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
virtual QString dump() const override
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()
static const QList< Function * > & Functions()
int matchedLength() const
QList< Key > keys() const
static QVariant fcnToReal(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnGetGeometry(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
static bool isFunctionName(QString name)
static QVariant fcnIntersection(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool createFromOgcWmsCrs(QString theCrs)
Set up this CRS from the given OGC CRS.
static QHash< QString, QString > gFunctionHelpTexts
static int functionCount()
Returns the number of functions defined in the parser.
virtual bool needsGeometry() const override
double measure(const QgsGeometry *geometry) const
general measurement (line distance or polygon area)
void acceptVisitor(Visitor &v) const
entry function for the visitor pattern
bool leftAssociative() const
bool contains(const QgsPoint *p) const
Test for containment of a point (uses GEOS)
static QVariant fcnTransformGeometry(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f) override
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f) override
QString number(int n, int base)
int count(const T &value) const
static QVariant fcnAttribute(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnLPad(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
void append(const T &value)
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) ...
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)
int toInt(bool *ok) const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
static QVariant fcnFeature(const QVariantList &, const QgsFeature *f, QgsExpression *)
virtual bool prepare(QgsExpression *parent, const QgsFields &fields) override
static int functionIndex(const QString &name)
double xMaximum() const
Get the x maximum value (right side of rectangle)
QString rightJustified(int width, QChar fill, bool truncate) const
virtual QString dump() const override
static bool registerFunction(Function *function)
static QVariant fcnAtan2(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
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 needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
bool overlaps(const QgsGeometry *geometry) const
Test for if geometry overlaps another (uses GEOS)
int toInt(bool *ok, int base) const
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)
virtual QString dump() const override
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
This class wraps a request for features to a vector layer (or directly its vector data provider)...
static QVariant fcnY(const QVariantList &, const QgsFeature *f, QgsExpression *)
static QVariant fcnRndF(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static const QString AllAttributes
QDateTime computeDateTimeFromInterval(QDateTime d, QgsExpression::Interval *i)
double measurePerimeter(const QgsGeometry *geometry) const
measures perimeter of polygon
int count() const
Return number of items.
static QVariant fcnGeomToWKT(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnGetFeature(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnSpecialColumn(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QList< Function * > gmFunctions
virtual bool prepare(QgsExpression *parent, const QgsFields &fields) override
QgsGeometry * centroid() const
Returns the center of mass of a geometry.
static QVariant fcnWordwrap(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual bool prepare(QgsExpression *parent, const QgsFields &fields) override
virtual QString dump() const
static QVariant fcnLength(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QString name()
The name of the function.
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)
bool isIntervalSafe(const QVariant &v)
QgsGeometry * buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
static QVariant fcnRPad(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
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)
const T value(const Key &key) const
bool contains(QChar ch, Qt::CaseSensitivity cs) const
static QVariant fcnBbox(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnBoundsWidth(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QList< QgsMapLayer * > mapLayersByName(QString layerName)
Retrieve a pointer to a loaded layer by name.
static QVariant fcnGeomArea(const QVariantList &, const QgsFeature *f, QgsExpression *parent)
static QVariant fcnAcos(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QVariant fromValue(const T &value)
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 QgsFeature getFeature(const QVariant &value, QgsExpression *parent)
virtual QStringList referencedColumns() const
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)
static QVariant fcnGeomFromGML(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
General purpose distance and area calculator.
QgsGeometry * intersection(const QgsGeometry *geometry) const
Returns a geometry representing the points shared by this geometry and other.
QgsGeometry * combine(const QgsGeometry *geometry) const
Returns a geometry representing all the points in this geometry and other (a union geometry operation...
QString & replace(int position, int n, QChar after)
static QMap< QString, QString > gmSpecialColumnGroups
virtual QString dump() const override
static QVariant fcnBounds(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnWeek(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QDateTime currentDateTime()
static QVariant fcnRegexpReplace(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool isIntSafe(const QVariant &v)
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QString mid(int position, int n) const
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)
int secsTo(const QDateTime &other) const
static QgsExpression::Node * getNode(const QVariant &value, QgsExpression *parent)
static QVariant fncColorHsva(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
virtual bool prepare(QgsExpression *parent, const QgsFields &fields) override
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)
Class for storing a coordinate reference system (CRS)
int count(const T &value) const
virtual QStringList referencedColumns() const override
bool within(const QgsGeometry *geometry) const
Test for if geometry is within another (uses GEOS)
virtual bool prepare(QgsExpression *parent, const QgsFields &fields) override
static QVariant fcnRegexpMatch(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
QList< T > mid(int pos, int length) const
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)
Creates a new geometry from a QgsRectangle.
QString leftJustified(int width, QChar fill, bool truncate) const
int lastIndexOf(const QRegExp &rx, int from) const
static QVariant fcnExpScale(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct.
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)
Creates a new geometry from a WKT string.
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)
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
virtual QVariant eval(QgsExpression *parent, const QgsFeature *f) override
int indexOf(const QRegExp &rx, int from) const
double toDouble(bool *ok) const
bool disjoint(const QgsGeometry *geometry) const
Test for if geometry is disjoint of another (uses GEOS)
iterator insert(const Key &key, const T &value)
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)
void setValid(bool valid)
static void setSpecialColumn(const QString &name, QVariant value)
Assign a special column.
const_iterator constEnd() const
static QVariant fcnGeomFromWKT(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
static QVariant fcnColorCmyk(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QDateTime addSecs(int s) const
static QVariant fcnExp(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
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.
int compare(const QString &other) const
static QVariant fcnBoundsHeight(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QString parserErrorString() const
Returns parser error.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
bool exactMatch(const QString &str) const
static double evaluateToDouble(const QString &text, const double fallbackValue)
Attempts to evaluate a text string as an expression to a resultant double value.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
double xMinimum() const
Get the x minimum value (left side of rectangle)
virtual QStringList referencedColumns() const override
QString evalErrorString() const
Returns evaluation error.
QString exportToWkt(const int &precision=17) const
Exports the geometry to WKT.
virtual void accept(Visitor &v) const =0
iterator find(const Key &key)
static QVariant fcnSymDifference(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
bool isNull(const QVariant &v)
virtual QString dump() const override
static QVariant fcnLn(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
static QVariant fcnRegexpSubstr(const QVariantList &values, const QgsFeature *, QgsExpression *parent)
QColor fromHsvF(qreal h, qreal s, qreal v, qreal a)
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.
QColor fromHslF(qreal h, qreal s, qreal l, qreal a)
static QgsExpression::Interval getInterval(const QVariant &value, QgsExpression *parent, bool report_error=false)
const T value(const Key &key) const
static QDateTime getDateTimeValue(const QVariant &value, QgsExpression *parent)
static QVariant fcnRound(const QVariantList &values, const QgsFeature *f, QgsExpression *parent)
static void unsetSpecialColumn(const QString &name)
Unset a special column.
static const char * BinaryOperatorText[]
static QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=0, const QgsDistanceArea *distanceArea=0)
This function currently replaces each expression between [% and %] in the string with the result of i...
static QMap< QString, QVariant > gmSpecialColumns