QGIS API Documentation  3.21.0-Master (5b68dc587e)
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  void disableSymbolLevels() override SIP_SKIP;
104 
114  int matchToSymbols( QgsStyle *style );
115 
116  public slots:
117  void changeCategorizedSymbol();
118  void categoryColumnChanged( const QString &field );
119  void categoriesDoubleClicked( const QModelIndex &idx );
120  void addCategory();
121  void addCategories();
122 
126  void applyColorRamp();
127 
128  void deleteCategories();
129  void deleteAllCategories();
130 
131  void showSymbolLevels();
132 
133  void rowsMoved();
134 
142  void matchToSymbolsFromLibrary();
143 
151  void matchToSymbolsFromXml();
152 
153  protected:
154  void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
155 
156  protected slots:
157 
158  void pasteSymbolToSelection() override;
159 
160  private slots:
161 
162  void cleanUpSymbolSelector( QgsPanelWidget *container );
163  void updateSymbolsFromWidget();
164  void updateSymbolsFromButton();
165  void dataDefinedSizeLegend();
166 
172  void mergeSelectedCategories();
173 
179  void unmergeSelectedCategories();
180 
181  void showContextMenu( QPoint p );
182 
183  void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
184 
185  protected:
186 
187  void updateUiFromRenderer();
188 
189  // Called by virtual refreshSymbolView()
190  void populateCategories();
191 
193  int currentCategoryRow();
194 
196  QList<int> selectedCategories();
197 
199  void changeSelectedSymbols();
200 
201  void changeCategorySymbol();
203  void applyChangeToSymbol();
204 
205  QList<QgsSymbol *> selectedSymbols() override;
206  QgsCategoryList selectedCategoryList();
207  void refreshSymbolView() override;
208  void keyPressEvent( QKeyEvent *event ) override;
209 
210  protected:
211  std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer;
212 
213  std::unique_ptr< QgsSymbol > mCategorizedSymbol;
214 
215  QgsCategorizedSymbolRendererModel *mModel = nullptr;
216 
217  private:
218  QString mOldClassificationAttribute;
219  QgsCategoryList mCopyBuffer;
220  QMenu *mContextMenu = nullptr;
221  QAction *mMergeCategoriesAction = nullptr;
222  QAction *mUnmergeCategoriesAction = nullptr;
223  QAction *mActionLevels = nullptr;
224 
225  QgsExpressionContext createExpressionContext() const override;
226 
227  friend class TestQgsCategorizedRendererWidget;
228 };
229 
230 #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_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