QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgsrulebasedrendererv2widget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrulebasedrendererv2widget.h - Settings widget for rule-based renderer
3  ---------------------
4  begin : May 2010
5  copyright : (C) 2010 by Martin Dobias
6  email : wonder dot sk at gmail dot 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 QGSRULEBASEDRENDERERV2WIDGET_H
17 #define QGSRULEBASEDRENDERERV2WIDGET_H
18 
19 #include "qgsrendererv2widget.h"
20 
21 #include "qgsrulebasedrendererv2.h"
22 class QMenu;
23 
25 
26 #include <QAbstractItemModel>
27 
28 /* Features count fro rule */
30 {
31  int count; // number of features
32  int duplicateCount; // number of features present also in other rule(s)
33  // map of feature counts in other rules
34  QMap<QgsRuleBasedRendererV2::Rule*, int> duplicateCountMap;
35 };
36 
37 /*
38 Tree model for the rules:
39 
40 (invalid) == root node
41  +--- top level rule
42  +--- top level rule
43 */
44 class GUI_EXPORT QgsRuleBasedRendererV2Model : public QAbstractItemModel
45 {
46  public:
48 
49  virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
50  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
51  virtual QVariant headerData( int section, Qt::Orientation orientation,
52  int role = Qt::DisplayRole ) const;
53  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
54  virtual int columnCount( const QModelIndex & = QModelIndex() ) const;
56  virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
58  virtual QModelIndex parent( const QModelIndex &index ) const;
59 
60  // editing support
61  virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
62 
63  // drag'n'drop support
64  Qt::DropActions supportedDropActions() const;
65  QStringList mimeTypes() const;
66  QMimeData *mimeData( const QModelIndexList &indexes ) const;
67  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
68 
69  bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() );
70 
71  // new methods
72 
73  QgsRuleBasedRendererV2::Rule* ruleForIndex( const QModelIndex& index ) const;
74 
75  void insertRule( const QModelIndex& parent, int before, QgsRuleBasedRendererV2::Rule* newrule );
76  void updateRule( const QModelIndex& parent, int row );
77  // update rule and all its descendants
78  void updateRule( const QModelIndex& index );
79  void removeRule( const QModelIndex& index );
80 
81  void willAddRules( const QModelIndex& parent, int count ); // call beginInsertRows
82  void finishedAddingRules(); // call endInsertRows
83 
85  void setFeatureCounts( QMap<QgsRuleBasedRendererV2::Rule*, QgsRuleBasedRendererV2Count> theCountMap );
86  void clearFeatureCounts();
87 
88  protected:
90  QMap<QgsRuleBasedRendererV2::Rule*, QgsRuleBasedRendererV2Count> mFeatureCountMap;
91 };
92 
93 
95 
96 #include "ui_qgsrulebasedrendererv2widget.h"
97 
98 class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsRuleBasedRendererV2Widget
99 {
100  Q_OBJECT
101 
102  public:
103 
104  static QgsRendererV2Widget* create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
105 
108 
109  virtual QgsFeatureRendererV2* renderer();
110 
111  public slots:
112 
113  void addRule();
114  void editRule();
115  void editRule( const QModelIndex& index );
116  void removeRule();
117  void countFeatures();
118  void clearFeatureCounts() { mModel->clearFeatureCounts(); }
119 
120  void refineRuleScales();
121  void refineRuleCategories();
122  void refineRuleRanges();
123 
124  void setRenderingOrder();
125 
126  void currentRuleChanged( const QModelIndex& current = QModelIndex(), const QModelIndex& previous = QModelIndex() );
127 
128  void saveSectionWidth( int section, int oldSize, int newSize );
129  void restoreSectionWidths();
130 
131  protected:
132  void refineRule( int type );
133  void refineRuleCategoriesGui( const QModelIndexList& index );
134  void refineRuleRangesGui( const QModelIndexList& index );
135  void refineRuleScalesGui( const QModelIndexList& index );
136 
137  QgsRuleBasedRendererV2::Rule* currentRule();
138 
139  QList<QgsSymbolV2*> selectedSymbols();
140  QgsRuleBasedRendererV2::RuleList selectedRules();
141  void refreshSymbolView();
142  void keyPressEvent( QKeyEvent* event );
143 
146 
147  QMenu* mRefineMenu;
148  QAction* mDeleteAction;
149 
151 
152  protected slots:
153  void copy();
154  void paste();
155 };
156 
158 
159 #include <QDialog>
160 
161 #include "ui_qgsrendererrulepropsdialogbase.h"
162 
163 class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog, private Ui::QgsRendererRulePropsDialog
164 {
165  Q_OBJECT
166 
167  public:
168  QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = 0 );
170 
171  QgsRuleBasedRendererV2::Rule* rule() { return mRule; }
172 
173  public slots:
174  void testFilter();
175  void buildExpression();
176  void accept();
177 
178  protected:
182 
184  QgsSymbolV2* mSymbol; // a clone of original symbol
185 };
186 
187 
188 #endif // QGSRULEBASEDRENDERERV2WIDGET_H
virtual QList< QgsSymbolV2 * > selectedSymbols()
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
static unsigned index
QMap< QgsRuleBasedRendererV2::Rule *, int > duplicateCountMap
QgsSymbolV2SelectorDialog * mSymbolSelector
QgsRuleBasedRendererV2Model * mModel
QgsRuleBasedRendererV2::RuleList mCopyBuffer
This class keeps data about a rules for rule-based renderer.
QMap< QgsRuleBasedRendererV2::Rule *, QgsRuleBasedRendererV2Count > mFeatureCountMap
When drawing a vector layer with rule-based renderer, it goes through the rules and draws features wi...
Base class for renderer settings widgets.
QgsRuleBasedRendererV2::Rule * mRule
QgsRuleBasedRendererV2::Rule * rule()
virtual void refreshSymbolView()
Represents a vector layer which manages a vector based data sets.
virtual QgsFeatureRendererV2 * renderer()=0
return pointer to the renderer (no transfer of ownership)