1 | // Copyright (C) 2014 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 <QtCore/QDebug> |
5 | |
6 | #include <Qt3DQuickRender/private/quick3dtexture_p.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | namespace Qt3DRender { |
11 | namespace Render { |
12 | namespace Quick { |
13 | |
14 | Quick3DTextureExtension::Quick3DTextureExtension(QObject *parent) |
15 | : QObject(parent) |
16 | { |
17 | } |
18 | |
19 | QQmlListProperty<QAbstractTextureImage> Quick3DTextureExtension::textureImages() |
20 | { |
21 | using qt_size_type = qsizetype; |
22 | using ListContentType = QAbstractTextureImage; |
23 | auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *textureImage) { |
24 | Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(object: list->object); |
25 | if (self) |
26 | self->parentTexture()->addTextureImage(textureImage); |
27 | }; |
28 | auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { |
29 | Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(object: list->object); |
30 | if (self) |
31 | return self->parentTexture()->textureImages().size(); |
32 | return 0; |
33 | }; |
34 | auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { |
35 | Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(object: list->object); |
36 | if (self) |
37 | return self->parentTexture()->textureImages().at(i: index); |
38 | return nullptr; |
39 | }; |
40 | auto clearFunction = [](QQmlListProperty<ListContentType> *list) { |
41 | if (Quick3DTextureExtension *self = qobject_cast<Quick3DTextureExtension *>(object: list->object)) { |
42 | const auto images = self->parentTexture()->textureImages(); |
43 | for (QAbstractTextureImage *img : images) |
44 | self->parentTexture()->removeTextureImage(textureImage: img); |
45 | } |
46 | }; |
47 | |
48 | return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); |
49 | } |
50 | |
51 | } // namespace Quick |
52 | } // namespace Render |
53 | } // namespace Qt3DRender |
54 | |
55 | QT_END_NAMESPACE |
56 | |
57 | #include "moc_quick3dtexture_p.cpp" |
58 |