QGIS API Documentation 4.1.0-Master (ca2ac17535b)
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
18#include "qgis_sip.h"
20#include "qgsproxystyle.h"
21#include "qgsrendererwidget.h"
23
24#include <QStandardItem>
25#include <QStyledItemDelegate>
26
30
31#include "ui_qgscategorizedsymbolrendererwidget.h"
32#include "qgis_gui.h"
33
34
35#ifndef SIP_RUN
37
38class GUI_EXPORT QgsCategorizedSymbolRendererModel : public QgsTemplatedCategorizedRendererModel<QgsCategorizedSymbolRenderer>
39{
40 Q_OBJECT
41 public:
42 QgsCategorizedSymbolRendererModel( QObject *parent = nullptr, QScreen *screen = nullptr );
43
44 Qt::ItemFlags extraFlags( const QModelIndex &index ) const override;
45 virtual QIcon symbolIcon( const QgsCategorizedSymbolRenderer::Category &category ) const override;
46 bool setExtraData( const QModelIndex &index, const QVariant &value ) override;
47 QVariant extraData( const QModelIndex &index, int role ) const override;
48 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
49 int columnCount( const QModelIndex & = QModelIndex() ) const override;
50 void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
51
52 signals:
53 void rowsMoved();
54
55 protected:
56 void onRowsMoved() override;
57};
58
63class GUI_EXPORT QgsCategorizedSymbolRendererViewStyle : public QgsProxyStyle
64{
65 Q_OBJECT
66
67 public:
68 explicit QgsCategorizedSymbolRendererViewStyle( QWidget *parent );
69
70 void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
71};
72
77class GUI_EXPORT QgsCategorizedRendererViewItemDelegate : public QStyledItemDelegate
78{
79 Q_OBJECT
80
81 public:
82 explicit QgsCategorizedRendererViewItemDelegate( QgsFieldExpressionWidget *expressionWidget, QObject *parent = nullptr );
83
84 // QAbstractItemDelegate interface
85 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
86
87 private:
88 QgsFieldExpressionWidget *mFieldExpressionWidget = nullptr;
89};
90
91
93
94#endif
95
101class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsCategorizedSymbolRendererWidget
102{
103 Q_OBJECT
104 public:
105 // *INDENT-OFF*
106
114 {
115 Value SIP_MONKEYPATCH_COMPAT_NAME( ValueRole ) = Qt::UserRole + 1
116 };
117 Q_ENUM( CustomRole )
118 // *INDENT-ON*
119
120 static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
121
124
125 QgsFeatureRenderer *renderer() override;
126 void setContext( const QgsSymbolWidgetContext &context ) override;
127 void disableSymbolLevels() override SIP_SKIP;
128 QgsExpressionContext createExpressionContext() const override;
129
138 int matchToSymbols( QgsStyle *style );
139
140 public slots:
141 void changeCategorizedSymbol();
142 void categoryColumnChanged( const QString &field );
143 void categoriesDoubleClicked( const QModelIndex &idx );
144 void addCategory();
145 void addCategories();
146
150 void applyColorRamp();
151
152 void deleteCategories();
153 void deleteAllCategories();
154
158 void deleteUnusedCategories();
159
160 void showSymbolLevels();
161
162 void rowsMoved();
163
170 void matchToSymbolsFromLibrary();
171
178 void matchToSymbolsFromXml();
179
180 protected:
181 void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
182
183 protected slots:
184
185 void pasteSymbolToSelection() override;
186
187 private slots:
188
189 void updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget );
190 void updateSymbolsFromButton();
191 void dataDefinedSizeLegend();
192
198 void mergeSelectedCategories();
199
205 void unmergeSelectedCategories();
206
207 void showContextMenu( QPoint p );
208
209 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
210
211 protected:
212 void updateUiFromRenderer();
213
214 // Called by virtual refreshSymbolView()
215 void populateCategories();
216
218 int currentCategoryRow();
219
221 QList<int> selectedCategories();
222
224 void changeSelectedSymbols();
225
226 void changeCategorySymbol();
228 void applyChangeToSymbol();
229
237 Q_DECL_DEPRECATED QList<QVariant> layerUniqueValues( const QString &attrName ) SIP_DEPRECATED;
238
239 QList<QgsSymbol *> selectedSymbols() override;
240 QgsCategoryList selectedCategoryList();
241 void refreshSymbolView() override;
242 void keyPressEvent( QKeyEvent *event ) override;
243
244 protected:
246
248
249 QgsCategorizedSymbolRendererModel *mModel = nullptr;
250
251 private:
252 QString mOldClassificationAttribute;
253 QgsCategoryList mCopyBuffer;
254 QMenu *mContextMenu = nullptr;
255 QAction *mMergeCategoriesAction = nullptr;
256 QAction *mUnmergeCategoriesAction = nullptr;
257 QAction *mActionLevels = nullptr;
258
260};
261
262#endif // QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
A widget for configuring a QgsCategorizedSymbolRenderer.
std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer
QgsCategorizedSymbolRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
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 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.
QgsRendererWidget(QgsVectorLayer *layer, QgsStyle *style)
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition qgsstyle.h:91
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:227
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:265
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:267
QList< QgsRendererCategory > QgsCategoryList
QList< QgsLegendSymbolItem > QgsLegendSymbolList