From 4a9fb9e013566c9848a5dfd6224c2972c27ca784 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 19 Nov 2012 21:06:26 +0100 Subject: [PATCH] MODIFIED: #1471 Adding new property now works. --HG-- branch : gsoc2012-gui-editor --- .../src/plugins/gui_editor/CMakeLists.txt | 2 + .../gui_editor/new_property_widget.cpp | 123 ++++++++++++++++++ .../plugins/gui_editor/new_property_widget.h | 57 ++++++++ .../plugins/gui_editor/new_property_widget.ui | 85 ++++++++++++ .../gui_editor/widget_info_tree_node.h | 24 ++++ .../plugins/gui_editor/widget_properties.cpp | 33 +++++ .../plugins/gui_editor/widget_properties.h | 12 ++ 7 files changed, 336 insertions(+) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_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 80dcff21e..d804815d3 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 @@ -56,6 +56,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR project_window.h nel3d_widget.h nelgui_widget.h + new_property_widget.h ) SET(OVQT_PLUGIN_GUI_EDITOR_UIS @@ -68,6 +69,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS proc_editor.ui action_editor.ui project_window.ui + new_property_widget.ui ) SET(QT_USE_QTGUI TRUE) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.cpp new file mode 100644 index 000000000..f46a6943d --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.cpp @@ -0,0 +1,123 @@ +// 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_property_widget.h" +#include "widget_info_tree_node.h" +#include + + +namespace GUIEditor +{ + NewPropertyWidget::NewPropertyWidget( QWidget *parent ) : + QWidget( parent ) + { + widgetInfoTreeNode = NULL; + setupUi( this ); + connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); + connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); + } + + NewPropertyWidget::~NewPropertyWidget() + { + } + + void NewPropertyWidget::onAddClicked() + { + if( nameEdit->text().isEmpty() ) + { + QMessageBox::warning( this, + tr( "Adding a new property" ), + tr( "You need to specify a name for the new property!" ), + QMessageBox::Ok + ); + return; + } + + if( !checkName() ) + { + QMessageBox::warning( this, + tr( "Adding a new property" ), + tr( "A property with that name already exists in the widget!" ), + QMessageBox::Ok + ); + return; + } + + if( !checkDefaultValue() ) + { + QMessageBox::warning( this, + tr( "Adding a new property" ), + tr( "You need to specify a valid default value." ), + QMessageBox::Ok + ); + return; + } + + SPropEntry prop; + prop.propName = nameEdit->text().toStdString(); + prop.propType = typeCB->currentText().toStdString(); + prop.propDefault = defvalEdit->text().toStdString(); + widgetInfoTreeNode->addPropertyToAll( prop ); + + widgetInfoTreeNode = NULL; + hide(); + + Q_EMIT propertyAdded(); + } + + + bool NewPropertyWidget::checkName() const + { + if( widgetInfoTreeNode == NULL ) + return false; + + if( widgetInfoTreeNode->hasProperty( nameEdit->text().toStdString() ) ) + return false; + + return true; + } + + bool NewPropertyWidget::checkDefaultValue() const + { + if( widgetInfoTreeNode == NULL ) + return false; + + if( ( typeCB->currentText() != "string" ) && ( defvalEdit->text().isEmpty() ) ) + return false; + + if( typeCB->currentText() == "bool" ) + { + if( defvalEdit->text().toUpper() == "TRUE" ) + return true; + if( defvalEdit->text().toUpper() == "FALSE" ) + return true; + return false; + } + else + if( typeCB->currentText() == "int" ) + { + bool ok = false; + defvalEdit->text().toInt( &ok ); + if( ok ) + return true; + return false; + } + + return true; + } + +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.h new file mode 100644 index 000000000..bf20a015d --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.h @@ -0,0 +1,57 @@ +// 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_PROPERTY_WIDGET_H +#define NEW_PROPERTY_WIDGET_H + +#include "ui_new_property_widget.h" + +namespace GUIEditor +{ + class CWidgetInfoTreeNode; + + /// Widget for adding a new property + class NewPropertyWidget : public QWidget, public Ui::NewPropertyWidget + { + Q_OBJECT + public: + NewPropertyWidget( QWidget *parent = NULL ); + ~NewPropertyWidget(); + + /// Sets the widget info, so that we can check for duplicates + void setWidgetInfo( CWidgetInfoTreeNode *node ){ widgetInfoTreeNode = node; } + + private Q_SLOTS: + void onAddClicked(); + + /// Checks the validity of the property name field + bool checkName() const; + + /// Checks the validity of the default value field + bool checkDefaultValue() const; + + private: + CWidgetInfoTreeNode *widgetInfoTreeNode; + + + Q_SIGNALS: + void propertyAdded(); + }; +} + +#endif + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.ui new file mode 100644 index 000000000..bf725dc4c --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/new_property_widget.ui @@ -0,0 +1,85 @@ + + + NewPropertyWidget + + + + 0 + 0 + 299 + 121 + + + + New property + + + + + + + + Name + + + + + + + + + + Type + + + + + + + + string + + + + + int + + + + + bool + + + + + + + + Default value + + + + + + + + + + + + Add + + + + + + + Cancel + + + + + + + + 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 80d1f5a45..9bb2527d7 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 @@ -138,12 +138,36 @@ namespace GUIEditor children.clear(); } + /// Checks if this node has this property + bool hasProperty( const std::string &name ) + { + std::vector< SPropEntry >::const_iterator itr = info.findProp( name ); + if( itr != info.props.end() ) + return true; + else + return false; + } + /// Add new property to the node void addProperty( const SPropEntry &prop ) { info.props.push_back( prop ); } + /// Add new property to the node and all children + void addPropertyToAll( const SPropEntry &prop ) + { + addProperty( prop ); + + std::vector< CWidgetInfoTreeNode* >::iterator itr = children.begin(); + while( itr != children.end() ) + { + ( *itr )->addPropertyToAll( prop ); + ++itr; + } + + } + /// Removes this property from the node void removeProperty( const SPropEntry &prop ) { 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 09e1e80d2..7c8621042 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,19 +16,27 @@ #include "widget_properties.h" #include "widget_info_tree.h" +#include "new_property_widget.h" #include namespace GUIEditor{ CWidgetProperties::CWidgetProperties( QWidget *parent ) : QWidget( parent ) { + newPropertyWidget = new NewPropertyWidget(); + 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( newPropertyWidget, SIGNAL( propertyAdded() ), this, SLOT( onPropertyAdded() ) ); } CWidgetProperties::~CWidgetProperties() { + delete newPropertyWidget; + newPropertyWidget = NULL; + tree = NULL; } void CWidgetProperties::setupWidgetInfo( CWidgetInfoTree *tree ) @@ -102,6 +110,31 @@ namespace GUIEditor{ } + void CWidgetProperties::onAddWButtonClicked() + { + } + + void CWidgetProperties::onAddPButtonClicked() + { + if( widgetList->count() == 0 ) + return; + + if( ( widgetList->currentRow() >= widgetList->count() ) || ( widgetList->currentRow() < 0 ) ) + return; + + CWidgetInfoTreeNode *node = tree->findNodeByName( widgetList->currentItem()->text().toStdString() ); + if( node == NULL ) + return; + + newPropertyWidget->setWidgetInfo( node ); + newPropertyWidget->show(); + } + + void CWidgetProperties::onPropertyAdded() + { + onListSelectionChanged( widgetList->currentRow() ); + } + void CWidgetProperties::buildWidgetList() { widgetList->clear(); 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 42a3ad394..f2b2fd323 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 @@ -27,7 +27,10 @@ namespace GUIEditor { class CWidgetInfoTree; + class NewPropertyWidget; + /// Widget that shows all available GUI widgets and their properties, + /// Also allows the user to add / remove widgets and properties class CWidgetProperties : public QWidget, public Ui::WidgetProperties { Q_OBJECT @@ -46,6 +49,14 @@ namespace GUIEditor /// Removes widget property from the list void onRemovePButtonClicked(); + /// Adds a widget to the list + void onAddWButtonClicked(); + + /// Adds a widget property to the list + void onAddPButtonClicked(); + + void onPropertyAdded(); + private: /// Builds the widget list void buildWidgetList(); @@ -54,6 +65,7 @@ namespace GUIEditor void setPropsOf( const char *name ); CWidgetInfoTree *tree; + NewPropertyWidget *newPropertyWidget; }; }