From 365ef61ec94faec0ad388672ffaadd29b0b6f476 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 23 Feb 2013 06:55:19 +0100 Subject: [PATCH] MODIFIED: Update property browser when selecting in the central widget. --HG-- branch : gsoc2012-gui-editor --- .../nel/gui/editor_selection_watcher.h | 30 ++++++++++++++++ code/nel/include/nel/gui/widget_manager.h | 6 ++++ code/nel/src/gui/widget_manager.cpp | 36 +++++++++++++++++++ .../src/plugins/gui_editor/CMakeLists.txt | 1 + .../gui_editor/editor_selection_watcher.cpp | 26 ++++++++++++++ .../gui_editor/editor_selection_watcher.h | 36 +++++++++++++++++++ .../plugins/gui_editor/gui_editor_window.cpp | 22 +++++++++--- .../plugins/gui_editor/gui_editor_window.h | 1 + .../src/plugins/gui_editor/nelgui_widget.cpp | 7 ++++ .../src/plugins/gui_editor/nelgui_widget.h | 4 +++ .../plugins/gui_editor/widget_hierarchy.cpp | 16 ++++++--- .../src/plugins/gui_editor/widget_hierarchy.h | 4 +-- 12 files changed, 177 insertions(+), 12 deletions(-) create mode 100644 code/nel/include/nel/gui/editor_selection_watcher.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.h diff --git a/code/nel/include/nel/gui/editor_selection_watcher.h b/code/nel/include/nel/gui/editor_selection_watcher.h new file mode 100644 index 000000000..415f4f9db --- /dev/null +++ b/code/nel/include/nel/gui/editor_selection_watcher.h @@ -0,0 +1,30 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include + +namespace NLGUI +{ + /// Watches the currently selected GUI widget + class IEditorSelectionWatcher + { + public: + + /// Notifies the watcher about the change + virtual void selectionChanged( std::string &newSelection ) = 0; + }; +} + diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 5700a52e6..12f4a065b 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -47,6 +47,7 @@ namespace NLGUI class CInterfaceOptions; class CInterfaceAnim; class CProcedure; + class IEditorSelectionWatcher; /** GUI Widget Manager @@ -485,6 +486,9 @@ namespace NLGUI IParser* getParser() const{ return parser; } void setCurrentEditorSelection( const std::string &name ); + void notifySelectionWatchers(); + void registerSelectionWatcher( IEditorSelectionWatcher *watcher ); + void unregisterSelectionWatcher( IEditorSelectionWatcher *watcher ); private: CWidgetManager(); @@ -564,6 +568,8 @@ namespace NLGUI std::vector< INewScreenSizeHandler* > newScreenSizeHandlers; std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers; + std::vector< IEditorSelectionWatcher* > selectionWatchers; + std::string currentEditorSelection; }; diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index c923c40fe..4640931f5 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -31,6 +31,7 @@ #include "nel/gui/proc.h" #include "nel/gui/interface_expr.h" #include "nel/gui/reflect_register.h" +#include "nel/gui/editor_selection_watcher.h" #include "nel/misc/events.h" namespace NLGUI @@ -3181,9 +3182,44 @@ namespace NLGUI } e->setEditorSelected( true ); currentEditorSelection = name; + notifySelectionWatchers(); } } + void CWidgetManager::notifySelectionWatchers() + { + std::vector< IEditorSelectionWatcher* >::iterator itr = selectionWatchers.begin(); + while( itr != selectionWatchers.end() ) + { + (*itr)->selectionChanged( currentEditorSelection ); + ++itr; + } + } + + void CWidgetManager::registerSelectionWatcher( IEditorSelectionWatcher *watcher ) + { + std::vector< IEditorSelectionWatcher* >::iterator itr = + std::find( selectionWatchers.begin(), selectionWatchers.end(), watcher ); + + // We already have this watcher + if( itr != selectionWatchers.end() ) + return; + + selectionWatchers.push_back( watcher ); + } + + void CWidgetManager::unregisterSelectionWatcher( IEditorSelectionWatcher *watcher ) + { + std::vector< IEditorSelectionWatcher* >::iterator itr = + std::find( selectionWatchers.begin(), selectionWatchers.end(), watcher ); + + // We don't have this watcher + if( itr == selectionWatchers.end() ) + return; + + selectionWatchers.erase( itr ); + } + CWidgetManager::CWidgetManager() { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt index 0a5d8533d..c08157373 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt @@ -60,6 +60,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR nelgui_widget.h new_property_widget.h new_widget_widget.h + editor_selection_watcher.h ) SET(OVQT_PLUGIN_GUI_EDITOR_UIS diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.cpp new file mode 100644 index 000000000..ee3a079ad --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.cpp @@ -0,0 +1,26 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "editor_selection_watcher.h" + +namespace GUIEditor +{ + void CEditorSelectionWatcher::selectionChanged( std::string &newSelection ) + { + Q_EMIT sgnSelectionChanged( newSelection ); + } +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.h new file mode 100644 index 000000000..61218c0cd --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/editor_selection_watcher.h @@ -0,0 +1,36 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#include "nel/gui/editor_selection_watcher.h" +#include + +namespace GUIEditor +{ + /// Watches the Editor selection, and emits a signal when it changes + class CEditorSelectionWatcher : public QObject, public NLGUI::IEditorSelectionWatcher + { + Q_OBJECT + + public: + CEditorSelectionWatcher() : QObject( NULL ){} + + void selectionChanged( std::string &newSelection ); + + Q_SIGNALS: + void sgnSelectionChanged( std::string &id ); + }; +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index 5a0aff4de..66945b562 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -41,6 +41,7 @@ #include "project_file_serializer.h" #include "project_window.h" #include "nelgui_widget.h" +#include "editor_selection_watcher.h" namespace GUIEditor { @@ -91,11 +92,7 @@ namespace GUIEditor viewPort->init(); - connect( viewPort, SIGNAL( guiLoadComplete() ), hierarchyView, SLOT( onGUILoaded() ) ); - connect( viewPort, SIGNAL( guiLoadComplete() ), procList, SLOT( onGUILoaded() ) ); - connect( viewPort, SIGNAL( guiLoadComplete() ), linkList, SLOT( onGUILoaded() ) ); - connect( hierarchyView, SIGNAL( selectionChanged( std::string& ) ), - &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) ); + connect( viewPort, SIGNAL( guiLoadComplete() ), this, SLOT( onGUILoaded() ) ); } GUIEditorWindow::~GUIEditorWindow() @@ -262,6 +259,11 @@ namespace GUIEditor if( reply != QMessageBox::Yes ) return false; + + CEditorSelectionWatcher *w = viewPort->getWatcher(); + disconnect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), hierarchyView, SLOT( onSelectionChanged( std::string& ) ) ); + disconnect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) ); + projectFiles.clearAll(); projectWindow->clear(); hierarchyView->clearHierarchy(); @@ -291,6 +293,16 @@ namespace GUIEditor setCursor( Qt::ArrowCursor ); } + void GUIEditorWindow::onGUILoaded() + { + hierarchyView->onGUILoaded(); + procList->onGUILoaded(); + linkList->onGUILoaded(); + + CEditorSelectionWatcher *w = viewPort->getWatcher(); + connect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), hierarchyView, SLOT( onSelectionChanged( std::string& ) ) ); + connect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) ); + } void GUIEditorWindow::createMenus() { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h index d4327d3d9..41cd30e9a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h @@ -58,6 +58,7 @@ public Q_SLOTS: private Q_SLOTS: void onProjectFilesChanged(); + void onGUILoaded(); private: void createMenus(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp index 85525e428..d86d31269 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp @@ -27,6 +27,7 @@ #include #include #include +#include "editor_selection_watcher.h" namespace GUIEditor { @@ -37,6 +38,7 @@ namespace GUIEditor { timerID = 0; guiLoaded = false; + watcher = NULL; } NelGUIWidget::~NelGUIWidget() @@ -70,6 +72,8 @@ namespace GUIEditor NLGUI::CViewRenderer::getInstance()->init(); CWidgetManager::getInstance()->getParser()->setEditorMode( true ); + + watcher = new CEditorSelectionWatcher(); } bool NelGUIWidget::parse( SProjectFiles &files ) @@ -106,6 +110,8 @@ namespace GUIEditor guiLoaded = true; Q_EMIT guiLoadComplete(); + CWidgetManager::getInstance()->registerSelectionWatcher( watcher ); + return true; } @@ -115,6 +121,7 @@ namespace GUIEditor if( timerID != 0 ) killTimer( timerID ); timerID = 0; + CWidgetManager::getInstance()->unregisterSelectionWatcher( watcher ); CWidgetManager::getInstance()->reset(); CWidgetManager::getInstance()->getParser()->removeAll(); CViewRenderer::getInstance()->reset(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h index 5a45cc351..34c510507 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.h @@ -23,6 +23,8 @@ namespace GUIEditor { + class CEditorSelectionWatcher; + /// Qt viewport for the Nel GUI library class NelGUIWidget : public Nel3DWidget { @@ -35,6 +37,7 @@ namespace GUIEditor bool parse( SProjectFiles &files ); void draw(); void reset(); + CEditorSelectionWatcher* getWatcher(){ return watcher; } Q_SIGNALS: void guiLoadComplete(); @@ -49,6 +52,7 @@ Q_SIGNALS: private: int timerID; bool guiLoaded; + CEditorSelectionWatcher *watcher; }; } 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 f510d6fb1..a238c1f03 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 @@ -130,6 +130,16 @@ namespace GUIEditor if( masterGroup.empty() ) return; buildHierarchy( masterGroup ); + currentSelection.clear(); + } + + void WidgetHierarchy::onSelectionChanged( std::string &newSelection ) + { + if( newSelection == currentSelection ) + return; + + + // Update the tree } void WidgetHierarchy::onItemDblClicked( QTreeWidgetItem *item ) @@ -138,9 +148,7 @@ namespace GUIEditor return; std::string n = item->text( 0 ).toUtf8().constData(); - std::string selection = makeFullName( item, n ); - CWidgetManager::getInstance()->setCurrentEditorSelection( selection ); - - Q_EMIT selectionChanged( selection ); + currentSelection = makeFullName( item, n ); + CWidgetManager::getInstance()->setCurrentEditorSelection( currentSelection ); } } 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 493fd2a08..4c138d226 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 @@ -45,6 +45,7 @@ namespace GUIEditor public Q_SLOTS: void onGUILoaded(); + void onSelectionChanged( std::string &newSelection ); private Q_SLOTS: void onItemDblClicked( QTreeWidgetItem *item ); @@ -52,9 +53,6 @@ namespace GUIEditor private: std::string currentSelection; std::string masterGroup; - - Q_SIGNALS: - void selectionChanged( std::string &id ); }; }