| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICK3DREPEATER_P_H |
| 5 | #define QQUICK3DREPEATER_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtQuick3D/private/qquick3dnode_p.h> |
| 19 | |
| 20 | #include <QtCore/qvector.h> |
| 21 | #include <QtCore/qpointer.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | class QQmlChangeSet; |
| 25 | class QQmlContext; |
| 26 | class QQmlInstanceModel; |
| 27 | class QQuick3DRepeaterPrivate; |
| 28 | |
| 29 | class Q_QUICK3D_EXPORT QQuick3DRepeater : public QQuick3DNode |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | |
| 33 | Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) |
| 34 | Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) |
| 35 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
| 36 | Q_CLASSINFO("DefaultProperty" , "delegate" ) |
| 37 | |
| 38 | QML_NAMED_ELEMENT(Repeater3D) |
| 39 | |
| 40 | public: |
| 41 | QQuick3DRepeater(QQuick3DNode *parent = nullptr); |
| 42 | ~QQuick3DRepeater() override; |
| 43 | |
| 44 | QVariant model() const; |
| 45 | void setModel(const QVariant &); |
| 46 | |
| 47 | QQmlComponent *delegate() const; |
| 48 | void setDelegate(QQmlComponent *); |
| 49 | |
| 50 | int count() const; |
| 51 | |
| 52 | Q_INVOKABLE QQuick3DObject *objectAt(int index) const; |
| 53 | |
| 54 | Q_SIGNALS: |
| 55 | void modelChanged(); |
| 56 | void delegateChanged(); |
| 57 | void countChanged(); |
| 58 | |
| 59 | void objectAdded(int index, QQuick3DObject *object); |
| 60 | void objectRemoved(int index, QQuick3DObject *object); |
| 61 | |
| 62 | private: |
| 63 | void clear(); |
| 64 | void regenerate(); |
| 65 | |
| 66 | protected: |
| 67 | void componentComplete() override; |
| 68 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
| 69 | virtual void initDelegate(int, QQuick3DNode *) {} |
| 70 | |
| 71 | private Q_SLOTS: |
| 72 | void createdObject(int index, QObject *item); |
| 73 | void initObject(int, QObject *item); |
| 74 | void modelUpdated(const QQmlChangeSet &changeSet, bool reset); |
| 75 | |
| 76 | private: |
| 77 | Q_DISABLE_COPY(QQuick3DRepeater) |
| 78 | |
| 79 | void requestItems(); |
| 80 | |
| 81 | QPointer<QQmlInstanceModel> m_model; |
| 82 | QVariant m_dataSource; |
| 83 | QPointer<QObject> m_dataSourceAsObject; |
| 84 | int m_itemCount; |
| 85 | bool m_ownModel : 1; |
| 86 | bool m_dataSourceIsObject : 1; |
| 87 | bool m_delegateValidated : 1; |
| 88 | |
| 89 | QVector<QPointer<QQuick3DNode> > m_deletables; |
| 90 | }; |
| 91 | |
| 92 | QT_END_NAMESPACE |
| 93 | |
| 94 | QML_DECLARE_TYPE(QQuick3DRepeater) |
| 95 | |
| 96 | #endif // QQUICK3DREPEATER_P_H |
| 97 | |