QGIS API Documentation 4.3.0-Master (3b7b3208a79)
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 QString formatRangeValue( double value ) const;
71 QString tooltip( const QModelIndex &index ) const;
72
73 QgsGraduatedSymbolRenderer *mRenderer = nullptr;
74 QString mMimeFormat;
75 QPointer<QScreen> mScreen;
76};
77
78// View style which shows a drop indicator line between items
79class QgsGraduatedSymbolRendererViewStyle : public QgsProxyStyle
80{
81 Q_OBJECT
82
83 public:
84 explicit QgsGraduatedSymbolRendererViewStyle( QWidget *parent );
85
86 void drawPrimitive( PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr ) const override;
87};
88
90#endif
91
97class GUI_EXPORT QgsGraduatedSymbolRendererWidget : public QgsRendererWidget, private Ui::QgsGraduatedSymbolRendererWidget
98{
99 Q_OBJECT
100
101 public:
103
106
107 QgsFeatureRenderer *renderer() override;
108 void setContext( const QgsSymbolWidgetContext &context ) override;
109 void disableSymbolLevels() override SIP_SKIP;
111
112 public slots:
113 void graduatedColumnChanged( const QString &field );
114 void classifyGraduated();
115 void reapplyColorRamp();
116 void reapplySizes();
117 void rangesDoubleClicked( const QModelIndex &idx );
118 void rangesClicked( const QModelIndex &idx );
119 void changeCurrentValue( QStandardItem *item );
120
122 void addClass();
124 void deleteClasses();
126 void deleteAllClasses();
128 void toggleBoundariesLink( bool linked );
129
130 void labelFormatChanged();
131
132 void showSymbolLevels();
133
134 void rowsMoved();
135 void modelDataChanged();
136
142 void refreshRanges( bool reset );
143
144 protected:
145 void setSymbolLevels( const QgsLegendSymbolList &levels, bool enabled ) override;
146
147 private slots:
148 void mSizeUnitWidget_changed();
149 void methodComboBox_currentIndexChanged( int );
150 void updateMethodParameters();
151 void updateSymbolsFromWidget( QgsSymbolSelectorWidget *widget );
152 void dataDefinedSizeLegend();
153 void changeGraduatedSymbol();
154 void selectionChanged( const QItemSelection &selected, const QItemSelection &deselected );
155 void symmetryPointEditingFinished();
156 void classifyGraduatedImpl();
157
158 protected slots:
159
160 void pasteSymbolToSelection() override;
161
162 protected:
163 void updateUiFromRenderer( bool updateCount = true );
166 bool rowsOrdered();
167
169 QList<int> selectedClasses();
171
172 void changeRangeSymbol( int rangeIdx );
173 void changeRange( int rangeIdx );
174
177 void applyChangeToSymbol();
178
179 QList<QgsSymbol *> selectedSymbols() override;
180 QgsSymbol *findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList &ranges ) const;
181 void refreshSymbolView() override;
182
183 void keyPressEvent( QKeyEvent *event ) override;
184
185 private:
186 enum MethodMode
187 {
188 ColorMode,
189 SizeMode
190 };
191
192 void toggleMethodWidgets( MethodMode mode );
193
194 void clearParameterWidgets();
195
196 std::unique_ptr<QgsGraduatedSymbolRenderer> mRenderer;
197
198 std::unique_ptr<QgsSymbol> mGraduatedSymbol;
199
200 int mRowSelected;
201
202 QgsGraduatedSymbolRendererModel *mModel = nullptr;
203
204 QgsRangeList mCopyBuffer;
205
206 QgsDoubleValidator *mSymmetryPointValidator = nullptr;
207 QAction *mActionLevels = nullptr;
208
209 std::unique_ptr< QgsClassificationMethod > mClassificationMethod;
210 std::vector<std::unique_ptr<QgsAbstractProcessingParameterWidgetWrapper>> mParameterWidgetWrappers;
211
212 int mBlockUpdates = 0;
213
214 QTimer mUpdateTimer;
215};
216
217
218#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:91
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:227
Represents a vector layer which manages a vector based dataset.
#define SIP_SKIP
Definition qgis_sip.h:138
#define SIP_FACTORY
Definition qgis_sip.h:83
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsRendererRange > QgsRangeList