本文整理汇总了C++中QNode::d_func方法的典型用法代码示例。如果您正苦于以下问题:C++ QNode::d_func方法的具体用法?C++ QNode::d_func怎么用?C++ QNode::d_func使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNode
的用法示例。
在下文中一共展示了QNode::d_func方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _q_setParentHelper
/*!
* \internal
*
* Reparents the public QNode to \a parent. If the new parent is nullptr then this
* QNode is no longer part of the scene and so we notify the backend of its removal
* from its parent's list of children, and then send a QNodeDestroyedChange to the
* aspects so that the corresponding backend node is destroyed.
*
* If \a parent is not null, then we must tell its new parent about this QNode now
* being a child of it on the backend. If this QNode did not have a parent upon
* entry to this function, then we must first send a QNodeCreatedChange to the backend
* prior to sending the QPropertyNodeAddedChange to its parent.
*
* Note: This function should never be called from the ctor directly as the type may
* not be fully created yet and creating creation changes involves calling a virtual
* function on QNode. The function _q_notifyCreationAndChildChanges() is used
* for sending initial notification when a parent is passed to the QNode ctor.
* That function does a subset of this function with the assumption that the new object
* had no parent before (must be true as it is newly constructed).
*/
void QNodePrivate::_q_setParentHelper(QNode *parent)
{
Q_Q(QNode);
QNode *oldParentNode = q->parentNode();
// We may get the situation where the QML engine has set the QObject
// parent but we have not yet set up the QNode parent requirements.
// This check handles this and means we propagate the scene and arbiter
// from the parent in the code below.
const bool needsSceneInit = !oldParentNode
|| (oldParentNode && m_parentId != oldParentNode->id());
// If we had a parent, we let him know that we are about to change
// parent
if (oldParentNode && m_hasBackendNode) {
QNodePrivate::get(oldParentNode)->_q_removeChild(q);
// If we have an old parent but the new parent is null
// the backend node needs to be destroyed
if (!parent)
notifyDestructionChangesAndRemoveFromScene();
}
// Flag that we need to notify any new parent
m_notifiedParent = false;
// Basically QObject::setParent but for QObjectPrivate
QObjectPrivate::setParent_helper(parent);
QNode *newParentNode = q->parentNode();
if (newParentNode) {
// If we had no parent but are about to set one,
// we need to send a QNodeCreatedChange
if (needsSceneInit) {
QNodePrivate *newParentPrivate = QNodePrivate::get(newParentNode);
// Set the scene helper / arbiter
if (newParentPrivate->m_scene) {
QNodeVisitor visitor;
visitor.traverse(q, newParentNode->d_func(), &QNodePrivate::setSceneHelper);
}
// We want to make sure that subTreeRoot is always created before
// child.
// Given a case such as below
// QEntity *subTreeRoot = new QEntity(someGlobalExisitingRoot)
// QEntity *child = new QEntity();
// child->setParent(subTreeRoot)
// We need to take into account that subTreeRoot needs to be
// created in the backend before the child.
// Therefore we only call notifyCreationChanges if the parent
// hasn't been created yet as we know that when the parent will be
// fully created, it will also send the changes for all of its
// children
if (QNodePrivate::get(newParentNode)->m_hasBackendNode)
notifyCreationChange();
}
// If we have a valid new parent, we let him know that we are its child
QNodePrivate::get(newParentNode)->_q_addChild(q);
}
}