QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
94  void setSymbol( const QModelIndex &index, QgsSymbol *symbol SIP_TRANSFER );
95 
96  void willAddRules( const QModelIndex &parent, int count ); // call beginInsertRows
97  void finishedAddingRules(); // call endInsertRows
98 
100  void setFeatureCounts( const QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> &countMap ) SIP_SKIP;
101  void clearFeatureCounts();
102 
103  protected:
104  QgsRuleBasedRenderer *mR = nullptr;
105  QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> mFeatureCountMap;
106 };
107 
108 
110 
111 #include "ui_qgsrulebasedrendererwidget.h"
112 
117 class GUI_EXPORT QgsRuleBasedRendererWidget : public QgsRendererWidget, private Ui::QgsRuleBasedRendererWidget
118 {
119  Q_OBJECT
120 
121  public:
122 
123  static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
124 
125  QgsRuleBasedRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer );
126  ~QgsRuleBasedRendererWidget() override;
127 
128  QgsFeatureRenderer *renderer() override;
129 
130  public slots:
131 
132  void addRule();
133  void editRule();
134  void editRule( const QModelIndex &index );
135  void removeRule();
136  void countFeatures();
137  void clearFeatureCounts() { mModel->clearFeatureCounts(); }
138 
139  void refineRuleScales();
140  void refineRuleCategories();
141  void refineRuleRanges();
142 
143  void setRenderingOrder();
144 
145  void currentRuleChanged( const QModelIndex &current = QModelIndex(), const QModelIndex &previous = QModelIndex() );
146  void selectedRulesChanged();
147 
148  void saveSectionWidth( int section, int oldSize, int newSize );
149  void restoreSectionWidths();
150 
151  protected:
152  void refineRule( int type );
154  void refineRuleCategoriesGui();
156  void refineRuleRangesGui();
157  void refineRuleScalesGui( const QModelIndexList &index );
158 
159  QgsRuleBasedRenderer::Rule *currentRule();
160 
161  QList<QgsSymbol *> selectedSymbols() override;
162  QgsRuleBasedRenderer::RuleList selectedRules();
163  void refreshSymbolView() override;
164  void keyPressEvent( QKeyEvent *event ) override;
165 
166  QgsRuleBasedRenderer *mRenderer = nullptr;
167  QgsRuleBasedRendererModel *mModel = nullptr;
168 
169  QMenu *mRefineMenu = nullptr;
170  QAction *mDeleteAction = nullptr;
171 
173  QMenu *mContextMenu = nullptr;
174 
175  protected slots:
176  void copy() override;
177  void paste() override;
178  void pasteSymbolToSelection() override;
179 
180  private slots:
181  void refineRuleCategoriesAccepted( QgsPanelWidget *panel );
182  void refineRuleRangesAccepted( QgsPanelWidget *panel );
183  void ruleWidgetPanelAccepted( QgsPanelWidget *panel );
184  void liveUpdateRuleFromPanel();
185  void showContextMenu( QPoint p );
186 };
187 
189 
190 #include <QDialog>
191 
192 #include "ui_qgsrendererrulepropsdialogbase.h"
193 #include "qgis_gui.h"
194 
199 class GUI_EXPORT QgsRendererRulePropsWidget : public QgsPanelWidget, private Ui::QgsRendererRulePropsWidget
200 {
201  Q_OBJECT
202 
203  public:
204 
213  QgsRendererRulePropsWidget( QgsRuleBasedRenderer::Rule *rule,
214  QgsVectorLayer *layer,
215  QgsStyle *style,
216  QWidget *parent SIP_TRANSFERTHIS = nullptr,
217  const QgsSymbolWidgetContext &context = QgsSymbolWidgetContext() );
218 
223  QgsRuleBasedRenderer::Rule *rule() { return mRule; }
224 
225  public slots:
226 
230  void testFilter();
231 
235  void buildExpression();
236 
240  void apply();
241 
246  void setDockMode( bool dockMode ) override;
247 
248  protected:
250  QgsVectorLayer *mLayer = nullptr;
251 
252  QgsSymbolSelectorWidget *mSymbolSelector = nullptr;
253  QgsSymbol *mSymbol = nullptr; // a clone of original symbol
254 
256 };
257 
262 class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog
263 {
264  Q_OBJECT
265 
266  public:
267 
277 
278  QgsRuleBasedRenderer::Rule *rule() { return mPropsWidget->rule(); }
279 
280  public slots:
281  void testFilter();
282  void buildExpression();
283  void accept() override;
284 
285  private slots:
286  void showHelp();
287 
288  private:
289  QgsRendererRulePropsWidget *mPropsWidget = nullptr;
290  QDialogButtonBox *buttonBox = nullptr;
291 };
292 
293 
294 #endif // QGSRULEBASEDRENDERERWIDGET_H
Tree model for the rules:
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
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:126
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
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:76
QgsRuleBasedRenderer::Rule * mRule
QHash< QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount > mFeatureCountMap
Represents a vector layer which manages a vector based data sets.