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