QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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
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 QgsExpressionContext createExpressionContext() const override;
144
153 int matchToSymbols( QgsStyle *style );
154
155 public slots:
156 void changeCategorizedSymbol();
157 void categoryColumnChanged( const QString &field );
158 void categoriesDoubleClicked( const QModelIndex &idx );
159 void addCategory();
160 void addCategories();
161
165 void applyColorRamp();
166
167 void deleteCategories();
168 void deleteAllCategories();
169
170 void showSymbolLevels();
171
172 void rowsMoved();
173
180 void matchToSymbolsFromLibrary();
181
188 void matchToSymbolsFromXml();
189
190 protected:
191 void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
192
193 protected slots:
194
195 void pasteSymbolToSelection() override;
196
197 private slots:
198
199 void updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget );
200 void updateSymbolsFromButton();
201 void dataDefinedSizeLegend();
202
208 void mergeSelectedCategories();
209
215 void unmergeSelectedCategories();
216
217 void showContextMenu( QPoint p );
218
219 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
220
221 protected:
222
223 void updateUiFromRenderer();
224
225 // Called by virtual refreshSymbolView()
226 void populateCategories();
227
229 int currentCategoryRow();
230
232 QList<int> selectedCategories();
233
235 void changeSelectedSymbols();
236
237 void changeCategorySymbol();
239 void applyChangeToSymbol();
240
241 QList<QgsSymbol *> selectedSymbols() override;
242 QgsCategoryList selectedCategoryList();
243 void refreshSymbolView() override;
244 void keyPressEvent( QKeyEvent *event ) override;
245
246 protected:
247 std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer;
248
249 std::unique_ptr< QgsSymbol > mCategorizedSymbol;
250
251 QgsCategorizedSymbolRendererModel *mModel = nullptr;
252
253 private:
254 QString mOldClassificationAttribute;
255 QgsCategoryList mCopyBuffer;
256 QMenu *mContextMenu = nullptr;
257 QAction *mMergeCategoriesAction = nullptr;
258 QAction *mUnmergeCategoriesAction = nullptr;
259 QAction *mActionLevels = nullptr;
260
261 friend class TestQgsCategorizedRendererWidget;
262};
263
264#endif // QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract base class for all 2D vector feature renderers.
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,...
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:231
Represents a vector layer which manages a vector based data sets.
#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