Quantum GIS API Documentation
1.7.4
|
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 /* $Id$ */ 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 <qgis.h> 00030 #include <qgsfield.h> 00031 #include <qgsfeature.h> 00032 00033 class QgsDistanceArea; 00034 class QgsSearchTreeValue; 00035 00043 class CORE_EXPORT QgsSearchTreeNode 00044 { 00045 public: 00046 00048 enum Type 00049 { 00050 tOperator = 1, 00051 tNumber, 00052 tColumnRef, 00053 tString, 00054 tNodeList, 00055 }; 00056 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 00090 // measuring 00091 opLENGTH, 00092 opAREA, 00093 opPERIMETER, 00094 00095 // feature id 00096 opID, 00097 00098 // comparison 00099 opISNULL, // IS NULL 00100 opISNOTNULL, // IS NOT NULL 00101 opEQ, // = 00102 opNE, // != resp. <> 00103 opGT, // > 00104 opLT, // < 00105 opGE, // >= 00106 opLE, // <= 00107 opRegexp, // ~ 00108 opLike, // LIKE 00109 opILike, // ILIKE 00110 opIN, // IN 00111 opNOTIN, // NOT IN 00112 00113 // string handling 00114 opCONCAT, 00115 opLOWER, 00116 opUPPER, 00117 opREPLACE, 00118 opSTRLEN, 00119 opSUBSTR, 00120 00121 opROWNUM 00122 }; 00123 00125 QgsSearchTreeNode( Type type ); 00126 QgsSearchTreeNode( double number ); 00127 QgsSearchTreeNode( Operator op, QgsSearchTreeNode* left, QgsSearchTreeNode* right ); 00128 QgsSearchTreeNode( QString text, bool isColumnRef ); 00129 00131 QgsSearchTreeNode( const QgsSearchTreeNode& node ); 00132 00134 ~QgsSearchTreeNode(); 00135 00137 Type type() const { return mType; } 00138 00140 Operator op() const { return mOp; } 00141 double number() const { return mNumber; } 00142 QString columnRef() const { return mText; } 00143 QString string() const { return mText; } 00144 00146 void setOp( Operator op ) { mType = tOperator; mOp = op; } 00147 void setNumber( double number ) { mType = tNumber; mNumber = number; } 00148 void setColumnRef( const QString& str ) { mType = tColumnRef; mText = str; } 00149 void setString( const QString& str ) { mType = tString; mText = str; stripText(); } 00150 00152 QgsSearchTreeNode* Left() { return mLeft; } 00153 QgsSearchTreeNode* Right() { return mRight; } 00154 void setLeft( QgsSearchTreeNode* left ) { mLeft = left; } 00155 void setRight( QgsSearchTreeNode* right ) { mRight = right; } 00156 00158 QString makeSearchString(); 00159 00162 bool checkAgainst( const QgsFieldMap& fields, QgsFeature &f ); 00163 00165 Q_DECL_DEPRECATED bool checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 ); 00166 00168 bool hasError() { return ( !mError.isEmpty() ); } 00169 00171 const QString& errorMsg() { return mError; } 00172 00175 bool getValue( QgsSearchTreeValue& value, 00176 QgsSearchTreeNode* node, 00177 const QgsFieldMap& fields, 00178 QgsFeature &f ); 00179 00181 Q_DECL_DEPRECATED bool getValue( QgsSearchTreeValue& value, 00182 QgsSearchTreeNode* node, 00183 const QgsFieldMap &fields, 00184 const QgsAttributeMap &attributes, 00185 QgsGeometry* geom = 0 ); 00186 00189 QStringList referencedColumns(); 00190 00193 QList<QgsSearchTreeNode*> columnRefNodes(); 00194 00197 bool needsGeometry(); 00198 00201 static QString quotedColumnRef( QString name ); 00202 00206 void setCurrentRowNumber( int rownum ); 00207 00210 void append( QgsSearchTreeNode * ); 00211 00214 void append( QList<QgsSearchTreeNode*> ); 00215 00216 protected: 00218 QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, QgsFeature &f ); 00219 00221 Q_DECL_DEPRECATED QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 ); 00222 00224 void stripText(); 00225 00227 void stripColRef(); 00228 00230 void init(); 00231 00232 private: 00233 00235 Type mType; 00236 00238 Operator mOp; 00239 double mNumber; 00240 QString mText; 00241 QList<QgsSearchTreeNode *> mNodeList; 00242 00243 QString mError; 00244 00246 QgsSearchTreeNode* mLeft; 00247 QgsSearchTreeNode* mRight; 00248 00250 QgsDistanceArea* mCalc; 00251 }; 00252 00253 // TODO: put it into separate file 00254 class CORE_EXPORT QgsSearchTreeValue 00255 { 00256 public: 00257 00258 enum Type 00259 { 00260 valError, 00261 valString, 00262 valNumber, 00263 valNull 00264 }; 00265 00266 QgsSearchTreeValue() { mType = valNull; } 00267 QgsSearchTreeValue( QString string ) { mType = string.isNull() ? valNull : valString; mString = string; } 00268 QgsSearchTreeValue( double number ) { mType = valNumber; mNumber = number; } 00269 QgsSearchTreeValue( int error, QString errorMsg ) { mType = valError; mNumber = error; mString = errorMsg; } 00270 00271 static int compare( QgsSearchTreeValue& value1, QgsSearchTreeValue& value2, 00272 Qt::CaseSensitivity = Qt::CaseSensitive ); 00273 00274 bool isNumeric() { return mType == valNumber; } 00275 bool isError() { return mType == valError; } 00276 bool isNull() { return mType == valNull; } 00277 00278 QString& string() { return mString; } 00279 double number() { return mNumber; } 00280 00281 private: 00282 Type mType; 00283 QString mString; 00284 double mNumber; 00285 00286 }; 00287 00288 #endif 00289