QGIS API Documentation  2.99.0-Master (314842d)
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 "qgspropertycollection.h"
28 
40 class GUI_EXPORT QgsWidgetWrapper : public QObject
41 {
42  Q_OBJECT
43  public:
44 
48  enum Property
49  {
50  RootPath = 0,
51  };
52 
57  static const QgsPropertiesDefinition &propertyDefinitions();
58 
66  explicit QgsWidgetWrapper( QgsVectorLayer *vl, QWidget *editor = nullptr, QWidget *parent = nullptr );
67 
73  QWidget *widget();
74 
81  template <class T>
82  T *widget() { return dynamic_cast<T>( mWidget ); }
83 
89  void setConfig( const QVariantMap &config );
90 
96  void setContext( const QgsAttributeEditorContext &context );
97 
106  QVariant config( const QString &key, const QVariant &defaultVal = QVariant() ) const;
107 
113  QVariantMap config() const;
114 
120  const QgsAttributeEditorContext &context() const;
121 
129  QgsVectorLayer *layer() const;
130 
136  static QgsWidgetWrapper *fromWidget( QWidget *widget );
137 
149  virtual bool valid() const = 0;
150 
151 
156  QgsPropertyCollection &dataDefinedProperties() { return mPropertyCollection; }
157 
162  const QgsPropertyCollection &dataDefinedProperties() const { return mPropertyCollection; }
163 
169  void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mPropertyCollection = collection; }
170 
171  protected:
172 
184  virtual QWidget *createWidget( QWidget *parent ) = 0;
185 
191  virtual void initWidget( QWidget *editor );
192 
195 
196  public slots:
197 
204  virtual void setFeature( const QgsFeature &feature ) = 0;
205 
212  virtual void setEnabled( bool enabled );
213 
214  private:
215  QgsAttributeEditorContext mContext;
216  QVariantMap mConfig;
217  QWidget *mWidget = nullptr;
218  QWidget *mParent = nullptr;
219  QgsVectorLayer *mLayer = nullptr;
220  bool mInitialized;
221 };
222 
223 // We'll use this class inside a QVariant in the widgets properties
225 
226 #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.
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:136
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...
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.
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.