QGIS API Documentation  3.6.0-Noosa (5873452)
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 % End
37 #endif
38 
51 class GUI_EXPORT QgsWidgetWrapper : public QObject
52 {
53 
54 #ifdef SIP_RUN
56  if ( qobject_cast<QgsEditorWidgetWrapper *>( sipCpp ) )
57  sipType = sipType_QgsEditorWidgetWrapper;
58  else if ( qobject_cast<QgsRelationWidgetWrapper *>( sipCpp ) )
59  sipType = sipType_QgsRelationWidgetWrapper;
60  else if ( qobject_cast<QgsQmlWidgetWrapper *>( sipCpp ) )
61  sipType = sipType_QgsQmlWidgetWrapper;
62  else
63  sipType = 0;
64  SIP_END
65 #endif
66 
67  Q_OBJECT
68  public:
69 
73  enum Property
74  {
75  RootPath = 0,
76  DocumentViewerContent
77  };
78 
83  static const QgsPropertiesDefinition &propertyDefinitions();
84 
92  explicit QgsWidgetWrapper( QgsVectorLayer *vl, QWidget *editor = nullptr, QWidget *parent = nullptr );
93 
99  QWidget *widget();
100 
109  template <class T> SIP_SKIP
110  T *widget() { return dynamic_cast<T>( mWidget ); }
111 
117  void setConfig( const QVariantMap &config );
118 
124  void setContext( const QgsAttributeEditorContext &context );
125 
134  QVariant config( const QString &key, const QVariant &defaultVal = QVariant() ) const;
135 
139  QVariantMap config() const;
140 
144  const QgsAttributeEditorContext &context() const;
145 
149  QgsVectorLayer *layer() const;
150 
156  static QgsWidgetWrapper *fromWidget( QWidget *widget );
157 
169  virtual bool valid() const = 0;
170 
171 
179  QgsPropertyCollection &dataDefinedProperties() { return mPropertyCollection; } SIP_SKIP
180 
187  const QgsPropertyCollection &dataDefinedProperties() const { return mPropertyCollection; }
188 
196  void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mPropertyCollection = collection; }
197 
205  void notifyAboutToSave();
206 
207  signals:
208 
214  void contextChanged();
215 
216  protected:
217 
229  virtual QWidget *createWidget( QWidget *parent ) = 0;
230 
236  virtual void initWidget( QWidget *editor );
237 
240 
241  public slots:
242 
249  virtual void setFeature( const QgsFeature &feature ) = 0;
250 
257  virtual void setEnabled( bool enabled );
258 
259  private:
260 
267  virtual void aboutToSave();
268 
269  QgsAttributeEditorContext mContext;
270  QVariantMap mConfig;
271  QWidget *mWidget = nullptr;
272  QWidget *mParent = nullptr;
273  QgsVectorLayer *mLayer = nullptr;
274  bool mInitialized;
275 };
276 
277 // We'll use this class inside a QVariant in the widgets properties
279 
280 #endif // QGSWIDGETWRAPPER_H
T * widget()
Access the widget managed by this wrapper and cast it to a given type Example: QPushButton* pb = wrap...
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the editor widget&#39;s property collection, used for data defined overrides...
This class contains context information for attribute editor widgets.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Q_DECLARE_METATYPE(QModelIndex)
QgsPropertyCollection mPropertyCollection
Data defined property collection.
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the editor widget&#39;s property collection, used for data defined overrides...
#define SIP_SKIP
Definition: qgis_sip.h:119
#define SIP_END
Definition: qgis_sip.h:182
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the editor widget&#39;s property collection, used for data defined overrides.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Property
Data defined properties for different editor widgets.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.