-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added python bindings for search strings
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12579 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
wonder
committed
Dec 22, 2009
1 parent
9538c18
commit 873a9ed
Showing
4 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
class QgsSearchString | ||
{ | ||
%TypeHeaderCode | ||
#include "qgssearchstring.h" | ||
%End | ||
|
||
public: | ||
//! constructor | ||
QgsSearchString(); | ||
|
||
//! copy constructor - makes also copy of search tree | ||
QgsSearchString( const QgsSearchString& str ); | ||
|
||
//! destructor - deletes node tree | ||
~QgsSearchString(); | ||
|
||
//! assignment operator takes care to copy search tree correctly | ||
// unable to wrap QgsSearchString& operator=( const QgsSearchString& str ); | ||
|
||
/** sets search string and parses search tree | ||
on success returns true and sets member variables to the new values */ | ||
bool setString( QString str ); | ||
|
||
/** copies tree and makes search string for it | ||
on success returns true and sets member variables to the new values */ | ||
bool setTree( QgsSearchTreeNode* tree ); | ||
|
||
//! getter functions | ||
QgsSearchTreeNode* tree(); | ||
QString string(); | ||
|
||
//! returns parser error message - valid only after unsuccessfull parsing | ||
const QString& parserErrorMsg(); | ||
|
||
//! returns true if no string is set | ||
bool isEmpty(); | ||
|
||
//! clear search string | ||
void clear(); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
|
||
class QgsSearchTreeNode | ||
{ | ||
%TypeHeaderCode | ||
#include "qgssearchtreenode.h" | ||
%End | ||
|
||
public: | ||
//! defines possible types of node | ||
enum Type | ||
{ | ||
tOperator = 1, | ||
tNumber, | ||
tColumnRef, | ||
tString | ||
}; | ||
|
||
//! possible operators | ||
enum Operator | ||
{ | ||
// binary | ||
opAND = 1, | ||
opOR, | ||
opNOT, | ||
|
||
// arithmetic | ||
opPLUS, | ||
opMINUS, | ||
opMUL, | ||
opDIV, | ||
opPOW, | ||
opSQRT, | ||
opSIN, | ||
opCOS, | ||
opTAN, | ||
opASIN, | ||
opACOS, | ||
opATAN, | ||
opTOINT, | ||
opTOREAL, | ||
opTOSTRING, | ||
opLENGTH, | ||
opAREA, | ||
|
||
// comparison | ||
opEQ, // = | ||
opNE, // != resp. <> | ||
opGT, // > | ||
opLT, // < | ||
opGE, // >= | ||
opLE, // <= | ||
opRegexp, // ~ | ||
opLike // LIKE | ||
}; | ||
|
||
//! constructors | ||
QgsSearchTreeNode( double number ); | ||
QgsSearchTreeNode( Operator o, QgsSearchTreeNode* left, QgsSearchTreeNode* right ); | ||
QgsSearchTreeNode( QString text, bool isColumnRef ); | ||
|
||
//! copy contructor - copies whole tree! | ||
QgsSearchTreeNode( const QgsSearchTreeNode& node ); | ||
|
||
//! destructor - deletes children nodes (if any) | ||
~QgsSearchTreeNode(); | ||
|
||
//! returns type of current node | ||
Type type(); | ||
|
||
//! node value getters | ||
// TODO: for some reason this function is not found by dynamic linker | ||
//Operator op(); | ||
double number(); | ||
QString columnRef(); | ||
QString string(); | ||
|
||
//! node value setters (type is set also) | ||
void setOp( Operator o ); | ||
void setNumber( double number ); | ||
void setColumnRef( QString& str ); | ||
void setString( QString& str ); | ||
|
||
//! children | ||
QgsSearchTreeNode* Left(); | ||
QgsSearchTreeNode* Right(); | ||
void setLeft( QgsSearchTreeNode* left ); | ||
void setRight( QgsSearchTreeNode* right ); | ||
|
||
//! returns search string that should be equal to original parsed string | ||
QString makeSearchString(); | ||
|
||
//! checks whether the node tree is valid against supplied attributes | ||
bool checkAgainst( const QMap<int,QgsField>& fields, const QMap<int, QVariant>& attributes ); | ||
|
||
//! checks if there were errors during evaluation | ||
bool hasError(); | ||
|
||
//! returns error message | ||
const QString& errorMsg(); | ||
|
||
//! wrapper around valueAgainst() | ||
bool getValue( QgsSearchTreeValue& value /Out/, QgsSearchTreeNode* node, | ||
const QMap<int,QgsField>& fields, const QMap<int,QVariant>& attributes, QgsGeometry* geom = 0 ); | ||
|
||
protected: | ||
|
||
|
||
//! returns scalar value of node | ||
QgsSearchTreeValue valueAgainst( const QMap<int,QgsField>& fields, const QMap<int,QVariant>& attributes, QgsGeometry* geom = 0 ); | ||
|
||
//! strips mText when node is of string type | ||
void stripText(); | ||
|
||
}; | ||
|
||
|
||
class QgsSearchTreeValue | ||
{ | ||
%TypeHeaderCode | ||
#include "qgssearchtreenode.h" | ||
%End | ||
|
||
public: | ||
|
||
enum Type | ||
{ | ||
valError, | ||
valString, | ||
valNumber | ||
}; | ||
|
||
QgsSearchTreeValue(); | ||
QgsSearchTreeValue( QString string ); | ||
QgsSearchTreeValue( double number ); | ||
QgsSearchTreeValue( int error, QString errorMsg ); | ||
|
||
static int compare( QgsSearchTreeValue& value1, QgsSearchTreeValue& value2, | ||
Qt::CaseSensitivity = Qt::CaseSensitive ); | ||
|
||
bool isNumeric(); | ||
bool isError(); | ||
|
||
QString& string(); | ||
double number(); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters