QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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 "ui_qgsgraduatedsymbolrendererwidget.h"
20
21#include "qgis_gui.h"
22#include "qgis_sip.h"
23#include "qgsdoublevalidator.h"
26#include "qgsproxystyle.h"
27#include "qgsrendererwidget.h"
28
29#include <QStandardItem>
30#include <qtimer.h>
31
33
34#ifndef SIP_RUN
36
37class GUI_EXPORT QgsGraduatedSymbolRendererModel : public QAbstractItemModel
38{
39 Q_OBJECT
40 public:
41 QgsGraduatedSymbolRendererModel( QObject *parent = nullptr, QScreen *screen = 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 QPointer<QScreen> mScreen;
73};
74
75// View style which shows a drop indicator line between items
76class QgsGraduatedSymbolRendererViewStyle : public QgsProxyStyle
77{
78 Q_OBJECT
79
80 public:
81 explicit QgsGraduatedSymbolRendererViewStyle( QWidget *parent );
82
83 void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
84};
85
87#endif
88
94class GUI_EXPORT QgsGraduatedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsGraduatedSymbolRendererWidget
95{
96 Q_OBJECT
97
98 public:
100
103
104 QgsFeatureRenderer *renderer() override;
105 void setContext( const QgsSymbolWidgetContext &context ) override;
106 void disableSymbolLevels() override SIP_SKIP;
108
109 public slots:
110 void graduatedColumnChanged( const QString &field );
111 void classifyGraduated();
112 void reapplyColorRamp();
113 void reapplySizes();
114 void rangesDoubleClicked( const QModelIndex &idx );
115 void rangesClicked( const QModelIndex &idx );
116 void changeCurrentValue( QStandardItem *item );
117
119 void addClass();
121 void deleteClasses();
123 void deleteAllClasses();
125 void toggleBoundariesLink( bool linked );
126
127 void labelFormatChanged();
128
129 void showSymbolLevels();
130
131 void rowsMoved();
132 void modelDataChanged();
133
139 void refreshRanges( bool reset );
140
141 protected:
142 void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
143
144 private slots:
145 void mSizeUnitWidget_changed();
146 void methodComboBox_currentIndexChanged( int );
147 void updateMethodParameters();
148 void updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget );
149 void dataDefinedSizeLegend();
150 void changeGraduatedSymbol();
151 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
152 void symmetryPointEditingFinished();
153 void classifyGraduatedImpl();
154
155 protected slots:
156
157 void pasteSymbolToSelection() override;
158
159 protected:
160 void updateUiFromRenderer( bool updateCount = true );
163 bool rowsOrdered();
164
166 QList<int> selectedClasses();
168
169 void changeRangeSymbol( int rangeIdx );
170 void changeRange( int rangeIdx );
171
174 void applyChangeToSymbol();
175
176 QList<QgsSymbol *> selectedSymbols() override;
177 QgsSymbol *findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList &ranges ) const;
178 void refreshSymbolView() override;
179
180 void keyPressEvent( QKeyEvent *event ) override;
181
182 private:
183 enum MethodMode
184 {
185 ColorMode,
186 SizeMode
187 };
188
189 void toggleMethodWidgets( MethodMode mode );
190
191 void clearParameterWidgets();
192
193 std::unique_ptr<QgsGraduatedSymbolRenderer> mRenderer;
194
195 std::unique_ptr<QgsSymbol> mGraduatedSymbol;
196
197 int mRowSelected;
198
199 QgsGraduatedSymbolRendererModel *mModel = nullptr;
200
201 QgsRangeList mCopyBuffer;
202
203 QgsDoubleValidator *mSymmetryPointValidator = nullptr;
204 QAction *mActionLevels = nullptr;
205
206 std::unique_ptr< QgsClassificationMethod > mClassificationMethod;
207 std::vector<std::unique_ptr<QgsAbstractProcessingParameterWidgetWrapper>> mParameterWidgetWrappers;
208
209 int mBlockUpdates = 0;
210
211 QTimer mUpdateTimer;
212};
213
214
215#endif // QGSGRADUATEDSYMBOLRENDERERWIDGET_H
A custom validator which allows entry of doubles in a locale-tolerant way.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract base class for all 2D vector feature renderers.
void deleteClasses()
Removes currently selected classes.
QList< QgsSymbol * > selectedSymbols() override
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
void disableSymbolLevels() override
Disables symbol level modification on the widget.
static QgsRendererWidget * create(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
QgsGraduatedSymbolRendererWidget(QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer)
void setContext(const QgsSymbolWidgetContext &context) override
Sets the context in which the renderer widget is shown, e.g., the associated map canvas and expressio...
void refreshRanges(bool reset)
Refreshes the ranges for the renderer.
QgsFeatureRenderer * renderer() override
Returns pointer to the renderer (no transfer of ownership).
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void setSymbolLevels(const QgsLegendSymbolList &levels, bool enabled) override
Sets the symbol levels for the renderer defined in the widget.
QgsSymbol * findSymbolForRange(double lowerBound, double upperBound, const QgsRangeList &ranges) const
void deleteAllClasses()
Removes all classes from the classification.
void addClass()
Adds a class manually to the classification.
void toggleBoundariesLink(bool linked)
Toggle the link between classes boundaries.
void applyChangeToSymbol()
Applies current symbol to selected ranges, or to all ranges if none is selected.
QList< int > selectedClasses()
Returns a list of indexes for the classes under selection.
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
QgsRendererWidget(QgsVectorLayer *layer, QgsStyle *style)
QgsSymbolWidgetContext context() const
Returns the context in which the renderer widget is shown, e.g., the associated map canvas and expres...
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition qgsstyle.h:88
Symbol selector widget that can be used to select and build a symbol.
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:231
Represents a vector layer which manages a vector based dataset.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_FACTORY
Definition qgis_sip.h:84
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsRendererRange > QgsRangeList