QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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
QgsPropertyAssistantWidget
Definition: qgspropertyassistantwidget.h:115
QgsProperty
A store for object properties.
Definition: qgsproperty.h:231
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
Definition: qgsmapcanvas.h:83
QgsColorRampTransformer
QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp.
Definition: qgspropertytransformer.h:608
QgsSymbol
Definition: qgssymbol.h:63
QgsPropertyAssistantWidget::setSymbol
void setSymbol(std::shared_ptr< QgsSymbol > symbol)
Sets a symbol which can be used for previews inside the widget.
Definition: qgspropertyassistantwidget.h:150
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
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
Definition: qgslayertreegroup.h:34
QgsPropertyDefinition
Definition for a property.
Definition: qgsproperty.h:47
QgsCurveTransform
Handles scaling of input values to output values by using a curve created from smoothly joining a num...
Definition: qgspropertytransformer.h:56
QgsVectorLayer
Definition: qgsvectorlayer.h:385
qgsproperty.h
QgsGenericNumericTransformer
QgsPropertyTransformer subclass for scaling an input numeric value into an output numeric value.
Definition: qgspropertytransformer.h:343
qgspanelwidget.h
QgsExpressionContextGenerator
Definition: qgsexpressioncontextgenerator.h:36
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgssymbol.h