1
/***************************************************************************
3
Definition of node for parsed tree of search string
6
copyright : (C) 2005 by Martin Dobias
7
email : won.der at centrum.sk
8
***************************************************************************/
10
/***************************************************************************
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. *
17
***************************************************************************/
18
/* $Id: qgssearchtreenode.h 4502 2006-01-08 01:18:20Z timlinux $ */
20
#ifndef QGSSEARCHTREENODE_H
21
#define QGSSEARCHTREENODE_H
25
#include "qgsfeatureattribute.h"
27
// forward declaration due recursive declaration
28
class QgsFeatureAttribute;
30
class QgsSearchTreeValue;
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
39
class QgsSearchTreeNode
43
//! defines possible types of node
52
//! possible operators
78
QgsSearchTreeNode(double number);
79
QgsSearchTreeNode(Operator op, QgsSearchTreeNode* left, QgsSearchTreeNode* right);
80
QgsSearchTreeNode(QString text, bool isColumnRef);
82
//! copy contructor - copies whole tree!
83
QgsSearchTreeNode(const QgsSearchTreeNode& node);
85
//! destructor - deletes children nodes (if any)
88
//! returns type of current node
89
Type type() { return mType; }
91
//! node value getters
93
double number() { return mNumber; }
94
QString columnRef() { return mText; }
95
QString string() { return mText; }
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(); }
104
QgsSearchTreeNode* Left() { return mLeft; }
105
QgsSearchTreeNode* Right() { return mRight; }
106
void setLeft (QgsSearchTreeNode* left ) { mLeft = left; }
107
void setRight(QgsSearchTreeNode* right) { mRight = right; }
109
//! returns search string that should be equal to original parsed string
110
QString makeSearchString();
112
//! checks whether the node tree is valid against supplied attributes
113
bool checkAgainst(const std::vector<QgsFeatureAttribute>& attributes);
115
//! checks if there were errors during evaluation
116
bool hasError() { return (!mError.isEmpty()); }
118
//! returns error message
119
const QString& errorMsg() { return mError; }
123
//! 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);
130
//! strips mText when node is of string type
146
QgsSearchTreeNode* mLeft;
147
QgsSearchTreeNode* mRight;
150
// TODO: poslat do zvlast suboru
151
class 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; }