mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-27 19:10:52 +00:00
ADDED: #1471 CProjectFileSerializer class, and also it's possible to save the project file changes now.
This commit is contained in:
parent
9bb6bb99b1
commit
074e742900
7 changed files with 230 additions and 4 deletions
|
@ -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()
|
||||
|
|
|
@ -78,6 +78,7 @@ private:
|
|||
|
||||
CPropBrowserCtrl browserCtrl;
|
||||
QString currentProject;
|
||||
QString currentProjectFile;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue