diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2014-05-12 10:06:27 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2014-05-12 10:07:15 +0300 |
commit | 6880277f23b47117f7788f08f855ed99b5120f9f (patch) | |
tree | de8b9e64ffce03a3ce77c8ffac396f7174e91956 /src/datavisualization/data | |
parent | 590d11726e0708e9f8fad0ec386cc5859dbe5cc8 (diff) |
CustomDataItem made into a public class
Task-number: QTRD-3055
Change-Id: I1e449df7c1bcb48fc639dbae579e2e1499c9ef2b
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/data')
-rw-r--r-- | src/datavisualization/data/customdataitem.cpp | 47 | ||||
-rw-r--r-- | src/datavisualization/data/data.pri | 5 | ||||
-rw-r--r-- | src/datavisualization/data/qcustom3ditem.cpp | 274 | ||||
-rw-r--r-- | src/datavisualization/data/qcustom3ditem.h | 84 | ||||
-rw-r--r-- | src/datavisualization/data/qcustom3ditem_p.h (renamed from src/datavisualization/data/customdataitem_p.h) | 39 |
5 files changed, 379 insertions, 70 deletions
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/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 <QtDataVisualization/qdatavisualizationglobal.h> +#include <QtGui/QImage> +#include <QtGui/QVector3D> +#include <QtGui/QQuaternion> + +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<QCustom3DItemPrivate> d_ptr; + +private: + Q_DISABLE_COPY(QCustom3DItem) + + friend class Abstract3DRenderer; +}; + +QT_END_NAMESPACE_DATAVISUALIZATION + +#endif diff --git a/src/datavisualization/data/customdataitem_p.h b/src/datavisualization/data/qcustom3ditem_p.h index c077a17a..77062768 100644 --- a/src/datavisualization/data/customdataitem_p.h +++ b/src/datavisualization/data/qcustom3ditem_p.h @@ -26,39 +26,36 @@ // // We mean it. -#ifndef CUSTOMDATAITEM_P_H -#define CUSTOMDATAITEM_P_H +#ifndef QCUSTOM3DITEM_P_H +#define QCUSTOM3DITEM_P_H -#include "datavisualizationglobal_p.h" +#include "qcustom3ditem.h" QT_BEGIN_NAMESPACE_DATAVISUALIZATION -class TextureHelper; - -class QT_DATAVISUALIZATION_EXPORT CustomDataItem +class QCustom3DItemPrivate : public QObject { + Q_OBJECT public: - CustomDataItem(); - virtual ~CustomDataItem(); + QCustom3DItemPrivate(QCustom3DItem *q, QObject *parent); + QCustom3DItemPrivate(QCustom3DItem *q, const QString &meshFile, const QVector3D &position, + const QVector3D &scaling, const QQuaternion &rotation, QObject *parent); + virtual ~QCustom3DItemPrivate(); - 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; } + QImage textureImage(); + void clearTextureImage(); -private: - TextureHelper *m_textureHelper; - GLuint m_texture; +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 |