19 #include <QDomDocument>
44 #if QT_VERSION < 0x050000
45 #include <qtextdocument.h>
63 QRegExp rx(
"([-+]?\\d?\\.?\\d+\\s+\\S+)", Qt::CaseInsensitive );
67 while (( pos = rx.
indexIn(
string, pos ) ) != -1 )
74 map.
insert( 1,
QStringList() <<
"second" <<
"seconds" <<
tr(
"second|seconds",
"list of words separated by | which reference years" ).split(
"|" ) );
75 map.
insert( 0 + MINUTE,
QStringList() <<
"minute" <<
"minutes" <<
tr(
"minute|minutes",
"list of words separated by | which reference minutes" ).split(
"|" ) );
76 map.
insert( 0 + HOUR,
QStringList() <<
"hour" <<
"hours" <<
tr(
"hour|hours",
"list of words separated by | which reference minutes hours" ).split(
"|" ) );
77 map.
insert( 0 + DAY,
QStringList() <<
"day" <<
"days" <<
tr(
"day|days",
"list of words separated by | which reference days" ).split(
"|" ) );
78 map.
insert( 0 + WEEKS,
QStringList() <<
"week" <<
"weeks" <<
tr(
"week|weeks",
"wordlist separated by | which reference weeks" ).split(
"|" ) );
79 map.
insert( 0 + MONTHS,
QStringList() <<
"month" <<
"months" <<
tr(
"month|months",
"list of words separated by | which reference months" ).split(
"|" ) );
80 map.
insert( 0 + YEARS,
QStringList() <<
"year" <<
"years" <<
tr(
"year|years",
"list of words separated by | which reference years" ).split(
"|" ) );
82 Q_FOREACH (
const QString& match, list )
86 double value = split.
at( 0 ).toDouble( &ok );
93 Q_FOREACH (
int duration, map.
keys() )
95 Q_FOREACH (
const QString& name, map[duration] )
97 if ( match.
contains( name, Qt::CaseInsensitive ) )
106 seconds += value * duration;
121 return ( mSeconds == other.mSeconds );
155 case False:
return 0;
163 #define TVL_True QVariant(1)
164 #define TVL_False QVariant(0)
165 #define TVL_Unknown QVariant()
172 if ( v.
type() == QVariant::Int )
return true;
173 if ( v.
type() == QVariant::UInt )
return true;
174 if ( v.
type() == QVariant::LongLong )
return true;
175 if ( v.
type() == QVariant::ULongLong )
return true;
176 if ( v.
type() == QVariant::Double )
return false;
177 if ( v.
type() == QVariant::String ) {
bool ok; v.
toString().
toInt( &ok );
return ok; }
182 if ( v.
type() == QVariant::Double )
return true;
183 if ( v.
type() == QVariant::Int )
return true;
184 if ( v.
type() == QVariant::UInt )
return true;
185 if ( v.
type() == QVariant::LongLong )
return true;
186 if ( v.
type() == QVariant::ULongLong )
return true;
187 if ( v.
type() == QVariant::String )
191 ok = ok && qIsFinite( val ) && !qIsNaN( val );
199 return v.
type() == QVariant::DateTime || v.
type() == QVariant::Date ||
200 v.
type() == QVariant::Time;
210 if ( v.
type() == QVariant::String )
222 #define ENSURE_NO_EVAL_ERROR { if (parent->hasEvalError()) return QVariant(); }
223 #define SET_EVAL_ERROR(x) { parent->setEvalErrorString(x); return QVariant(); }
232 "=",
"<>",
"<=",
">=",
"<",
">",
"~",
"LIKE",
"NOT LIKE",
"ILIKE",
"NOT ILIKE",
"IS",
"IS NOT",
233 "+",
"-",
"*",
"/",
"//",
"%",
"^",
256 if ( !ok || qIsNaN( x ) || !qIsFinite( x ) )
327 if ( inter.isValid() )
372 if ( value.
type() == QVariant::Int )
467 if ( x <= 0 || b <= 0 )
469 return QVariant( log( x ) / log( b ) );
479 double f = ( double )qrand() / RAND_MAX;
480 return QVariant( min + f * ( max - min ) );
490 return QVariant( min + ( qrand() % (
int )( max - min + 1 ) ) );
501 if ( domainMin >= domainMax )
508 if ( val >= domainMax )
512 else if ( val <= domainMin )
518 double m = ( rangeMax - rangeMin ) / ( domainMax - domainMin );
519 double c = rangeMin - ( domainMin * m );
534 if ( domainMin >= domainMax )
546 if ( val >= domainMax )
550 else if ( val <= domainMin )
556 return QVariant((( rangeMax - rangeMin ) / pow( domainMax - domainMin, exponent ) ) * pow( val - domainMin, exponent ) + rangeMin );
565 for (
int i = 1; i < values.length(); ++i )
568 if ( testVal > maxVal )
583 for (
int i = 1; i < values.length(); ++i )
586 if ( testVal < minVal )
602 if ( testValue <= minValue )
606 else if ( testValue >= maxValue )
648 Q_FOREACH (
const QVariant &value, values )
670 for (
int i = 0; i < elems.size(); i++ )
672 if ( elems[i].size() > 1 )
673 elems[i] = elems[i].left( 1 ).toUpper() + elems[i].
mid( 1 ).toLower();
675 return QVariant( elems.join(
" " ) );
714 if ( values.length() == 2 || values.length() == 3 )
719 if ( !str.
isEmpty() && wrap != 0 )
723 if ( values.length() == 3 ) delimiterstr =
getStringValue( values.at( 2 ), parent );
724 if ( delimiterstr.
isEmpty() ) delimiterstr =
" ";
725 int delimiterlength = delimiterstr.
length();
728 int strlength, strcurrent, strhit, lasthit;
730 for (
int i = 0; i < lines.
size(); i++ )
732 strlength = lines[i].
length();
737 while ( strcurrent < strlength )
744 strhit = lines[i].
lastIndexOf( delimiterstr, strcurrent + wrap );
745 if ( strhit == lasthit || strhit == -1 )
748 strhit = lines[i].
indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
754 strhit = lines[i].
indexOf( delimiterstr, strcurrent + qAbs( wrap ) );
758 newstr.
append( lines[i].midRef( strcurrent, strhit - strcurrent ) );
760 strcurrent = strhit + delimiterlength;
764 newstr.
append( lines[i].midRef( strcurrent ) );
765 strcurrent = strlength;
768 if ( i < lines.
size() - 1 ) newstr.
append(
"\n" );
845 ( void )re.indexIn( str );
846 if ( re.captureCount() > 0 )
849 return QVariant( re.capturedTexts().at( 1 ) );
872 if ( context && context->
hasVariable(
"row_number" ) )
873 return context->
variable(
"row_number" );
884 return context->
variable(
"map_id" );
893 if ( context && context->
hasVariable(
"layout_numpages" ) )
894 return context->
variable(
"layout_numpages" );
903 if ( context && context->
hasVariable(
"layout_page" ) )
904 return context->
variable(
"layout_page" );
913 if ( context && context->
hasVariable(
"atlas_featurenumber" ) )
914 return context->
variable(
"atlas_featurenumber" );
923 if ( context && context->
hasVariable(
"atlas_featureid" ) )
924 return context->
variable(
"atlas_featureid" );
934 if ( context && context->
hasVariable(
"atlas_feature" ) )
935 return context->
variable(
"atlas_feature" );
944 if ( context && context->
hasVariable(
"atlas_geometry" ) )
945 return context->
variable(
"atlas_geometry" );
954 if ( context && context->
hasVariable(
"atlas_totalfeatures" ) )
955 return context->
variable(
"atlas_totalfeatures" );
962 #define FEAT_FROM_CONTEXT(c, f) if (!c || !c->hasVariable(QgsExpressionContext::EXPR_FEATURE)) return QVariant(); \
963 QgsFeature f = qvariant_cast<QgsFeature>( c->variable( QgsExpressionContext::EXPR_FEATURE ) );
989 Q_FOREACH (
const QVariant &value, values )
1006 return string.right( pos );
1013 return string.left( pos );
1019 int length =
getIntValue( values.at( 1 ), parent );
1027 int length =
getIntValue( values.at( 1 ), parent );
1035 for (
int n = 1; n < values.length(); n++ )
1067 int seconds = d2.
secsTo( d1 );
1073 if ( !values.at( 0 ).canConvert<
QDate>() )
1191 #define ENSURE_GEOM_TYPE(f, g, geomtype) const QgsGeometry* g = f.constGeometry(); \
1192 if (!g || g->type() != geomtype) return QVariant();
1198 if ( g->isMultipart() )
1200 return g->asMultiPoint().at( 0 ).x();
1204 return g->asPoint().x();
1212 if ( g->isMultipart() )
1214 return g->asMultiPoint().at( 0 ).y();
1218 return g->asPoint().y();
1268 int idx =
getIntValue( values.at( 1 ), parent ) - 1;
1329 idx += polyline.
count();
1331 if ( idx < 0 || idx >= polyline.
count() )
1342 if ( v.
type() == QVariant::PointF )
1350 if ( v.
type() == QVariant::PointF )
1527 if ( values.length() < 2 || values.length() > 3 )
1533 if ( values.length() == 3 )
1601 if ( values.length() < 1 || values.length() > 2 )
1606 if ( values.length() == 2 )
1614 if ( values.length() == 2 )
1617 double scaler = pow( 10.0,
getIntValue( values.at( 1 ), parent ) );
1618 return QVariant( qRound( number * scaler ) / scaler );
1621 if ( values.length() == 1 )
1623 double number =
getIntValue( values.at( 0 ), parent );
1645 int places =
getIntValue( values.at( 1 ), parent );
1651 return QString(
"%L1" ).
arg( value, 0,
'f', places );
1664 int green =
getIntValue( values.at( 1 ), parent );
1667 if ( ! color.isValid() )
1670 color =
QColor( 0, 0, 0 );
1673 return QString(
"%1,%2,%3" ).
arg( color.red() ).arg( color.green() ).arg( color.blue() );
1684 node =
getNode( values.at( 1 ), parent );
1686 value = node->
eval( parent, context );
1691 node =
getNode( values.at( 2 ), parent );
1693 value = node->
eval( parent, context );
1702 int green =
getIntValue( values.at( 1 ), parent );
1704 int alpha =
getIntValue( values.at( 3 ), parent );
1706 if ( ! color.isValid() )
1709 color =
QColor( 0, 0, 0 );
1724 QColor color = mRamp->color( value );
1731 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1733 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1735 double lightness =
getIntValue( values.at( 2 ), parent ) / 100.0;
1739 if ( ! color.isValid() )
1742 color =
QColor( 0, 0, 0 );
1745 return QString(
"%1,%2,%3" ).
arg( color.red() ).arg( color.green() ).arg( color.blue() );
1751 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1753 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1755 double lightness =
getIntValue( values.at( 2 ), parent ) / 100.0;
1757 double alpha =
getIntValue( values.at( 3 ), parent ) / 255.0;
1760 if ( ! color.isValid() )
1762 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( lightness ).arg( alpha ) );
1763 color =
QColor( 0, 0, 0 );
1771 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1773 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1775 double value =
getIntValue( values.at( 2 ), parent ) / 100.0;
1779 if ( ! color.isValid() )
1782 color =
QColor( 0, 0, 0 );
1785 return QString(
"%1,%2,%3" ).
arg( color.red() ).arg( color.green() ).arg( color.blue() );
1791 double hue =
getIntValue( values.at( 0 ), parent ) / 360.0;
1793 double saturation =
getIntValue( values.at( 1 ), parent ) / 100.0;
1795 double value =
getIntValue( values.at( 2 ), parent ) / 100.0;
1797 double alpha =
getIntValue( values.at( 3 ), parent ) / 255.0;
1800 if ( ! color.isValid() )
1802 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4' to color" ).arg( hue ).arg( saturation ).arg( value ).arg( alpha ) );
1803 color =
QColor( 0, 0, 0 );
1811 double cyan =
getIntValue( values.at( 0 ), parent ) / 100.0;
1813 double magenta =
getIntValue( values.at( 1 ), parent ) / 100.0;
1815 double yellow =
getIntValue( values.at( 2 ), parent ) / 100.0;
1817 double black =
getIntValue( values.at( 3 ), parent ) / 100.0;
1821 if ( ! color.isValid() )
1824 color =
QColor( 0, 0, 0 );
1827 return QString(
"%1,%2,%3" ).
arg( color.red() ).arg( color.green() ).arg( color.blue() );
1833 double cyan =
getIntValue( values.at( 0 ), parent ) / 100.0;
1835 double magenta =
getIntValue( values.at( 1 ), parent ) / 100.0;
1837 double yellow =
getIntValue( values.at( 2 ), parent ) / 100.0;
1839 double black =
getIntValue( values.at( 3 ), parent ) / 100.0;
1841 double alpha =
getIntValue( values.at( 4 ), parent ) / 255.0;
1844 if ( ! color.isValid() )
1846 parent->
setEvalErrorString(
QObject::tr(
"Cannot convert '%1:%2:%3:%4:%5' to color" ).arg( cyan ).arg( magenta ).arg( yellow ).arg( black ).arg( alpha ) );
1847 color =
QColor( 0, 0, 0 );
1865 return color.
green();
1867 return color.
blue();
1869 return color.
alpha();
1875 return color.
valueF() * 100;
1883 return color.
cyanF() * 100;
1889 return color.
blackF() * 100;
1905 int value =
getIntValue( values.at( 2 ), parent );
1966 if ( ! s.createFromOgcWmsCrs( sAuthId ) )
1986 if ( layersByName.
size() > 0 )
1999 int attributeId = vl->fieldNameIndex( attribute );
2000 if ( attributeId == -1 )
2005 const QVariant& attVal = values.at( 2 );
2016 if ( fet.
attribute( attributeId ) == attVal )
2033 if ( layersByName.
size() > 0 )
2035 layer = layersByName.
at( 0 );
2044 return layer->name();
2048 return layer->title();
2050 return layer->abstract();
2052 return layer->keywordList();
2054 return layer->dataUrl();
2056 return layer->attribution();
2058 return layer->attributionUrl();
2060 return layer->publicSource();
2062 return (
double )layer->minimumScale();
2064 return (
double )layer->maximumScale();
2066 return layer->crs().authid();
2068 return layer->crs().toProj4();
2078 switch ( layer->type() )
2114 if ( transferOwnership )
2148 <<
"abs" <<
"sqrt" <<
"cos" <<
"sin" <<
"tan"
2149 <<
"asin" <<
"acos" <<
"atan" <<
"atan2"
2150 <<
"exp" <<
"ln" <<
"log10" <<
"log"
2151 <<
"round" <<
"rand" <<
"randf" <<
"max" <<
"min" <<
"clamp"
2152 <<
"scale_linear" <<
"scale_exp" <<
"floor" <<
"ceil" <<
"$pi"
2153 <<
"toint" <<
"to_int" <<
"toreal" <<
"to_real" <<
"tostring" <<
"to_string"
2154 <<
"todatetime" <<
"to_datetime" <<
"todate" <<
"to_date"
2155 <<
"totime" <<
"to_time" <<
"tointerval" <<
"to_interval"
2156 <<
"coalesce" <<
"if" <<
"regexp_match" <<
"age" <<
"year"
2157 <<
"month" <<
"week" <<
"day" <<
"hour" <<
"day_of_week"
2158 <<
"minute" <<
"second" <<
"lower" <<
"upper"
2159 <<
"title" <<
"length" <<
"replace" <<
"trim" <<
"wordwrap"
2160 <<
"regexp_replace" <<
"regexp_substr"
2161 <<
"substr" <<
"concat" <<
"strpos" <<
"left"
2162 <<
"right" <<
"rpad" <<
"lpad" <<
"format"
2163 <<
"format_number" <<
"format_date"
2164 <<
"color_rgb" <<
"color_rgba" <<
"ramp_color"
2165 <<
"color_hsl" <<
"color_hsla" <<
"color_hsv" <<
"color_hsva"
2166 <<
"color_cmyk" <<
"color_cmyka" <<
"color_part" <<
"set_color_part"
2167 <<
"xat" <<
"yat" <<
"$area" <<
"area" <<
"perimeter"
2168 <<
"$length" <<
"$perimeter" <<
"x" <<
"y" <<
"$x" <<
"$y" <<
"num_points"
2169 <<
"point_n" <<
"start_point" <<
"end_point" <<
"make_point"
2170 <<
"$x_at" <<
"x_at" <<
"xat" <<
"$y_at" <<
"y_at" <<
"yat" <<
"x_min" <<
"xmin" <<
"x_max" <<
"xmax"
2171 <<
"y_min" <<
"ymin" <<
"y_max" <<
"ymax" <<
"geom_from_wkt" <<
"geomFromWKT"
2172 <<
"geom_from_gml" <<
"geomFromGML" <<
"intersects_bbox" <<
"bbox"
2173 <<
"disjoint" <<
"intersects" <<
"touches" <<
"crosses" <<
"contains"
2174 <<
"overlaps" <<
"within" <<
"buffer" <<
"centroid" <<
"bounds"
2175 <<
"bounds_width" <<
"bounds_height" <<
"convex_hull" <<
"difference"
2176 <<
"distance" <<
"intersection" <<
"sym_difference" <<
"combine"
2177 <<
"union" <<
"geom_to_wkt" <<
"geomToWKT" <<
"geometry"
2178 <<
"transform" <<
"get_feature" <<
"getFeature"
2179 <<
"levenshtein" <<
"longest_common_substring" <<
"hamming_distance"
2181 <<
"attribute" <<
"var" <<
"layer_property"
2182 <<
"$id" <<
"$scale" <<
"_specialcol_";
2404 return isValid( text, &context, errorMessage );
2449 for (
int i = 0; i < count; i++ )
2494 for (
int i = 0; i < columns.
count(); i++ )
2497 for (
int j = i + 1; j < columns.
count(); j++ )
2583 bool res =
prepare( &context );
2625 return tr(
"(no root)" );
2649 if ( substitutionMap )
2656 if ( !oldValue.isNull() )
2657 savedValues.
insert( sit.key(), oldValue );
2666 while ( index < action.
size() )
2670 int pos = rx.
indexIn( action, index );
2683 expr_action += action.
midRef( start, index - start );
2698 expr_action += action.
midRef( start, index - start );
2703 expr_action += action.
mid( start, pos - start ) + result.
toString();
2706 expr_action += action.
midRef( index );
2723 double convertedValue = text.
toDouble( &ok );
2726 return convertedValue;
2737 convertedValue = result.
toDouble( &ok );
2740 return fallbackValue;
2742 return convertedValue;
2751 QString msg;
bool first =
true;
2754 if ( !first ) msg +=
", ";
else first =
false;
2765 QVariant val = mOperand->eval( parent, context );
2786 Q_ASSERT( 0 &&
"unknown unary operation" );
2793 return mOperand->prepare( parent, context );
2805 QVariant vL = mOpLeft->eval( parent, context );
2807 QVariant vR = mOpRight->eval( parent, context );
2813 if ( vL.
type() == QVariant::String && vR.
type() == QVariant::String )
2833 if ( mOp ==
boMod && iR == 0 )
2836 return QVariant( computeInt( iL, iR ) );
2847 return QVariant( computeDateTimeFromInterval( dL, &iL ) );
2854 if (( mOp ==
boDiv || mOp ==
boMod ) && fR == 0. )
2856 return QVariant( computeDouble( fL, fR ) );
2866 return QVariant( qFloor( fL / fR ) );
2962 esc_regexp.
replace(
"%",
".*" );
2963 esc_regexp.
replace(
"_",
"." );
2999 case boEQ:
return diff == 0;
3000 case boNE:
return diff != 0;
3001 case boLT:
return diff < 0;
3002 case boGT:
return diff > 0;
3003 case boLE:
return diff <= 0;
3004 case boGE:
return diff >= 0;
3005 default: Q_ASSERT(
false );
return false;
3015 case boMul:
return x*y;
3016 case boDiv:
return x/y;
3017 case boMod:
return x%y;
3018 default: Q_ASSERT(
false );
return 0;
3028 default: Q_ASSERT(
false );
return QDateTime();
3038 case boMul:
return x*y;
3039 case boDiv:
return x/y;
3040 case boMod:
return fmod( x,y );
3041 default: Q_ASSERT(
false );
return 0;
3047 bool resL = mOpLeft->prepare( parent, context );
3048 bool resR = mOpRight->prepare( parent, context );
3049 return resL && resR;
3094 Q_ASSERT( 0 &&
"unexpected binary operator" );
3130 Q_ASSERT( 0 &&
"unexpected binary operator" );
3140 if ( leftAssociative() )
3142 fmt += lOp && ( lOp->
precedence() < precedence() ) ?
"(%1)" :
"%1";
3144 fmt += rOp && ( rOp->
precedence() <= precedence() ) ?
"(%3)" :
"%3";
3148 fmt += lOp && ( lOp->
precedence() <= precedence() ) ?
"(%1)" :
"%1";
3150 fmt += rOp && ( rOp->
precedence() < precedence() ) ?
"(%3)" :
"%3";
3160 if ( mList->count() == 0 )
3162 QVariant v1 = mNode->eval( parent, context );
3167 bool listHasNull =
false;
3169 Q_FOREACH (
Node* n, mList->list() )
3206 bool res = mNode->prepare( parent, context );
3207 Q_FOREACH (
Node* n, mList->list() )
3209 res = res && n->
prepare( parent, context );
3216 return QString(
"%1 %2 IN (%3)" ).
arg( mNode->dump(), mNotIn ?
"NOT" :
"", mList->dump() );
3227 QVariantList argValues;
3230 Q_FOREACH (
Node* n, mArgs->list() )
3240 v = n->
eval( parent, context );
3245 argValues.append( v );
3262 Q_FOREACH (
Node* n, mArgs->list() )
3264 res = res && n->
prepare( parent, context );
3287 return functionColumns;
3290 Q_FOREACH (
Node* n, mArgs->list() )
3296 return functionColumns.
toSet().toList();
3303 Q_UNUSED( context );
3311 Q_UNUSED( context );
3318 if ( mValue.isNull() )
3321 switch ( mValue.type() )
3325 case QVariant::String:
return quotedString( mValue.toString() );
3326 case QVariant::Bool:
return mValue.toBool() ?
"TRUE" :
"FALSE";
3327 default:
return tr(
"[unsupported type;%1; value:%2]" ).arg( mValue.typeName(), mValue.toString() );
3344 return QVariant(
"[" + mName +
"]" );
3354 for (
int i = 0; i < fields.
count(); ++i )
3376 Q_FOREACH (
WhenThen* cond, mConditions )
3391 QVariant vElse = mElseExp->eval( parent, context );
3403 Q_FOREACH (
WhenThen* cond, mConditions )
3407 if ( !res )
return false;
3411 return mElseExp->prepare( parent, context );
3419 Q_FOREACH (
WhenThen* cond, mConditions )
3424 msg +=
QString(
" ELSE %1" ).
arg( mElseExp->dump() );
3432 Q_FOREACH (
WhenThen* cond, mConditions )
3438 lst += mElseExp->referencedColumns();
3445 Q_FOREACH (
WhenThen* cond, mConditions )
3452 if ( mElseExp && mElseExp->needsGeometry() )
3464 return tr(
"function help for %1 missing" ).arg( name );
3469 if ( f.
mType ==
tr(
"group" ) )
3470 name =
group( name );
3472 #if QT_VERSION < 0x050000
3475 name = name.toHtmlEscaped();
3478 QString helpContents(
QString(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
3479 .arg(
tr(
"%1 %2" ).arg( f.
mType, name ),
3489 if ( f.
mType !=
tr(
"group" ) )
3490 helpContents +=
QString(
"<h4>%1</h4>\n<div class=\"syntax\">\n" ).
arg(
tr(
"Syntax" ) );
3492 if ( f.
mType ==
tr(
"operator" ) )
3496 helpContents +=
QString(
"<code><span class=\"functionname\">%1</span> <span class=\"argument\">%2</span></code>" )
3501 helpContents +=
QString(
"<code><span class=\"argument\">%1</span> <span class=\"functionname\">%2</span> <span class=\"argument\">%3</span></code>" )
3505 else if ( f.
mType !=
tr(
"group" ) )
3507 helpContents +=
QString(
"<code><span class=\"functionname\">%1</span>" ).
arg( name );
3511 helpContents +=
"(";
3516 helpContents += delim;
3519 helpContents +=
QString(
"<span class=\"argument\">%1</span>" ).
arg( a.
mArg );
3524 helpContents +=
"...";
3527 helpContents +=
")";
3530 helpContents +=
"</code>";
3535 helpContents +=
QString(
"<h4>%1</h4>\n<div class=\"arguments\">\n<table>" ).
arg(
tr(
"Arguments" ) );
3545 helpContents +=
"</table>\n</div>\n";
3550 helpContents +=
QString(
"<h4>%1</h4>\n<div class=\"examples\">\n<ul>\n" ).
arg(
tr(
"Examples" ) );
3554 helpContents +=
"<li><code>" + e.
mExpression +
"</code> → <code>" + e.
mReturns +
"</code>";
3559 helpContents +=
"</li>\n";
3562 helpContents +=
"</ul>\n</div>\n";
3567 helpContents +=
QString(
"<h4>%1</h4>\n<div class=\"notes\"><p>%2</p></div>\n" ).
arg(
tr(
"Notes" ), v.
mNotes );
3571 return helpContents;
3640 else if ( value.
type() == QVariant::String )
3686 return func( values, &c, parent );
3697 return func( values, &f, parent );
3705 return eval( parent, &c );
3716 return eval( parent, &f );
3741 return mFnc ? mFnc( values, f, parent ) :
QVariant();
static bool isFunctionName(const QString &name)
static QVariant fcnDisjoint(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnConvexHull(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QString longestCommonSubstring(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the longest common substring between two strings.
bool canConvert(Type t) const
Class for parsing and evaluation of expressions (formerly called "search strings").
qlonglong toLongLong(bool *ok) const
const QString & name() const
Gets the name of the field.
virtual QStringList referencedColumns() const =0
Abstract virtual method which returns a list of columns required to evaluate this node...
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.
QString toString(Qt::DateFormat format) const
const QgsVectorColorRampV2 * colorRampRef(const QString &name) const
return a const pointer to a symbol (doesn't create new instance)
static QVariant fcnGeomLength(const QVariantList &, const QgsExpressionContext *context, QgsExpression *parent)
QColor fromCmykF(qreal c, qreal m, qreal y, qreal k, qreal a)
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
static QVariant fcnSin(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
virtual Q_DECL_DEPRECATED QVariant eval(QgsExpression *parent, const QgsFeature *f)
Abstract virtual eval method Errors are reported to the parent.
bool hasFunction(const QString &name) const
Checks whether a specified function is contained in the context.
Base class for all map layer types.
static QVariant fcnBoundsWidth(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnY(const QVariantList &, const QgsExpressionContext *context, QgsExpression *)
QString cap(int nth) const
static QVariant fcnGeomPerimeter(const QVariantList &, const QgsExpressionContext *context, QgsExpression *parent)
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.
static QVariant fcnAtlasCurrentGeometry(const QVariantList &, const QgsExpressionContext *context, QgsExpression *)
virtual QString dump() const override
Abstract virtual dump method.
static QVariant fcnGeomFromWKT(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
virtual bool prepare(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
virtual Q_DECL_DEPRECATED QVariant func(const QVariantList &values, const QgsFeature *f, QgsExpression *parent) override
static QVariant fcnFormatDate(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
iterator erase(iterator pos)
QStringList referencedColumns() const
Get list of columns referenced by the expression.
static QVariant fcnFormatString(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
QgsGeometry * convexHull() const
Returns the smallest convex polygon that contains all the points in the geometry. ...
bool contains(const Key &key) const
static QString quotedColumnRef(QString name)
return quoted column reference (in double quotes)
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
virtual bool handlesNull() const
static QVariant fcnBuffer(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
QgsGeometry * symDifference(const QgsGeometry *geometry) const
Returns a Geometry representing the points making up this Geometry that do not make up other...
virtual bool prepare(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
static QVariant fcnClamp(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within the context.
static QVariant fcnGetGeometry(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
bool lazyEval()
True if this function should use lazy evaluation.
static QVariant fcnStrpos(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static void initVariableHelp()
static QVariant fcnXat(const QVariantList &values, const QgsExpressionContext *f, QgsExpression *parent)
QgsGeometry * difference(const QgsGeometry *geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...
double distance(const QgsGeometry &geom) const
Returns the minimum distanace between this geometry and another geometry, using GEOS.
static QString group(const QString &group)
Returns the translated name for a function group.
void initGeomCalculator()
static QVariant fcnWordwrap(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
bool compare(double diff)
A abstract base class for defining QgsExpression functions.
Q_DECL_DEPRECATED bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
static QVariant fcnCentroid(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
double yMaximum() const
Get the y maximum value (top side of rectangle)
QgsFields fields() const
Returns the list of fields of this layer.
double computeDouble(double x, double y)
static QVariant fcnIf(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent)
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
static QString encodeColor(const QColor &color)
QDateTime toDateTime() const
static QgsExpressionContext createFeatureBasedContext(const QgsFeature &feature, const QgsFields &fields)
Helper function for creating an expression context which contains just a feature and fields collectio...
virtual QString dump() const =0
Abstract virtual dump method.
static QVariant fcnPi(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QDate getDateValue(const QVariant &value, QgsExpression *parent)
static QVariant pointAt(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent)
QString escape(const QString &str)
static QVariant fcnAtan2(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QString helptext(QString name)
Returns the help text for a specified function.
#define FEAT_FROM_CONTEXT(c, f)
static QVariant fcnMapId(const QVariantList &, const QgsExpressionContext *context, QgsExpression *)
static QVariant fcnRegexpMatch(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
const T & at(int i) const
static QVariant fcnFloor(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
QVariant evaluate()
Evaluate the feature and return the result.
static QVariant fncColorCmyka(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnAcos(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnAbs(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
#define Q_NOWARN_DEPRECATED_PUSH
QgsExpression()
Used by QgsOgcUtils to create an empty.
QgsRectangle boundingBox() const
Returns the bounding box of this feature.
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
virtual QVariant eval(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
bool crosses(const QgsGeometry *geometry) const
Test for if geometry crosses another (uses GEOS)
static QVariant fncColorHsva(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
Container of fields for a vector layer.
static QVariant fcnAge(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnToTime(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
virtual Q_DECL_DEPRECATED bool prepare(QgsExpression *parent, const QgsFields &fields)
Abstract virtual preparation method Errors are reported to the parent.
A geometry is the spatial representation of a feature.
Q_DECL_DEPRECATED int currentRowNumber()
Return the number used for $rownum special column.
static const char * vectorGeometryType(GeometryType type)
description strings for geometry types
QgsExpression::Node * parseExpression(const QString &str, QString &parserErrorMsg)
static QVariant fcnTouches(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QTime getTimeValue(const QVariant &value, QgsExpression *parent)
QString dump() const
Return the expression string that represents this QgsExpression.
bool isDoubleSafe(const QVariant &v)
static QVariant fcnWithin(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnExpScale(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
static QVariant fcnMax(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
QList< HelpVariant > mVariants
static QVariant fcnLCS(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnXMin(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static TVL getTVLValue(const QVariant &value, QgsExpression *parent)
static QVariant fcnFormatNumber(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
double toDouble(bool *ok) const
static QVariant fcnToDateTime(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static Q_DECL_DEPRECATED bool isValid(const QString &text, const QgsFields &fields, QString &errorMessage)
static QVariant fncColorHsla(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
int weekNumber(int *yearNumber) const
QString tr(const char *sourceText, const char *disambiguation, int n)
static QVariant fncColorPart(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QString soundex(const QString &string)
Returns the Soundex representation of a string.
double x() const
Get the x value of the point.
static QVariant fcnComposerPage(const QVariantList &, const QgsExpressionContext *context, QgsExpression *)
int computeInt(int x, int y)
int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual QString dump() const override
Abstract virtual dump method.
static QVariant fcnGeomArea(const QVariantList &, const QgsExpressionContext *context, QgsExpression *parent)
static QVariant fcnLevenshtein(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
void setEvalErrorString(const QString &str)
Set evaluation error (used internally by evaluation functions)
static QgsGeometry getGeometry(const QVariant &value, QgsExpression *parent)
#define ENSURE_NO_EVAL_ERROR
static QVariant fcnToReal(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
QString mParserErrorString
static Q_DECL_DEPRECATED void setSpecialColumn(const QString &name, const QVariant &value)
Assign a special column.
static QVariant fcnYat(const QVariantList &values, const QgsExpressionContext *f, QgsExpression *parent)
virtual QString dump() const override
Abstract virtual dump method.
static QVariant fcnCos(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static const QStringList & BuiltinFunctions()
static QVariant fcnSymDifference(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
static bool unregisterFunction(const QString &name)
Unregisters a function from the expression engine.
static const QList< Function * > & Functions()
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
int matchedLength() const
QList< Key > keys() const
static QVariant fcnGetLayerProperty(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnColorHsl(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
static QVariant fcnMin(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
bool createFromOgcWmsCrs(QString theCrs)
Set up this CRS from the given OGC CRS.
static QVariant fncSetColorPart(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
static QVariant fcnAtlasFeature(const QVariantList &, const QgsExpressionContext *context, QgsExpression *)
static int functionCount()
Returns the number of functions defined in the parser.
static QVariant fcnRndF(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
virtual bool needsGeometry() const override
Abstract virtual method which returns if the geometry is required to evaluate this expression...
static QVariant fcnMinute(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
void acceptVisitor(Visitor &v) const
Entry function for the visitor pattern.
static QVariant fcnTrim(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
bool leftAssociative() const
bool contains(const QgsPoint *p) const
Test for containment of a point (uses GEOS)
QString number(int n, int base)
int count(const T &value) const
static QVariant fcnMonth(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnStartPoint(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
void append(const T &value)
static QVariant fcnLn(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnMakePoint(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QgsDistanceArea * geomCalculator()
Return calculator used for distance and area calculations (used by internal functions) ...
static QVariant fcnGeomY(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
virtual QVariant eval(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual eval method Errors are reported to the parent.
int toInt(bool *ok) const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
static QVariant fcnIntersects(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnColorHsv(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnCoalesce(const QVariantList &values, const QgsExpressionContext *, QgsExpression *)
static int functionIndex(const QString &name)
double xMaximum() const
Get the x maximum value (right side of rectangle)
static QVariant fcnWeek(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
QString rightJustified(int width, QChar fill, bool truncate) const
Utility class for identifying a unique vertex within a geometry.
virtual Q_DECL_DEPRECATED QVariant func(const QVariantList &, const QgsFeature *, QgsExpression *)
virtual QString dump() const override
Abstract virtual dump method.
static QVariant fcnScale(const QVariantList &, const QgsExpressionContext *, QgsExpression *parent)
static QVariant fcnRowNumber(const QVariantList &, const QgsExpressionContext *context, QgsExpression *parent)
static QVariant fcnConcat(const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent)
virtual bool prepare(QgsExpression *parent, const QgsExpressionContext *context) override
Abstract virtual preparation method Errors are reported to the parent.
static QVariant fcnHamming(const QVariantList &values, const QgsExpressionContext *, 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.
static void cleanRegisteredFunctions()
Deletes all registered functions whose ownership have been transferred to the expression engine...
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 QVariant fcnAtlasFeatureId(const QVariantList &, const QgsExpressionContext *context, QgsExpression *)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...