QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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"
29 #include "qgssymbol.h"
31 #include "qgis_gui.h"
32 #include <QStandardItemModel>
33 #include <QItemDelegate>
34 
35 class QgsMapCanvas;
36 
37 #ifndef SIP_RUN
38 
40 
41 class GUI_EXPORT QgsPropertyAbstractTransformerWidget : public QWidget
42 {
43  Q_OBJECT
44 
45  public:
46 
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 
62  QgsPropertyDefinition mDefinition;
63 
64 };
65 
66 class GUI_EXPORT QgsPropertyGenericNumericAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertyGenericNumericAssistant
67 {
68  Q_OBJECT
69 
70  public:
71 
72  QgsPropertyGenericNumericAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
73 
74  QgsGenericNumericTransformer *createTransformer( double minValue, double maxValue ) const override;
75 
76 };
77 
78 class GUI_EXPORT QgsPropertySizeAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertySizeAssistant
79 {
80  Q_OBJECT
81 
82  public:
83 
84  QgsPropertySizeAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
85 
86  QgsSizeScaleTransformer *createTransformer( double minValue, double maxValue ) const override;
87 
88  QList< QgsSymbolLegendNode * > generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const override;
89 };
90 
91 class GUI_EXPORT QgsPropertyColorAssistantWidget : public QgsPropertyAbstractTransformerWidget, private Ui::PropertyColorAssistant
92 {
93  Q_OBJECT
94 
95  public:
96 
97  QgsPropertyColorAssistantWidget( QWidget *parent = nullptr, const QgsPropertyDefinition &definition = QgsPropertyDefinition(), const QgsProperty &initialState = QgsProperty() );
98 
99  QgsColorRampTransformer *createTransformer( double minValue, double maxValue ) const override;
100 
101  QList< QgsSymbolLegendNode * > generatePreviews( const QList<double> &breaks, QgsLayerTreeLayer *parent, const QgsSymbol *symbol, double minValue, double maxValue, QgsCurveTransform *curve ) const override;
102 };
103 
105 
106 #endif
107 
108 
115 class GUI_EXPORT QgsPropertyAssistantWidget : public QgsPanelWidget, private Ui::PropertyAssistantBase
116 {
117  Q_OBJECT
118 
119  public:
120 
128  QgsPropertyAssistantWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr,
129  const QgsPropertyDefinition &definition = QgsPropertyDefinition(),
130  const QgsProperty &initialState = QgsProperty(),
131  const QgsVectorLayer *layer = nullptr );
132 
137  void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );
138 
143  void updateProperty( QgsProperty &property );
144 
150  void setSymbol( std::shared_ptr< QgsSymbol > symbol ) { mSymbol = symbol; updatePreview(); } SIP_SKIP
151 
152  void setDockMode( bool dockMode ) override;
153 
154  private slots:
155  void computeValuesFromLayer();
156  void updatePreview();
157 
158 
159  private:
160 
161  QgsPropertyDefinition mDefinition;
162  const QgsVectorLayer *mLayer = nullptr;
163  QgsExpressionContextGenerator *mExpressionContextGenerator = nullptr;
164  QgsPropertyAbstractTransformerWidget *mTransformerWidget = nullptr;
165 
166  QgsLayerTreeLayer *mLayerTreeLayer = nullptr;
167  QgsLayerTreeGroup mRoot;
168  QStandardItemModel mPreviewList;
169 
170  std::shared_ptr< QgsSymbol > mSymbol;
171 
172  bool computeValuesFromExpression( const QString &expression, double &minValue, double &maxValue ) const;
173  bool computeValuesFromField( const QString &fieldName, double &minValue, double &maxValue ) const;
174 
175 };
176 
177 #ifndef SIP_RUN
178 
180 class QgsAssistantPreviewItemDelegate : public QItemDelegate
181 {
182  Q_OBJECT
183 
184  public:
185  explicit QgsAssistantPreviewItemDelegate( QStandardItemModel *model ) : mModel( model ) {}
186 
187  QSize sizeHint( const QStyleOptionViewItem & /*option*/, const QModelIndex &index ) const override
188  {
189  QSize size = mModel->item( index.row() )->icon().actualSize( QSize( 512, 512 ) );
190  size.rheight() += 6;
191  return size;
192  }
193 
194  private:
195  QStandardItemModel *mModel = nullptr;
196 
197 };
198 
200 
201 #endif
202 
203 #endif // QGSPROPERTYASSISTANTWIDGET_H
Layer tree group node serves as a container for layers and further groups.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
void setSymbol(std::shared_ptr< QgsSymbol > symbol)
Sets a symbol which can be used for previews inside the widget.
QgsPropertyTransformer subclass for scaling an input numeric value into an output numeric value...
Abstract base class for objects which transform the calculated value of a property.
Base class for any widget that can be shown as a inline panel.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs...
#define SIP_SKIP
Definition: qgis_sip.h:119
Shows a user-friendly assistant guiding users through the creation of QgsProperty overrides...
A store for object properties.
Definition: qgsproperty.h:229
Definition for a property.
Definition: qgsproperty.h:46
Abstract interface for generating an expression context.
Handles scaling of input values to output values by using a curve created from smoothly joining a num...
QgsPropertyTransformer subclass for scaling a value into a size according to various scaling methods...
Represents a vector layer which manages a vector based data sets.
QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp...
Layer tree node points to a map layer.