QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgscategorizedsymbolrendererv2widget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscategorizedsymbolrendererv2widget.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 "qgsrendererv2widget.h"
20 #include <QStandardItem>
21 #include <QProxyStyle>
22 
25 
26 #include "ui_qgscategorizedsymbolrendererv2widget.h"
27 
29 
30 class GUI_EXPORT QgsCategorizedSymbolRendererV2Model : public QAbstractItemModel
31 {
32  Q_OBJECT
33  public:
34  QgsCategorizedSymbolRendererV2Model( QObject * parent = nullptr );
35  Qt::ItemFlags flags( const QModelIndex & index ) const override;
36  Qt::DropActions supportedDropActions() const override;
37  QVariant data( const QModelIndex &index, int role ) const override;
38  bool setData( const QModelIndex & index, const QVariant & value, int role ) override;
39  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
40  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
41  int columnCount( const QModelIndex & = QModelIndex() ) const override;
42  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
43  QModelIndex parent( const QModelIndex &index ) const override;
44  QStringList mimeTypes() const override;
45  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
46  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
47 
48  void setRenderer( QgsCategorizedSymbolRendererV2* renderer );
49 
50  void addCategory( const QgsRendererCategoryV2 &cat );
51  QgsRendererCategoryV2 category( const QModelIndex &index );
52  void deleteRows( QList<int> rows );
53  void removeAllRows();
54  void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
55  void updateSymbology();
56 
57  signals:
58  void rowsMoved();
59 
60  private:
62  QString mMimeFormat;
63 };
64 
68 class QgsCategorizedSymbolRendererV2ViewStyle: public QProxyStyle
69 {
70  Q_OBJECT
71 
72  public:
73  explicit QgsCategorizedSymbolRendererV2ViewStyle( QStyle* style = nullptr );
74 
75  void drawPrimitive( PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = nullptr ) const override;
76 };
77 
79 
83 class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsCategorizedSymbolRendererV2Widget
84 {
85  Q_OBJECT
86  public:
87  static QgsRendererV2Widget* create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
88 
91 
92  virtual QgsFeatureRendererV2* renderer() override;
93 
102  int matchToSymbols( QgsStyleV2* style );
103 
104  public slots:
105  void changeCategorizedSymbol();
106  void categoryColumnChanged( const QString& field );
107  void categoriesDoubleClicked( const QModelIndex & idx );
108  void addCategory();
109  void addCategories();
110  void applyColorRamp();
111  void deleteCategories();
112  void deleteAllCategories();
113 
114  void sizeScaleFieldChanged( const QString& fldName );
115  void scaleMethodChanged( QgsSymbolV2::ScaleMethod scaleMethod );
116 
117  void showSymbolLevels();
118 
119  void rowsMoved();
120 
127  void matchToSymbolsFromLibrary();
128 
135  void matchToSymbolsFromXml();
136 
137  private slots:
138 
139  void cleanUpSymbolSelector( QgsPanelWidget* container );
140  void updateSymbolsFromWidget();
141 
142  protected:
143 
144  void updateUiFromRenderer();
145 
146  void updateCategorizedSymbolIcon();
147 
148  // Called by virtual refreshSymbolView()
149  void populateCategories();
150 
152  int currentCategoryRow();
153 
155  QList<int> selectedCategories();
156 
158  void changeSelectedSymbols();
159 
160  void changeCategorySymbol();
161 
162  QgsVectorColorRampV2* getColorRamp();
163 
164  QList<QgsSymbolV2*> selectedSymbols() override;
165  QgsCategoryList selectedCategoryList();
166  void refreshSymbolView() override;
167  void keyPressEvent( QKeyEvent* event ) override;
168 
169  protected:
171 
173 
174  QgsCategorizedSymbolRendererV2Model* mModel;
175 
176  private:
177  QString mOldClassificationAttribute;
178  QgsCategoryList mCopyBuffer;
179 };
180 
181 #endif // QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H
static unsigned index
virtual int rowCount(const QModelIndex &parent) const=0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const=0
Base class for any widget that can be shown as a inline panel.
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
virtual QStringList mimeTypes() const
virtual void sort(int column, Qt::SortOrder order)
void rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
virtual Qt::DropActions supportedDropActions() const
virtual QVariant data(const QModelIndex &index, int role) const=0
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
ScaleMethod
Scale method.
Definition: qgssymbolv2.h:90
typedef DropActions
virtual int columnCount(const QModelIndex &parent) const=0
Base class for renderer settings widgets.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
QObject * parent() const
Represents a vector layer which manages a vector based data sets.
Abstract base class for color ramps.
typedef ItemFlags