~ubuntu-branches/ubuntu/quantal/qgis/quantal

« back to all changes in this revision

Viewing changes to src/core/qgssearchtreenode.h

  • Committer: Bazaar Package Importer
  • Author(s): William Grant
  • Date: 2007-05-06 13:42:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506134232-pyli6t388w5asd8x
Tags: 0.8.0-3ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
  - debian/rules, debian/qgis.install, debian/qgis.dirs debian/qgis.desktop:
    Add and install .desktop.
* debian/qgis.desktop: Remove Applications category; it's not real.
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: qgssearchtreenode.h 4502 2006-01-08 01:18:20Z timlinux $ */
 
19
 
 
20
#ifndef QGSSEARCHTREENODE_H
 
21
#define QGSSEARCHTREENODE_H
 
22
 
 
23
#include <qstring.h>
 
24
#include <vector>
 
25
#include "qgsfeatureattribute.h"
 
26
 
 
27
// forward declaration due recursive declaration
 
28
class QgsFeatureAttribute;
 
29
 
 
30
class QgsSearchTreeValue;
 
31
 
 
32
/**
 
33
 * QgsSearchTreeNode
 
34
 *
 
35
 * node in tree of parsed search string
 
36
 * node is terminal (has no children) if it's a number, column ref or string
 
37
 * non-terminal is only node with operator - with 1 or 2 children
 
38
 */
 
39
class QgsSearchTreeNode
 
40
{
 
41
public:
 
42
 
 
43
    //! defines possible types of node
 
44
    enum Type
 
45
    {
 
46
      tOperator = 1,
 
47
      tNumber,
 
48
      tColumnRef,
 
49
      tString
 
50
    };
 
51
 
 
52
    //! possible operators
 
53
    enum Operator
 
54
    {
 
55
      // binary
 
56
      opAND = 1,
 
57
      opOR,
 
58
      opNOT,
 
59
 
 
60
      // arithmetic
 
61
      opPLUS,
 
62
      opMINUS,
 
63
      opMUL,
 
64
      opDIV,
 
65
 
 
66
      // comparison
 
67
      opEQ,   // =
 
68
      opNE,   // != resp. <>
 
69
      opGT,   // >
 
70
      opLT,   // <
 
71
      opGE,   // >=
 
72
      opLE,   // <=
 
73
      opRegexp, // ~
 
74
      opLike, // LIKE
 
75
    };
 
76
 
 
77
    //! constructors
 
78
    QgsSearchTreeNode(double number);
 
79
    QgsSearchTreeNode(Operator op, QgsSearchTreeNode* left, QgsSearchTreeNode* right);
 
80
    QgsSearchTreeNode(QString text, bool isColumnRef);
 
81
 
 
82
    //! copy contructor - copies whole tree!
 
83
    QgsSearchTreeNode(const QgsSearchTreeNode& node);
 
84
 
 
85
    //! destructor - deletes children nodes (if any)
 
86
    ~QgsSearchTreeNode();
 
87
 
 
88
    //! returns type of current node
 
89
    Type type()   { return mType; }
 
90
    
 
91
    //! node value getters
 
92
    Operator op();
 
93
    double number() { return mNumber; }
 
94
    QString columnRef() { return mText; }
 
95
    QString string() { return mText; }
 
96
 
 
97
    //! 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(); }
 
102
 
 
103
    //! children
 
104
    QgsSearchTreeNode* Left()  { return mLeft;  }
 
105
    QgsSearchTreeNode* Right() { return mRight; }
 
106
    void setLeft (QgsSearchTreeNode* left ) { mLeft = left;   }
 
107
    void setRight(QgsSearchTreeNode* right) { mRight = right; }
 
108
 
 
109
    //! returns search string that should be equal to original parsed string
 
110
    QString makeSearchString();
 
111
 
 
112
    //! checks whether the node tree is valid against supplied attributes
 
113
    bool checkAgainst(const std::vector<QgsFeatureAttribute>& attributes);
 
114
    
 
115
    //! checks if there were errors during evaluation
 
116
    bool hasError() { return (!mError.isEmpty()); }
 
117
    
 
118
    //! returns error message
 
119
    const QString& errorMsg() { return mError; }
 
120
 
 
121
protected:
 
122
 
 
123
    //! 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);
 
129
 
 
130
    //! strips mText when node is of string type
 
131
    void stripText();
 
132
    
 
133
private:
 
134
    
 
135
    //! node type
 
136
    Type mType;
 
137
 
 
138
    //! data
 
139
    Operator mOp;
 
140
    double mNumber;
 
141
    QString mText;
 
142
 
 
143
    QString mError;
 
144
 
 
145
    //! children
 
146
    QgsSearchTreeNode* mLeft;
 
147
    QgsSearchTreeNode* mRight;
 
148
};
 
149
 
 
150
// TODO: poslat do zvlast suboru
 
151
class QgsSearchTreeValue
 
152
{
 
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;
 
179
 
 
180
};
 
181
 
 
182
#endif
 
183