ADDED: #1471 Project window and project xml file parser.
--HG-- branch : gsoc2012-gui-editorhg/feature/sse2
parent
3598c4c46a
commit
33d024bcc0
@ -0,0 +1,127 @@
|
||||
// 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_parser.h"
|
||||
|
||||
namespace GUIEditor
|
||||
{
|
||||
CProjectFileParser::CProjectFileParser()
|
||||
{
|
||||
}
|
||||
|
||||
CProjectFileParser::~CProjectFileParser()
|
||||
{
|
||||
}
|
||||
|
||||
bool CProjectFileParser::parseProjectFile( std::string &name )
|
||||
{
|
||||
QFile file( name.c_str() );
|
||||
if( !file.open( QIODevice::ReadOnly ) )
|
||||
return false;
|
||||
|
||||
if( !parseXMLFile( file ) )
|
||||
{
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CProjectFileParser::getProjectFileNames( std::vector< std::string > &names ) const
|
||||
{
|
||||
names.resize( fileNames.size() );
|
||||
std::copy( fileNames.begin(), fileNames.end(), names.begin() );
|
||||
}
|
||||
|
||||
bool CProjectFileParser::parseXMLFile(QFile &f)
|
||||
{
|
||||
QXmlStreamReader reader;
|
||||
reader.setDevice( &f );
|
||||
|
||||
reader.readNext();
|
||||
if( reader.atEnd() )
|
||||
return false;
|
||||
|
||||
while( !reader.atEnd() && !( reader.isStartElement() && ( reader.name() == "project" ) ) )
|
||||
reader.readNext();
|
||||
if( reader.atEnd() )
|
||||
return false;
|
||||
|
||||
while( !reader.atEnd() && !( reader.isStartElement() && ( reader.name() == "header" ) ) )
|
||||
reader.readNext();
|
||||
if( reader.atEnd() )
|
||||
return false;
|
||||
|
||||
if( !parseHeader( reader ) )
|
||||
return false;
|
||||
|
||||
if( !parseFiles( reader ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CProjectFileParser::parseHeader( QXmlStreamReader &reader )
|
||||
{
|
||||
while( !reader.atEnd() && !( reader.isStartElement() && ( reader.name() == "name" ) ) )
|
||||
reader.readNext();
|
||||
if( reader.atEnd() )
|
||||
return false;
|
||||
|
||||
QString name = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||
if( name.isEmpty() )
|
||||
return false;
|
||||
projectName = name.toStdString();
|
||||
|
||||
while( !reader.atEnd() && !( reader.isEndElement() ) && ( reader.name() == "header" ) )
|
||||
reader.readNext();
|
||||
if( reader.atEnd() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CProjectFileParser::parseFiles( QXmlStreamReader &reader )
|
||||
{
|
||||
while( !reader.atEnd() && !( reader.isStartElement() && reader.name() == "files" ) )
|
||||
reader.readNext();
|
||||
if( reader.atEnd() )
|
||||
return false;
|
||||
|
||||
while( !reader.atEnd() && !( reader.isEndElement() && ( reader.name() == "files" ) ) )
|
||||
{
|
||||
if( reader.isStartElement() && ( reader.name() == "file" ) )
|
||||
{
|
||||
QString fileName = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement );
|
||||
if( !fileName.isEmpty() )
|
||||
fileNames.push_back( fileName.toStdString() );
|
||||
}
|
||||
|
||||
reader.readNext();
|
||||
}
|
||||
if( fileNames.empty() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
// 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 PRT_FILE_PARSER_H
|
||||
#define PRT_FILE_PARSER_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
namespace GUIEditor
|
||||
{
|
||||
/// Parses GUI Editor project files.
|
||||
class CProjectFileParser
|
||||
{
|
||||
public:
|
||||
CProjectFileParser();
|
||||
~CProjectFileParser();
|
||||
|
||||
bool parseProjectFile( std::string &name );
|
||||
const std::string& getProjectName() const{ return projectName; }
|
||||
void getProjectFileNames( std::vector< std::string > &names ) const;
|
||||
|
||||
private:
|
||||
bool parseXMLFile( QFile &f );
|
||||
bool parseHeader( QXmlStreamReader &reader );
|
||||
bool parseFiles( QXmlStreamReader &reader );
|
||||
|
||||
std::vector< std::string > fileNames;
|
||||
std::string projectName;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,11 @@
|
||||
<project>
|
||||
<header>
|
||||
<name>login</name>
|
||||
</header>
|
||||
<files>
|
||||
<file>login_config.xml</file>
|
||||
<file>login_keys.xml</file>
|
||||
<file>login_main.xml</file>
|
||||
<file>login_widgets.xml</file>
|
||||
</files>
|
||||
</project>
|
@ -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/>.
|
||||
|
||||
|
||||
#include "project_window.h"
|
||||
|
||||
namespace GUIEditor
|
||||
{
|
||||
ProjectWindow::ProjectWindow( QWidget *parent ) :
|
||||
QWidget( parent )
|
||||
{
|
||||
setupUi( this );
|
||||
connect( okButton, SIGNAL( clicked(bool) ), this, SLOT( hide() ) );
|
||||
connect( cancelButton, SIGNAL( clicked(bool) ), this, SLOT( hide() ) );
|
||||
}
|
||||
|
||||
ProjectWindow::~ProjectWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void ProjectWindow::setupFileList( const std::vector< std::string > &fileNames )
|
||||
{
|
||||
fileList->clear();
|
||||
|
||||
std::vector< std::string >::const_iterator itr;
|
||||
for( itr = fileNames.begin(); itr != fileNames.end(); ++itr )
|
||||
{
|
||||
const std::string &s = *itr;
|
||||
fileList->addItem( s.c_str() );
|
||||
}
|
||||
fileList->sortItems();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,41 @@
|
||||
// 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 PROJECT_WINDOW_H
|
||||
#define PROJECT_WINDOW_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "ui_project_window.h"
|
||||
|
||||
namespace GUIEditor
|
||||
{
|
||||
class ProjectWindow : public QWidget, public Ui::ProjectWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectWindow( QWidget *parent = NULL );
|
||||
~ProjectWindow();
|
||||
|
||||
void setupFileList( const std::vector< std::string > &fileNames );
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ProjectWindow</class>
|
||||
<widget class="QWidget" name="ProjectWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>379</width>
|
||||
<height>335</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Project files</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" rowspan="2" colspan="2">
|
||||
<widget class="QListWidget" name="fileList"/>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="addButton">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>223</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="okButton">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>194</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue