From 29ef7af61af0e306dcec99c1895e475d48c192aa Mon Sep 17 00:00:00 2001
From: dfighter1985 <none@none>
Date: Sat, 2 Mar 2013 03:24:22 +0100
Subject: [PATCH] MODIFIED: When selecting a widget in the central widget, the
 hierarchy tree should now be updated as well.

--HG--
branch : gsoc2012-gui-editor
---
 .../plugins/gui_editor/widget_hierarchy.cpp   | 24 ++++++++++++++++++-
 .../src/plugins/gui_editor/widget_hierarchy.h |  3 +++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp
index a238c1f03..b7485baa4 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.cpp
@@ -75,6 +75,7 @@ namespace GUIEditor
 	void WidgetHierarchy::clearHierarchy()
 	{
 		widgetHT->clear();
+		widgetHierarchyMap.clear();
 	}
 
 	void WidgetHierarchy::buildHierarchy( std::string &masterGroup )
@@ -87,6 +88,7 @@ namespace GUIEditor
 			QTreeWidgetItem *item = new QTreeWidgetItem( NULL );
 			item->setText( 0, "ui" );
 			widgetHT->addTopLevelItem( item );
+			widgetHierarchyMap[ "ui" ] = item;
 
 			buildHierarchy( item, mg );
 		}
@@ -96,7 +98,9 @@ namespace GUIEditor
 	{
 		// First add ourselves
 		QTreeWidgetItem *item = new QTreeWidgetItem( parent );
+		
 		item->setText( 0, makeNodeName( group->getId() ).c_str() );
+		widgetHierarchyMap[ group->getId() ] = item;
 
 		// Then add recursively our subgroups
 		const std::vector< CInterfaceGroup* > &groups = group->getGroups();
@@ -113,6 +117,7 @@ namespace GUIEditor
 		{
 			QTreeWidgetItem *subItem = new QTreeWidgetItem( item );
 			subItem->setText( 0, makeNodeName( (*citr)->getId() ).c_str() );
+			widgetHierarchyMap[ (*citr)->getId() ] = subItem;
 		}
 
 		// Add our views
@@ -122,6 +127,7 @@ namespace GUIEditor
 		{
 			QTreeWidgetItem *subItem = new QTreeWidgetItem( item );
 			subItem->setText( 0, makeNodeName( (*vitr)->getId() ).c_str() );
+			widgetHierarchyMap[ (*vitr)->getId() ] = subItem;
 		}
 	}
 
@@ -138,8 +144,24 @@ namespace GUIEditor
 		if( newSelection == currentSelection )
 			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 )
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h
index 4c138d226..58e66212e 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_hierarchy.h
@@ -18,6 +18,8 @@
 #define WIDGET_HA_H
 
 #include "ui_widget_hierarchy.h"
+#include <string>
+#include <map>
 
 namespace NLGUI
 {
@@ -53,6 +55,7 @@ namespace GUIEditor
 	private:
 		std::string currentSelection;
 		std::string masterGroup;
+		std::map< std::string, QTreeWidgetItem* > widgetHierarchyMap;
 	};
 }