QGIS API Documentation  2.15.0-Master (02a0ebe)
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  void selectedRulesChanged();
130 
131  void saveSectionWidth( int section, int oldSize, int newSize );
132  void restoreSectionWidths();
133 
134  protected:
135  void refineRule( int type );
136  void refineRuleCategoriesGui( const QModelIndexList& index );
137  void refineRuleRangesGui( const QModelIndexList& index );
138  void refineRuleScalesGui( const QModelIndexList& index );
139 
140  QgsRuleBasedRendererV2::Rule* currentRule();
141 
142  QList<QgsSymbolV2*> selectedSymbols() override;
143  QgsRuleBasedRendererV2::RuleList selectedRules();
144  void refreshSymbolView() override;
145  void keyPressEvent( QKeyEvent* event ) override;
146 
149 
152 
154 
155  protected slots:
156  void copy() override;
157  void paste() override;
158 
159  private slots:
160  void ruleWidgetPanelAccepted( QgsPanelWidget* panel );
161  void liveUpdateRuleFromPanel();
162 };
163 
165 
166 #include <QDialog>
167 
168 #include "ui_qgsrendererrulepropsdialogbase.h"
170 
171 class GUI_EXPORT QgsRendererRulePropsWidget : public QgsPanelWidget, private Ui::QgsRendererRulePropsWidget
172 {
173  Q_OBJECT
174 
175  public:
184  QgsRendererRulePropsWidget( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = nullptr, QgsMapCanvas* mapCanvas = nullptr );
186 
191  QgsRuleBasedRendererV2::Rule* rule() { return mRule; }
192 
193  public slots:
194 
198  void testFilter();
199 
203  void buildExpression();
204 
208  void apply();
213  virtual void setDockMode( bool dockMode );
214 
215  protected:
218 
220  QgsSymbolV2* mSymbol; // a clone of original symbol
221 
223 };
224 
225 
226 class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog
227 {
228  Q_OBJECT
229 
230  public:
231  QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = nullptr, QgsMapCanvas* mapCanvas = nullptr );
233 
234  QgsRuleBasedRendererV2::Rule* rule() { return mPropsWidget->rule(); }
235 
236  public slots:
237  void testFilter();
238  void buildExpression();
239  void accept() override;
240 
241  private:
242  QgsRendererRulePropsWidget* mPropsWidget;
243  QDialogButtonBox* buttonBox;
244 };
245 
246 
247 #endif // QGSRULEBASEDRENDERERV2WIDGET_H
Symbol selector widget that cna be used to select and build a symbol.
static unsigned index
QMap< QgsRuleBasedRendererV2::Rule *, int > duplicateCountMap
QgsRuleBasedRendererV2Model * mModel
QgsRuleBasedRendererV2::Rule * rule()
Return the current set rule.
QgsRuleBasedRendererV2::Rule * mRule
QgsRuleBasedRendererV2::RuleList mCopyBuffer
Base class for any widget that can be shown as a inline panel.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
QgsSymbolV2SelectorWidget * mSymbolSelector
This class keeps data about a rules for rule-based renderer.
QMap< QgsRuleBasedRendererV2::Rule *, QgsRuleBasedRendererV2Count > mFeatureCountMap
typedef DropActions
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 * rule()
Represents a vector layer which manages a vector based data sets.
typedef ItemFlags