Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgsrulebasedrendererv2.h - Rule-based renderer (symbology-ng) 00003 --------------------- 00004 begin : May 2010 00005 copyright : (C) 2010 by Martin Dobias 00006 email : wonder.sk at gmail.com 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 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 QString label = QString(), QString description = QString() ); 00049 Rule( const Rule& other ); 00050 ~Rule(); 00051 QString dump() const; 00052 QStringList needsFields() const; 00053 bool isFilterOK( const QgsFieldMap& fields, QgsFeature& f ) const; 00054 bool isScaleOK( double scale ) const; 00055 00056 QgsSymbolV2* symbol() { return mSymbol; } 00057 bool dependsOnScale() const { return mScaleMinDenom != 0 || mScaleMaxDenom != 0; } 00058 int scaleMinDenom() const { return mScaleMinDenom; } 00059 int scaleMaxDenom() const { return mScaleMaxDenom; } 00060 QString filterExpression() const { return mFilterExp; } 00061 QString label() const { return mLabel; } 00062 QString description() const { return mDescription; } 00063 00064 void setScaleMinDenom( int scaleMinDenom ) { mScaleMinDenom = scaleMinDenom; } 00065 void setScaleMaxDenom( int scaleMaxDenom ) { mScaleMaxDenom = scaleMaxDenom; } 00066 void setFilterExpression( QString filterExp ) { mFilterExp = filterExp; initFilter(); } 00067 void setLabel( QString label ) { mLabel = label; } 00068 void setDescription( QString description ) { mDescription = description; } 00069 00070 Rule& operator=( const Rule& other ); 00071 00072 protected: 00073 00074 void initFilter(); 00075 00076 QgsSymbolV2* mSymbol; 00077 int mScaleMinDenom, mScaleMaxDenom; 00078 QString mFilterExp, mLabel, mDescription; 00079 00080 // temporary 00081 QgsSearchString mFilterParsed; 00082 QgsSearchTreeNode* mFilterTree; 00083 }; 00084 00086 00087 static QgsFeatureRendererV2* create( QDomElement& element ); 00088 00090 QgsRuleBasedRendererV2( QgsSymbolV2* defaultSymbol ); 00091 00093 virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ); 00094 00095 virtual void renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false ); 00096 00097 virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer ); 00098 00099 virtual void stopRender( QgsRenderContext& context ); 00100 00101 virtual QList<QString> usedAttributes(); 00102 00103 virtual QgsFeatureRendererV2* clone(); 00104 00105 virtual QgsSymbolV2List symbols(); 00106 00108 virtual QDomElement save( QDomDocument& doc ); 00109 00111 virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize ); 00112 00115 virtual QgsLegendSymbolList legendSymbolItems(); 00116 00118 00120 int ruleCount(); 00122 Rule& ruleAt( int index ); 00124 void addRule( const Rule& rule ); 00126 void insertRule( int index, const Rule& rule ); 00128 void updateRuleAt( int index, const Rule& rule ); 00130 void removeRuleAt( int index ); 00132 void swapRules( int index1, int index2); 00133 00135 00137 static QList<Rule> refineRuleCategories( Rule& initialRule, QgsCategorizedSymbolRendererV2* r ); 00139 static QList<Rule> refineRuleRanges( Rule& initialRule, QgsGraduatedSymbolRendererV2* r ); 00141 static QList<Rule> refineRuleScales( Rule& initialRule, QList<int> scales ); 00142 00143 protected: 00145 QList<Rule> mRules; 00147 QgsSymbolV2* mDefaultSymbol; 00148 00149 // temporary 00150 QList<Rule*> mCurrentRules; 00151 QgsFieldMap mCurrentFields; 00152 QgsSymbolV2* mCurrentSymbol; 00153 00154 }; 00155 00156 #endif // QGSRULEBASEDRENDERERV2_H