16 #ifndef QGSEXPRESSION_H
17 #define QGSEXPRESSION_H
20 #include <QStringList>
23 #include <QDomDocument>
109 QStringList referencedColumns();
111 bool needsGeometry();
117 QVariant evaluate(
const QgsFeature* f = NULL );
145 static void setSpecialColumn(
const QString& name, QVariant value );
147 static void unsetSpecialColumn(
const QString& name );
149 static QVariant specialColumn(
const QString& name );
152 static bool hasSpecialColumn(
const QString& name );
162 QString dump()
const;
179 static QString replaceExpressionText(
const QString &action,
const QgsFeature *feat,
181 const QMap<QString, QVariant> *substitutionMap = 0 );
232 static const char* BinaryOperatorText[];
233 static const char* UnaryOperatorText[];
244 Function( QString fnname,
int params, QString group, QString helpText = QString(),
bool usesGeometry =
false )
245 : mName( fnname ), mParams( params ), mUsesGeometry( usesGeometry ), mGroup( group ), mHelpText( helpText ) {}
247 QString
name() {
return mName; }
261 if ( QString::compare( mName, other.
mName, Qt::CaseInsensitive ) == 0 )
278 StaticFunction( QString fnname,
int params, FcnEval fcn, QString group, QString helpText = QString(),
bool usesGeometry =
false )
279 :
Function( fnname, params, group, helpText, usesGeometry ), mFnc( fcn ) {}
283 return mFnc( values, f, parent );
290 static const QList<Function*> &Functions();
294 static const QStringList &BuiltinFunctions();
296 static bool registerFunction(
Function*
function );
297 static bool unregisterFunction( QString name );
300 static bool isFunctionName( QString name );
303 static int functionIndex( QString name );
308 static int functionCount();
313 static QList<Function*> specialColumns();
316 static QString
quotedColumnRef( QString name ) {
return QString(
"\"%1\"" ).arg( name.replace(
"\"",
"\"\"" ) ); }
318 static QString
quotedString( QString text ) {
return QString(
"'%1'" ).arg( text.replace(
"'",
"''" ) ); }
339 virtual NodeType nodeType()
const = 0;
348 virtual QString dump()
const = 0;
350 virtual QStringList referencedColumns()
const = 0;
351 virtual bool needsGeometry()
const = 0;
354 virtual void accept(
Visitor& v )
const = 0;
363 int count() {
return mList.count(); }
364 QList<Node*>
list() {
return mList; }
366 virtual QString dump()
const;
376 static const int YEARS = 31557600;
377 static const int MONTHS = 60 * 60 * 24 * 30;
378 static const int WEEKS = 60 * 60 * 24 * 7;
379 static const int DAY = 60 * 60 * 24;
380 static const int HOUR = 60 * 60;
381 static const int MINUTE = 60;
383 Interval(
double seconds = 0 ) : mSeconds( seconds ), mValid( true ) { }
385 double years() {
return mSeconds / YEARS;}
386 double months() {
return mSeconds / MONTHS; }
387 double weeks() {
return mSeconds / WEEKS;}
388 double days() {
return mSeconds / DAY;}
389 double hours() {
return mSeconds / HOUR;}
414 virtual QString dump()
const;
438 virtual QString dump()
const;
440 virtual QStringList
referencedColumns()
const {
return mOpLeft->referencedColumns() + mOpRight->referencedColumns(); }
441 virtual bool needsGeometry()
const {
return mOpLeft->needsGeometry() || mOpRight->needsGeometry(); }
445 bool compare(
double diff );
446 int computeInt(
int x,
int y );
447 double computeDouble(
double x,
double y );
468 virtual QString dump()
const;
493 virtual QString dump()
const;
496 virtual bool needsGeometry()
const {
bool needs = Functions()[mFnIndex]->usesgeometry();
if ( mArgs ) {
foreach (
Node* n, mArgs->list() ) needs |= n->
needsGeometry(); }
return needs; }
510 QVariant
value()
const {
return mValue; }
515 virtual QString dump()
const;
530 QString
name()
const {
return mName; }
535 virtual QString dump()
const;
568 virtual QString dump()
const;
570 virtual QStringList referencedColumns()
const;
571 virtual bool needsGeometry()
const;
597 void acceptVisitor( Visitor& v )
const;
599 static QString helptext( QString name );
600 static QString group( QString group );
606 void initGeomCalculator();
622 static void initFunctionHelp();
629 #endif // QGSEXPRESSION_H