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