QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "ui_qgspropertyassistantwidgetbase.h"
22#include "ui_qgspropertycolorassistantwidget.h"
23#include "ui_qgspropertygenericnumericassistantwidget.h"
24#include "ui_qgspropertysizeassistantwidget.h"
25
26#include "qgis_gui.h"
27#include "qgis_sip.h"
28#include "qgslayertreegroup.h"
30#include "qgspanelwidget.h"
31#include "qgsproperty.h"
32
33#include <QItemDelegate>
34#include <QStandardItemModel>
35
36class QgsMapCanvas;
37
38#ifndef SIP_RUN
39
41
42class GUI_EXPORT QgsPropertyAbstractTransformerWidget : public QWidget
43{
44 Q_OBJECT
45
46 public:
47 QgsPropertyAbstractTransformerWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition() )
48 : QWidget( parent )
49 , mDefinition( definition )
50 {}
51
52 virtual QgsPropertyTransformer *createTransformer( double minValue, double maxValue ) const = 0;
53
54 virtual QList<QgsSymbolLegendNode *> generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const;
55
56 signals:
57
58 void widgetChanged();
59
60 protected:
61 QgsPropertyDefinition mDefinition;
62};
63
64class GUI_EXPORT QgsPropertyGenericNumericAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertyGenericNumericAssistant
65{
66 Q_OBJECT
67
68 public:
69 QgsPropertyGenericNumericAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
70
71 QgsGenericNumericTransformer *createTransformer( double minValue, double maxValue ) const override;
72};
73
74class GUI_EXPORT QgsPropertySizeAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertySizeAssistant
75{
76 Q_OBJECT
77
78 public:
79 QgsPropertySizeAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
80
81 QgsSizeScaleTransformer *createTransformer( double minValue, double maxValue ) const override;
82
83 QList<QgsSymbolLegendNode *> generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const override;
84};
85
86class GUI_EXPORT QgsPropertyColorAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertyColorAssistant
87{
88 Q_OBJECT
89
90 public:
91 QgsPropertyColorAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
92
93 QgsColorRampTransformer *createTransformer( double minValue, double maxValue ) const override;
94
95 QList<QgsSymbolLegendNode *> generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const override;
96};
97
99
100#endif
101
102
108class GUI_EXPORT QgsPropertyAssistantWidget : public QgsPanelWidget, private Ui::PropertyAssistantBase
109{
110 Q_OBJECT
111
112 public:
120 QgsPropertyAssistantWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty(), const QgsVectorLayer *layer = nullptr );
121
127
132 void updateProperty( QgsProperty &property );
133
139 void setSymbol( std::shared_ptr<QgsSymbol> symbol ) SIP_SKIP
140 {
141 mSymbol = std::move( symbol );
142 updatePreview();
143 }
144
145 void setDockMode( bool dockMode ) override;
146
147 private slots:
148 void computeValuesFromLayer();
149 void updatePreview();
150
151 private:
152 QgsPropertyDefinition mDefinition;
153 const QgsVectorLayer *mLayer = nullptr;
154 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
155 QgsPropertyAbstractTransformerWidget *mTransformerWidget = nullptr;
156
157 QgsLayerTreeLayer *mLayerTreeLayer = nullptr;
158 QgsLayerTreeGroup mRoot;
159 QStandardItemModel mPreviewList;
160
161 std::shared_ptr<QgsSymbol> mSymbol;
162
163 bool computeValuesFromExpression( const QString &expression, double &minValue, double &maxValue ) const;
164 bool computeValuesFromField( const QString &fieldName, double &minValue, double &maxValue ) const;
165};
166
167#ifndef SIP_RUN
168
170class QgsAssistantPreviewItemDelegate : public QItemDelegate
171{
172 Q_OBJECT
173
174 public:
175 explicit QgsAssistantPreviewItemDelegate( QStandardItemModel *model )
176 : mModel( model ) {}
177
178 QSize sizeHint( const QStyleOptionViewItem & /*option*/, const QModelIndex &index ) const override
179 {
180 QSize size = mModel->item( index.row() )->icon().actualSize( QSize( 512, 512 ) );
181 size.rheight() += 6;
182 return size;
183 }
184
185 private:
186 QStandardItemModel *mModel = nullptr;
187};
188
190
191#endif
192
193#endif // QGSPROPERTYASSISTANTWIDGET_H
Abstract interface for generating an expression context.
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.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
QgsPropertyAssistantWidget(QWidget *parent=nullptr, const QgsPropertyDefinition &definition=QgsPropertyDefinition(), const QgsProperty &initialState=QgsProperty(), const QgsVectorLayer *layer=nullptr)
Constructor for QgsPropertyAssistantWidget.
void setSymbol(std::shared_ptr< QgsSymbol > symbol)
Sets a symbol which can be used for previews inside the widget.
void updateProperty(QgsProperty &property)
Updates a property in place to corresponding to the current settings shown in the widget.
Definition for a property.
Definition qgsproperty.h:45
A store for object properties.
Represents a vector layer which manages a vector based dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134