QGIS API Documentation  3.0.2-Girona (307d082)
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 <QStandardItem>
22 #include <QProxyStyle>
23 
26 
27 #include "ui_qgscategorizedsymbolrendererv2widget.h"
28 #include "qgis_gui.h"
29 
30 
31 #ifndef SIP_RUN
32 
34 class GUI_EXPORT QgsCategorizedSymbolRendererModel : public QAbstractItemModel
35 {
36  Q_OBJECT
37  public:
38  QgsCategorizedSymbolRendererModel( QObject *parent = nullptr );
39  Qt::ItemFlags flags( const QModelIndex &index ) const override;
40  Qt::DropActions supportedDropActions() const override;
41  QVariant data( const QModelIndex &index, int role ) const override;
42  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
43  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
44  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
45  int columnCount( const QModelIndex & = QModelIndex() ) const override;
46  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
47  QModelIndex parent( const QModelIndex &index ) const override;
48  QStringList mimeTypes() const override;
49  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
50  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
51 
52  void setRenderer( QgsCategorizedSymbolRenderer *renderer );
53 
54  void addCategory( const QgsRendererCategory &cat );
55  QgsRendererCategory category( const QModelIndex &index );
56  void deleteRows( QList<int> rows );
57  void removeAllRows();
58  void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
59  void updateSymbology();
60 
61  signals:
62  void rowsMoved();
63 
64  private:
65  QgsCategorizedSymbolRenderer *mRenderer = nullptr;
66  QString mMimeFormat;
67 };
68 
73 class QgsCategorizedSymbolRendererViewStyle: public QProxyStyle
74 {
75  Q_OBJECT
76 
77  public:
78  explicit QgsCategorizedSymbolRendererViewStyle( QStyle *style = nullptr );
79 
80  void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
81 };
82 
84 
85 #endif
86 
91 class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsCategorizedSymbolRendererWidget, private QgsExpressionContextGenerator
92 {
93  Q_OBJECT
94  public:
95  static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
96 
99 
100  QgsFeatureRenderer *renderer() override;
101 
111  int matchToSymbols( QgsStyle *style );
112 
113  public slots:
114  void changeCategorizedSymbol();
115  void categoryColumnChanged( const QString &field );
116  void categoriesDoubleClicked( const QModelIndex &idx );
117  void addCategory();
118  void addCategories();
119 
123  void applyColorRamp();
124 
125  void deleteCategories();
126  void deleteAllCategories();
127 
128  void showSymbolLevels();
129 
130  void rowsMoved();
131 
139  void matchToSymbolsFromLibrary();
140 
148  void matchToSymbolsFromXml();
149 
150  private slots:
151 
152  void cleanUpSymbolSelector( QgsPanelWidget *container );
153  void updateSymbolsFromWidget();
154  void dataDefinedSizeLegend();
155 
156  protected:
157 
158  void updateUiFromRenderer();
159 
160  void updateCategorizedSymbolIcon();
161 
162  // Called by virtual refreshSymbolView()
163  void populateCategories();
164 
166  int currentCategoryRow();
167 
169  QList<int> selectedCategories();
170 
172  void changeSelectedSymbols();
173 
174  void changeCategorySymbol();
175 
176  QList<QgsSymbol *> selectedSymbols() override;
177  QgsCategoryList selectedCategoryList();
178  void refreshSymbolView() override;
179  void keyPressEvent( QKeyEvent *event ) override;
180 
181  protected:
182  QgsCategorizedSymbolRenderer *mRenderer = nullptr;
183 
184  QgsSymbol *mCategorizedSymbol = nullptr;
185 
186  QgsCategorizedSymbolRendererModel *mModel = nullptr;
187 
188  private:
189  QString mOldClassificationAttribute;
190  QgsCategoryList mCopyBuffer;
191 
192  QgsExpressionContext createExpressionContext() const override;
193 };
194 
195 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H
Base class for renderer settings widgets.
Base class for any widget that can be shown as a inline panel.
QList< QgsRendererCategory > QgsCategoryList
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
#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.