QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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, QScreen *screen = nullptr );
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 QPointer< QScreen > mScreen;
107};
108
109
111
112#include "ui_qgsrulebasedrendererwidget.h"
113
118class GUI_EXPORT QgsRuleBasedRendererWidget : public QgsRendererWidget, private Ui::QgsRuleBasedRendererWidget
119{
120 Q_OBJECT
121
122 public:
123
124 static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
125
128
129 QgsFeatureRenderer *renderer() override;
130 void setDockMode( bool dockMode ) override;
131
132 public slots:
133
134 void addRule();
135 void editRule();
136 void editRule( const QModelIndex &index );
137 void removeRule();
138 void countFeatures();
139 void clearFeatureCounts() { mModel->clearFeatureCounts(); }
140
141 void refineRuleScales();
142 void refineRuleCategories();
143 void refineRuleRanges();
144
145 void setRenderingOrder();
146
147 void currentRuleChanged( const QModelIndex &current = QModelIndex(), const QModelIndex &previous = QModelIndex() );
148 void selectedRulesChanged();
149
150 void saveSectionWidth( int section, int oldSize, int newSize );
151 void restoreSectionWidths();
152
153 protected:
154 void refineRule( int type );
156 void refineRuleCategoriesGui();
158 void refineRuleRangesGui();
159 void refineRuleScalesGui( const QModelIndexList &index );
160
161 void setSymbolLevels( const QList< QgsLegendSymbolItem > &levels, bool enabled ) override;
162
163 QgsRuleBasedRenderer::Rule *currentRule();
164
165 QList<QgsSymbol *> selectedSymbols() override;
166 QgsRuleBasedRenderer::RuleList selectedRules();
167 void refreshSymbolView() override;
168 void keyPressEvent( QKeyEvent *event ) override;
169
170 std::unique_ptr< QgsRuleBasedRenderer > mRenderer;
171 QgsRuleBasedRendererModel *mModel = nullptr;
172
173 QMenu *mRefineMenu = nullptr;
174 QAction *mDeleteAction = nullptr;
175
177 QMenu *mContextMenu = nullptr;
178
179 protected slots:
180 void copy() override;
181 void paste() override;
182 void pasteSymbolToSelection() override;
183
184 private slots:
185 void refineRuleCategoriesAccepted( QgsPanelWidget *panel );
186 void refineRuleRangesAccepted( QgsPanelWidget *panel );
187 void ruleWidgetPanelAccepted( QgsPanelWidget *panel );
188 void liveUpdateRuleFromPanel();
189 void showContextMenu( QPoint p );
190};
191
193
194#include <QDialog>
195
196#include "ui_qgsrendererrulepropsdialogbase.h"
197#include "qgis_gui.h"
198
203class GUI_EXPORT QgsRendererRulePropsWidget : public QgsPanelWidget, private Ui::QgsRendererRulePropsWidget
204{
205 Q_OBJECT
206
207 public:
208
218 QgsVectorLayer *layer,
219 QgsStyle *style,
220 QWidget *parent SIP_TRANSFERTHIS = nullptr,
222
227 QgsRuleBasedRenderer::Rule *rule() { return mRule; }
228
229 public slots:
230
234 void testFilter();
235
239 void buildExpression();
240
244 void apply();
245
250 void setDockMode( bool dockMode ) override;
251
252 protected:
254 QgsVectorLayer *mLayer = nullptr;
255
256 QgsSymbolSelectorWidget *mSymbolSelector = nullptr;
257 QgsSymbol *mSymbol = nullptr; // a clone of original symbol
258
260};
261
266class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog
267{
268 Q_OBJECT
269
270 public:
271
281
282 QgsRuleBasedRenderer::Rule *rule() { return mPropsWidget->rule(); }
283
284 public slots:
285 void testFilter();
286 void buildExpression();
287 void accept() override;
288
289 private slots:
290 void showHelp();
291
292 private:
293 QgsRendererRulePropsWidget *mPropsWidget = nullptr;
294 QDialogButtonBox *buttonBox = nullptr;
295};
296
297
298#endif // QGSRULEBASEDRENDERERWIDGET_H
Abstract base class for all 2D vector feature renderers.
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:231
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