00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef QGSSEARCHTREENODE_H
00021 #define QGSSEARCHTREENODE_H
00022
00023 #include <QMap>
00024 #include <QString>
00025 #include <QStringList>
00026 #include <QVariant>
00027 #include <QList>
00028
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
00057 enum Operator
00058 {
00059
00060 opAND = 1,
00061 opOR,
00062 opNOT,
00063
00064
00065 opPLUS,
00066 opMINUS,
00067 opMUL,
00068 opDIV,
00069 opPOW,
00070 opSQRT,
00071 opSIN,
00072 opCOS,
00073 opTAN,
00074 opASIN,
00075 opACOS,
00076 opATAN,
00077
00078
00079 opTOINT,
00080 opTOREAL,
00081 opTOSTRING,
00082
00083
00084 opLENGTH,
00085 opAREA,
00086
00087
00088 opID,
00089
00090
00091 opISNULL,
00092 opISNOTNULL,
00093 opEQ,
00094 opNE,
00095 opGT,
00096 opLT,
00097 opGE,
00098 opLE,
00099 opRegexp,
00100 opLike,
00101 opILike,
00102 opIN,
00103 opNOTIN,
00104
00105
00106 opCONCAT,
00107 opLOWER,
00108 opUPPER,
00109
00110 opROWNUM
00111 };
00112
00114 QgsSearchTreeNode( Type type );
00115 QgsSearchTreeNode( double number );
00116 QgsSearchTreeNode( Operator op, QgsSearchTreeNode* left, QgsSearchTreeNode* right );
00117 QgsSearchTreeNode( QString text, bool isColumnRef );
00118
00120 QgsSearchTreeNode( const QgsSearchTreeNode& node );
00121
00123 ~QgsSearchTreeNode();
00124
00126 Type type() const { return mType; }
00127
00129 Operator op() const { return mOp; }
00130 double number() const { return mNumber; }
00131 QString columnRef() const { return mText; }
00132 QString string() const { return mText; }
00133
00135 void setOp( Operator op ) { mType = tOperator; mOp = op; }
00136 void setNumber( double number ) { mType = tNumber; mNumber = number; }
00137 void setColumnRef( const QString& str ) { mType = tColumnRef; mText = str; }
00138 void setString( const QString& str ) { mType = tString; mText = str; stripText(); }
00139
00141 QgsSearchTreeNode* Left() { return mLeft; }
00142 QgsSearchTreeNode* Right() { return mRight; }
00143 void setLeft( QgsSearchTreeNode* left ) { mLeft = left; }
00144 void setRight( QgsSearchTreeNode* right ) { mRight = right; }
00145
00147 QString makeSearchString();
00148
00151 bool checkAgainst( const QgsFieldMap& fields, QgsFeature &f );
00152
00154 bool checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
00155
00157 bool hasError() { return ( !mError.isEmpty() ); }
00158
00160 const QString& errorMsg() { return mError; }
00161
00164 bool getValue( QgsSearchTreeValue& value,
00165 QgsSearchTreeNode* node,
00166 const QgsFieldMap& fields,
00167 QgsFeature &f );
00168
00170 bool getValue( QgsSearchTreeValue& value,
00171 QgsSearchTreeNode* node,
00172 const QgsFieldMap &fields,
00173 const QgsAttributeMap &attributes,
00174 QgsGeometry* geom = 0 );
00175
00178 QStringList referencedColumns();
00179
00182 QList<QgsSearchTreeNode*> columnRefNodes();
00183
00186 bool needsGeometry();
00187
00190 static QString quotedColumnRef( QString name );
00191
00195 void setCurrentRowNumber( int rownum );
00196
00199 void append( QgsSearchTreeNode * );
00200
00203 void append( QList<QgsSearchTreeNode*> );
00204
00205 protected:
00207 QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, QgsFeature &f );
00208
00210 QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
00211
00213 void stripText();
00214
00216 void stripColRef();
00217
00219 void init();
00220
00221 private:
00222
00224 Type mType;
00225
00227 Operator mOp;
00228 double mNumber;
00229 QString mText;
00230 QList<QgsSearchTreeNode *> mNodeList;
00231
00232 QString mError;
00233
00235 QgsSearchTreeNode* mLeft;
00236 QgsSearchTreeNode* mRight;
00237
00239 QgsDistanceArea* mCalc;
00240 };
00241
00242
00243 class CORE_EXPORT QgsSearchTreeValue
00244 {
00245 public:
00246
00247 enum Type
00248 {
00249 valError,
00250 valString,
00251 valNumber,
00252 valNull
00253 };
00254
00255 QgsSearchTreeValue() { mType = valNull; }
00256 QgsSearchTreeValue( QString string ) { mType = string.isNull() ? valNull : valString; mString = string; }
00257 QgsSearchTreeValue( double number ) { mType = valNumber; mNumber = number; }
00258 QgsSearchTreeValue( int error, QString errorMsg ) { mType = valError; mNumber = error; mString = errorMsg; }
00259
00260 static int compare( QgsSearchTreeValue& value1, QgsSearchTreeValue& value2,
00261 Qt::CaseSensitivity = Qt::CaseSensitive );
00262
00263 bool isNumeric() { return mType == valNumber; }
00264 bool isError() { return mType == valError; }
00265 bool isNull() { return mType == valNull; }
00266
00267 QString& string() { return mString; }
00268 double number() { return mNumber; }
00269
00270 private:
00271 Type mType;
00272 QString mString;
00273 double mNumber;
00274
00275 };
00276
00277 #endif
00278