1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qblendtreenode_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \qmltype BlendTreeNode |
10 | \inherits QObject |
11 | \nativetype QBlendTreeNode |
12 | \inqmlmodule QtQuick.Timeline.BlendTrees |
13 | \ingroup qtqmltypes |
14 | |
15 | \brief Base class for all blend tree nodes. |
16 | |
17 | BlendTreeNode is the base class for all blend tree nodes. It is not |
18 | intended to be used directly, but rather to be subclassed to create |
19 | custom blend tree nodes. |
20 | */ |
21 | |
22 | /*! |
23 | \qmlproperty bool BlendTreeNode::outputEnabled |
24 | |
25 | This property determines whether the blend tree node should commit |
26 | the property changes. The default value is /c false. |
27 | |
28 | Any node can be an output node which commits the property changes, |
29 | but it should usually be the last node in the blend tree. If multiple |
30 | nodes are outputting data and there is a conflict, then the last |
31 | property change will be used. So ideally if there are multiple output |
32 | nodes in a tree, the targets and properties effected should be disjoint. |
33 | */ |
34 | |
35 | QBlendTreeNode::QBlendTreeNode(QObject *parent) |
36 | : QObject{parent} |
37 | { |
38 | connect(sender: this, signal: &QBlendTreeNode::frameDataChanged, context: this, slot: &QBlendTreeNode::handleFrameDataChanged); |
39 | connect(sender: this, signal: &QBlendTreeNode::outputEnabledChanged, context: this, slot: &QBlendTreeNode::handleFrameDataChanged); |
40 | } |
41 | |
42 | const QHash<QQmlProperty, QVariant> &QBlendTreeNode::frameData() |
43 | { |
44 | return m_frameData; |
45 | } |
46 | |
47 | bool QBlendTreeNode::outputEnabled() const |
48 | { |
49 | return m_outputEnabled; |
50 | } |
51 | |
52 | void QBlendTreeNode::setOutputEnabled(bool isOutputEnabled) |
53 | { |
54 | if (m_outputEnabled == isOutputEnabled) |
55 | return; |
56 | m_outputEnabled = isOutputEnabled; |
57 | Q_EMIT outputEnabledChanged(); |
58 | } |
59 | |
60 | void QBlendTreeNode::handleFrameDataChanged() |
61 | { |
62 | // If we are not outputting data, then there is nothing to do |
63 | if (!m_outputEnabled) |
64 | return; |
65 | |
66 | // Commit the property |
67 | for (auto it = m_frameData.cbegin(), end = m_frameData.cend(); it != end; ++it) { |
68 | const auto &property = it.key(); |
69 | property.write(it.value()); |
70 | } |
71 | } |
72 | |
73 | QT_END_NAMESPACE |
74 | |