Refactored IWidgetAdditionWatcher, now it's called IWidgetWatcher and it also reports widget moves.

This commit is contained in:
dfighter1985 2014-09-24 23:32:24 +02:00
parent f7825fc8b3
commit e6f4801129
5 changed files with 70 additions and 67 deletions

View file

@ -1,32 +0,0 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// 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 <http://www.gnu.org/licenses/>.
#ifndef WIDGET_ADD_WATCHER
#define WIDGET_ADD_WATCHER
#include <string>
namespace NLGUI
{
class IWidgetAdditionWatcher
{
public:
virtual void widgetAdded( const std::string &name ) = 0;
};
}
#endif

View file

@ -75,6 +75,16 @@ namespace NLGUI
virtual void process() = 0; virtual void process() = 0;
}; };
// Interface for event handlers that can be called when widgets are added or moved
class IWidgetWatcher
{
public:
IWidgetWatcher(){}
virtual ~IWidgetWatcher(){}
virtual void onWidgetAdded( const std::string &name ) = 0;
virtual void onWidgetMoved( const std::string &oldid, const std::string &newid ) = 0;
};
/// Frame render times /// Frame render times
struct SInterfaceTimes struct SInterfaceTimes
{ {
@ -498,10 +508,12 @@ namespace NLGUI
void notifySelectionWatchers(); void notifySelectionWatchers();
void registerSelectionWatcher( IEditorSelectionWatcher *watcher ); void registerSelectionWatcher( IEditorSelectionWatcher *watcher );
void unregisterSelectionWatcher( IEditorSelectionWatcher *watcher ); void unregisterSelectionWatcher( IEditorSelectionWatcher *watcher );
void notifyAdditionWatchers( const std::string &widgetName );
void registerAdditionWatcher( IWidgetAdditionWatcher *watcher ); void onWidgetAdded( const std::string &id );
void unregisterAdditionWatcher( IWidgetAdditionWatcher *watcher ); void onWidgetMoved( const std::string &oldid, const std::string &newid );
void registerWidgetWatcher( IWidgetWatcher *watcher );
void unregisterWidgetWatcher( IWidgetWatcher *watcher );
CInterfaceElement* addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName ); CInterfaceElement* addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName );
@ -594,7 +606,7 @@ namespace NLGUI
std::vector< INewScreenSizeHandler* > newScreenSizeHandlers; std::vector< INewScreenSizeHandler* > newScreenSizeHandlers;
std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers; std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers;
std::vector< IEditorSelectionWatcher* > selectionWatchers; std::vector< IEditorSelectionWatcher* > selectionWatchers;
std::vector< IWidgetAdditionWatcher* > additionWatchers; std::vector< IWidgetWatcher* > widgetWatchers;
std::string currentEditorSelection; std::string currentEditorSelection;

View file

@ -34,7 +34,6 @@
#include "nel/gui/interface_expr.h" #include "nel/gui/interface_expr.h"
#include "nel/gui/reflect_register.h" #include "nel/gui/reflect_register.h"
#include "nel/gui/editor_selection_watcher.h" #include "nel/gui/editor_selection_watcher.h"
#include "nel/gui/widget_addition_watcher.h"
#include "nel/misc/events.h" #include "nel/misc/events.h"
namespace NLGUI namespace NLGUI
@ -2669,6 +2668,8 @@ namespace NLGUI
if( g == NULL ) if( g == NULL )
g = tw; g = tw;
std::string oldid = e->getId();
e->setParent( g ); e->setParent( g );
e->setIdRecurse( e->getShortId() ); e->setIdRecurse( e->getShortId() );
@ -2677,6 +2678,8 @@ namespace NLGUI
g->addElement( e ); g->addElement( e );
draggedElement = NULL; draggedElement = NULL;
onWidgetMoved( oldid, e->getId() );
} }
} }
@ -3364,36 +3367,46 @@ namespace NLGUI
selectionWatchers.erase( itr ); selectionWatchers.erase( itr );
} }
void CWidgetManager::notifyAdditionWatchers( const std::string &widgetName ) void CWidgetManager::onWidgetAdded( const std::string &id )
{ {
std::vector< IWidgetAdditionWatcher* >::const_iterator itr = additionWatchers.begin(); std::vector< IWidgetWatcher* >::const_iterator itr = widgetWatchers.begin();
while( itr != additionWatchers.end() ) while( itr != widgetWatchers.end() )
{ {
(*itr)->widgetAdded( widgetName ); (*itr)->onWidgetAdded( id );
++itr; ++itr;
} }
} }
void CWidgetManager::registerAdditionWatcher( IWidgetAdditionWatcher *watcher ) void CWidgetManager::onWidgetMoved( const std::string &oldid, const std::string &newid )
{ {
std::vector< IWidgetAdditionWatcher* >::const_iterator itr std::vector< IWidgetWatcher* >::const_iterator itr = widgetWatchers.begin();
= std::find( additionWatchers.begin(), additionWatchers.end(), watcher ); while( itr != widgetWatchers.end() )
// already exists {
if( itr != additionWatchers.end() ) (*itr)->onWidgetMoved( oldid, newid );
return; ++itr;
}
additionWatchers.push_back( watcher );
} }
void CWidgetManager::unregisterAdditionWatcher( IWidgetAdditionWatcher *watcher ) void CWidgetManager::registerWidgetWatcher( IWidgetWatcher *watcher )
{ {
std::vector< IWidgetAdditionWatcher* >::iterator itr std::vector< IWidgetWatcher* >::const_iterator itr
= std::find( additionWatchers.begin(), additionWatchers.end(), watcher ); = std::find( widgetWatchers.begin(), widgetWatchers.end(), watcher );
// doesn't exist // already exists
if( itr == additionWatchers.end() ) if( itr != widgetWatchers.end() )
return; return;
additionWatchers.erase( itr ); widgetWatchers.push_back( watcher );
}
void CWidgetManager::unregisterWidgetWatcher( IWidgetWatcher *watcher )
{
std::vector< IWidgetWatcher* >::iterator itr
= std::find( widgetWatchers.begin(), widgetWatchers.end(), watcher );
// doesn't exist
if( itr == widgetWatchers.end() )
return;
widgetWatchers.erase( itr );
} }
CInterfaceElement* CWidgetManager::addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName ) CInterfaceElement* CWidgetManager::addWidgetToGroup( std::string &group, std::string &widgetClass, std::string &widgetName )
@ -3426,7 +3439,7 @@ namespace NLGUI
else else
g->addView( v ); g->addView( v );
notifyAdditionWatchers( v->getId() ); onWidgetAdded( v->getId() );
return v; return v;
} }

View file

@ -18,7 +18,6 @@
#include "widget_hierarchy.h" #include "widget_hierarchy.h"
#include "nel/gui/interface_group.h" #include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h" #include "nel/gui/widget_manager.h"
#include "nel/gui/widget_addition_watcher.h"
namespace namespace
{ {
@ -76,18 +75,24 @@ namespace
GUIEditor::WidgetHierarchy *h; GUIEditor::WidgetHierarchy *h;
}; };
class CWidgetAdditionWatcher : public IWidgetAdditionWatcher class CWidgetWatcher : public CWidgetManager::IWidgetWatcher
{ {
public: public:
CWidgetAdditionWatcher(){ h = NULL; } CWidgetWatcher(){ h = NULL; }
~CWidgetAdditionWatcher(){} ~CWidgetWatcher(){}
void widgetAdded( const std::string &name ) void onWidgetAdded( const std::string &name )
{ {
if( h != NULL ) if( h != NULL )
h->onWidgetAdded( name ); h->onWidgetAdded( name );
} }
void onWidgetMoved( const std::string &oldid, const std::string &newid )
{
if( h != NULL )
h->onWidgetMoved( oldid, newid );
}
void setWidgetHierarchy( GUIEditor::WidgetHierarchy *h ){ this->h = h; } void setWidgetHierarchy( GUIEditor::WidgetHierarchy *h ){ this->h = h; }
private: private:
@ -95,7 +100,7 @@ namespace
}; };
CWidgetDeletionWatcher deletionWatcher; CWidgetDeletionWatcher deletionWatcher;
CWidgetAdditionWatcher additionWatcher; CWidgetWatcher widgetwatcher;
} }
namespace GUIEditor namespace GUIEditor
@ -107,7 +112,7 @@ namespace GUIEditor
connect( widgetHT, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), connect( widgetHT, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ),
this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) ); this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) );
deletionWatcher.setWidgetHierarchy( this ); deletionWatcher.setWidgetHierarchy( this );
additionWatcher.setWidgetHierarchy( this ); widgetwatcher.setWidgetHierarchy( this );
} }
WidgetHierarchy::~WidgetHierarchy() WidgetHierarchy::~WidgetHierarchy()
@ -117,7 +122,7 @@ namespace GUIEditor
void WidgetHierarchy::clearHierarchy() void WidgetHierarchy::clearHierarchy()
{ {
CInterfaceElement::unregisterDeletionWatcher( &deletionWatcher ); CInterfaceElement::unregisterDeletionWatcher( &deletionWatcher );
CWidgetManager::getInstance()->unregisterAdditionWatcher( &additionWatcher ); CWidgetManager::getInstance()->unregisterWidgetWatcher( &widgetwatcher );
widgetHT->clear(); widgetHT->clear();
widgetHierarchyMap.clear(); widgetHierarchyMap.clear();
} }
@ -126,7 +131,7 @@ namespace GUIEditor
{ {
clearHierarchy(); clearHierarchy();
CInterfaceElement::registerDeletionWatcher( &deletionWatcher ); CInterfaceElement::registerDeletionWatcher( &deletionWatcher );
CWidgetManager::getInstance()->registerAdditionWatcher( &additionWatcher ); CWidgetManager::getInstance()->registerWidgetWatcher( &widgetwatcher );
CInterfaceGroup *mg = CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup ); CInterfaceGroup *mg = CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup );
if( mg != NULL ) if( mg != NULL )
@ -231,6 +236,10 @@ namespace GUIEditor
widgetHierarchyMap[ id ] = item; widgetHierarchyMap[ id ] = item;
} }
void WidgetHierarchy::onWidgetMoved( const std::string &oldid, const std::string &newid )
{
}
void WidgetHierarchy::getCurrentGroup( QString &g ) void WidgetHierarchy::getCurrentGroup( QString &g )
{ {
std::string s = CWidgetManager::getInstance()->getCurrentEditorSelection(); std::string s = CWidgetManager::getInstance()->getCurrentEditorSelection();

View file

@ -44,6 +44,7 @@ namespace GUIEditor
void onWidgetDeleted( const std::string &id ); void onWidgetDeleted( const std::string &id );
void onWidgetAdded( const std::string &id ); void onWidgetAdded( const std::string &id );
void onWidgetMoved( const std::string &oldid, const std::string &newid );
void getCurrentGroup( QString &g ); void getCurrentGroup( QString &g );