15
15
* (at your option) any later version. *
17
17
***************************************************************************/
18
/* $Id: qgssearchtreenode.h 4502 2006-01-08 01:18:20Z timlinux $ */
20
20
#ifndef QGSSEARCHTREENODE_H
21
21
#define QGSSEARCHTREENODE_H
25
#include "qgsfeatureattribute.h"
27
// forward declaration due recursive declaration
28
class QgsFeatureAttribute;
27
#include <qgsdistancearea.h>
29
#include <qgsfeature.h>
30
31
class QgsSearchTreeValue;
34
* A representation of a node in a search tree.
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
39
class QgsSearchTreeNode
40
class CORE_EXPORT QgsSearchTreeNode
43
44
//! defines possible types of node
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 );
82
96
//! copy contructor - copies whole tree!
83
QgsSearchTreeNode(const QgsSearchTreeNode& node);
97
QgsSearchTreeNode( const QgsSearchTreeNode& node );
85
99
//! destructor - deletes children nodes (if any)
86
100
~QgsSearchTreeNode();
88
102
//! returns type of current node
89
103
Type type() { return mType; }
91
105
//! node value getters
93
107
double number() { return mNumber; }
95
109
QString string() { return mText; }
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(); }
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; }
109
123
//! returns search string that should be equal to original parsed string
110
124
QString makeSearchString();
112
126
//! checks whether the node tree is valid against supplied attributes
113
bool checkAgainst(const std::vector<QgsFeatureAttribute>& attributes);
127
bool checkAgainst( const QgsFieldMap& fields, const QgsAttributeMap& attributes );
115
129
//! checks if there were errors during evaluation
116
bool hasError() { return (!mError.isEmpty()); }
130
bool hasError() { return ( !mError.isEmpty() ); }
118
132
//! returns error message
119
133
const QString& errorMsg() { return mError; }
135
//! wrapper around valueAgainst()
136
bool getValue( QgsSearchTreeValue& value, QgsSearchTreeNode* node,
137
const QgsFieldMap& fields, const QgsAttributeMap& attributes, QgsGeometry* geom = 0 );
123
142
//! returns scalar value of node
124
QgsSearchTreeValue valueAgainst(const std::vector<QgsFeatureAttribute>& attributes);
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 );
130
145
//! strips mText when node is of string type
131
146
void stripText();
146
161
QgsSearchTreeNode* mLeft;
147
162
QgsSearchTreeNode* mRight;
164
/**For length() and area() functions*/
165
QgsDistanceArea mCalc;
150
// TODO: poslat do zvlast suboru
151
class QgsSearchTreeValue
168
// TODO: put it into separate file
169
class CORE_EXPORT QgsSearchTreeValue
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; }
167
static int compare(QgsSearchTreeValue& value1, QgsSearchTreeValue& value2);
169
bool isNumeric() { return mType == valNumber; }
170
bool isError() { return mType == valError; }
172
QString& string() { return mString; }
173
double number() { return mNumber; }
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; }
185
static int compare( QgsSearchTreeValue& value1, QgsSearchTreeValue& value2,
186
Qt::CaseSensitivity = Qt::CaseSensitive );
188
bool isNumeric() { return mType == valNumber; }
189
bool isError() { return mType == valError; }
191
QString& string() { return mString; }
192
double number() { return mNumber; }