From e8d325599069ea0d211e61709bc5cd69959cbcec Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 20 Nov 2012 04:50:51 +0100 Subject: [PATCH] MODIFIED: #1471 Adding new widget now works in the widget property dialog. --- .../src/plugins/gui_editor/CMakeLists.txt | 2 + .../plugins/gui_editor/new_widget_widget.cpp | 108 ++++++++++++++++++ .../plugins/gui_editor/new_widget_widget.h | 65 +++++++++++ .../plugins/gui_editor/new_widget_widget.ui | 59 ++++++++++ .../plugins/gui_editor/widget_properties.cpp | 16 ++- .../plugins/gui_editor/widget_properties.h | 5 + 6 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.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 d804815d3..d8a8a094f 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 @@ -57,6 +57,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR nel3d_widget.h nelgui_widget.h new_property_widget.h + new_widget_widget.h ) SET(OVQT_PLUGIN_GUI_EDITOR_UIS @@ -70,6 +71,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS action_editor.ui project_window.ui new_property_widget.ui + new_widget_widget.ui ) SET(QT_USE_QTGUI TRUE) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.cpp new file mode 100644 index 000000000..a641c4dc4 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.cpp @@ -0,0 +1,108 @@ +// 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 "new_widget_widget.h" +#include "widget_info_tree.h" + +namespace GUIEditor +{ + NewWidgetWidget::NewWidgetWidget( QWidget *parent ) : + QWidget( parent ) + { + widgetInfoTree = NULL; + setupUi( this ); + connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); + connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); + } + + NewWidgetWidget::~NewWidgetWidget() + { + widgetInfoTree = NULL; + } + + void NewWidgetWidget::fillWidgetList( std::vector< std::string > &widgets ) + { + ancestorCB->clear(); + + std::vector< std::string >::const_iterator itr = widgets.begin(); + while( itr != widgets.end() ) + { + ancestorCB->addItem( QString( itr->c_str() ) ); + ++itr; + } + } + + + void NewWidgetWidget::onAddClicked() + { + if( !checkNameField() ) + { + return; + } + + if( !checkNameDuplicate() ) + { + return; + } + + addNewWidget(); + hide(); + Q_EMIT widgetAdded(); + } + + + bool NewWidgetWidget::checkNameField() + { + if( nameEdit->text().toStdString().empty() ) + return false; + + return true; + } + + bool NewWidgetWidget::checkNameDuplicate() + { + if( widgetInfoTree == NULL ) + return false; + + CWidgetInfoTreeNode *node = widgetInfoTree->findNodeByName( nameEdit->text().toStdString() ); + if( node != NULL ) + return false; + + return true; + } + + + void NewWidgetWidget::addNewWidget() + { + CWidgetInfoTreeNode *node = widgetInfoTree->findNodeByName( ancestorCB->currentText().toStdString() ); + if( node == NULL ) + { + nlerror( "Ancestor %s doesn't exist! Aborting addition!", ancestorCB->currentText().toStdString().c_str() ); + return; + } + + SWidgetInfo info; + info.ancestor = ancestorCB->currentText().toStdString(); + info.name = nameEdit->text().toStdString(); + info.GUIName = "C" + info.name; + info.isAbstract = false; + info.resolved = true; + node->addChild( info ); + } + +} + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.h new file mode 100644 index 000000000..9967c3147 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.h @@ -0,0 +1,65 @@ +// 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 NEW_WIDGET_WIDGET_H +#define NEW_WIDGET_WIDGET_H + +#include "ui_new_widget_widget.h" +#include +#include + +namespace GUIEditor +{ + class CWidgetInfoTree; + + class NewWidgetWidget : public QWidget, public Ui::NewWidgetWidget + { + Q_OBJECT + public: + NewWidgetWidget( QWidget *parent = NULL ); + ~NewWidgetWidget(); + + /// Fills the widget list with the widget names + void fillWidgetList( std::vector< std::string > &widgets ); + + /// Sets the widget info tree so we can add new widgets + void setWidgetInfoTree( CWidgetInfoTree *tree ){ widgetInfoTree = tree; } + + private Q_SLOTS: + void onAddClicked(); + + private: + /// Checks if the name is valid + bool checkNameField(); + + /// Checks if the name is not a duplicate + bool checkNameDuplicate(); + + /// Adds the new widget + void addNewWidget(); + + CWidgetInfoTree *widgetInfoTree; + + Q_SIGNALS: + void widgetAdded(); + + }; +} + + +#endif + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.ui new file mode 100644 index 000000000..194d76de4 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_widget_widget.ui @@ -0,0 +1,59 @@ + + + NewWidgetWidget + + + + 0 + 0 + 249 + 108 + + + + New Widget + + + + + + + + Name + + + + + + + + + + Ancestor + + + + + + + + + + + + Add + + + + + + + Cancel + + + + + + + + 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 7c8621042..570182d61 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 @@ -17,6 +17,7 @@ #include "widget_properties.h" #include "widget_info_tree.h" #include "new_property_widget.h" +#include "new_widget_widget.h" #include namespace GUIEditor{ @@ -24,18 +25,23 @@ namespace GUIEditor{ QWidget( parent ) { newPropertyWidget = new NewPropertyWidget(); + newWidgetWidget = new NewWidgetWidget(); setupUi( this ); connect( rmWButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveWButtonClicked() ) ); 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( newPropertyWidget, SIGNAL( propertyAdded() ), this, SLOT( onPropertyAdded() ) ); + connect( newWidgetWidget, SIGNAL( widgetAdded() ), this, SLOT( onWidgetAdded() ) ); } CWidgetProperties::~CWidgetProperties() { delete newPropertyWidget; newPropertyWidget = NULL; + delete newWidgetWidget; + newWidgetWidget = NULL; tree = NULL; } @@ -112,6 +118,9 @@ namespace GUIEditor{ void CWidgetProperties::onAddWButtonClicked() { + newWidgetWidget->setWidgetInfoTree( tree ); + newWidgetWidget->fillWidgetList( widgetNames ); + newWidgetWidget->show(); } void CWidgetProperties::onAddPButtonClicked() @@ -135,10 +144,15 @@ namespace GUIEditor{ onListSelectionChanged( widgetList->currentRow() ); } + void CWidgetProperties::onWidgetAdded() + { + buildWidgetList(); + } + void CWidgetProperties::buildWidgetList() { widgetList->clear(); - std::vector< std::string > widgetNames; + widgetNames.clear(); tree->getNames( widgetNames ); std::sort( widgetNames.begin(), widgetNames.end() ); for( std::vector< std::string >::const_iterator itr = widgetNames.begin(); itr != widgetNames.end(); ++itr ) 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 f2b2fd323..947ff443b 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 @@ -28,6 +28,7 @@ namespace GUIEditor { class CWidgetInfoTree; class NewPropertyWidget; + class NewWidgetWidget; /// Widget that shows all available GUI widgets and their properties, /// Also allows the user to add / remove widgets and properties @@ -56,6 +57,7 @@ namespace GUIEditor void onAddPButtonClicked(); void onPropertyAdded(); + void onWidgetAdded(); private: /// Builds the widget list @@ -64,8 +66,11 @@ namespace GUIEditor /// Builds the property list for the currently selected widget void setPropsOf( const char *name ); + std::vector< std::string > widgetNames; + CWidgetInfoTree *tree; NewPropertyWidget *newPropertyWidget; + NewWidgetWidget *newWidgetWidget; }; }