QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgswidgetwrapper.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswidgetwrapper.cpp
3  --------------------------------------
4  Date : 14.5.2013
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 #include "qgswidgetwrapper.h"
17 #include "qgsvectorlayer.h"
18 
19 #include <QWidget>
20 
22  : QObject( parent )
23  , mWidget( editor )
24  , mParent( parent )
25  , mLayer( vl )
26  , mInitialized( false )
27 {
28 }
29 
31 {
32  if ( !mWidget )
33  mWidget = createWidget( mParent );
34 
35  if ( !mInitialized )
36  {
37  mWidget->setProperty( "EWV2Wrapper", QVariant::fromValue<QgsWidgetWrapper*>( this ) );
38  initWidget( mWidget );
39  mInitialized = true;
40  }
41 
42  return mWidget;
43 }
44 
46 {
47  mConfig = config;
48 }
49 
51 {
52  mContext = context;
53 }
54 
55 QVariant QgsWidgetWrapper::config( const QString& key, const QVariant& defaultVal ) const
56 {
57  if ( mConfig.contains( key ) )
58  {
59  return mConfig[key];
60  }
61  return defaultVal;
62 }
63 
65 {
66  return mConfig;
67 }
68 
70 {
71  return mContext;
72 }
73 
75 {
76  return mLayer;
77 }
78 
80 {
81  return widget->property( "EWV2Wrapper" ).value<QgsWidgetWrapper*>();
82 }
83 
85 {
86  Q_UNUSED( editor )
87 }
88 
89 void QgsWidgetWrapper::setEnabled( bool enabled )
90 {
91  Q_UNUSED( enabled );
92 }
virtual void setEnabled(bool enabled)
Is used to enable or disable the edit functionality of the managed widget.
This class contains context information for attribute editor widgets.
T value() const
QgsWidgetWrapper(QgsVectorLayer *vl, QWidget *editor=nullptr, QWidget *parent=nullptr)
Create a new widget wrapper.
void setContext(const QgsAttributeEditorContext &context)
Set the context in which this widget is shown.
void setConfig(const QgsEditorWidgetConfig &config)
Will set the config of this wrapper to the specified config.
QVariantMap QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
QVariant property(const char *name) const
virtual QWidget * createWidget(QWidget *parent)=0
This method should create a new widget with the provided parent.
virtual void initWidget(QWidget *editor)
This method should initialize the editor widget with runtime data.
static QgsWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
bool setProperty(const char *name, const QVariant &value)
QWidget * widget()
Access the widget managed by this wrapper.
QgsEditorWidgetConfig config() const
Returns the whole config.
QgsVectorLayer * layer() const
Access the QgsVectorLayer, you are working on.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.