summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3danimation/items/quick3danimationcontroller.cpp
blob: cae8c497174ee857455af6088e5deb3c12a2fd82 (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) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "quick3danimationcontroller_p.h"

QT_BEGIN_NAMESPACE

namespace Qt3DAnimation {
namespace Quick {

QQuick3DAnimationController::QQuick3DAnimationController(QObject *parent)
    : QObject(parent)
{
}

QQmlListProperty<QAnimationGroup> QQuick3DAnimationController::animationGroups()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
    using qt_size_type = qsizetype;
#else
    using qt_size_type = int;
#endif

    using ListContentType = QAnimationGroup;
    auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *bar) {
        QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object);
        if (controller)
            controller->parentAnimationController()->addAnimationGroup(bar);
    };
    auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type {
        QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object);
        if (controller)
            return controller->parentAnimationController()->animationGroupList().size();
        return 0;
    };
    auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * {
        QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object);
        if (controller)
            return qobject_cast<QAnimationGroup *>(controller->parentAnimationController()->getGroup(index));
        return nullptr;
    };
    auto clearFunction = [](QQmlListProperty<ListContentType> *list) {
        QQuick3DAnimationController *controller = qobject_cast<QQuick3DAnimationController *>(list->object);
        if (controller)
            controller->parentAnimationController()->setAnimationGroups({});
    };

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


} // namespace Quick
} // namespace Qt3DAnimation

QT_END_NAMESPACE

#include "moc_quick3danimationcontroller_p.cpp"