QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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
34 
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  void setContext( const QgsSymbolWidgetContext &context ) override;
103 
113  int matchToSymbols( QgsStyle *style );
114 
115  public slots:
116  void changeCategorizedSymbol();
117  void categoryColumnChanged( const QString &field );
118  void categoriesDoubleClicked( const QModelIndex &idx );
119  void addCategory();
120  void addCategories();
121 
125  void applyColorRamp();
126 
127  void deleteCategories();
128  void deleteAllCategories();
129 
130  void showSymbolLevels();
131 
132  void rowsMoved();
133 
141  void matchToSymbolsFromLibrary();
142 
150  void matchToSymbolsFromXml();
151 
152  protected slots:
153 
154  void pasteSymbolToSelection() override;
155 
156  private slots:
157 
158  void cleanUpSymbolSelector( QgsPanelWidget *container );
159  void updateSymbolsFromWidget();
160  void updateSymbolsFromButton();
161  void dataDefinedSizeLegend();
162 
168  void mergeSelectedCategories();
169 
175  void unmergeSelectedCategories();
176 
177  void showContextMenu( QPoint p );
178 
179  void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
180 
181  protected:
182 
183  void updateUiFromRenderer();
184 
185  // Called by virtual refreshSymbolView()
186  void populateCategories();
187 
189  int currentCategoryRow();
190 
192  QList<int> selectedCategories();
193 
195  void changeSelectedSymbols();
196 
197  void changeCategorySymbol();
199  void applyChangeToSymbol();
200 
201  QList<QgsSymbol *> selectedSymbols() override;
202  QgsCategoryList selectedCategoryList();
203  void refreshSymbolView() override;
204  void keyPressEvent( QKeyEvent *event ) override;
205 
206  protected:
207  std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer;
208 
209  std::unique_ptr< QgsSymbol > mCategorizedSymbol;
210 
211  QgsCategorizedSymbolRendererModel *mModel = nullptr;
212 
213  private:
214  QString mOldClassificationAttribute;
215  QgsCategoryList mCopyBuffer;
216  QMenu *mContextMenu = nullptr;
217  QAction *mMergeCategoriesAction = nullptr;
218  QAction *mUnmergeCategoriesAction = nullptr;
219 
220  QgsExpressionContext createExpressionContext() const override;
221 
222  friend class TestQgsCategorizedRendererWidget;
223 };
224 
225 #endif // QGSCATEGORIZEDSYMBOLRENDERERWIDGET_H
std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer
Abstract interface for generating an expression context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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,...
Represents a vector layer which manages a vector based data sets.
#define SIP_FACTORY
Definition: qgis_sip.h:76
QList< QgsRendererCategory > QgsCategoryList
const QgsField & field
Definition: qgsfield.h:472