QGIS API Documentation  2.13.0-Master
qgsgraduatedsymbolrendererv2widget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgraduatedsymbolrendererv2widget.h
3  ---------------------
4  begin : December 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 
16 #ifndef QGSGRADUATEDSYMBOLRENDERERV2WIDGET_H
17 #define QGSGRADUATEDSYMBOLRENDERERV2WIDGET_H
18 
20 #include "qgsrendererv2widget.h"
21 #include <QStandardItem>
22 #include <QProxyStyle>
23 
24 #include "ui_qgsgraduatedsymbolrendererv2widget.h"
25 
27 
28 class GUI_EXPORT QgsGraduatedSymbolRendererV2Model : public QAbstractItemModel
29 {
30  Q_OBJECT
31  public:
32  QgsGraduatedSymbolRendererV2Model( QObject * parent = nullptr );
33  Qt::ItemFlags flags( const QModelIndex & index ) const override;
34  Qt::DropActions supportedDropActions() const override;
35  QVariant data( const QModelIndex &index, int role ) const override;
36  bool setData( const QModelIndex & index, const QVariant & value, int role ) override;
37  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
38  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
39  int columnCount( const QModelIndex & = QModelIndex() ) const override;
40  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
41  QModelIndex parent( const QModelIndex &index ) const override;
42  QStringList mimeTypes() const override;
43  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
44  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
45 
46  void setRenderer( QgsGraduatedSymbolRendererV2* renderer );
47 
48  QgsRendererRangeV2 rendererRange( const QModelIndex &index );
49  void addClass( QgsSymbolV2* symbol );
50  void addClass( const QgsRendererRangeV2& range );
51  void deleteRows( QList<int> rows );
52  void removeAllRows();
53  void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
54  void updateSymbology( bool resetModel = false );
55  void updateLabels();
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 QgsGraduatedSymbolRendererV2ViewStyle: public QProxyStyle
67 {
68  Q_OBJECT
69 
70  public:
71  explicit QgsGraduatedSymbolRendererV2ViewStyle( 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 QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget, private Ui::QgsGraduatedSymbolRendererV2Widget
79 {
80  Q_OBJECT
81 
82  public:
83  static QgsRendererV2Widget* create( QgsVectorLayer* layer, QgsStyleV2* style, QgsFeatureRendererV2* renderer );
84 
87 
88  virtual QgsFeatureRendererV2* renderer() override;
89 
90  public slots:
91  void changeGraduatedSymbol();
92  void graduatedColumnChanged( const QString& field );
93  void classifyGraduated();
94  void reapplyColorRamp();
95  void reapplySizes();
96  void rangesDoubleClicked( const QModelIndex & idx );
97  void rangesClicked( const QModelIndex & idx );
98  void changeCurrentValue( QStandardItem * item );
99 
101  void addClass();
103  void deleteClasses();
105  void deleteAllClasses();
107  void toggleBoundariesLink( bool linked );
108 
109  void sizeScaleFieldChanged( const QString& fldName );
110  void scaleMethodChanged( QgsSymbolV2::ScaleMethod scaleMethod );
111  void labelFormatChanged();
112 
113  void showSymbolLevels();
114 
115  void rowsMoved();
116  void modelDataChanged();
117  void on_mSizeUnitWidget_changed();
118  void on_methodComboBox_currentIndexChanged( int );
119  void refreshRanges( bool reset = false );
120 
121  protected:
122  void updateUiFromRenderer( bool updateCount = true );
123  void connectUpdateHandlers();
124  void disconnectUpdateHandlers();
125  bool rowsOrdered();
126 
127  void updateGraduatedSymbolIcon();
128 
130  QList<int> selectedClasses();
131  QgsRangeList selectedRanges();
132 
133  void changeRangeSymbol( int rangeIdx );
134  void changeRange( int rangeIdx );
135 
136  void changeSelectedSymbols();
137 
139  QgsSymbolV2* findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList& ranges ) const;
140  void refreshSymbolView() override;
141 
142  void keyPressEvent( QKeyEvent* event ) override;
143 
144  protected:
146 
148 
150 
151  QgsGraduatedSymbolRendererV2Model* mModel;
152 
154 };
155 
156 
157 #endif // QGSGRADUATEDSYMBOLRENDERERV2WIDGET_H
virtual QList< QgsSymbolV2 * > selectedSymbols()
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
static unsigned index
virtual int rowCount(const QModelIndex &parent) const =0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
void create(WId window, bool initializeWindow, bool destroyOldWindow)
virtual void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
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
virtual void keyPressEvent(QKeyEvent *event)
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
virtual void refreshSymbolView()
QObject * parent() const
Represents a vector layer which manages a vector based data sets.
virtual QgsFeatureRendererV2 * renderer()=0
return pointer to the renderer (no transfer of ownership)
typedef ItemFlags