QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgspropertyassistantwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspropertyassistantwidget.h
3 ----------------------------
4 begin : February, 2017
5 copyright : (C) 2017 Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18#ifndef QGSPROPERTYASSISTANTWIDGET_H
19#define QGSPROPERTYASSISTANTWIDGET_H
20
21#include "qgspanelwidget.h"
22#include "qgis_sip.h"
23#include "ui_qgspropertyassistantwidgetbase.h"
24#include "ui_qgspropertysizeassistantwidget.h"
25#include "ui_qgspropertycolorassistantwidget.h"
26#include "ui_qgspropertygenericnumericassistantwidget.h"
27#include "qgsproperty.h"
28#include "qgslayertreegroup.h"
30#include "qgis_gui.h"
31#include <QStandardItemModel>
32#include <QItemDelegate>
33
34class QgsMapCanvas;
35
36#ifndef SIP_RUN
37
39
40class GUI_EXPORT QgsPropertyAbstractTransformerWidget : public QWidget
41{
42 Q_OBJECT
43
44 public:
45
46 QgsPropertyAbstractTransformerWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition() )
47 : QWidget( parent )
48 , mDefinition( definition )
49 {}
50
51 virtual QgsPropertyTransformer *createTransformer( double minValue, double maxValue ) const = 0;
52
53 virtual QList< QgsSymbolLegendNode * > generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const;
54
55 signals:
56
57 void widgetChanged();
58
59 protected:
60
61 QgsPropertyDefinition mDefinition;
62
63};
64
65class GUI_EXPORT QgsPropertyGenericNumericAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertyGenericNumericAssistant
66{
67 Q_OBJECT
68
69 public:
70
71 QgsPropertyGenericNumericAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
72
73 QgsGenericNumericTransformer *createTransformer( double minValue, double maxValue ) const override;
74
75};
76
77class GUI_EXPORT QgsPropertySizeAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertySizeAssistant
78{
79 Q_OBJECT
80
81 public:
82
83 QgsPropertySizeAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
84
85 QgsSizeScaleTransformer *createTransformer( double minValue, double maxValue ) const override;
86
87 QList< QgsSymbolLegendNode * > generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const override;
88};
89
90class GUI_EXPORT QgsPropertyColorAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertyColorAssistant
91{
92 Q_OBJECT
93
94 public:
95
96 QgsPropertyColorAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
97
98 QgsColorRampTransformer *createTransformer( double minValue, double maxValue ) const override;
99
100 QList< QgsSymbolLegendNode * > generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const override;
101};
102
104
105#endif
106
107
113class GUI_EXPORT QgsPropertyAssistantWidget : public QgsPanelWidget, private Ui::PropertyAssistantBase
114{
115 Q_OBJECT
116
117 public:
118
126 QgsPropertyAssistantWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr,
127 const QgsPropertyDefinition &definition = QgsPropertyDefinition(),
128 const QgsProperty &initialState = QgsProperty(),
129 const QgsVectorLayer *layer = nullptr );
130
135 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
136
141 void updateProperty( QgsProperty &property );
142
148 void setSymbol( std::shared_ptr< QgsSymbol > symbol ) { mSymbol = symbol; updatePreview(); } SIP_SKIP
149
150 void setDockMode( bool dockMode ) override;
151
152 private slots:
153 void computeValuesFromLayer();
154 void updatePreview();
155
156 private:
157
158 QgsPropertyDefinition mDefinition;
159 const QgsVectorLayer *mLayer = nullptr;
160 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
161 QgsPropertyAbstractTransformerWidget *mTransformerWidget = nullptr;
162
163 QgsLayerTreeLayer *mLayerTreeLayer = nullptr;
164 QgsLayerTreeGroup mRoot;
165 QStandardItemModel mPreviewList;
166
167 std::shared_ptr< QgsSymbol > mSymbol;
168
169 bool computeValuesFromExpression( const QString &expression, double &minValue, double &maxValue ) const;
170 bool computeValuesFromField( const QString &fieldName, double &minValue, double &maxValue ) const;
171};
172
173#ifndef SIP_RUN
174
176class QgsAssistantPreviewItemDelegate : public QItemDelegate
177{
178 Q_OBJECT
179
180 public:
181 explicit QgsAssistantPreviewItemDelegate( QStandardItemModel *model ) : mModel( model ) {}
182
183 QSize sizeHint( const QStyleOptionViewItem & /*option*/, const QModelIndex &index ) const override
184 {
185 QSize size = mModel->item( index.row() )->icon().actualSize( QSize( 512, 512 ) );
186 size.rheight() += 6;
187 return size;
188 }
189
190 private:
191 QStandardItemModel *mModel = nullptr;
192
193};
194
196
197#endif
198
199#endif // QGSPROPERTYASSISTANTWIDGET_H
QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp.
Handles scaling of input values to output values by using a curve created from smoothly joining a num...
Abstract interface for generating an expression context.
QgsPropertyTransformer subclass for scaling an input numeric value into an output numeric value.
Layer tree group node serves as a container for layers and further groups.
Layer tree node points to a map layer.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:93
Base class for any widget that can be shown as a inline panel.
Shows a user-friendly assistant guiding users through the creation of QgsProperty overrides.
void setSymbol(std::shared_ptr< QgsSymbol > symbol)
Sets a symbol which can be used for previews inside the widget.
Definition for a property.
Definition: qgsproperty.h:45
Abstract base class for objects which transform the calculated value of a property.
A store for object properties.
Definition: qgsproperty.h:228
QgsPropertyTransformer subclass for scaling a value into a size according to various scaling methods.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:94
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126