QGIS API Documentation 3.43.0-Master (c67cf405802)
qgscategorizedsymbolrendererwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscategorizedsymbolrendererwidget.h
3 ---------------------
4 begin : November 2009
5 copyright : (C) 2009 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#ifndef QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
16#define QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
17
19#include "qgis_sip.h"
20#include "qgsrendererwidget.h"
21#include "qgsproxystyle.h"
22#include <QStandardItem>
23#include <QStyledItemDelegate>
24
25
29
30#include "ui_qgscategorizedsymbolrendererwidget.h"
31#include "qgis_gui.h"
32
33
34#ifndef SIP_RUN
36
37class GUI_EXPORT QgsCategorizedSymbolRendererModel : public QAbstractItemModel
38{
39 Q_OBJECT
40 public:
41 QgsCategorizedSymbolRendererModel( QObject *parent = nullptr, QScreen *screen = nullptr );
42 Qt::ItemFlags flags( const QModelIndex &index ) const override;
43 Qt::DropActions supportedDropActions() const override;
44 QVariant data( const QModelIndex &index, int role ) const override;
45 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
46 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
47 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
48 int columnCount( const QModelIndex & = QModelIndex() ) const override;
49 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
50 QModelIndex parent( const QModelIndex &index ) const override;
51 QStringList mimeTypes() const override;
52 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
53 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
54
55 void setRenderer( QgsCategorizedSymbolRenderer *renderer );
56
57 void addCategory( const QgsRendererCategory &cat );
58 QgsRendererCategory category( const QModelIndex &index );
59 void deleteRows( QList<int> rows );
60 void removeAllRows();
61 void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
62 void updateSymbology();
63
64 signals:
65 void rowsMoved();
66
67 private:
68 QgsCategorizedSymbolRenderer *mRenderer = nullptr;
69 QString mMimeFormat;
70 QPointer<QScreen> mScreen;
71};
72
77class QgsCategorizedSymbolRendererViewStyle : public QgsProxyStyle
78{
79 Q_OBJECT
80
81 public:
82 explicit QgsCategorizedSymbolRendererViewStyle( QWidget *parent );
83
84 void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
85};
86
91class QgsCategorizedRendererViewItemDelegate : public QStyledItemDelegate
92{
93 Q_OBJECT
94
95 public:
96 explicit QgsCategorizedRendererViewItemDelegate( QgsFieldExpressionWidget *expressionWidget, QObject *parent = nullptr );
97
98 // QAbstractItemDelegate interface
99 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
100
101 private:
102 QgsFieldExpressionWidget *mFieldExpressionWidget = nullptr;
103};
104
105
107
108#endif
109
115class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsCategorizedSymbolRendererWidget
116{
117 Q_OBJECT
118 public:
119 // *INDENT-OFF*
120
128 {
129 Value SIP_MONKEYPATCH_COMPAT_NAME( ValueRole ) = Qt::UserRole + 1
130 };
131 Q_ENUM( CustomRole )
132 // *INDENT-ON*
133
134 static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
135
138
139 QgsFeatureRenderer *renderer() override;
140 void setContext( const QgsSymbolWidgetContext &context ) override;
141 void disableSymbolLevels() override SIP_SKIP;
142 QgsExpressionContext createExpressionContext() const override;
143
152 int matchToSymbols( QgsStyle *style );
153
154 public slots:
155 void changeCategorizedSymbol();
156 void categoryColumnChanged( const QString &field );
157 void categoriesDoubleClicked( const QModelIndex &idx );
158 void addCategory();
159 void addCategories();
160
164 void applyColorRamp();
165
166 void deleteCategories();
167 void deleteAllCategories();
168
172 void deleteUnusedCategories();
173
174 void showSymbolLevels();
175
176 void rowsMoved();
177
184 void matchToSymbolsFromLibrary();
185
192 void matchToSymbolsFromXml();
193
194 protected:
195 void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
196
197 protected slots:
198
199 void pasteSymbolToSelection() override;
200
201 private slots:
202
203 void updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget );
204 void updateSymbolsFromButton();
205 void dataDefinedSizeLegend();
206
212 void mergeSelectedCategories();
213
219 void unmergeSelectedCategories();
220
221 void showContextMenu( QPoint p );
222
223 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
224
225 protected:
226 void updateUiFromRenderer();
227
228 // Called by virtual refreshSymbolView()
229 void populateCategories();
230
232 int currentCategoryRow();
233
235 QList<int> selectedCategories();
236
238 void changeSelectedSymbols();
239
240 void changeCategorySymbol();
242 void applyChangeToSymbol();
243
249 QList<QVariant> layerUniqueValues( const QString &attrName );
250
251 QList<QgsSymbol *> selectedSymbols() override;
252 QgsCategoryList selectedCategoryList();
253 void refreshSymbolView() override;
254 void keyPressEvent( QKeyEvent *event ) override;
255
256 protected:
257 std::unique_ptr<QgsCategorizedSymbolRenderer> mRenderer;
258
259 std::unique_ptr<QgsSymbol> mCategorizedSymbol;
260
261 QgsCategorizedSymbolRendererModel *mModel = nullptr;
262
263 private:
264 QString mOldClassificationAttribute;
265 QgsCategoryList mCopyBuffer;
266 QMenu *mContextMenu = nullptr;
267 QAction *mMergeCategoriesAction = nullptr;
268 QAction *mUnmergeCategoriesAction = nullptr;
269 QAction *mActionLevels = nullptr;
270
271 friend class TestQgsCategorizedRendererWidget;
272};
273
274#endif // QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
A widget for configuring a QgsCategorizedSymbolRenderer.
A feature renderer which represents features using a list of renderer categories.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract base class for all 2D vector feature renderers.
A widget for selection of layer fields or expression creation.
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
Base class for renderer settings widgets.
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_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273
QList< QgsRendererCategory > QgsCategoryList
QList< QgsLegendSymbolItem > QgsLegendSymbolList