From 2cd23faa1fe1ae68de64b21c89e4a78cc289dc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Mon, 9 Sep 2013 14:01:45 +0300 Subject: QML support for surface added Task-number: QTRD-2253 - incomplete (as is surface itself) - documentation incomplete - example needs better data Change-Id: I87063925749448c6cad2f1b529f2669514fb1cb9 Reviewed-by: Miikka Heikkinen --- examples/examples.pro | 1 + examples/qmlbarchart/doc/src/qmlbarchart.qdoc | 2 +- examples/qmlscatter/doc/src/qmlscatter.qdoc | 2 +- examples/qmlsurface/doc/src/qmlsurface.qdoc | 29 +++ examples/qmlsurface/main.cpp | 45 ++++ examples/qmlsurface/qml/qmlsurface/button.qml | 59 +++++ examples/qmlsurface/qml/qmlsurface/data.qml | 58 +++++ examples/qmlsurface/qml/qmlsurface/main.qml | 92 +++++++ examples/qmlsurface/qmlsurface.desktop | 11 + examples/qmlsurface/qmlsurface.pro | 22 ++ examples/qmlsurface/qmlsurface.qrc | 7 + examples/qmlsurface/qmlsurface64.png | Bin 0 -> 3400 bytes .../qtquick2applicationviewer.cpp | 81 ++++++ .../qtquick2applicationviewer.h | 33 +++ .../qtquick2applicationviewer.pri | 170 ++++++++++++ src/datavis3d/data/data.pri | 12 +- src/datavis3d/data/qabstractdatamapping.h | 1 + .../data/qitemmodelsurfacedatamapping.cpp | 223 ++++++++++++++++ src/datavis3d/data/qitemmodelsurfacedatamapping.h | 76 ++++++ .../data/qitemmodelsurfacedatamapping_p.h | 58 +++++ src/datavis3d/data/qitemmodelsurfacedataproxy.cpp | 161 ++++++++++++ src/datavis3d/data/qitemmodelsurfacedataproxy.h | 62 +++++ src/datavis3d/data/qitemmodelsurfacedataproxy_p.h | 58 +++++ src/datavis3d/data/surfaceitemmodelhandler.cpp | 94 +++++++ src/datavis3d/data/surfaceitemmodelhandler_p.h | 52 ++++ src/datavis3dqml2/datavis3dqml2.pro | 8 +- src/datavis3dqml2/datavis3dqml2_plugin.cpp | 13 +- src/datavis3dqml2/datavis3dqml2_plugin.h | 13 +- src/datavis3dqml2/declarativesurface.cpp | 288 +++++++++++++++++++++ src/datavis3dqml2/declarativesurface_p.h | 156 +++++++++++ src/datavis3dqml2/declarativesurfacerenderer.cpp | 87 +++++++ src/datavis3dqml2/declarativesurfacerenderer_p.h | 65 +++++ 32 files changed, 2027 insertions(+), 12 deletions(-) create mode 100644 examples/qmlsurface/doc/src/qmlsurface.qdoc create mode 100644 examples/qmlsurface/main.cpp create mode 100644 examples/qmlsurface/qml/qmlsurface/button.qml create mode 100644 examples/qmlsurface/qml/qmlsurface/data.qml create mode 100644 examples/qmlsurface/qml/qmlsurface/main.qml create mode 100644 examples/qmlsurface/qmlsurface.desktop create mode 100644 examples/qmlsurface/qmlsurface.pro create mode 100644 examples/qmlsurface/qmlsurface.qrc create mode 100644 examples/qmlsurface/qmlsurface64.png create mode 100644 examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.cpp create mode 100644 examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.h create mode 100644 examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.pri create mode 100644 src/datavis3d/data/qitemmodelsurfacedatamapping.cpp create mode 100644 src/datavis3d/data/qitemmodelsurfacedatamapping.h create mode 100644 src/datavis3d/data/qitemmodelsurfacedatamapping_p.h create mode 100644 src/datavis3d/data/qitemmodelsurfacedataproxy.cpp create mode 100644 src/datavis3d/data/qitemmodelsurfacedataproxy.h create mode 100644 src/datavis3d/data/qitemmodelsurfacedataproxy_p.h create mode 100644 src/datavis3d/data/surfaceitemmodelhandler.cpp create mode 100644 src/datavis3d/data/surfaceitemmodelhandler_p.h create mode 100644 src/datavis3dqml2/declarativesurface.cpp create mode 100644 src/datavis3dqml2/declarativesurface_p.h create mode 100644 src/datavis3dqml2/declarativesurfacerenderer.cpp create mode 100644 src/datavis3dqml2/declarativesurfacerenderer_p.h diff --git a/examples/examples.pro b/examples/examples.pro index 41cccfc1..46ed44e5 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -4,6 +4,7 @@ SUBDIRS += barchart \ widget \ qmlbarchart \ qmlscatter \ + qmlsurface \ surfacechart \ scatterchart diff --git a/examples/qmlbarchart/doc/src/qmlbarchart.qdoc b/examples/qmlbarchart/doc/src/qmlbarchart.qdoc index becc5d8b..091d4b77 100644 --- a/examples/qmlbarchart/doc/src/qmlbarchart.qdoc +++ b/examples/qmlbarchart/doc/src/qmlbarchart.qdoc @@ -20,7 +20,7 @@ \example qmlbarchart \title Qt Quick 2 Barchart Example - The Qt Quick 2 barchart example shows how to make a simple 3D bar chart using Q3DBars using Qt + The Qt Quick 2 barchart example shows how to make a simple 3D bar chart using Q3DBars and Qt Quick 2. \image qmlbarchart-example.png diff --git a/examples/qmlscatter/doc/src/qmlscatter.qdoc b/examples/qmlscatter/doc/src/qmlscatter.qdoc index d52798c2..4c1d8c2f 100644 --- a/examples/qmlscatter/doc/src/qmlscatter.qdoc +++ b/examples/qmlscatter/doc/src/qmlscatter.qdoc @@ -21,7 +21,7 @@ \title Qt Quick 2 Scatter Example The Qt Quick 2 scatter example shows how to make a simple scatter chart visualization using - Q3DScatter using Qt Quick 2. + Q3DScatter and Qt Quick 2. \image qmlscatter-example.png diff --git a/examples/qmlsurface/doc/src/qmlsurface.qdoc b/examples/qmlsurface/doc/src/qmlsurface.qdoc new file mode 100644 index 00000000..23a5a67d --- /dev/null +++ b/examples/qmlsurface/doc/src/qmlsurface.qdoc @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +/*! + \example qmlsurface + \title Qt Quick 2 Surface Example + + The Qt Quick 2 surface example shows how to make a simple 3D surface plot using Q3DSurface with + Qt Quick 2. + + \image qmlsurface-example.png + + TODO +*/ diff --git a/examples/qmlsurface/main.cpp b/examples/qmlsurface/main.cpp new file mode 100644 index 00000000..b58e66f8 --- /dev/null +++ b/examples/qmlsurface/main.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include +#include "qtquick2applicationviewer.h" +#ifdef Q_OS_ANDROID +#include +#include +#endif +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QtQuick2ApplicationViewer viewer; +#ifdef Q_OS_ANDROID + viewer.addImportPath(QString::fromLatin1("assets:/qml")); + viewer.engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), + QString::fromLatin1("lib"))); +#else + viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), + QString::fromLatin1("qml"))); +#endif + viewer.setSource(QUrl("qrc:/qml/main.qml")); + viewer.setResizeMode(QQuickView::SizeRootObjectToView); + viewer.show(); + + return app.exec(); +} diff --git a/examples/qmlsurface/qml/qmlsurface/button.qml b/examples/qmlsurface/qml/qmlsurface/button.qml new file mode 100644 index 00000000..75032c39 --- /dev/null +++ b/examples/qmlsurface/qml/qmlsurface/button.qml @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +import QtQuick 2.1 + +Item { + id: button + + property alias text: buttonText.text + property alias color: buttonRectangle.color + property alias radius: buttonRectangle.radius + + property color defaultColor: "steelblue" + property color pressedColor: "lightsteelblue" + property color borderColor: "darkblue" + + signal clicked + + height: 75 + + Rectangle { + id: buttonRectangle + width: parent.width + height: parent.height + color: defaultColor + radius: 5 + border.color: borderColor + + Text { + id: buttonText + wrapMode: Text.WordWrap + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + anchors.fill: parent + } + + MouseArea { + anchors.fill: parent + onPressed: buttonRectangle.color = pressedColor + onReleased: buttonRectangle.color = defaultColor + onClicked: button.clicked() + } + } +} diff --git a/examples/qmlsurface/qml/qmlsurface/data.qml b/examples/qmlsurface/qml/qmlsurface/data.qml new file mode 100644 index 00000000..c1601e71 --- /dev/null +++ b/examples/qmlsurface/qml/qmlsurface/data.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +import QtQuick 2.1 +import com.digia.QtDataVis3D 1.0 + +Item { + property alias mapping: surfaceMapping + property alias model: dataModel + property alias proxy: modelProxy + + SurfaceDataMapping { + id: surfaceMapping + rowRole: "year" + columnRole: "month" + valueRole: "expenses" + rowCategories: ["2000", "2001", "2002", "2003"] + columnCategories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] + } + + ItemModelSurfaceDataProxy { + id: modelProxy + activeMapping: surfaceMapping + itemModel: dataModel + } + + ListModel { + id: dataModel + ListElement{ year: "2000"; month: "Jan"; expenses: "3"; } + ListElement{ year: "2000"; month: "Feb"; expenses: "8"; } + ListElement{ year: "2000"; month: "Mar"; expenses: "10"; } + ListElement{ year: "2000"; month: "Apr"; expenses: "12"; } + ListElement{ year: "2000"; month: "May"; expenses: "10"; } + ListElement{ year: "2000"; month: "Jun"; expenses: "5"; } + ListElement{ year: "2000"; month: "Jul"; expenses: "1"; } + ListElement{ year: "2000"; month: "Aug"; expenses: "7"; } + ListElement{ year: "2000"; month: "Sep"; expenses: "4"; } + ListElement{ year: "2000"; month: "Oct"; expenses: "22"; } + ListElement{ year: "2000"; month: "Nov"; expenses: "16"; } + ListElement{ year: "2000"; month: "Dec"; expenses: "2"; } + } +} diff --git a/examples/qmlsurface/qml/qmlsurface/main.qml b/examples/qmlsurface/qml/qmlsurface/main.qml new file mode 100644 index 00000000..b5b0cc87 --- /dev/null +++ b/examples/qmlsurface/qml/qmlsurface/main.qml @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 +import com.digia.QtDataVis3D 1.0 +import "." + +Item { + id: mainview + width: 1280 + height: 1024 + visible: true + + Data { + id: surfaceData + } + + Item { + id: surfaceView + width: mainview.width - surfaceGridToggle.width + height: mainview.height + anchors.right: mainview.right; + + Surface3D { + id: surfaceplot + width: surfaceView.width + height: surfaceView.height + //shadowQuality: Surface3D.ShadowMedium + font.pointSize: 35 + cameraPreset: Surface3D.PresetIsometricLeft + itemLabelFormat: "X:@xLabel Y:@yLabel Z:@zLabel" + dataProxy: surfaceData.proxy +// axisX.segmentCount: 4 +// axisX.subSegmentCount: 1 +// axisX.labelFormat: "%.2f" +// axisZ.segmentCount: 1 +// axisZ.subSegmentCount: 1 +// axisZ.labelFormat: "%.2f" +// axisY.segmentCount: 1 +// axisY.subSegmentCount: 1 +// axisY.labelFormat: "%.2f" + } + } + + Button { + id: surfaceGridToggle + anchors.left: parent.left + width: 200 + text: "Hide Surface Grid" + onClicked: { + if (surfaceplot.surfaceGrid == false) { + surfaceplot.surfaceGrid = true; + text = "Hide Surface Grid" + } else { + surfaceplot.surfaceGrid = false; + text = "Show Surface Grid" + } + } + } + + Button { + id: smoothSurfaceToggle + anchors.top: surfaceGridToggle.bottom + width: surfaceGridToggle.width + text: "Show Smooth" + onClicked: { + if (surfaceplot.smoothSurface == true) { + surfaceplot.smoothSurface = false; + text = "Show Smooth" + } else { + surfaceplot.smoothSurface = true; + text = "Show Flat" + } + } + } +} diff --git a/examples/qmlsurface/qmlsurface.desktop b/examples/qmlsurface/qmlsurface.desktop new file mode 100644 index 00000000..66dd0a72 --- /dev/null +++ b/examples/qmlsurface/qmlsurface.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Encoding=UTF-8 +Version=1.0 +Type=Application +Terminal=false +Name=qmlsurface +Exec=/opt/qmlsurface/bin/qmlsurface +Icon=qmlsurface64 +X-Window-Icon= +X-HildonDesk-ShowInToolbar=true +X-Osso-Type=application/x-executable diff --git a/examples/qmlsurface/qmlsurface.pro b/examples/qmlsurface/qmlsurface.pro new file mode 100644 index 00000000..251619cf --- /dev/null +++ b/examples/qmlsurface/qmlsurface.pro @@ -0,0 +1,22 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +QT += widgets + +# Add more folders to ship with the application, here +folder_01.source = qml/qmlsurface +folder_01.target = qml +DEPLOYMENTFOLDERS = folder_01 + +# Additional import path used to resolve QML modules in Creator's code model +QML_IMPORT_PATH = + +# The .cpp file which was generated for your project. Feel free to hack it. +SOURCES += main.cpp + +# Please do not modify the following two lines. Required for deployment. +include(qtquick2applicationviewer/qtquick2applicationviewer.pri) +qtcAddDeployment() + +RESOURCES += qmlsurface.qrc diff --git a/examples/qmlsurface/qmlsurface.qrc b/examples/qmlsurface/qmlsurface.qrc new file mode 100644 index 00000000..87883d07 --- /dev/null +++ b/examples/qmlsurface/qmlsurface.qrc @@ -0,0 +1,7 @@ + + + qml/qmlsurface/main.qml + qml/qmlsurface/button.qml + qml/qmlsurface/data.qml + + diff --git a/examples/qmlsurface/qmlsurface64.png b/examples/qmlsurface/qmlsurface64.png new file mode 100644 index 00000000..707d5c4e Binary files /dev/null and b/examples/qmlsurface/qmlsurface64.png differ diff --git a/examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.cpp b/examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.cpp new file mode 100644 index 00000000..10709d7a --- /dev/null +++ b/examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.cpp @@ -0,0 +1,81 @@ +// checksum 0x4f6f version 0x90005 +/* + This file was generated by the Qt Quick 2 Application wizard of Qt Creator. + QtQuick2ApplicationViewer is a convenience class containing mobile device specific + code such as screen orientation handling. Also QML paths and debugging are + handled here. + It is recommended not to modify this file, since newer versions of Qt Creator + may offer an updated version of it. +*/ + +#include "qtquick2applicationviewer.h" + +#include +#include +#include + +class QtQuick2ApplicationViewerPrivate +{ + QString mainQmlFile; + friend class QtQuick2ApplicationViewer; + static QString adjustPath(const QString &path); +}; + +QString QtQuick2ApplicationViewerPrivate::adjustPath(const QString &path) +{ +#if defined(Q_OS_MAC) + if (!QDir::isAbsolutePath(path)) + return QString::fromLatin1("%1/../Resources/%2") + .arg(QCoreApplication::applicationDirPath(), path); +#elif defined(Q_OS_BLACKBERRY) + if (!QDir::isAbsolutePath(path)) + return QString::fromLatin1("app/native/%1").arg(path); +#elif !defined(Q_OS_ANDROID) + QString pathInInstallDir = + QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path); + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; + pathInInstallDir = + QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path); + if (QFileInfo(pathInInstallDir).exists()) + return pathInInstallDir; +#endif + return path; +} + +QtQuick2ApplicationViewer::QtQuick2ApplicationViewer(QWindow *parent) + : QQuickView(parent) + , d(new QtQuick2ApplicationViewerPrivate()) +{ + connect(engine(), SIGNAL(quit()), SLOT(close())); + setResizeMode(QQuickView::SizeRootObjectToView); +} + +QtQuick2ApplicationViewer::~QtQuick2ApplicationViewer() +{ + delete d; +} + +void QtQuick2ApplicationViewer::setMainQmlFile(const QString &file) +{ + d->mainQmlFile = QtQuick2ApplicationViewerPrivate::adjustPath(file); +#ifdef Q_OS_ANDROID + setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile)); +#else + setSource(QUrl::fromLocalFile(d->mainQmlFile)); +#endif +} + +void QtQuick2ApplicationViewer::addImportPath(const QString &path) +{ + engine()->addImportPath(QtQuick2ApplicationViewerPrivate::adjustPath(path)); +} + +void QtQuick2ApplicationViewer::showExpanded() +{ +#if defined(Q_WS_SIMULATOR) || defined(Q_OS_QNX) + showFullScreen(); +#else + show(); +#endif +} diff --git a/examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.h b/examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.h new file mode 100644 index 00000000..cf66f140 --- /dev/null +++ b/examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.h @@ -0,0 +1,33 @@ +// checksum 0xfde6 version 0x90005 +/* + This file was generated by the Qt Quick 2 Application wizard of Qt Creator. + QtQuick2ApplicationViewer is a convenience class containing mobile device specific + code such as screen orientation handling. Also QML paths and debugging are + handled here. + It is recommended not to modify this file, since newer versions of Qt Creator + may offer an updated version of it. +*/ + +#ifndef QTQUICK2APPLICATIONVIEWER_H +#define QTQUICK2APPLICATIONVIEWER_H + +#include + +class QtQuick2ApplicationViewer : public QQuickView +{ + Q_OBJECT + +public: + explicit QtQuick2ApplicationViewer(QWindow *parent = 0); + virtual ~QtQuick2ApplicationViewer(); + + void setMainQmlFile(const QString &file); + void addImportPath(const QString &path); + + void showExpanded(); + +private: + class QtQuick2ApplicationViewerPrivate *d; +}; + +#endif // QTQUICK2APPLICATIONVIEWER_H diff --git a/examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.pri b/examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.pri new file mode 100644 index 00000000..a071e63d --- /dev/null +++ b/examples/qmlsurface/qtquick2applicationviewer/qtquick2applicationviewer.pri @@ -0,0 +1,170 @@ +# checksum 0x7b0d version 0x90005 +# This file was generated by the Qt Quick 2 Application wizard of Qt Creator. +# The code below adds the QtQuick2ApplicationViewer to the project and handles +# the activation of QML debugging. +# It is recommended not to modify this file, since newer versions of Qt Creator +# may offer an updated version of it. + +QT += qml quick + +SOURCES += $$PWD/qtquick2applicationviewer.cpp +HEADERS += $$PWD/qtquick2applicationviewer.h +INCLUDEPATH += $$PWD +# This file was generated by an application wizard of Qt Creator. +# The code below handles deployment to Android and Maemo, aswell as copying +# of the application data to shadow build directories on desktop. +# It is recommended not to modify this file, since newer versions of Qt Creator +# may offer an updated version of it. + +defineTest(qtcAddDeployment) { +for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + greaterThan(QT_MAJOR_VERSION, 4) { + itemsources = $${item}.files + } else { + itemsources = $${item}.sources + } + $$itemsources = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath= $$eval($${deploymentfolder}.target) + export($$itemsources) + export($$itempath) + DEPLOYMENT += $$item +} + +MAINPROFILEPWD = $$PWD + +android-no-sdk { + for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + itemfiles = $${item}.files + $$itemfiles = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) + export($$itemfiles) + export($$itempath) + INSTALLS += $$item + } + + target.path = /data/user/qt + + export(target.path) + INSTALLS += target +} else:android { + for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + itemfiles = $${item}.files + $$itemfiles = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath = /assets/$$eval($${deploymentfolder}.target) + export($$itemfiles) + export($$itempath) + INSTALLS += $$item + } + INSTALLS += target +} else:win32 { + copyCommand = + for(deploymentfolder, DEPLOYMENTFOLDERS) { + source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) + source = $$replace(source, /, \\) + sourcePathSegments = $$split(source, \\) + target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) + target = $$replace(target, /, \\) + target ~= s,\\\\\\.?\\\\,\\, + !isEqual(source,$$target) { + !isEmpty(copyCommand):copyCommand += && + isEqual(QMAKE_DIR_SEP, \\) { + copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" + } else { + source = $$replace(source, \\\\, /) + target = $$OUT_PWD/$$eval($${deploymentfolder}.target) + target = $$replace(target, \\\\, /) + copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" + } + } + } + !isEmpty(copyCommand) { + copyCommand = @echo Copying application data... && $$copyCommand + copydeploymentfolders.commands = $$copyCommand + first.depends = $(first) copydeploymentfolders + export(first.depends) + export(copydeploymentfolders.commands) + QMAKE_EXTRA_TARGETS += first copydeploymentfolders + } +} else:unix { + maemo5 { + desktopfile.files = $${TARGET}.desktop + desktopfile.path = /usr/share/applications/hildon + icon.files = $${TARGET}64.png + icon.path = /usr/share/icons/hicolor/64x64/apps + } else:!isEmpty(MEEGO_VERSION_MAJOR) { + desktopfile.files = $${TARGET}_harmattan.desktop + desktopfile.path = /usr/share/applications + icon.files = $${TARGET}80.png + icon.path = /usr/share/icons/hicolor/80x80/apps + } else { # Assumed to be a Desktop Unix + copyCommand = + for(deploymentfolder, DEPLOYMENTFOLDERS) { + source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) + source = $$replace(source, \\\\, /) + macx { + target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) + } else { + target = $$OUT_PWD/$$eval($${deploymentfolder}.target) + } + target = $$replace(target, \\\\, /) + sourcePathSegments = $$split(source, /) + targetFullPath = $$target/$$last(sourcePathSegments) + targetFullPath ~= s,/\\.?/,/, + !isEqual(source,$$targetFullPath) { + !isEmpty(copyCommand):copyCommand += && + copyCommand += $(MKDIR) \"$$target\" + copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" + } + } + !isEmpty(copyCommand) { + copyCommand = @echo Copying application data... && $$copyCommand + copydeploymentfolders.commands = $$copyCommand + first.depends = $(first) copydeploymentfolders + export(first.depends) + export(copydeploymentfolders.commands) + QMAKE_EXTRA_TARGETS += first copydeploymentfolders + } + } + !isEmpty(target.path) { + installPrefix = $${target.path} + } else { + installPrefix = /opt/$${TARGET} + } + for(deploymentfolder, DEPLOYMENTFOLDERS) { + item = item$${deploymentfolder} + itemfiles = $${item}.files + $$itemfiles = $$eval($${deploymentfolder}.source) + itempath = $${item}.path + $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) + export($$itemfiles) + export($$itempath) + INSTALLS += $$item + } + + !isEmpty(desktopfile.path) { + export(icon.files) + export(icon.path) + export(desktopfile.files) + export(desktopfile.path) + INSTALLS += icon desktopfile + } + + isEmpty(target.path) { + target.path = $${installPrefix}/bin + export(target.path) + } + INSTALLS += target +} + +export (ICON) +export (INSTALLS) +export (DEPLOYMENT) +export (LIBS) +export (QMAKE_EXTRA_TARGETS) +} diff --git a/src/datavis3d/data/data.pri b/src/datavis3d/data/data.pri index da5fa477..6571aacc 100644 --- a/src/datavis3d/data/data.pri +++ b/src/datavis3d/data/data.pri @@ -27,7 +27,12 @@ HEADERS += \ $$PWD/qabstractdatamapping_p.h \ $$PWD/scatteritemmodelhandler_p.h \ $$PWD/qsurfacedataproxy.h \ - $$PWD/qsurfacedataproxy_p.h + $$PWD/qsurfacedataproxy_p.h \ + $$PWD/qitemmodelsurfacedatamapping.h \ + $$PWD/qitemmodelsurfacedatamapping_p.h \ + $$PWD/qitemmodelsurfacedataproxy.h \ + $$PWD/qitemmodelsurfacedataproxy_p.h \ + $$PWD/surfaceitemmodelhandler_p.h SOURCES += \ $$PWD/labelitem.cpp \ @@ -47,4 +52,7 @@ SOURCES += \ $$PWD/baritemmodelhandler.cpp \ $$PWD/qabstractdatamapping.cpp \ $$PWD/scatteritemmodelhandler.cpp \ - $$PWD/qsurfacedataproxy.cpp + $$PWD/qsurfacedataproxy.cpp \ + $$PWD/qitemmodelsurfacedatamapping.cpp \ + $$PWD/qitemmodelsurfacedataproxy.cpp \ + $$PWD/surfaceitemmodelhandler.cpp diff --git a/src/datavis3d/data/qabstractdatamapping.h b/src/datavis3d/data/qabstractdatamapping.h index 7f91c7ae..8e1f3b2a 100644 --- a/src/datavis3d/data/qabstractdatamapping.h +++ b/src/datavis3d/data/qabstractdatamapping.h @@ -44,6 +44,7 @@ private: friend class QItemModelBarDataMapping; friend class QItemModelScatterDataMapping; + friend class QItemModelSurfaceDataMapping; }; diff --git a/src/datavis3d/data/qitemmodelsurfacedatamapping.cpp b/src/datavis3d/data/qitemmodelsurfacedatamapping.cpp new file mode 100644 index 00000000..2122a570 --- /dev/null +++ b/src/datavis3d/data/qitemmodelsurfacedatamapping.cpp @@ -0,0 +1,223 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "qitemmodelsurfacedatamapping_p.h" + +QT_DATAVIS3D_BEGIN_NAMESPACE + +/*! + * \class QItemModelSurfaceDataMapping + * \inmodule QtDataVis3D + * \brief Data model mapping for Q3DSurface. + * \since 1.0.0 + * + * DOCUMENTATION GOES HERE + * + * \sa QItemModelSurfaceDataProxy + */ + +/*! + * Constructs QItemModelSurfaceDataMapping with the given \a parent. + */ +QItemModelSurfaceDataMapping::QItemModelSurfaceDataMapping(QObject *parent) + : QAbstractDataMapping(new QItemModelSurfaceDataMappingPrivate(this), parent) +{ +} + +/*! + * Constructs QItemModelSurfaceDataMapping with \a valueRole and the given \a parent. + */ +QItemModelSurfaceDataMapping::QItemModelSurfaceDataMapping(const QString &valueRole, QObject *parent) + : QAbstractDataMapping(new QItemModelSurfaceDataMappingPrivate(this), parent) +{ + dptr()->m_valueRole = valueRole; +} + +/*! + * Constructs QItemModelSurfaceDataMapping with \a rowRole, \a columnRole, \a valueRole, + * \a rowCategories, \a columnCategories and the given \a parent. + */ +QItemModelSurfaceDataMapping::QItemModelSurfaceDataMapping(const QString &rowRole, + const QString &columnRole, + const QString &valueRole, + const QStringList &rowCategories, + const QStringList &columnCategories, + QObject *parent) + : QAbstractDataMapping(new QItemModelSurfaceDataMappingPrivate(this), parent) +{ + dptr()->m_rowRole = rowRole; + dptr()->m_columnRole = columnRole; + dptr()->m_valueRole = valueRole; + dptr()->m_rowCategories = rowCategories; + dptr()->m_columnCategories = columnCategories; +} + +/*! + * Destroys QItemModelSurfaceDataMapping. + */ +QItemModelSurfaceDataMapping::~QItemModelSurfaceDataMapping() +{ +} + +/*! + * \property QItemModelSurfaceDataMapping::rowRole + * + * Defines the row role for the mapping. + */ +void QItemModelSurfaceDataMapping::setRowRole(const QString &role) +{ + dptr()->m_rowRole = role; + emit mappingChanged(); +} + +QString QItemModelSurfaceDataMapping::rowRole() const +{ + return dptrc()->m_rowRole; +} + +/*! + * \property QItemModelSurfaceDataMapping::columnRole + * + * Defines the column role for the mapping. + */ +void QItemModelSurfaceDataMapping::setColumnRole(const QString &role) +{ + dptr()->m_columnRole = role; + emit mappingChanged(); +} + +QString QItemModelSurfaceDataMapping::columnRole() const +{ + return dptrc()->m_columnRole; +} + +/*! + * \property QItemModelSurfaceDataMapping::valueRole + * + * Defines the value role for the mapping. + */ +void QItemModelSurfaceDataMapping::setValueRole(const QString &role) +{ + dptr()->m_valueRole = role; + emit mappingChanged(); +} + +QString QItemModelSurfaceDataMapping::valueRole() const +{ + return dptrc()->m_valueRole; +} + +/*! + * \property QItemModelSurfaceDataMapping::rowCategories + * + * Defines the row categories for the mapping. + */ +void QItemModelSurfaceDataMapping::setRowCategories(const QStringList &categories) +{ + dptr()->m_rowCategories = categories; + emit mappingChanged(); +} + +QStringList QItemModelSurfaceDataMapping::rowCategories() const +{ + return dptrc()->m_rowCategories; +} + +/*! + * \property QItemModelSurfaceDataMapping::columnCategories + * + * Defines the column categories for the mapping. + */ +void QItemModelSurfaceDataMapping::setColumnCategories(const QStringList &categories) +{ + dptr()->m_columnCategories = categories; + emit mappingChanged(); +} + +QStringList QItemModelSurfaceDataMapping::columnCategories() const +{ + return dptrc()->m_columnCategories; +} + +/*! + * Changes \a rowRole, \a columnRole, \a valueRole, \a rowCategories and \a columnCategories to the + * mapping. + */ +void QItemModelSurfaceDataMapping::remap(const QString &rowRole, + const QString &columnRole, + const QString &valueRole, + const QStringList &rowCategories, + const QStringList &columnCategories) +{ + dptr()->m_rowRole = rowRole; + dptr()->m_columnRole = columnRole; + dptr()->m_valueRole = valueRole; + dptr()->m_rowCategories = rowCategories; + dptr()->m_columnCategories = columnCategories; + + emit mappingChanged(); +} + +/*! + * /return index of the specified \a category in row categories list. + * If the category is not found, -1 is returned. + */ +int QItemModelSurfaceDataMapping::rowCategoryIndex(const QString &category) +{ + return dptr()->m_rowCategories.indexOf(category); +} + +/*! + * /return index of the specified \a category in column categories list. + * If the category is not found, -1 is returned. + */ +int QItemModelSurfaceDataMapping::columnCategoryIndex(const QString &category) +{ + return dptr()->m_columnCategories.indexOf(category); +} + +/*! + * \internal + */ +QItemModelSurfaceDataMappingPrivate *QItemModelSurfaceDataMapping::dptr() +{ + return static_cast(d_ptr.data()); +} + +/*! + * \internal + */ +const QItemModelSurfaceDataMappingPrivate *QItemModelSurfaceDataMapping::dptrc() const +{ + return static_cast(d_ptr.data()); +} + +// QItemModelSurfaceDataMappingPrivate + +QItemModelSurfaceDataMappingPrivate::QItemModelSurfaceDataMappingPrivate(QItemModelSurfaceDataMapping *q) + : QAbstractDataMappingPrivate(q, QAbstractDataProxy::DataTypeSurface) +{ +} + +QItemModelSurfaceDataMappingPrivate::~QItemModelSurfaceDataMappingPrivate() +{ +} + + +QT_DATAVIS3D_END_NAMESPACE + diff --git a/src/datavis3d/data/qitemmodelsurfacedatamapping.h b/src/datavis3d/data/qitemmodelsurfacedatamapping.h new file mode 100644 index 00000000..ff16f296 --- /dev/null +++ b/src/datavis3d/data/qitemmodelsurfacedatamapping.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#ifndef QITEMMODELSURFACEDATAMAPPING_H +#define QITEMMODELSURFACEDATAMAPPING_H + +#include +#include +#include + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class QItemModelSurfaceDataMappingPrivate; + +class QT_DATAVIS3D_EXPORT QItemModelSurfaceDataMapping : public QAbstractDataMapping +{ + Q_OBJECT + Q_PROPERTY(QString rowRole READ rowRole WRITE setRowRole) + Q_PROPERTY(QString columnRole READ columnRole WRITE setColumnRole) + Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole) + Q_PROPERTY(QStringList rowCategories READ rowCategories WRITE setRowCategories) + Q_PROPERTY(QStringList columnCategories READ columnCategories WRITE setColumnCategories) + +public: + explicit QItemModelSurfaceDataMapping(QObject *parent = 0); + QItemModelSurfaceDataMapping(const QString &valueRole, QObject *parent = 0); + QItemModelSurfaceDataMapping(const QString &rowRole, const QString &columnRole, + const QString &valueRole, const QStringList &rowCategories, + const QStringList &columnCategories, QObject *parent = 0); + virtual ~QItemModelSurfaceDataMapping(); + + void setRowRole(const QString &role); + QString rowRole() const; + void setColumnRole(const QString &role); + QString columnRole() const; + void setValueRole(const QString &role); + QString valueRole() const; + + void setRowCategories(const QStringList &categories); + QStringList rowCategories() const; + void setColumnCategories(const QStringList &categories); + QStringList columnCategories() const; + + void remap(const QString &rowRole, const QString &columnRole, + const QString &valueRole, const QStringList &rowCategories, + const QStringList &columnCategories); + + Q_INVOKABLE int rowCategoryIndex(const QString& category); + Q_INVOKABLE int columnCategoryIndex(const QString& category); + +protected: + QItemModelSurfaceDataMappingPrivate *dptr(); + const QItemModelSurfaceDataMappingPrivate *dptrc() const; + +private: + Q_DISABLE_COPY(QItemModelSurfaceDataMapping) +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3d/data/qitemmodelsurfacedatamapping_p.h b/src/datavis3d/data/qitemmodelsurfacedatamapping_p.h new file mode 100644 index 00000000..26d1fbc7 --- /dev/null +++ b/src/datavis3d/data/qitemmodelsurfacedatamapping_p.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVis3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#include "qitemmodelsurfacedatamapping.h" +#include "qabstractdatamapping_p.h" + +#ifndef QITEMMODELSURFACEDATAMAPPING_P_H +#define QITEMMODELSURFACEDATAMAPPING_P_H + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class QItemModelSurfaceDataMappingPrivate : public QAbstractDataMappingPrivate +{ + Q_OBJECT +public: + QItemModelSurfaceDataMappingPrivate(QItemModelSurfaceDataMapping *q); + virtual ~QItemModelSurfaceDataMappingPrivate(); + +private: + QString m_rowRole; + QString m_columnRole; + QString m_valueRole; + + // For row/column items, sort items into these categories. Other categories are ignored. + QStringList m_rowCategories; + QStringList m_columnCategories; + + friend class QItemModelSurfaceDataMapping; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3d/data/qitemmodelsurfacedataproxy.cpp b/src/datavis3d/data/qitemmodelsurfacedataproxy.cpp new file mode 100644 index 00000000..3d2929c1 --- /dev/null +++ b/src/datavis3d/data/qitemmodelsurfacedataproxy.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "qitemmodelsurfacedataproxy_p.h" +#include "surfaceitemmodelhandler_p.h" +#include + +QT_DATAVIS3D_BEGIN_NAMESPACE + +// TODO: CHECK DOCUMENTATION! + +/*! + * \class QItemModelSurfaceDataProxy + * \inmodule QtDataVis3D + * \brief Proxy class for Q3DSurface data model mapping. + * \since 1.0.0 + * + * QItemModelSurfaceDataProxy allows you to use QAbstractItemModel derived models as a data source + * for Q3DSurface. It maps roles defined in QItemModelSurfaceDataMapping to roles in the model. + */ + +/*! + * Constructs QItemModelSurfaceDataProxy. + */ +QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy() : + QSurfaceDataProxy(new QItemModelSurfaceDataProxyPrivate(this)) +{ +} + +/*! + * Constructs QItemModelSurfaceDataProxy with \a itemModel and \a mapping. Does not take ownership + * of the model or the mapping, but does connect to them to listen for changes. + */ +QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, + QItemModelSurfaceDataMapping *mapping) : + QSurfaceDataProxy(new QItemModelSurfaceDataProxyPrivate(this)) +{ + dptr()->m_itemModelHandler->setItemModel(itemModel); + dptr()->m_itemModelHandler->setActiveMapping(mapping); +} + +/*! + * Destroys QItemModelSurfaceDataProxy. + */ +QItemModelSurfaceDataProxy::~QItemModelSurfaceDataProxy() +{ +} + +/*! + * \property QItemModelSurfaceDataProxy::itemModel + * + * Defines item model. Does not take ownership of the model, but does connect to it to listen for + * changes. + */ +void QItemModelSurfaceDataProxy::setItemModel(const QAbstractItemModel *itemModel) +{ + dptr()->m_itemModelHandler->setItemModel(itemModel); +} + +const QAbstractItemModel *QItemModelSurfaceDataProxy::itemModel() const +{ + return dptrc()->m_itemModelHandler->itemModel(); +} + +/*! + * \property QItemModelSurfaceDataProxy::activeMapping + * + * Defines data mapping. Proxy takes ownership of the \a mapping. + * Modifying a mapping that is set to the proxy will trigger data set re-resolving. + */ +void QItemModelSurfaceDataProxy::setActiveMapping(QItemModelSurfaceDataMapping *mapping) +{ + dptr()->m_itemModelHandler->setActiveMapping(mapping); +} + +QItemModelSurfaceDataMapping *QItemModelSurfaceDataProxy::activeMapping() const +{ + return static_cast(dptrc()->m_itemModelHandler->activeMapping()); +} + +/*! + * Transfers the ownership of the \a mapping to this proxy. The mapping is not taken to use yet. + * \sa setActiveMapping(), releaseMapping() + */ +void QItemModelSurfaceDataProxy::addMapping(QItemModelSurfaceDataMapping *mapping) +{ + dptr()->m_itemModelHandler->addMapping(mapping); +} + +/*! + * Releases the ownership of the \a mapping back to the caller. If the mapping was the currently + * active one, no mapping remains active after this call. + */ +void QItemModelSurfaceDataProxy::releaseMapping(QItemModelSurfaceDataMapping *mapping) +{ + dptr()->m_itemModelHandler->releaseMapping(mapping); +} + +/*! + * \return list of mappings owned by the proxy. + */ +QList QItemModelSurfaceDataProxy::mappings() const +{ + QList retList; + QList abstractList = dptrc()->m_itemModelHandler->mappings(); + foreach (QAbstractDataMapping *mapping, abstractList) + retList.append(static_cast(mapping)); + + return retList; +} + +/*! + * \internal + */ +QItemModelSurfaceDataProxyPrivate *QItemModelSurfaceDataProxy::dptr() +{ + return static_cast(d_ptr.data()); +} + +/*! + * \internal + */ +const QItemModelSurfaceDataProxyPrivate *QItemModelSurfaceDataProxy::dptrc() const +{ + return static_cast(d_ptr.data()); +} + +// QItemModelSurfaceDataProxyPrivate + +QItemModelSurfaceDataProxyPrivate::QItemModelSurfaceDataProxyPrivate(QItemModelSurfaceDataProxy *q) + : QSurfaceDataProxyPrivate(q), + m_itemModelHandler(new SurfaceItemModelHandler(q)) +{ +} + +QItemModelSurfaceDataProxyPrivate::~QItemModelSurfaceDataProxyPrivate() +{ + delete m_itemModelHandler; +} + +QItemModelSurfaceDataProxy *QItemModelSurfaceDataProxyPrivate::qptr() +{ + return static_cast(q_ptr); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/data/qitemmodelsurfacedataproxy.h b/src/datavis3d/data/qitemmodelsurfacedataproxy.h new file mode 100644 index 00000000..d10e7005 --- /dev/null +++ b/src/datavis3d/data/qitemmodelsurfacedataproxy.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#ifndef QITEMMODELSURFACEDATAPROXY_H +#define QITEMMODELSURFACEDATAPROXY_H + +#include +#include +#include +#include + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class QItemModelSurfaceDataProxyPrivate; + +class QT_DATAVIS3D_EXPORT QItemModelSurfaceDataProxy : public QSurfaceDataProxy +{ + Q_OBJECT + Q_PROPERTY(const QAbstractItemModel* itemModel READ itemModel WRITE setItemModel) + Q_PROPERTY(QItemModelSurfaceDataMapping* activeMapping READ activeMapping WRITE setActiveMapping) + +public: + explicit QItemModelSurfaceDataProxy(); + explicit QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, + QItemModelSurfaceDataMapping *mapping); + virtual ~QItemModelSurfaceDataProxy(); + + void setItemModel(const QAbstractItemModel *itemModel); + const QAbstractItemModel *itemModel() const; + + void setActiveMapping(QItemModelSurfaceDataMapping *mapping); + QItemModelSurfaceDataMapping *activeMapping() const; + void addMapping(QItemModelSurfaceDataMapping *mapping); + void releaseMapping(QItemModelSurfaceDataMapping *mapping); + QList mappings() const; + +protected: + QItemModelSurfaceDataProxyPrivate *dptr(); + const QItemModelSurfaceDataProxyPrivate *dptrc() const; + +private: + Q_DISABLE_COPY(QItemModelSurfaceDataProxy) +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3d/data/qitemmodelsurfacedataproxy_p.h b/src/datavis3d/data/qitemmodelsurfacedataproxy_p.h new file mode 100644 index 00000000..f9d12618 --- /dev/null +++ b/src/datavis3d/data/qitemmodelsurfacedataproxy_p.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVis3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef QITEMMODELSURFACEDATAPROXY_P_H +#define QITEMMODELSURFACEDATAPROXY_P_H + +#include "qitemmodelsurfacedataproxy.h" +#include "qsurfacedataproxy_p.h" +#include +#include + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class SurfaceItemModelHandler; + +class QItemModelSurfaceDataProxyPrivate : public QSurfaceDataProxyPrivate +{ + Q_OBJECT +public: + QItemModelSurfaceDataProxyPrivate(QItemModelSurfaceDataProxy *q); + virtual ~QItemModelSurfaceDataProxyPrivate(); + +private: + QItemModelSurfaceDataProxy *qptr(); + + SurfaceItemModelHandler *m_itemModelHandler; + + friend class QItemModelSurfaceDataProxy; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3d/data/surfaceitemmodelhandler.cpp b/src/datavis3d/data/surfaceitemmodelhandler.cpp new file mode 100644 index 00000000..cdd04ae7 --- /dev/null +++ b/src/datavis3d/data/surfaceitemmodelhandler.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "surfaceitemmodelhandler_p.h" +#include + +QT_DATAVIS3D_BEGIN_NAMESPACE + +SurfaceItemModelHandler::SurfaceItemModelHandler(QItemModelSurfaceDataProxy *proxy, QObject *parent) + : AbstractItemModelHandler(parent), + m_proxy(proxy) +{ +} + +SurfaceItemModelHandler::~SurfaceItemModelHandler() +{ +} + +// Resolve entire item model into QSurfaceDataArray. +void SurfaceItemModelHandler::resolveModel() +{ + QItemModelSurfaceDataMapping *mapping = static_cast(m_activeMapping); + if (m_itemModel.isNull() || !mapping) { + m_proxy->resetArray(0); + return; + } + + bool useModelRows(false); + if (!mapping->rowCategories().size() || !mapping->columnCategories().size()) { + useModelRows = true; + } else if (mapping->rowRole().isEmpty() || mapping->columnRole().isEmpty()) { + m_proxy->resetArray(0); + return; + } + + QSurfaceDataArray *newProxyArray = new QSurfaceDataArray; + QHash roleHash = m_itemModel->roleNames(); + // Default to display role if no mapping + int valueRole = roleHash.key(mapping->valueRole().toLatin1(), Qt::DisplayRole); + int rowCount = m_itemModel->rowCount(); + int columnCount = m_itemModel->columnCount(); + + if (useModelRows) { + for (int i = 0; i < rowCount; i++) { + QSurfaceDataRow *newProxyRow = new QSurfaceDataRow(columnCount); + for (int j = 0; j < columnCount; j++) + (*newProxyRow)[j] = m_itemModel->index(i, j).data(valueRole).toReal(); + newProxyArray->append(newProxyRow); + } + } else { + int rowRole = roleHash.key(mapping->rowRole().toLatin1()); + int columnRole = roleHash.key(mapping->columnRole().toLatin1()); + const QStringList &rowList = mapping->rowCategories(); + const QStringList &columnList = mapping->columnCategories(); + + // Sort values into rows and columns + typedef QHash ColumnValueMap; + QHash itemValueMap; + for (int i = 0; i < rowCount; i++) { + for (int j = 0; j < columnCount; j++) { + QModelIndex index = m_itemModel->index(i, j); + itemValueMap[index.data(rowRole).toString()][index.data(columnRole).toString()] + = index.data(valueRole).toReal(); + } + } + + // Create new data array from itemValueMap + foreach (QString rowKey, rowList) { + QSurfaceDataRow *newProxyRow = new QSurfaceDataRow(columnList.size()); + for (int i = 0; i < columnList.size(); i++) + (*newProxyRow)[i] = itemValueMap[rowKey][columnList.at(i)]; + newProxyArray->append(newProxyRow); + } + } + + m_proxy->resetArray(newProxyArray); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/data/surfaceitemmodelhandler_p.h b/src/datavis3d/data/surfaceitemmodelhandler_p.h new file mode 100644 index 00000000..2cdf5b47 --- /dev/null +++ b/src/datavis3d/data/surfaceitemmodelhandler_p.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVis3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef SURFACEITEMMODELHANDLER_P_H +#define SURFACEITEMMODELHANDLER_P_H + +#include "abstractitemmodelhandler_p.h" +#include "qitemmodelsurfacedataproxy.h" + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class SurfaceItemModelHandler : public AbstractItemModelHandler +{ + Q_OBJECT +public: + SurfaceItemModelHandler(QItemModelSurfaceDataProxy *proxy, QObject *parent = 0); + virtual ~SurfaceItemModelHandler(); + +protected: + void virtual resolveModel(); + + QItemModelSurfaceDataProxy *m_proxy; // Not owned +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3dqml2/datavis3dqml2.pro b/src/datavis3dqml2/datavis3dqml2.pro index b7157a26..aa4d7d71 100644 --- a/src/datavis3dqml2/datavis3dqml2.pro +++ b/src/datavis3dqml2/datavis3dqml2.pro @@ -21,14 +21,18 @@ SOURCES += \ declarativebars.cpp \ declarativebarsrenderer.cpp \ declarativescatter.cpp \ - declarativescatterrenderer.cpp + declarativescatterrenderer.cpp \ + declarativesurface.cpp \ + declarativesurfacerenderer.cpp HEADERS += \ datavis3dqml2_plugin.h \ declarativebars_p.h \ declarativebarsrenderer_p.h \ declarativescatter_p.h \ - declarativescatterrenderer_p.h + declarativescatterrenderer_p.h \ + declarativesurface_p.h \ + declarativesurfacerenderer_p.h OTHER_FILES = qmldir diff --git a/src/datavis3dqml2/datavis3dqml2_plugin.cpp b/src/datavis3dqml2/datavis3dqml2_plugin.cpp index 8c73e318..6caacfd1 100644 --- a/src/datavis3dqml2/datavis3dqml2_plugin.cpp +++ b/src/datavis3dqml2/datavis3dqml2_plugin.cpp @@ -26,29 +26,34 @@ void Datavis3Dqml2Plugin::registerTypes(const char *uri) { // @uri com.digia.QtDataVis3D qmlRegisterUncreatableType(uri, 1, 0, "AbstractItemModel", - QLatin1String("Trying to create uncreatable: AbstractItemModel.")); + QLatin1String("Trying to create uncreatable: AbstractItemModel.")); qmlRegisterUncreatableType(uri, 1, 0, "DataVis", QLatin1String("Trying to create uncreatable: DataVis.")); qmlRegisterUncreatableType(uri, 1, 0, "AbstractAxis3D", - QLatin1String("Trying to create uncreatable: AbstractAxis.")); + QLatin1String("Trying to create uncreatable: AbstractAxis.")); qmlRegisterUncreatableType(uri, 1, 0, "AbstractDataProxy", - QLatin1String("Trying to create uncreatable: AbstractDataProxy.")); + QLatin1String("Trying to create uncreatable: AbstractDataProxy.")); qmlRegisterUncreatableType(uri, 1, 0, "BarDataProxy", QLatin1String("Trying to create uncreatable: BarDataProxy.")); qmlRegisterUncreatableType(uri, 1, 0, "ScatterDataProxy", - QLatin1String("Trying to create uncreatable: ScatterDataProxy.")); + QLatin1String("Trying to create uncreatable: ScatterDataProxy.")); + qmlRegisterUncreatableType(uri, 1, 0, "SurfaceDataProxy", + QLatin1String("Trying to create uncreatable: SurfaceDataProxy.")); qmlRegisterType(uri, 1, 0, "BarDataMapping"); qmlRegisterType(uri, 1, 0, "ScatterDataMapping"); + qmlRegisterType(uri, 1, 0, "SurfaceDataMapping"); qmlRegisterType(uri, 1, 0, "Bars3D"); qmlRegisterType(uri, 1, 0, "Scatter3D"); + qmlRegisterType(uri, 1, 0, "Surface3D"); qmlRegisterType(uri, 1, 0, "ValueAxis3D"); qmlRegisterType(uri, 1, 0, "CategoryAxis3D"); qmlRegisterType(uri, 1, 0, "ItemModelBarDataProxy"); qmlRegisterType(uri, 1, 0, "ItemModelScatterDataProxy"); + qmlRegisterType(uri, 1, 0, "ItemModelSurfaceDataProxy"); } QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/datavis3dqml2_plugin.h b/src/datavis3dqml2/datavis3dqml2_plugin.h index cc9894ba..35b98ca6 100644 --- a/src/datavis3dqml2/datavis3dqml2_plugin.h +++ b/src/datavis3dqml2/datavis3dqml2_plugin.h @@ -22,12 +22,15 @@ #include "datavis3dglobal_p.h" #include "declarativebars_p.h" #include "declarativescatter_p.h" +#include "declarativesurface_p.h" #include "qitemmodelbardatamapping.h" #include "qitemmodelscatterdatamapping.h" -#include "q3dvalueaxis.h" -#include "q3dcategoryaxis.h" +#include "qitemmodelsurfacedatamapping.h" #include "qitemmodelbardataproxy.h" #include "qitemmodelscatterdataproxy.h" +#include "qitemmodelsurfacedataproxy.h" +#include "q3dvalueaxis.h" +#include "q3dcategoryaxis.h" #include @@ -35,10 +38,14 @@ QT_DATAVIS3D_USE_NAMESPACE Q_DECLARE_METATYPE(DeclarativeBars *) Q_DECLARE_METATYPE(DeclarativeScatter *) +Q_DECLARE_METATYPE(DeclarativeSurface *) Q_DECLARE_METATYPE(QItemModelBarDataMapping *) Q_DECLARE_METATYPE(QItemModelScatterDataMapping *) +Q_DECLARE_METATYPE(QItemModelSurfaceDataMapping *) + Q_DECLARE_METATYPE(const QAbstractItemModel *) + Q_DECLARE_METATYPE(QDataVis *) Q_DECLARE_METATYPE(Q3DAbstractAxis *) @@ -50,6 +57,8 @@ Q_DECLARE_METATYPE(QBarDataProxy *) Q_DECLARE_METATYPE(QItemModelBarDataProxy *) Q_DECLARE_METATYPE(QScatterDataProxy *) Q_DECLARE_METATYPE(QItemModelScatterDataProxy *) +Q_DECLARE_METATYPE(QSurfaceDataProxy *) +Q_DECLARE_METATYPE(QItemModelSurfaceDataProxy *) QT_DATAVIS3D_BEGIN_NAMESPACE diff --git a/src/datavis3dqml2/declarativesurface.cpp b/src/datavis3dqml2/declarativesurface.cpp new file mode 100644 index 00000000..a85b926e --- /dev/null +++ b/src/datavis3dqml2/declarativesurface.cpp @@ -0,0 +1,288 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "declarativesurface_p.h" +#include "declarativesurfacerenderer_p.h" +#include "q3dvalueaxis.h" +#include "qitemmodelsurfacedataproxy.h" + +QT_DATAVIS3D_BEGIN_NAMESPACE + +DeclarativeSurface::DeclarativeSurface(QQuickItem *parent) + : QQuickItem(parent), + m_shared(0), + m_initialisedSize(0, 0), + m_cameraPreset(QDataVis::NoPreset), + m_theme(QDataVis::ThemeDefault) +{ + setFlags(QQuickItem::ItemHasContents); + setAcceptedMouseButtons(Qt::AllButtons); + + // TODO: These seem to have no effect; find a way to activate anti-aliasing + setAntialiasing(true); + setSmooth(true); + + // Create the shared component on the main GUI thread. + m_shared = new Surface3DController(boundingRect().toRect()); + QObject::connect(m_shared, &Abstract3DController::shadowQualityChanged, this, + &DeclarativeSurface::handleShadowQualityUpdate); + + QItemModelSurfaceDataProxy *proxy = new QItemModelSurfaceDataProxy; + m_shared->setActiveDataProxy(proxy); +} + +DeclarativeSurface::~DeclarativeSurface() +{ + delete m_shared; +} + +void DeclarativeSurface::handleShadowQualityUpdate(QDataVis::ShadowQuality quality) +{ + emit shadowQualityChanged(quality); +} + +QSGNode *DeclarativeSurface::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + // If old node exists and has right size, reuse it. + if (oldNode && m_initialisedSize == boundingRect().size().toSize()) { + // Update bounding rectangle (that has same size as before). + static_cast( oldNode )->setRect(boundingRect()); + return oldNode; + } + + // Create a new render node when size changes or if there is no node yet + m_initialisedSize = boundingRect().size().toSize(); + + // Delete old node + if (oldNode) + delete oldNode; + + // Create a new one and set it's bounding rectangle + DeclarativeSurfaceRenderer *node = new DeclarativeSurfaceRenderer(window(), m_shared); + node->setRect(boundingRect()); + m_shared->setBoundingRect(boundingRect().toRect()); + return node; +} + +void DeclarativeSurface::setGradientColorAt(qreal pos, const QColor &color) +{ + m_shared->setGradientColorAt(pos, color); +} + +void DeclarativeSurface::setDataProxy(QSurfaceDataProxy *dataProxy) +{ + m_shared->setActiveDataProxy(dataProxy); +} + +QSurfaceDataProxy *DeclarativeSurface::dataProxy() const +{ + return static_cast(m_shared->activeDataProxy()); +} + +void DeclarativeSurface::setCameraPreset(QDataVis::CameraPreset preset) +{ + // TODO: Implement correctly once "improved camera api" (QTRD-2122) is implemented + // We need to save this locally, as there are no getters for it in controller + m_cameraPreset = preset; + m_shared->setCameraPreset(preset); +} + +Q3DValueAxis *DeclarativeSurface::axisX() const +{ + return static_cast(m_shared->axisX()); +} + +void DeclarativeSurface::setAxisX(Q3DValueAxis *axis) +{ + m_shared->setAxisX(axis); +} + +Q3DValueAxis *DeclarativeSurface::axisY() const +{ + return static_cast(m_shared->axisY()); +} + +void DeclarativeSurface::setAxisY(Q3DValueAxis *axis) +{ + m_shared->setAxisY(axis); +} + +Q3DValueAxis *DeclarativeSurface::axisZ() const +{ + return static_cast(m_shared->axisZ()); +} + +void DeclarativeSurface::setAxisZ(Q3DValueAxis *axis) +{ + m_shared->setAxisZ(axis); +} + +QDataVis::CameraPreset DeclarativeSurface::cameraPreset() +{ + return m_cameraPreset; +} + +void DeclarativeSurface::setTheme(QDataVis::ColorTheme theme) +{ + // TODO: Implement correctly once "user-modifiable themes" (QTRD-2120) is implemented + // We need to save this locally, as there are no getters for it in controller + m_theme = theme; + m_shared->setColorTheme(theme); +} + +QDataVis::ColorTheme DeclarativeSurface::theme() +{ + return m_theme; +} + +void DeclarativeSurface::setFont(const QFont &font) +{ + m_shared->setFont(font); +} + +QFont DeclarativeSurface::font() +{ + return m_shared->font(); +} + +void DeclarativeSurface::setLabelTransparency(QDataVis::LabelTransparency transparency) +{ + m_shared->setLabelTransparency(transparency); +} + +QDataVis::LabelTransparency DeclarativeSurface::labelTransparency() +{ + return m_shared->labelTransparency(); +} + +void DeclarativeSurface::setGridVisible(bool visible) +{ + m_shared->setGridEnabled(visible); +} + +bool DeclarativeSurface::isGridVisible() +{ + return m_shared->gridEnabled(); +} + +void DeclarativeSurface::setBackgroundVisible(bool visible) +{ + m_shared->setBackgroundEnabled(visible); +} + +bool DeclarativeSurface::isBackgroundVisible() +{ + return m_shared->backgroundEnabled(); +} + +void DeclarativeSurface::setSmoothSurface(bool enable) +{ + m_shared->setSmoothSurface(enable); +} + +bool DeclarativeSurface::smoothSurface() const +{ + return m_shared->smoothSurface(); +} + +void DeclarativeSurface::setSurfaceGrid(bool enable) +{ + m_shared->setSurfaceGrid(enable); +} + +bool DeclarativeSurface::surfaceGrid() const +{ + return m_shared->surfaceGrid(); +} + +void DeclarativeSurface::setSelectionMode(QDataVis::SelectionMode mode) +{ + m_shared->setSelectionMode(mode); +} + +QDataVis::SelectionMode DeclarativeSurface::selectionMode() +{ + return m_shared->selectionMode(); +} + +void DeclarativeSurface::setShadowQuality(QDataVis::ShadowQuality quality) +{ + m_shared->setShadowQuality(quality); +} + +QDataVis::ShadowQuality DeclarativeSurface::shadowQuality() +{ + return m_shared->shadowQuality(); +} + +void DeclarativeSurface::setItemLabelFormat(const QString &format) +{ + m_shared->activeDataProxy()->setItemLabelFormat(format); +} + +QString DeclarativeSurface::itemLabelFormat() +{ + return m_shared->activeDataProxy()->itemLabelFormat(); +} + +void DeclarativeSurface::mouseDoubleClickEvent(QMouseEvent *event) +{ +#if defined(Q_OS_ANDROID) + m_shared->mouseDoubleClickEvent(event); +#else + Q_UNUSED(event) +#endif +} + +void DeclarativeSurface::touchEvent(QTouchEvent *event) +{ +#if defined(Q_OS_ANDROID) + m_shared->touchEvent(event); + update(); +#else + Q_UNUSED(event) +#endif +} + +void DeclarativeSurface::mousePressEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mousePressEvent(event, mousePos); +} + +void DeclarativeSurface::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseReleaseEvent(event, mousePos); +} + +void DeclarativeSurface::mouseMoveEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseMoveEvent(event, mousePos); +} + +void DeclarativeSurface::wheelEvent(QWheelEvent *event) +{ + m_shared->wheelEvent(event); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativesurface_p.h b/src/datavis3dqml2/declarativesurface_p.h new file mode 100644 index 00000000..f115963c --- /dev/null +++ b/src/datavis3dqml2/declarativesurface_p.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVis3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef DECLARATIVESURFACE_P_H +#define DECLARATIVESURFACE_P_H + +#include "datavis3dglobal_p.h" +#include "surface3dcontroller_p.h" +#include "declarativesurface_p.h" +#include "q3dvalueaxis.h" +#include "qsurfacedataproxy.h" + +#include +#include +#include +#include + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class DeclarativeSurface : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QSurfaceDataProxy *dataProxy READ dataProxy WRITE setDataProxy) + Q_PROPERTY(Q3DValueAxis *axisX READ axisX WRITE setAxisX) + Q_PROPERTY(Q3DValueAxis *axisY READ axisY WRITE setAxisY) + Q_PROPERTY(Q3DValueAxis *axisZ READ axisZ WRITE setAxisZ) + Q_PROPERTY(QtDataVis3D::QDataVis::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + Q_PROPERTY(QtDataVis3D::QDataVis::LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) + Q_PROPERTY(QtDataVis3D::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality) + Q_PROPERTY(QtDataVis3D::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset) + Q_PROPERTY(QtDataVis3D::QDataVis::ColorTheme theme READ theme WRITE setTheme) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible) + Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) + Q_PROPERTY(bool smoothSurface READ smoothSurface WRITE setSmoothSurface) + Q_PROPERTY(bool surfaceGrid READ surfaceGrid WRITE setSurfaceGrid) + Q_PROPERTY(QString itemLabelFormat READ itemLabelFormat WRITE setItemLabelFormat) + Q_ENUMS(QtDataVis3D::QDataVis::SelectionMode) + Q_ENUMS(QtDataVis3D::QDataVis::ShadowQuality) + Q_ENUMS(QtDataVis3D::QDataVis::LabelTransparency) + Q_ENUMS(QtDataVis3D::QDataVis::CameraPreset) + Q_ENUMS(QtDataVis3D::QDataVis::ColorTheme) + +public: + explicit DeclarativeSurface(QQuickItem *parent = 0); + ~DeclarativeSurface(); + + Q_INVOKABLE void setGradientColorAt(qreal pos, const QColor &color); + + QSurfaceDataProxy *dataProxy() const; + void setDataProxy(QSurfaceDataProxy *dataProxy); + + Q3DValueAxis *axisX() const; + void setAxisX(Q3DValueAxis *axis); + Q3DValueAxis *axisY() const; + void setAxisY(Q3DValueAxis *axis); + Q3DValueAxis *axisZ() const; + void setAxisZ(Q3DValueAxis *axis); + + // Select preset camera placement + void setCameraPreset(QDataVis::CameraPreset preset); + QDataVis::CameraPreset cameraPreset(); + + // Set theme (object colors, shaders, window color, background colors, light intensity and text + // colors are affected) + void setTheme(QDataVis::ColorTheme theme); + QDataVis::ColorTheme theme(); + + // Change selection mode + void setSelectionMode(QDataVis::SelectionMode mode); + QDataVis::SelectionMode selectionMode(); + + // Set font + void setFont(const QFont &font); + QFont font(); + + // Label transparency adjustment + void setLabelTransparency(QDataVis::LabelTransparency transparency); + QDataVis::LabelTransparency labelTransparency(); + + // Enable or disable background grid + void setGridVisible(bool visible); + bool isGridVisible(); + + // Enable or disable background mesh + void setBackgroundVisible(bool visible); + bool isBackgroundVisible(); + + // Enable or disable the smoothes of the surface + void setSmoothSurface(bool enable); + bool smoothSurface() const; + + // Enable or disable the grid on the surface + void setSurfaceGrid(bool enable); + bool surfaceGrid() const; + + // Adjust shadow quality + void setShadowQuality(QDataVis::ShadowQuality quality); + QDataVis::ShadowQuality shadowQuality(); + + void setItemLabelFormat(const QString &format); + QString itemLabelFormat(); + +signals: + // Signals shadow quality changes. + void shadowQualityChanged(QDataVis::ShadowQuality quality); + +protected: + Surface3DController *m_shared; + + // Used to detect when shadow quality changes autonomously due to e.g. resizing. + void handleShadowQualityUpdate(QDataVis::ShadowQuality quality); + + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); + + void mouseDoubleClickEvent(QMouseEvent *event); + void touchEvent(QTouchEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); + +private: + QSize m_initialisedSize; + QDataVis::CameraPreset m_cameraPreset; + QDataVis::ColorTheme m_theme; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3dqml2/declarativesurfacerenderer.cpp b/src/datavis3dqml2/declarativesurfacerenderer.cpp new file mode 100644 index 00000000..5e3dc367 --- /dev/null +++ b/src/datavis3dqml2/declarativesurfacerenderer.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "declarativesurfacerenderer_p.h" + +#include +#include + +QT_DATAVIS3D_BEGIN_NAMESPACE + +DeclarativeSurfaceRenderer::DeclarativeSurfaceRenderer(QQuickWindow *window, + Surface3DController *renderer) + : m_fbo(0), + m_texture(0), + m_window(window), + m_surfaceRenderer(renderer) +{ + connect(m_window, &QQuickWindow::beforeSynchronizing, this, + &DeclarativeSurfaceRenderer::synchDataToRenderer, Qt::DirectConnection); + connect(m_window, &QQuickWindow::beforeRendering, this, + &DeclarativeSurfaceRenderer::renderFBO, Qt::DirectConnection); + connect(m_surfaceRenderer, &Abstract3DController::needRender, m_window, + &QQuickWindow::update); +} + +DeclarativeSurfaceRenderer::~DeclarativeSurfaceRenderer() +{ + delete m_texture; + delete m_fbo; +} + +void DeclarativeSurfaceRenderer::synchDataToRenderer() +{ + m_surfaceRenderer->initializeOpenGL(); + m_surfaceRenderer->synchDataToRenderer(); +} + +void DeclarativeSurfaceRenderer::renderFBO() +{ + QSize size = rect().size().toSize(); + + // Create FBO + if (!m_fbo) { + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::Depth); + m_fbo = new QOpenGLFramebufferObject(size, format); + m_texture = m_window->createTextureFromId(m_fbo->texture(), size); + + setTexture(m_texture); + + // Flip texture + // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2) + QSize ts = m_texture->textureSize(); + QRectF sourceRect(0, 0, ts.width(), ts.height()); + float tmp = sourceRect.top(); + sourceRect.setTop(sourceRect.bottom()); + sourceRect.setBottom(tmp); + QSGGeometry *geometry = this->geometry(); + QSGGeometry::updateTexturedRectGeometry(geometry, rect(), + m_texture->convertToNormalizedSourceRect(sourceRect)); + markDirty(DirtyMaterial); + } + + // Call the shared rendering function + m_fbo->bind(); + + m_surfaceRenderer->render(m_fbo->handle()); + + m_fbo->release(); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativesurfacerenderer_p.h b/src/datavis3dqml2/declarativesurfacerenderer_p.h new file mode 100644 index 00000000..4aae91b1 --- /dev/null +++ b/src/datavis3dqml2/declarativesurfacerenderer_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVis3D module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVis3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef DECLARATIVESURFACERENDERER_H +#define DECLARATIVESURFACERENDERER_H + +#include "datavis3dglobal_p.h" +#include "surface3dcontroller_p.h" +#include + +class QOpenGLFramebufferObject; +class QSGTexture; +class QQuickWindow; + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class DeclarativeSurfaceRenderer : public QObject, public QSGSimpleTextureNode +{ + Q_OBJECT + +public: + DeclarativeSurfaceRenderer(QQuickWindow *window, Surface3DController *shared); + ~DeclarativeSurfaceRenderer(); + +public slots: + // Used to synch up data model from controller to renderer while main thread is locked + void synchDataToRenderer(); + // Renders view to FBO before render cycle starts. + void renderFBO(); + +private: + QOpenGLFramebufferObject *m_fbo; + QSGTexture *m_texture; + QQuickWindow *m_window; + Surface3DController *m_surfaceRenderer; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif -- cgit v1.2.3