From 15ec7410f6783e088999067955f85293061eaa7e Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 20 Jul 2012 03:50:23 +0200 Subject: [PATCH] CHANGED: #1471 Project file changes in the project window will now be applied. Also it will cause the GUI XML files to be reparsed and the NelGUI widget to be redrawn. --HG-- branch : gsoc2012-gui-editor --- .../plugins/gui_editor/gui_editor_window.cpp | 31 ++++++++++-- .../plugins/gui_editor/gui_editor_window.h | 1 + .../src/plugins/gui_editor/project_files.h | 6 +++ .../src/plugins/gui_editor/project_window.cpp | 48 ++++++++++++++++++- .../src/plugins/gui_editor/project_window.h | 7 ++- 5 files changed, 88 insertions(+), 5 deletions(-) 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 9b34fc7a1..c85671d39 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 @@ -43,6 +43,7 @@ namespace GUIEditor { QString _lastDir; std::map< std::string, SWidgetInfo > widgetInfo; + SProjectFiles projectFiles; GUIEditorWindow::GUIEditorWindow(QWidget *parent) : QMainWindow(parent) @@ -53,6 +54,7 @@ namespace GUIEditor linkEditor = new LinkEditor; procEditor = new ProcEditor; projectWindow = new ProjectWindow; + connect( projectWindow, SIGNAL( projectFilesChanged() ), this, SLOT( onProjectFilesChanged() ) ); viewPort = new NelGUIWidget; setCentralWidget( viewPort ); @@ -138,12 +140,35 @@ namespace GUIEditor setCursor( Qt::ArrowCursor ); return; } - SProjectFiles projectFiles; + projectFiles.clear(); parser.getProjectFiles( projectFiles ); currentProject = parser.getProjectName().c_str(); projectWindow->setupFiles( projectFiles ); - viewPort->parse( projectFiles ); - viewPort->draw(); + if( viewPort->parse( projectFiles ) ) + viewPort->draw(); + else + { + QMessageBox::critical( this, + tr( "Error parsing GUI XML files" ), + tr( "There was an error while parsing the GUI XML files. See the log file for details." ) ); + } + + setCursor( Qt::ArrowCursor ); + } + + void GUIEditorWindow::onProjectFilesChanged() + { + setCursor( Qt::WaitCursor ); + + projectWindow->updateFiles( projectFiles ); + if( !viewPort->parse( projectFiles ) ) + { + QMessageBox::critical( this, + tr( "Error parsing GUI XML files" ), + tr( "There was an error while parsing the GUI XML files. See the log file for details." ) ); + } + else + viewPort->draw(); setCursor( Qt::ArrowCursor ); } 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 8dcbee745..86766e7ae 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 @@ -49,6 +49,7 @@ public Q_SLOTS: void open(); private Q_SLOTS: + void onProjectFilesChanged(); private: void createMenus(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files.h index 314495d57..9decad3c9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/project_files.h @@ -28,6 +28,12 @@ namespace GUIEditor public: std::vector< std::string > guiFiles; std::vector< std::string > mapFiles; + + void clear() + { + guiFiles.clear(); + mapFiles.clear(); + } }; } 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 index 1c2894ec5..4aec6cea8 100644 --- 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 @@ -25,7 +25,9 @@ namespace GUIEditor QWidget( parent ) { setupUi( this ); - connect( okButton, SIGNAL( clicked(bool) ), this, SLOT( hide() ) ); + filesChanged = false; + + connect( okButton, SIGNAL( clicked(bool) ), this, SLOT( onOKButtonClicked() ) ); connect( cancelButton, SIGNAL( clicked(bool) ), this, SLOT( hide() ) ); connect( addButton, SIGNAL( clicked(bool) ), this, SLOT( onAddButtonClicked() ) ); @@ -73,6 +75,35 @@ namespace GUIEditor } } + void ProjectWindow::updateFiles( SProjectFiles &projectFiles ) + { + projectFiles.clear(); + + QTreeWidgetItem *topItem; + + topItem = fileTree->topLevelItem( 0 ); + if( topItem != NULL ) + { + int c = topItem->childCount(); + for( int i = 0; i < c; i++ ) + { + QTreeWidgetItem *item = topItem->child( i ); + projectFiles.guiFiles.push_back( item->text( 0 ).toStdString() ); + } + } + + topItem = fileTree->topLevelItem( 1 ); + if( topItem != NULL ) + { + int c = topItem->childCount(); + for( int i = 0; i < c; i++ ) + { + QTreeWidgetItem *item = topItem->child( i ); + projectFiles.mapFiles.push_back( item->text( 0 ).toStdString() ); + } + } + } + void ProjectWindow::onAddButtonClicked() { if( fileTree->currentItem() == NULL ) @@ -99,6 +130,7 @@ namespace GUIEditor { QTreeWidgetItem *newItem = new QTreeWidgetItem( item ); newItem->setText( 0, newFile ); + filesChanged = true; } } @@ -120,9 +152,23 @@ namespace GUIEditor QMessageBox::Yes | QMessageBox::Cancel ); if( reply == QMessageBox::Yes ) + { fileTree->currentItem()->parent()->removeChild( fileTree->currentItem() ); + filesChanged = true; + } } + + void ProjectWindow::onOKButtonClicked() + { + hide(); + + if( filesChanged ) + { + filesChanged = false; + Q_EMIT projectFilesChanged(); + } + } } 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 index 97242ea75..71ce77ed8 100644 --- 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 @@ -33,13 +33,18 @@ namespace GUIEditor ~ProjectWindow(); void setupFiles( SProjectFiles &projectFiles ); + void updateFiles( SProjectFiles &projectFiles ); + + Q_SIGNALS: + void projectFilesChanged(); private Q_SLOTS: void onAddButtonClicked(); void onRemoveButtonClicked(); + void onOKButtonClicked(); private: - + bool filesChanged; }; }