From 7cad2331e7c04bf3f31ec4546982d169ce1125b1 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 21 Nov 2012 21:33:08 +0100 Subject: [PATCH] MODIFIED: #1471 Widget template changes can now be saved. --HG-- branch : gsoc2012-gui-editor --- .../gui_editor/widget_info_serializer.cpp | 77 +++++++++++++++++++ .../gui_editor/widget_info_serializer.h | 37 +++++++++ .../src/plugins/gui_editor/widget_info_tree.h | 7 ++ .../gui_editor/widget_info_tree_node.h | 9 +++ .../gui_editor/widget_info_tree_visitor.h | 34 ++++++++ .../plugins/gui_editor/widget_properties.cpp | 11 ++- .../plugins/gui_editor/widget_properties.h | 3 + .../plugins/gui_editor/widget_properties.ui | 65 +++++++++------- 8 files changed, 215 insertions(+), 28 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_visitor.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.cpp new file mode 100644 index 000000000..fdde2c04c --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.cpp @@ -0,0 +1,77 @@ +// 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 "widget_info_serializer.h" +#include "widget_info_tree.h" +#include + +namespace GUIEditor +{ + void CWidgetInfoSerializer::serialize( CWidgetInfoTree *tree ) + { + tree->accept( this ); + } + + void CWidgetInfoSerializer::visit( CWidgetInfoTreeNode *node ) + { + std::fstream f; + std::string filename = "widgets/" + node->getInfo().name + ".xml"; + SWidgetInfo &info = node->getInfo(); + + f.open( filename.c_str(), std::ios_base::out ); + if( !f.is_open() ) + { + nlinfo( "Failed to open %s for writing!\n", filename.c_str() ); + return; + } + + f << "" << std::endl; + f << "\t
" << std::endl; + f << "\t\t" << info.name << "" << std::endl; + f << "\t\t" << info.GUIName << "" << std::endl; + f << "\t\t" << info.ancestor << "" << std::endl; + f << "\t\t" << info.description << "" << std::endl; + + if( info.isAbstract ) + f << "\t\t" << "true" << "" << std::endl; + else + f << "\t\t" << "false" << "" << std::endl; + + f << "\t\t" << info.icon << "" << std::endl; + + f << "\t
" << std::endl; + f << "\t" << std::endl; + + for( std::vector< SPropEntry >::const_iterator itr = info.props.begin(); itr != info.props.end(); ++itr ) + { + f << "\t\t" << std::endl; + + f << "\t\t\t" << itr->propName << "" << std::endl; + f << "\t\t\t" << itr->propType << "" << std::endl; + f << "\t\t\t" << itr->propDefault << "" << std::endl; + + f << "\t\t" << std::endl; + } + + f << "\t" << std::endl; + f << "
" << std::endl; + f << std::endl; + + f.close(); + + } +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.h new file mode 100644 index 000000000..08835e92a --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_serializer.h @@ -0,0 +1,37 @@ +// 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 WIDGET_INFO_SERIALIZER_H +#define WIDGET_INFO_SERIALIZER_H + +#include "widget_info_tree_visitor.h" + +namespace GUIEditor +{ + class CWidgetInfoTree; + + class CWidgetInfoSerializer : public CWidgetInfoTreeVisitor + { + public: + void serialize( CWidgetInfoTree *tree ); + void visit( CWidgetInfoTreeNode *node ); + + private: + }; +} + +#endif + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree.h index b93dff2cb..27fbc6233 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree.h @@ -100,6 +100,13 @@ namespace GUIEditor root->getNames( v ); } + + /// Accepts a visitor + void accept( CWidgetInfoTreeVisitor *visitor ) + { + root->accept( visitor ); + } + private: CWidgetInfoTreeNode *root; }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_node.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_node.h index 9bb2527d7..274938c57 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_node.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_node.h @@ -18,6 +18,7 @@ #define WIDGET_INFO_TREE_NODE #include "widget_info.h" +#include "widget_info_tree_visitor.h" namespace GUIEditor { @@ -221,6 +222,14 @@ namespace GUIEditor ( *itr )->getNames( v ); } + /// Accepts a visitor to itself and to the children nodes + void accept( CWidgetInfoTreeVisitor *visitor ) + { + visitor->visit( this ); + for( std::vector< CWidgetInfoTreeNode* >::iterator itr = children.begin(); itr != children.end(); ++itr ) + ( *itr )->accept( visitor ); + } + private: SWidgetInfo info; CWidgetInfoTreeNode *parent; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_visitor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_visitor.h new file mode 100644 index 000000000..d4ff0713a --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_info_tree_visitor.h @@ -0,0 +1,34 @@ +// 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 WIDGET_INFO_TREE_VISITOR_H +#define WIDGET_INFO_TREE_VISITOR_H + +namespace GUIEditor +{ + class CWidgetInfoTreeNode; + + /// Visitor base class for CWidgetInfoTree + class CWidgetInfoTreeVisitor + { + public: + /// Visits a node + virtual void visit( CWidgetInfoTreeNode *node ) = 0; + }; +} + +#endif + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.cpp index 570182d61..dda52a4d5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.cpp @@ -16,9 +16,10 @@ #include "widget_properties.h" #include "widget_info_tree.h" +#include "widget_info_serializer.h" #include "new_property_widget.h" #include "new_widget_widget.h" -#include +#include namespace GUIEditor{ CWidgetProperties::CWidgetProperties( QWidget *parent ) : @@ -32,6 +33,7 @@ namespace GUIEditor{ connect( rmPButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemovePButtonClicked() ) ); connect( addPButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddPButtonClicked() ) ); connect( addWButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddWButtonClicked() ) ); + connect( saveButton, SIGNAL( clicked( bool ) ), this, SLOT( onSaveButtonClicked() ) ); connect( newPropertyWidget, SIGNAL( propertyAdded() ), this, SLOT( onPropertyAdded() ) ); connect( newWidgetWidget, SIGNAL( widgetAdded() ), this, SLOT( onWidgetAdded() ) ); } @@ -139,6 +141,13 @@ namespace GUIEditor{ newPropertyWidget->show(); } + + void CWidgetProperties::onSaveButtonClicked() + { + CWidgetInfoSerializer serializer; + serializer.serialize( tree ); + } + void CWidgetProperties::onPropertyAdded() { onListSelectionChanged( widgetList->currentRow() ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.h index 947ff443b..2280e1ee8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.h @@ -56,6 +56,9 @@ namespace GUIEditor /// Adds a widget property to the list void onAddPButtonClicked(); + /// Saves the widgets + void onSaveButtonClicked(); + void onPropertyAdded(); void onWidgetAdded(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.ui index 3ad30adbb..bcf742307 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_properties.ui @@ -14,7 +14,7 @@ Widget Properties - + @@ -41,38 +41,49 @@ - + - + + + + + Add + + + + + + + Remove + + + + + + + - Add + Save - - - Remove - - - - - - - - - - - Add - - - - - - - Remove - - + + + + + Add + + + + + + + Remove + + + +