Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgssearchtreenode.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssearchtreenode.h
3  Definition of node for parsed tree of search string
4  --------------------
5  begin : 2005-07-26
6  copyright : (C) 2005 by Martin Dobias
7  email : won.der at centrum.sk
8 ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 /* $Id$ */
19 
20 #ifndef QGSSEARCHTREENODE_H
21 #define QGSSEARCHTREENODE_H
22 
23 #include <QMap>
24 #include <QString>
25 #include <QStringList>
26 #include <QVariant>
27 #include <QList>
28 
29 #include <qgis.h>
30 #include <qgsfield.h>
31 #include <qgsfeature.h>
32 
33 class QgsDistanceArea;
34 class QgsSearchTreeValue;
35 
43 class CORE_EXPORT QgsSearchTreeNode
44 {
45  public:
46 
48  enum Type
49  {
50  tOperator = 1,
55  };
56 
58  enum Operator
59  {
60  // binary
61  opAND = 1,
64 
65  // arithmetic
80 
81  // conversion
85 
86  // coordinates
87  opX,
88  opY,
89 
90  // measuring
94 
95  // feature id
97 
98  // comparison
99  opISNULL, // IS NULL
100  opISNOTNULL, // IS NOT NULL
101  opEQ, // =
102  opNE, // != resp. <>
103  opGT, // >
104  opLT, // <
105  opGE, // >=
106  opLE, // <=
107  opRegexp, // ~
108  opLike, // LIKE
109  opILike, // ILIKE
110  opIN, // IN
111  opNOTIN, // NOT IN
112 
113  // string handling
120 
121  opROWNUM
122  };
123 
125  QgsSearchTreeNode( Type type );
126  QgsSearchTreeNode( double number );
127  QgsSearchTreeNode( Operator op, QgsSearchTreeNode* left, QgsSearchTreeNode* right );
128  QgsSearchTreeNode( QString text, bool isColumnRef );
129 
131  QgsSearchTreeNode( const QgsSearchTreeNode& node );
132 
135 
137  Type type() const { return mType; }
138 
140  Operator op() const { return mOp; }
141  double number() const { return mNumber; }
142  QString columnRef() const { return mText; }
143  QString string() const { return mText; }
144 
146  void setOp( Operator op ) { mType = tOperator; mOp = op; }
147  void setNumber( double number ) { mType = tNumber; mNumber = number; }
148  void setColumnRef( const QString& str ) { mType = tColumnRef; mText = str; }
149  void setString( const QString& str ) { mType = tString; mText = str; stripText(); }
150 
152  QgsSearchTreeNode* Left() { return mLeft; }
153  QgsSearchTreeNode* Right() { return mRight; }
154  void setLeft( QgsSearchTreeNode* left ) { mLeft = left; }
155  void setRight( QgsSearchTreeNode* right ) { mRight = right; }
156 
158  QString makeSearchString();
159 
162  bool checkAgainst( const QgsFieldMap& fields, QgsFeature &f );
163 
165  Q_DECL_DEPRECATED bool checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
166 
168  bool hasError() { return ( !mError.isEmpty() ); }
169 
171  const QString& errorMsg() { return mError; }
172 
175  bool getValue( QgsSearchTreeValue& value,
176  QgsSearchTreeNode* node,
177  const QgsFieldMap& fields,
178  QgsFeature &f );
179 
181  Q_DECL_DEPRECATED bool getValue( QgsSearchTreeValue& value,
182  QgsSearchTreeNode* node,
183  const QgsFieldMap &fields,
184  const QgsAttributeMap &attributes,
185  QgsGeometry* geom = 0 );
186 
189  QStringList referencedColumns();
190 
193  QList<QgsSearchTreeNode*> columnRefNodes();
194 
197  bool needsGeometry();
198 
201  static QString quotedColumnRef( QString name );
202 
206  void setCurrentRowNumber( int rownum );
207 
210  void append( QgsSearchTreeNode * );
211 
214  void append( QList<QgsSearchTreeNode*> );
215 
216  protected:
218  QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, QgsFeature &f );
219 
221  Q_DECL_DEPRECATED QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
222 
224  void stripText();
225 
227  void stripColRef();
228 
230  void init();
231 
232  private:
233 
236 
239  double mNumber;
240  QString mText;
241  QList<QgsSearchTreeNode *> mNodeList;
242 
243  QString mError;
244 
248 
251 };
252 
253 // TODO: put it into separate file
254 class CORE_EXPORT QgsSearchTreeValue
255 {
256  public:
257 
258  enum Type
259  {
263  valNull
264  };
265 
266  QgsSearchTreeValue() { mType = valNull; }
267  QgsSearchTreeValue( QString string ) { mType = string.isNull() ? valNull : valString; mString = string; }
268  QgsSearchTreeValue( double number ) { mType = valNumber; mNumber = number; }
269  QgsSearchTreeValue( int error, QString errorMsg ) { mType = valError; mNumber = error; mString = errorMsg; }
270 
271  static int compare( QgsSearchTreeValue& value1, QgsSearchTreeValue& value2,
272  Qt::CaseSensitivity = Qt::CaseSensitive );
273 
274  bool isNumeric() { return mType == valNumber; }
275  bool isError() { return mType == valError; }
276  bool isNull() { return mType == valNull; }
277 
278  QString& string() { return mString; }
279  double number() { return mNumber; }
280 
281  private:
283  QString mString;
284  double mNumber;
285 
286 };
287 
288 #endif
289