QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
23class 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
47class 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
117class 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
127
128 QgsFeatureRenderer *renderer() override;
129 void setDockMode( bool dockMode ) override;
130
131 public slots:
132
133 void addRule();
134 void editRule();
135 void editRule( const QModelIndex &index );
136 void removeRule();
137 void countFeatures();
138 void clearFeatureCounts() { mModel->clearFeatureCounts(); }
139
140 void refineRuleScales();
141 void refineRuleCategories();
142 void refineRuleRanges();
143
144 void setRenderingOrder();
145
146 void currentRuleChanged( const QModelIndex &current = QModelIndex(), const QModelIndex &previous = QModelIndex() );
147 void selectedRulesChanged();
148
149 void saveSectionWidth( int section, int oldSize, int newSize );
150 void restoreSectionWidths();
151
152 protected:
153 void refineRule( int type );
155 void refineRuleCategoriesGui();
157 void refineRuleRangesGui();
158 void refineRuleScalesGui( const QModelIndexList &index );
159
160 void setSymbolLevels( const QList< QgsLegendSymbolItem > &levels, bool enabled ) override;
161
162 QgsRuleBasedRenderer::Rule *currentRule();
163
164 QList<QgsSymbol *> selectedSymbols() override;
165 QgsRuleBasedRenderer::RuleList selectedRules();
166 void refreshSymbolView() override;
167 void keyPressEvent( QKeyEvent *event ) override;
168
169 std::unique_ptr< QgsRuleBasedRenderer > mRenderer;
170 QgsRuleBasedRendererModel *mModel = nullptr;
171
172 QMenu *mRefineMenu = nullptr;
173 QAction *mDeleteAction = nullptr;
174
176 QMenu *mContextMenu = nullptr;
177
178 protected slots:
179 void copy() override;
180 void paste() override;
181 void pasteSymbolToSelection() override;
182
183 private slots:
184 void refineRuleCategoriesAccepted( QgsPanelWidget *panel );
185 void refineRuleRangesAccepted( QgsPanelWidget *panel );
186 void ruleWidgetPanelAccepted( QgsPanelWidget *panel );
187 void liveUpdateRuleFromPanel();
188 void showContextMenu( QPoint p );
189};
190
192
193#include <QDialog>
194
195#include "ui_qgsrendererrulepropsdialogbase.h"
196#include "qgis_gui.h"
197
202class GUI_EXPORT QgsRendererRulePropsWidget : public QgsPanelWidget, private Ui::QgsRendererRulePropsWidget
203{
204 Q_OBJECT
205
206 public:
207
217 QgsVectorLayer *layer,
218 QgsStyle *style,
219 QWidget *parent SIP_TRANSFERTHIS = nullptr,
221
226 QgsRuleBasedRenderer::Rule *rule() { return mRule; }
227
228 public slots:
229
233 void testFilter();
234
238 void buildExpression();
239
243 void apply();
244
249 void setDockMode( bool dockMode ) override;
250
251 protected:
253 QgsVectorLayer *mLayer = nullptr;
254
255 QgsSymbolSelectorWidget *mSymbolSelector = nullptr;
256 QgsSymbol *mSymbol = nullptr; // a clone of original symbol
257
259};
260
265class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog
266{
267 Q_OBJECT
268
269 public:
270
280
281 QgsRuleBasedRenderer::Rule *rule() { return mPropsWidget->rule(); }
282
283 public slots:
284 void testFilter();
285 void buildExpression();
286 void accept() override;
287
288 private slots:
289 void showHelp();
290
291 private:
292 QgsRendererRulePropsWidget *mPropsWidget = nullptr;
293 QDialogButtonBox *buttonBox = nullptr;
294};
295
296
297#endif // QGSRULEBASEDRENDERERWIDGET_H
Base class for any widget that can be shown as a inline panel.
QgsRuleBasedRenderer::Rule * rule()
QgsRuleBasedRenderer::Rule * mRule
QgsRuleBasedRenderer::Rule * rule()
Returns the current set rule.
Base class for renderer settings widgets.
QHash< QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount > mFeatureCountMap
QgsRuleBasedRenderer::RuleList mCopyBuffer
std::unique_ptr< QgsRuleBasedRenderer > mRenderer
This class keeps data about a rules for rule-based renderer.
Rule based renderer.
QList< QgsRuleBasedRenderer::Rule * > RuleList
Symbol selector widget that can be used to select and build a symbol.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
QHash< QgsRuleBasedRenderer::Rule *, int > duplicateCountMap