QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
93  QgsGraduatedSymbolRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer );
94  ~QgsGraduatedSymbolRendererWidget() override;
95 
96  QgsFeatureRenderer *renderer() override;
97  void setContext( const QgsSymbolWidgetContext &context ) override;
98 
99  public slots:
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 dataDefinedSizeLegend();
131  void changeGraduatedSymbol();
132  void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
133  void symmetryPointEditingFinished();
134 
135  protected slots:
136 
137  void pasteSymbolToSelection() override;
138 
139  protected:
140  void updateUiFromRenderer( bool updateCount = true );
141  void connectUpdateHandlers();
142  void disconnectUpdateHandlers();
143  bool rowsOrdered();
144 
146  QList<int> selectedClasses();
147  QgsRangeList selectedRanges();
148 
149  void changeRangeSymbol( int rangeIdx );
150  void changeRange( int rangeIdx );
151 
152  void changeSelectedSymbols();
154  void applyChangeToSymbol();
155 
156  QList<QgsSymbol *> selectedSymbols() override;
157  QgsSymbol *findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList &ranges ) const;
158  void refreshSymbolView() override;
159 
160  void keyPressEvent( QKeyEvent *event ) override;
161 
162  private:
163  enum MethodMode
164  {
165  ColorMode,
166  SizeMode
167  };
168 
169  QgsExpressionContext createExpressionContext() const override;
170  void toggleMethodWidgets( MethodMode mode );
171 
172  std::unique_ptr< QgsGraduatedSymbolRenderer > mRenderer;
173 
174  std::unique_ptr< QgsSymbol > mGraduatedSymbol;
175 
176  int mRowSelected;
177 
178  QgsGraduatedSymbolRendererModel *mModel = nullptr;
179 
180  QgsRangeList mCopyBuffer;
181 
182  QDoubleValidator *mSymmetryPointValidator;
183 };
184 
185 
186 #endif // QGSGRADUATEDSYMBOLRENDERERWIDGET_H
QList< QgsRendererRange > QgsRangeList
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
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
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
#define SIP_FACTORY
Definition: qgis_sip.h:76
Abstract interface for generating an expression context.
Represents a vector layer which manages a vector based data sets.