Skip to content

Commit 873a9ed

Browse files
author
wonder
committed
Added python bindings for search strings
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12579 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9538c18 commit 873a9ed

File tree

4 files changed

+192
-2
lines changed

4 files changed

+192
-2
lines changed

python/core/core.sip

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
%Include qgsrenderer.sip
6161
%Include qgsrunprocess.sip
6262
%Include qgsscalecalculator.sip
63+
%Include qgssearchstring.sip
64+
%Include qgssearchtreenode.sip
6365
%Include qgssinglesymbolrenderer.sip
6466
%Include qgssnapper.sip
6567
%Include qgsspatialindex.sip

python/core/qgssearchstring.sip

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
class QgsSearchString
3+
{
4+
%TypeHeaderCode
5+
#include "qgssearchstring.h"
6+
%End
7+
8+
public:
9+
//! constructor
10+
QgsSearchString();
11+
12+
//! copy constructor - makes also copy of search tree
13+
QgsSearchString( const QgsSearchString& str );
14+
15+
//! destructor - deletes node tree
16+
~QgsSearchString();
17+
18+
//! assignment operator takes care to copy search tree correctly
19+
// unable to wrap QgsSearchString& operator=( const QgsSearchString& str );
20+
21+
/** sets search string and parses search tree
22+
on success returns true and sets member variables to the new values */
23+
bool setString( QString str );
24+
25+
/** copies tree and makes search string for it
26+
on success returns true and sets member variables to the new values */
27+
bool setTree( QgsSearchTreeNode* tree );
28+
29+
//! getter functions
30+
QgsSearchTreeNode* tree();
31+
QString string();
32+
33+
//! returns parser error message - valid only after unsuccessfull parsing
34+
const QString& parserErrorMsg();
35+
36+
//! returns true if no string is set
37+
bool isEmpty();
38+
39+
//! clear search string
40+
void clear();
41+
42+
};

python/core/qgssearchtreenode.sip

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
2+
class QgsSearchTreeNode
3+
{
4+
%TypeHeaderCode
5+
#include "qgssearchtreenode.h"
6+
%End
7+
8+
public:
9+
//! defines possible types of node
10+
enum Type
11+
{
12+
tOperator = 1,
13+
tNumber,
14+
tColumnRef,
15+
tString
16+
};
17+
18+
//! possible operators
19+
enum Operator
20+
{
21+
// binary
22+
opAND = 1,
23+
opOR,
24+
opNOT,
25+
26+
// arithmetic
27+
opPLUS,
28+
opMINUS,
29+
opMUL,
30+
opDIV,
31+
opPOW,
32+
opSQRT,
33+
opSIN,
34+
opCOS,
35+
opTAN,
36+
opASIN,
37+
opACOS,
38+
opATAN,
39+
opTOINT,
40+
opTOREAL,
41+
opTOSTRING,
42+
opLENGTH,
43+
opAREA,
44+
45+
// comparison
46+
opEQ, // =
47+
opNE, // != resp. <>
48+
opGT, // >
49+
opLT, // <
50+
opGE, // >=
51+
opLE, // <=
52+
opRegexp, // ~
53+
opLike // LIKE
54+
};
55+
56+
//! constructors
57+
QgsSearchTreeNode( double number );
58+
QgsSearchTreeNode( Operator o, QgsSearchTreeNode* left, QgsSearchTreeNode* right );
59+
QgsSearchTreeNode( QString text, bool isColumnRef );
60+
61+
//! copy contructor - copies whole tree!
62+
QgsSearchTreeNode( const QgsSearchTreeNode& node );
63+
64+
//! destructor - deletes children nodes (if any)
65+
~QgsSearchTreeNode();
66+
67+
//! returns type of current node
68+
Type type();
69+
70+
//! node value getters
71+
// TODO: for some reason this function is not found by dynamic linker
72+
//Operator op();
73+
double number();
74+
QString columnRef();
75+
QString string();
76+
77+
//! node value setters (type is set also)
78+
void setOp( Operator o );
79+
void setNumber( double number );
80+
void setColumnRef( QString& str );
81+
void setString( QString& str );
82+
83+
//! children
84+
QgsSearchTreeNode* Left();
85+
QgsSearchTreeNode* Right();
86+
void setLeft( QgsSearchTreeNode* left );
87+
void setRight( QgsSearchTreeNode* right );
88+
89+
//! returns search string that should be equal to original parsed string
90+
QString makeSearchString();
91+
92+
//! checks whether the node tree is valid against supplied attributes
93+
bool checkAgainst( const QMap<int,QgsField>& fields, const QMap<int, QVariant>& attributes );
94+
95+
//! checks if there were errors during evaluation
96+
bool hasError();
97+
98+
//! returns error message
99+
const QString& errorMsg();
100+
101+
//! wrapper around valueAgainst()
102+
bool getValue( QgsSearchTreeValue& value /Out/, QgsSearchTreeNode* node,
103+
const QMap<int,QgsField>& fields, const QMap<int,QVariant>& attributes, QgsGeometry* geom = 0 );
104+
105+
protected:
106+
107+
108+
//! returns scalar value of node
109+
QgsSearchTreeValue valueAgainst( const QMap<int,QgsField>& fields, const QMap<int,QVariant>& attributes, QgsGeometry* geom = 0 );
110+
111+
//! strips mText when node is of string type
112+
void stripText();
113+
114+
};
115+
116+
117+
class QgsSearchTreeValue
118+
{
119+
%TypeHeaderCode
120+
#include "qgssearchtreenode.h"
121+
%End
122+
123+
public:
124+
125+
enum Type
126+
{
127+
valError,
128+
valString,
129+
valNumber
130+
};
131+
132+
QgsSearchTreeValue();
133+
QgsSearchTreeValue( QString string );
134+
QgsSearchTreeValue( double number );
135+
QgsSearchTreeValue( int error, QString errorMsg );
136+
137+
static int compare( QgsSearchTreeValue& value1, QgsSearchTreeValue& value2,
138+
Qt::CaseSensitivity = Qt::CaseSensitive );
139+
140+
bool isNumeric();
141+
bool isError();
142+
143+
QString& string();
144+
double number();
145+
146+
};

src/core/qgssearchtreenode.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ class CORE_EXPORT QgsSearchTreeNode
165165
QgsDistanceArea mCalc;
166166
};
167167

168-
// TODO: poslat do zvlast suboru
169-
class QgsSearchTreeValue
168+
// TODO: put it into separate file
169+
class CORE_EXPORT QgsSearchTreeValue
170170
{
171171
public:
172172

0 commit comments

Comments
 (0)