QGIS API Documentation  3.6.0-Noosa (5873452)
qgsrulebasedrendererwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrulebasedrendererwidget.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 QGSRULEBASEDRENDERERWIDGET_H
17 #define QGSRULEBASEDRENDERERWIDGET_H
18 
19 #include "qgsrendererwidget.h"
20 #include "qgis_sip.h"
21 
22 #include "qgsrulebasedrenderer.h"
23 class QMenu;
25 
27 
28 #include <QAbstractItemModel>
29 
30 /* Features count for rule */
32 {
33  int count; // number of features
34  int duplicateCount; // number of features present also in other rule(s)
35  // map of feature counts in other rules
36  QHash<QgsRuleBasedRenderer::Rule *, int> duplicateCountMap;
37 };
38 
47 class GUI_EXPORT QgsRuleBasedRendererModel : public QAbstractItemModel
48 {
49  Q_OBJECT
50 
51  public:
52 
56  QgsRuleBasedRendererModel( QgsRuleBasedRenderer *renderer, QObject *parent );
57 
58  Qt::ItemFlags flags( const QModelIndex &index ) const override;
59  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
60  QVariant headerData( int section, Qt::Orientation orientation,
61  int role = Qt::DisplayRole ) const override;
62  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
63  int columnCount( const QModelIndex & = QModelIndex() ) const override;
64  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
65  QModelIndex parent( const QModelIndex &index ) const override;
66 
67  // editing support
68  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
69 
70  // drag'n'drop support
71  Qt::DropActions supportedDropActions() const override;
72  QStringList mimeTypes() const override;
73  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
74  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
75 
76  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
77 
78  // new methods
79 
80  QgsRuleBasedRenderer::Rule *ruleForIndex( const QModelIndex &index ) const;
81 
82  void insertRule( const QModelIndex &parent, int before, QgsRuleBasedRenderer::Rule *newrule );
83  void updateRule( const QModelIndex &parent, int row );
84  // update rule and all its descendants
85  void updateRule( const QModelIndex &index );
86  void removeRule( const QModelIndex &index );
87 
88  void willAddRules( const QModelIndex &parent, int count ); // call beginInsertRows
89  void finishedAddingRules(); // call endInsertRows
90 
92  void setFeatureCounts( const QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> &countMap ) SIP_SKIP;
93  void clearFeatureCounts();
94 
95  protected:
96  QgsRuleBasedRenderer *mR = nullptr;
97  QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> mFeatureCountMap;
98 };
99 
100 
102 
103 #include "ui_qgsrulebasedrendererwidget.h"
104 
109 class GUI_EXPORT QgsRuleBasedRendererWidget : public QgsRendererWidget, private Ui::QgsRuleBasedRendererWidget
110 {
111  Q_OBJECT
112 
113  public:
114 
115  static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
116 
118  ~QgsRuleBasedRendererWidget() override;
119 
120  QgsFeatureRenderer *renderer() override;
121 
122  public slots:
123 
124  void addRule();
125  void editRule();
126  void editRule( const QModelIndex &index );
127  void removeRule();
128  void countFeatures();
129  void clearFeatureCounts() { mModel->clearFeatureCounts(); }
130 
131  void refineRuleScales();
132  void refineRuleCategories();
133  void refineRuleRanges();
134 
135  void setRenderingOrder();
136 
137  void currentRuleChanged( const QModelIndex &current = QModelIndex(), const QModelIndex &previous = QModelIndex() );
138  void selectedRulesChanged();
139 
140  void saveSectionWidth( int section, int oldSize, int newSize );
141  void restoreSectionWidths();
142 
143  protected:
144  void refineRule( int type );
146  void refineRuleCategoriesGui();
148  void refineRuleRangesGui();
149  void refineRuleScalesGui( const QModelIndexList &index );
150 
151  QgsRuleBasedRenderer::Rule *currentRule();
152 
153  QList<QgsSymbol *> selectedSymbols() override;
154  QgsRuleBasedRenderer::RuleList selectedRules();
155  void refreshSymbolView() override;
156  void keyPressEvent( QKeyEvent *event ) override;
157 
158  QgsRuleBasedRenderer *mRenderer = nullptr;
159  QgsRuleBasedRendererModel *mModel = nullptr;
160 
161  QMenu *mRefineMenu = nullptr;
162  QAction *mDeleteAction = nullptr;
163 
165 
166  protected slots:
167  void copy() override;
168  void paste() override;
169 
170  private slots:
171  void refineRuleCategoriesAccepted( QgsPanelWidget *panel );
172  void refineRuleRangesAccepted( QgsPanelWidget *panel );
173  void ruleWidgetPanelAccepted( QgsPanelWidget *panel );
174  void liveUpdateRuleFromPanel();
175 };
176 
178 
179 #include <QDialog>
180 
181 #include "ui_qgsrendererrulepropsdialogbase.h"
182 #include "qgis_gui.h"
183 
188 class GUI_EXPORT QgsRendererRulePropsWidget : public QgsPanelWidget, private Ui::QgsRendererRulePropsWidget
189 {
190  Q_OBJECT
191 
192  public:
193 
203  QgsVectorLayer *layer,
204  QgsStyle *style,
205  QWidget *parent SIP_TRANSFERTHIS = nullptr,
206  const QgsSymbolWidgetContext &context = QgsSymbolWidgetContext() );
207 
212  QgsRuleBasedRenderer::Rule *rule() { return mRule; }
213 
214  public slots:
215 
219  void testFilter();
220 
224  void buildExpression();
225 
229  void apply();
230 
235  void setDockMode( bool dockMode ) override;
236 
237  protected:
239  QgsVectorLayer *mLayer = nullptr;
240 
241  QgsSymbolSelectorWidget *mSymbolSelector = nullptr;
242  QgsSymbol *mSymbol = nullptr; // a clone of original symbol
243 
245 };
246 
251 class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog
252 {
253  Q_OBJECT
254 
255  public:
256 
266 
267  ~QgsRendererRulePropsDialog() override;
268 
269  QgsRuleBasedRenderer::Rule *rule() { return mPropsWidget->rule(); }
270 
271  public slots:
272  void testFilter();
273  void buildExpression();
274  void accept() override;
275 
276  private slots:
277  void showHelp();
278 
279  private:
280  QgsRendererRulePropsWidget *mPropsWidget = nullptr;
281  QDialogButtonBox *buttonBox = nullptr;
282 };
283 
284 
285 #endif // QGSRULEBASEDRENDERERWIDGET_H
Tree model for the rules:
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
Base class for renderer settings widgets.
This class keeps data about a rules for rule-based renderer.
QgsRuleBasedRenderer::RuleList mCopyBuffer
QgsRuleBasedRenderer::Rule * rule()
Returns the current set rule.
Base class for any widget that can be shown as a inline panel.
QList< QgsRuleBasedRenderer::Rule * > RuleList
QgsRuleBasedRenderer::Rule * rule()
QHash< QgsRuleBasedRenderer::Rule *, int > duplicateCountMap
#define SIP_SKIP
Definition: qgis_sip.h:119
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
When drawing a vector layer with rule-based renderer, it goes through the rules and draws features wi...
Symbol selector widget that can be used to select and build a symbol.
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsRuleBasedRenderer::Rule * mRule
QHash< QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount > mFeatureCountMap
Represents a vector layer which manages a vector based data sets.