Skip to content
Permalink
Browse files

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
wonder committed Dec 22, 2009
1 parent 9538c18 commit 873a9ed2aa78654339f055b29bde62828d67ee9f
Showing with 192 additions and 2 deletions.
  1. +2 −0 python/core/core.sip
  2. +42 −0 python/core/qgssearchstring.sip
  3. +146 −0 python/core/qgssearchtreenode.sip
  4. +2 −2 src/core/qgssearchtreenode.h
@@ -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
@@ -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();

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

};
@@ -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:

0 comments on commit 873a9ed

Please sign in to comment.
You can’t perform that action at this time.