diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/datavis3d/data/data.pri | 12 | ||||
-rw-r--r-- | src/datavis3d/data/qabstractdatamapping.h | 1 | ||||
-rw-r--r-- | src/datavis3d/data/qitemmodelsurfacedatamapping.cpp | 223 | ||||
-rw-r--r-- | src/datavis3d/data/qitemmodelsurfacedatamapping.h | 76 | ||||
-rw-r--r-- | src/datavis3d/data/qitemmodelsurfacedatamapping_p.h | 58 | ||||
-rw-r--r-- | src/datavis3d/data/qitemmodelsurfacedataproxy.cpp | 161 | ||||
-rw-r--r-- | src/datavis3d/data/qitemmodelsurfacedataproxy.h | 62 | ||||
-rw-r--r-- | src/datavis3d/data/qitemmodelsurfacedataproxy_p.h | 58 | ||||
-rw-r--r-- | src/datavis3d/data/surfaceitemmodelhandler.cpp | 94 | ||||
-rw-r--r-- | src/datavis3d/data/surfaceitemmodelhandler_p.h | 52 | ||||
-rw-r--r-- | src/datavis3dqml2/datavis3dqml2.pro | 8 | ||||
-rw-r--r-- | src/datavis3dqml2/datavis3dqml2_plugin.cpp | 13 | ||||
-rw-r--r-- | src/datavis3dqml2/datavis3dqml2_plugin.h | 13 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativesurface.cpp | 288 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativesurface_p.h | 156 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativesurfacerenderer.cpp | 87 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativesurfacerenderer_p.h | 65 |
17 files changed, 1417 insertions, 10 deletions
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<QItemModelSurfaceDataMappingPrivate *>(d_ptr.data()); +} + +/*! + * \internal + */ +const QItemModelSurfaceDataMappingPrivate *QItemModelSurfaceDataMapping::dptrc() const +{ + return static_cast<const QItemModelSurfaceDataMappingPrivate *>(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 <QtDataVis3D/qdatavis3denums.h> +#include <QtDataVis3D/qabstractdatamapping.h> +#include <QStringList> + +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 <QTimer> + +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<QItemModelSurfaceDataMapping *>(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<QItemModelSurfaceDataMapping *> QItemModelSurfaceDataProxy::mappings() const +{ + QList<QItemModelSurfaceDataMapping *> retList; + QList<QAbstractDataMapping *> abstractList = dptrc()->m_itemModelHandler->mappings(); + foreach (QAbstractDataMapping *mapping, abstractList) + retList.append(static_cast<QItemModelSurfaceDataMapping *>(mapping)); + + return retList; +} + +/*! + * \internal + */ +QItemModelSurfaceDataProxyPrivate *QItemModelSurfaceDataProxy::dptr() +{ + return static_cast<QItemModelSurfaceDataProxyPrivate *>(d_ptr.data()); +} + +/*! + * \internal + */ +const QItemModelSurfaceDataProxyPrivate *QItemModelSurfaceDataProxy::dptrc() const +{ + return static_cast<const QItemModelSurfaceDataProxyPrivate *>(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<QItemModelSurfaceDataProxy *>(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 <QtDataVis3D/qsurfacedataproxy.h> +#include <QtDataVis3D/qitemmodelsurfacedatamapping.h> +#include <QAbstractItemModel> +#include <QStringList> + +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<QItemModelSurfaceDataMapping *> 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 <QPointer> +#include <QTimer> + +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 <QTimer> + +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<QItemModelSurfaceDataMapping *>(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<int, QByteArray> 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<QString, qreal> ColumnValueMap; + QHash <QString, ColumnValueMap> 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<const QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", - QLatin1String("Trying to create uncreatable: 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.")); + QLatin1String("Trying to create uncreatable: AbstractAxis.")); qmlRegisterUncreatableType<QAbstractDataProxy>(uri, 1, 0, "AbstractDataProxy", - QLatin1String("Trying to create uncreatable: 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.")); + 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_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 <QQmlExtensionPlugin> @@ -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<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_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 <QAbstractItemModel> +#include <QQuickItem> +#include <QObject> +#include <QQuickWindow> + +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 <QtQuick/QQuickWindow> +#include <QtGui/QOpenGLFramebufferObject> + +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 <qsgsimpletexturenode.h> + +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 |