QGIS API Documentation  3.6.0-Noosa (5873452)
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 
21 
23 {
24  static QgsPropertiesDefinition properties;
25 
26  if ( properties.isEmpty() )
27  {
28  properties =
29  {
30  { RootPath, QgsPropertyDefinition( "propertyRootPath", QgsPropertyDefinition::DataTypeString, QObject::tr( "Root path" ), QObject::tr( "string of variable length representing root path to attachment" ) ) },
31  { DocumentViewerContent, QgsPropertyDefinition( "documentViewerContent", QgsPropertyDefinition::DataTypeString, QObject::tr( "Document viewer content" ), QObject::tr( "string" ) + "<b>NoContent</b>|<b>Image</b>|<b>Web</b>" ) }
32  };
33  }
34  return properties;
35 }
36 
37 QgsWidgetWrapper::QgsWidgetWrapper( QgsVectorLayer *vl, QWidget *editor, QWidget *parent )
38  : QObject( parent )
39  , mWidget( editor )
40  , mParent( parent )
41  , mLayer( vl )
42  , mInitialized( false )
43 {
44 }
45 
47 {
48  if ( !mWidget )
49  mWidget = createWidget( mParent );
50 
51  if ( !mInitialized )
52  {
53  mWidget->setProperty( "EWV2Wrapper", QVariant::fromValue<QgsWidgetWrapper *>( this ) );
54  initWidget( mWidget );
55  mInitialized = true;
56  }
57 
58  return mWidget;
59 }
60 
61 void QgsWidgetWrapper::setConfig( const QVariantMap &config )
62 {
63  mConfig = config;
64 }
65 
67 {
68  mContext = context;
69  emit contextChanged();
70 }
71 
72 QVariant QgsWidgetWrapper::config( const QString &key, const QVariant &defaultVal ) const
73 {
74  if ( mConfig.contains( key ) )
75  {
76  return mConfig[key];
77  }
78  return defaultVal;
79 }
80 
81 QVariantMap QgsWidgetWrapper::config() const
82 {
83  return mConfig;
84 }
85 
87 {
88  return mContext;
89 }
90 
92 {
93  return mLayer;
94 }
95 
97 {
98  return widget->property( "EWV2Wrapper" ).value<QgsWidgetWrapper *>();
99 }
100 
102 {
103  aboutToSave();
104 }
105 
106 void QgsWidgetWrapper::initWidget( QWidget *editor )
107 {
108  Q_UNUSED( editor )
109 }
110 
111 void QgsWidgetWrapper::setEnabled( bool enabled )
112 {
113  Q_UNUSED( enabled );
114 }
115 
116 void QgsWidgetWrapper::aboutToSave()
117 {
118 
119 }
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the editor widget property definitions.
void contextChanged()
Signal when QgsAttributeEditorContext mContext changed.
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.
QgsWidgetWrapper(QgsVectorLayer *vl, QWidget *editor=nullptr, QWidget *parent=nullptr)
Create a new widget wrapper.
QVariantMap config() const
Returns the whole config.
Root path for external resource.
void setContext(const QgsAttributeEditorContext &context)
Set the context in which this widget is shown.
void notifyAboutToSave()
Notify this widget, that the containing form is about to save and that any pending changes should be ...
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.
Document type for external resource.
static QgsWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
Definition for a property.
Definition: qgsproperty.h:46
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
Property requires a string value.
Definition: qgsproperty.h:91
QWidget * widget()
Access the widget managed by this wrapper.
void setConfig(const QVariantMap &config)
Will set the config of this wrapper to the specified config.
QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.