Added python bindings for search strings

git-svn-id: http://svn.osgeo.org/qgis/trunk@12579 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2009-12-22 14:52:54 +00:00
parent 9fc31d468f
commit 3a7851c8a1
4 changed files with 192 additions and 2 deletions

View File

@ -60,6 +60,8 @@
%Include qgsrenderer.sip
%Include qgsrunprocess.sip
%Include qgsscalecalculator.sip
%Include qgssearchstring.sip
%Include qgssearchtreenode.sip
%Include qgssinglesymbolrenderer.sip
%Include qgssnapper.sip
%Include qgsspatialindex.sip

View File

@ -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();
};

View File

@ -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();
};

View File

@ -165,8 +165,8 @@ class CORE_EXPORT QgsSearchTreeNode
QgsDistanceArea mCalc;
};
// TODO: poslat do zvlast suboru
class QgsSearchTreeValue
// TODO: put it into separate file
class CORE_EXPORT QgsSearchTreeValue
{
public: