QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgswidgetwrapper.h
Go to the documentation of this file.
1/***************************************************************************
2 qgswidgetwrapper.h
3 --------------------------------------
4 Date : 14.5.2014
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#ifndef QGSWIDGETWRAPPER_H
17#define QGSWIDGETWRAPPER_H
18
19#include <QObject>
20#include <QMap>
21#include <QVariant>
22
23class QgsVectorLayer;
24
26#include "qgis_gui.h"
27#include "qgis_sip.h"
29
30#ifdef SIP_RUN
31// This is required for the ConvertToSubClassCode to work properly
32// so RTTI for casting is available in the whole module.
33//%ModuleCode
35#include "qgsqmlwidgetwrapper.h"
37//%End
38#endif
39
52class GUI_EXPORT QgsWidgetWrapper : public QObject
53{
54#ifdef SIP_RUN
56 if ( qobject_cast<QgsEditorWidgetWrapper *>( sipCpp ) )
57 sipType = sipType_QgsEditorWidgetWrapper;
58 else if ( qobject_cast<QgsRelationWidgetWrapper *>( sipCpp ) )
59 sipType = sipType_QgsRelationWidgetWrapper;
60 else if ( qobject_cast<QgsQmlWidgetWrapper *>( sipCpp ) )
61 sipType = sipType_QgsQmlWidgetWrapper;
62 else if ( qobject_cast<QgsHtmlWidgetWrapper *>( sipCpp ) )
63 sipType = sipType_QgsHtmlWidgetWrapper;
64 else
65 sipType = 0;
67#endif
68
69 Q_OBJECT
70 public:
71 // *INDENT-OFF*
72
77 {
78 RootPath = 0,
79 DocumentViewerContent,
80 StorageUrl
81 };
82 // *INDENT-ON*
83
87 static const QgsPropertiesDefinition &propertyDefinitions();
88
96 explicit QgsWidgetWrapper( QgsVectorLayer *vl, QWidget *editor = nullptr, QWidget *parent = nullptr );
97
103 QWidget *widget();
104
116 template<class T> SIP_SKIP T *widget() { return dynamic_cast<T>( mWidget ); }
117
123 void setConfig( const QVariantMap &config );
124
130 void setContext( const QgsAttributeEditorContext &context );
131
140 QVariant config( const QString &key, const QVariant &defaultVal = QVariant() ) const;
141
145 QVariantMap config() const;
146
150 const QgsAttributeEditorContext &context() const;
151
155 QgsVectorLayer *layer() const;
156
162 static QgsWidgetWrapper *fromWidget( QWidget *widget );
163
174 virtual bool valid() const = 0;
175
176
184 {
185 return mPropertyCollection;
186 }
187
193 const QgsPropertyCollection &dataDefinedProperties() const { return mPropertyCollection; }
194
201 void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mPropertyCollection = collection; }
202
210 void notifyAboutToSave();
211
212 signals:
213
220
221 protected:
233 virtual QWidget *createWidget( QWidget *parent ) = 0;
234
240 virtual void initWidget( QWidget *editor );
241
244
245 public slots:
246
253 virtual void setFeature( const QgsFeature &feature ) = 0;
254
261 virtual void setEnabled( bool enabled );
262
263 private:
270 virtual void aboutToSave();
271
273 QVariantMap mConfig;
274 QWidget *mWidget = nullptr;
275 QWidget *mParent = nullptr;
276 QgsVectorLayer *mLayer = nullptr;
277 bool mInitialized;
278};
279
280// We'll use this class inside a QVariant in the widgets properties
282
283#endif // QGSWIDGETWRAPPER_H
This class contains context information for attribute editor widgets.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.
virtual void setFeature(const QgsFeature &feature)=0
Is called when the value of the widget needs to be changed.
virtual bool valid() const =0
Returns true if the widget has been properly initialized.
T * widget()
Access the widget managed by this wrapper and cast it to a given type.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the editor widget's property collection, used for data defined overrides.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the editor widget's property collection, used for data defined overrides.
void contextChanged()
Signal when QgsAttributeEditorContext mContext changed.
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the editor widget's property collection, used for data defined overrides.
QgsPropertyCollection mPropertyCollection
Data defined property collection.
Property
Data defined properties for different editor widgets.
virtual QWidget * createWidget(QWidget *parent)=0
This method should create a new widget with the provided parent.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_END
Definition qgis_sip.h:208
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.