MODIFIED: collapse the widget hierarchy tree and remove the widget from it when it's deleted. Also clear the widget properties panel.

--HG--
branch : gsoc2012-gui-editor
This commit is contained in:
dfighter1985 2013-03-03 03:49:56 +01:00
parent b80c47cc10
commit 532a3ef7d3
4 changed files with 48 additions and 2 deletions

View file

@ -3181,10 +3181,14 @@ namespace NLGUI
prev->setEditorSelected( false ); prev->setEditorSelected( false );
} }
e->setEditorSelected( true ); e->setEditorSelected( true );
}
else
if( !name.empty() )
return;
currentEditorSelection = name; currentEditorSelection = name;
notifySelectionWatchers(); notifySelectionWatchers();
} }
}
void CWidgetManager::notifySelectionWatchers() void CWidgetManager::notifySelectionWatchers()
{ {

View file

@ -50,7 +50,9 @@ namespace GUIEditor
return; return;
if( g->delElement( e ) ) if( g->delElement( e ) )
{
CWidgetManager::getInstance()->setCurrentEditorSelection( "" ); CWidgetManager::getInstance()->setCurrentEditorSelection( "" );
} }
}
} }

View file

@ -78,7 +78,12 @@ namespace GUIEditor
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id ); CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id );
if( e == NULL ) if( e == NULL )
{
connect( propertyMgr, SIGNAL( propertyChanged( QtProperty* ) ),
this, SLOT( onPropertyChanged( QtProperty* ) ) );
return; return;
}
currentElement = id; currentElement = id;

View file

@ -144,14 +144,47 @@ namespace GUIEditor
if( newSelection == currentSelection ) if( newSelection == currentSelection )
return; return;
if( newSelection.empty() )
{
if( widgetHT->currentItem() != NULL )
{
QTreeWidgetItem *item = widgetHT->currentItem();
QTreeWidgetItem *p = item;
// Deselect item
item->setSelected( false );
widgetHT->setCurrentItem( NULL );
// Collapse the tree
while( p != NULL )
{
p->setExpanded( false );
p = p->parent();
}
// Finally remove the item!
delete item;
item = NULL;
std::map< std::string, QTreeWidgetItem* >::iterator itr =
widgetHierarchyMap.find( currentSelection );
if( itr != widgetHierarchyMap.end() )
widgetHierarchyMap.erase( itr );
currentSelection = "";
}
return;
}
std::map< std::string, QTreeWidgetItem* >::iterator itr = std::map< std::string, QTreeWidgetItem* >::iterator itr =
widgetHierarchyMap.find( newSelection ); widgetHierarchyMap.find( newSelection );
if( itr == widgetHierarchyMap.end() ) if( itr == widgetHierarchyMap.end() )
return; return;
// deselect current item
if( widgetHT->currentItem() != NULL ) if( widgetHT->currentItem() != NULL )
widgetHT->currentItem()->setSelected( false ); widgetHT->currentItem()->setSelected( false );
// expand the tree items, so that we can see the selected item
QTreeWidgetItem *item = itr->second; QTreeWidgetItem *item = itr->second;
QTreeWidgetItem *currItem = item; QTreeWidgetItem *currItem = item;
while( currItem != NULL ) while( currItem != NULL )
@ -160,8 +193,10 @@ namespace GUIEditor
currItem = currItem->parent(); currItem = currItem->parent();
} }
// select the current item
item->setSelected( true ); item->setSelected( true );
widgetHT->setCurrentItem( item ); widgetHT->setCurrentItem( item );
currentSelection = newSelection;
} }
void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item ) void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item )