16 #ifndef QGSEXPRESSION_H
17 #define QGSEXPRESSION_H
20 #include <QStringList>
23 #include <QDomDocument>
111 QStringList referencedColumns();
114 bool needsGeometry();
120 QVariant evaluate(
const QgsFeature* f = NULL );
149 static void setSpecialColumn(
const QString& name, QVariant value );
151 static void unsetSpecialColumn(
const QString& name );
153 static QVariant specialColumn(
const QString& name );
156 static bool hasSpecialColumn(
const QString& name );
158 static bool isValid(
const QString& text,
const QgsFields& fields, QString &errorMessage );
168 QString dump()
const;
191 static QString replaceExpressionText(
const QString &action,
const QgsFeature *feat,
193 const QMap<QString, QVariant> *substitutionMap = 0,
246 static const char* BinaryOperatorText[];
247 static const char* UnaryOperatorText[];
258 Function( QString fnname,
int params, QString group, QString helpText = QString(),
bool usesGeometry =
false, QStringList referencedColumns = QStringList() )
259 : mName( fnname ), mParams( params ), mUsesGeometry( usesGeometry ), mGroup( group ), mHelpText( helpText ), mReferencedColumns( referencedColumns ) {}
261 QString
name() {
return mName; }
278 if ( QString::compare( mName, other.mName, Qt::CaseInsensitive ) == 0 )
290 QStringList mReferencedColumns;
296 StaticFunction( QString fnname,
int params, FcnEval fcn, QString group, QString helpText = QString(),
bool usesGeometry =
false, QStringList referencedColumns = QStringList() )
297 :
Function( fnname, params, group, helpText, usesGeometry, referencedColumns ), mFnc( fcn ) {}
301 return mFnc( values, f, parent );
308 static const QList<Function*> &Functions();
312 static const QStringList &BuiltinFunctions();
314 static bool registerFunction(
Function*
function );
315 static bool unregisterFunction( QString name );
318 static bool isFunctionName( QString name );
321 static int functionIndex( QString name );
326 static int functionCount();
331 static QList<Function*> specialColumns();
334 static QString quotedColumnRef( QString name );
336 static QString quotedString( QString text );
357 virtual NodeType nodeType()
const = 0;
366 virtual QString dump()
const = 0;
368 virtual QStringList referencedColumns()
const = 0;
369 virtual bool needsGeometry()
const = 0;
372 virtual void accept(
Visitor& v )
const = 0;
381 int count() {
return mList.count(); }
382 QList<Node*>
list() {
return mList; }
384 virtual QString dump()
const;
394 static const int YEARS = 31557600;
395 static const int MONTHS = 60 * 60 * 24 * 30;
396 static const int WEEKS = 60 * 60 * 24 * 7;
397 static const int DAY = 60 * 60 * 24;
398 static const int HOUR = 60 * 60;
399 static const int MINUTE = 60;
401 Interval(
double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
403 double years() {
return mSeconds / YEARS;}
404 double months() {
return mSeconds / MONTHS; }
405 double weeks() {
return mSeconds / WEEKS;}
406 double days() {
return mSeconds / DAY;}
407 double hours() {
return mSeconds / HOUR;}
432 virtual QString dump()
const;
456 virtual QString dump()
const;
458 virtual QStringList
referencedColumns()
const {
return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
459 virtual bool needsGeometry()
const {
return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
462 int precedence()
const;
465 bool compare(
double diff );
466 int computeInt(
int x,
int y );
467 double computeDouble(
double x,
double y );
488 virtual QString dump()
const;
513 virtual QString dump()
const;
515 virtual QStringList referencedColumns()
const;
516 virtual bool needsGeometry()
const {
bool needs = Functions()[mFnIndex]->usesgeometry();
if ( mArgs ) {
foreach (
Node* n, mArgs->list() ) needs |= n->
needsGeometry(); }
return needs; }
530 QVariant
value()
const {
return mValue; }
535 virtual QString dump()
const;
550 QString
name()
const {
return mName; }
555 virtual QString dump()
const;
588 virtual QString dump()
const;
590 virtual QStringList referencedColumns()
const;
591 virtual bool needsGeometry()
const;
617 void acceptVisitor( Visitor& v )
const;
619 static QString helptext( QString name );
620 static QString group( QString group );
626 void initGeomCalculator();
644 static void initFunctionHelp();
654 #endif // QGSEXPRESSION_H