16 #ifndef QGSEXPRESSION_H
17 #define QGSEXPRESSION_H
20 #include <QStringList>
23 #include <QDomDocument>
108 QStringList referencedColumns();
110 bool needsGeometry();
116 QVariant evaluate(
const QgsFeature* f = NULL );
143 static void setSpecialColumn(
const QString& name, QVariant value );
145 static void unsetSpecialColumn(
const QString& name );
147 static QVariant specialColumn(
const QString& name );
156 QString dump()
const;
173 static QString replaceExpressionText( QString action,
QgsFeature* feat,
175 const QMap<QString, QVariant> *substitutionMap = 0 );
178 static QString replaceExpressionText( QString action,
QgsFeature& feat,
180 const QMap<QString, QVariant> *substitutionMap = 0 );
231 static const char* BinaryOperatorText[];
232 static const char* UnaryOperatorText[];
243 Function( QString fnname,
int params, QString group, QString helpText = QString(),
bool usesGeometry =
false )
244 : mName( fnname ), mParams( params ), mUsesGeometry( usesGeometry ), mGroup( group ), mHelpText( helpText ) {}
246 QString
name() {
return mName; }
260 if ( QString::compare( mName, other.
mName, Qt::CaseInsensitive ) == 0 )
277 StaticFunction( QString fnname,
int params, FcnEval fcn, QString group, QString helpText = QString(),
bool usesGeometry =
false )
278 :
Function( fnname, params, group, helpText, usesGeometry ), mFnc( fcn ) {}
282 return mFnc( values, f, parent );
289 const static QList<Function*> &Functions();
293 const static QStringList &BuiltinFunctions();
295 static bool registerFunction(
Function*
function );
296 static bool unregisterFunction( QString name );
299 static bool isFunctionName( QString name );
302 static int functionIndex( QString name );
307 static int functionCount();
312 static QList<Function*> specialColumns();
315 static QString
quotedColumnRef( QString name ) {
return QString(
"\"%1\"" ).arg( name.replace(
"\"",
"\"\"" ) ); }
317 static QString
quotedString( QString text ) {
return QString(
"'%1'" ).arg( text.replace(
"'",
"''" ) ); }
338 virtual NodeType nodeType()
const = 0;
347 virtual QString dump()
const = 0;
349 virtual QStringList referencedColumns()
const = 0;
350 virtual bool needsGeometry()
const = 0;
353 virtual void accept(
Visitor& v )
const = 0;
362 int count() {
return mList.count(); }
363 QList<Node*>
list() {
return mList; }
365 virtual QString dump()
const;
375 static const int YEARS = 31557600;
376 static const int MONTHS = 60 * 60 * 24 * 30;
377 static const int WEEKS = 60 * 60 * 24 * 7;
378 static const int DAY = 60 * 60 * 24;
379 static const int HOUR = 60 * 60;
380 static const int MINUTE = 60;
382 Interval(
double seconds = 0 ): mSeconds( seconds ), mValid( true ) { }
384 double years() {
return mSeconds / YEARS;}
385 double months() {
return mSeconds / MONTHS; }
386 double weeks() {
return mSeconds / WEEKS;}
387 double days() {
return mSeconds / DAY;}
388 double hours() {
return mSeconds / HOUR;}
413 virtual QString dump()
const;
437 virtual QString dump()
const;
439 virtual QStringList
referencedColumns()
const {
return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
440 virtual bool needsGeometry()
const {
return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
444 bool compare(
double diff );
445 int computeInt(
int x,
int y );
446 double computeDouble(
double x,
double y );
467 virtual QString dump()
const;
492 virtual QString dump()
const;
495 virtual bool needsGeometry()
const {
bool needs = Functions()[mFnIndex]->usesgeometry();
if ( mArgs ) {
foreach (
Node* n, mArgs->list() ) needs |= n->
needsGeometry(); }
return needs; }
509 QVariant
value()
const {
return mValue; }
514 virtual QString dump()
const;
529 QString
name()
const {
return mName; }
534 virtual QString dump()
const;
566 virtual QString dump()
const;
568 virtual QStringList referencedColumns()
const;
569 virtual bool needsGeometry()
const;
595 void acceptVisitor( Visitor& v )
const;
597 static QString helptext( QString name );
598 static QString group( QString group );
604 void initGeomCalculator();
620 static void initFunctionHelp();
627 #endif // QGSEXPRESSION_H