QGIS API Documentation  2.17.0-Master (bf77d09)
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 
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 
103 class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsRuleBasedRendererV2Widget
104 {
105  Q_OBJECT
106 
107  public:
108 
109  static QgsRendererV2Widget* create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
110 
113 
114  virtual QgsFeatureRendererV2* renderer() override;
115 
116  public slots:
117 
118  void addRule();
119  void editRule();
120  void editRule( const QModelIndex& index );
121  void removeRule();
122  void countFeatures();
123  void clearFeatureCounts() { mModel->clearFeatureCounts(); }
124 
125  void refineRuleScales();
126  void refineRuleCategories();
127  void refineRuleRanges();
128 
129  void setRenderingOrder();
130 
131  void currentRuleChanged( const QModelIndex& current = QModelIndex(), const QModelIndex& previous = QModelIndex() );
132  void selectedRulesChanged();
133 
134  void saveSectionWidth( int section, int oldSize, int newSize );
135  void restoreSectionWidths();
136 
137  protected:
138  void refineRule( int type );
139  //TODO QGIS 3.0 - remove index parameter
140  void refineRuleCategoriesGui( const QModelIndexList& index );
141  //TODO QGIS 3.0 - remove index parameter
142  void refineRuleRangesGui( const QModelIndexList& index );
143  void refineRuleScalesGui( const QModelIndexList& index );
144 
145  QgsRuleBasedRendererV2::Rule* currentRule();
146 
147  QList<QgsSymbolV2*> selectedSymbols() override;
148  QgsRuleBasedRendererV2::RuleList selectedRules();
149  void refreshSymbolView() override;
150  void keyPressEvent( QKeyEvent* event ) override;
151 
154 
157 
159 
160  protected slots:
161  void copy() override;
162  void paste() override;
163 
164  private slots:
165  void refineRuleCategoriesAccepted( QgsPanelWidget* panel );
166  void refineRuleRangesAccepted( QgsPanelWidget* panel );
167  void ruleWidgetPanelAccepted( QgsPanelWidget* panel );
168  void liveUpdateRuleFromPanel();
169 };
170 
172 
173 #include <QDialog>
174 
175 #include "ui_qgsrendererrulepropsdialogbase.h"
177 
181 class GUI_EXPORT QgsRendererRulePropsWidget : public QgsPanelWidget, private Ui::QgsRendererRulePropsWidget
182 {
183  Q_OBJECT
184 
185  public:
194  QgsRendererRulePropsWidget( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = nullptr, QgsMapCanvas* mapCanvas = nullptr );
196 
201  QgsRuleBasedRendererV2::Rule* rule() { return mRule; }
202 
203  public slots:
204 
208  void testFilter();
209 
213  void buildExpression();
214 
218  void apply();
223  virtual void setDockMode( bool dockMode );
224 
225  protected:
228 
230  QgsSymbolV2* mSymbol; // a clone of original symbol
231 
233 };
234 
238 class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog
239 {
240  Q_OBJECT
241 
242  public:
243  QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::Rule* rule, QgsVectorLayer* layer, QgsStyleV2* style, QWidget* parent = nullptr, QgsMapCanvas* mapCanvas = nullptr );
245 
246  QgsRuleBasedRendererV2::Rule* rule() { return mPropsWidget->rule(); }
247 
248  public slots:
249  void testFilter();
250  void buildExpression();
251  void accept() override;
252 
253  private:
254  QgsRendererRulePropsWidget* mPropsWidget;
255  QDialogButtonBox* buttonBox;
256 };
257 
258 
259 #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