QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  { StorageUrl, QgsPropertyDefinition( "storageUrl", QgsPropertyDefinition::DataTypeString, QObject::tr( "Storage Url" ), QObject::tr( "String of variable length representing the URL used to store document with an external storage" ) ) }
33  };
34  }
35  return properties;
36 }
37 
38 QgsWidgetWrapper::QgsWidgetWrapper( QgsVectorLayer *vl, QWidget *editor, QWidget *parent )
39  : QObject( parent )
40  , mWidget( editor )
41  , mParent( parent )
42  , mLayer( vl )
43  , mInitialized( false )
44 {
45 }
46 
48 {
49  if ( !mWidget )
50  mWidget = createWidget( mParent );
51 
52  if ( !mInitialized )
53  {
54  mWidget->setProperty( "EWV2Wrapper", QVariant::fromValue<QgsWidgetWrapper *>( this ) );
55  initWidget( mWidget );
56  mInitialized = true;
57  }
58 
59  return mWidget;
60 }
61 
62 void QgsWidgetWrapper::setConfig( const QVariantMap &config )
63 {
64  mConfig = config;
65 }
66 
68 {
69  mContext = context;
70  emit contextChanged();
71 }
72 
73 QVariant QgsWidgetWrapper::config( const QString &key, const QVariant &defaultVal ) const
74 {
75  if ( mConfig.contains( key ) )
76  {
77  return mConfig[key];
78  }
79  return defaultVal;
80 }
81 
82 QVariantMap QgsWidgetWrapper::config() const
83 {
84  return mConfig;
85 }
86 
88 {
89  return mContext;
90 }
91 
93 {
94  return mLayer;
95 }
96 
98 {
99  return widget->property( "EWV2Wrapper" ).value<QgsWidgetWrapper *>();
100 }
101 
103 {
104  aboutToSave();
105 }
106 
107 void QgsWidgetWrapper::initWidget( QWidget *editor )
108 {
109  Q_UNUSED( editor )
110 }
111 
112 void QgsWidgetWrapper::setEnabled( bool enabled )
113 {
114  Q_UNUSED( enabled )
115 }
116 
117 void QgsWidgetWrapper::aboutToSave()
118 {
119 
120 }
QgsWidgetWrapper::initWidget
virtual void initWidget(QWidget *editor)
This method should initialize the editor widget with runtime data.
Definition: qgswidgetwrapper.cpp:107
QgsWidgetWrapper::DocumentViewerContent
@ DocumentViewerContent
Document type for external resource.
Definition: qgswidgetwrapper.h:79
QgsWidgetWrapper::notifyAboutToSave
void notifyAboutToSave()
Notify this widget, that the containing form is about to save and that any pending changes should be ...
Definition: qgswidgetwrapper.cpp:102
QgsWidgetWrapper
Manages an editor widget Widget and wrapper share the same parent.
Definition: qgswidgetwrapper.h:52
QgsPropertyDefinition::DataTypeString
@ DataTypeString
Property requires a string value.
Definition: qgsproperty.h:92
QgsWidgetWrapper::fromWidget
static QgsWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
Definition: qgswidgetwrapper.cpp:97
QgsWidgetWrapper::RootPath
@ RootPath
Root path for external resource.
Definition: qgswidgetwrapper.h:78
QgsWidgetWrapper::context
const QgsAttributeEditorContext & context() const
Returns information about the context in which this widget is shown.
Definition: qgswidgetwrapper.cpp:87
QgsWidgetWrapper::widget
QWidget * widget()
Access the widget managed by this wrapper.
Definition: qgswidgetwrapper.cpp:47
QgsWidgetWrapper::setEnabled
virtual void setEnabled(bool enabled)
Is used to enable or disable the edit functionality of the managed widget.
Definition: qgswidgetwrapper.cpp:112
QgsWidgetWrapper::contextChanged
void contextChanged()
Signal when QgsAttributeEditorContext mContext changed.
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
QgsWidgetWrapper::layer
QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
Definition: qgswidgetwrapper.cpp:92
QgsWidgetWrapper::StorageUrl
@ StorageUrl
Storage URL for external resource.
Definition: qgswidgetwrapper.h:80
QgsWidgetWrapper::setConfig
void setConfig(const QVariantMap &config)
Will set the config of this wrapper to the specified config.
Definition: qgswidgetwrapper.cpp:62
QgsPropertyDefinition
Definition for a property.
Definition: qgsproperty.h:46
qgsvectorlayer.h
QgsWidgetWrapper::propertyDefinitions
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the editor widget property definitions.
Definition: qgswidgetwrapper.cpp:22
QgsWidgetWrapper::QgsWidgetWrapper
QgsWidgetWrapper(QgsVectorLayer *vl, QWidget *editor=nullptr, QWidget *parent=nullptr)
Create a new widget wrapper.
Definition: qgswidgetwrapper.cpp:38
QgsWidgetWrapper::config
QVariantMap config() const
Returns the whole config.
Definition: qgswidgetwrapper.cpp:82
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
qgswidgetwrapper.h
QgsAttributeEditorContext
This class contains context information for attribute editor widgets. It will be passed to embedded w...
Definition: qgsattributeeditorcontext.h:40
QgsWidgetWrapper::setContext
void setContext(const QgsAttributeEditorContext &context)
Set the context in which this widget is shown.
Definition: qgswidgetwrapper.cpp:67
QgsWidgetWrapper::createWidget
virtual QWidget * createWidget(QWidget *parent)=0
This method should create a new widget with the provided parent.