This commit is contained in:
Matthias Kuhn 2018-08-03 10:14:00 +02:00 committed by signedav
parent ae68549186
commit 493bdb1bf2
4 changed files with 75 additions and 9 deletions

View File

@ -7,6 +7,7 @@
************************************************************************/
class QgsQmlWidgetWrapper : QgsWidgetWrapper
{
%Docstring
@ -46,6 +47,7 @@ the Free Software Foundation; either version 2 of the License, or *
virtual void setFeature( const QgsFeature &feature );
};
/************************************************************************

View File

@ -733,6 +733,18 @@ SET(QGIS_GUI_MOC_HDRS
processing/qgsprocessingwidgetwrapper.h
processing/qgsprocessingwidgetwrapperimpl.h
)
FIND_PACKAGE(Qt5Qml REQUIRED)
FIND_PACKAGE(Qt5QuickWidgets REQUIRED)
IF(Qt5Qml_FOUND)
ADD_DEFINITIONS(-DWITH_QML)
SET(QGIS_GUI_MOC_HDRS
${QGIS_GUI_MOC_HDRS}
editorwidgets/qgsqmlwidgetwrapper.h
qgsqmlwidget.h
)
ENDIF(Qt5Qml_FOUND)
SET_PROPERTY(GLOBAL PROPERTY QGIS_GUI_MOC_HDRS ${QGIS_GUI_MOC_HDRS})
QT5_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
@ -839,22 +851,13 @@ SET(QGIS_GUI_HDRS
symbology/qgssymbolwidgetcontext.h
)
Find_Package(Qt5Qml)
IF(Qt5Qml_FOUND)
ADD_DEFINITIONS(-DWITH_QML)
SET(QGIS_GUI_MOC_HDRS
${QGIS_GUI_MOC_HDRS}
editorwidgets/qgsqmlwidgetwrapper.h
qgsqmlwidget.h
)
SET(QGIS_GUI_SRCS
${QGIS_GUI_SRCS}
editorwidgets/qgsqmlwidgetwrapper.cpp
qgsqmlwidget.cpp
)
ENDIF(Qt5Qml_FOUND)
SET_PROPERTY(GLOBAL PROPERTY QGIS_GUI_HDRS ${QGIS_GUI_HDRS})
@ -1029,6 +1032,7 @@ TARGET_LINK_LIBRARIES(qgis_gui
${Qt5UiTools_LIBRARIES}
${QWT_LIBRARY}
${QSCINTILLA_LIBRARY}
${Qt5QuickWidgets_LIBRARIES}
)
IF(ENABLE_MODELTEST)

View File

@ -14,9 +14,61 @@
* *
***************************************************************************/
#include "qgsqmlwidgetwrapper.h"
#include "qgsmessagelog.h"
#include <QtQuickWidgets/QQuickWidget>
QgsQmlWidgetWrapper::QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent )
: QgsWidgetWrapper( layer, editor, parent )
{
}
bool QgsQmlWidgetWrapper::valid() const
{
return true;
}
QWidget *QgsQmlWidgetWrapper::createWidget( QWidget *parent )
{
return new QQuickWidget( parent );
}
void QgsQmlWidgetWrapper::initWidget( QWidget *editor )
{
QQuickWidget *quickWidget = qobject_cast<QQuickWidget *>( editor );
if ( !quickWidget )
return;
if ( !mQmlFile.open() )
{
QgsMessageLog::logMessage( tr( "Failed to open temporary QML file" ) );
return;
}
QString qmlCode = QStringLiteral(
"import QtQuick 2.0"
"import QtCharts 2.0"
""
"ChartView {"
" width: 600"
" height: 400"
""
" PieSeries {"
" id: pieSeries"
" PieSlice { label: \"outlet 1\"; value: attributes.outlet_1 }"
" PieSlice { label: \"outlet 2\"; value: attributes.outlet_2 }"
" PieSlice { label: \"outlet 3\"; value: attributes.outlet_3 }"
" PieSlice { label: \"outlet 4\"; value: attributes.outlet_4 }"
" }"
"}" );
mQmlFile.write( qmlCode.toUtf8() );
quickWidget->setSource( QUrl::fromLocalFile( mQmlFile.fileName() ) );
}
void QgsQmlWidgetWrapper::setFeature( const QgsFeature &feature )
{
}

View File

@ -17,9 +17,14 @@
#define QGSQMLWIDGETWRAPPER_H
#include "qgswidgetwrapper.h"
#include "qgis.h"
#include "qgis_gui.h"
class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
{
Q_OBJECT
public:
QgsQmlWidgetWrapper( QgsVectorLayer *layer, QWidget *editor, QWidget *parent );
@ -32,6 +37,9 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
public slots:
void setFeature( const QgsFeature &feature ) override;
private:
QTemporaryFile mQmlFile;
};
#endif // QGSQMLWIDGETWRAPPER_H