QGIS API Documentation  3.2.0-Bonn (bc43194)
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 QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H
16 #define QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H
17 
19 #include "qgis.h"
20 #include "qgsrendererwidget.h"
21 #include "qgsproxystyle.h"
22 #include <QStandardItem>
23 
24 
27 
28 #include "ui_qgscategorizedsymbolrendererv2widget.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 
157  protected:
158 
159  void updateUiFromRenderer();
160 
161  void updateCategorizedSymbolIcon();
162 
163  // Called by virtual refreshSymbolView()
164  void populateCategories();
165 
167  int currentCategoryRow();
168 
170  QList<int> selectedCategories();
171 
173  void changeSelectedSymbols();
174 
175  void changeCategorySymbol();
177  void applyChangeToSymbol();
178 
179  QList<QgsSymbol *> selectedSymbols() override;
180  QgsCategoryList selectedCategoryList();
181  void refreshSymbolView() override;
182  void keyPressEvent( QKeyEvent *event ) override;
183 
184  protected:
185  std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer;
186 
187  std::unique_ptr< QgsSymbol > mCategorizedSymbol;
188 
189  QgsCategorizedSymbolRendererModel *mModel = nullptr;
190 
191  private:
192  QString mOldClassificationAttribute;
193  QgsCategoryList mCopyBuffer;
194 
195  QgsExpressionContext createExpressionContext() const override;
196 };
197 
198 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H
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.