QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskTreeNode.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskTreeNode.h"
7
8static const auto extraFlag =
9 static_cast< QSGNode::Flag >( QSGNode::IsVisitableNode << 1 );
10
11static inline QSGNode* qskCheckedNode( const QSGNode* node, QSGNode::NodeType type )
12{
13 return node && ( node->type() == type ) && ( node->flags() & extraFlag )
14 ? const_cast< QSGNode* >( node ) : nullptr;
15}
16
17QskTreeNode::QskTreeNode()
18{
19 setFlag( extraFlag, true );
20}
21
22QskTreeNode::QskTreeNode( QSGNodePrivate& d )
23 : QSGNode( d, QSGNode::BasicNodeType )
24{
25 setFlag( extraFlag, true );
26}
27
28QskTreeNode::~QskTreeNode()
29{
30}
31
32void QskTreeNode::setSubtreeBlocked( bool on, bool notify )
33{
34 if ( on == m_isBlocked )
35 return;
36
37 m_isBlocked = on;
38
39 if ( notify )
40 markDirty( DirtySubtreeBlocked );
41}
42
43bool QskTreeNode::isSubtreeBlocked() const
44{
45 return m_isBlocked;
46}
47
48QskTreeNode* qskTreeNodeCast( QSGNode* node )
49{
50 return static_cast< QskTreeNode* >(
51 qskCheckedNode( node, QSGNode::BasicNodeType ) );
52}
53
54const QskTreeNode* qskTreeNodeCast( const QSGNode* node )
55{
56 return static_cast< QskTreeNode* >(
57 qskCheckedNode( node, QSGNode::BasicNodeType ) );
58}
59
60
61// == QskItemNode
62
63QskItemNode::QskItemNode()
64{
65 setFlag( extraFlag, true );
66}
67
68QskItemNode::~QskItemNode()
69{
70}
71
72void QskItemNode::setSubtreeBlocked( bool on, bool notify )
73{
74 if ( on == m_isBlocked )
75 return;
76
77 m_isBlocked = on;
78
79 if ( notify )
80 markDirty( DirtySubtreeBlocked );
81}
82
83bool QskItemNode::isSubtreeBlocked() const
84{
85 return m_isBlocked;
86}
87
88QskItemNode* qskItemNodeCast( QSGNode* node )
89{
90 return static_cast< QskItemNode* >(
91 qskCheckedNode( node, QSGNode::TransformNodeType ) );
92}
93
94const QskItemNode* qskItemNodeCast( const QSGNode* node )
95{
96 return static_cast< QskItemNode* >(
97 qskCheckedNode( node, QSGNode::TransformNodeType ) );
98}
99
100bool qskIsBlockableNode( const QSGNode* node )
101{
102 switch( node->type() )
103 {
104 case QSGNode::BasicNodeType:
105 case QSGNode::TransformNodeType:
106 return node->flags() & extraFlag;
107
108 default:
109 return false;
110 }
111}
112
113bool qskTryBlockNode( QSGNode* node, bool on, bool notify )
114{
115 if ( node && ( node->flags() & extraFlag ) )
116 {
117 if ( node->type() == QSGNode::BasicNodeType )
118 {
119 static_cast< QskTreeNode* >( node )->setSubtreeBlocked( on, notify );
120 return true;
121 }
122
123 if ( node->type() == QSGNode::TransformNodeType )
124 {
125 static_cast< QskItemNode* >( node )->setSubtreeBlocked( on, notify );
126 return true;
127 }
128 }
129
130 return false;
131}
132
133void qskTryBlockTree( QSGNode* node, bool on, bool notify )
134{
135 if ( qskTryBlockNode( node, on, notify ) )
136 return;
137
138 for ( auto child = node->firstChild();
139 child != nullptr; child = child->nextSibling() )
140 {
141 qskTryBlockTree( child, on, notify );
142 }
143}
144
145void qskTryBlockTrailingNodes(
146 QSGNode* node, const QSGNode* ancestorNode, bool on, bool notify )
147{
148 qskTryBlockTree( node, on, notify );
149
150 for ( auto sibling = node->nextSibling();
151 sibling != nullptr; sibling = sibling->nextSibling() )
152 {
153 qskTryBlockTree( sibling, on, notify );
154 }
155
156 if ( node != ancestorNode )
157 {
158 if ( auto upperNode = node->parent() )
159 {
160 upperNode = upperNode->nextSibling();
161 if ( upperNode )
162 qskTryBlockTrailingNodes( upperNode, ancestorNode, on, notify );
163 }
164 }
165}