From dabbfc0f31c664a293b579e7c454310e3662f09d Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 25 Sep 2014 00:37:25 +0200 Subject: [PATCH] Collapse the tree, and only expand the items that are needed to get to the selected items. --- .../plugins/gui_editor/widget_hierarchy.cpp | 34 +++++++++++++------ .../src/plugins/gui_editor/widget_hierarchy.h | 1 + 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/widget_hierarchy.cpp b/code/studio/src/plugins/gui_editor/widget_hierarchy.cpp index 333386aca..d52f55e27 100644 --- a/code/studio/src/plugins/gui_editor/widget_hierarchy.cpp +++ b/code/studio/src/plugins/gui_editor/widget_hierarchy.cpp @@ -285,7 +285,24 @@ namespace GUIEditor item->setData( 0, Qt::DisplayRole, id ); item->setSelected( true ); newParent->addChild( item ); - newParent->setExpanded( true ); + + + selectItem( item ); + } + + void WidgetHierarchy::selectItem( QTreeWidgetItem *item ) + { + widgetHT->collapseAll(); + + QTreeWidgetItem *currItem = item; + while( currItem != NULL ) + { + currItem->setExpanded( true ); + currItem = currItem->parent(); + } + + widgetHT->setCurrentItem( item ); + item->setSelected( true ); } void WidgetHierarchy::getCurrentGroup( QString &g ) @@ -345,18 +362,11 @@ namespace GUIEditor if( widgetHT->currentItem() != NULL ) widgetHT->currentItem()->setSelected( false ); - // expand the tree items, so that we can see the selected item - QTreeWidgetItem *item = itr->second; - QTreeWidgetItem *currItem = item; - while( currItem != NULL ) - { - currItem->setExpanded( true ); - currItem = currItem->parent(); - } + widgetHT->collapseAll(); // select the current item - item->setSelected( true ); - widgetHT->setCurrentItem( item ); + QTreeWidgetItem *item = itr->second; + selectItem( item ); currentSelection = newSelection; } @@ -364,6 +374,8 @@ namespace GUIEditor { if( item->parent() == NULL ) return; + + selectItem( item ); std::string n = item->text( 0 ).toUtf8().constData(); currentSelection = makeFullName( item, n ); diff --git a/code/studio/src/plugins/gui_editor/widget_hierarchy.h b/code/studio/src/plugins/gui_editor/widget_hierarchy.h index 3d748e15f..27218715d 100644 --- a/code/studio/src/plugins/gui_editor/widget_hierarchy.h +++ b/code/studio/src/plugins/gui_editor/widget_hierarchy.h @@ -52,6 +52,7 @@ namespace GUIEditor void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group ); QTreeWidgetItem* findItem( const std::string &id ); QTreeWidgetItem* findParent( const std::string &id ); + void selectItem( QTreeWidgetItem *item ); public Q_SLOTS: void onGUILoaded();