1 | // Copyright (C) 2017 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 "quick3dspritesheet_p.h" |
5 | #include <Qt3DExtras/qspritesheetitem.h> |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | namespace Qt3DExtras { |
10 | namespace Extras { |
11 | namespace Quick { |
12 | |
13 | Quick3DSpriteSheet::Quick3DSpriteSheet(QObject *parent) |
14 | : QObject(parent) |
15 | { |
16 | } |
17 | |
18 | Quick3DSpriteSheet::~Quick3DSpriteSheet() |
19 | { |
20 | } |
21 | |
22 | QQmlListProperty<Qt3DExtras::QSpriteSheetItem> Quick3DSpriteSheet::sprites() |
23 | { |
24 | using qt_size_type = qsizetype; |
25 | using ListContentType = Qt3DExtras::QSpriteSheetItem; |
26 | auto appendFunction = [](QQmlListProperty<ListContentType> *list, ListContentType *sprite) { |
27 | Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(object: list->object); |
28 | spritesheet->parentSpriteSheet()->addSprite(sprite); |
29 | }; |
30 | auto countFunction = [](QQmlListProperty<ListContentType> *list) -> qt_size_type { |
31 | Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(object: list->object); |
32 | return spritesheet->parentSpriteSheet()->sprites().size(); |
33 | }; |
34 | auto atFunction = [](QQmlListProperty<ListContentType> *list, qt_size_type index) -> ListContentType * { |
35 | Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(object: list->object); |
36 | return spritesheet->parentSpriteSheet()->sprites().at(i: index); |
37 | }; |
38 | auto clearFunction = [](QQmlListProperty<ListContentType> *list) { |
39 | Quick3DSpriteSheet *spritesheet = qobject_cast<Quick3DSpriteSheet *>(object: list->object); |
40 | const auto sprites = spritesheet->parentSpriteSheet()->sprites(); |
41 | for (QSpriteSheetItem *sprite : sprites) |
42 | spritesheet->parentSpriteSheet()->removeSprite(sprite); |
43 | }; |
44 | |
45 | return QQmlListProperty<ListContentType>(this, nullptr, appendFunction, countFunction, atFunction, clearFunction); |
46 | } |
47 | |
48 | } // namespace Quick |
49 | } // namespace Extras |
50 | } // namespace Qt3DExtras |
51 | |
52 | QT_END_NAMESPACE |
53 | |
54 | #include "moc_quick3dspritesheet_p.cpp" |
55 | |
56 |