QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 
24 
27 
28 #include "ui_qgscategorizedsymbolrendererwidget.h"
29 #include "qgis_gui.h"
30 
31 
32 #ifndef SIP_RUN
33 
35 class GUI_EXPORT QgsCategorizedSymbolRendererModel : public QAbstractItemModel
36 {
37  Q_OBJECT
38  public:
39  QgsCategorizedSymbolRendererModel( QObject *parent = nullptr );
40  Qt::ItemFlags flags( const QModelIndex &index ) const override;
41  Qt::DropActions supportedDropActions() const override;
42  QVariant data( const QModelIndex &index, int role ) const override;
43  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
44  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
45  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
46  int columnCount( const QModelIndex & = QModelIndex() ) const override;
47  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
48  QModelIndex parent( const QModelIndex &index ) const override;
49  QStringList mimeTypes() const override;
50  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
51  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
52 
53  void setRenderer( QgsCategorizedSymbolRenderer *renderer );
54 
55  void addCategory( const QgsRendererCategory &cat );
56  QgsRendererCategory category( const QModelIndex &index );
57  void deleteRows( QList<int> rows );
58  void removeAllRows();
59  void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
60  void updateSymbology();
61 
62  signals:
63  void rowsMoved();
64 
65  private:
66  QgsCategorizedSymbolRenderer *mRenderer = nullptr;
67  QString mMimeFormat;
68 };
69 
74 class QgsCategorizedSymbolRendererViewStyle: public QgsProxyStyle
75 {
76  Q_OBJECT
77 
78  public:
79  explicit QgsCategorizedSymbolRendererViewStyle( QWidget *parent );
80 
81  void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
82 };
83 
85 
86 #endif
87 
92 class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsCategorizedSymbolRendererWidget, private QgsExpressionContextGenerator
93 {
94  Q_OBJECT
95  public:
96  static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
97 
100 
101  QgsFeatureRenderer *renderer() override;
102 
112  int matchToSymbols( QgsStyle *style );
113 
114  public slots:
115  void changeCategorizedSymbol();
116  void categoryColumnChanged( const QString &field );
117  void categoriesDoubleClicked( const QModelIndex &idx );
118  void addCategory();
119  void addCategories();
120 
124  void applyColorRamp();
125 
126  void deleteCategories();
127  void deleteAllCategories();
128 
129  void showSymbolLevels();
130 
131  void rowsMoved();
132 
140  void matchToSymbolsFromLibrary();
141 
149  void matchToSymbolsFromXml();
150 
151  private slots:
152 
153  void cleanUpSymbolSelector( QgsPanelWidget *container );
154  void updateSymbolsFromWidget();
155  void dataDefinedSizeLegend();
156 
162  void mergeSelectedCategories();
163 
169  void unmergeSelectedCategories();
170 
171  void showContextMenu( QPoint p );
172 
173  protected:
174 
175  void updateUiFromRenderer();
176 
177  void updateCategorizedSymbolIcon();
178 
179  // Called by virtual refreshSymbolView()
180  void populateCategories();
181 
183  int currentCategoryRow();
184 
186  QList<int> selectedCategories();
187 
189  void changeSelectedSymbols();
190 
191  void changeCategorySymbol();
193  void applyChangeToSymbol();
194 
195  QList<QgsSymbol *> selectedSymbols() override;
196  QgsCategoryList selectedCategoryList();
197  void refreshSymbolView() override;
198  void keyPressEvent( QKeyEvent *event ) override;
199 
200  protected:
201  std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer;
202 
203  std::unique_ptr< QgsSymbol > mCategorizedSymbol;
204 
205  QgsCategorizedSymbolRendererModel *mModel = nullptr;
206 
207  private:
208  QString mOldClassificationAttribute;
209  QgsCategoryList mCopyBuffer;
210  QMenu *mContextMenu = nullptr;
211  QAction *mMergeCategoriesAction = nullptr;
212  QAction *mUnmergeCategoriesAction = nullptr;
213 
214  QgsExpressionContext createExpressionContext() const override;
215 
216  friend class TestQgsCategorizedRendererWidget;
217 };
218 
219 #endif // QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
Base class for renderer settings widgets.
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:30
QList< QgsRendererCategory > QgsCategoryList
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer
#define SIP_FACTORY
Definition: qgis_sip.h:69
Abstract interface for generating an expression context.
Represents a vector layer which manages a vector based data sets.