QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
103 QgsFieldExpressionWidget *mFieldExpressionWidget = nullptr;
104};
105
106
108
109#endif
110
115class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsCategorizedSymbolRendererWidget, private QgsExpressionContextGenerator
116{
117 Q_OBJECT
118 public:
119
120 // *INDENT-OFF*
121
129 {
130 Value SIP_MONKEYPATCH_COMPAT_NAME(ValueRole) = Qt::UserRole + 1
131 };
132 Q_ENUM( CustomRole )
133 // *INDENT-ON*
134
135 static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
136
139
140 QgsFeatureRenderer *renderer() override;
141 void setContext( const QgsSymbolWidgetContext &context ) override;
142 void disableSymbolLevels() override SIP_SKIP;
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
169 void showSymbolLevels();
170
171 void rowsMoved();
172
179 void matchToSymbolsFromLibrary();
180
187 void matchToSymbolsFromXml();
188
189 protected:
190 void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
191
192 protected slots:
193
194 void pasteSymbolToSelection() override;
195
196 private slots:
197
198 void updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget );
199 void updateSymbolsFromButton();
200 void dataDefinedSizeLegend();
201
207 void mergeSelectedCategories();
208
214 void unmergeSelectedCategories();
215
216 void showContextMenu( QPoint p );
217
218 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
219
220 protected:
221
222 void updateUiFromRenderer();
223
224 // Called by virtual refreshSymbolView()
225 void populateCategories();
226
228 int currentCategoryRow();
229
231 QList<int> selectedCategories();
232
234 void changeSelectedSymbols();
235
236 void changeCategorySymbol();
238 void applyChangeToSymbol();
239
240 QList<QgsSymbol *> selectedSymbols() override;
241 QgsCategoryList selectedCategoryList();
242 void refreshSymbolView() override;
243 void keyPressEvent( QKeyEvent *event ) override;
244
245 protected:
247
248 std::unique_ptr< QgsSymbol > mCategorizedSymbol;
249
250 QgsCategorizedSymbolRendererModel *mModel = nullptr;
251
252 private:
253 QString mOldClassificationAttribute;
254 QgsCategoryList mCopyBuffer;
255 QMenu *mContextMenu = nullptr;
256 QAction *mMergeCategoriesAction = nullptr;
257 QAction *mUnmergeCategoriesAction = nullptr;
258 QAction *mActionLevels = nullptr;
259
260 QgsExpressionContext createExpressionContext() const override;
261
262 friend class TestQgsCategorizedRendererWidget;
263};
264
265#endif // QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
Abstract interface for generating an expression context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The QgsFieldExpressionWidget class creates a widget to choose fields and edit expressions It contains...
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
Definition: qgsproxystyle.h:31
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
Base class for renderer settings widgets.
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:94
Represents a vector layer which manages a vector based data sets.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:73
#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