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