1 | // Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). |
---|---|
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 <Qt3DQuickRender/private/quick3dscreenraycaster_p.h> |
5 | #include <Qt3DQuickRender/private/quick3dscreenraycaster_p_p.h> |
6 | #include <Qt3DQuickRender/private/quick3draycaster_p_p.h> |
7 | #include <Qt3DCore/private/qscene_p.h> |
8 | |
9 | #include <Qt3DCore/QEntity> |
10 | |
11 | #include <QQmlEngine> |
12 | #include <QJSValue> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | namespace Qt3DRender { |
17 | namespace Render { |
18 | namespace Quick { |
19 | |
20 | Quick3DScreenRayCaster::Quick3DScreenRayCaster(QObject *parent) |
21 | : QScreenRayCaster(*new Quick3DScreenRayCasterPrivate(), qobject_cast<Qt3DCore::QNode *>(object: parent)) |
22 | { |
23 | } |
24 | |
25 | QQmlListProperty<Qt3DRender::QLayer> Qt3DRender::Render::Quick::Quick3DScreenRayCaster::qmlLayers() |
26 | { |
27 | using qt_size_type = qsizetype; |
28 | using ListContentType = Qt3DRender::QLayer; |
29 | auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *layer) { |
30 | QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(object: list->object); |
31 | if (filter) |
32 | filter->addLayer(layer); |
33 | }; |
34 | auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { |
35 | QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(object: list->object); |
36 | if (filter) |
37 | return int(filter->layers().size()); |
38 | return 0; |
39 | }; |
40 | auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { |
41 | QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(object: list->object); |
42 | if (filter) |
43 | return filter->layers().at(i: index); |
44 | return nullptr; |
45 | }; |
46 | auto clearFunction = [](QQmlListProperty<ListContentType> *list) { |
47 | QAbstractRayCaster *filter = qobject_cast<QAbstractRayCaster *>(object: list->object); |
48 | if (filter) { |
49 | const auto layers = filter->layers(); |
50 | for (QLayer *layer : layers) |
51 | filter->removeLayer(layer); |
52 | } |
53 | }; |
54 | |
55 | return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); |
56 | } |
57 | |
58 | } // namespace Quick |
59 | } // namespace Render |
60 | } // namespace Qt3DRender |
61 | |
62 | QT_END_NAMESPACE |
63 | |
64 | #include "moc_quick3dscreenraycaster_p.cpp" |
65 |