QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
35 
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 
99  QgsGraduatedSymbolRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer );
100  ~QgsGraduatedSymbolRendererWidget() override;
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 
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  int mBlockUpdates = 0;
206 };
207 
208 
209 #endif // QGSGRADUATEDSYMBOLRENDERERWIDGET_H
QgsRendererWidget::renderer
virtual QgsFeatureRenderer * renderer()=0
Returns pointer to the renderer (no transfer of ownership)
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsRendererWidget::refreshSymbolView
virtual void refreshSymbolView()
Definition: qgsrendererwidget.h:138
qgsproxystyle.h
QgsSymbolWidgetContext
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Definition: qgssymbolwidgetcontext.h:35
QgsRendererRange
Definition: qgsrendererrange.h:36
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
field
const QgsField & field
Definition: qgsfield.h:463
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsRendererWidget::disableSymbolLevels
virtual void disableSymbolLevels()
Disables symbol level modification on the widget.
Definition: qgsrendererwidget.cpp:369
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
QgsRangeList
QList< QgsRendererRange > QgsRangeList
Definition: qgsrendererrange.h:191
QgsRendererWidget::pasteSymbolToSelection
virtual void pasteSymbolToSelection()
Pastes the clipboard symbol over selected items.
Definition: qgsrendererwidget.cpp:302
QgsGraduatedSymbolRenderer
Definition: qgsgraduatedsymbolrenderer.h:35
QgsDoubleValidator
QgsDoubleValidator is a QLineEdit Validator that combines QDoubleValidator and QRegularExpressionVali...
Definition: qgsdoublevalidator.h:40
qgis_sip.h
qgsprocessingwidgetwrapper.h
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsPanelWidget::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Overridden key press event to handle the esc event on the widget.
Definition: qgspanelwidget.cpp:117
QgsRendererWidget::setSymbolLevels
virtual void setSymbolLevels(const QList< QgsLegendSymbolItem > &levels, bool enabled)
Sets the symbol levels for the renderer defined in the widget.
Definition: qgsrendererwidget.cpp:387
QgsRendererWidget
Base class for renderer settings widgets.
Definition: qgsrendererwidget.h:45
QgsRendererWidget::selectedSymbols
virtual QList< QgsSymbol * > selectedSymbols()
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
Definition: qgsrendererwidget.h:137
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsStyle
Definition: qgsstyle.h:159
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
qgsrendererwidget.h
qgsdoublevalidator.h
qgsgraduatedsymbolrenderer.h
QgsLegendSymbolList
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Definition: qgslegendsymbolitem.h:144
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
QgsRendererWidget::setContext
virtual void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the renderer widget is shown, e.g., the associated map canvas and expressio...
Definition: qgsrendererwidget.cpp:341
QgsProxyStyle
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
Definition: qgsproxystyle.h:30