From 503b9c42347c4f209d541852c551a939b602ad06 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 17 Aug 2012 04:37:07 +0200 Subject: [PATCH] CHANGED: #1471 Tree/node data is now serialized. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/group_container.h | 1 + code/nel/include/nel/gui/interface_group.h | 1 + code/nel/include/nel/gui/widget_manager.h | 1 + code/nel/src/gui/group_container.cpp | 24 +++++++++++++++ code/nel/src/gui/interface_group.cpp | 16 ++++++++++ code/nel/src/gui/widget_manager.cpp | 27 +++++++++++++++++ .../plugins/gui_editor/widget_serializer.cpp | 30 ++++++++++++++----- 7 files changed, 92 insertions(+), 8 deletions(-) diff --git a/code/nel/include/nel/gui/group_container.h b/code/nel/include/nel/gui/group_container.h index 1dc467255..d405b8ec6 100644 --- a/code/nel/include/nel/gui/group_container.h +++ b/code/nel/include/nel/gui/group_container.h @@ -169,6 +169,7 @@ namespace NLGUI std::string getProperty( const std::string &name ) const; void setProperty( const std::string &name, const std::string &value ); xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const; + xmlNodePtr serializeTreeData( xmlNodePtr parentNode ) const; virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup); diff --git a/code/nel/include/nel/gui/interface_group.h b/code/nel/include/nel/gui/interface_group.h index 3dca37610..3f21886c3 100644 --- a/code/nel/include/nel/gui/interface_group.h +++ b/code/nel/include/nel/gui/interface_group.h @@ -48,6 +48,7 @@ namespace NLGUI xmlNodePtr serializeSubGroups( xmlNodePtr parentNode ) const; xmlNodePtr serializeControls( xmlNodePtr parentNode ) const; xmlNodePtr serializeViews( xmlNodePtr parentNode ) const; + virtual xmlNodePtr serializeTreeData( xmlNodePtr parentNode ) const; virtual uint32 getMemory (); diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index 1a61a12c3..e415bb9ed 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -393,6 +393,7 @@ namespace NLGUI void removeOptions( std::string name ); void removeAllOptions(); bool serializeOptions( xmlNodePtr parentNode ) const; + bool serializeTreeData( xmlNodePtr parentNode ) const; // Enable mouse Events to interface. if false, release Captures. void enableMouseHandling( bool handle ); diff --git a/code/nel/src/gui/group_container.cpp b/code/nel/src/gui/group_container.cpp index ba29c2f73..2ee306866 100644 --- a/code/nel/src/gui/group_container.cpp +++ b/code/nel/src/gui/group_container.cpp @@ -2061,6 +2061,30 @@ namespace NLGUI return node; } + + xmlNodePtr CGroupContainer::serializeTreeData( xmlNodePtr parentNode ) const + { + xmlNodePtr node = CInterfaceGroup::serializeTreeData( parentNode ); + if( node == NULL ) + return NULL; + + if( _List == NULL ) + return NULL; + + CInterfaceGroup *g = NULL; + for( sint32 i = 0; i < _List->getChildrenNb(); i++ ) + { + g = dynamic_cast< CInterfaceGroup* >( _List->getChild( i ) ); + if( g == NULL ) + continue; + + if( g->serializeTreeData( node ) == NULL ) + return NULL; + } + + return node; + } + // *************************************************************************** bool CGroupContainer::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup) { diff --git a/code/nel/src/gui/interface_group.cpp b/code/nel/src/gui/interface_group.cpp index 762ca8e89..42dac362d 100644 --- a/code/nel/src/gui/interface_group.cpp +++ b/code/nel/src/gui/interface_group.cpp @@ -758,6 +758,22 @@ namespace NLGUI return parentNode; } + xmlNodePtr CInterfaceGroup::serializeTreeData( xmlNodePtr parentNode ) const + { + if( parentNode == NULL ) + return NULL; + + xmlNodePtr node = xmlNewNode( NULL, BAD_CAST "tree" ); + if( node == NULL ) + return NULL; + + xmlAddChild( parentNode, node ); + + xmlSetProp( node, BAD_CAST "node", BAD_CAST CInterfaceElement::stripId( getId() ).c_str() ); + + return node; + } + // ------------------------------------------------------------------------------------------------ void CInterfaceGroup::parseMaxSizeRef(const char *ptr) { diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index 4b711a008..63c0c5a1a 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -2865,6 +2865,33 @@ namespace NLGUI return true; } + + + bool CWidgetManager::serializeTreeData( xmlNodePtr parentNode ) const + { + if( parentNode == NULL ) + return NULL; + + std::vector< SMasterGroup >::size_type i; + for( i = 0; i < _MasterGroups.size(); i++ ) + { + const SMasterGroup &mg = _MasterGroups[ i ]; + + std::vector< CInterfaceGroup* >::size_type j; + for( j = 0; j < mg.Group->getNumGroup(); j++ ) + { + CInterfaceGroup *g = mg.Group->getGroup( j ); + + if( dynamic_cast< CGroupModal* >( g ) != NULL ) + continue; + + if( g->serializeTreeData( parentNode ) == NULL ) + return false; + } + } + + return true; + } // *************************************************************************** diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp index be7a3898e..bd7428ee6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp @@ -64,6 +64,13 @@ namespace GUIEditor return false; } + if( !CWidgetManager::getInstance()->serializeTreeData( root ) ) + { + xmlFreeNode( root ); + out.close(); + return false; + } + level = -1; serializeTree( root ); @@ -98,16 +105,23 @@ namespace GUIEditor prop = prop->next; } - out << tabs << ">" << std::endl << std::endl; - - xmlNodePtr child = node->children; - while( child != NULL ) + if( node->children != NULL ) { - serializeTree( child ); - child = child->next; - } + out << tabs << ">" << std::endl << std::endl; - out << tabs << "name << ">" << std::endl << std::endl; + xmlNodePtr child = node->children; + while( child != NULL ) + { + serializeTree( child ); + child = child->next; + } + + out << tabs << "name << ">" << std::endl << std::endl; + } + else + { + out << tabs << "/>" << std::endl << std::endl; + } level--;