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 "updatetreeenabledjob_p.h" |
5 | |
6 | #include <Qt3DRender/private/entity_p.h> |
7 | #include <Qt3DRender/private/job_common_p.h> |
8 | #include <Qt3DRender/private/managers_p.h> |
9 | #include <Qt3DRender/private/nodemanagers_p.h> |
10 | |
11 | #include <QThread> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | namespace Qt3DRender { |
16 | namespace Render { |
17 | |
18 | namespace { |
19 | |
20 | void updateTreeEnabled(NodeManagers *manager, Entity *node, bool parentEnabled) |
21 | { |
22 | const bool treeEnabled = node->isEnabled() && parentEnabled; |
23 | node->setTreeEnabled(treeEnabled); |
24 | |
25 | const auto &childrenHandles = node->childrenHandles(); |
26 | for (const HEntity &handle : childrenHandles) { |
27 | Entity *child = manager->renderNodesManager()->data(handle); |
28 | if (child) |
29 | updateTreeEnabled(manager, node: child, parentEnabled: treeEnabled); |
30 | } |
31 | } |
32 | |
33 | } |
34 | |
35 | UpdateTreeEnabledJob::UpdateTreeEnabledJob() |
36 | : Qt3DCore::QAspectJob() |
37 | , m_node(nullptr) |
38 | , m_manager(nullptr) |
39 | { |
40 | SET_JOB_RUN_STAT_TYPE(this, JobTypes::UpdateTreeEnabled, 0) |
41 | } |
42 | |
43 | void UpdateTreeEnabledJob::setRoot(Entity *root) |
44 | { |
45 | m_node = root; |
46 | } |
47 | |
48 | void UpdateTreeEnabledJob::setManagers(NodeManagers *manager) |
49 | { |
50 | m_manager = manager; |
51 | } |
52 | |
53 | void UpdateTreeEnabledJob::run() |
54 | { |
55 | if (m_node && m_manager) |
56 | updateTreeEnabled(manager: m_manager, node: m_node, parentEnabled: true); |
57 | } |
58 | |
59 | } // namespace Render |
60 | } // namespace Qt3DRender |
61 | |
62 | QT_END_NAMESPACE |
63 | |