QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 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 #include "qgswidgetwrapper.h"
17 #include "qgsvectorlayer.h"
18 
19 #include <QWidget>
20 
21 QgsWidgetWrapper::QgsWidgetWrapper( QgsVectorLayer* vl, QWidget* editor, QWidget* parent )
22  : QObject( parent )
23  , mWidget( editor )
24  , mParent( parent )
25  , mLayer( vl )
26  , mInitialized( false )
27 {
28 }
29 
31 {
32  if ( !mWidget )
34 
35  if ( !mInitialized )
36  {
37  mWidget->setProperty( "EWV2Wrapper", QVariant::fromValue<QgsWidgetWrapper*>( this ) );
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( QString key, QVariant defaultVal )
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 
84 void QgsWidgetWrapper::initWidget( QWidget* editor )
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.
QgsVectorLayer * layer()
Access the QgsVectorLayer, you are working on.
QgsVectorLayer * mLayer
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.
const QgsAttributeEditorContext & context()
Returns information about the context in which this widget is shown.
QgsWidgetWrapper(QgsVectorLayer *vl, QWidget *editor=0, QWidget *parent=0)
Create a new widget wrapper.
const QgsEditorWidgetConfig config()
Returns the whole config.
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.
QgsAttributeEditorContext mContext
QMap< QString, QVariant > QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
QgsEditorWidgetConfig mConfig
QWidget * widget()
Access the widget managed by this wrapper.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.