Here the solution I wrote :
{
// Check if the item is the same.
if( Item == TestItem )
return true;
// For each child of the item.
for( int i = 0; i < Item->childCount(); ++i )
{
// Check if we found the item.
if( RecursiveFindItem( Item->child( i ), TestItem ) )
return true;
}
// Return not found.
return false;
}
void CSceneOutlinerWidget::DeleteSelectedActors()
{
// Find unique items.
{
// Find the selected item in the list.
bool ItemFound = false;
{
if( RecursiveFindItem( UniqueItem, Item ) )
{
ItemFound = true;
break;
}
}
// Remove the item if found or add in the list.
if( ItemFound )
UniqueItems.removeOne( Item );
else
UniqueItems.append( Item );
}
// Delete each unique item.
{
CSceneOutlinerItem* SceneOutlinerItem = static_cast< CSceneOutlinerItem* >( Item );
CMainEditorWindow::GetUndoStack()->push( new CUndoCommandDeleteActor( SceneOutlinerItem->GetUniqueID() ) );
}
}
bool RecursiveFindItem( QTreeWidgetItem* Item, QTreeWidgetItem* TestItem )
{
// Check if the item is the same.
if( Item == TestItem )
return true;
// For each child of the item.
for( int i = 0; i < Item->childCount(); ++i )
{
// Check if we found the item.
if( RecursiveFindItem( Item->child( i ), TestItem ) )
return true;
}
// Return not found.
return false;
}
void CSceneOutlinerWidget::DeleteSelectedActors()
{
// Find unique items.
QList< QTreeWidgetItem* > UniqueItems;
foreach( QTreeWidgetItem* Item, m_SceneOutlinerTree->selectedItems() )
{
// Find the selected item in the list.
bool ItemFound = false;
foreach( QTreeWidgetItem* UniqueItem, UniqueItems )
{
if( RecursiveFindItem( UniqueItem, Item ) )
{
ItemFound = true;
break;
}
}
// Remove the item if found or add in the list.
if( ItemFound )
UniqueItems.removeOne( Item );
else
UniqueItems.append( Item );
}
// Delete each unique item.
foreach( QTreeWidgetItem* Item, UniqueItems )
{
CSceneOutlinerItem* SceneOutlinerItem = static_cast< CSceneOutlinerItem* >( Item );
CMainEditorWindow::GetUndoStack()->push( new CUndoCommandDeleteActor( SceneOutlinerItem->GetUniqueID() ) );
}
}
To copy to clipboard, switch view to plain text mode
That works but the I surely missed something because if I select A then B then C, only A is removed, if I select C then B then A I got 3 item to delete, normally only A is needed.
EDIT : The final solution working :
{
// Check if the item is the same.
if( Item == TestItem )
return true;
// For each child of the item.
for( int i = 0; i < Item->childCount(); ++i )
{
// Check if we found the item.
if( RecursiveFindItem( Item->child( i ), TestItem ) )
return true;
}
// Return not found.
return false;
}
{
// Remove the item if found in the unique list.
{
if( UniqueItem == Item )
{
UniqueItems->removeOne( UniqueItem );
break;
}
}
// For each child of the item.
for( int i = 0; i < Item->childCount(); ++i )
RecursiveRemoveUniqueItems( Item->child( i ), UniqueItems );
}
void CSceneOutlinerWidget::DeleteSelectedActors()
{
// Find unique items.
{
// Remove item and children if already in unique list.
RecursiveRemoveUniqueItems( Item, &UniqueItems );
// Search the item.
bool ItemFound = false;
{
if( RecursiveFindItem( UniqueItem, Item ) )
{
ItemFound = true;
break;
}
}
// Check if the item is found.
if( ItemFound )
continue;
// Add the item in the list.
UniqueItems.append( Item );
}
// Delete each unique item.
{
CSceneOutlinerItem* SceneOutlinerItem = static_cast< CSceneOutlinerItem* >( Item );
CMainEditorWindow::GetUndoStack()->push( new CUndoCommandDeleteActor( SceneOutlinerItem->GetUniqueID() ) );
}
}
bool RecursiveFindItem( QTreeWidgetItem* Item, QTreeWidgetItem* TestItem )
{
// Check if the item is the same.
if( Item == TestItem )
return true;
// For each child of the item.
for( int i = 0; i < Item->childCount(); ++i )
{
// Check if we found the item.
if( RecursiveFindItem( Item->child( i ), TestItem ) )
return true;
}
// Return not found.
return false;
}
void RecursiveRemoveUniqueItems( QTreeWidgetItem* Item, QList< QTreeWidgetItem* >* UniqueItems )
{
// Remove the item if found in the unique list.
foreach( QTreeWidgetItem* UniqueItem, *UniqueItems )
{
if( UniqueItem == Item )
{
UniqueItems->removeOne( UniqueItem );
break;
}
}
// For each child of the item.
for( int i = 0; i < Item->childCount(); ++i )
RecursiveRemoveUniqueItems( Item->child( i ), UniqueItems );
}
void CSceneOutlinerWidget::DeleteSelectedActors()
{
// Find unique items.
QList< QTreeWidgetItem* > UniqueItems;
foreach( QTreeWidgetItem* Item, m_SceneOutlinerTree->selectedItems() )
{
// Remove item and children if already in unique list.
RecursiveRemoveUniqueItems( Item, &UniqueItems );
// Search the item.
bool ItemFound = false;
foreach( QTreeWidgetItem* UniqueItem, UniqueItems )
{
if( RecursiveFindItem( UniqueItem, Item ) )
{
ItemFound = true;
break;
}
}
// Check if the item is found.
if( ItemFound )
continue;
// Add the item in the list.
UniqueItems.append( Item );
}
// Delete each unique item.
foreach( QTreeWidgetItem* Item, UniqueItems )
{
CSceneOutlinerItem* SceneOutlinerItem = static_cast< CSceneOutlinerItem* >( Item );
CMainEditorWindow::GetUndoStack()->push( new CUndoCommandDeleteActor( SceneOutlinerItem->GetUniqueID() ) );
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks