QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgswidgetwrapper.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgswidgetwrapper.h
3  --------------------------------------
4  Date : 14.5.2014
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias at opengis dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSWIDGETWRAPPER_H
17 #define QGSWIDGETWRAPPER_H
18 
19 #include <QObject>
20 #include <QMap>
21 #include <QVariant>
22 
23 class QgsVectorLayer;
24 
26 #include "qgis_gui.h"
27 #include "qgis_sip.h"
28 #include "qgspropertycollection.h"
29 
30 #ifdef SIP_RUN
31 // This is required for the ConvertToSubClassCode to work properly
32 // so RTTI for casting is available in the whole module.
33 % ModuleCode
35 #include "qgsqmlwidgetwrapper.h"
36 #include "qgshtmlwidgetwrapper.h"
37 % End
38 #endif
39 
52 class GUI_EXPORT QgsWidgetWrapper : public QObject
53 {
54 
55 #ifdef SIP_RUN
57  if ( qobject_cast<QgsEditorWidgetWrapper *>( sipCpp ) )
58  sipType = sipType_QgsEditorWidgetWrapper;
59  else if ( qobject_cast<QgsRelationWidgetWrapper *>( sipCpp ) )
60  sipType = sipType_QgsRelationWidgetWrapper;
61  else if ( qobject_cast<QgsQmlWidgetWrapper *>( sipCpp ) )
62  sipType = sipType_QgsQmlWidgetWrapper;
63  else if ( qobject_cast<QgsHtmlWidgetWrapper *>( sipCpp ) )
64  sipType = sipType_QgsHtmlWidgetWrapper;
65  else
66  sipType = 0;
67  SIP_END
68 #endif
69 
70  Q_OBJECT
71  public:
72 
76  enum Property
77  {
78  RootPath = 0,
80  StorageUrl
81  };
82 
87  static const QgsPropertiesDefinition &propertyDefinitions();
88 
96  explicit QgsWidgetWrapper( QgsVectorLayer *vl, QWidget *editor = nullptr, QWidget *parent = nullptr );
97 
103  QWidget *widget();
104 
116  template <class T> SIP_SKIP
117  T *widget() { return dynamic_cast<T>( mWidget ); }
118 
124  void setConfig( const QVariantMap &config );
125 
131  void setContext( const QgsAttributeEditorContext &context );
132 
141  QVariant config( const QString &key, const QVariant &defaultVal = QVariant() ) const;
142 
146  QVariantMap config() const;
147 
151  const QgsAttributeEditorContext &context() const;
152 
156  QgsVectorLayer *layer() const;
157 
163  static QgsWidgetWrapper *fromWidget( QWidget *widget );
164 
176  virtual bool valid() const = 0;
177 
178 
186  QgsPropertyCollection &dataDefinedProperties() { return mPropertyCollection; } SIP_SKIP
187 
194  const QgsPropertyCollection &dataDefinedProperties() const { return mPropertyCollection; }
195 
203  void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mPropertyCollection = collection; }
204 
212  void notifyAboutToSave();
213 
214  signals:
215 
221  void contextChanged();
222 
223  protected:
224 
236  virtual QWidget *createWidget( QWidget *parent ) = 0;
237 
243  virtual void initWidget( QWidget *editor );
244 
247 
248  public slots:
249 
256  virtual void setFeature( const QgsFeature &feature ) = 0;
257 
264  virtual void setEnabled( bool enabled );
265 
266  private:
267 
274  virtual void aboutToSave();
275 
276  QgsAttributeEditorContext mContext;
277  QVariantMap mConfig;
278  QWidget *mWidget = nullptr;
279  QWidget *mParent = nullptr;
280  QgsVectorLayer *mLayer = nullptr;
281  bool mInitialized;
282 };
283 
284 // We'll use this class inside a QVariant in the widgets properties
286 
287 #endif // QGSWIDGETWRAPPER_H
QgsWidgetWrapper::DocumentViewerContent
@ DocumentViewerContent
Document type for external resource.
Definition: qgswidgetwrapper.h:79
QgsWidgetWrapper::setDataDefinedProperties
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the editor widget's property collection, used for data defined overrides.
Definition: qgswidgetwrapper.h:203
QgsWidgetWrapper
Manages an editor widget Widget and wrapper share the same parent.
Definition: qgswidgetwrapper.h:52
QgsWidgetWrapper::Property
Property
Data defined properties for different editor widgets.
Definition: qgswidgetwrapper.h:76
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
QgsWidgetWrapper::widget
T * widget()
Access the widget managed by this wrapper and cast it to a given type.
Definition: qgswidgetwrapper.h:117
qgsqmlwidgetwrapper.h
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgis_sip.h
qgsattributeeditorcontext.h
QgsWidgetWrapper::dataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the editor widget's property collection, used for data defined overrides.
Definition: qgswidgetwrapper.h:186
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsWidgetWrapper::mPropertyCollection
QgsPropertyCollection mPropertyCollection
Data defined property collection.
Definition: qgswidgetwrapper.h:246
QgsWidgetWrapper::dataDefinedProperties
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the editor widget's property collection, used for data defined overrides.
Definition: qgswidgetwrapper.h:194
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
qgspropertycollection.h
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsAttributeEditorContext
This class contains context information for attribute editor widgets. It will be passed to embedded w...
Definition: qgsattributeeditorcontext.h:40
qgsrelationwidgetwrapper.h
qgshtmlwidgetwrapper.h
SIP_END
#define SIP_END
Definition: qgis_sip.h:203