QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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:
50  explicit QgsWidgetWrapper( QgsVectorLayer* vl, QWidget* editor = nullptr, QWidget* parent = nullptr );
51 
57  QWidget* widget();
58 
65  template <class T>
66  T* widget() { return dynamic_cast<T>( mWidget ); }
67 
73  void setConfig( const QgsEditorWidgetConfig& config );
74 
80  void setContext( const QgsAttributeEditorContext& context );
81 
90  QVariant config( const QString& key, const QVariant& defaultVal = QVariant() ) const;
91 
97  QgsEditorWidgetConfig config() const;
98 
104  const QgsAttributeEditorContext& context() const;
105 
113  QgsVectorLayer* layer() const;
114 
120  static QgsWidgetWrapper* fromWidget( QWidget* widget );
121 
133  virtual bool valid() const = 0;
134 
135  protected:
147  virtual QWidget* createWidget( QWidget* parent ) = 0;
148 
154  virtual void initWidget( QWidget* editor );
155 
156  public slots:
163  virtual void setFeature( const QgsFeature& feature ) = 0;
164 
171  virtual void setEnabled( bool enabled );
172 
173  private:
174  QgsAttributeEditorContext mContext;
175  QgsEditorWidgetConfig mConfig;
176  QWidget* mWidget;
177  QWidget* mParent;
178  QgsVectorLayer* mLayer;
179  bool mInitialized;
180 };
181 
182 // We'll use this class inside a QVariant in the widgets properties
184 
185 #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:187
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.