|
| 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 | +}; |
0 commit comments