MODIFIED: When selecting a widget in the central widget, the hierarchy tree should now be updated as well.

--HG--
branch : gsoc2012-gui-editor
This commit is contained in:
dfighter1985 2013-03-02 03:24:22 +01:00
parent 365ef61ec9
commit 29ef7af61a
2 changed files with 26 additions and 1 deletions

View file

@ -75,6 +75,7 @@ namespace GUIEditor
void WidgetHierarchy::clearHierarchy() void WidgetHierarchy::clearHierarchy()
{ {
widgetHT->clear(); widgetHT->clear();
widgetHierarchyMap.clear();
} }
void WidgetHierarchy::buildHierarchy( std::string &masterGroup ) void WidgetHierarchy::buildHierarchy( std::string &masterGroup )
@ -87,6 +88,7 @@ namespace GUIEditor
QTreeWidgetItem *item = new QTreeWidgetItem( NULL ); QTreeWidgetItem *item = new QTreeWidgetItem( NULL );
item->setText( 0, "ui" ); item->setText( 0, "ui" );
widgetHT->addTopLevelItem( item ); widgetHT->addTopLevelItem( item );
widgetHierarchyMap[ "ui" ] = item;
buildHierarchy( item, mg ); buildHierarchy( item, mg );
} }
@ -96,7 +98,9 @@ namespace GUIEditor
{ {
// First add ourselves // First add ourselves
QTreeWidgetItem *item = new QTreeWidgetItem( parent ); QTreeWidgetItem *item = new QTreeWidgetItem( parent );
item->setText( 0, makeNodeName( group->getId() ).c_str() ); item->setText( 0, makeNodeName( group->getId() ).c_str() );
widgetHierarchyMap[ group->getId() ] = item;
// Then add recursively our subgroups // Then add recursively our subgroups
const std::vector< CInterfaceGroup* > &groups = group->getGroups(); const std::vector< CInterfaceGroup* > &groups = group->getGroups();
@ -113,6 +117,7 @@ namespace GUIEditor
{ {
QTreeWidgetItem *subItem = new QTreeWidgetItem( item ); QTreeWidgetItem *subItem = new QTreeWidgetItem( item );
subItem->setText( 0, makeNodeName( (*citr)->getId() ).c_str() ); subItem->setText( 0, makeNodeName( (*citr)->getId() ).c_str() );
widgetHierarchyMap[ (*citr)->getId() ] = subItem;
} }
// Add our views // Add our views
@ -122,6 +127,7 @@ namespace GUIEditor
{ {
QTreeWidgetItem *subItem = new QTreeWidgetItem( item ); QTreeWidgetItem *subItem = new QTreeWidgetItem( item );
subItem->setText( 0, makeNodeName( (*vitr)->getId() ).c_str() ); subItem->setText( 0, makeNodeName( (*vitr)->getId() ).c_str() );
widgetHierarchyMap[ (*vitr)->getId() ] = subItem;
} }
} }
@ -138,8 +144,24 @@ namespace GUIEditor
if( newSelection == currentSelection ) if( newSelection == currentSelection )
return; return;
std::map< std::string, QTreeWidgetItem* >::iterator itr =
widgetHierarchyMap.find( newSelection );
if( itr == widgetHierarchyMap.end() )
return;
// Update the tree if( widgetHT->currentItem() != NULL )
widgetHT->currentItem()->setSelected( false );
QTreeWidgetItem *item = itr->second;
QTreeWidgetItem *currItem = item;
while( currItem != NULL )
{
currItem->setExpanded( true );
currItem = currItem->parent();
}
item->setSelected( true );
widgetHT->setCurrentItem( item );
} }
void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item ) void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item )

View file

@ -18,6 +18,8 @@
#define WIDGET_HA_H #define WIDGET_HA_H
#include "ui_widget_hierarchy.h" #include "ui_widget_hierarchy.h"
#include <string>
#include <map>
namespace NLGUI namespace NLGUI
{ {
@ -53,6 +55,7 @@ namespace GUIEditor
private: private:
std::string currentSelection; std::string currentSelection;
std::string masterGroup; std::string masterGroup;
std::map< std::string, QTreeWidgetItem* > widgetHierarchyMap;
}; };
} }