ADDED: #1471 CProjectFileSerializer class, and also it's possible to save the project file changes now.
--HG-- branch : gsoc2012-gui-editor
This commit is contained in:
parent
ce86607415
commit
f10ef64bee
7 changed files with 230 additions and 4 deletions
|
@ -36,6 +36,7 @@
|
||||||
#include "link_list.h"
|
#include "link_list.h"
|
||||||
#include "proc_list.h"
|
#include "proc_list.h"
|
||||||
#include "project_file_parser.h"
|
#include "project_file_parser.h"
|
||||||
|
#include "project_file_serializer.h"
|
||||||
#include "project_window.h"
|
#include "project_window.h"
|
||||||
#include "nelgui_widget.h"
|
#include "nelgui_widget.h"
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ namespace GUIEditor
|
||||||
QString _lastDir;
|
QString _lastDir;
|
||||||
std::map< std::string, SWidgetInfo > widgetInfo;
|
std::map< std::string, SWidgetInfo > widgetInfo;
|
||||||
SProjectFiles projectFiles;
|
SProjectFiles projectFiles;
|
||||||
|
CProjectFileParser projectParser;
|
||||||
|
|
||||||
GUIEditorWindow::GUIEditorWindow(QWidget *parent) :
|
GUIEditorWindow::GUIEditorWindow(QWidget *parent) :
|
||||||
QMainWindow(parent)
|
QMainWindow(parent)
|
||||||
|
@ -142,8 +144,9 @@ namespace GUIEditor
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CProjectFileParser parser;
|
projectParser.clear();
|
||||||
if( !parser.parseProjectFile( fileName.toStdString() ) )
|
|
||||||
|
if( !projectParser.parseProjectFile( fileName.toStdString() ) )
|
||||||
{
|
{
|
||||||
QMessageBox::critical( this,
|
QMessageBox::critical( this,
|
||||||
tr( "Error parsing project file" ),
|
tr( "Error parsing project file" ),
|
||||||
|
@ -152,8 +155,9 @@ namespace GUIEditor
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
projectFiles.clearAll();
|
projectFiles.clearAll();
|
||||||
parser.getProjectFiles( projectFiles );
|
projectParser.getProjectFiles( projectFiles );
|
||||||
currentProject = projectFiles.projectName.c_str();
|
currentProject = projectFiles.projectName.c_str();
|
||||||
|
currentProjectFile = fileName;
|
||||||
projectWindow->setupFiles( projectFiles );
|
projectWindow->setupFiles( projectFiles );
|
||||||
if( viewPort->parse( projectFiles ) )
|
if( viewPort->parse( projectFiles ) )
|
||||||
{
|
{
|
||||||
|
@ -178,6 +182,15 @@ namespace GUIEditor
|
||||||
if( currentProject.isEmpty() )
|
if( currentProject.isEmpty() )
|
||||||
return;
|
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()
|
void GUIEditorWindow::saveAs()
|
||||||
|
@ -206,8 +219,9 @@ namespace GUIEditor
|
||||||
browserCtrl.clear();
|
browserCtrl.clear();
|
||||||
linkList->clear();
|
linkList->clear();
|
||||||
procList->clear();
|
procList->clear();
|
||||||
|
|
||||||
currentProject = "";
|
currentProject = "";
|
||||||
|
currentProjectFile = "";
|
||||||
|
projectParser.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIEditorWindow::onProjectFilesChanged()
|
void GUIEditorWindow::onProjectFilesChanged()
|
||||||
|
|
|
@ -78,6 +78,7 @@ private:
|
||||||
|
|
||||||
CPropBrowserCtrl browserCtrl;
|
CPropBrowserCtrl browserCtrl;
|
||||||
QString currentProject;
|
QString currentProject;
|
||||||
|
QString currentProjectFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ namespace GUIEditor
|
||||||
{
|
{
|
||||||
CProjectFileParser::CProjectFileParser()
|
CProjectFileParser::CProjectFileParser()
|
||||||
{
|
{
|
||||||
|
loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CProjectFileParser::~CProjectFileParser()
|
CProjectFileParser::~CProjectFileParser()
|
||||||
|
@ -46,6 +47,9 @@ namespace GUIEditor
|
||||||
|
|
||||||
void CProjectFileParser::getProjectFiles( SProjectFiles &projectFiles ) const
|
void CProjectFileParser::getProjectFiles( SProjectFiles &projectFiles ) const
|
||||||
{
|
{
|
||||||
|
if( !loaded )
|
||||||
|
return;
|
||||||
|
|
||||||
projectFiles.guiFiles.resize( files.guiFiles.size() );
|
projectFiles.guiFiles.resize( files.guiFiles.size() );
|
||||||
projectFiles.mapFiles.resize( files.mapFiles.size() );
|
projectFiles.mapFiles.resize( files.mapFiles.size() );
|
||||||
std::copy( files.guiFiles.begin(), files.guiFiles.end(), projectFiles.guiFiles.begin() );
|
std::copy( files.guiFiles.begin(), files.guiFiles.end(), projectFiles.guiFiles.begin() );
|
||||||
|
@ -55,8 +59,27 @@ namespace GUIEditor
|
||||||
projectFiles.activeGroup = files.activeGroup;
|
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)
|
bool CProjectFileParser::parseXMLFile(QFile &f)
|
||||||
{
|
{
|
||||||
|
loaded = false;
|
||||||
|
|
||||||
QXmlStreamReader reader;
|
QXmlStreamReader reader;
|
||||||
reader.setDevice( &f );
|
reader.setDevice( &f );
|
||||||
|
|
||||||
|
@ -83,6 +106,7 @@ namespace GUIEditor
|
||||||
if( !parseMapFiles( reader ) )
|
if( !parseMapFiles( reader ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
loaded = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +124,14 @@ namespace GUIEditor
|
||||||
files.projectName = name.toStdString();
|
files.projectName = name.toStdString();
|
||||||
}
|
}
|
||||||
else
|
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" )
|
if( reader.name() == "mastergroup" )
|
||||||
{
|
{
|
||||||
QString mg = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
QString mg = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||||
|
|
|
@ -35,6 +35,8 @@ namespace GUIEditor
|
||||||
|
|
||||||
bool parseProjectFile( std::string &name );
|
bool parseProjectFile( std::string &name );
|
||||||
void getProjectFiles( SProjectFiles &projectFiles ) const;
|
void getProjectFiles( SProjectFiles &projectFiles ) const;
|
||||||
|
unsigned long getProjectVersion() const;
|
||||||
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool parseXMLFile( QFile &f );
|
bool parseXMLFile( QFile &f );
|
||||||
|
@ -42,6 +44,8 @@ namespace GUIEditor
|
||||||
bool parseGUIFiles( QXmlStreamReader &reader );
|
bool parseGUIFiles( QXmlStreamReader &reader );
|
||||||
bool parseMapFiles( QXmlStreamReader &reader );
|
bool parseMapFiles( QXmlStreamReader &reader );
|
||||||
|
|
||||||
|
bool loaded;
|
||||||
|
|
||||||
SProjectFiles files;
|
SProjectFiles files;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
// 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 "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 << "<project>" << std::endl;
|
||||||
|
|
||||||
|
if( !serializeHeader( project ) )
|
||||||
|
{
|
||||||
|
out.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !serializeGUIFiles( project ) )
|
||||||
|
{
|
||||||
|
out.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !serializeMapFiles( project ) )
|
||||||
|
{
|
||||||
|
out.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
out << "</project>" << std::endl;
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CProjectFileSerializer::serializeHeader( const SProjectFiles &project )
|
||||||
|
{
|
||||||
|
if( !out.good() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
out << '\t' << "<header>" << std::endl;
|
||||||
|
out << "\t\t" << "<name>" << project.projectName << "</name>" << std::endl;
|
||||||
|
out << "\t\t" << "<version>" << project.version << "</version>" << std::endl;
|
||||||
|
out << "\t\t" << "<mastergroup>" << project.masterGroup << "</mastergroup>" << std::endl;
|
||||||
|
out << "\t\t" << "<activegroup>" << project.activeGroup << "</activegroup>" << std::endl;
|
||||||
|
out << '\t' << "</header>" << std::endl;
|
||||||
|
|
||||||
|
if( !out.good() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CProjectFileSerializer::serializeGUIFiles( const SProjectFiles &project )
|
||||||
|
{
|
||||||
|
if( !out.good() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
out << '\t' << "<guifiles>" << std::endl;
|
||||||
|
|
||||||
|
std::vector< std::string >::const_iterator itr;
|
||||||
|
for( itr = project.guiFiles.begin(); itr != project.guiFiles.end(); ++itr )
|
||||||
|
{
|
||||||
|
out << "\t\t" << "<file>" << *itr << "</file>" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
out << '\t' << "</guifiles>" << std::endl;
|
||||||
|
|
||||||
|
if( !out.good() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CProjectFileSerializer::serializeMapFiles( const SProjectFiles &project )
|
||||||
|
{
|
||||||
|
if( !out.good() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
out << '\t' << "<mapfiles>" << std::endl;
|
||||||
|
|
||||||
|
std::vector< std::string >::const_iterator itr;
|
||||||
|
for( itr = project.mapFiles.begin(); itr != project.mapFiles.end(); ++itr )
|
||||||
|
{
|
||||||
|
out << "\t\t" << "<file>" << *itr << "</file>" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
out << '\t' << "</mapfiles>" << std::endl;
|
||||||
|
|
||||||
|
if( !out.good() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
// 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 PRJ_F_SERIALIZER
|
||||||
|
#define PRJ_F_SERIALIZER
|
||||||
|
|
||||||
|
#include "project_files.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
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
|
|
@ -23,10 +23,18 @@
|
||||||
|
|
||||||
namespace GUIEditor
|
namespace GUIEditor
|
||||||
{
|
{
|
||||||
|
enum ProjectVersion
|
||||||
|
{
|
||||||
|
OLD = 0,
|
||||||
|
NEW = 1,
|
||||||
|
MAX_PROJECTFILE_VERSION
|
||||||
|
};
|
||||||
|
|
||||||
struct SProjectFiles
|
struct SProjectFiles
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string projectName;
|
std::string projectName;
|
||||||
|
unsigned long version;
|
||||||
std::string masterGroup;
|
std::string masterGroup;
|
||||||
std::string activeGroup;
|
std::string activeGroup;
|
||||||
std::vector< std::string > guiFiles;
|
std::vector< std::string > guiFiles;
|
||||||
|
|
Loading…
Reference in a new issue