8static inline void qskRemoveChildNode( QSGNode* parent, QSGNode* child )
10 parent->removeChildNode( child );
12 if ( child->flags() & QSGNode::OwnedByParent )
17static inline void qskRemoveAllChildNodesAfter( QSGNode* parent, QSGNode* child )
19 while (
auto sibling = parent->lastChild() )
21 if ( sibling == child )
24 qskRemoveChildNode( parent, sibling );
28static void qskInsertChildSorted( QSGNode* parent, QSGNode* child,
29 const QVector< quint8 >& roles )
31 QSGNode* sibling =
nullptr;
33 if ( parent->childCount() > 0 )
35 using namespace QskSGNode;
37 const int nodePos = roles.indexOf( nodeRole( child ) );
41 for (
auto childNode = parent->lastChild();
42 childNode !=
nullptr; childNode = childNode->previousSibling() )
44 const auto childNodeRole = nodeRole( childNode );
45 if ( childNodeRole == BackgroundRole )
56 const int index = roles.indexOf( nodeRole( childNode ) );
57 if ( index >= 0 && index < nodePos )
61 if ( sibling !=
nullptr )
67 parent->insertChildNodeAfter( child, sibling );
69 parent->prependChildNode( child );
72void QskSGNode::setParentNode( QSGNode* node, QSGNode* parent )
76 auto oldParent = node->parent();
78 if ( oldParent != parent )
81 oldParent->removeChildNode( node );
84 parent->appendChildNode( node );
89QSGNode* QskSGNode::findChildNode( QSGNode* parent, quint8 role )
91 auto node = parent->firstChild();
94 if ( nodeRole( node ) == role )
97 node = node->nextSibling();
103bool QskSGNode::removeChildNode( QSGNode* parent, quint8 role )
105 if (
auto node = findChildNode( parent, role ) )
107 qskRemoveChildNode( parent, node );
114void QskSGNode::removeAllChildNodesAfter( QSGNode* parent, QSGNode* child )
116 if ( parent && child && child->parent() == parent )
117 qskRemoveAllChildNodesAfter( parent, child );
120void QskSGNode::removeAllChildNodesFrom( QSGNode* parent, QSGNode* child )
122 if ( parent && child && child->parent() == parent )
124 qskRemoveAllChildNodesAfter( parent, child );
125 qskRemoveChildNode( parent, child );
129void QskSGNode::replaceChildNode(
130 const QVector< quint8 >& roles, quint8 role,
131 QSGNode* parentNode, QSGNode* oldNode, QSGNode* newNode )
133 if ( newNode && newNode->parent() != parentNode )
135 setNodeRole( newNode, role );
141 parentNode->prependChildNode( newNode );
146 auto firstNode = parentNode->firstChild();
148 if ( firstNode && ( nodeRole( firstNode ) == BackgroundRole ) )
149 parentNode->insertChildNodeAfter( newNode, firstNode );
151 parentNode->prependChildNode( newNode );
157 qskInsertChildSorted( parentNode, newNode, roles );
162 if ( oldNode && oldNode != newNode )
164 parentNode->removeChildNode( oldNode );
165 if ( oldNode->flags() & QSGNode::OwnedByParent )
170void QskSGNode::resetGeometry( QSGGeometryNode* node )
174 if (
auto g = node->geometry() )
176 const bool hasVertices = g->vertexCount() > 0;
177 const bool hasIndexes = g->indexCount() > 0;
179 if ( hasVertices || hasIndexes )
184 g->markVertexDataDirty();
187 g->markIndexDataDirty();
189 node->markDirty( QSGNode::DirtyGeometry );