QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 "qgis_sip.h"
20#include "qgsrendererwidget.h"
22
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
51class GUI_EXPORT QgsRuleBasedRendererModel : public QAbstractItemModel
52{
53 Q_OBJECT
54
55 public:
56
60 QgsRuleBasedRendererModel( QgsRuleBasedRenderer *renderer, QObject *parent, QScreen *screen = nullptr );
61
62 Qt::ItemFlags flags( const QModelIndex &index ) const override;
63 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
64 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
65 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
66 int columnCount( const QModelIndex & = QModelIndex() ) const override;
67 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
68 QModelIndex parent( const QModelIndex &index ) const override;
69
70 // editing support
71 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
72
73 // drag'n'drop support
74 Qt::DropActions supportedDropActions() const override;
75 QStringList mimeTypes() const override;
76 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
77 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
78
79 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
80
81 // new methods
82
83 QgsRuleBasedRenderer::Rule *ruleForIndex( const QModelIndex &index ) const;
84
85 void insertRule( const QModelIndex &parent, int before, QgsRuleBasedRenderer::Rule *newrule );
86 void updateRule( const QModelIndex &parent, int row );
87 // update rule and all its descendants
88 void updateRule( const QModelIndex &index );
89 void removeRule( const QModelIndex &index );
90
97 void setSymbol( const QModelIndex &index, QgsSymbol *symbol SIP_TRANSFER );
98
99 void willAddRules( const QModelIndex &parent, int count ); // call beginInsertRows
100 void finishedAddingRules(); // call endInsertRows
101
103 void setFeatureCounts( const QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> &countMap ) SIP_SKIP;
104 void clearFeatureCounts();
105
106 protected:
108 QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> mFeatureCountMap;
109 QPointer<QScreen> mScreen;
110};
111
112
114
115#include "ui_qgsrulebasedrendererwidget.h"
116
122class GUI_EXPORT QgsRuleBasedRendererWidget : public QgsRendererWidget, private Ui::QgsRuleBasedRendererWidget
123{
124 Q_OBJECT
125
126 public:
128
131
132 QgsFeatureRenderer *renderer() override;
133 void setDockMode( bool dockMode ) override;
134
135 public slots:
136
137 void addRule();
138 void editRule();
139 void editRule( const QModelIndex &index );
140 void removeRule();
141 void countFeatures();
142 void clearFeatureCounts() { mModel->clearFeatureCounts(); }
143
144 void refineRuleScales();
145 void refineRuleCategories();
146 void refineRuleRanges();
147
148 void setRenderingOrder();
149
150 void currentRuleChanged( const QModelIndex &current = QModelIndex(), const QModelIndex &previous = QModelIndex() );
151 void selectedRulesChanged();
152
153 void saveSectionWidth( int section, int oldSize, int newSize );
154 void restoreSectionWidths();
155
156 protected:
157 void refineRule( int type );
159 void refineRuleCategoriesGui();
161 void refineRuleRangesGui();
162 void refineRuleScalesGui( const QModelIndexList &index );
163
164 void setSymbolLevels( const QList<QgsLegendSymbolItem> &levels, bool enabled ) override;
165
166 QgsRuleBasedRenderer::Rule *currentRule();
167
168 QList<QgsSymbol *> selectedSymbols() override;
169 QgsRuleBasedRenderer::RuleList selectedRules();
170 void refreshSymbolView() override;
171 void keyPressEvent( QKeyEvent *event ) override;
172
173 std::unique_ptr<QgsRuleBasedRenderer> mRenderer;
175
176 QMenu *mRefineMenu = nullptr;
177 QAction *mDeleteAction = nullptr;
178
180 QMenu *mContextMenu = nullptr;
181
182 protected slots:
183 void copy() override;
184 void paste() override;
185 void pasteSymbolToSelection() override;
186
187 private slots:
188 void refineRuleCategoriesAccepted( QgsPanelWidget *panel );
189 void refineRuleRangesAccepted( QgsPanelWidget *panel );
190 void ruleWidgetPanelAccepted( QgsPanelWidget *panel );
191 void liveUpdateRuleFromPanel();
192 void showContextMenu( QPoint p );
193};
194
196
197#include <QDialog>
198
199#include "ui_qgsrendererrulepropsdialogbase.h"
200#include "qgis_gui.h"
201
207class GUI_EXPORT QgsRendererRulePropsWidget : public QgsPanelWidget, private Ui::QgsRendererRulePropsWidget
208{
209 Q_OBJECT
210
211 public:
212
222
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:
255
257 QgsSymbol *mSymbol = nullptr; // a clone of original symbol
258
260};
261
267class GUI_EXPORT QgsRendererRulePropsDialog : public QDialog
268{
269 Q_OBJECT
270
271 public:
272
282
283 QgsRuleBasedRenderer::Rule *rule() { return mPropsWidget->rule(); }
284
285 public slots:
286 void testFilter();
287 void buildExpression();
288 void accept() override;
289
290 private slots:
291 void showHelp();
292
293 private:
294 QgsRendererRulePropsWidget *mPropsWidget = nullptr;
295 QDialogButtonBox *buttonBox = nullptr;
296};
297
298
299#endif // QGSRULEBASEDRENDERERWIDGET_H
Abstract base class for all 2D vector feature renderers.
bool dockMode() const
Returns the dock mode state.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
QgsRuleBasedRenderer::Rule * rule()
QgsRendererRulePropsDialog(QgsRuleBasedRenderer::Rule *rule, QgsVectorLayer *layer, QgsStyle *style, QWidget *parent=nullptr, const QgsSymbolWidgetContext &context=QgsSymbolWidgetContext())
Constructor for QgsRendererRulePropsDialog.
A widget for editing the details of a rule based renderer rule.
QgsRendererRulePropsWidget(QgsRuleBasedRenderer::Rule *rule, QgsVectorLayer *layer, QgsStyle *style, QWidget *parent=nullptr, const QgsSymbolWidgetContext &context=QgsSymbolWidgetContext())
Widget to edit the details of a rule based renderer rule.
QgsSymbolSelectorWidget * mSymbolSelector
QgsRuleBasedRenderer::Rule * mRule
QgsRuleBasedRenderer::Rule * rule()
Returns the current set rule.
QgsRendererWidget(QgsVectorLayer *layer, QgsStyle *style)
Tree model for a rule-based renderer's rules.
QgsRuleBasedRenderer::Rule * ruleForIndex(const QModelIndex &index) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
void updateRule(const QModelIndex &parent, int row)
void willAddRules(const QModelIndex &parent, int count)
Qt::ItemFlags flags(const QModelIndex &index) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void setSymbol(const QModelIndex &index, QgsSymbol *symbol)
Sets the symbol for the rule at the specified index.
QStringList mimeTypes() const override
void removeRule(const QModelIndex &index)
int columnCount(const QModelIndex &=QModelIndex()) const override
Qt::DropActions supportedDropActions() const override
QgsRuleBasedRendererModel(QgsRuleBasedRenderer *renderer, QObject *parent, QScreen *screen=nullptr)
Constructor for QgsRuleBasedRendererModel, for the specified renderer.
void setFeatureCounts(const QHash< QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount > &countMap)
QModelIndex parent(const QModelIndex &index) const override
QHash< QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount > mFeatureCountMap
QMimeData * mimeData(const QModelIndexList &indexes) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
void insertRule(const QModelIndex &parent, int before, QgsRuleBasedRenderer::Rule *newrule)
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
static QgsRendererWidget * create(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
std::unique_ptr< QgsRuleBasedRenderer > mRenderer
QgsRuleBasedRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
QgsRuleBasedRenderer::RuleList mCopyBuffer
QgsRuleBasedRendererModel * mModel
void setDockMode(bool dockMode) override
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
QgsFeatureRenderer * renderer() override
Returns pointer to the renderer (no transfer of ownership).
Represents an individual rule for a rule-based renderer.
Rule based renderer.
QList< QgsRuleBasedRenderer::Rule * > RuleList
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition qgsstyle.h:88
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 dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:84
QHash< QgsRuleBasedRenderer::Rule *, int > duplicateCountMap