QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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
28
29#include "ui_qgscategorizedsymbolrendererwidget.h"
30#include "qgis_gui.h"
31
32
33#ifndef SIP_RUN
35
36class GUI_EXPORT QgsCategorizedSymbolRendererModel : public QAbstractItemModel
37{
38 Q_OBJECT
39 public:
40 QgsCategorizedSymbolRendererModel( QObject *parent = nullptr, QScreen *screen = nullptr );
41 Qt::ItemFlags flags( const QModelIndex &index ) const override;
42 Qt::DropActions supportedDropActions() const override;
43 QVariant data( const QModelIndex &index, int role ) const override;
44 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
45 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
46 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
47 int columnCount( const QModelIndex & = QModelIndex() ) const override;
48 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
49 QModelIndex parent( const QModelIndex &index ) const override;
50 QStringList mimeTypes() const override;
51 QMimeData *mimeData( const QModelIndexList &indexes ) const override;
52 bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
53
54 void setRenderer( QgsCategorizedSymbolRenderer *renderer );
55
56 void addCategory( const QgsRendererCategory &cat );
57 QgsRendererCategory category( const QModelIndex &index );
58 void deleteRows( QList<int> rows );
59 void removeAllRows();
60 void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
61 void updateSymbology();
62
63 signals:
64 void rowsMoved();
65
66 private:
67 QgsCategorizedSymbolRenderer *mRenderer = nullptr;
68 QString mMimeFormat;
69 QPointer< QScreen > mScreen;
70};
71
76class QgsCategorizedSymbolRendererViewStyle: public QgsProxyStyle
77{
78 Q_OBJECT
79
80 public:
81 explicit QgsCategorizedSymbolRendererViewStyle( QWidget *parent );
82
83 void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
84};
85
90class QgsCategorizedRendererViewItemDelegate: public QStyledItemDelegate
91{
92 Q_OBJECT
93
94 public:
95 explicit QgsCategorizedRendererViewItemDelegate( QgsFieldExpressionWidget *expressionWidget, QObject *parent = nullptr );
96
97 // QAbstractItemDelegate interface
98 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
99
100 private:
101
102 QgsFieldExpressionWidget *mFieldExpressionWidget = nullptr;
103};
104
105
107
108#endif
109
114class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsCategorizedSymbolRendererWidget, private QgsExpressionContextGenerator
115{
116 Q_OBJECT
117 public:
118
124 {
125 ValueRole = Qt::UserRole + 1
126 };
127
128 static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
129
132
133 QgsFeatureRenderer *renderer() override;
134 void setContext( const QgsSymbolWidgetContext &context ) override;
135 void disableSymbolLevels() override SIP_SKIP;
136
146 int matchToSymbols( QgsStyle *style );
147
148 public slots:
149 void changeCategorizedSymbol();
150 void categoryColumnChanged( const QString &field );
151 void categoriesDoubleClicked( const QModelIndex &idx );
152 void addCategory();
153 void addCategories();
154
158 void applyColorRamp();
159
160 void deleteCategories();
161 void deleteAllCategories();
162
163 void showSymbolLevels();
164
165 void rowsMoved();
166
174 void matchToSymbolsFromLibrary();
175
183 void matchToSymbolsFromXml();
184
185 protected:
186 void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
187
188 protected slots:
189
190 void pasteSymbolToSelection() override;
191
192 private slots:
193
194 void cleanUpSymbolSelector( QgsPanelWidget *container );
195 void updateSymbolsFromWidget();
196 void updateSymbolsFromButton();
197 void dataDefinedSizeLegend();
198
204 void mergeSelectedCategories();
205
211 void unmergeSelectedCategories();
212
213 void showContextMenu( QPoint p );
214
215 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
216
217 protected:
218
219 void updateUiFromRenderer();
220
221 // Called by virtual refreshSymbolView()
222 void populateCategories();
223
225 int currentCategoryRow();
226
228 QList<int> selectedCategories();
229
231 void changeSelectedSymbols();
232
233 void changeCategorySymbol();
235 void applyChangeToSymbol();
236
237 QList<QgsSymbol *> selectedSymbols() override;
238 QgsCategoryList selectedCategoryList();
239 void refreshSymbolView() override;
240 void keyPressEvent( QKeyEvent *event ) override;
241
242 protected:
244
245 std::unique_ptr< QgsSymbol > mCategorizedSymbol;
246
247 QgsCategorizedSymbolRendererModel *mModel = nullptr;
248
249 private:
250 QString mOldClassificationAttribute;
251 QgsCategoryList mCopyBuffer;
252 QMenu *mContextMenu = nullptr;
253 QAction *mMergeCategoriesAction = nullptr;
254 QAction *mUnmergeCategoriesAction = nullptr;
255 QAction *mActionLevels = nullptr;
256
257 QgsExpressionContext createExpressionContext() const override;
258
259 friend class TestQgsCategorizedRendererWidget;
260};
261
262#endif // QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
CustomRoles
CustomRoles enum represent custom roles for the widget.
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 reates a widget to choose fields and edit expressions It contains ...
Base class for any widget that can be shown as a inline panel.
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.
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:74
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_FACTORY
Definition: qgis_sip.h:76
QList< QgsRendererCategory > QgsCategoryList
const QgsField & field
Definition: qgsfield.h:554
QList< QgsLegendSymbolItem > QgsLegendSymbolList