ADDED: #1471 Project window and project xml file parser.

This commit is contained in:
dfighter1985 2012-07-18 08:24:50 +02:00
parent 8e903dff0c
commit 0aa208f840
9 changed files with 419 additions and 20 deletions

View file

@ -19,6 +19,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR
link_editor.h
proc_editor.h
property_browser_ctrl.h
project_window.h
)
SET(OVQT_PLUGIN_GUI_EDITOR_UIS
@ -28,6 +29,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS
action_editor.ui
link_editor.ui
proc_editor.ui
project_window.ui
)
SET(QT_USE_QTGUI TRUE)
@ -59,8 +61,10 @@ TARGET_LINK_LIBRARIES(
${QT_LIBRARIES}
${QT_QTOPENGL_LIBRARY}
qt_property_browser
${LUA_LIBRARIES}
${LUA_LIBRARIES}
${LUABIND_LIBRARIES}
${CURL_LIBRARIES}
${LIBWWW_LIBRARIES}
)
NL_DEFAULT_PROPS(ovqt_plugin_gui_editor "NeL, Tools, 3D: Object Viewer Qt Plugin: GUI Editor")

View file

@ -27,6 +27,7 @@
#include <QtCore/QSettings>
#include <QtGui/QFileDialog>
#include <QDockWidget>
#include <QMessageBox>
#include "../../3rdparty/qtpropertybrowser/QtTreePropertyBrowser"
#include "widget_properties.h"
@ -34,6 +35,8 @@
#include "widget_hierarchy.h"
#include "link_editor.h"
#include "proc_editor.h"
#include "project_file_parser.h"
#include "project_window.h"
namespace GUIEditor
{
@ -44,10 +47,11 @@ namespace GUIEditor
QMainWindow(parent)
{
m_ui.setupUi(this);
m_undoStack = new QUndoStack(this);
widgetProps = new CWidgetProperties;
linkEditor = new LinkEditor;
procEditor = new ProcEditor;
m_undoStack = new QUndoStack(this);
widgetProps = new CWidgetProperties;
linkEditor = new LinkEditor;
procEditor = new ProcEditor;
projectWindow = new ProjectWindow();
createMenus();
readSettings();
@ -84,6 +88,9 @@ namespace GUIEditor
delete procEditor;
procEditor = NULL;
delete projectWindow;
projectWindow = NULL;
}
QUndoStack *GUIEditorWindow::undoStack() const
@ -93,18 +100,43 @@ namespace GUIEditor
void GUIEditorWindow::open()
{
QStringList fileNames = QFileDialog::getOpenFileNames(this,
tr("Open GUI XML files"),
QString fileName = QFileDialog::getOpenFileName( this,
tr( "Open GUI XML files" ),
_lastDir,
tr("All XML files (*.xml)"));
tr( "All XML files (*.xml)" ) );
setCursor(Qt::WaitCursor);
if(!fileNames.isEmpty())
setCursor( Qt::WaitCursor );
if( !fileName.isEmpty() )
{
QStringList list = fileNames;
_lastDir = QFileInfo(list.front()).absolutePath();
_lastDir = QFileInfo( fileName ).absolutePath();
}
setCursor(Qt::ArrowCursor);
else
{
QMessageBox::critical( this,
tr( "Error opening project file" ),
tr( "Cannot open the specified project file!" ) );
setCursor( Qt::ArrowCursor );
return;
}
CProjectFileParser parser;
if( !parser.parseProjectFile( fileName.toStdString() ) )
{
QMessageBox::critical( this,
tr( "Error parsing project file" ),
tr( "There was an error while parsing the project file. Not a project file?" ) );
setCursor( Qt::ArrowCursor );
return;
}
std::vector< std::string > fileNames;
parser.getProjectFileNames( fileNames );
currentProject = parser.getProjectName().c_str();
projectWindow->setupFileList( fileNames );
setCursor( Qt::ArrowCursor );
}
@ -125,6 +157,10 @@ namespace GUIEditor
a = new QAction( "Proc Editor", this );
connect( a, SIGNAL( triggered( bool ) ), procEditor, SLOT( show() ) );
menu->addAction( a );
a = new QAction( "Project Window", this );
connect( a, SIGNAL( triggered( bool ) ), projectWindow, SLOT( show() ) );
menu->addAction( a );
}
}

View file

@ -30,6 +30,7 @@ namespace GUIEditor
class CWidgetProperties;
class LinkEditor;
class ProcEditor;
class ProjectWindow;
class GUIEditorWindow: public QMainWindow
{
@ -55,20 +56,16 @@ private:
void writeSettings();
void parseGUIWidgets();
void parseGUIWidget( const QString &file );
void parseGUIWidgetXML( QFile &file );
QString parseGUIWidgetHeader( QXmlStreamReader &reader );
void parseGUIWidgetProperties( QXmlStreamReader &reader, const QString &widgetName );
QUndoStack *m_undoStack;
Ui::GUIEditorWindow m_ui;
CWidgetProperties *widgetProps;
LinkEditor *linkEditor;
ProcEditor *procEditor;
ProjectWindow *projectWindow;
CPropBrowserCtrl browserCtrl;
QString currentProject;
};
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -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>

View file

@ -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();
}
}

View file

@ -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

View file

@ -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>