void GraphComponent::addChildInternal( GraphComponentPtr child ) { child->parentChanging( this ); GraphComponent *previousParent = child->m_parent; if( previousParent ) { // remove the child from the previous parent, but don't emit parentChangedSignal. // this prevents a parent changed signal with new parent 0 followed by a parent // changed signal with the new parent. previousParent->removeChildInternal( child, false ); } m_children.push_back( child ); child->m_parent = this; child->setName( child->m_name.value() ); // to force uniqueness childAddedSignal()( this, child.get() ); child->parentChangedSignal()( child.get(), previousParent ); }
void GraphComponent::addChildInternal( GraphComponentPtr child, size_t index ) { child->parentChanging( this ); GraphComponent *previousParent = child->m_parent; if( previousParent ) { // remove the child from the previous parent, but don't emit parentChangedSignal. // this prevents a parent changed signal with new parent null followed by a parent // changed signal with the new parent. previousParent->removeChildInternal( child, false ); } m_children.insert( m_children.begin() + min( index, m_children.size() ), child ); child->m_parent = this; child->setName( child->m_name.value() ); // to force uniqueness Signals::emitLazily( m_signals.get(), &Signals::childAddedSignal, this, child.get() ); child->parentChanged( previousParent ); Signals::emitLazily( child->m_signals.get(), &Signals::parentChangedSignal, child.get(), previousParent ); }