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 | #ifndef QT3DCORE_QENTITY_H |
5 | #define QT3DCORE_QENTITY_H |
6 | |
7 | #include <Qt3DCore/qnode.h> |
8 | #include <Qt3DCore/qt3dcore_global.h> |
9 | #include <QtCore/QMetaType> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | namespace Qt3DCore { |
14 | |
15 | class QComponent; |
16 | class QEntityPrivate; |
17 | |
18 | using QComponentVector = QList<QComponent*>; |
19 | |
20 | class Q_3DCORESHARED_EXPORT QEntity : public QNode |
21 | { |
22 | Q_OBJECT |
23 | public: |
24 | explicit QEntity(QNode *parent = nullptr); |
25 | virtual ~QEntity(); |
26 | |
27 | QComponentVector components() const; |
28 | |
29 | template<class T> |
30 | QList<T *> componentsOfType() const |
31 | { |
32 | QList<T*> matchComponents; |
33 | const QComponentVector comps = this->components(); |
34 | for (QComponent *component : comps) { |
35 | T *typedComponent = qobject_cast<T*>(component); |
36 | if (typedComponent != nullptr) |
37 | matchComponents.append(typedComponent); |
38 | } |
39 | return matchComponents; |
40 | } |
41 | |
42 | void addComponent(QComponent *comp); |
43 | void removeComponent(QComponent *comp); |
44 | |
45 | QEntity *parentEntity() const; |
46 | |
47 | protected: |
48 | explicit QEntity(QEntityPrivate &dd, QNode *parent = nullptr); |
49 | |
50 | private Q_SLOTS: |
51 | void onParentChanged(QObject *); |
52 | |
53 | private: |
54 | Q_DECLARE_PRIVATE(QEntity) |
55 | }; |
56 | |
57 | typedef QSharedPointer<QEntity> QEntityPtr; |
58 | |
59 | } // namespace Qt3DCore |
60 | |
61 | QT_END_NAMESPACE |
62 | |
63 | #endif // QT3DCORE_QENTITY_H |
64 |