QGIS API Documentation  2.99.0-Master (37c43df)
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 
25 #include "qgseditorwidgetconfig.h"
27 
39 class GUI_EXPORT QgsWidgetWrapper : public QObject
40 {
41  Q_OBJECT
42  public:
43 
51  explicit QgsWidgetWrapper( QgsVectorLayer* vl, QWidget* editor = nullptr, QWidget* parent = nullptr );
52 
58  QWidget* widget();
59 
66  template <class T>
67  T* widget() { return dynamic_cast<T>( mWidget ); }
68 
74  void setConfig( const QgsEditorWidgetConfig& config );
75 
81  void setContext( const QgsAttributeEditorContext& context );
82 
91  QVariant config( const QString& key, const QVariant& defaultVal = QVariant() ) const;
92 
98  QgsEditorWidgetConfig config() const;
99 
105  const QgsAttributeEditorContext& context() const;
106 
114  QgsVectorLayer* layer() const;
115 
121  static QgsWidgetWrapper* fromWidget( QWidget* widget );
122 
134  virtual bool valid() const = 0;
135 
136  protected:
137 
149  virtual QWidget* createWidget( QWidget* parent ) = 0;
150 
156  virtual void initWidget( QWidget* editor );
157 
158  public slots:
159 
166  virtual void setFeature( const QgsFeature& feature ) = 0;
167 
174  virtual void setEnabled( bool enabled );
175 
176  private:
177  QgsAttributeEditorContext mContext;
178  QgsEditorWidgetConfig mConfig;
179  QWidget* mWidget;
180  QWidget* mParent;
181  QgsVectorLayer* mLayer;
182  bool mInitialized;
183 };
184 
185 // We'll use this class inside a QVariant in the widgets properties
187 
188 #endif // QGSWIDGETWRAPPER_H
T * widget()
Access the widget managed by this wrapper and cast it to a given type Example: QPushButton* pb = wrap...
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:135
QVariantMap QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.