[QGIS Commit] r12579 - in trunk/qgis: python/core src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Dec 22 09:52:54 EST 2009


Author: wonder
Date: 2009-12-22 09:52:54 -0500 (Tue, 22 Dec 2009)
New Revision: 12579

Added:
   trunk/qgis/python/core/qgssearchstring.sip
   trunk/qgis/python/core/qgssearchtreenode.sip
Modified:
   trunk/qgis/python/core/core.sip
   trunk/qgis/src/core/qgssearchtreenode.h
Log:
Added python bindings for search strings


Modified: trunk/qgis/python/core/core.sip
===================================================================
--- trunk/qgis/python/core/core.sip	2009-12-22 14:13:49 UTC (rev 12578)
+++ trunk/qgis/python/core/core.sip	2009-12-22 14:52:54 UTC (rev 12579)
@@ -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

Added: trunk/qgis/python/core/qgssearchstring.sip
===================================================================
--- trunk/qgis/python/core/qgssearchstring.sip	                        (rev 0)
+++ trunk/qgis/python/core/qgssearchstring.sip	2009-12-22 14:52:54 UTC (rev 12579)
@@ -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();
+
+};

Added: trunk/qgis/python/core/qgssearchtreenode.sip
===================================================================
--- trunk/qgis/python/core/qgssearchtreenode.sip	                        (rev 0)
+++ trunk/qgis/python/core/qgssearchtreenode.sip	2009-12-22 14:52:54 UTC (rev 12579)
@@ -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();
+
+};

Modified: trunk/qgis/src/core/qgssearchtreenode.h
===================================================================
--- trunk/qgis/src/core/qgssearchtreenode.h	2009-12-22 14:13:49 UTC (rev 12578)
+++ trunk/qgis/src/core/qgssearchtreenode.h	2009-12-22 14:52:54 UTC (rev 12579)
@@ -165,8 +165,8 @@
     QgsDistanceArea mCalc;
 };
 
-// TODO: poslat do zvlast suboru
-class QgsSearchTreeValue
+// TODO: put it into separate file
+class CORE_EXPORT QgsSearchTreeValue
 {
   public:
 



More information about the QGIS-commit mailing list