summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3d/items/quick3djoint.cpp
blob: baa79dd56e74d703230c36d800d1fcc0540cda5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#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()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    using qt_size_type = qsizetype;
#else
    using qt_size_type = int;
#endif

    using ListContentType = QJoint;
    auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *joint) {
        Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object);
        jointExtension->parentJoint()->addChildJoint(joint);
    };
    auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type {
        Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object);
        return jointExtension->parentJoint()->childJoints().size();
    };
    auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * {
        Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object);
        return jointExtension->parentJoint()->childJoints().at(index);
    };
    auto clearFunction = [](QQmlListProperty<ListContentType> *list) {
        Quick3DJoint *jointExtension = qobject_cast<Quick3DJoint *>(list->object);
        const auto joints = jointExtension->parentJoint()->childJoints();
        for (QJoint *joint : joints)
            jointExtension->parentJoint()->removeChildJoint(joint);
    };

    return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction);
}

} // namespace Quick
} // namespace Qt3DCore

QT_END_NAMESPACE

#include "moc_quick3djoint_p.cpp"