00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef QGSRULEBASEDRENDERERV2_H
00017 #define QGSRULEBASEDRENDERERV2_H
00018
00019 #include "qgsfield.h"
00020 #include "qgssearchstring.h"
00021
00022 #include "qgsrendererv2.h"
00023
00024 class QgsCategorizedSymbolRendererV2;
00025 class QgsGraduatedSymbolRendererV2;
00026
00031 class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
00032 {
00033 public:
00034
00043 class CORE_EXPORT Rule
00044 {
00045 public:
00047 Rule( QgsSymbolV2* symbol, int scaleMinDenom = 0, int scaleMaxDenom = 0, QString filterExp = QString() );
00048 Rule( const Rule& other );
00049 ~Rule();
00050 QString dump() const;
00051 QStringList needsFields() const;
00052 bool isFilterOK( const QgsFieldMap& fields, QgsFeature& f ) const;
00053 bool isScaleOK( double scale ) const;
00054
00055 QgsSymbolV2* symbol() { return mSymbol; }
00056 bool dependsOnScale() const { return mScaleMinDenom != 0 || mScaleMaxDenom != 0; }
00057 int scaleMinDenom() const { return mScaleMinDenom; }
00058 int scaleMaxDenom() const { return mScaleMaxDenom; }
00059 QString filterExpression() const { return mFilterExp; }
00060
00061 void setScaleMinDenom( int scaleMinDenom ) { mScaleMinDenom = scaleMinDenom; }
00062 void setScaleMaxDenom( int scaleMaxDenom ) { mScaleMaxDenom = scaleMaxDenom; }
00063 void setFilterExpression( QString filterExp ) { mFilterExp = filterExp; initFilter(); }
00064
00065 Rule& operator=( const Rule& other );
00066
00067 protected:
00068
00069 void initFilter();
00070
00071 QgsSymbolV2* mSymbol;
00072 int mScaleMinDenom, mScaleMaxDenom;
00073 QString mFilterExp;
00074
00075
00076 QgsSearchString mFilterParsed;
00077 QgsSearchTreeNode* mFilterTree;
00078 };
00079
00081
00082 static QgsFeatureRendererV2* create( QDomElement& element );
00083
00085 QgsRuleBasedRendererV2( QgsSymbolV2* defaultSymbol );
00086
00088 virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
00089
00090 virtual void renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
00091
00092 virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
00093
00094 virtual void stopRender( QgsRenderContext& context );
00095
00096 virtual QList<QString> usedAttributes();
00097
00098 virtual QgsFeatureRendererV2* clone();
00099
00100 virtual QgsSymbolV2List symbols();
00101
00103 virtual QDomElement save( QDomDocument& doc );
00104
00106 virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
00107
00110 virtual QgsLegendSymbolList legendSymbolItems();
00111
00113
00115 int ruleCount();
00117 Rule& ruleAt( int index );
00119 void addRule( const Rule& rule );
00121 void insertRule( int index, const Rule& rule );
00123 void updateRuleAt( int index, const Rule& rule );
00125 void removeRuleAt( int index );
00126
00128
00130 static QList<Rule> refineRuleCategories( Rule& initialRule, QgsCategorizedSymbolRendererV2* r );
00132 static QList<Rule> refineRuleRanges( Rule& initialRule, QgsGraduatedSymbolRendererV2* r );
00134 static QList<Rule> refineRuleScales( Rule& initialRule, QList<int> scales );
00135
00136 protected:
00138 QList<Rule> mRules;
00140 QgsSymbolV2* mDefaultSymbol;
00141
00142
00143 QList<Rule*> mCurrentRules;
00144 QgsFieldMap mCurrentFields;
00145 QgsSymbolV2* mCurrentSymbol;
00146 };
00147
00148 #endif // QGSRULEBASEDRENDERERV2_H