Skip to content

Commit 493bdb1

Browse files
m-kuhnsignedav
authored andcommitted
f
1 parent ae68549 commit 493bdb1

File tree

4 files changed

+75
-9
lines changed

4 files changed

+75
-9
lines changed

python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
************************************************************************/
88

99

10+
1011
class QgsQmlWidgetWrapper : QgsWidgetWrapper
1112
{
1213
%Docstring
@@ -46,6 +47,7 @@ the Free Software Foundation; either version 2 of the License, or *
4647

4748
virtual void setFeature( const QgsFeature &feature );
4849

50+
4951
};
5052

5153
/************************************************************************

src/gui/CMakeLists.txt

+13-9
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,18 @@ SET(QGIS_GUI_MOC_HDRS
733733
processing/qgsprocessingwidgetwrapper.h
734734
processing/qgsprocessingwidgetwrapperimpl.h
735735
)
736+
FIND_PACKAGE(Qt5Qml REQUIRED)
737+
FIND_PACKAGE(Qt5QuickWidgets REQUIRED)
738+
739+
IF(Qt5Qml_FOUND)
740+
ADD_DEFINITIONS(-DWITH_QML)
741+
SET(QGIS_GUI_MOC_HDRS
742+
${QGIS_GUI_MOC_HDRS}
743+
editorwidgets/qgsqmlwidgetwrapper.h
744+
qgsqmlwidget.h
745+
)
746+
ENDIF(Qt5Qml_FOUND)
747+
736748
SET_PROPERTY(GLOBAL PROPERTY QGIS_GUI_MOC_HDRS ${QGIS_GUI_MOC_HDRS})
737749

738750
QT5_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
@@ -839,22 +851,13 @@ SET(QGIS_GUI_HDRS
839851
symbology/qgssymbolwidgetcontext.h
840852
)
841853

842-
Find_Package(Qt5Qml)
843-
844854
IF(Qt5Qml_FOUND)
845-
ADD_DEFINITIONS(-DWITH_QML)
846-
SET(QGIS_GUI_MOC_HDRS
847-
${QGIS_GUI_MOC_HDRS}
848-
editorwidgets/qgsqmlwidgetwrapper.h
849-
qgsqmlwidget.h
850-
)
851855

852856
SET(QGIS_GUI_SRCS
853857
${QGIS_GUI_SRCS}
854858
editorwidgets/qgsqmlwidgetwrapper.cpp
855859
qgsqmlwidget.cpp
856860
)
857-
858861
ENDIF(Qt5Qml_FOUND)
859862

860863
SET_PROPERTY(GLOBAL PROPERTY QGIS_GUI_HDRS ${QGIS_GUI_HDRS})
@@ -1029,6 +1032,7 @@ TARGET_LINK_LIBRARIES(qgis_gui
10291032
${Qt5UiTools_LIBRARIES}
10301033
${QWT_LIBRARY}
10311034
${QSCINTILLA_LIBRARY}
1035+
${Qt5QuickWidgets_LIBRARIES}
10321036
)
10331037

10341038
IF(ENABLE_MODELTEST)

src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,61 @@
1414
* *
1515
***************************************************************************/
1616
#include "qgsqmlwidgetwrapper.h"
17+
#include "qgsmessagelog.h"
18+
#include <QtQuickWidgets/QQuickWidget>
1719

1820
QgsQmlWidgetWrapper::QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent )
1921
: QgsWidgetWrapper( layer, editor, parent )
2022
{
2123

2224
}
25+
26+
bool QgsQmlWidgetWrapper::valid() const
27+
{
28+
return true;
29+
}
30+
31+
QWidget *QgsQmlWidgetWrapper::createWidget( QWidget *parent )
32+
{
33+
return new QQuickWidget( parent );
34+
}
35+
36+
void QgsQmlWidgetWrapper::initWidget( QWidget *editor )
37+
{
38+
QQuickWidget *quickWidget = qobject_cast<QQuickWidget *>( editor );
39+
40+
if ( !quickWidget )
41+
return;
42+
43+
if ( !mQmlFile.open() )
44+
{
45+
QgsMessageLog::logMessage( tr( "Failed to open temporary QML file" ) );
46+
return;
47+
}
48+
49+
QString qmlCode = QStringLiteral(
50+
"import QtQuick 2.0"
51+
"import QtCharts 2.0"
52+
""
53+
"ChartView {"
54+
" width: 600"
55+
" height: 400"
56+
""
57+
" PieSeries {"
58+
" id: pieSeries"
59+
" PieSlice { label: \"outlet 1\"; value: attributes.outlet_1 }"
60+
" PieSlice { label: \"outlet 2\"; value: attributes.outlet_2 }"
61+
" PieSlice { label: \"outlet 3\"; value: attributes.outlet_3 }"
62+
" PieSlice { label: \"outlet 4\"; value: attributes.outlet_4 }"
63+
" }"
64+
"}" );
65+
66+
mQmlFile.write( qmlCode.toUtf8() );
67+
68+
quickWidget->setSource( QUrl::fromLocalFile( mQmlFile.fileName() ) );
69+
}
70+
71+
void QgsQmlWidgetWrapper::setFeature( const QgsFeature &feature )
72+
{
73+
74+
}

src/gui/editorwidgets/qgsqmlwidgetwrapper.h

+8
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
#define QGSQMLWIDGETWRAPPER_H
1818

1919
#include "qgswidgetwrapper.h"
20+
#include "qgis.h"
21+
#include "qgis_gui.h"
22+
2023

2124
class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
2225
{
26+
Q_OBJECT
27+
2328
public:
2429
QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
2530

@@ -32,6 +37,9 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
3237
public slots:
3338

3439
void setFeature( const QgsFeature &feature ) override;
40+
41+
private:
42+
QTemporaryFile mQmlFile;
3543
};
3644

3745
#endif // QGSQMLWIDGETWRAPPER_H

0 commit comments

Comments
 (0)