Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn authored and signedav committed Sep 5, 2018
1 parent ae68549 commit 493bdb1
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 9 deletions.
Expand Up @@ -7,6 +7,7 @@
************************************************************************/



class QgsQmlWidgetWrapper : QgsWidgetWrapper
{
%Docstring
Expand Down Expand Up @@ -46,6 +47,7 @@ the Free Software Foundation; either version 2 of the License, or *

virtual void setFeature( const QgsFeature &feature );


};

/************************************************************************
Expand Down
22 changes: 13 additions & 9 deletions src/gui/CMakeLists.txt
Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -1029,6 +1032,7 @@ TARGET_LINK_LIBRARIES(qgis_gui
${Qt5UiTools_LIBRARIES}
${QWT_LIBRARY}
${QSCINTILLA_LIBRARY}
${Qt5QuickWidgets_LIBRARIES}
)

IF(ENABLE_MODELTEST)
Expand Down
52 changes: 52 additions & 0 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp
Expand Up @@ -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 )
{

}
8 changes: 8 additions & 0 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.h
Expand Up @@ -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 );

Expand All @@ -32,6 +37,9 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
public slots:

void setFeature( const QgsFeature &feature ) override;

private:
QTemporaryFile mQmlFile;
};

#endif // QGSQMLWIDGETWRAPPER_H

0 comments on commit 493bdb1

Please sign in to comment.