QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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
34 
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 
98  QgsGraduatedSymbolRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer );
99  ~QgsGraduatedSymbolRendererWidget() override;
100 
101  QgsFeatureRenderer *renderer() override;
102  void setContext( const QgsSymbolWidgetContext &context ) override;
103 
104  public slots:
105  void graduatedColumnChanged( const QString &field );
106  void classifyGraduated();
107  void reapplyColorRamp();
108  void reapplySizes();
109  void rangesDoubleClicked( const QModelIndex &idx );
110  void rangesClicked( const QModelIndex &idx );
111  void changeCurrentValue( QStandardItem *item );
112 
114  void addClass();
116  void deleteClasses();
118  void deleteAllClasses();
120  void toggleBoundariesLink( bool linked );
121 
122  void labelFormatChanged();
123 
124  void showSymbolLevels();
125 
126  void rowsMoved();
127  void modelDataChanged();
128 
134  void refreshRanges( bool reset );
135 
136  private slots:
137  void mSizeUnitWidget_changed();
138  void methodComboBox_currentIndexChanged( int );
139  void updateMethodParameters();
140  void cleanUpSymbolSelector( QgsPanelWidget *container );
141  void updateSymbolsFromWidget();
142  void dataDefinedSizeLegend();
143  void changeGraduatedSymbol();
144  void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
145  void symmetryPointEditingFinished();
146 
147  protected slots:
148 
149  void pasteSymbolToSelection() override;
150 
151  protected:
152  void updateUiFromRenderer( bool updateCount = true );
153  void connectUpdateHandlers();
154  void disconnectUpdateHandlers();
155  bool rowsOrdered();
156 
158  QList<int> selectedClasses();
159  QgsRangeList selectedRanges();
160 
161  void changeRangeSymbol( int rangeIdx );
162  void changeRange( int rangeIdx );
163 
164  void changeSelectedSymbols();
166  void applyChangeToSymbol();
167 
168  QList<QgsSymbol *> selectedSymbols() override;
169  QgsSymbol *findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList &ranges ) const;
170  void refreshSymbolView() override;
171 
172  void keyPressEvent( QKeyEvent *event ) override;
173 
174  private:
175  enum MethodMode
176  {
177  ColorMode,
178  SizeMode
179  };
180 
182  void toggleMethodWidgets( MethodMode mode );
183 
184  void clearParameterWidgets();
185 
186  std::unique_ptr< QgsGraduatedSymbolRenderer > mRenderer;
187 
188  std::unique_ptr< QgsSymbol > mGraduatedSymbol;
189 
190  int mRowSelected;
191 
192  QgsGraduatedSymbolRendererModel *mModel = nullptr;
193 
194  QgsRangeList mCopyBuffer;
195 
196  QDoubleValidator *mSymmetryPointValidator;
197 
198  std::vector< std::unique_ptr< QgsAbstractProcessingParameterWidgetWrapper >> mParameterWidgetWrappers;
199 };
200 
201 
202 #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:369
QgsRendererWidget::refreshSymbolView
virtual void refreshSymbolView()
Definition: qgsrendererwidget.h:124
qgsproxystyle.h
QgsSymbolWidgetContext
Definition: qgssymbolwidgetcontext.h:35
QgsRendererRange
Definition: qgsrendererrange.h:36
QgsSymbol
Definition: qgssymbol.h:63
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
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:98
QgsRendererWidget::pasteSymbolToSelection
virtual void pasteSymbolToSelection()
Pastes the clipboard symbol over selected items.
Definition: qgsrendererwidget.cpp:300
QgsGraduatedSymbolRenderer
Definition: qgsgraduatedsymbolrenderer.h:35
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:112
QgsRendererWidget
Definition: qgsrendererwidget.h:44
QgsRendererWidget::selectedSymbols
virtual QList< QgsSymbol * > selectedSymbols()
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
Definition: qgsrendererwidget.h:123
QgsFeatureRenderer
Definition: qgsrenderer.h:102
QgsStyle
Definition: qgsstyle.h:159
QgsVectorLayer
Definition: qgsvectorlayer.h:385
qgsrendererwidget.h
qgsgraduatedsymbolrenderer.h
QgsExpressionContextGenerator
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:337
QgsProxyStyle
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
Definition: qgsproxystyle.h:30