Quantum GIS API Documentation  1.8
src/core/qgssearchtreenode.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgssearchtreenode.h
00003             Definition of node for parsed tree of search string
00004                           --------------------
00005     begin                : 2005-07-26
00006     copyright            : (C) 2005 by Martin Dobias
00007     email                : won.der at centrum.sk
00008 ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #ifndef QGSSEARCHTREENODE_H
00020 #define QGSSEARCHTREENODE_H
00021 
00022 #include <QMap>
00023 #include <QString>
00024 #include <QStringList>
00025 #include <QVariant>
00026 #include <QList>
00027 
00028 #include <qgis.h>
00029 #include <qgsfield.h>
00030 #include <qgsfeature.h>
00031 
00032 class QgsDistanceArea;
00033 class QgsSearchTreeValue;
00034 
00042 class CORE_EXPORT QgsSearchTreeNode
00043 {
00044   public:
00045 
00047     enum Type
00048     {
00049       tOperator = 1,
00050       tNumber,
00051       tColumnRef,
00052       tString,
00053       tNodeList,
00054     };
00055 
00058     enum Operator
00059     {
00060       // binary
00061       opAND = 1,
00062       opOR,
00063       opNOT,
00064 
00065       // arithmetic
00066       opPLUS,
00067       opMINUS,
00068       opMUL,
00069       opMOD,
00070       opDIV,
00071       opPOW,
00072       opSQRT,
00073       opSIN,
00074       opCOS,
00075       opTAN,
00076       opASIN,
00077       opACOS,
00078       opATAN,
00079       opATAN2,
00080 
00081       // conversion
00082       opTOINT,
00083       opTOREAL,
00084       opTOSTRING,
00085 
00086       // coordinates
00087       opX,
00088       opY,
00089       opXAT,
00090       opYAT,
00091 
00092       // measuring
00093       opLENGTH,
00094       opAREA,
00095       opPERIMETER,
00096 
00097       // feature id
00098       opID,
00099 
00100       // comparison
00101       opISNULL,     // IS NULL
00102       opISNOTNULL,  // IS NOT NULL
00103       opEQ,         // =
00104       opNE,         // != resp. <>
00105       opGT,         // >
00106       opLT,         // <
00107       opGE,         // >=
00108       opLE,         // <=
00109       opRegexp,     // ~
00110       opLike,       // LIKE
00111       opILike,      // ILIKE
00112       opIN,         // IN
00113       opNOTIN,      // NOT IN
00114 
00115       // string handling
00116       opCONCAT,
00117       opLOWER,
00118       opUPPER,
00119       opREPLACE,
00120       opREGEXPREPLACE,
00121       opSTRLEN,
00122       opSUBSTR,
00123 
00124       opROWNUM
00125     };
00126 
00128     QgsSearchTreeNode( Type type );
00129     QgsSearchTreeNode( double number );
00130     QgsSearchTreeNode( Operator op, QgsSearchTreeNode* left, QgsSearchTreeNode* right );
00131     QgsSearchTreeNode( QString text, bool isColumnRef );
00132 
00134     QgsSearchTreeNode( const QgsSearchTreeNode& node );
00135 
00137     ~QgsSearchTreeNode();
00138 
00140     Type type() const  { return mType; }
00141 
00143     Operator op() const { return mOp; }
00144     double number() const { return mNumber; }
00145     QString columnRef() const { return mText; }
00146     QString string() const { return mText; }
00147 
00149     void setOp( Operator op )         { mType = tOperator;  mOp = op; }
00150     void setNumber( double number )   { mType = tNumber;    mNumber = number; }
00151     void setColumnRef( const QString& str ) { mType = tColumnRef; mText = str; }
00152     void setString( const QString& str )    { mType = tString;    mText = str; stripText(); }
00153 
00155     QgsSearchTreeNode* Left()  { return mLeft;  }
00156     QgsSearchTreeNode* Right() { return mRight; }
00157     void setLeft( QgsSearchTreeNode* left ) { mLeft = left;   }
00158     void setRight( QgsSearchTreeNode* right ) { mRight = right; }
00159 
00161     QString makeSearchString();
00162 
00165     bool checkAgainst( const QgsFieldMap& fields, QgsFeature &f );
00166 
00168     Q_DECL_DEPRECATED bool checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
00169 
00171     bool hasError() { return ( !mError.isEmpty() ); }
00172 
00174     const QString& errorMsg() { return mError; }
00175 
00178     bool getValue( QgsSearchTreeValue& value,
00179                    QgsSearchTreeNode* node,
00180                    const QgsFieldMap& fields,
00181                    QgsFeature &f );
00182 
00184     Q_DECL_DEPRECATED bool getValue( QgsSearchTreeValue& value,
00185                                      QgsSearchTreeNode* node,
00186                                      const QgsFieldMap &fields,
00187                                      const QgsAttributeMap &attributes,
00188                                      QgsGeometry* geom = 0 );
00189 
00192     QStringList referencedColumns();
00193 
00196     QList<QgsSearchTreeNode*> columnRefNodes();
00197 
00200     bool needsGeometry();
00201 
00204     static QString quotedColumnRef( QString name );
00205 
00209     void setCurrentRowNumber( int rownum );
00210 
00213     void append( QgsSearchTreeNode * );
00214 
00217     void append( QList<QgsSearchTreeNode*> );
00218 
00219   protected:
00221     QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, QgsFeature &f );
00222 
00224     Q_DECL_DEPRECATED QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
00225 
00227     void stripText();
00228 
00230     void stripColRef();
00231 
00233     void init();
00234 
00235   private:
00236 
00238     Type mType;
00239 
00241     Operator mOp;
00242     double mNumber;
00243     QString mText;
00244     QList<QgsSearchTreeNode *> mNodeList;
00245 
00246     QString mError;
00247 
00249     QgsSearchTreeNode* mLeft;
00250     QgsSearchTreeNode* mRight;
00251 
00253     QgsDistanceArea* mCalc;
00254 };
00255 
00256 // TODO: put it into separate file
00257 class CORE_EXPORT QgsSearchTreeValue
00258 {
00259   public:
00260 
00261     enum Type
00262     {
00263       valError,
00264       valString,
00265       valNumber,
00266       valNull
00267     };
00268 
00269     QgsSearchTreeValue() { mType = valNull; }
00270     QgsSearchTreeValue( QString string ) { mType = string.isNull() ? valNull : valString; mString = string; }
00271     QgsSearchTreeValue( double number ) { mType = valNumber; mNumber = number; }
00272     QgsSearchTreeValue( int error, QString errorMsg ) { mType = valError; mNumber = error; mString = errorMsg; }
00273 
00274     static QgsSearchTreeValue compare( QgsSearchTreeValue& value1, QgsSearchTreeValue& value2,
00275                                        Qt::CaseSensitivity = Qt::CaseSensitive );
00276 
00277     bool isNumeric() { return mType == valNumber; }
00278     bool isError() { return mType == valError; }
00279     bool isNull() { return mType == valNull; }
00280 
00281     QString& string() { return mString; }
00282     double number() { return mNumber; }
00283 
00284   private:
00285     Type mType;
00286     QString mString;
00287     double mNumber;
00288 
00289 };
00290 
00291 #endif
00292 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines