QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
19 #include <QStandardItem>
20 
21 
23 #include "qgis_sip.h"
24 #include "qgsrendererwidget.h"
25 #include "qgsproxystyle.h"
27 
28 #include "ui_qgsgraduatedsymbolrendererwidget.h"
29 
30 #include "qgis_gui.h"
31 
32 
33 #ifndef SIP_RUN
35 
36 class GUI_EXPORT QgsGraduatedSymbolRendererModel : public QAbstractItemModel
37 {
38  Q_OBJECT
39  public:
40  QgsGraduatedSymbolRendererModel( QObject *parent = nullptr );
41  Qt::ItemFlags flags( const QModelIndex &index ) const override;
42  Qt::DropActions supportedDropActions() const override;
43  QVariant data( const QModelIndex &index, int role ) const override;
44  bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
45  QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
46  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
47  int columnCount( const QModelIndex & = QModelIndex() ) const override;
48  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
49  QModelIndex parent( const QModelIndex &index ) const override;
50  QStringList mimeTypes() const override;
51  QMimeData *mimeData( const QModelIndexList &indexes ) const override;
52  bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;
53 
54  void setRenderer( QgsGraduatedSymbolRenderer *renderer );
55 
56  QgsRendererRange rendererRange( const QModelIndex &index );
57  void addClass( QgsSymbol *symbol );
58  void addClass( const QgsRendererRange &range );
59  void deleteRows( QList<int> rows );
60  void removeAllRows();
61  void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
62  void updateSymbology();
63  void updateLabels();
64 
65  signals:
66  void rowsMoved();
67 
68  private:
69  QgsGraduatedSymbolRenderer *mRenderer = nullptr;
70  QString mMimeFormat;
71 };
72 
73 // View style which shows drop indicator line between items
74 class QgsGraduatedSymbolRendererViewStyle: public QgsProxyStyle
75 {
76  Q_OBJECT
77 
78  public:
79  explicit QgsGraduatedSymbolRendererViewStyle( QWidget *parent );
80 
81  void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
82 };
83 
85 #endif
86 
91 class GUI_EXPORT QgsGraduatedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsGraduatedSymbolRendererWidget, private QgsExpressionContextGenerator
92 {
93  Q_OBJECT
94 
95  public:
96  static QgsRendererWidget *create( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer ) SIP_FACTORY;
97 
100 
101  QgsFeatureRenderer *renderer() override;
102  void setContext( const QgsSymbolWidgetContext &context ) override;
103  void disableSymbolLevels() override SIP_SKIP;
104 
105  public slots:
106  void graduatedColumnChanged( const QString &field );
107  void classifyGraduated();
108  void reapplyColorRamp();
109  void reapplySizes();
110  void rangesDoubleClicked( const QModelIndex &idx );
111  void rangesClicked( const QModelIndex &idx );
112  void changeCurrentValue( QStandardItem *item );
113 
115  void addClass();
117  void deleteClasses();
119  void deleteAllClasses();
121  void toggleBoundariesLink( bool linked );
122 
123  void labelFormatChanged();
124 
125  void showSymbolLevels();
126 
127  void rowsMoved();
128  void modelDataChanged();
129 
135  void refreshRanges( bool reset );
136 
137  protected:
138  void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
139 
140  private slots:
141  void mSizeUnitWidget_changed();
142  void methodComboBox_currentIndexChanged( int );
143  void updateMethodParameters();
144  void cleanUpSymbolSelector( QgsPanelWidget *container );
145  void updateSymbolsFromWidget();
146  void dataDefinedSizeLegend();
147  void changeGraduatedSymbol();
148  void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
149  void symmetryPointEditingFinished();
150 
151  protected slots:
152 
153  void pasteSymbolToSelection() override;
154 
155  protected:
156  void updateUiFromRenderer( bool updateCount = true );
157  void connectUpdateHandlers();
158  void disconnectUpdateHandlers();
159  bool rowsOrdered();
160 
162  QList<int> selectedClasses();
163  QgsRangeList selectedRanges();
164 
165  void changeRangeSymbol( int rangeIdx );
166  void changeRange( int rangeIdx );
167 
168  void changeSelectedSymbols();
170  void applyChangeToSymbol();
171 
172  QList<QgsSymbol *> selectedSymbols() override;
173  QgsSymbol *findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList &ranges ) const;
174  void refreshSymbolView() override;
175 
176  void keyPressEvent( QKeyEvent *event ) override;
177 
178  private:
179  enum MethodMode
180  {
181  ColorMode,
182  SizeMode
183  };
184 
185  QgsExpressionContext createExpressionContext() const override;
186  void toggleMethodWidgets( MethodMode mode );
187 
188  void clearParameterWidgets();
189 
190  std::unique_ptr< QgsGraduatedSymbolRenderer > mRenderer;
191 
192  std::unique_ptr< QgsSymbol > mGraduatedSymbol;
193 
194  int mRowSelected;
195 
196  QgsGraduatedSymbolRendererModel *mModel = nullptr;
197 
198  QgsRangeList mCopyBuffer;
199 
200  QDoubleValidator *mSymmetryPointValidator = nullptr;
201  QAction *mActionLevels = nullptr;
202  std::vector< std::unique_ptr< QgsAbstractProcessingParameterWidgetWrapper >> mParameterWidgetWrappers;
203 };
204 
205 
206 #endif // QGSGRADUATEDSYMBOLRENDERERWIDGET_H
Abstract interface for generating an expression context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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:31
Base class for renderer settings widgets.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
Represents a vector layer which manages a vector based data sets.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_FACTORY
Definition: qgis_sip.h:76
const QgsField & field
Definition: qgsfield.h:463
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsRendererRange > QgsRangeList