QGIS API Documentation  2.13.0-Master
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 
65 // View style which shows drop indicator line between items
66 class QgsCategorizedSymbolRendererV2ViewStyle: public QProxyStyle
67 {
68  Q_OBJECT
69 
70  public:
71  explicit QgsCategorizedSymbolRendererV2ViewStyle( QStyle* style = nullptr );
72 
73  void drawPrimitive( PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = nullptr ) const override;
74 };
75 
77 
78 class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsCategorizedSymbolRendererV2Widget
79 {
80  Q_OBJECT
81  public:
82  static QgsRendererV2Widget* create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
83 
86 
87  virtual QgsFeatureRendererV2* renderer() override;
88 
97  int matchToSymbols( QgsStyleV2* style );
98 
99  public slots:
100  void changeCategorizedSymbol();
101  void categoryColumnChanged( const QString& field );
102  void categoriesDoubleClicked( const QModelIndex & idx );
103  void addCategory();
104  void addCategories();
105  void applyColorRamp();
106  void deleteCategories();
107  void deleteAllCategories();
108 
109  void sizeScaleFieldChanged( const QString& fldName );
110  void scaleMethodChanged( QgsSymbolV2::ScaleMethod scaleMethod );
111 
112  void showSymbolLevels();
113 
114  void rowsMoved();
115 
122  void matchToSymbolsFromLibrary();
123 
130  void matchToSymbolsFromXml();
131 
132  protected:
133 
134  void updateUiFromRenderer();
135 
136  void updateCategorizedSymbolIcon();
137 
138  // Called by virtual refreshSymbolView()
139  void populateCategories();
140 
142  int currentCategoryRow();
143 
145  QList<int> selectedCategories();
146 
148  void changeSelectedSymbols();
149 
150  void changeCategorySymbol();
151 
152  QgsVectorColorRampV2* getColorRamp();
153 
154  QList<QgsSymbolV2*> selectedSymbols() override;
155  QgsCategoryList selectedCategoryList();
156  void refreshSymbolView() override { populateCategories(); }
157  void keyPressEvent( QKeyEvent* event ) override;
158 
159  protected:
161 
163 
164  QgsCategorizedSymbolRendererV2Model* mModel;
165 
166  private:
167  QString mOldClassificationAttribute;
168  QgsCategoryList mCopyBuffer;
169 };
170 
171 #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
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:84
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.
typedef ItemFlags