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 66231486f..e3667d70c 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
@@ -36,6 +36,7 @@
#include "link_list.h"
#include "proc_list.h"
#include "project_file_parser.h"
+#include "project_file_serializer.h"
#include "project_window.h"
#include "nelgui_widget.h"
@@ -44,6 +45,7 @@ namespace GUIEditor
QString _lastDir;
std::map< std::string, SWidgetInfo > widgetInfo;
SProjectFiles projectFiles;
+ CProjectFileParser projectParser;
GUIEditorWindow::GUIEditorWindow(QWidget *parent) :
QMainWindow(parent)
@@ -142,8 +144,9 @@ namespace GUIEditor
return;
}
- CProjectFileParser parser;
- if( !parser.parseProjectFile( fileName.toStdString() ) )
+ projectParser.clear();
+
+ if( !projectParser.parseProjectFile( fileName.toStdString() ) )
{
QMessageBox::critical( this,
tr( "Error parsing project file" ),
@@ -152,8 +155,9 @@ namespace GUIEditor
return;
}
projectFiles.clearAll();
- parser.getProjectFiles( projectFiles );
+ projectParser.getProjectFiles( projectFiles );
currentProject = projectFiles.projectName.c_str();
+ currentProjectFile = fileName;
projectWindow->setupFiles( projectFiles );
if( viewPort->parse( projectFiles ) )
{
@@ -178,6 +182,15 @@ namespace GUIEditor
if( currentProject.isEmpty() )
return;
+ CProjectFileSerializer serializer;
+ serializer.setFile( currentProjectFile.toStdString() );
+ serializer.serialize( projectFiles );
+
+ // Can't save old projects any further, since the widgets are in multiple files in them
+ // using templates, styles and whatnot. There's no way to restore the original XML structure
+ // after it's loaded
+ if( projectParser.getProjectVersion() == OLD )
+ return;
}
void GUIEditorWindow::saveAs()
@@ -206,8 +219,9 @@ namespace GUIEditor
browserCtrl.clear();
linkList->clear();
procList->clear();
-
currentProject = "";
+ currentProjectFile = "";
+ projectParser.clear();
}
void GUIEditorWindow::onProjectFilesChanged()
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 f2132e932..a9b477370 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
@@ -78,6 +78,7 @@ private:
CPropBrowserCtrl browserCtrl;
QString currentProject;
+ QString currentProjectFile;
};
}
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.cpp
index 6ccc1f4b5..97079d425 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.cpp
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.cpp
@@ -21,6 +21,7 @@ namespace GUIEditor
{
CProjectFileParser::CProjectFileParser()
{
+ loaded = false;
}
CProjectFileParser::~CProjectFileParser()
@@ -46,6 +47,9 @@ namespace GUIEditor
void CProjectFileParser::getProjectFiles( SProjectFiles &projectFiles ) const
{
+ if( !loaded )
+ return;
+
projectFiles.guiFiles.resize( files.guiFiles.size() );
projectFiles.mapFiles.resize( files.mapFiles.size() );
std::copy( files.guiFiles.begin(), files.guiFiles.end(), projectFiles.guiFiles.begin() );
@@ -55,8 +59,27 @@ namespace GUIEditor
projectFiles.activeGroup = files.activeGroup;
}
+ unsigned long CProjectFileParser::getProjectVersion() const
+ {
+ if( !loaded )
+ return OLD;
+
+ return files.version;
+ }
+
+ void CProjectFileParser::clear()
+ {
+ files.projectName = "";
+ files.version = OLD;
+ files.activeGroup = "";
+ files.guiFiles.clear();
+ files.mapFiles.clear();
+ }
+
bool CProjectFileParser::parseXMLFile(QFile &f)
{
+ loaded = false;
+
QXmlStreamReader reader;
reader.setDevice( &f );
@@ -83,6 +106,7 @@ namespace GUIEditor
if( !parseMapFiles( reader ) )
return false;
+ loaded = true;
return true;
}
@@ -100,6 +124,14 @@ namespace GUIEditor
files.projectName = name.toStdString();
}
else
+ if( reader.name() == "version" )
+ {
+ QString name = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
+ if( name.isEmpty() )
+ return false;
+ files.version = static_cast< unsigned long >( name.toLong() );
+ }
+ else
if( reader.name() == "mastergroup" )
{
QString mg = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.h
index f8398ad19..de4808346 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.h
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.h
@@ -35,6 +35,8 @@ namespace GUIEditor
bool parseProjectFile( std::string &name );
void getProjectFiles( SProjectFiles &projectFiles ) const;
+ unsigned long getProjectVersion() const;
+ void clear();
private:
bool parseXMLFile( QFile &f );
@@ -42,6 +44,8 @@ namespace GUIEditor
bool parseGUIFiles( QXmlStreamReader &reader );
bool parseMapFiles( QXmlStreamReader &reader );
+ bool loaded;
+
SProjectFiles files;
};
}
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_serializer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_serializer.cpp
new file mode 100644
index 000000000..8cf0372fe
--- /dev/null
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_serializer.cpp
@@ -0,0 +1,122 @@
+// Object Viewer Qt GUI Editor plugin
+// 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 "project_file_serializer.h"
+
+
+namespace GUIEditor
+{
+ bool CProjectFileSerializer::serialize( const SProjectFiles &project )
+ {
+ if( fileName.empty() )
+ return false;
+
+ if( project.version >= MAX_PROJECTFILE_VERSION )
+ return false;
+
+ out.open( fileName.c_str() );
+ if( !out.is_open() )
+ return false;
+
+ out << "" << std::endl;
+
+ if( !serializeHeader( project ) )
+ {
+ out.close();
+ return false;
+ }
+
+ if( !serializeGUIFiles( project ) )
+ {
+ out.close();
+ return false;
+ }
+
+ if( !serializeMapFiles( project ) )
+ {
+ out.close();
+ return false;
+ }
+
+ out << "" << std::endl;
+
+ out.close();
+
+ return true;
+ }
+
+ bool CProjectFileSerializer::serializeHeader( const SProjectFiles &project )
+ {
+ if( !out.good() )
+ return false;
+
+ out << '\t' << "" << std::endl;
+ out << "\t\t" << "" << project.projectName << "" << std::endl;
+ out << "\t\t" << "" << project.version << "" << std::endl;
+ out << "\t\t" << "" << project.masterGroup << "" << std::endl;
+ out << "\t\t" << "" << project.activeGroup << "" << std::endl;
+ out << '\t' << "" << std::endl;
+
+ if( !out.good() )
+ return false;
+
+ return true;
+ }
+
+ bool CProjectFileSerializer::serializeGUIFiles( const SProjectFiles &project )
+ {
+ if( !out.good() )
+ return false;
+
+ out << '\t' << "" << std::endl;
+
+ std::vector< std::string >::const_iterator itr;
+ for( itr = project.guiFiles.begin(); itr != project.guiFiles.end(); ++itr )
+ {
+ out << "\t\t" << "" << *itr << "" << std::endl;
+ }
+
+ out << '\t' << "" << std::endl;
+
+ if( !out.good() )
+ return false;
+
+ return true;
+ }
+
+ bool CProjectFileSerializer::serializeMapFiles( const SProjectFiles &project )
+ {
+ if( !out.good() )
+ return false;
+
+ out << '\t' << "" << std::endl;
+
+ std::vector< std::string >::const_iterator itr;
+ for( itr = project.mapFiles.begin(); itr != project.mapFiles.end(); ++itr )
+ {
+ out << "\t\t" << "" << *itr << "" << std::endl;
+ }
+
+ out << '\t' << "" << std::endl;
+
+ if( !out.good() )
+ return false;
+
+ return true;
+ }
+}
+
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_serializer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_serializer.h
new file mode 100644
index 000000000..d3e110055
--- /dev/null
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_serializer.h
@@ -0,0 +1,45 @@
+// Object Viewer Qt GUI Editor plugin
+// 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 .
+
+
+#ifndef PRJ_F_SERIALIZER
+#define PRJ_F_SERIALIZER
+
+#include "project_files.h"
+#include
+
+namespace GUIEditor
+{
+ class CProjectFileSerializer
+ {
+ public:
+ CProjectFileSerializer(){}
+ ~CProjectFileSerializer(){}
+
+ void setFile( const std::string &name ){ fileName = name; }
+ bool serialize( const SProjectFiles &project );
+
+ private:
+ bool serializeHeader( const SProjectFiles &project );
+ bool serializeGUIFiles( const SProjectFiles &project );
+ bool serializeMapFiles( const SProjectFiles &project );
+
+ std::string fileName;
+ std::ofstream out;
+ };
+}
+
+#endif
diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files.h
index 2479f16da..51d5b99ea 100644
--- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files.h
+++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files.h
@@ -23,10 +23,18 @@
namespace GUIEditor
{
+ enum ProjectVersion
+ {
+ OLD = 0,
+ NEW = 1,
+ MAX_PROJECTFILE_VERSION
+ };
+
struct SProjectFiles
{
public:
std::string projectName;
+ unsigned long version;
std::string masterGroup;
std::string activeGroup;
std::vector< std::string > guiFiles;