From 6880277f23b47117f7788f08f855ed99b5120f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Mon, 12 May 2014 10:06:27 +0300 Subject: CustomDataItem made into a public class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTRD-3055 Change-Id: I1e449df7c1bcb48fc639dbae579e2e1499c9ef2b Reviewed-by: Tomi Korpipää --- .../customitems/customitemgraph.cpp | 38 +-- .../customitems/doc/src/customitems.qdoc | 11 +- src/datavisualization/data/customdataitem.cpp | 47 ---- src/datavisualization/data/customdataitem_p.h | 66 ----- src/datavisualization/data/data.pri | 5 +- src/datavisualization/data/qcustom3ditem.cpp | 274 +++++++++++++++++++++ src/datavisualization/data/qcustom3ditem.h | 84 +++++++ src/datavisualization/data/qcustom3ditem_p.h | 63 +++++ ...tdatavisualization-qml-abstractdeclarative.qdoc | 33 ++- .../engine/abstract3dcontroller.cpp | 60 +++-- .../engine/abstract3dcontroller_p.h | 11 +- .../engine/abstract3drenderer.cpp | 25 +- .../engine/abstract3drenderer_p.h | 4 +- src/datavisualization/engine/qabstract3dgraph.cpp | 42 ++-- src/datavisualization/engine/qabstract3dgraph.h | 8 +- src/datavisualizationqml2/abstractdeclarative.cpp | 51 +++- src/datavisualizationqml2/abstractdeclarative_p.h | 17 +- .../datavisualizationqml2_plugin.cpp | 5 +- .../datavisualizationqml2_plugin.h | 3 + src/datavisualizationqml2/declarativebars_p.h | 1 - src/datavisualizationqml2/declarativecolor.cpp | 2 + src/datavisualizationqml2/declarativetheme.cpp | 8 +- src/datavisualizationqml2/declarativetheme_p.h | 8 +- tests/qmlcamera/qml/qmlcamera/main.qml | 31 ++- 24 files changed, 637 insertions(+), 260 deletions(-) delete mode 100644 src/datavisualization/data/customdataitem.cpp delete mode 100644 src/datavisualization/data/customdataitem_p.h create mode 100644 src/datavisualization/data/qcustom3ditem.cpp create mode 100644 src/datavisualization/data/qcustom3ditem.h create mode 100644 src/datavisualization/data/qcustom3ditem_p.h diff --git a/examples/datavisualization/customitems/customitemgraph.cpp b/examples/datavisualization/customitems/customitemgraph.cpp index 822ca24a..c2479a9a 100644 --- a/examples/datavisualization/customitems/customitemgraph.cpp +++ b/examples/datavisualization/customitems/customitemgraph.cpp @@ -19,6 +19,7 @@ #include "customitemgraph.h" #include +#include #include using namespace QtDataVisualization; @@ -104,15 +105,18 @@ void CustomItemGraph::toggleItemOne(bool show) color.fill(Qt::red); //! [0] //! [2] - m_graph->addCustomItem(":/items/oilrig.obj", positionOne, - QVector3D(0.025f, 0.025f, 0.025f), - QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 45.0f), - color); + QCustom3DItem *item = new QCustom3DItem(":/items/oilrig.obj", positionOne, + QVector3D(0.025f, 0.025f, 0.025f), + QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 45.0f), + color); //! [2] - } else { //! [3] - m_graph->removeCustomItemAt(positionOne); + m_graph->addCustomItem(item); //! [3] + } else { + //! [4] + m_graph->removeCustomItemAt(positionOne); + //! [4] } } @@ -122,10 +126,13 @@ void CustomItemGraph::toggleItemTwo(bool show) if (show) { QImage color = QImage(2, 2, QImage::Format_ARGB32); color.fill(Qt::red); - m_graph->addCustomItem(":/items/oilrig.obj", positionTwo, - QVector3D(0.025f, 0.025f, 0.025f), - QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 25.0f), - color); + QCustom3DItem *item = new QCustom3DItem(); + item->setMeshFile(":/items/oilrig.obj"); + item->setPosition(positionTwo); + item->setScaling(QVector3D(0.025f, 0.025f, 0.025f)); + item->setRotation(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 25.0f)); + item->setTextureImage(color); + m_graph->addCustomItem(item); } else { m_graph->removeCustomItemAt(positionTwo); } @@ -137,10 +144,13 @@ void CustomItemGraph::toggleItemThree(bool show) if (show) { QImage color = QImage(2, 2, QImage::Format_ARGB32); color.fill(Qt::darkMagenta); - m_graph->addCustomItem(":/items/refinery.obj", positionThree, - QVector3D(0.04f, 0.04f, 0.04f), - QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 75.0f), - color); + QCustom3DItem *item = new QCustom3DItem(); + item->setMeshFile(":/items/refinery.obj"); + item->setPosition(positionThree); + item->setScaling(QVector3D(0.04f, 0.04f, 0.04f)); + item->setRotation(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 75.0f)); + item->setTextureImage(color); + m_graph->addCustomItem(item); } else { m_graph->removeCustomItemAt(positionThree); } diff --git a/examples/datavisualization/customitems/doc/src/customitems.qdoc b/examples/datavisualization/customitems/doc/src/customitems.qdoc index 1878609b..d034019a 100644 --- a/examples/datavisualization/customitems/doc/src/customitems.qdoc +++ b/examples/datavisualization/customitems/doc/src/customitems.qdoc @@ -53,16 +53,19 @@ \snippet customitems/customitemgraph.cpp 1 - And finally we'll just add the item to the wanted position with the scale and rotation we want: + Then we'll create a new QCustom3DItem with all the parameters: \snippet customitems/customitemgraph.cpp 2 + And finally we'll just add the item: + + \snippet customitems/customitemgraph.cpp 3 + \section1 Removing custom item from a graph - We'll just call \c removeCustomItemAt() with the position - of the item: + We'll just call \c removeCustomItemAt() with the position of the item: - \snippet customitems/customitemgraph.cpp 3 + \snippet customitems/customitemgraph.cpp 4 \section1 Example Contents */ diff --git a/src/datavisualization/data/customdataitem.cpp b/src/datavisualization/data/customdataitem.cpp deleted file mode 100644 index d5964c62..00000000 --- a/src/datavisualization/data/customdataitem.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 "customdataitem_p.h" -#include "objecthelper_p.h" -#include "texturehelper_p.h" - -QT_BEGIN_NAMESPACE_DATAVISUALIZATION - -CustomDataItem::CustomDataItem() : - m_textureHelper(0), - m_texture(0) -{ - m_textureHelper = new TextureHelper(); -} - -CustomDataItem::~CustomDataItem() -{ - m_textureHelper->deleteTexture(&m_texture); - delete m_textureHelper; -} - -void CustomDataItem::setTextureImage(const QImage &textureImage) -{ - m_textureHelper->deleteTexture(&m_texture); - - // Make a texture out of the image - if (!textureImage.isNull()) - m_texture = m_textureHelper->create2DTexture(textureImage, true, true, true); -} - -QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/data/customdataitem_p.h b/src/datavisualization/data/customdataitem_p.h deleted file mode 100644 index c077a17a..00000000 --- a/src/datavisualization/data/customdataitem_p.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 CUSTOMDATAITEM_P_H -#define CUSTOMDATAITEM_P_H - -#include "datavisualizationglobal_p.h" - -QT_BEGIN_NAMESPACE_DATAVISUALIZATION - -class TextureHelper; - -class QT_DATAVISUALIZATION_EXPORT CustomDataItem -{ -public: - CustomDataItem(); - virtual ~CustomDataItem(); - - inline void setMeshFile(const QString &meshFile) { m_meshFile = meshFile; } - inline QString meshFile() { return m_meshFile;} - void setTextureImage(const QImage &textureImage); - inline GLuint texture() { return m_texture; } - inline void setPosition(const QVector3D &position) { m_position = position; } - inline QVector3D position() { return m_position; } - inline void setScaling(const QVector3D &scaling) { m_scaling = scaling; } - inline QVector3D scaling() { return m_scaling; } - inline void setRotation(const QQuaternion &rotation) { m_rotation = rotation; } - inline QQuaternion rotation() { return m_rotation; } - -private: - TextureHelper *m_textureHelper; - GLuint m_texture; - QString m_meshFile; - QVector3D m_position; - QVector3D m_scaling; - QQuaternion m_rotation; -}; - -QT_END_NAMESPACE_DATAVISUALIZATION - -#endif diff --git a/src/datavisualization/data/data.pri b/src/datavisualization/data/data.pri index d3d67076..ca139984 100644 --- a/src/datavisualization/data/data.pri +++ b/src/datavisualization/data/data.pri @@ -38,7 +38,8 @@ HEADERS += \ $$PWD/qsurface3dseries.h \ $$PWD/qsurface3dseries_p.h \ $$PWD/customrenderitem_p.h \ - $$PWD/customdataitem_p.h + $$PWD/qcustom3ditem.h \ + $$PWD/qcustom3ditem_p.h SOURCES += \ $$PWD/labelitem.cpp \ @@ -65,4 +66,4 @@ SOURCES += \ $$PWD/qscatter3dseries.cpp \ $$PWD/qsurface3dseries.cpp \ $$PWD/customrenderitem.cpp \ - $$PWD/customdataitem.cpp + $$PWD/qcustom3ditem.cpp diff --git a/src/datavisualization/data/qcustom3ditem.cpp b/src/datavisualization/data/qcustom3ditem.cpp new file mode 100644 index 00000000..69da30bf --- /dev/null +++ b/src/datavisualization/data/qcustom3ditem.cpp @@ -0,0 +1,274 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 "qcustom3ditem_p.h" +#include "objecthelper_p.h" +#include "texturehelper_p.h" + +QT_BEGIN_NAMESPACE_DATAVISUALIZATION + +/*! + * \class QCustom3DItem + * \inmodule QtDataVisualization + * \brief The QCustom3DItem class is for creating custom items to be added to a graph. + * \since Qt Data Visualization 1.1 + * + * This class is for creating custom items to be added to a graph. The item has a custom mesh, + * position, scaling, rotation, and an optional texture. + * + * \sa QAbstract3DGraph::addCustomItem() + */ + +/*! + * \qmltype Custom3DItem + * \inqmlmodule QtDataVisualization + * \since QtDataVisualization 1.1 + * \ingroup datavisualization_qml + * \instantiates QCustom3DItem + * \brief The Custom3DItem type is for creating custom items to be added to a graph. + * + * This type is for creating custom items to be added to a graph. The item has a custom mesh, + * position, scaling, rotation, and an optional texture. + */ + +/*! \qmlproperty string Custom3DItem::meshFile + * + * Holds item mesh file name. Item in the file must be in Wavefront obj format and include + * vertices, normals, and UVs. It also needs to be in triangles. + */ + +/*! \qmlproperty string Custom3DItem::textureFile + * + * Holds the texture file name for the item. If left unset, a solid gray texture will be + * used. + */ + +// TODO: Position check in task QTRD-3057 +/*! \qmlproperty vector3d Custom3DItem::position + * + * Holds the item \a position as a vector3d. Item position is in data coordinates. Defaults to + * \c {vector3d(0.0, 0.0, 0.0)}. + * + * \note No validity checks are made for the position of the item, so it is up to the user to + * provide a valid position. Items positioned outside axis ranges are still rendered. + */ + +/*! \qmlproperty vector3d Custom3DItem::scaling + * + * Holds the item \a scaling as a vector3d. Defaults to \c {vector3d(0.1, 0.1, 0.1)}. + */ + +/*! \qmlproperty quaternion Custom3DItem::rotation + * + * Holds the item \a rotation as a quaternion. Defaults to \c {quaternion(0.0, 0.0, 0.0, 0.0)}. + */ + +/*! + * \qmlmethod void Custom3DItem::setRotationAxisAndAngle(vector3d axis, real angle) + * + * A convenience function to construct rotation quaternion from \a axis and \a angle. + * + * \sa rotation + */ + +/*! + * Constructs QCustom3DItem with given \a parent. + */ +QCustom3DItem::QCustom3DItem(QObject *parent) : + d_ptr(new QCustom3DItemPrivate(this, parent)) +{ +} + +/*! + * Constructs QCustom3DItem with given \a meshFile, \a position, \a scaling, + * \a rotation, \a texture image, and optional \a parent. + */ +QCustom3DItem::QCustom3DItem(const QString &meshFile, const QVector3D &position, + const QVector3D &scaling, const QQuaternion &rotation, + const QImage &texture, QObject *parent) : + d_ptr(new QCustom3DItemPrivate(this, meshFile, position, scaling, rotation, parent)) +{ + setTextureImage(texture); +} + +/*! + * Destroys QCustom3DItem. + */ +QCustom3DItem::~QCustom3DItem() +{ +} + +/*! \property QCustom3DItem::meshFile + * + * Holds item mesh file name. Item in the file must be in Wavefront obj format and include + * vertices, normals, and UVs. It also needs to be in triangles. + */ +void QCustom3DItem::setMeshFile(const QString &meshFile) +{ + if (d_ptr->m_meshFile != meshFile) { + d_ptr->m_meshFile = meshFile; + emit meshFileChanged(meshFile); + } +} + +QString QCustom3DItem::meshFile() +{ + return d_ptr->m_meshFile; +} + +/*! \property QCustom3DItem::position + * + * Holds the item \a position as a QVector3D. Item position is in data coordinates. Defaults to + * \c {QVector3D(0.0, 0.0, 0.0)}. + * + * \note No validity checks are made for the position of the item, so it is up to the user to + * provide a valid position. Items positioned outside axis ranges are still rendered. + */ +void QCustom3DItem::setPosition(const QVector3D &position) +{ + if (d_ptr->m_position != position) { + d_ptr->m_position = position; + emit positionChanged(position); + } +} + +QVector3D QCustom3DItem::position() +{ + return d_ptr->m_position; +} + +/*! \property QCustom3DItem::scaling + * + * Holds the item \a scaling as a QVector3D. Defaults to \c {QVector3D(0.1, 0.1, 0.1)}. + */ +void QCustom3DItem::setScaling(const QVector3D &scaling) +{ + if (d_ptr->m_scaling != scaling) { + d_ptr->m_scaling = scaling; + emit scalingChanged(scaling); + } +} + +QVector3D QCustom3DItem::scaling() +{ + return d_ptr->m_scaling; +} + +/*! \property QCustom3DItem::rotation + * + * Holds the item \a rotation as a QQuaternion. Defaults to \c {QQuaternion(0.0, 0.0, 0.0, 0.0)}. + */ +void QCustom3DItem::setRotation(const QQuaternion &rotation) +{ + if (d_ptr->m_rotation != rotation) { + d_ptr->m_rotation = rotation; + emit rotationChanged(rotation); + } +} + +QQuaternion QCustom3DItem::rotation() +{ + return d_ptr->m_rotation; +} + +/*! + * A convenience function to construct rotation quaternion from \a axis and \a angle. + * + * \sa rotation + */ +void QCustom3DItem::setRotationAxisAndAngle(const QVector3D &axis, float angle) +{ + setRotation(QQuaternion::fromAxisAndAngle(axis, angle)); +} + +/*! + * Set the \a textureImage as a QImage for the item. Texture defaults to solid gray. + */ +void QCustom3DItem::setTextureImage(const QImage &textureImage) +{ + if (textureImage.isNull()) { + // Make a solid gray texture + d_ptr->m_textureImage = QImage(2, 2, QImage::Format_ARGB32); + d_ptr->m_textureImage.fill(Qt::gray); + } else { + d_ptr->m_textureImage = textureImage; + } + + if (!d_ptr->m_textureFile.isEmpty()) { + d_ptr->m_textureFile.clear(); + emit textureFileChanged(d_ptr->m_textureFile); + } +} + +/*! \property QCustom3DItem::textureFile + * + * Holds the texture file name for the item. If both this and textureImage are unset, a solid + * gray texture will be used. + */ +void QCustom3DItem::setTextureFile(const QString &textureFile) +{ + if (d_ptr->m_textureFile != textureFile) { + d_ptr->m_textureFile = textureFile; + if (!textureFile.isEmpty()) { + d_ptr->m_textureImage = QImage(textureFile); + } else { + d_ptr->m_textureImage = QImage(2, 2, QImage::Format_ARGB32); + d_ptr->m_textureImage.fill(Qt::gray); + } + emit textureFileChanged(textureFile); + } +} + +QString QCustom3DItem::textureFile() +{ + return d_ptr->m_textureFile; +} + +QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, QObject *parent) : + QObject(parent), + q_ptr(q) +{ +} + +QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, const QString &meshFile, + const QVector3D &position, const QVector3D &scaling, + const QQuaternion &rotation, QObject *parent) : + QObject(parent), + q_ptr(q), + m_meshFile(meshFile), + m_position(position), + m_scaling(scaling), + m_rotation(rotation) +{ +} + +QCustom3DItemPrivate::~QCustom3DItemPrivate() +{ +} + +QImage QCustom3DItemPrivate::textureImage() +{ + return m_textureImage; +} + +void QCustom3DItemPrivate::clearTextureImage() +{ + m_textureImage = QImage(); +} + +QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/data/qcustom3ditem.h b/src/datavisualization/data/qcustom3ditem.h new file mode 100644 index 00000000..394c51d7 --- /dev/null +++ b/src/datavisualization/data/qcustom3ditem.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 QCUSTOM3DITEM_H +#define QCUSTOM3DITEM_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE_DATAVISUALIZATION + +class QCustom3DItemPrivate; + +class QT_DATAVISUALIZATION_EXPORT QCustom3DItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString meshFile READ meshFile WRITE setMeshFile NOTIFY meshFileChanged) + Q_PROPERTY(QString textureFile READ textureFile WRITE setTextureFile NOTIFY textureFileChanged) + Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(QVector3D scaling READ scaling WRITE setScaling NOTIFY scalingChanged) + Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged) + +public: + explicit QCustom3DItem(QObject *parent = 0); + explicit QCustom3DItem(const QString &meshFile, const QVector3D &position, + const QVector3D &scaling, const QQuaternion &rotation, + const QImage &texture, QObject *parent = 0); + virtual ~QCustom3DItem(); + + void setMeshFile(const QString &meshFile); + QString meshFile(); + + void setTextureFile(const QString &textureFile); + QString textureFile(); + + void setPosition(const QVector3D &position); + QVector3D position(); + + void setScaling(const QVector3D &scaling); + QVector3D scaling(); + + void setRotation(const QQuaternion &rotation); + QQuaternion rotation(); + + Q_INVOKABLE void setRotationAxisAndAngle(const QVector3D &axis, float angle); + + void setTextureImage(const QImage &textureImage); + +signals: + void meshFileChanged(const QString &meshFile); + void textureFileChanged(const QString &textureFile); + void positionChanged(const QVector3D &position); + void scalingChanged(const QVector3D &scaling); + void rotationChanged(const QQuaternion &rotation); + +protected: + QScopedPointer d_ptr; + +private: + Q_DISABLE_COPY(QCustom3DItem) + + friend class Abstract3DRenderer; +}; + +QT_END_NAMESPACE_DATAVISUALIZATION + +#endif diff --git a/src/datavisualization/data/qcustom3ditem_p.h b/src/datavisualization/data/qcustom3ditem_p.h new file mode 100644 index 00000000..77062768 --- /dev/null +++ b/src/datavisualization/data/qcustom3ditem_p.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 QCUSTOM3DITEM_P_H +#define QCUSTOM3DITEM_P_H + +#include "qcustom3ditem.h" + +QT_BEGIN_NAMESPACE_DATAVISUALIZATION + +class QCustom3DItemPrivate : public QObject +{ + Q_OBJECT +public: + QCustom3DItemPrivate(QCustom3DItem *q, QObject *parent); + QCustom3DItemPrivate(QCustom3DItem *q, const QString &meshFile, const QVector3D &position, + const QVector3D &scaling, const QQuaternion &rotation, QObject *parent); + virtual ~QCustom3DItemPrivate(); + + QImage textureImage(); + void clearTextureImage(); + +public: + QCustom3DItem *q_ptr; + QImage m_textureImage; + QString m_textureFile; + QString m_meshFile; + QVector3D m_position; + QVector3D m_scaling; + QQuaternion m_rotation; + +private: + friend class QCustom3DItem; +}; + +QT_END_NAMESPACE_DATAVISUALIZATION + +#endif diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc index 36c812f1..4d0b8212 100644 --- a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc +++ b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc @@ -150,30 +150,30 @@ */ /*! - * \qmlmethod int AbstractGraph3D::addCustomItem(string meshFile, vector3d position, vector3d scaling, quaternion rotation, string textureFile) + * \qmlmethod int AbstractGraph3D::addCustomItem(Custom3DItem item) * - * Adds a custom mesh item located in \a meshFile to a graph at \a position with \a {scaling}, - * \a rotation and optional image for a texture located at \a textureFile. Item must be in - * Wavefront obj format and include vertices, normals and UVs. It also needs to be in triangles. - * Item position is given in data coordinates. + * Adds a Custom3DItem \a item to the graph. Graph takes ownership of the added item. * - * \return index to the added item. + * \return index to the added item if add was successful, -1 if trying to add a null item, and + * index of the item if trying to add an already added item. * - * \note No validity checks are made for the position of the item, so it is up to the user to - * provide a valid position. Items positioned outside axis ranges are still rendered. - * - * \sa removeCustomItemAt() + * \sa removeCustomItems(), removeCustomItem(), removeCustomItemAt() * * \since Qt Data Visualization 1.1 */ /*! - * \qmlmethod void AbstractGraph3D::removeCustomItemAt(int index) + * \qmlmethod void AbstractGraph3D::removeCustomItems() * - * Removes the custom item at \a {index}. Deletes the resources allocated to it. + * Removes all custom items. Deletes the resources allocated to them. * - * \note The index of the remaining items will change if the item removed is other than - * the last. + * \since Qt Data Visualization 1.1 + */ + +/*! + * \qmlmethod void AbstractGraph3D::removeCustomItem(Custom3DItem item) + * + * Removes the custom \a {item}. Deletes the resources allocated to it. * * \since Qt Data Visualization 1.1 */ @@ -181,10 +181,7 @@ /*! * \qmlmethod void AbstractGraph3D::removeCustomItemAt(vector3d position) * - * Removes the custom item at \a {position}. Deletes the resources allocated to it. - * - * \note The index of the remaining items will change if an item is removed from a position that - * is not at the last index. + * Removes all custom items at \a {position}. Deletes the resources allocated to them. * * \since Qt Data Visualization 1.1 */ diff --git a/src/datavisualization/engine/abstract3dcontroller.cpp b/src/datavisualization/engine/abstract3dcontroller.cpp index 2b566a91..790a0889 100644 --- a/src/datavisualization/engine/abstract3dcontroller.cpp +++ b/src/datavisualization/engine/abstract3dcontroller.cpp @@ -88,7 +88,7 @@ Abstract3DController::~Abstract3DController() destroyRenderer(); delete m_scene; delete m_themeManager; - foreach (CustomDataItem *item, m_customItems) + foreach (QCustom3DItem *item, m_customItems) delete item; m_customItems.clear(); } @@ -851,46 +851,52 @@ void Abstract3DController::requestRender(QOpenGLFramebufferObject *fbo) m_renderer->render(fbo->handle()); } -int Abstract3DController::addCustomItem(const QString &meshFile, const QVector3D &position, - const QVector3D &scaling, const QQuaternion &rotation, - const QImage &textureImage) +int Abstract3DController::addCustomItem(QCustom3DItem *item) { - CustomDataItem *newItem = new CustomDataItem(); - newItem->setMeshFile(meshFile); - newItem->setPosition(position); - newItem->setScaling(scaling); - newItem->setRotation(rotation); - newItem->setTextureImage(textureImage); - m_customItems.append(newItem); + if (!item) + return -1; + + int index = m_customItems.indexOf(item); + + if (index != -1) + return index; + + item->setParent(this); + m_customItems.append(item); m_isCustomDataDirty = true; emitNeedRender(); return m_customItems.count() - 1; } -void Abstract3DController::deleteCustomItem(int index) +void Abstract3DController::deleteCustomItems() { - if (m_customItems.size() > index) { - delete m_customItems[index]; - m_customItems.removeAt(index); - m_isCustomDataDirty = true; - emitNeedRender(); - } + foreach (QCustom3DItem *item, m_customItems) + delete item; + m_customItems.clear(); + m_isCustomDataDirty = true; + emitNeedRender(); +} + +void Abstract3DController::deleteCustomItem(QCustom3DItem *item) +{ + if (!item) + return; + + m_customItems.removeOne(item); + delete item; + item = 0; + m_isCustomDataDirty = true; + emitNeedRender(); } void Abstract3DController::deleteCustomItem(const QVector3D &position) { - int index = -1; - int counter = 0; - // Get the index for the item at position - foreach (CustomDataItem *item, m_customItems) { + // Get the item for the position + foreach (QCustom3DItem *item, m_customItems) { if (item->position() == position) { - index = counter; - break; + deleteCustomItem(item); } - counter++; } - if (index >= 0) - deleteCustomItem(index); } void Abstract3DController::handleAxisTitleChanged(const QString &title) diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h index 78c6c81c..53560760 100644 --- a/src/datavisualization/engine/abstract3dcontroller_p.h +++ b/src/datavisualization/engine/abstract3dcontroller_p.h @@ -35,7 +35,7 @@ #include "qabstract3dinputhandler.h" #include "qabstractdataproxy.h" #include "q3dscene_p.h" -#include "customdataitem_p.h" +#include "qcustom3ditem.h" #include #include @@ -175,7 +175,7 @@ protected: QVector m_changedSeriesList; - QList m_customItems; + QList m_customItems; explicit Abstract3DController(QRect initialViewport, Q3DScene *scene, QObject *parent = 0); @@ -236,9 +236,9 @@ public: void requestRender(QOpenGLFramebufferObject *fbo); - int addCustomItem(const QString &meshFile, const QVector3D &position, const QVector3D &scaling, - const QQuaternion &rotation, const QImage &textureImage); - void deleteCustomItem(int index); + int addCustomItem(QCustom3DItem *item); + void deleteCustomItems(); + void deleteCustomItem(QCustom3DItem *item); void deleteCustomItem(const QVector3D &position); void emitNeedRender(); @@ -321,6 +321,7 @@ private: void setAxisHelper(QAbstract3DAxis::AxisOrientation orientation, QAbstract3DAxis *axis, QAbstract3DAxis **axisPtr); + friend class AbstractDeclarative; friend class Bars3DController; friend class QAbstract3DGraphPrivate; }; diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp index 95cecbd3..bff24bc7 100644 --- a/src/datavisualization/engine/abstract3drenderer.cpp +++ b/src/datavisualization/engine/abstract3drenderer.cpp @@ -28,6 +28,7 @@ #include "objecthelper_p.h" #include "qvalue3daxisformatter_p.h" #include "shaderhelper_p.h" +#include "qcustom3ditem_p.h" QT_BEGIN_NAMESPACE_DATAVISUALIZATION @@ -74,6 +75,13 @@ Abstract3DRenderer::~Abstract3DRenderer() } m_renderCacheList.clear(); + foreach (CustomRenderItem *item, m_customRenderCache) { + GLuint texture = item->texture(); + m_textureHelper->deleteTexture(&texture); + delete item; + } + m_customRenderCache.clear(); + delete m_textureHelper; } @@ -402,16 +410,19 @@ void Abstract3DRenderer::updateSeries(const QList &seriesLi } } -void Abstract3DRenderer::updateCustomData(const QList &customItems) +void Abstract3DRenderer::updateCustomData(const QList &customItems) { if (customItems.isEmpty() && m_customRenderCache.isEmpty()) return; // There are probably not too many custom items, just recreate the array if something changes - foreach (CustomRenderItem *item, m_customRenderCache) + foreach (CustomRenderItem *item, m_customRenderCache) { + GLuint texture = item->texture(); + m_textureHelper->deleteTexture(&texture); delete item; + } m_customRenderCache.clear(); - foreach (CustomDataItem *item, customItems) + foreach (QCustom3DItem *item, customItems) addCustomItem(item); } @@ -526,12 +537,16 @@ QVector4D Abstract3DRenderer::indexToSelectionColor(GLint index) return QVector4D(idxRed, idxGreen, idxBlue, 0); } -void Abstract3DRenderer::addCustomItem(CustomDataItem *item) { +void Abstract3DRenderer::addCustomItem(QCustom3DItem *item) { CustomRenderItem *newItem = new CustomRenderItem(); newItem->setMesh(item->meshFile()); newItem->setScaling(item->scaling()); newItem->setRotation(item->rotation()); - newItem->setTexture(item->texture()); + GLuint texture = m_textureHelper->create2DTexture(item->d_ptr->textureImage(), + true, true, true); + newItem->setTexture(texture); + // TODO: Uncomment this once custom item render cache handling has been optimized + //item->d_ptr->clearTextureImage(); QVector3D translation = convertPositionToTranslation(item->position()); newItem->setTranslation(translation); m_customRenderCache.append(newItem); diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h index 65dcd8f6..ea61ae51 100644 --- a/src/datavisualization/engine/abstract3drenderer_p.h +++ b/src/datavisualization/engine/abstract3drenderer_p.h @@ -67,7 +67,7 @@ public: virtual void updateData() = 0; virtual void updateSeries(const QList &seriesList); - virtual void updateCustomData(const QList &customItems); + virtual void updateCustomData(const QList &customItems); virtual SeriesRenderCache *createNewCache(QAbstract3DSeries *series); virtual void cleanCache(SeriesRenderCache *cache); virtual void render(GLuint defaultFboHandle); @@ -111,7 +111,7 @@ public: virtual void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh); - virtual void addCustomItem(CustomDataItem *item); + virtual void addCustomItem(QCustom3DItem *item); virtual QVector3D convertPositionToTranslation(const QVector3D &position) = 0; diff --git a/src/datavisualization/engine/qabstract3dgraph.cpp b/src/datavisualization/engine/qabstract3dgraph.cpp index e143e756..85ee79c9 100644 --- a/src/datavisualization/engine/qabstract3dgraph.cpp +++ b/src/datavisualization/engine/qabstract3dgraph.cpp @@ -382,46 +382,42 @@ void QAbstract3DGraph::clearSelection() } /*! - * Adds a custom mesh item located in \a meshFile to a graph at \a position with \a {scaling}, - * \a rotation and optional \a textureImage. Item must be in Wavefront obj format and include - * vertices, normals and UVs. It also needs to be in triangles. Item position is given in data - * coordinates. + * Adds a QCustom3DItem \a item to the graph. Graph takes ownership of the added item. * - * \return index to the added item. + * \return index to the added item if add was successful, -1 if trying to add a null item, and + * index of the item if trying to add an already added item. * - * \note No validity checks are made for the position of the item, so it is up to the user to - * provide a valid position. Items positioned outside axis ranges are still rendered. - * - * \sa removeCustomItemAt() + * \sa removeCustomItems(), removeCustomItem(), removeCustomItemAt() * * \since Qt Data Visualization 1.1 */ -int QAbstract3DGraph::addCustomItem(const QString &meshFile, const QVector3D &position, - const QVector3D &scaling, const QQuaternion &rotation, - const QImage &textureImage) +int QAbstract3DGraph::addCustomItem(QCustom3DItem *item) { - return d_ptr->m_visualController->addCustomItem(meshFile, position, scaling, rotation, - textureImage); + return d_ptr->m_visualController->addCustomItem(item); } /*! - * Removes the custom item at \a {index}. Deletes the resources allocated to it. - * - * \note The index of the remaining items will change if the item removed is other than - * the last. + * Removes all custom items. Deletes the resources allocated to them. * * \since Qt Data Visualization 1.1 */ -void QAbstract3DGraph::removeCustomItemAt(int index) +void QAbstract3DGraph::removeCustomItems() { - d_ptr->m_visualController->deleteCustomItem(index); + d_ptr->m_visualController->deleteCustomItems(); } /*! - * Removes the custom item at \a {position}. Deletes the resources allocated to it. + * Removes the custom \a {item}. Deletes the resources allocated to it. * - * \note The index of the remaining items will change if an item is removed from a position that - * is not at the last index. + * \since Qt Data Visualization 1.1 + */ +void QAbstract3DGraph::removeCustomItem(QCustom3DItem *item) +{ + d_ptr->m_visualController->deleteCustomItem(item); +} + +/*! + * Removes all custom items at \a {position}. Deletes the resources allocated to them. * * \since Qt Data Visualization 1.1 */ diff --git a/src/datavisualization/engine/qabstract3dgraph.h b/src/datavisualization/engine/qabstract3dgraph.h index dc0bf6f0..ae1efacf 100644 --- a/src/datavisualization/engine/qabstract3dgraph.h +++ b/src/datavisualization/engine/qabstract3dgraph.h @@ -29,6 +29,7 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION class QAbstract3DGraphPrivate; +class QCustom3DItem; class QT_DATAVISUALIZATION_EXPORT QAbstract3DGraph : public QWindow, protected QOpenGLFunctions { @@ -107,10 +108,9 @@ public: void clearSelection(); - int addCustomItem(const QString &meshFile, const QVector3D &position, - const QVector3D &scaling, const QQuaternion &rotation, - const QImage &textureImage = QImage()); - void removeCustomItemAt(int index); + int addCustomItem(QCustom3DItem *item); + void removeCustomItems(); + void removeCustomItem(QCustom3DItem *item); void removeCustomItemAt(const QVector3D &position); QImage renderToImage(int msaaSamples = 0, const QSize &imageSize = QSize()); diff --git a/src/datavisualizationqml2/abstractdeclarative.cpp b/src/datavisualizationqml2/abstractdeclarative.cpp index 70ba8df8..fa69cac9 100644 --- a/src/datavisualizationqml2/abstractdeclarative.cpp +++ b/src/datavisualizationqml2/abstractdeclarative.cpp @@ -211,19 +211,19 @@ bool AbstractDeclarative::shadowsSupported() const return m_controller->shadowsSupported(); } -int AbstractDeclarative::addCustomItem(const QString &meshFile, const QVector3D &position, - const QVector3D &scaling, const QQuaternion &rotation, - const QString &textureFile) +int AbstractDeclarative::addCustomItem(QCustom3DItem *item) { - QImage textureImage; - if (!textureFile.isNull()) - textureImage = QImage(textureFile); - return m_controller->addCustomItem(meshFile, position, scaling, rotation, textureImage); + return m_controller->addCustomItem(item); } -void AbstractDeclarative::removeCustomItemAt(int index) +void AbstractDeclarative::removeCustomItems() { - m_controller->deleteCustomItem(index); + m_controller->deleteCustomItems(); +} + +void AbstractDeclarative::removeCustomItem(QCustom3DItem *item) +{ + m_controller->deleteCustomItem(item); } void AbstractDeclarative::removeCustomItemAt(const QVector3D &position) @@ -231,6 +231,39 @@ void AbstractDeclarative::removeCustomItemAt(const QVector3D &position) m_controller->deleteCustomItem(position); } +QQmlListProperty AbstractDeclarative::customItemList() +{ + return QQmlListProperty(this, this, + &AbstractDeclarative::appendCustomItemFunc, + &AbstractDeclarative::countCustomItemFunc, + &AbstractDeclarative::atCustomItemFunc, + &AbstractDeclarative::clearCustomItemFunc); +} + +void AbstractDeclarative::appendCustomItemFunc(QQmlListProperty *list, + QCustom3DItem *item) +{ + AbstractDeclarative *decl = reinterpret_cast(list->data); + decl->addCustomItem(item); +} + +int AbstractDeclarative::countCustomItemFunc(QQmlListProperty *list) +{ + return reinterpret_cast(list->data)->m_controller->m_customItems.size(); +} + +QCustom3DItem *AbstractDeclarative::atCustomItemFunc(QQmlListProperty *list, + int index) +{ + return reinterpret_cast(list->data)->m_controller->m_customItems.at(index); +} + +void AbstractDeclarative::clearCustomItemFunc(QQmlListProperty *list) +{ + AbstractDeclarative *decl = reinterpret_cast(list->data); + decl->removeCustomItems(); +} + void AbstractDeclarative::setSharedController(Abstract3DController *controller) { Q_ASSERT(controller); diff --git a/src/datavisualizationqml2/abstractdeclarative_p.h b/src/datavisualizationqml2/abstractdeclarative_p.h index d5ad8836..8121e35d 100644 --- a/src/datavisualizationqml2/abstractdeclarative_p.h +++ b/src/datavisualizationqml2/abstractdeclarative_p.h @@ -68,6 +68,7 @@ class AbstractDeclarative : public QQuickItem Q_PROPERTY(RenderingMode renderingMode READ renderingMode WRITE setRenderingMode NOTIFY renderingModeChanged) Q_PROPERTY(bool measureFps READ measureFps WRITE setMeasureFps NOTIFY measureFpsChanged REVISION 1) Q_PROPERTY(qreal currentFps READ currentFps NOTIFY currentFpsChanged REVISION 1) + Q_PROPERTY(QQmlListProperty customItemList READ customItemList REVISION 1) public: enum SelectionFlag { @@ -128,14 +129,18 @@ public: Q_INVOKABLE virtual void clearSelection(); - Q_REVISION(1) Q_INVOKABLE virtual int addCustomItem(const QString &meshFile, - const QVector3D &position, - const QVector3D &scaling, - const QQuaternion &rotation, - const QString &textureFile = 0); - Q_REVISION(1) Q_INVOKABLE virtual void removeCustomItemAt(int index); + Q_REVISION(1) Q_INVOKABLE virtual int addCustomItem(QCustom3DItem *item); + Q_REVISION(1) Q_INVOKABLE virtual void removeCustomItems(); + Q_REVISION(1) Q_INVOKABLE virtual void removeCustomItem(QCustom3DItem *item); Q_REVISION(1) Q_INVOKABLE virtual void removeCustomItemAt(const QVector3D &position); + QQmlListProperty customItemList(); + static void appendCustomItemFunc(QQmlListProperty *list, + QCustom3DItem *item); + static int countCustomItemFunc(QQmlListProperty *list); + static QCustom3DItem *atCustomItemFunc(QQmlListProperty *list, int index); + static void clearCustomItemFunc(QQmlListProperty *list); + virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); void setSharedController(Abstract3DController *controller); diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp index d7a82d6b..d419d904 100644 --- a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp +++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp @@ -43,7 +43,7 @@ void QtDataVisualizationQml2Plugin::registerTypes(const char *uri) qmlRegisterUncreatableType(uri, 1, 0, "AbstractGraph3D", QLatin1String("Trying to create uncreatable: AbstractGraph3D.")); qmlRegisterUncreatableType(uri, 1, 0, "Scene3D", - QLatin1String("Trying to create uncreatable: Scene3D.")); + QLatin1String("Trying to create uncreatable: Scene3D.")); qmlRegisterUncreatableType(uri, 1, 0, "Abstract3DSeries", QLatin1String("Trying to create uncreatable: Abstract3DSeries.")); qmlRegisterUncreatableType(uri, 1, 0, "QBar3DSeries", @@ -89,7 +89,7 @@ void QtDataVisualizationQml2Plugin::registerTypes(const char *uri) // New revisions qmlRegisterType(uri, 1, 1, "ValueAxis3D"); qmlRegisterUncreatableType(uri, 1, 1, "Abstract3DSeries", - QLatin1String("Trying to create uncreatable: Abstract3DSeries.")); + QLatin1String("Trying to create uncreatable: Abstract3DSeries.")); qmlRegisterUncreatableType(uri, 1, 1, "AbstractGraph3D", QLatin1String("Trying to create uncreatable: AbstractGraph3D.")); qmlRegisterType(uri, 1, 1, "ItemModelBarDataProxy"); @@ -97,6 +97,7 @@ void QtDataVisualizationQml2Plugin::registerTypes(const char *uri) // New types qmlRegisterType(uri, 1, 1, "ValueAxis3DFormatter"); qmlRegisterType(uri, 1, 1, "LogValueAxis3DFormatter"); + qmlRegisterType(uri, 1, 1, "Custom3DItem"); } QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.h b/src/datavisualizationqml2/datavisualizationqml2_plugin.h index 14fb530e..fcc0bcde 100644 --- a/src/datavisualizationqml2/datavisualizationqml2_plugin.h +++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.h @@ -45,6 +45,7 @@ #include "qabstract3dinputhandler.h" #include "declarativecolor_p.h" #include "declarativescene_p.h" +#include "qcustom3ditem.h" #include @@ -96,6 +97,8 @@ QML_DECLARE_TYPE(DeclarativeTheme3D) QML_DECLARE_TYPE(QAbstract3DInputHandler) +QML_DECLARE_TYPE(QCustom3DItem) + QT_BEGIN_NAMESPACE_DATAVISUALIZATION class QtDataVisualizationQml2Plugin : public QQmlExtensionPlugin diff --git a/src/datavisualizationqml2/declarativebars_p.h b/src/datavisualizationqml2/declarativebars_p.h index 97f5882a..ae44e2ab 100644 --- a/src/datavisualizationqml2/declarativebars_p.h +++ b/src/datavisualizationqml2/declarativebars_p.h @@ -88,7 +88,6 @@ public: Q_INVOKABLE void insertSeries(int index, QBar3DSeries *series); void setPrimarySeries(QBar3DSeries *series); QBar3DSeries *primarySeries() const; - QBar3DSeries *selectedSeries() const; public slots: diff --git a/src/datavisualizationqml2/declarativecolor.cpp b/src/datavisualizationqml2/declarativecolor.cpp index ffd4227f..f8ef06d2 100644 --- a/src/datavisualizationqml2/declarativecolor.cpp +++ b/src/datavisualizationqml2/declarativecolor.cpp @@ -20,6 +20,8 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION +// TODO: Docs missing? + DeclarativeColor::DeclarativeColor(QObject *parent) : QObject(parent) { diff --git a/src/datavisualizationqml2/declarativetheme.cpp b/src/datavisualizationqml2/declarativetheme.cpp index f051341e..ab10155e 100644 --- a/src/datavisualizationqml2/declarativetheme.cpp +++ b/src/datavisualizationqml2/declarativetheme.cpp @@ -36,17 +36,17 @@ DeclarativeTheme3D::~DeclarativeTheme3D() { } -QQmlListProperty DeclarativeTheme3D::seriesChildren() +QQmlListProperty DeclarativeTheme3D::themeChildren() { - return QQmlListProperty(this, this, &DeclarativeTheme3D::appendSeriesChildren, + return QQmlListProperty(this, this, &DeclarativeTheme3D::appendThemeChildren, 0, 0, 0); } -void DeclarativeTheme3D::appendSeriesChildren(QQmlListProperty *list, QObject *element) +void DeclarativeTheme3D::appendThemeChildren(QQmlListProperty *list, QObject *element) { Q_UNUSED(list) Q_UNUSED(element) - // Nothing to do, seriesChildren is there only to enable scoping gradient items in Theme3D item. + // Nothing to do, themeChildren is there only to enable scoping gradient items in Theme3D item. } void DeclarativeTheme3D::handleTypeChange(Theme themeType) diff --git a/src/datavisualizationqml2/declarativetheme_p.h b/src/datavisualizationqml2/declarativetheme_p.h index a7f40b1e..89b66f8c 100644 --- a/src/datavisualizationqml2/declarativetheme_p.h +++ b/src/datavisualizationqml2/declarativetheme_p.h @@ -42,19 +42,19 @@ class DeclarativeTheme3D : public Q3DTheme, public QQmlParserStatus { Q_OBJECT Q_INTERFACES(QQmlParserStatus) - Q_PROPERTY(QQmlListProperty seriesChildren READ seriesChildren) + Q_PROPERTY(QQmlListProperty themeChildren READ themeChildren) Q_PROPERTY(QQmlListProperty baseColors READ baseColors) Q_PROPERTY(QQmlListProperty baseGradients READ baseGradients) Q_PROPERTY(ColorGradient *singleHighlightGradient READ singleHighlightGradient WRITE setSingleHighlightGradient NOTIFY singleHighlightGradientChanged) Q_PROPERTY(ColorGradient *multiHighlightGradient READ multiHighlightGradient WRITE setMultiHighlightGradient NOTIFY multiHighlightGradientChanged) - Q_CLASSINFO("DefaultProperty", "seriesChildren") + Q_CLASSINFO("DefaultProperty", "themeChildren") public: DeclarativeTheme3D(QObject *parent = 0); virtual ~DeclarativeTheme3D(); - QQmlListProperty seriesChildren(); - static void appendSeriesChildren(QQmlListProperty *list, QObject *element); + QQmlListProperty themeChildren(); + static void appendThemeChildren(QQmlListProperty *list, QObject *element); QQmlListProperty baseColors(); static void appendBaseColorsFunc(QQmlListProperty *list, diff --git a/tests/qmlcamera/qml/qmlcamera/main.qml b/tests/qmlcamera/qml/qmlcamera/main.qml index 56e7d035..0f708615 100644 --- a/tests/qmlcamera/qml/qmlcamera/main.qml +++ b/tests/qmlcamera/qml/qmlcamera/main.qml @@ -18,7 +18,7 @@ import QtQuick 2.1 import QtQuick.Controls 1.0 -import QtDataVisualization 1.0 +import QtDataVisualization 1.1 import "." Rectangle { @@ -66,6 +66,16 @@ Rectangle { scene.activeCamera.yRotation: camControlArea.yValue scene.activeCamera.zoomLevel: zoomSlider.value inputHandler: null + + customItemList: [shuttleItem] + } + + Custom3DItem { + id: shuttleItem + meshFile: ":/items/shuttle.obj" + textureFile: ":/items/shuttle.png" + position: Qt.vector3d(5.0,35.0,3.0) + scaling: Qt.vector3d(0.2,0.2,0.2) } MouseArea { @@ -168,23 +178,10 @@ Rectangle { id: shuttleAdd anchors.bottom: dataToggle.top width: camControlArea.width - text: "Add Shuttle" - property bool addObject: true + text: "Remove Shuttle" onClicked: { - if (addObject === true) { - testChart.addCustomItem(":/items/shuttle.obj", - Qt.vector3d(5.0,35.0,3.0), - Qt.vector3d(0.2,0.2,0.2), - Qt.quaternion(0.0,0.0,0.0,0.0), - ":/items/shuttle.png") - text = "Remove Shuttle" - addObject = false - } else { - testChart.removeCustomItemAt(Qt.vector3d(5.0,35.0,3.0)) - text = "Add Shuttle" - addObject = true - } + testChart.removeCustomItemAt(Qt.vector3d(5.0,35.0,3.0)) + text = "Shuttle has been deleted" } } - } -- cgit v1.2.3