QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 QgsFieldExpressionWidget *mFieldExpressionWidget = nullptr;
103};
104
105
107
108#endif
109
114class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsCategorizedSymbolRendererWidget
115{
116 Q_OBJECT
117 public:
118 // *INDENT-OFF*
119
127 {
128 Value SIP_MONKEYPATCH_COMPAT_NAME( ValueRole ) = Qt::UserRole + 1
129 };
130 Q_ENUM( CustomRole )
131 // *INDENT-ON*
132
133 static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
134
137
138 QgsFeatureRenderer *renderer() override;
139 void setContext( const QgsSymbolWidgetContext &context ) override;
140 void disableSymbolLevels() override SIP_SKIP;
141 QgsExpressionContext createExpressionContext() const override;
142
151 int matchToSymbols( QgsStyle *style );
152
153 public slots:
154 void changeCategorizedSymbol();
155 void categoryColumnChanged( const QString &field );
156 void categoriesDoubleClicked( const QModelIndex &idx );
157 void addCategory();
158 void addCategories();
159
163 void applyColorRamp();
164
165 void deleteCategories();
166 void deleteAllCategories();
167
168 void showSymbolLevels();
169
170 void rowsMoved();
171
178 void matchToSymbolsFromLibrary();
179
186 void matchToSymbolsFromXml();
187
188 protected:
189 void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
190
191 protected slots:
192
193 void pasteSymbolToSelection() override;
194
195 private slots:
196
197 void updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget );
198 void updateSymbolsFromButton();
199 void dataDefinedSizeLegend();
200
206 void mergeSelectedCategories();
207
213 void unmergeSelectedCategories();
214
215 void showContextMenu( QPoint p );
216
217 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
218
219 protected:
220 void updateUiFromRenderer();
221
222 // Called by virtual refreshSymbolView()
223 void populateCategories();
224
226 int currentCategoryRow();
227
229 QList<int> selectedCategories();
230
232 void changeSelectedSymbols();
233
234 void changeCategorySymbol();
236 void applyChangeToSymbol();
237
238 QList<QgsSymbol *> selectedSymbols() override;
239 QgsCategoryList selectedCategoryList();
240 void refreshSymbolView() override;
241 void keyPressEvent( QKeyEvent *event ) override;
242
243 protected:
244 std::unique_ptr<QgsCategorizedSymbolRenderer> mRenderer;
245
246 std::unique_ptr<QgsSymbol> mCategorizedSymbol;
247
248 QgsCategorizedSymbolRendererModel *mModel = nullptr;
249
250 private:
251 QString mOldClassificationAttribute;
252 QgsCategoryList mCopyBuffer;
253 QMenu *mContextMenu = nullptr;
254 QAction *mMergeCategoriesAction = nullptr;
255 QAction *mUnmergeCategoriesAction = nullptr;
256 QAction *mActionLevels = nullptr;
257
258 friend class TestQgsCategorizedRendererWidget;
259};
260
261#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