QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 dot kuhn at gmx 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 = 0, QWidget* parent = 0 );
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( QString key, QVariant defaultVal = QVariant() );
91 
97  const QgsEditorWidgetConfig config();
98 
104  const QgsAttributeEditorContext& context();
105 
113  QgsVectorLayer* layer();
114 
120  static QgsWidgetWrapper* fromWidget( QWidget* widget );
121 
122  protected:
134  virtual QWidget* createWidget( QWidget* parent ) = 0;
135 
141  virtual void initWidget( QWidget* editor );
142 
143  public slots:
150  virtual void setFeature( const QgsFeature& feature ) = 0;
151 
158  virtual void setEnabled( bool enabled );
159 
160  private:
161  QgsAttributeEditorContext mContext;
162  QgsEditorWidgetConfig mConfig;
163  QWidget* mWidget;
164  QWidget* mParent;
165  QgsVectorLayer* mLayer;
166  bool mInitialized;
167 };
168 
169 // We'll use this class inside a QVariant in the widgets properties
171 
172 #endif // QGSWIDGETWRAPPER_H