QGIS API Documentation 4.3.0-Master (91d4a333d5d)
Loading...
Searching...
No Matches
qgsqmlwidgetwrapper.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsqmlwidgetwrapper.h
3
4 ---------------------
5 begin : 25.6.2018
6 copyright : (C) 2018 by Matthias Kuhn
7 email : matthias@opengis.ch
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSQMLWIDGETWRAPPER_H
17#define QGSQMLWIDGETWRAPPER_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21#include "qgsattributeform.h"
22#include "qgswidgetwrapper.h"
23
24#include <QQuickWidget>
25
26class QgsQmlAttributeFormBridge;
27
33class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
34{
35 Q_OBJECT
36
37 public:
45 QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
46
47 bool valid() const override;
48
49 QWidget *createWidget( QWidget *parent ) override;
50
51 void initWidget( QWidget *editor ) override;
52
54 void reinitWidget();
55
57 void setQmlCode( const QString &qmlCode );
58
59 public slots:
60 void setFeature( const QgsFeature &feature ) override;
61
62 private slots:
64 void setQmlContext();
65
66 private:
67 QTemporaryFile mQmlFile;
68 QString mQmlCode;
69 QQuickWidget *mWidget = nullptr;
70 QgsQmlAttributeFormBridge *mWidgetBridge = nullptr;
71 QgsFeature mFeature;
72 QgsFeature mFormFeature;
73 bool mRequiresFormScope = false;
74};
75
76
77#ifndef SIP_RUN
79
85class QgsQmlExpression : public QObject
86{
87 Q_OBJECT
88
89 public:
91 void setExpressionContext( const QgsExpressionContext &context );
92
94 Q_INVOKABLE QVariant evaluate( const QString &expression ) const;
95
96 private:
97 QgsExpressionContext mExpressionContext;
98};
99
100
106class QgsQmlAttributeFormBridge : public QObject
107{
108 Q_OBJECT
109
111 Q_PROPERTY( QgsVectorLayer *layer READ layer )
112
113
114 Q_PROPERTY( bool editable READ editable NOTIFY editableChanged )
115
116
117 Q_PROPERTY( QgsAttributeEditorContext context READ context NOTIFY contextChanged )
118
119
123 Q_PROPERTY( QgsFeature currentFormFeature READ currentFormFeature NOTIFY currentFormFeatureChanged )
124
125 public:
131 QgsQmlAttributeFormBridge( QgsAttributeForm *form, QObject *parent = nullptr );
132 ~QgsQmlAttributeFormBridge() override = default;
133
135 bool editable() const;
136
138 QgsVectorLayer *layer() const;
139
141 QgsAttributeEditorContext context() const;
142
144 void setContext( const QgsAttributeEditorContext &context );
145
150 QgsFeature currentFormFeature() const;
151
155 Q_INVOKABLE void changeGeometry( const QgsGeometry &geometry );
156
164 Q_INVOKABLE void changeAttribute( const QString &field, const QVariant &value );
165
171 Q_INVOKABLE QVariant attribute( const QString &field );
172
173 signals:
175 void editableChanged();
176
178 void contextChanged();
179
181 void currentFormFeatureChanged();
182
183 private:
184 QgsAttributeForm *mForm = nullptr;
185 QgsAttributeEditorContext mContext;
186};
187
189#endif //SIP_RUN
190
191#endif // QGSQMLWIDGETWRAPPER_H
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
void reinitWidget()
Clears the content and makes new initialization.
void setQmlCode(const QString &qmlCode)
writes the qmlCode into a temporary file
QgsQmlWidgetWrapper(QgsVectorLayer *layer, QWidget *editor, QWidget *parent)
Create a qml widget wrapper.
Represents a vector layer which manages a vector based dataset.
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.
virtual void initWidget(QWidget *editor)
This method should initialize the editor widget with runtime data.
QgsWidgetWrapper(QgsVectorLayer *vl, QWidget *editor=nullptr, QWidget *parent=nullptr)
Create a new widget wrapper.
QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
virtual QWidget * createWidget(QWidget *parent)=0
This method should create a new widget with the provided parent.