summaryrefslogtreecommitdiffstats
path: root/src/core/nodes
diff options
context:
space:
mode:
authorJuan Jose Casafranca <juan.casafranca@kdab.com>2018-02-04 20:34:06 +0100
committerJuan José Casafranca <juan.casafranca@kdab.com>2018-09-19 13:32:08 +0000
commitb3d15538a995843a000be92b03fc7b1ac8b87826 (patch)
tree4162b563087ccb9028ab720727e087b4701688a1 /src/core/nodes
parent4c7f3546b42c320c600bdba92e4e9126cbeedae3 (diff)
Add an easy way to get a particular component from an entity
Change-Id: I188fab5019d3e05354a4c1582fb12097a569fbb8 Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/core/nodes')
-rw-r--r--src/core/nodes/qentity.cpp7
-rw-r--r--src/core/nodes/qentity.h13
2 files changed, 20 insertions, 0 deletions
diff --git a/src/core/nodes/qentity.cpp b/src/core/nodes/qentity.cpp
index 64ea65087..3c8805a67 100644
--- a/src/core/nodes/qentity.cpp
+++ b/src/core/nodes/qentity.cpp
@@ -77,6 +77,13 @@ namespace Qt3DCore {
\sa Qt3DCore::QComponent, Qt3DCore::QTransform
*/
+/*!
+ \fn template<typename T> QVector<T *> QEntity::componentsOfType() const
+
+ Returns all the components added to this entity that can be cast to
+ type T or an empty vector if there are no such components.
+*/
+
/*! \internal */
QEntityPrivate::QEntityPrivate()
: QNodePrivate()
diff --git a/src/core/nodes/qentity.h b/src/core/nodes/qentity.h
index dc7dc62c1..ef6aedc4d 100644
--- a/src/core/nodes/qentity.h
+++ b/src/core/nodes/qentity.h
@@ -62,6 +62,19 @@ public:
QComponentVector components() const;
+ template<class T>
+ QVector<T *> componentsOfType() const
+ {
+ QVector<T*> matchComponents;
+ const QComponentVector components = this->components();
+ for (QComponent *component : components) {
+ T *typedComponent = qobject_cast<T*>(component);
+ if (typedComponent != nullptr)
+ matchComponents.append(typedComponent);
+ }
+ return matchComponents;
+ }
+
void addComponent(QComponent *comp);
void removeComponent(QComponent *comp);