From aac2efc57784154f264b08f56ef79d886a7f649d Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 18 Jul 2012 08:24:50 +0200 Subject: [PATCH] ADDED: #1471 Project window and project xml file parser. --- .../src/plugins/gui_editor/CMakeLists.txt | 6 +- .../plugins/gui_editor/gui_editor_window.cpp | 60 +++++++-- .../plugins/gui_editor/gui_editor_window.h | 11 +- .../gui_editor/project_file_parser.cpp | 127 ++++++++++++++++++ .../plugins/gui_editor/project_file_parser.h | 49 +++++++ .../gui_editor/project_files/login.xml | 11 ++ .../src/plugins/gui_editor/project_window.cpp | 48 +++++++ .../src/plugins/gui_editor/project_window.h | 41 ++++++ .../src/plugins/gui_editor/project_window.ui | 86 ++++++++++++ 9 files changed, 419 insertions(+), 20 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files/login.xml create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.ui diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt index a1e1c5727..f355524a3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt @@ -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") 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 566e86fd2..425aba88d 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 @@ -27,6 +27,7 @@ #include #include #include +#include #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 ); } } 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 25f454fb4..f3acdbfa7 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 @@ -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; }; } 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 new file mode 100644 index 000000000..0ce40a5ac --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.cpp @@ -0,0 +1,127 @@ +// 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_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; + } +} + + + 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 new file mode 100644 index 000000000..f51a7ef93 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_file_parser.h @@ -0,0 +1,49 @@ +// 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 PRT_FILE_PARSER_H +#define PRT_FILE_PARSER_H + +#include +#include +#include +#include + +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 diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files/login.xml b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files/login.xml new file mode 100644 index 000000000..d8cea9dbc --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files/login.xml @@ -0,0 +1,11 @@ + +
+ login +
+ + login_config.xml + login_keys.xml + login_main.xml + login_widgets.xml + +
\ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.cpp new file mode 100644 index 000000000..cebbfe848 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.cpp @@ -0,0 +1,48 @@ +// 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_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(); + } +} + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.h new file mode 100644 index 000000000..155c171e8 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.h @@ -0,0 +1,41 @@ +// 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 PROJECT_WINDOW_H +#define PROJECT_WINDOW_H + +#include +#include +#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 diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.ui new file mode 100644 index 000000000..2b67bd8fb --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_window.ui @@ -0,0 +1,86 @@ + + + ProjectWindow + + + + 0 + 0 + 379 + 335 + + + + Project files + + + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + Qt::Vertical + + + + 20 + 223 + + + + + + + + + + OK + + + + + + + Cancel + + + + + + + + + Qt::Horizontal + + + + 194 + 20 + + + + + + + + +