예제 #1
0
void CParentNode::RemoveOrCopyChildren( QVector<CNode*> &children, long nFrom, long nTo, int fRemove )
{
	if( nTo == -1 ) nTo = (long) m_children.size();
	Q_ASSERT( nTo <= (long) m_children.size() );
	Q_ASSERT( nTo >= nFrom );
	children.resize( nTo - nFrom );
	if( children.size() )
	{
		for( long i = 0; i < (long) children.size(); i++ )
		{
			children[ i ] = (fRemove ? m_children[ nFrom + i ] : CreateCopy( m_children[ nFrom + i ] ) );
			children[ i ]->SetParent( NULL );
		}

		children[ 0 ]->SetPrev( NULL );
		children[ children.size() - 1 ]->SetNext( NULL );
		if( fRemove )
		{
			m_children.remove( nFrom, nTo - nFrom );
			CNode *pPrev = (nFrom - 1 > -1 && nFrom - 1 < (long) m_children.size()) ? m_children[ nFrom - 1 ] : NULL;
			CNode *pNext = (nFrom > -1 && nFrom < (long) m_children.size()) ? m_children[ nFrom ] : NULL;
			if( pPrev ) pPrev->SetNext( pNext );
			if( pNext ) pNext->SetPrev( pPrev );
		}
	}
}
예제 #2
0
CNode* CParentNode::RemoveChild( long no )
{
	CNode *pNode = GetChild( no );

	if( pNode )
	{
		if( pNode->GetPrev() )
			pNode->GetPrev()->SetNext( pNode->GetNext() );
		if( pNode->GetNext() )
			pNode->GetNext()->SetPrev( pNode->GetPrev() );
		pNode->SetNext( NULL );
		pNode->SetPrev( NULL );
		pNode->SetParent( NULL );

		m_children.remove( no );
	}

	return pNode;
}
예제 #3
0
void CParentNode::InsertChildren( QVector<CNode*> &children, long nBefore )
{
	if( children.size() )
	{
		if( nBefore == -1 ) nBefore = (long) m_children.size();
		if( m_children.size() )
		{
			CNode *pPrev = (nBefore - 1 > -1 && nBefore - 1 < (long) m_children.size() ? m_children[ nBefore - 1 ] : NULL);
			CNode *pNext = (nBefore > -1 && nBefore < (long) m_children.size() ? m_children[ nBefore ]: NULL);
			if( pNext ) pNext->SetPrev( children[ children.size() - 1 ] );
			if( pPrev ) pPrev->SetNext( children[ 0 ] );
			children[ children.size() - 1 ]->SetNext( pNext );
			children[ 0 ]->SetPrev( pPrev );
		}
		for( long i = 0; i < children.size(); i++ )
		{
			children[ i ]->SetParent( this );
			children[ i ]->SetLevel( GetLevel() );
			m_children.insert( nBefore + i, children[ i ] );
		}
		children.clear();
	}
}