QGIS API Documentation  3.6.0-Noosa (5873452)
qgsgraduatedsymbolrendererwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgraduatedsymbolrendererwidget.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 QGSGRADUATEDSYMBOLRENDERERWIDGET_H
17 #define QGSGRADUATEDSYMBOLRENDERERWIDGET_H
18 
20 #include "qgis_sip.h"
21 #include "qgsrendererwidget.h"
22 #include "qgsproxystyle.h"
23 #include <QStandardItem>
24 
25 #include "ui_qgsgraduatedsymbolrendererwidget.h"
26 #include "qgis_gui.h"
27 
28 #ifndef SIP_RUN
29 
31 class GUI_EXPORT QgsGraduatedSymbolRendererModel : public QAbstractItemModel
32 {
33  Q_OBJECT
34  public:
35  QgsGraduatedSymbolRendererModel( QObject *parent = nullptr );
36  Qt::ItemFlags flags( const QModelIndex &index ) const override;
37  Qt::DropActions supportedDropActions() const override;
38  QVariant data( const QModelIndex &index, int role ) const override;
39  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
40  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
41  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
42  int columnCount( const QModelIndex & = QModelIndex() ) const override;
43  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
44  QModelIndex parent( const QModelIndex &index ) const override;
45  QStringList mimeTypes() const override;
46  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
47  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
48 
49  void setRenderer( QgsGraduatedSymbolRenderer *renderer );
50 
51  QgsRendererRange rendererRange( const QModelIndex &index );
52  void addClass( QgsSymbol *symbol );
53  void addClass( const QgsRendererRange &range );
54  void deleteRows( QList<int> rows );
55  void removeAllRows();
56  void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
57  void updateSymbology( bool resetModel = false );
58  void updateLabels();
59 
60  signals:
61  void rowsMoved();
62 
63  private:
64  QgsGraduatedSymbolRenderer *mRenderer = nullptr;
65  QString mMimeFormat;
66 };
67 
68 // View style which shows drop indicator line between items
69 class QgsGraduatedSymbolRendererViewStyle: public QgsProxyStyle
70 {
71  Q_OBJECT
72 
73  public:
74  explicit QgsGraduatedSymbolRendererViewStyle( QWidget *parent );
75 
76  void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
77 };
78 
80 #endif
81 
86 class GUI_EXPORT QgsGraduatedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsGraduatedSymbolRendererWidget, private QgsExpressionContextGenerator
87 {
88  Q_OBJECT
89 
90  public:
91  static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
92 
95 
96  QgsFeatureRenderer *renderer() override;
97 
98  public slots:
99  void changeGraduatedSymbol();
100  void graduatedColumnChanged( const QString &field );
101  void classifyGraduated();
102  void reapplyColorRamp();
103  void reapplySizes();
104  void rangesDoubleClicked( const QModelIndex &idx );
105  void rangesClicked( const QModelIndex &idx );
106  void changeCurrentValue( QStandardItem *item );
107 
109  void addClass();
111  void deleteClasses();
113  void deleteAllClasses();
115  void toggleBoundariesLink( bool linked );
116 
117  void labelFormatChanged();
118 
119  void showSymbolLevels();
120 
121  void rowsMoved();
122  void modelDataChanged();
123  void refreshRanges( bool reset = false );
124 
125  private slots:
126  void mSizeUnitWidget_changed();
127  void methodComboBox_currentIndexChanged( int );
128  void cleanUpSymbolSelector( QgsPanelWidget *container );
129  void updateSymbolsFromWidget();
130  void toggleMethodWidgets( int idx );
131  void dataDefinedSizeLegend();
132 
133  protected:
134  void updateUiFromRenderer( bool updateCount = true );
135  void connectUpdateHandlers();
136  void disconnectUpdateHandlers();
137  bool rowsOrdered();
138 
139  void updateGraduatedSymbolIcon();
140 
142  QList<int> selectedClasses();
143  QgsRangeList selectedRanges();
144 
145  void changeRangeSymbol( int rangeIdx );
146  void changeRange( int rangeIdx );
147 
148  void changeSelectedSymbols();
150  void applyChangeToSymbol();
151 
152  QList<QgsSymbol *> selectedSymbols() override;
153  QgsSymbol *findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList &ranges ) const;
154  void refreshSymbolView() override;
155 
156  void keyPressEvent( QKeyEvent *event ) override;
157 
158  private:
159  std::unique_ptr< QgsGraduatedSymbolRenderer > mRenderer;
160 
161  std::unique_ptr< QgsSymbol > mGraduatedSymbol;
162 
163  int mRowSelected;
164 
165  QgsGraduatedSymbolRendererModel *mModel = nullptr;
166 
167  QgsRangeList mCopyBuffer;
168 
169  QgsExpressionContext createExpressionContext() const override;
170 };
171 
172 
173 #endif // QGSGRADUATEDSYMBOLRENDERERWIDGET_H
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
QList< QgsRendererRange > QgsRangeList
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
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.