16 #ifndef QGSEXPRESSION_H
17 #define QGSEXPRESSION_H
20 #include <QStringList>
23 #include <QDomDocument>
112 QStringList referencedColumns()
const;
115 bool needsGeometry()
const;
121 QVariant evaluate(
const QgsFeature* f = NULL );
150 static void setSpecialColumn(
const QString& name, QVariant value );
152 static void unsetSpecialColumn(
const QString& name );
154 static QVariant specialColumn(
const QString& name );
157 static bool hasSpecialColumn(
const QString& name );
159 static bool isValid(
const QString& text,
const QgsFields& fields, QString &errorMessage );
166 const QString expression()
const
168 if ( !mExp.isNull() )
175 QString dump()
const;
198 static QString replaceExpressionText(
const QString &action,
const QgsFeature *feat,
200 const QMap<QString, QVariant> *substitutionMap = 0,
211 static double evaluateToDouble(
const QString& text,
const double fallbackValue );
273 static const char* BinaryOperatorText[];
274 static const char* UnaryOperatorText[];
285 Function( QString fnname,
int params, QString group, QString helpText = QString(),
bool usesGeometry =
false, QStringList referencedColumns = QStringList(),
bool lazyEval =
false )
286 : mName( fnname ), mParams( params ), mUsesGeometry( usesGeometry ), mGroup( group ), mHelpText( helpText ), mReferencedColumns( referencedColumns ), mLazyEval( lazyEval ) {}
288 QString
name() {
return mName; }
310 if ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 )
322 QStringList mReferencedColumns;
329 StaticFunction( QString fnname,
int params, FcnEval fcn, QString group, QString helpText = QString(),
bool usesGeometry =
false, QStringList referencedColumns = QStringList(),
bool lazyEval =
false )
330 :
Function( fnname, params, group, helpText, usesGeometry, referencedColumns, lazyEval ), mFnc( fcn ) {}
334 return mFnc( values, f, parent );
341 static const QList<Function*> &Functions();
345 static const QStringList &BuiltinFunctions();
347 static bool registerFunction(
Function*
function );
348 static bool unregisterFunction( QString name );
351 static bool isFunctionName( QString name );
354 static int functionIndex( QString name );
359 static int functionCount();
364 static QList<Function*> specialColumns();
367 static QString quotedColumnRef( QString name );
369 static QString quotedString( QString text );
390 virtual NodeType nodeType()
const = 0;
399 virtual QString dump()
const = 0;
401 virtual QStringList referencedColumns()
const = 0;
402 virtual bool needsGeometry()
const = 0;
405 virtual void accept(
Visitor& v )
const = 0;
414 int count() {
return mList.count(); }
415 QList<Node*>
list() {
return mList; }
417 virtual QString dump()
const;
427 static const int YEARS = 31557600;
428 static const int MONTHS = 60 * 60 * 24 * 30;
429 static const int WEEKS = 60 * 60 * 24 * 7;
430 static const int DAY = 60 * 60 * 24;
431 static const int HOUR = 60 * 60;
432 static const int MINUTE = 60;
434 Interval(
double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
436 double years() {
return mSeconds / YEARS;}
437 double months() {
return mSeconds / MONTHS; }
438 double weeks() {
return mSeconds / WEEKS;}
439 double days() {
return mSeconds / DAY;}
440 double hours() {
return mSeconds / HOUR;}
465 virtual QString dump()
const override;
467 virtual QStringList
referencedColumns()
const override {
return mOperand->referencedColumns(); }
468 virtual bool needsGeometry()
const override {
return mOperand->needsGeometry(); }
489 virtual QString dump()
const override;
491 virtual QStringList
referencedColumns()
const override {
return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
492 virtual bool needsGeometry()
const override {
return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
495 int precedence()
const;
498 bool compare(
double diff );
499 int computeInt(
int x,
int y );
500 double computeDouble(
double x,
double y );
521 virtual QString dump()
const override;
546 virtual QString dump()
const override;
548 virtual QStringList referencedColumns()
const override;
549 virtual bool needsGeometry()
const override {
bool needs = Functions()[mFnIndex]->usesgeometry();
if ( mArgs ) {
foreach (
Node* n, mArgs->list() ) needs |= n->
needsGeometry(); }
return needs; }
563 QVariant
value()
const {
return mValue; }
568 virtual QString dump()
const override;
583 QString
name()
const {
return mName; }
588 virtual QString dump()
const override;
621 virtual QString dump()
const override;
623 virtual QStringList referencedColumns()
const override;
624 virtual bool needsGeometry()
const override;
650 void acceptVisitor( Visitor& v )
const;
652 static QString helptext( QString name );
653 static QString group( QString group );
659 QgsExpression() : mRootNode( 0 ), mRowNumber( 0 ), mScale( 0.0 ), mCalc( 0 ) {}
661 void initGeomCalculator();
680 static void initFunctionHelp();
691 #endif // QGSEXPRESSION_H