QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
34 class QgsMapCanvas;
35 
36 #ifndef SIP_RUN
37 
39 
40 class 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 
65 class 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 
77 class 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 
90 class 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 
114 class GUI_EXPORT QgsPropertyAssistantWidget : public QgsPanelWidget, private Ui::PropertyAssistantBase
115 {
116  Q_OBJECT
117 
118  public:
119 
127  QgsPropertyAssistantWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr,
128  const QgsPropertyDefinition &definition = QgsPropertyDefinition(),
129  const QgsProperty &initialState = QgsProperty(),
130  const QgsVectorLayer *layer = nullptr );
131 
136  void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
137 
142  void updateProperty( QgsProperty &property );
143 
149  void setSymbol( std::shared_ptr< QgsSymbol > symbol ) { mSymbol = symbol; updatePreview(); } SIP_SKIP
150 
151  void setDockMode( bool dockMode ) override;
152 
153  private slots:
154  void computeValuesFromLayer();
155  void updatePreview();
156 
157 
158  private:
159 
160  QgsPropertyDefinition mDefinition;
161  const QgsVectorLayer *mLayer = nullptr;
162  QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
163  QgsPropertyAbstractTransformerWidget *mTransformerWidget = nullptr;
164 
165  QgsLayerTreeLayer *mLayerTreeLayer = nullptr;
166  QgsLayerTreeGroup mRoot;
167  QStandardItemModel mPreviewList;
168 
169  std::shared_ptr< QgsSymbol > mSymbol;
170 
171  bool computeValuesFromExpression( const QString &expression, double &minValue, double &maxValue ) const;
172  bool computeValuesFromField( const QString &fieldName, double &minValue, double &maxValue ) const;
173 
174 };
175 
176 #ifndef SIP_RUN
177 
179 class QgsAssistantPreviewItemDelegate : public QItemDelegate
180 {
181  Q_OBJECT
182 
183  public:
184  explicit QgsAssistantPreviewItemDelegate( QStandardItemModel *model ) : mModel( model ) {}
185 
186  QSize sizeHint( const QStyleOptionViewItem & /*option*/, const QModelIndex &index ) const override
187  {
188  QSize size = mModel->item( index.row() )->icon().actualSize( QSize( 512, 512 ) );
189  size.rheight() += 6;
190  return size;
191  }
192 
193  private:
194  QStandardItemModel *mModel = nullptr;
195 
196 };
197 
199 
200 #endif
201 
202 #endif // QGSPROPERTYASSISTANTWIDGET_H
QgsPropertyAssistantWidget
Shows a user-friendly assistant guiding users through the creation of QgsProperty overrides.
Definition: qgspropertyassistantwidget.h:114
QgsProperty
A store for object properties.
Definition: qgsproperty.h:230
qgslayertreemodellegendnode.h
QgsPanelWidget::setDockMode
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
Definition: qgspanelwidget.cpp:44
QgsPropertyTransformer
Abstract base class for objects which transform the calculated value of a property....
Definition: qgspropertytransformer.h:170
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsColorRampTransformer
QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp.
Definition: qgspropertytransformer.h:608
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsPropertyAssistantWidget::setSymbol
void setSymbol(std::shared_ptr< QgsSymbol > symbol)
Sets a symbol which can be used for previews inside the widget.
Definition: qgspropertyassistantwidget.h:149
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
qgslayertreegroup.h
QgsLayerTreeLayer
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:43
QgsSizeScaleTransformer
QgsPropertyTransformer subclass for scaling a value into a size according to various scaling methods.
Definition: qgspropertytransformer.h:461
qgis_sip.h
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:40
QgsPropertyDefinition
Definition for a property.
Definition: qgsproperty.h:46
QgsCurveTransform
Handles scaling of input values to output values by using a curve created from smoothly joining a num...
Definition: qgspropertytransformer.h:56
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
qgsproperty.h
QgsGenericNumericTransformer
QgsPropertyTransformer subclass for scaling an input numeric value into an output numeric value.
Definition: qgspropertytransformer.h:343
qgspanelwidget.h
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53