diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-09-10 11:42:13 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-09-10 12:04:24 +0300 |
commit | a28cdb72a4ea768a898ca07f0df0fa3c17c073a8 (patch) | |
tree | 0bafdcfa99fc783e9f5204539a8242bf6128d795 /src/datavisualizationqml2 | |
parent | f3e38983d77c72f3121c33a149a58fdf9c64158c (diff) |
Diffstat (limited to 'src/datavisualizationqml2')
16 files changed, 2181 insertions, 0 deletions
diff --git a/src/datavisualizationqml2/datavisualizationqml2.pro b/src/datavisualizationqml2/datavisualizationqml2.pro new file mode 100644 index 00000000..c5ee910b --- /dev/null +++ b/src/datavisualizationqml2/datavisualizationqml2.pro @@ -0,0 +1,54 @@ +TEMPLATE = lib +TARGET = datavisualizationqml2 +QT += qml quick datavisualization +CONFIG += qt plugin + +TARGET = $$qtLibraryTarget($$TARGET) +uri = com.digia.QtDataVisualization + +static { + DEFINES += QT_DATAVISUALIZATION_STATICLIB + CONFIG -= static staticlib +} + +# Input +INCLUDEPATH += ../datavisualization/engine \ + ../datavisualization/global \ + ../datavisualization/data + +SOURCES += \ + datavisualizationqml2_plugin.cpp \ + declarativebars.cpp \ + declarativebarsrenderer.cpp \ + declarativescatter.cpp \ + declarativescatterrenderer.cpp \ + declarativesurface.cpp \ + declarativesurfacerenderer.cpp + +HEADERS += \ + datavisualizationqml2_plugin.h \ + declarativebars_p.h \ + declarativebarsrenderer_p.h \ + declarativescatter_p.h \ + declarativescatterrenderer_p.h \ + declarativesurface_p.h \ + declarativesurfacerenderer_p.h + +OTHER_FILES = qmldir + +!equals(_PRO_FILE_PWD_, $$OUT_PWD) { + copy_qmldir.target = $$OUT_PWD/qmldir + copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir + copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" + QMAKE_EXTRA_TARGETS += copy_qmldir + PRE_TARGETDEPS += $$copy_qmldir.target +} + +qmldir.files = qmldir +unix { + installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) + qmldir.path = $$installPath + target.path = $$installPath + INSTALLS += target qmldir +} + diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp new file mode 100644 index 00000000..83c9eaf8 --- /dev/null +++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 QtDataVisualization 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 "datavisualizationqml2_plugin.h" + +#include <qqml.h> + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +void Datavis3Dqml2Plugin::registerTypes(const char *uri) +{ + // @uri com.digia.QtDataVisualization + qmlRegisterUncreatableType<const QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", + QLatin1String("Trying to create uncreatable: AbstractItemModel.")); + qmlRegisterUncreatableType<QDataVis>(uri, 1, 0, "DataVis", + QLatin1String("Trying to create uncreatable: DataVis.")); + qmlRegisterUncreatableType<Q3DAbstractAxis>(uri, 1, 0, "AbstractAxis3D", + QLatin1String("Trying to create uncreatable: AbstractAxis.")); + qmlRegisterUncreatableType<QAbstractDataProxy>(uri, 1, 0, "AbstractDataProxy", + QLatin1String("Trying to create uncreatable: AbstractDataProxy.")); + qmlRegisterUncreatableType<QBarDataProxy>(uri, 1, 0, "BarDataProxy", + QLatin1String("Trying to create uncreatable: BarDataProxy.")); + qmlRegisterUncreatableType<QScatterDataProxy>(uri, 1, 0, "ScatterDataProxy", + QLatin1String("Trying to create uncreatable: ScatterDataProxy.")); + qmlRegisterUncreatableType<QSurfaceDataProxy>(uri, 1, 0, "SurfaceDataProxy", + QLatin1String("Trying to create uncreatable: SurfaceDataProxy.")); + + qmlRegisterType<QItemModelBarDataMapping>(uri, 1, 0, "BarDataMapping"); + qmlRegisterType<QItemModelScatterDataMapping>(uri, 1, 0, "ScatterDataMapping"); + qmlRegisterType<QItemModelSurfaceDataMapping>(uri, 1, 0, "SurfaceDataMapping"); + + qmlRegisterType<DeclarativeBars>(uri, 1, 0, "Bars3D"); + qmlRegisterType<DeclarativeScatter>(uri, 1, 0, "Scatter3D"); + qmlRegisterType<DeclarativeSurface>(uri, 1, 0, "Surface3D"); + + qmlRegisterType<Q3DValueAxis>(uri, 1, 0, "ValueAxis3D"); + qmlRegisterType<Q3DCategoryAxis>(uri, 1, 0, "CategoryAxis3D"); + + qmlRegisterType<QItemModelBarDataProxy>(uri, 1, 0, "ItemModelBarDataProxy"); + qmlRegisterType<QItemModelScatterDataProxy>(uri, 1, 0, "ItemModelScatterDataProxy"); + qmlRegisterType<QItemModelSurfaceDataProxy>(uri, 1, 0, "ItemModelSurfaceDataProxy"); +} + +QT_DATAVISUALIZATION_END_NAMESPACE + diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.h b/src/datavisualizationqml2/datavisualizationqml2_plugin.h new file mode 100644 index 00000000..543afb9c --- /dev/null +++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 QtDataVisualization 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 DATAVISUALIZATIONQML2_PLUGIN_H +#define DATAVISUALIZATIONQML2_PLUGIN_H + +#include "datavisualizationglobal_p.h" +#include "declarativebars_p.h" +#include "declarativescatter_p.h" +#include "declarativesurface_p.h" +#include "qitemmodelbardatamapping.h" +#include "qitemmodelscatterdatamapping.h" +#include "qitemmodelsurfacedatamapping.h" +#include "qitemmodelbardataproxy.h" +#include "qitemmodelscatterdataproxy.h" +#include "qitemmodelsurfacedataproxy.h" +#include "q3dvalueaxis.h" +#include "q3dcategoryaxis.h" + +#include <QQmlExtensionPlugin> + +QT_DATAVISUALIZATION_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 *) +Q_DECLARE_METATYPE(Q3DCategoryAxis *) +Q_DECLARE_METATYPE(Q3DValueAxis *) + +Q_DECLARE_METATYPE(QAbstractDataProxy *) +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_DATAVISUALIZATION_BEGIN_NAMESPACE + +class Datavis3Dqml2Plugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri); +}; + +QT_DATAVISUALIZATION_END_NAMESPACE + +#endif // DATAVISUALIZATIONQML2_PLUGIN_H + diff --git a/src/datavisualizationqml2/declarativebars.cpp b/src/datavisualizationqml2/declarativebars.cpp new file mode 100644 index 00000000..29d138e2 --- /dev/null +++ b/src/datavisualizationqml2/declarativebars.cpp @@ -0,0 +1,390 @@ +/**************************************************************************** +** +** 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 QtDataVisualization 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 "declarativebars_p.h" +#include "declarativebarsrenderer_p.h" +#include "q3dvalueaxis.h" +#include "qitemmodelbardataproxy.h" + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +const QString smoothString(QStringLiteral("Smooth")); + +DeclarativeBars::DeclarativeBars(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 Bars3DController(boundingRect().toRect()); + QObject::connect(m_shared, &Abstract3DController::shadowQualityChanged, this, + &DeclarativeBars::handleShadowQualityUpdate); + + QItemModelBarDataProxy *proxy = new QItemModelBarDataProxy; + m_shared->setActiveDataProxy(proxy); +} + +DeclarativeBars::~DeclarativeBars() +{ + delete m_shared; +} + +void DeclarativeBars::handleShadowQualityUpdate(QDataVis::ShadowQuality quality) +{ + emit shadowQualityChanged(quality); +} + +QSGNode *DeclarativeBars::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<DeclarativeBarsRenderer *>( 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 + DeclarativeBarsRenderer *node = new DeclarativeBarsRenderer(window(), m_shared); + node->setRect(boundingRect()); + m_shared->setBoundingRect(boundingRect().toRect()); + return node; +} + +void DeclarativeBars::setDataWindow(int rowCount, int columnCount) +{ + m_shared->setDataWindow(rowCount, columnCount); +} + +void DeclarativeBars::setBarColor(const QColor &baseColor, const QColor &heightColor, + const QColor &depthColor, bool uniform) +{ + m_shared->setObjectColor(baseColor, heightColor, depthColor, uniform); +} + +void DeclarativeBars::setCameraPosition(qreal horizontal, qreal vertical, int distance) +{ + m_shared->setCameraPosition(GLfloat(horizontal), GLfloat(vertical), GLint(distance)); +} + +void DeclarativeBars::setDataProxy(QBarDataProxy *dataProxy) +{ + m_shared->setActiveDataProxy(dataProxy); +} + +QBarDataProxy *DeclarativeBars::dataProxy() const +{ + return static_cast<QBarDataProxy *>(m_shared->activeDataProxy()); +} + +Q3DCategoryAxis *DeclarativeBars::rowAxis() const +{ + return static_cast<Q3DCategoryAxis *>(m_shared->axisX()); +} + +void DeclarativeBars::setRowAxis(Q3DCategoryAxis *axis) +{ + m_shared->setAxisX(axis); +} + +Q3DValueAxis *DeclarativeBars::valueAxis() const +{ + return static_cast<Q3DValueAxis *>(m_shared->axisY()); +} + +void DeclarativeBars::setValueAxis(Q3DValueAxis *axis) +{ + m_shared->setAxisY(axis); +} + +Q3DCategoryAxis *DeclarativeBars::columnAxis() const +{ + return static_cast<Q3DCategoryAxis *>(m_shared->axisZ()); +} + +void DeclarativeBars::setColumnAxis(Q3DCategoryAxis *axis) +{ + m_shared->setAxisZ(axis); +} + +void DeclarativeBars::setBarThickness(qreal thicknessRatio) +{ + m_shared->setBarSpecs(GLfloat(thicknessRatio), barSpacing(), isBarSpacingRelative()); +} + +qreal DeclarativeBars::barThickness() +{ + return m_shared->barThickness(); +} + +void DeclarativeBars::setBarSpacing(QSizeF spacing) +{ + m_shared->setBarSpecs(GLfloat(barThickness()), spacing, isBarSpacingRelative()); +} + +QSizeF DeclarativeBars::barSpacing() +{ + return m_shared->barSpacing(); +} + +void DeclarativeBars::setBarSpacingRelative(bool relative) +{ + m_shared->setBarSpecs(GLfloat(barThickness()), barSpacing(), relative); +} + +bool DeclarativeBars::isBarSpacingRelative() +{ + return m_shared->isBarSpecRelative(); +} + +void DeclarativeBars::setBarType(QDataVis::MeshStyle style) +{ + QString objFile = m_shared->meshFileName(); + bool smooth = objFile.endsWith(smoothString); + m_shared->setBarType(style, smooth); +} + +QDataVis::MeshStyle DeclarativeBars::barType() +{ + QString objFile = m_shared->meshFileName(); + if (objFile.contains("/sphere")) + return QDataVis::Spheres; + else + return QDataVis::Dots; +} + +void DeclarativeBars::setBarSmooth(bool smooth) +{ + QString objFile = m_shared->meshFileName(); + if (objFile.endsWith(smoothString)) { + if (smooth) + return; // Already smooth; do nothing + else // Rip Smooth off the end + objFile.resize(objFile.indexOf(smoothString)); + } else { + if (!smooth) // Already flat; do nothing + return; + else // Append Smooth to the end + objFile.append(smoothString); + } + m_shared->setMeshFileName(objFile); +} + +bool DeclarativeBars::barSmooth() +{ + QString objFile = m_shared->meshFileName(); + return objFile.endsWith(smoothString); +} + +void DeclarativeBars::setMeshFileName(const QString &objFileName) +{ + m_shared->setMeshFileName(objFileName); +} + +QString DeclarativeBars::meshFileName() +{ + return m_shared->meshFileName(); +} + +void DeclarativeBars::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); +} + +QDataVis::CameraPreset DeclarativeBars::cameraPreset() +{ + return m_cameraPreset; +} + +void DeclarativeBars::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 DeclarativeBars::theme() +{ + return m_theme; +} + +void DeclarativeBars::setFont(const QFont &font) +{ + m_shared->setFont(font); +} + +QFont DeclarativeBars::font() +{ + return m_shared->font(); +} + +void DeclarativeBars::setLabelTransparency(QDataVis::LabelTransparency transparency) +{ + m_shared->setLabelTransparency(transparency); +} + +QDataVis::LabelTransparency DeclarativeBars::labelTransparency() +{ + return m_shared->labelTransparency(); +} + +void DeclarativeBars::setGridVisible(bool visible) +{ + m_shared->setGridEnabled(visible); +} + +bool DeclarativeBars::isGridVisible() +{ + return m_shared->gridEnabled(); +} + +void DeclarativeBars::setBackgroundVisible(bool visible) +{ + m_shared->setBackgroundEnabled(visible); +} + +bool DeclarativeBars::isBackgroundVisible() +{ + return m_shared->backgroundEnabled(); +} + +void DeclarativeBars::setSelectionMode(QDataVis::SelectionMode mode) +{ + m_shared->setSelectionMode(mode); +} + +QDataVis::SelectionMode DeclarativeBars::selectionMode() +{ + return m_shared->selectionMode(); +} + +void DeclarativeBars::setShadowQuality(QDataVis::ShadowQuality quality) +{ + m_shared->setShadowQuality(quality); +} + +QDataVis::ShadowQuality DeclarativeBars::shadowQuality() +{ + return m_shared->shadowQuality(); +} + +int DeclarativeBars::rows() const +{ + return m_shared->rowCount(); +} + +void DeclarativeBars::setRows(int rows) +{ + setDataWindow(rows, columns()); +} + +int DeclarativeBars::columns() const +{ + return m_shared->columnCount(); +} + +void DeclarativeBars::setColumns(int columns) +{ + setDataWindow(rows(), columns); +} + +void DeclarativeBars::setItemLabelFormat(const QString &format) +{ + m_shared->activeDataProxy()->setItemLabelFormat(format); +} + +QString DeclarativeBars::itemLabelFormat() +{ + return m_shared->activeDataProxy()->itemLabelFormat(); +} + +void DeclarativeBars::setSelectedBarPos(const QPointF &position) +{ + m_shared->setSelectedBarPos(position.toPoint()); +} + +QPointF DeclarativeBars::selectedBarPos() const +{ + return QPointF(m_shared->selectedBarPos()); +} + +void DeclarativeBars::mouseDoubleClickEvent(QMouseEvent *event) +{ +#if defined(Q_OS_ANDROID) + m_shared->mouseDoubleClickEvent(event); +#else + Q_UNUSED(event) +#endif +} + +void DeclarativeBars::touchEvent(QTouchEvent *event) +{ +#if defined(Q_OS_ANDROID) + m_shared->touchEvent(event); + update(); +#else + Q_UNUSED(event) +#endif +} + +void DeclarativeBars::mousePressEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mousePressEvent(event, mousePos); +} + +void DeclarativeBars::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseReleaseEvent(event, mousePos); +} + +void DeclarativeBars::mouseMoveEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseMoveEvent(event, mousePos); +} + +void DeclarativeBars::wheelEvent(QWheelEvent *event) +{ + m_shared->wheelEvent(event); +} + +QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativebars_p.h b/src/datavisualizationqml2/declarativebars_p.h new file mode 100644 index 00000000..79ad7884 --- /dev/null +++ b/src/datavisualizationqml2/declarativebars_p.h @@ -0,0 +1,202 @@ +/**************************************************************************** +** +** 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 QtDataVisualization 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 QtDataVisualization 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 DECLARATIVEBARS_P_H +#define DECLARATIVEBARS_P_H + +#include "datavisualizationglobal_p.h" +#include "bars3dcontroller_p.h" +#include "declarativebars_p.h" +#include "q3dvalueaxis.h" +#include "q3dcategoryaxis.h" +#include "qbardataproxy.h" + +#include <QAbstractItemModel> +#include <QQuickItem> +#include <QObject> +#include <QQuickWindow> + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +class DeclarativeBars : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QBarDataProxy *dataProxy READ dataProxy WRITE setDataProxy) + Q_PROPERTY(Q3DCategoryAxis *rowAxis READ rowAxis WRITE setRowAxis) + Q_PROPERTY(Q3DValueAxis *valueAxis READ valueAxis WRITE setValueAxis) + Q_PROPERTY(Q3DCategoryAxis *columnAxis READ columnAxis WRITE setColumnAxis) + Q_PROPERTY(QtDataVisualization::QDataVis::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + Q_PROPERTY(QtDataVisualization::QDataVis::LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) + Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality) + Q_PROPERTY(QtDataVisualization::QDataVis::MeshStyle barType READ barType WRITE setBarType) + Q_PROPERTY(QtDataVisualization::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset) + Q_PROPERTY(QtDataVisualization::QDataVis::ColorTheme theme READ theme WRITE setTheme) + Q_PROPERTY(qreal barThickness READ barThickness WRITE setBarThickness) + Q_PROPERTY(QSizeF barSpacing READ barSpacing WRITE setBarSpacing) + Q_PROPERTY(bool barSpacingRelative READ isBarSpacingRelative WRITE setBarSpacingRelative) + Q_PROPERTY(bool barSmooth READ barSmooth WRITE setBarSmooth) + Q_PROPERTY(QString meshFileName READ meshFileName WRITE setMeshFileName) + 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(int rows READ rows WRITE setRows) + Q_PROPERTY(int columns READ columns WRITE setColumns) + Q_PROPERTY(QString itemLabelFormat READ itemLabelFormat WRITE setItemLabelFormat) + Q_PROPERTY(QPointF selectedBarPos READ selectedBarPos WRITE setSelectedBarPos) + Q_ENUMS(QtDataVisualization::QDataVis::SelectionMode) + Q_ENUMS(QtDataVisualization::QDataVis::ShadowQuality) + Q_ENUMS(QtDataVisualization::QDataVis::LabelTransparency) + Q_ENUMS(QtDataVisualization::QDataVis::MeshStyle) + Q_ENUMS(QtDataVisualization::QDataVis::CameraPreset) + Q_ENUMS(QtDataVisualization::QDataVis::ColorTheme) + +public: + explicit DeclarativeBars(QQuickItem *parent = 0); + ~DeclarativeBars(); + + // how many samples per row and column + Q_INVOKABLE void setDataWindow(int rowCount, int columnCount); + + // Set color if you don't want to use themes. Set uniform to false if you want the (height) + // color to change from bottom to top + Q_INVOKABLE void setBarColor(const QColor &baseColor, const QColor &heightColor, + const QColor &depthColor, bool uniform = true); + + // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and + // vertical (0...90) (or (-90...90) if there are negative values) angles and distance in + // percentage (10...500)) + Q_INVOKABLE void setCameraPosition(qreal horizontal, qreal vertical, int distance); + + QBarDataProxy *dataProxy() const; + void setDataProxy(QBarDataProxy *dataProxy); + + Q3DCategoryAxis *rowAxis() const; + void setRowAxis(Q3DCategoryAxis *axis); + Q3DValueAxis *valueAxis() const; + void setValueAxis(Q3DValueAxis *axis); + Q3DCategoryAxis *columnAxis() const; + void setColumnAxis(Q3DCategoryAxis *axis); + + // Set bar thickness. + void setBarThickness(qreal thicknessRatio); + qreal barThickness(); + + // Set spacing between bars. Y-component sets the spacing of Z-direction. + // If spacing is relative, 0.0f means side-to-side and 1.0f = one thickness in between. + void setBarSpacing(QSizeF spacing); + QSizeF barSpacing(); + + // Set bar spacing relative to thickness or absolute + void setBarSpacingRelative(bool relative); + bool isBarSpacingRelative(); + + // Bar type + void setBarType(QDataVis::MeshStyle style); + QDataVis::MeshStyle barType(); + + // Bar smoothing + void setBarSmooth(bool smooth); + bool barSmooth(); + + // override object type with own mesh + void setMeshFileName(const QString &objFileName); + QString meshFileName(); + + // 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; single bar, bar and row, bar and column, or all + 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(); + + // Adjust shadow quality + void setShadowQuality(QDataVis::ShadowQuality quality); + QDataVis::ShadowQuality shadowQuality(); + + int rows() const; + void setRows(int rows); + + int columns() const; + void setColumns(int columns); + + void setItemLabelFormat(const QString &format); + QString itemLabelFormat(); + + void setSelectedBarPos(const QPointF &position); + QPointF selectedBarPos() const; + +signals: + // Signals shadow quality changes. + void shadowQualityChanged(QDataVis::ShadowQuality quality); + +protected: + Bars3DController *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_DATAVISUALIZATION_END_NAMESPACE + +#endif diff --git a/src/datavisualizationqml2/declarativebarsrenderer.cpp b/src/datavisualizationqml2/declarativebarsrenderer.cpp new file mode 100644 index 00000000..3925e062 --- /dev/null +++ b/src/datavisualizationqml2/declarativebarsrenderer.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 QtDataVisualization 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 "declarativebarsrenderer_p.h" + +#include <QtQuick/QQuickWindow> +#include <QtGui/QOpenGLFramebufferObject> + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +DeclarativeBarsRenderer::DeclarativeBarsRenderer(QQuickWindow *window, Bars3DController *renderer) + : m_fbo(0), + m_texture(0), + m_window(window), + m_barsRenderer(renderer) +{ + connect(m_window, &QQuickWindow::beforeSynchronizing, this, + &DeclarativeBarsRenderer::synchDataToRenderer, Qt::DirectConnection); + connect(m_window, &QQuickWindow::beforeRendering, this, + &DeclarativeBarsRenderer::renderFBO, Qt::DirectConnection); + connect(m_barsRenderer, &Abstract3DController::needRender, m_window, + &QQuickWindow::update); +} + +DeclarativeBarsRenderer::~DeclarativeBarsRenderer() +{ + delete m_texture; + delete m_fbo; +} + +void DeclarativeBarsRenderer::synchDataToRenderer() +{ + m_barsRenderer->initializeOpenGL(); + m_barsRenderer->synchDataToRenderer(); +} + +void DeclarativeBarsRenderer::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); + //qDebug() << "create node" << m_fbo->handle() << m_texture->textureId() << m_fbo->size(); + } + + // Call the shared rendering function + m_fbo->bind(); + + m_barsRenderer->render(m_fbo->handle()); + + m_fbo->release(); +} + +QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativebarsrenderer_p.h b/src/datavisualizationqml2/declarativebarsrenderer_p.h new file mode 100644 index 00000000..3be9b911 --- /dev/null +++ b/src/datavisualizationqml2/declarativebarsrenderer_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 QtDataVisualization 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 QtDataVisualization 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 DECLARATIVEBARSRENDERER_H +#define DECLARATIVEBARSRENDERER_H + +#include "datavisualizationglobal_p.h" +#include "bars3dcontroller_p.h" +#include <qsgsimpletexturenode.h> + +class QOpenGLFramebufferObject; +class QSGTexture; +class QQuickWindow; + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +class DeclarativeBarsRenderer : public QObject, public QSGSimpleTextureNode +{ + Q_OBJECT + +public: + DeclarativeBarsRenderer(QQuickWindow *window, Bars3DController *shared); + ~DeclarativeBarsRenderer(); + +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; + Bars3DController *m_barsRenderer; +}; + +QT_DATAVISUALIZATION_END_NAMESPACE + +#endif diff --git a/src/datavisualizationqml2/declarativescatter.cpp b/src/datavisualizationqml2/declarativescatter.cpp new file mode 100644 index 00000000..dc9ac209 --- /dev/null +++ b/src/datavisualizationqml2/declarativescatter.cpp @@ -0,0 +1,327 @@ +/**************************************************************************** +** +** 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 QtDataVisualization 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 "declarativescatter_p.h" +#include "declarativescatterrenderer_p.h" +#include "qitemmodelscatterdataproxy.h" + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +const QString smoothString(QStringLiteral("Smooth")); + +DeclarativeScatter::DeclarativeScatter(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 Scatter3DController(boundingRect().toRect()); + QObject::connect(m_shared, &Abstract3DController::shadowQualityChanged, this, + &DeclarativeScatter::handleShadowQualityUpdate); + + m_shared->setActiveDataProxy(new QItemModelScatterDataProxy); +} + +DeclarativeScatter::~DeclarativeScatter() +{ + delete m_shared; +} + +void DeclarativeScatter::handleShadowQualityUpdate(QDataVis::ShadowQuality quality) +{ + emit shadowQualityChanged(quality); +} + +QSGNode *DeclarativeScatter::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<DeclarativeScatterRenderer *>( 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 + DeclarativeScatterRenderer *node = new DeclarativeScatterRenderer(window(), m_shared); + node->setRect(boundingRect()); + m_shared->setBoundingRect(boundingRect().toRect()); + return node; +} + +void DeclarativeScatter::setCameraPosition(qreal horizontal, qreal vertical, int distance) +{ + m_shared->setCameraPosition(GLfloat(horizontal), GLfloat(vertical), GLint(distance)); +} + +void DeclarativeScatter::setObjectColor(const QColor &baseColor, const QColor &heightColor, + const QColor &depthColor, bool uniform) +{ + m_shared->setObjectColor(baseColor, heightColor, depthColor, uniform); +} + +QScatterDataProxy *DeclarativeScatter::dataProxy() const +{ + return static_cast<QScatterDataProxy *>(m_shared->activeDataProxy()); +} + +void DeclarativeScatter::setDataProxy(QScatterDataProxy *dataProxy) +{ + m_shared->setActiveDataProxy(dataProxy); +} + +Q3DValueAxis *DeclarativeScatter::axisX() const +{ + return static_cast<Q3DValueAxis *>(m_shared->axisX()); +} + +void DeclarativeScatter::setAxisX(Q3DValueAxis *axis) +{ + m_shared->setAxisX(axis); +} + +Q3DValueAxis *DeclarativeScatter::axisY() const +{ + return static_cast<Q3DValueAxis *>(m_shared->axisY()); +} + +void DeclarativeScatter::setAxisY(Q3DValueAxis *axis) +{ + m_shared->setAxisY(axis); +} + +Q3DValueAxis *DeclarativeScatter::axisZ() const +{ + return static_cast<Q3DValueAxis *>(m_shared->axisZ()); +} + +void DeclarativeScatter::setAxisZ(Q3DValueAxis *axis) +{ + m_shared->setAxisZ(axis); +} + +void DeclarativeScatter::setObjectType(QDataVis::MeshStyle style) +{ + QString objFile = m_shared->meshFileName(); + bool smooth = objFile.endsWith(smoothString); + m_shared->setObjectType(style, smooth); +} + +QDataVis::MeshStyle DeclarativeScatter::objectType() +{ + QString objFile = m_shared->meshFileName(); + if (objFile.contains("/sphere")) + return QDataVis::Spheres; + else + return QDataVis::Dots; +} + +void DeclarativeScatter::setObjectSmooth(bool smooth) +{ + QString objFile = m_shared->meshFileName(); + if (objFile.endsWith(smoothString)) { + if (smooth) + return; // Already smooth; do nothing + else // Rip Smooth off the end + objFile.resize(objFile.indexOf(smoothString)); + } else { + if (!smooth) // Already flat; do nothing + return; + else // Append Smooth to the end + objFile.append(smoothString); + } + m_shared->setMeshFileName(objFile); +} + +bool DeclarativeScatter::objectSmooth() +{ + QString objFile = m_shared->meshFileName(); + return objFile.endsWith(smoothString); +} + +void DeclarativeScatter::setMeshFileName(const QString &objFileName) +{ + m_shared->setMeshFileName(objFileName); +} + +QString DeclarativeScatter::meshFileName() +{ + return m_shared->meshFileName(); +} + +void DeclarativeScatter::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); +} + +QDataVis::CameraPreset DeclarativeScatter::cameraPreset() +{ + return m_cameraPreset; +} + +void DeclarativeScatter::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); + + // TODO: Investigate why the beforeSynchronizing() signal requires update and is not sent automatically when this value changes, + // but is sent wen e.g. enable/disable background changes. + update(); +} + +QDataVis::ColorTheme DeclarativeScatter::theme() +{ + return m_theme; +} + +void DeclarativeScatter::setFont(const QFont &font) +{ + m_shared->setFont(font); +} + +QFont DeclarativeScatter::font() +{ + return m_shared->font(); +} + +void DeclarativeScatter::setLabelTransparency(QDataVis::LabelTransparency transparency) +{ + m_shared->setLabelTransparency(transparency); +} + +QDataVis::LabelTransparency DeclarativeScatter::labelTransparency() +{ + return m_shared->labelTransparency(); +} + +void DeclarativeScatter::setGridVisible(bool visible) +{ + m_shared->setGridEnabled(visible); +} + +bool DeclarativeScatter::isGridVisible() +{ + return m_shared->gridEnabled(); +} + +void DeclarativeScatter::setBackgroundVisible(bool visible) +{ + m_shared->setBackgroundEnabled(visible); +} + +bool DeclarativeScatter::isBackgroundVisible() +{ + return m_shared->backgroundEnabled(); +} + +void DeclarativeScatter::setSelectionMode(QDataVis::SelectionMode mode) +{ + m_shared->setSelectionMode(mode); +} + +QDataVis::SelectionMode DeclarativeScatter::selectionMode() +{ + return m_shared->selectionMode(); +} + +void DeclarativeScatter::setShadowQuality(QDataVis::ShadowQuality quality) +{ + m_shared->setShadowQuality(quality); +} + +QDataVis::ShadowQuality DeclarativeScatter::shadowQuality() +{ + return m_shared->shadowQuality(); +} + +void DeclarativeScatter::setItemLabelFormat(const QString &format) +{ + m_shared->activeDataProxy()->setItemLabelFormat(format); +} + +QString DeclarativeScatter::itemLabelFormat() +{ + return m_shared->activeDataProxy()->itemLabelFormat(); +} + +void DeclarativeScatter::mouseDoubleClickEvent(QMouseEvent *event) +{ +#if defined(Q_OS_ANDROID) + m_shared->mouseDoubleClickEvent(event); +#else + Q_UNUSED(event) +#endif +} + +void DeclarativeScatter::touchEvent(QTouchEvent *event) +{ +#if defined(Q_OS_ANDROID) + m_shared->touchEvent(event); + update(); +#else + Q_UNUSED(event) +#endif +} + +void DeclarativeScatter::mousePressEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mousePressEvent(event, mousePos); +} + +void DeclarativeScatter::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseReleaseEvent(event, mousePos); +} + +void DeclarativeScatter::mouseMoveEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseMoveEvent(event, mousePos); +} + +void DeclarativeScatter::wheelEvent(QWheelEvent *event) +{ + m_shared->wheelEvent(event); +} + +QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativescatter_p.h b/src/datavisualizationqml2/declarativescatter_p.h new file mode 100644 index 00000000..ad6ccb2a --- /dev/null +++ b/src/datavisualizationqml2/declarativescatter_p.h @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** 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 QtDataVisualization 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 QtDataVisualization 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 DECLARATIVESCATTER_P_H +#define DECLARATIVESCATTER_P_H + +#include "datavisualizationglobal_p.h" +#include "scatter3dcontroller_p.h" +#include "declarativescatter_p.h" +#include "q3dvalueaxis.h" +#include "qscatterdataproxy.h" + +#include <QAbstractItemModel> +#include <QQuickItem> +#include <QObject> + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +class DeclarativeScatter : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QScatterDataProxy *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(QtDataVisualization::QDataVis::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + Q_PROPERTY(QtDataVisualization::QDataVis::LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) + Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality) + Q_PROPERTY(QtDataVisualization::QDataVis::MeshStyle objectType READ objectType WRITE setObjectType) + Q_PROPERTY(QtDataVisualization::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset) + Q_PROPERTY(QtDataVisualization::QDataVis::ColorTheme theme READ theme WRITE setTheme) + Q_PROPERTY(bool objectSmooth READ objectSmooth WRITE setObjectSmooth) + Q_PROPERTY(QString meshFileName READ meshFileName WRITE setMeshFileName) + 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(QString itemLabelFormat READ itemLabelFormat WRITE setItemLabelFormat) + Q_ENUMS(QtDataVisualization::QDataVis::SelectionMode) + Q_ENUMS(QtDataVisualization::QDataVis::ShadowQuality) + Q_ENUMS(QtDataVisualization::QDataVis::LabelTransparency) + Q_ENUMS(QtDataVisualization::QDataVis::MeshStyle) + Q_ENUMS(QtDataVisualization::QDataVis::CameraPreset) + Q_ENUMS(QtDataVisualization::QDataVis::ColorTheme) + +public: + explicit DeclarativeScatter(QQuickItem *parent = 0); + ~DeclarativeScatter(); + + // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and + // vertical (-90...90) angles and distance in percentage (10...500)) + Q_INVOKABLE void setCameraPosition(qreal horizontal, qreal vertical, int distance); + + // Set color if you don't want to use themes. Set uniform to false if you want the (height) + // color to change from bottom to top + Q_INVOKABLE void setObjectColor(const QColor &baseColor, const QColor &heightColor, + const QColor &depthColor, bool uniform = true); + + QScatterDataProxy *dataProxy() const; + void setDataProxy(QScatterDataProxy *dataProxy); + + Q3DValueAxis *axisX() const; + void setAxisX(Q3DValueAxis *axis); + Q3DValueAxis *axisY() const; + void setAxisY(Q3DValueAxis *axis); + Q3DValueAxis *axisZ() const; + void setAxisZ(Q3DValueAxis *axis); + + // Object type + void setObjectType(QDataVis::MeshStyle style); + QDataVis::MeshStyle objectType(); + + // Object smoothing + void setObjectSmooth(bool smooth); + bool objectSmooth(); + + // override object type with own mesh + void setMeshFileName(const QString &objFileName); + QString meshFileName(); + + // 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(); + + void setItemLabelFormat(const QString &format); + QString itemLabelFormat(); + + // Adjust shadow quality + void setShadowQuality(QDataVis::ShadowQuality quality); + QDataVis::ShadowQuality shadowQuality(); + +signals: + // Signals shadow quality changes. + void shadowQualityChanged(QDataVis::ShadowQuality quality); + +protected: + Scatter3DController *m_shared; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); + + // Used to detect when shadow quality changes autonomously due to e.g. resizing. + void handleShadowQualityUpdate(QDataVis::ShadowQuality quality); + + 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_DATAVISUALIZATION_END_NAMESPACE + +#endif diff --git a/src/datavisualizationqml2/declarativescatterrenderer.cpp b/src/datavisualizationqml2/declarativescatterrenderer.cpp new file mode 100644 index 00000000..39aaa22e --- /dev/null +++ b/src/datavisualizationqml2/declarativescatterrenderer.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 QtDataVisualization 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 "declarativescatterrenderer_p.h" + +#include <QtQuick/QQuickWindow> +#include <QtGui/QOpenGLFramebufferObject> + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +DeclarativeScatterRenderer::DeclarativeScatterRenderer(QQuickWindow *window, + Scatter3DController *renderer) + : m_fbo(0), + m_texture(0), + m_window(window), + m_scatterRenderer(renderer) +{ + connect(m_window, &QQuickWindow::beforeSynchronizing, this, + &DeclarativeScatterRenderer::synchDataToRenderer, Qt::DirectConnection); + connect(m_window, &QQuickWindow::beforeRendering, this, + &DeclarativeScatterRenderer::renderFBO, Qt::DirectConnection); + connect(m_scatterRenderer, &Abstract3DController::needRender, m_window, + &QQuickWindow::update); +} + +DeclarativeScatterRenderer::~DeclarativeScatterRenderer() +{ + delete m_texture; + delete m_fbo; +} + +void DeclarativeScatterRenderer::synchDataToRenderer() +{ + m_scatterRenderer->initializeOpenGL(); + m_scatterRenderer->synchDataToRenderer(); +} + +void DeclarativeScatterRenderer::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); + //qDebug() << "create node" << m_fbo->handle() << m_texture->textureId() << m_fbo->size(); + } + + // Call the shared rendering function + m_fbo->bind(); + + m_scatterRenderer->render(m_fbo->handle()); + + m_fbo->release(); +} + +QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativescatterrenderer_p.h b/src/datavisualizationqml2/declarativescatterrenderer_p.h new file mode 100644 index 00000000..0bbd01ec --- /dev/null +++ b/src/datavisualizationqml2/declarativescatterrenderer_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 QtDataVisualization 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 QtDataVisualization 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 DECLARATIVESCATTERRENDERER_P_H +#define DECLARATIVESCATTERRENDERER_P_H + +#include "datavisualizationglobal_p.h" +#include "scatter3dcontroller_p.h" +#include <qsgsimpletexturenode.h> + +class QOpenGLFramebufferObject; +class QSGTexture; +class QQuickWindow; + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +class DeclarativeScatterRenderer : public QObject, public QSGSimpleTextureNode +{ + Q_OBJECT + +public: + DeclarativeScatterRenderer(QQuickWindow *window, Scatter3DController *shared); + ~DeclarativeScatterRenderer(); + +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; + Scatter3DController *m_scatterRenderer; +}; + +QT_DATAVISUALIZATION_END_NAMESPACE + +#endif diff --git a/src/datavisualizationqml2/declarativesurface.cpp b/src/datavisualizationqml2/declarativesurface.cpp new file mode 100644 index 00000000..7597bef0 --- /dev/null +++ b/src/datavisualizationqml2/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 QtDataVisualization 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_DATAVISUALIZATION_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<DeclarativeSurfaceRenderer *>( 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<QSurfaceDataProxy *>(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<Q3DValueAxis *>(m_shared->axisX()); +} + +void DeclarativeSurface::setAxisX(Q3DValueAxis *axis) +{ + m_shared->setAxisX(axis); +} + +Q3DValueAxis *DeclarativeSurface::axisY() const +{ + return static_cast<Q3DValueAxis *>(m_shared->axisY()); +} + +void DeclarativeSurface::setAxisY(Q3DValueAxis *axis) +{ + m_shared->setAxisY(axis); +} + +Q3DValueAxis *DeclarativeSurface::axisZ() const +{ + return static_cast<Q3DValueAxis *>(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_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativesurface_p.h b/src/datavisualizationqml2/declarativesurface_p.h new file mode 100644 index 00000000..c6aae7c0 --- /dev/null +++ b/src/datavisualizationqml2/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 QtDataVisualization 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 QtDataVisualization 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 "datavisualizationglobal_p.h" +#include "surface3dcontroller_p.h" +#include "declarativesurface_p.h" +#include "q3dvalueaxis.h" +#include "qsurfacedataproxy.h" + +#include <QAbstractItemModel> +#include <QQuickItem> +#include <QObject> +#include <QQuickWindow> + +QT_DATAVISUALIZATION_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(QtDataVisualization::QDataVis::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + Q_PROPERTY(QtDataVisualization::QDataVis::LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) + Q_PROPERTY(QtDataVisualization::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality) + Q_PROPERTY(QtDataVisualization::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset) + Q_PROPERTY(QtDataVisualization::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(QtDataVisualization::QDataVis::SelectionMode) + Q_ENUMS(QtDataVisualization::QDataVis::ShadowQuality) + Q_ENUMS(QtDataVisualization::QDataVis::LabelTransparency) + Q_ENUMS(QtDataVisualization::QDataVis::CameraPreset) + Q_ENUMS(QtDataVisualization::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_DATAVISUALIZATION_END_NAMESPACE + +#endif diff --git a/src/datavisualizationqml2/declarativesurfacerenderer.cpp b/src/datavisualizationqml2/declarativesurfacerenderer.cpp new file mode 100644 index 00000000..87a290ce --- /dev/null +++ b/src/datavisualizationqml2/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 QtDataVisualization 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 <QtQuick/QQuickWindow> +#include <QtGui/QOpenGLFramebufferObject> + +QT_DATAVISUALIZATION_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_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativesurfacerenderer_p.h b/src/datavisualizationqml2/declarativesurfacerenderer_p.h new file mode 100644 index 00000000..09128f59 --- /dev/null +++ b/src/datavisualizationqml2/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 QtDataVisualization 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 QtDataVisualization 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 "datavisualizationglobal_p.h" +#include "surface3dcontroller_p.h" +#include <qsgsimpletexturenode.h> + +class QOpenGLFramebufferObject; +class QSGTexture; +class QQuickWindow; + +QT_DATAVISUALIZATION_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_DATAVISUALIZATION_END_NAMESPACE + +#endif diff --git a/src/datavisualizationqml2/qmldir b/src/datavisualizationqml2/qmldir new file mode 100644 index 00000000..1def2238 --- /dev/null +++ b/src/datavisualizationqml2/qmldir @@ -0,0 +1,3 @@ +module com.digia.QtDataVisualization +plugin datavisualizationqml2 + |