~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/core/qgssearchtreenode.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
                          qgssearchtreenode.h 
 
2
                          qgssearchtreenode.h
3
3
            Definition of node for parsed tree of search string
4
4
                          --------------------
5
5
    begin                : 2005-07-26
15
15
 *   (at your option) any later version.                                   *
16
16
 *                                                                         *
17
17
 ***************************************************************************/
18
 
 /* $Id: qgssearchtreenode.h 4502 2006-01-08 01:18:20Z timlinux $ */
 
18
/* $Id$ */
19
19
 
20
20
#ifndef QGSSEARCHTREENODE_H
21
21
#define QGSSEARCHTREENODE_H
22
22
 
23
 
#include <qstring.h>
24
 
#include <vector>
25
 
#include "qgsfeatureattribute.h"
 
23
#include <QMap>
 
24
#include <QString>
 
25
#include <QVariant>
26
26
 
27
 
// forward declaration due recursive declaration
28
 
class QgsFeatureAttribute;
 
27
#include <qgsdistancearea.h>
 
28
#include <qgsfield.h>
 
29
#include <qgsfeature.h>
29
30
 
30
31
class QgsSearchTreeValue;
31
32
 
32
 
/**
33
 
 * QgsSearchTreeNode
 
33
/** \ingroup core
 
34
 * A representation of a node in a search tree.
34
35
 *
35
36
 * node in tree of parsed search string
36
37
 * node is terminal (has no children) if it's a number, column ref or string
37
38
 * non-terminal is only node with operator - with 1 or 2 children
38
39
 */
39
 
class QgsSearchTreeNode
 
40
class CORE_EXPORT QgsSearchTreeNode
40
41
{
41
 
public:
 
42
  public:
42
43
 
43
44
    //! defines possible types of node
44
45
    enum Type
62
63
      opMINUS,
63
64
      opMUL,
64
65
      opDIV,
 
66
      opPOW,
 
67
      opSQRT,
 
68
      opSIN,
 
69
      opCOS,
 
70
      opTAN,
 
71
      opASIN,
 
72
      opACOS,
 
73
      opATAN,
 
74
      opTOINT,
 
75
      opTOREAL,
 
76
      opTOSTRING,
 
77
      opLENGTH,
 
78
      opAREA,
65
79
 
66
80
      // comparison
67
81
      opEQ,   // =
71
85
      opGE,   // >=
72
86
      opLE,   // <=
73
87
      opRegexp, // ~
74
 
      opLike, // LIKE
 
88
      opLike  // LIKE
75
89
    };
76
90
 
77
91
    //! constructors
78
 
    QgsSearchTreeNode(double number);
79
 
    QgsSearchTreeNode(Operator op, QgsSearchTreeNode* left, QgsSearchTreeNode* right);
80
 
    QgsSearchTreeNode(QString text, bool isColumnRef);
 
92
    QgsSearchTreeNode( double number );
 
93
    QgsSearchTreeNode( Operator op, QgsSearchTreeNode* left, QgsSearchTreeNode* right );
 
94
    QgsSearchTreeNode( QString text, bool isColumnRef );
81
95
 
82
96
    //! copy contructor - copies whole tree!
83
 
    QgsSearchTreeNode(const QgsSearchTreeNode& node);
 
97
    QgsSearchTreeNode( const QgsSearchTreeNode& node );
84
98
 
85
99
    //! destructor - deletes children nodes (if any)
86
100
    ~QgsSearchTreeNode();
87
101
 
88
102
    //! returns type of current node
89
103
    Type type()   { return mType; }
90
 
    
 
104
 
91
105
    //! node value getters
92
106
    Operator op();
93
107
    double number() { return mNumber; }
95
109
    QString string() { return mText; }
96
110
 
97
111
    //! node value setters (type is set also)
98
 
    void setOp(Operator op)         { mType = tOperator;  mOp = op; }
99
 
    void setNumber(double number)   { mType = tNumber;    mNumber = number; }
100
 
    void setColumnRef(QString& str) { mType = tColumnRef; mText = str; }
101
 
    void setString(QString& str)    { mType = tString;    mText = str; stripText(); }
 
112
    void setOp( Operator op )         { mType = tOperator;  mOp = op; }
 
113
    void setNumber( double number )   { mType = tNumber;    mNumber = number; }
 
114
    void setColumnRef( QString& str ) { mType = tColumnRef; mText = str; }
 
115
    void setString( QString& str )    { mType = tString;    mText = str; stripText(); }
102
116
 
103
117
    //! children
104
118
    QgsSearchTreeNode* Left()  { return mLeft;  }
105
119
    QgsSearchTreeNode* Right() { return mRight; }
106
 
    void setLeft (QgsSearchTreeNode* left ) { mLeft = left;   }
107
 
    void setRight(QgsSearchTreeNode* right) { mRight = right; }
 
120
    void setLeft( QgsSearchTreeNode* left ) { mLeft = left;   }
 
121
    void setRight( QgsSearchTreeNode* right ) { mRight = right; }
108
122
 
109
123
    //! returns search string that should be equal to original parsed string
110
124
    QString makeSearchString();
111
125
 
112
126
    //! checks whether the node tree is valid against supplied attributes
113
 
    bool checkAgainst(const std::vector<QgsFeatureAttribute>& attributes);
114
 
    
 
127
    bool checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes );
 
128
 
115
129
    //! checks if there were errors during evaluation
116
 
    bool hasError() { return (!mError.isEmpty()); }
117
 
    
 
130
    bool hasError() { return ( !mError.isEmpty() ); }
 
131
 
118
132
    //! returns error message
119
133
    const QString& errorMsg() { return mError; }
120
134
 
121
 
protected:
 
135
    //! wrapper around valueAgainst()
 
136
    bool getValue( QgsSearchTreeValue& value, QgsSearchTreeNode* node,
 
137
                   const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
 
138
 
 
139
  protected:
 
140
 
122
141
 
123
142
    //! returns scalar value of node
124
 
    QgsSearchTreeValue valueAgainst(const std::vector<QgsFeatureAttribute>& attributes);
125
 
    
126
 
    //! wrapper around valueAgainst()
127
 
    bool getValue(QgsSearchTreeValue& value, QgsSearchTreeNode* node,
128
 
                  const std::vector<QgsFeatureAttribute>& attributes);
 
143
    QgsSearchTreeValue valueAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
129
144
 
130
145
    //! strips mText when node is of string type
131
146
    void stripText();
132
 
    
133
 
private:
134
 
    
 
147
 
 
148
  private:
 
149
 
135
150
    //! node type
136
151
    Type mType;
137
152
 
145
160
    //! children
146
161
    QgsSearchTreeNode* mLeft;
147
162
    QgsSearchTreeNode* mRight;
 
163
 
 
164
    /**For length() and area() functions*/
 
165
    QgsDistanceArea mCalc;
148
166
};
149
167
 
150
 
// TODO: poslat do zvlast suboru
151
 
class QgsSearchTreeValue
 
168
// TODO: put it into separate file
 
169
class CORE_EXPORT QgsSearchTreeValue
152
170
{
153
 
public:
154
 
 
155
 
  enum Type
156
 
  {
157
 
    valError,
158
 
    valString,
159
 
    valNumber
160
 
  };
161
 
 
162
 
  QgsSearchTreeValue() { }
163
 
  QgsSearchTreeValue(QString string) { mType = valString; mString = string; }
164
 
  QgsSearchTreeValue(double number) { mType = valNumber; mNumber = number; }
165
 
  QgsSearchTreeValue(int error, QString errorMsg) { mType = valError; mNumber = error; mString = errorMsg; }
166
 
 
167
 
  static int compare(QgsSearchTreeValue& value1, QgsSearchTreeValue& value2);
168
 
 
169
 
  bool isNumeric() { return mType == valNumber; }
170
 
  bool isError() { return mType == valError; }
171
 
 
172
 
  QString& string() { return mString; }
173
 
  double number() { return mNumber; }
174
 
 
175
 
private:
176
 
  Type mType;
177
 
  QString mString;
178
 
  double mNumber;
 
171
  public:
 
172
 
 
173
    enum Type
 
174
    {
 
175
      valError,
 
176
      valString,
 
177
      valNumber
 
178
    };
 
179
 
 
180
    QgsSearchTreeValue() { }
 
181
    QgsSearchTreeValue( QString string ) { mType = valString; mString = string; }
 
182
    QgsSearchTreeValue( double number ) { mType = valNumber; mNumber = number; }
 
183
    QgsSearchTreeValue( int error, QString errorMsg ) { mType = valError; mNumber = error; mString = errorMsg; }
 
184
 
 
185
    static int compare( QgsSearchTreeValue& value1, QgsSearchTreeValue& value2,
 
186
                        Qt::CaseSensitivity = Qt::CaseSensitive );
 
187
 
 
188
    bool isNumeric() { return mType == valNumber; }
 
189
    bool isError() { return mType == valError; }
 
190
 
 
191
    QString& string() { return mString; }
 
192
    double number() { return mNumber; }
 
193
 
 
194
  private:
 
195
    Type mType;
 
196
    QString mString;
 
197
    double mNumber;
179
198
 
180
199
};
181
200