QGIS API Documentation 3.41.0-Master (af5edcb665c)
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:
55 QgsRuleBasedRendererModel( QgsRuleBasedRenderer *renderer, QObject *parent, QScreen *screen = nullptr );
56
57 Qt::ItemFlags flags( const QModelIndex &index ) const override;
58 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
59 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
60 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
61 int columnCount( const QModelIndex & = QModelIndex() ) const override;
62 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
63 QModelIndex parent( const QModelIndex &index ) const override;
64
65 // editing support
66 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
67
68 // drag'n'drop support
69 Qt::DropActions supportedDropActions() const override;
70 QStringList mimeTypes() const override;
71 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
72 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
73
74 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
75
76 // new methods
77
78 QgsRuleBasedRenderer::Rule *ruleForIndex( const QModelIndex &index ) const;
79
80 void insertRule( const QModelIndex &parent, int before, QgsRuleBasedRenderer::Rule *newrule );
81 void updateRule( const QModelIndex &parent, int row );
82 // update rule and all its descendants
83 void updateRule( const QModelIndex &index );
84 void removeRule( const QModelIndex &index );
85
92 void setSymbol( const QModelIndex &index, QgsSymbol *symbol SIP_TRANSFER );
93
94 void willAddRules( const QModelIndex &parent, int count ); // call beginInsertRows
95 void finishedAddingRules(); // call endInsertRows
96
98 void setFeatureCounts( const QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> &countMap ) SIP_SKIP;
99 void clearFeatureCounts();
100
101 protected:
102 QgsRuleBasedRenderer *mR = nullptr;
103 QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> mFeatureCountMap;
104 QPointer<QScreen> mScreen;
105};
106
107
109
110#include "ui_qgsrulebasedrendererwidget.h"
111
116class GUI_EXPORT QgsRuleBasedRendererWidget : public QgsRendererWidget, private Ui::QgsRuleBasedRendererWidget
117{
118 Q_OBJECT
119
120 public:
121 static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
122
125
126 QgsFeatureRenderer *renderer() override;
127 void setDockMode( bool dockMode ) override;
128
129 public slots:
130
131 void addRule();
132 void editRule();
133 void editRule( const QModelIndex &index );
134 void removeRule();
135 void countFeatures();
136 void clearFeatureCounts() { mModel->clearFeatureCounts(); }
137
138 void refineRuleScales();
139 void refineRuleCategories();
140 void refineRuleRanges();
141
142 void setRenderingOrder();
143
144 void currentRuleChanged( const QModelIndex &current = QModelIndex(), const QModelIndex &previous = QModelIndex() );
145 void selectedRulesChanged();
146
147 void saveSectionWidth( int section, int oldSize, int newSize );
148 void restoreSectionWidths();
149
150 protected:
151 void refineRule( int type );
153 void refineRuleCategoriesGui();
155 void refineRuleRangesGui();
156 void refineRuleScalesGui( const QModelIndexList &index );
157
158 void setSymbolLevels( const QList<QgsLegendSymbolItem> &levels, bool enabled ) override;
159
160 QgsRuleBasedRenderer::Rule *currentRule();
161
162 QList<QgsSymbol *> selectedSymbols() override;
163 QgsRuleBasedRenderer::RuleList selectedRules();
164 void refreshSymbolView() override;
165 void keyPressEvent( QKeyEvent *event ) override;
166
167 std::unique_ptr<QgsRuleBasedRenderer> mRenderer;
168 QgsRuleBasedRendererModel *mModel = nullptr;
169
170 QMenu *mRefineMenu = nullptr;
171 QAction *mDeleteAction = nullptr;
172
174 QMenu *mContextMenu = nullptr;
175
176 protected slots:
177 void copy() override;
178 void paste() override;
179 void pasteSymbolToSelection() override;
180
181 private slots:
182 void refineRuleCategoriesAccepted( QgsPanelWidget *panel );
183 void refineRuleRangesAccepted( QgsPanelWidget *panel );
184 void ruleWidgetPanelAccepted( QgsPanelWidget *panel );
185 void liveUpdateRuleFromPanel();
186 void showContextMenu( QPoint p );
187};
188
190
191#include <QDialog>
192
193#include "ui_qgsrendererrulepropsdialogbase.h"
194#include "qgis_gui.h"
195
200class GUI_EXPORT QgsRendererRulePropsWidget : public QgsPanelWidget, private Ui::QgsRendererRulePropsWidget
201{
202 Q_OBJECT
203
204 public:
214
219 QgsRuleBasedRenderer::Rule *rule() { return mRule; }
220
221 public slots:
222
226 void testFilter();
227
231 void buildExpression();
232
236 void apply();
237
242 void setDockMode( bool dockMode ) override;
243
244 protected:
246 QgsVectorLayer *mLayer = nullptr;
247
248 QgsSymbolSelectorWidget *mSymbolSelector = nullptr;
249 QgsSymbol *mSymbol = nullptr; // a clone of original symbol
250
252};
253
258class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog
259{
260 Q_OBJECT
261
262 public:
272
273 QgsRuleBasedRenderer::Rule *rule() { return mPropsWidget->rule(); }
274
275 public slots:
276 void testFilter();
277 void buildExpression();
278 void accept() override;
279
280 private slots:
281 void showHelp();
282
283 private:
284 QgsRendererRulePropsWidget *mPropsWidget = nullptr;
285 QDialogButtonBox *buttonBox = nullptr;
286};
287
288
289#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
std::unique_ptr< QgsRuleBasedRenderer > mRenderer
QgsRuleBasedRenderer::RuleList mCopyBuffer
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