diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-08-11 13:01:07 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-08-16 13:19:43 +0000 |
commit | db8e814d941340cf4c32775d5a66d2f66247ffbb (patch) | |
tree | 472fa233cf6a7ffc763e5d50be76075e8d1b1cb6 /src/quick3d/quick3d/items | |
parent | c6d639e27212fc520f2d0d26b180a2c90c23a92f (diff) |
Add extension object for QJoint to manage child joints from QML
Change-Id: I074e78f5e0c0be878d697dc87846ecc6ed6cd78f
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/quick3d/quick3d/items')
-rw-r--r-- | src/quick3d/quick3d/items/items.pri | 6 | ||||
-rw-r--r-- | src/quick3d/quick3d/items/quick3djoint.cpp | 95 | ||||
-rw-r--r-- | src/quick3d/quick3d/items/quick3djoint_p.h | 88 |
3 files changed, 187 insertions, 2 deletions
diff --git a/src/quick3d/quick3d/items/items.pri b/src/quick3d/quick3d/items/items.pri index 4749c83cf..36e7ccedc 100644 --- a/src/quick3d/quick3d/items/items.pri +++ b/src/quick3d/quick3d/items/items.pri @@ -4,13 +4,15 @@ HEADERS += \ $$PWD/quick3dentityloader_p_p.h \ $$PWD/quick3dentityloader_p.h \ $$PWD/quick3dnode_p.h \ - $$PWD/quick3dnodev9_p.h + $$PWD/quick3dnodev9_p.h \ + $$PWD/quick3djoint_p.h SOURCES += \ $$PWD/quick3dnode.cpp \ $$PWD/quick3dentity.cpp \ $$PWD/quick3dentityloader.cpp \ $$PWD/quick3dnodeinstantiator.cpp \ - $$PWD/quick3dnodev9.cpp + $$PWD/quick3dnodev9.cpp \ + $$PWD/quick3djoint.cpp INCLUDEPATH += $$PWD diff --git a/src/quick3d/quick3d/items/quick3djoint.cpp b/src/quick3d/quick3d/items/quick3djoint.cpp new file mode 100644 index 000000000..810e37e1a --- /dev/null +++ b/src/quick3d/quick3d/items/quick3djoint.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "quick3djoint_p.h" +#include <Qt3DCore/qjoint.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { +namespace Quick { + +Quick3DJoint::Quick3DJoint(QObject *parent) + : QObject(parent) +{ +} + +/*! + \qmlproperty list<Joint> Qt3DCore::Joint::childJoints + \readonly +*/ +QQmlListProperty<QJoint> Quick3DJoint::childJoints() +{ + return QQmlListProperty<QJoint>(this, 0, + Quick3DJoint::appendJoint, + Quick3DJoint::jointCount, + Quick3DJoint::jointAt, + Quick3DJoint::clearJoints); +} + +void Quick3DJoint::appendJoint(QQmlListProperty<QJoint> *list, QJoint *joint) +{ + Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); + jointExtension->parentJoint()->addChildJoint(joint); +} + +QJoint *Quick3DJoint::jointAt(QQmlListProperty<QJoint> *list, int index) +{ + Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); + return jointExtension->parentJoint()->childJoints().at(index); +} + +int Quick3DJoint::jointCount(QQmlListProperty<QJoint> *list) +{ + Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); + return jointExtension->parentJoint()->childJoints().count(); +} + +void Quick3DJoint::clearJoints(QQmlListProperty<QJoint> *list) +{ + Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object); + const auto joints = jointExtension->parentJoint()->childJoints(); + for (QJoint *joint : joints) + jointExtension->parentJoint()->removeChildJoint(joint); +} + +} // namespace Quick +} // namespace Qt3DCore + +QT_END_NAMESPACE diff --git a/src/quick3d/quick3d/items/quick3djoint_p.h b/src/quick3d/quick3d/items/quick3djoint_p.h new file mode 100644 index 000000000..bef161643 --- /dev/null +++ b/src/quick3d/quick3d/items/quick3djoint_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DCORE_QUICK_QUICK3DJOINT_P_H +#define QT3DCORE_QUICK_QUICK3DJOINT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QObject> +#include <Qt3DCore/qjoint.h> +#include <QtQml/QQmlListProperty> + +#include <Qt3DQuick/private/qt3dquick_global_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { +namespace Quick { + +class QT3DQUICKSHARED_PRIVATE_EXPORT Quick3DJoint : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<Qt3DCore::QJoint> childJoints READ childJoints) +public: + explicit Quick3DJoint(QObject *parent = nullptr); + + QQmlListProperty<Qt3DCore::QJoint> childJoints(); + + inline QJoint *parentJoint() const { return qobject_cast<QJoint*>(parent()); } + +private: + static void appendJoint(QQmlListProperty<Qt3DCore::QJoint> *list, Qt3DCore::QJoint *obj); + static QJoint *jointAt(QQmlListProperty<Qt3DCore::QJoint> *list, int index); + static int jointCount(QQmlListProperty<Qt3DCore::QJoint> *list); + static void clearJoints(QQmlListProperty<Qt3DCore::QJoint> *list); +}; + +} // namespace Quick +} // namespace Qt3DCore + +QT_END_NAMESPACE + +#endif // QT3DCORE_QUICK_QUICK3DJOINT_P_H |