Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsrulebasedrendererv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrulebasedrendererv2.h - Rule-based renderer (symbology-ng)
3  ---------------------
4  begin : May 2010
5  copyright : (C) 2010 by Martin Dobias
6  email : wonder.sk at gmail.com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSRULEBASEDRENDERERV2_H
17 #define QGSRULEBASEDRENDERERV2_H
18 
19 #include "qgsfield.h"
20 #include "qgssearchstring.h"
21 
22 #include "qgsrendererv2.h"
23 
26 
31 class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
32 {
33  public:
34 
43  class CORE_EXPORT Rule
44  {
45  public:
47  Rule( QgsSymbolV2* symbol, int scaleMinDenom = 0, int scaleMaxDenom = 0, QString filterExp = QString(),
48  QString label = QString(), QString description = QString() );
49  Rule( const Rule& other );
50  ~Rule();
51  QString dump() const;
52  QStringList needsFields() const;
53  bool isFilterOK( const QgsFieldMap& fields, QgsFeature& f ) const;
54  bool isScaleOK( double scale ) const;
55 
56  QgsSymbolV2* symbol() { return mSymbol; }
57  bool dependsOnScale() const { return mScaleMinDenom != 0 || mScaleMaxDenom != 0; }
58  int scaleMinDenom() const { return mScaleMinDenom; }
59  int scaleMaxDenom() const { return mScaleMaxDenom; }
60  QString filterExpression() const { return mFilterExp; }
61  QString label() const { return mLabel; }
62  QString description() const { return mDescription; }
63 
64  void setScaleMinDenom( int scaleMinDenom ) { mScaleMinDenom = scaleMinDenom; }
65  void setScaleMaxDenom( int scaleMaxDenom ) { mScaleMaxDenom = scaleMaxDenom; }
66  void setFilterExpression( QString filterExp ) { mFilterExp = filterExp; initFilter(); }
67  void setLabel( QString label ) { mLabel = label; }
68  void setDescription( QString description ) { mDescription = description; }
69 
70  Rule& operator=( const Rule& other );
71 
72  protected:
73 
74  void initFilter();
75 
77  int mScaleMinDenom, mScaleMaxDenom;
78  QString mFilterExp, mLabel, mDescription;
79 
80  // temporary
83  };
84 
86 
87  static QgsFeatureRendererV2* create( QDomElement& element );
88 
90  QgsRuleBasedRendererV2( QgsSymbolV2* defaultSymbol );
91 
93  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
94 
95  virtual void renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
96 
97  virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
98 
99  virtual void stopRender( QgsRenderContext& context );
100 
101  virtual QList<QString> usedAttributes();
102 
103  virtual QgsFeatureRendererV2* clone();
104 
105  virtual QgsSymbolV2List symbols();
106 
108  virtual QDomElement save( QDomDocument& doc );
109 
111  virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
112 
115  virtual QgsLegendSymbolList legendSymbolItems();
116 
118 
120  int ruleCount();
122  Rule& ruleAt( int index );
124  void addRule( const Rule& rule );
126  void insertRule( int index, const Rule& rule );
128  void updateRuleAt( int index, const Rule& rule );
130  void removeRuleAt( int index );
132  void swapRules( int index1, int index2);
133 
135 
137  static QList<Rule> refineRuleCategories( Rule& initialRule, QgsCategorizedSymbolRendererV2* r );
139  static QList<Rule> refineRuleRanges( Rule& initialRule, QgsGraduatedSymbolRendererV2* r );
141  static QList<Rule> refineRuleScales( Rule& initialRule, QList<int> scales );
142 
143  protected:
145  QList<Rule> mRules;
148 
149  // temporary
150  QList<Rule*> mCurrentRules;
153 
154 };
155 
156 #endif // QGSRULEBASEDRENDERERV2_H