mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-17 13:01:41 +00:00
ADDED: #1471 CWidgetSerializer class, that serializes the widgets into a single XML file. Also CInterfaceElement fields can now be serializes.
This commit is contained in:
parent
83de816afc
commit
936260d54f
5 changed files with 197 additions and 1 deletions
|
@ -127,6 +127,8 @@ namespace NLGUI
|
|||
|
||||
virtual void setProperty( const std::string &name, const std::string &value );
|
||||
|
||||
virtual bool serialize( xmlNodePtr parentNode, const char *type ) const;
|
||||
|
||||
/// Parse the element and initalize it
|
||||
virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
|
||||
|
||||
|
@ -292,6 +294,7 @@ namespace NLGUI
|
|||
|
||||
// Parse tools
|
||||
static std::string HotSpotToString( THotSpot spot );
|
||||
static std::string HotSpotCoupleToString( THotSpot parentPosRef, THotSpot posRef );
|
||||
static THotSpot convertHotSpot (const char *ptr); //
|
||||
static void convertHotSpotCouple (const char *ptr, THotSpot &parentPosRef, THotSpot &posRef);
|
||||
static NLMISC::CRGBA convertColor (const char *ptr);
|
||||
|
|
|
@ -259,6 +259,34 @@ namespace NLGUI
|
|||
nlwarning( "Tried to set invalid property '%s' for widget '%s'", name.c_str(), _Id.c_str() );
|
||||
}
|
||||
|
||||
bool CInterfaceElement::serialize( xmlNodePtr parentNode, const char *type ) const
|
||||
{
|
||||
xmlNodePtr node = xmlNewNode( NULL, BAD_CAST type );
|
||||
if( node == NULL )
|
||||
return false;
|
||||
|
||||
xmlAddChild( parentNode, node );
|
||||
|
||||
xmlNewProp( node, BAD_CAST "id", BAD_CAST stripId( getId() ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "active", BAD_CAST toString( _Active ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "x", BAD_CAST toString( _X ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "y", BAD_CAST toString( _Y ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "w", BAD_CAST toString( _W ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "h", BAD_CAST toString( _H ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "posref", BAD_CAST HotSpotCoupleToString( _ParentPosRef, _PosRef ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "posparent",
|
||||
BAD_CAST CWidgetManager::getInstance()->getParser()->getParentPosAssociation( (CInterfaceElement*)this ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "sizeref", BAD_CAST getSizeRefAsString().c_str() );
|
||||
xmlNewProp( node, BAD_CAST "sizeparent",
|
||||
BAD_CAST CWidgetManager::getInstance()->getParser()->getParentSizeAssociation( (CInterfaceElement*)this ).c_str() );
|
||||
|
||||
xmlNewProp( node, BAD_CAST "global_color", BAD_CAST toString( _ModulateGlobalColor ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "render_layer", BAD_CAST toString( _RenderLayer ).c_str() );
|
||||
xmlNewProp( node, BAD_CAST "avoid_resize_parent", BAD_CAST toString( _AvoidResizeParent ).c_str() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CInterfaceElement::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup)
|
||||
{
|
||||
|
@ -884,6 +912,16 @@ namespace NLGUI
|
|||
return "";
|
||||
}
|
||||
|
||||
std::string CInterfaceElement::HotSpotCoupleToString( THotSpot parentPosRef, THotSpot posRef )
|
||||
{
|
||||
std::string hs;
|
||||
hs = HotSpotToString( parentPosRef );
|
||||
hs += " ";
|
||||
hs += HotSpotToString( posRef );
|
||||
|
||||
return hs;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
THotSpot CInterfaceElement::convertHotSpot (const char *ptr)
|
||||
{
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "widget_properties.h"
|
||||
#include "widget_properties_parser.h"
|
||||
#include "widget_hierarchy.h"
|
||||
#include "widget_serializer.h"
|
||||
#include "link_list.h"
|
||||
#include "proc_list.h"
|
||||
#include "project_file_parser.h"
|
||||
|
@ -214,7 +215,9 @@ namespace GUIEditor
|
|||
projectFiles.guiFiles.push_back( "ui_" + projectFiles.projectName + ".xml" );
|
||||
projectFiles.version = NEW;
|
||||
|
||||
QString newFile = dir + "/" + projectFiles.projectName.c_str() + ".xml";
|
||||
QString newFile =
|
||||
dir + "/" + projectFiles.projectName.c_str() + ".xml";
|
||||
|
||||
CProjectFileSerializer serializer;
|
||||
serializer.setFile( newFile.toStdString() );
|
||||
if( !serializer.serialize( projectFiles ) )
|
||||
|
@ -225,6 +228,18 @@ namespace GUIEditor
|
|||
return;
|
||||
}
|
||||
|
||||
std::string guiFile =
|
||||
dir.toStdString() + "/" + "ui_" + projectFiles.projectName + ".xml";
|
||||
|
||||
WidgetSerializer widgetSerializer;
|
||||
widgetSerializer.setFile( guiFile );
|
||||
if( !widgetSerializer.serialize( projectFiles.masterGroup ) )
|
||||
{
|
||||
QMessageBox::critical( this,
|
||||
tr( "Failed to save project" ),
|
||||
tr( "There was an error while trying to save the project." ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void GUIEditorWindow::close()
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
// Object Viewer Qt GUI Editor plugin <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/>.
|
||||
|
||||
|
||||
#include "widget_serializer.h"
|
||||
#include "nel/gui/interface_group.h"
|
||||
#include "nel/gui/widget_manager.h"
|
||||
|
||||
namespace GUIEditor
|
||||
{
|
||||
bool WidgetSerializer::serialize( const std::string &masterGroup )
|
||||
{
|
||||
if( fileName.empty() )
|
||||
return false;
|
||||
|
||||
CInterfaceGroup *mg =
|
||||
CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup );
|
||||
|
||||
if( mg == NULL )
|
||||
return false;
|
||||
|
||||
out.open( fileName.c_str() );
|
||||
if( !out.is_open() )
|
||||
return false;
|
||||
|
||||
xmlNodePtr root = xmlNewNode( NULL, BAD_CAST "interface_config" );
|
||||
if( root == NULL )
|
||||
{
|
||||
out.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !mg->serialize( root, "root" ) )
|
||||
{
|
||||
xmlFreeNode( root );
|
||||
out.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
serializeTree( root );
|
||||
|
||||
|
||||
xmlFreeNode( root );
|
||||
out.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WidgetSerializer::serializeTree( _xmlNode *node )
|
||||
{
|
||||
out << "<" << node->name;
|
||||
|
||||
xmlAttrPtr prop = node->properties;
|
||||
while( prop != NULL )
|
||||
{
|
||||
std::string name = std::string( (const char*)prop->name );
|
||||
std::string value = std::string( (const char*)xmlGetProp( node, BAD_CAST name.c_str() ) );
|
||||
out << " " << name << "=\"" << value << "\"" << std::endl;
|
||||
|
||||
prop = prop->next;
|
||||
}
|
||||
|
||||
out << ">" << std::endl;
|
||||
|
||||
xmlNodePtr child = node->children;
|
||||
while( child != NULL )
|
||||
{
|
||||
serializeTree( child );
|
||||
child = child->next;
|
||||
}
|
||||
|
||||
out << "</" << node->name << ">" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
// Object Viewer Qt GUI Editor plugin <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_SERIALIZER_H
|
||||
#define WIDGET_SERIALIZER_H
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
struct _xmlNode;
|
||||
|
||||
namespace GUIEditor
|
||||
{
|
||||
|
||||
class WidgetSerializer
|
||||
{
|
||||
public:
|
||||
WidgetSerializer(){}
|
||||
~WidgetSerializer(){}
|
||||
|
||||
void setFile( const std::string &name ){ fileName = name; }
|
||||
bool serialize( const std::string &masterGroup );
|
||||
|
||||
private:
|
||||
bool serializeTree( _xmlNode *node );
|
||||
|
||||
std::string fileName;
|
||||
std::ofstream out;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in a new issue