QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
36 class GUI_EXPORT QgsCategorizedSymbolRendererModel : public QAbstractItemModel
37 {
38  Q_OBJECT
39  public:
40  QgsCategorizedSymbolRendererModel( QObject *parent = 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 };
70 
75 class QgsCategorizedSymbolRendererViewStyle: public QgsProxyStyle
76 {
77  Q_OBJECT
78 
79  public:
80  explicit QgsCategorizedSymbolRendererViewStyle( QWidget *parent );
81 
82  void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
83 };
84 
89 class QgsCategorizedRendererViewItemDelegate: public QStyledItemDelegate
90 {
91  Q_OBJECT
92 
93  public:
94  explicit QgsCategorizedRendererViewItemDelegate( QgsFieldExpressionWidget *expressionWidget, QObject *parent = nullptr );
95 
96  // QAbstractItemDelegate interface
97  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
98 
99  private:
100 
101  QgsFieldExpressionWidget *mFieldExpressionWidget = nullptr;
102 };
103 
104 
106 
107 #endif
108 
113 class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsCategorizedSymbolRendererWidget, private QgsExpressionContextGenerator
114 {
115  Q_OBJECT
116  public:
117 
123  {
124  ValueRole = Qt::UserRole + 1
125  };
126 
127  static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
128 
131 
132  QgsFeatureRenderer *renderer() override;
133  void setContext( const QgsSymbolWidgetContext &context ) override;
134  void disableSymbolLevels() override SIP_SKIP;
135 
145  int matchToSymbols( QgsStyle *style );
146 
147  public slots:
148  void changeCategorizedSymbol();
149  void categoryColumnChanged( const QString &field );
150  void categoriesDoubleClicked( const QModelIndex &idx );
151  void addCategory();
152  void addCategories();
153 
157  void applyColorRamp();
158 
159  void deleteCategories();
160  void deleteAllCategories();
161 
162  void showSymbolLevels();
163 
164  void rowsMoved();
165 
173  void matchToSymbolsFromLibrary();
174 
182  void matchToSymbolsFromXml();
183 
184  protected:
185  void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
186 
187  protected slots:
188 
189  void pasteSymbolToSelection() override;
190 
191  private slots:
192 
193  void cleanUpSymbolSelector( QgsPanelWidget *container );
194  void updateSymbolsFromWidget();
195  void updateSymbolsFromButton();
196  void dataDefinedSizeLegend();
197 
203  void mergeSelectedCategories();
204 
210  void unmergeSelectedCategories();
211 
212  void showContextMenu( QPoint p );
213 
214  void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
215 
216  protected:
217 
218  void updateUiFromRenderer();
219 
220  // Called by virtual refreshSymbolView()
221  void populateCategories();
222 
224  int currentCategoryRow();
225 
227  QList<int> selectedCategories();
228 
230  void changeSelectedSymbols();
231 
232  void changeCategorySymbol();
234  void applyChangeToSymbol();
235 
236  QList<QgsSymbol *> selectedSymbols() override;
237  QgsCategoryList selectedCategoryList();
238  void refreshSymbolView() override;
239  void keyPressEvent( QKeyEvent *event ) override;
240 
241  protected:
243 
244  std::unique_ptr< QgsSymbol > mCategorizedSymbol;
245 
246  QgsCategorizedSymbolRendererModel *mModel = nullptr;
247 
248  private:
249  QString mOldClassificationAttribute;
250  QgsCategoryList mCopyBuffer;
251  QMenu *mContextMenu = nullptr;
252  QAction *mMergeCategoriesAction = nullptr;
253  QAction *mUnmergeCategoriesAction = nullptr;
254  QAction *mActionLevels = nullptr;
255 
256  QgsExpressionContext createExpressionContext() const override;
257 
258  friend class TestQgsCategorizedRendererWidget;
259 };
260 
261 #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:38
Represents a vector layer which manages a vector based data sets.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#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:463
QList< QgsLegendSymbolItem > QgsLegendSymbolList