QGIS API Documentation  2.12.0-Lyon
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
35 };
36 
37 /*
38 Tree model for the rules:
39 
40 (invalid) == root node
41  +--- top level rule
42  +--- top level rule
43 */
45 {
46  Q_OBJECT
47 
48  public:
50 
51  virtual Qt::ItemFlags flags( const QModelIndex &index ) const override;
52  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
53  virtual QVariant headerData( int section, Qt::Orientation orientation,
54  int role = Qt::DisplayRole ) const override;
55  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
56  virtual int columnCount( const QModelIndex & = QModelIndex() ) const override;
58  virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
60  virtual QModelIndex parent( const QModelIndex &index ) const override;
61 
62  // editing support
63  virtual bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) override;
64 
65  // drag'n'drop support
66  Qt::DropActions supportedDropActions() const override;
67  QStringList mimeTypes() const override;
68  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
69  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
70 
71  bool removeRows( int row, int count, const QModelIndex & parent = QModelIndex() ) override;
72 
73  // new methods
74 
75  QgsRuleBasedRendererV2::Rule* ruleForIndex( const QModelIndex& index ) const;
76 
77  void insertRule( const QModelIndex& parent, int before, QgsRuleBasedRendererV2::Rule* newrule );
78  void updateRule( const QModelIndex& parent, int row );
79  // update rule and all its descendants
80  void updateRule( const QModelIndex& index );
81  void removeRule( const QModelIndex& index );
82 
83  void willAddRules( const QModelIndex& parent, int count ); // call beginInsertRows
84  void finishedAddingRules(); // call endInsertRows
85 
87  void setFeatureCounts( const QMap<QgsRuleBasedRendererV2::Rule*, QgsRuleBasedRendererV2Count>& theCountMap );
88  void clearFeatureCounts();
89 
90  protected:
93 };
94 
95 
97 
98 #include "ui_qgsrulebasedrendererv2widget.h"
99 
100 class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsRuleBasedRendererV2Widget
101 {
102  Q_OBJECT
103 
104  public:
105 
106  static QgsRendererV2Widget* create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
107 
110 
111  virtual QgsFeatureRendererV2* renderer() override;
112 
113  public slots:
114 
115  void addRule();
116  void editRule();
117  void editRule( const QModelIndex& index );
118  void removeRule();
119  void countFeatures();
120  void clearFeatureCounts() { mModel->clearFeatureCounts(); }
121 
122  void refineRuleScales();
123  void refineRuleCategories();
124  void refineRuleRanges();
125 
126  void setRenderingOrder();
127 
128  void currentRuleChanged( const QModelIndex& current = QModelIndex(), const QModelIndex& previous = QModelIndex() );
129 
130  void saveSectionWidth( int section, int oldSize, int newSize );
131  void restoreSectionWidths();
132 
133  protected:
134  void refineRule( int type );
135  void refineRuleCategoriesGui( const QModelIndexList& index );
136  void refineRuleRangesGui( const QModelIndexList& index );
137  void refineRuleScalesGui( const QModelIndexList& index );
138 
139  QgsRuleBasedRendererV2::Rule* currentRule();
140 
142  QgsRuleBasedRendererV2::RuleList selectedRules();
143  void refreshSymbolView() override;
144  void keyPressEvent( QKeyEvent* event ) override;
145 
148 
151 
153 
154  protected slots:
155  void copy() override;
156  void paste() override;
157 };
158 
160 
161 #include <QDialog>
162 
163 #include "ui_qgsrendererrulepropsdialogbase.h"
164 
165 class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog, private Ui::QgsRendererRulePropsDialog
166 {
167  Q_OBJECT
168 
169  public:
170  QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = 0, QgsMapCanvas* mapCanvas = 0 );
172 
173  QgsRuleBasedRendererV2::Rule* rule() { return mRule; }
174 
175  public slots:
176  void testFilter();
177  void buildExpression();
178  void accept() override;
179 
180  protected:
183 
185  QgsSymbolV2* mSymbol; // a clone of original symbol
186 
188 };
189 
190 
191 #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
virtual int rowCount(const QModelIndex &parent) const =0
QgsSymbolV2SelectorDialog * mSymbolSelector
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
void create(WId window, bool initializeWindow, bool destroyOldWindow)
QgsRuleBasedRendererV2Model * mModel
QgsRuleBasedRendererV2::RuleList mCopyBuffer
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:107
virtual QStringList mimeTypes() const
virtual Qt::DropActions supportedDropActions() const
This class keeps data about a rules for rule-based renderer.
virtual QVariant data(const QModelIndex &index, int role) const =0
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
QMap< QgsRuleBasedRendererV2::Rule *, QgsRuleBasedRendererV2Count > mFeatureCountMap
virtual void accept()
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual bool removeRows(int row, int count, const QModelIndex &parent)
typedef DropActions
When drawing a vector layer with rule-based renderer, it goes through the rules and draws features wi...
virtual int columnCount(const QModelIndex &parent) const =0
virtual void keyPressEvent(QKeyEvent *event)
Base class for renderer settings widgets.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QgsRuleBasedRendererV2::Rule * mRule
virtual Qt::ItemFlags flags(const QModelIndex &index) const
QgsRuleBasedRendererV2::Rule * rule()
virtual void refreshSymbolView()
QObject * parent() const
Represents a vector layer which manages a vector based data sets.
virtual QgsFeatureRendererV2 * renderer()=0
return pointer to the renderer (no transfer of ownership)
typedef ItemFlags