diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-02-08 13:25:03 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-06-01 16:00:14 +0000 |
commit | 7a124e79515f0750cc4d91cf5419c14c2fddb10b (patch) | |
tree | 0837be53c327d1ee71cefe245622b9baf089111a | |
parent | 825ddb6fc73f307fee820c9e061e9d398439614e (diff) |
Add extent properties to QCuboidCollisionShape and testwip/physics
Change-Id: I48fdbed9e8147fcaee1dd8b867db3103ceca5d68
Reviewed-by: David Morgan <david.morgan@kdab.com>
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
4 files changed, 164 insertions, 14 deletions
diff --git a/src/physics/frontend/qcuboidcollisionshape.cpp b/src/physics/frontend/qcuboidcollisionshape.cpp index 4882101a1..5caa495e4 100644 --- a/src/physics/frontend/qcuboidcollisionshape.cpp +++ b/src/physics/frontend/qcuboidcollisionshape.cpp @@ -46,6 +46,9 @@ namespace Qt3DPhysics { QCuboidCollisionShapePrivate::QCuboidCollisionShapePrivate() : QAbstractCollisionShapePrivate() + , m_xExtent(1.0f) + , m_yExtent(1.0f) + , m_zExtent(1.0f) { } @@ -63,12 +66,74 @@ QCuboidCollisionShape::~QCuboidCollisionShape() { } +void QCuboidCollisionShape::setXExtent(float xExtent) +{ + Q_D(QCuboidCollisionShape); + if (d->m_xExtent != xExtent) { + d->m_xExtent = xExtent; + emit xExtentChanged(xExtent); + } +} + +void QCuboidCollisionShape::setYExtent(float yExtent) +{ + Q_D(QCuboidCollisionShape); + if (d->m_yExtent != yExtent) { + d->m_yExtent = yExtent; + emit yExtentChanged(yExtent); + } +} + +void QCuboidCollisionShape::setZExtent(float zExtent) +{ + Q_D(QCuboidCollisionShape); + if (d->m_zExtent != zExtent) { + d->m_zExtent = zExtent; + emit zExtentChanged(zExtent); + } +} + +/*! + * \property QCuboidCollisionShape::xExtent + * + * Holds the x extent of the geometry. + */ +float QCuboidCollisionShape::xExtent() const +{ + Q_D(const QCuboidCollisionShape); + return d->m_xExtent; +} + +/*! + * \property QCuboidCollisionShape::yExtent + * + * Holds the y extent of the geometry. + */ +float QCuboidCollisionShape::yExtent() const +{ + Q_D(const QCuboidCollisionShape); + return d->m_yExtent; +} + +/*! + * \property QCuboidCollisionShape::zExtent + * + * Holds the z extent of the geometry. + */ +float QCuboidCollisionShape::zExtent() const +{ + Q_D(const QCuboidCollisionShape); + return d->m_zExtent; +} + Qt3DCore::QNodeCreatedChangeBasePtr QCuboidCollisionShape::createNodeCreationChange() const { auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QCuboidCollisionShapeData>::create(this); auto &data = creationChange->data; Q_D(const QCuboidCollisionShape); - // TODO: Send data members in creation change + data.xExtent = d->m_xExtent; + data.yExtent = d->m_yExtent; + data.zExtent = d->m_zExtent; return creationChange; } diff --git a/src/physics/frontend/qcuboidcollisionshape.h b/src/physics/frontend/qcuboidcollisionshape.h index fedb53eaf..896c0d8ac 100644 --- a/src/physics/frontend/qcuboidcollisionshape.h +++ b/src/physics/frontend/qcuboidcollisionshape.h @@ -52,14 +52,27 @@ class QCuboidCollisionShapePrivate; class QT3DPHYSICSSHARED_EXPORT QCuboidCollisionShape : public QAbstractCollisionShape { Q_OBJECT - // TODO: Add property declarations + Q_PROPERTY(float xExtent READ xExtent WRITE setXExtent NOTIFY xExtentChanged) + Q_PROPERTY(float yExtent READ yExtent WRITE setYExtent NOTIFY yExtentChanged) + Q_PROPERTY(float zExtent READ zExtent WRITE setZExtent NOTIFY zExtentChanged) + public: explicit QCuboidCollisionShape(Qt3DCore::QNode *parent = nullptr); ~QCuboidCollisionShape(); + float xExtent() const; + float yExtent() const; + float zExtent() const; + public Q_SLOTS: + void setXExtent(float xExtent); + void setYExtent(float yExtent); + void setZExtent(float zExtent); Q_SIGNALS: + void xExtentChanged(float xExtent); + void yExtentChanged(float yExtent); + void zExtentChanged(float zExtent); protected: QCuboidCollisionShape(QCuboidCollisionShapePrivate &dd, Qt3DCore::QNode *parent = nullptr); diff --git a/src/physics/frontend/qcuboidcollisionshape_p.h b/src/physics/frontend/qcuboidcollisionshape_p.h index 1f50b6bc8..e99a24b11 100644 --- a/src/physics/frontend/qcuboidcollisionshape_p.h +++ b/src/physics/frontend/qcuboidcollisionshape_p.h @@ -64,12 +64,16 @@ public: Q_DECLARE_PUBLIC(QCuboidCollisionShape) - // TODO Add member variables + float m_xExtent; + float m_yExtent; + float m_zExtent; }; struct QCuboidCollisionShapeData { - // TODO: Add members that should be sent to the backend + float xExtent; + float yExtent; + float zExtent; }; } // namespace Qt3DPhysics diff --git a/tests/auto/physics/qcuboidcollisionshape/tst_qcuboidcollisionshape.cpp b/tests/auto/physics/qcuboidcollisionshape/tst_qcuboidcollisionshape.cpp index fa39c8cab..75d641c28 100644 --- a/tests/auto/physics/qcuboidcollisionshape/tst_qcuboidcollisionshape.cpp +++ b/tests/auto/physics/qcuboidcollisionshape/tst_qcuboidcollisionshape.cpp @@ -38,22 +38,16 @@ ****************************************************************************/ #include <QtTest/QTest> +#include <Qt3DPhysics/qcuboidcollisionshape.h> +#include <Qt3DPhysics/private/qcuboidcollisionshape_p.h> +#include <Qt3DCore/qpropertyupdatedchange.h> #include <Qt3DCore/private/qnode_p.h> #include <Qt3DCore/private/qscene_p.h> #include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> -#include <Qt3DPhysics/QCuboidCollisionShape> - -#include <Qt3DCore/QPropertyUpdatedChange> -#include <Qt3DCore/QPropertyNodeAddedChange> -#include <Qt3DCore/QPropertyNodeRemovedChange> - #include "testpostmanarbiter.h" -// We need to call QNode::clone which is protected -// We need to call QAxis::sceneChangeEvent which is protected -// So we sublcass QAxis instead of QObject -class tst_QCuboidCollisionShape: public Qt3DPhysics::QCuboidCollisionShape +class tst_QCuboidCollisionShape: public QObject { Q_OBJECT public: @@ -62,7 +56,81 @@ public: } private Q_SLOTS: + void checkCreationData() + { + // GIVEN + Qt3DPhysics::QCuboidCollisionShape shape; + shape.setXExtent(0.5f); + shape.setYExtent(1.5f); + shape.setZExtent(2.5f); + + // WHEN + Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&shape); + QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = creationChangeGenerator.creationChanges(); + + // THEN + QCOMPARE(creationChanges.size(), 1); + + const Qt3DCore::QNodeCreatedChangePtr<Qt3DPhysics::QCuboidCollisionShapeData> creationChangeData = + qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DPhysics::QCuboidCollisionShapeData>>(creationChanges.first()); + const Qt3DPhysics::QCuboidCollisionShapeData &creationData = creationChangeData->data; + + // THEN + QCOMPARE(creationChangeData->subjectId(), shape.id()); + QCOMPARE(creationChangeData->isNodeEnabled(), shape.isEnabled()); + QCOMPARE(creationChangeData->metaObject(), shape.metaObject()); + QCOMPARE(creationChangeData->parentId(), shape.parentNode() ? shape.parentNode()->id() : Qt3DCore::QNodeId()); + QCOMPARE(creationData.xExtent, shape.xExtent()); + QCOMPARE(creationData.yExtent, shape.yExtent()); + QCOMPARE(creationData.zExtent, shape.zExtent()); + } + + void checkPropertyUpdates() + { + // GIVEN + TestArbiter arbiter; + QScopedPointer<Qt3DPhysics::QCuboidCollisionShape> shape(new Qt3DPhysics::QCuboidCollisionShape()); + arbiter.setArbiterOnNode(shape.data()); + // WHEN + shape->setXExtent(1.5f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "xExtent"); + QCOMPARE(change->value().toFloat(), 1.5f); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + shape->setYExtent(2.0f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "yExtent"); + QCOMPARE(change->value().toFloat(), 2.0f); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + shape->setZExtent(3.0f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "zExtent"); + QCOMPARE(change->value().toFloat(), 3.0f); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + } }; QTEST_MAIN(tst_QCuboidCollisionShape) |