1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qt3dquick3dscene2d_p.h"
5#include <Qt3DCore/qentity.h>
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DRender {
10namespace Render {
11namespace Quick {
12
13QQuick3DScene2D::QQuick3DScene2D(QObject *parent)
14 : QObject(parent)
15{
16}
17
18QQmlListProperty<Qt3DCore::QEntity> QQuick3DScene2D::entities()
19{
20 using qt_size_type = qsizetype;
21 using ListContentType = Qt3DCore::QEntity;
22 auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *entity) {
23 QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(object: list->object);
24 if (scene2d)
25 scene2d->parentScene2D()->addEntity(entity);
26 };
27 auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type {
28 QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(object: list->object);
29 if (scene2d)
30 return scene2d->parentScene2D()->entities().size();
31 return 0;
32 };
33 auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * {
34 QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(object: list->object);
35 if (scene2d) {
36 return qobject_cast<Qt3DCore::QEntity *>(
37 object: scene2d->parentScene2D()->entities().at(i: index));
38 }
39 return nullptr;
40 };
41 auto clearFunction = [](QQmlListProperty<ListContentType> *list) {
42 QQuick3DScene2D *scene2d = qobject_cast<QQuick3DScene2D *>(object: list->object);
43 if (scene2d) {
44 QList<Qt3DCore::QEntity*> entities = scene2d->parentScene2D()->entities();
45 for (Qt3DCore::QEntity *e : entities)
46 scene2d->parentScene2D()->removeEntity(entity: e);
47 }
48 };
49
50 return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction);
51}
52
53} // namespace Quick
54} // namespace Render
55} // namespace Qt3DRender
56
57QT_END_NAMESPACE
58
59#include "moc_qt3dquick3dscene2d_p.cpp"
60

source code of qt3d/src/quick3d/quick3dscene2d/items/qt3dquick3dscene2d.cpp