summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@theqtcompany.com>2015-08-21 16:23:27 +0200
committerAndy Nichols <andy.nichols@theqtcompany.com>2015-10-27 10:48:56 +0000
commit31a4c1e3438bc47ac9d488f557f6144f0a7463ba (patch)
treef6a3ca82b7551c26003e42f4c94352b1510ccf5d
parent5017dd3572badfa9cd80eca3be220fd6f5635520 (diff)
QNode: Introduce enabled property
Previously there was only and enable property for the QNode subclass QComponent, but now all QNode subclasses should also have an enable property. This means that it is now possible to disable a QEntity which would also disable all of its children. This is a bit tricky though because each Aspect needs to now check if the corresponding QEntities are disabled or not before processing. This has been accounted for with RenderEntity in the Renderer already, but will need to be respected in each Aspect. This behavior is similar to the Unity3D GameObject active property which disabled the entity and disables all components. Change-Id: I5233b2b43f04aa5dfa7910eac6a88a9da656a997 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/core/nodes/qcomponent.cpp32
-rw-r--r--src/core/nodes/qcomponent.h4
-rw-r--r--src/core/nodes/qcomponent_p.h1
-rw-r--r--src/core/nodes/qentity.cpp2
-rw-r--r--src/core/nodes/qentity.h1
-rw-r--r--src/core/nodes/qentity_p.h1
-rw-r--r--src/core/nodes/qnode.cpp30
-rw-r--r--src/core/nodes/qnode.h5
-rw-r--r--src/core/nodes/qnode_p.h1
-rw-r--r--src/render/backend/entity.cpp20
-rw-r--r--src/render/backend/entity_p.h4
-rw-r--r--src/render/backend/renderview.cpp4
12 files changed, 63 insertions, 42 deletions
diff --git a/src/core/nodes/qcomponent.cpp b/src/core/nodes/qcomponent.cpp
index 1e81f9204..338a6a2fa 100644
--- a/src/core/nodes/qcomponent.cpp
+++ b/src/core/nodes/qcomponent.cpp
@@ -52,7 +52,6 @@ namespace Qt3DCore {
QComponentPrivate::QComponentPrivate()
: QNodePrivate()
, m_shareable(true)
- , m_enabled(true)
{
}
@@ -144,32 +143,6 @@ bool QComponent::shareable() const
}
/*!
- Returns whether the QComponent is enabled or not.
-*/
-bool QComponent::isEnabled() const
-{
- Q_D(const QComponent);
- return d->m_enabled;
-}
-
-/*!
- Set the QComponent to enabled if \a enabled is true.
- By default a Qt3DCore::QComponent is always enabled.
-
- \note the interpretation of what enabled means is aspect-dependent. Even if
- enabled is set to false, some aspects may still consider the component in
- some manner. This is documented on a class by class basis.
-*/
-void QComponent::setEnabled(bool enabled)
-{
- Q_D(QComponent);
- if (d->m_enabled != enabled) {
- d->m_enabled = enabled;
- emit enabledChanged();
- }
-}
-
-/*!
The QComponent can be shared across several entities if \a shareable is true.
*/
void QComponent::setShareable(bool shareable)
@@ -185,7 +158,6 @@ void QComponent::copy(const QNode *ref)
{
QNode::copy(ref);
const QComponent *comp = static_cast<const QComponent *>(ref);
- setEnabled(comp->isEnabled());
setShareable(comp->shareable());
}
@@ -218,8 +190,4 @@ QComponent::QComponent(QComponentPrivate &dd, QNode *parent)
\qmlproperty bool Qt3DCore::Component3D::shareable
*/
-/*!
- \qmlproperty bool Qt3DCore::Component3D::enabled
-*/
-
QT_END_NAMESPACE
diff --git a/src/core/nodes/qcomponent.h b/src/core/nodes/qcomponent.h
index 2eee89bb4..78ec6f0ae 100644
--- a/src/core/nodes/qcomponent.h
+++ b/src/core/nodes/qcomponent.h
@@ -50,7 +50,6 @@ class QT3DCORESHARED_EXPORT QComponent : public QNode
{
Q_OBJECT
Q_PROPERTY(bool shareable READ shareable WRITE setShareable NOTIFY shareableChanged)
- Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
public:
explicit QComponent(QNode *parent = 0);
@@ -59,9 +58,6 @@ public:
bool shareable() const;
void setShareable(bool shareable);
- bool isEnabled() const;
- void setEnabled(bool enabled);
-
QVector<QEntity *> entities() const;
protected:
diff --git a/src/core/nodes/qcomponent_p.h b/src/core/nodes/qcomponent_p.h
index 56c807a61..8f567c4b4 100644
--- a/src/core/nodes/qcomponent_p.h
+++ b/src/core/nodes/qcomponent_p.h
@@ -65,7 +65,6 @@ public:
Q_DECLARE_PUBLIC(QComponent)
bool m_shareable;
- bool m_enabled;
QVector<QEntity *> m_entities;
};
diff --git a/src/core/nodes/qentity.cpp b/src/core/nodes/qentity.cpp
index 7e0a66c82..ca2a3acf8 100644
--- a/src/core/nodes/qentity.cpp
+++ b/src/core/nodes/qentity.cpp
@@ -57,7 +57,6 @@ namespace Qt3DCore {
*/
QEntityPrivate::QEntityPrivate()
: QNodePrivate()
- , m_enabled(true)
, m_parentEntityId()
{}
@@ -113,7 +112,6 @@ void QEntity::copy(const QNode *ref)
{
QNode::copy(ref);
const QEntity *entity = static_cast<const QEntity*>(ref);
- d_func()->m_enabled = entity->d_func()->m_enabled;
d_func()->m_visible = entity->d_func()->m_visible;
d_func()->m_parentEntityId = entity->parentEntityId();
diff --git a/src/core/nodes/qentity.h b/src/core/nodes/qentity.h
index 2b87f0c39..36ffb2a6e 100644
--- a/src/core/nodes/qentity.h
+++ b/src/core/nodes/qentity.h
@@ -54,7 +54,6 @@ typedef QList<QComponent*> QComponentList;
class QT3DCORESHARED_EXPORT QEntity : public QNode
{
Q_OBJECT
-
public:
explicit QEntity(QNode *parent = 0);
virtual ~QEntity();
diff --git a/src/core/nodes/qentity_p.h b/src/core/nodes/qentity_p.h
index 03812dfae..be37c1c85 100644
--- a/src/core/nodes/qentity_p.h
+++ b/src/core/nodes/qentity_p.h
@@ -68,7 +68,6 @@ public :
// TODO: Is a bool enough here or do we need additional states for entities?
// Perhaps aboutToBeDeleted would be useful?
- bool m_enabled;
mutable QNodeId m_parentEntityId;
};
diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp
index 9ba2fe3c0..15a7a5bf3 100644
--- a/src/core/nodes/qnode.cpp
+++ b/src/core/nodes/qnode.cpp
@@ -67,6 +67,7 @@ QNodePrivate::QNodePrivate()
, m_id(QNodeId::createId())
, m_blockNotifications(false)
, m_wasCleanedUp(false)
+ , m_enabled(true)
, m_propertyChangesSetup(false)
, m_signals(this)
{
@@ -461,6 +462,7 @@ void QNode::copy(const QNode *ref)
{
if (ref) {
d_func()->m_id = ref->d_func()->m_id;
+ d_func()->m_enabled = ref->d_func()->m_enabled;
setObjectName(ref->objectName());
}
}
@@ -553,6 +555,33 @@ QNodeList QNode::childrenNodes() const
return nodeChildrenList;
}
+/*!
+ Set the QNode to enabled if \a enabled is true.
+ By default a Qt3DCore::QNode is always enabled.
+
+ \note the interpretation of what enabled means is aspect-dependent. Even if
+ enabled is set to false, some aspects may still consider the node in
+ some manner. This is documented on a class by class basis.
+*/
+void QNode::setEnabled(bool isEnabled)
+{
+ Q_D(QNode);
+
+ if (d->m_enabled == isEnabled)
+ return;
+
+ d->m_enabled = isEnabled;
+ emit enabledChanged(isEnabled);
+}
+
+/*!
+ Returns whether the QNode is enabled or not.
+*/
+bool QNode::isEnabled() const
+{
+ Q_D(const QNode);
+ return d->m_enabled;
+}
/*!
Returns a clone of \a node. All the children of \a node are cloned as well.
@@ -616,7 +645,6 @@ void QNode::cleanup()
} // namespace Qt3DCore
-
QT_END_NAMESPACE
#include "moc_qnode.cpp"
diff --git a/src/core/nodes/qnode.h b/src/core/nodes/qnode.h
index 1c0266ec2..39d0eca95 100644
--- a/src/core/nodes/qnode.h
+++ b/src/core/nodes/qnode.h
@@ -74,6 +74,7 @@ class QT3DCORESHARED_EXPORT QNode : public QObject
{
Q_OBJECT
Q_PROPERTY(Qt3DCore::QNode *parent READ parentNode WRITE setParent NOTIFY parentChanged)
+ Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
public:
explicit QNode(QNode *parent = 0);
virtual ~QNode();
@@ -87,6 +88,9 @@ public:
virtual void setParent(QNode *parent);
QNodeList childrenNodes() const;
+ void setEnabled(bool isEnabled);
+ bool isEnabled() const;
+
protected:
// Clone should only be made in the main thread
static QNode *clone(QNode *node);
@@ -114,6 +118,7 @@ private:
Q_SIGNALS:
void parentChanged();
+ void enabledChanged(bool enabled);
};
} // namespace Qt3DCore
diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h
index b51dff472..ef46b2e7a 100644
--- a/src/core/nodes/qnode_p.h
+++ b/src/core/nodes/qnode_p.h
@@ -86,6 +86,7 @@ public:
mutable QNodeId m_id;
bool m_blockNotifications;
bool m_wasCleanedUp;
+ bool m_enabled;
static QNodePrivate *get(QNode *q);
static void nodePtrDeleter(QNode *q);
diff --git a/src/render/backend/entity.cpp b/src/render/backend/entity.cpp
index 7cbf7605f..c76405fab 100644
--- a/src/render/backend/entity.cpp
+++ b/src/render/backend/entity.cpp
@@ -66,6 +66,7 @@ namespace Render {
Entity::Entity()
: QBackendNode()
, m_renderer(Q_NULLPTR)
+ , m_enabled(true)
{
}
@@ -103,6 +104,7 @@ void Entity::cleanup()
m_localBoundingVolume.reset();
m_worldBoundingVolume.reset();
m_worldBoundingVolumeWithChildren.reset();
+ m_enabled = true;
}
void Entity::setParentHandle(HEntity parentHandle)
@@ -156,6 +158,8 @@ void Entity::updateFromPeer(Qt3DCore::QNode *peer)
} else {
qCDebug(Render::RenderNodes) << Q_FUNC_INFO << "No parent entity found for Entity" << peerUuid();
}
+
+ m_enabled = entity->isEnabled();
}
void Entity::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
@@ -178,6 +182,12 @@ void Entity::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
break;
}
+ case NodeUpdated: {
+ if (propertyChange->propertyName() == QByteArrayLiteral("enabled"))
+ m_enabled = propertyChange->value().value<bool>();
+ break;
+ }
+
default:
break;
}
@@ -277,6 +287,16 @@ void Entity::removeComponent(const Qt3DCore::QNodeId &nodeId)
m_objectPickerComponent = QNodeId();
}
+bool Entity::isEnabled() const
+{
+ return m_enabled;
+}
+
+void Entity::setEnabled(bool isEnabled)
+{
+ m_enabled = isEnabled;
+}
+
template<>
HMaterial Entity::componentHandle<Material>() const
{
diff --git a/src/render/backend/entity_p.h b/src/render/backend/entity_p.h
index 64e90db5c..d03e8e1cb 100644
--- a/src/render/backend/entity_p.h
+++ b/src/render/backend/entity_p.h
@@ -108,6 +108,9 @@ public:
void addComponent(Qt3DCore::QComponent *component);
void removeComponent(const Qt3DCore::QNodeId &nodeId);
+ bool isEnabled() const;
+ void setEnabled(bool isEnabled);
+
template<class Backend, uint INDEXBITS>
Qt3DCore::QHandle<Backend, INDEXBITS> componentHandle() const
{
@@ -177,6 +180,7 @@ private:
Qt3DCore::QNodeId m_objectPickerComponent;
QString m_objectName;
+ bool m_enabled;
};
template<>
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp
index d1ca14fc3..8065a2e83 100644
--- a/src/render/backend/renderview.cpp
+++ b/src/render/backend/renderview.cpp
@@ -374,6 +374,10 @@ void RenderView::setRenderer(Renderer *renderer)
// Tries to order renderCommand by shader so as to minimize shader changes
void RenderView::buildRenderCommands(Entity *node)
{
+ // Skip branches that are not enabled
+ if (!node->isEnabled())
+ return;
+
// Build renderCommand for current node
if (isEntityInLayers(node, m_data->m_layers)) {
GeometryRenderer *geometryRenderer = Q_NULLPTR;