QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 "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 QgsPropertyAbstractTransformerWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition() )
46 : QWidget( parent )
47 , mDefinition( definition )
48 {}
49
50 virtual QgsPropertyTransformer *createTransformer( double minValue, double maxValue ) const = 0;
51
52 virtual QList<QgsSymbolLegendNode *> generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const;
53
54 signals:
55
56 void widgetChanged();
57
58 protected:
59 QgsPropertyDefinition mDefinition;
60};
61
62class GUI_EXPORT QgsPropertyGenericNumericAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertyGenericNumericAssistant
63{
64 Q_OBJECT
65
66 public:
67 QgsPropertyGenericNumericAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
68
69 QgsGenericNumericTransformer *createTransformer( double minValue, double maxValue ) const override;
70};
71
72class GUI_EXPORT QgsPropertySizeAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertySizeAssistant
73{
74 Q_OBJECT
75
76 public:
77 QgsPropertySizeAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
78
79 QgsSizeScaleTransformer *createTransformer( double minValue, double maxValue ) const override;
80
81 QList<QgsSymbolLegendNode *> generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const override;
82};
83
84class GUI_EXPORT QgsPropertyColorAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertyColorAssistant
85{
86 Q_OBJECT
87
88 public:
89 QgsPropertyColorAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
90
91 QgsColorRampTransformer *createTransformer( double minValue, double maxValue ) const override;
92
93 QList<QgsSymbolLegendNode *> generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const override;
94};
95
97
98#endif
99
100
106class GUI_EXPORT QgsPropertyAssistantWidget : public QgsPanelWidget, private Ui::PropertyAssistantBase
107{
108 Q_OBJECT
109
110 public:
118 QgsPropertyAssistantWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty(), const QgsVectorLayer *layer = nullptr );
119
124 void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
125
130 void updateProperty( QgsProperty &property );
131
137 void setSymbol( std::shared_ptr<QgsSymbol> symbol ) SIP_SKIP
138 {
139 mSymbol = symbol;
140 updatePreview();
141 }
142
143 void setDockMode( bool dockMode ) override;
144
145 private slots:
146 void computeValuesFromLayer();
147 void updatePreview();
148
149 private:
150 QgsPropertyDefinition mDefinition;
151 const QgsVectorLayer *mLayer = nullptr;
152 QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
153 QgsPropertyAbstractTransformerWidget *mTransformerWidget = nullptr;
154
155 QgsLayerTreeLayer *mLayerTreeLayer = nullptr;
156 QgsLayerTreeGroup mRoot;
157 QStandardItemModel mPreviewList;
158
159 std::shared_ptr<QgsSymbol> mSymbol;
160
161 bool computeValuesFromExpression( const QString &expression, double &minValue, double &maxValue ) const;
162 bool computeValuesFromField( const QString &fieldName, double &minValue, double &maxValue ) const;
163};
164
165#ifndef SIP_RUN
166
168class QgsAssistantPreviewItemDelegate : public QItemDelegate
169{
170 Q_OBJECT
171
172 public:
173 explicit QgsAssistantPreviewItemDelegate( QStandardItemModel *model )
174 : mModel( model ) {}
175
176 QSize sizeHint( const QStyleOptionViewItem & /*option*/, const QModelIndex &index ) const override
177 {
178 QSize size = mModel->item( index.row() )->icon().actualSize( QSize( 512, 512 ) );
179 size.rheight() += 6;
180 return size;
181 }
182
183 private:
184 QStandardItemModel *mModel = nullptr;
185};
186
188
189#endif
190
191#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.
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.
QgsPropertyTransformer subclass for scaling a value into a size according to various scaling methods.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
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