From f608e3a780ceba15be9755217c8bae32102b59eb Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 25 Jul 2012 21:51:05 +0200 Subject: [PATCH] CHANGED: #1471 LinkList and LinkEditor are now fully implemented. --- code/nel/include/nel/gui/interface_parser.h | 5 +- code/nel/include/nel/gui/link_data.h | 2 + code/nel/include/nel/gui/parser.h | 5 +- code/nel/src/gui/interface_parser.cpp | 51 ++++++++-- .../src/plugins/gui_editor/link_editor.cpp | 57 ++++++----- .../src/plugins/gui_editor/link_editor.h | 3 + .../src/plugins/gui_editor/link_editor.ui | 97 +++++++++++-------- .../src/plugins/gui_editor/link_list.cpp | 75 ++++++++++++++ .../src/plugins/gui_editor/link_list.h | 3 + 9 files changed, 220 insertions(+), 78 deletions(-) diff --git a/code/nel/include/nel/gui/interface_parser.h b/code/nel/include/nel/gui/interface_parser.h index 2893adfbf..6cf364d23 100644 --- a/code/nel/include/nel/gui/interface_parser.h +++ b/code/nel/include/nel/gui/interface_parser.h @@ -348,7 +348,10 @@ namespace NLGUI bool removeProc( const std::string &name ); const std::map< uint32, SLinkData >& getLinkMap() const{ return links; } - void addLinkData( const SLinkData &linkData ); + uint32 addLinkData( SLinkData &linkData ); + void removeLinkData( uint32 id ); + bool getLinkData( uint32 id, SLinkData &linkData ); + void updateLinkData( uint32 id, const SLinkData &linkData ); void setEditorMode( bool b ){ editorMode = b; } }; diff --git a/code/nel/include/nel/gui/link_data.h b/code/nel/include/nel/gui/link_data.h index 66aac9ced..c2d0c3427 100644 --- a/code/nel/include/nel/gui/link_data.h +++ b/code/nel/include/nel/gui/link_data.h @@ -17,6 +17,7 @@ #ifndef LINKDATA_H #define LINKDATA_H +#include "nel/misc/types_nl.h" #include namespace NLGUI @@ -25,6 +26,7 @@ namespace NLGUI struct SLinkData { public: + uint32 id; std::string parent; std::string expr; std::string target; diff --git a/code/nel/include/nel/gui/parser.h b/code/nel/include/nel/gui/parser.h index aba7d1f82..ebc0dd607 100644 --- a/code/nel/include/nel/gui/parser.h +++ b/code/nel/include/nel/gui/parser.h @@ -74,7 +74,10 @@ namespace NLGUI virtual bool removeProc( const std::string &name ) = 0; virtual void setEditorMode( bool b ) = 0; virtual const std::map< uint32, SLinkData >& getLinkMap() const = 0; - virtual void addLinkData( const SLinkData &linkData ) = 0; + virtual uint32 addLinkData( SLinkData &linkData ) = 0; + virtual void removeLinkData( uint32 id ) = 0; + virtual bool getLinkData( uint32 id, SLinkData &linkData ) = 0; + virtual void updateLinkData( uint32 id, const SLinkData &linkData ) = 0; }; } diff --git a/code/nel/src/gui/interface_parser.cpp b/code/nel/src/gui/interface_parser.cpp index bd9217eb3..afd118ef5 100644 --- a/code/nel/src/gui/interface_parser.cpp +++ b/code/nel/src/gui/interface_parser.cpp @@ -994,7 +994,7 @@ namespace NLGUI ptr = (char*) xmlGetProp (cur, (xmlChar*)"target"); std::string target = ptr; - if (ptr) + if( ( ptr != NULL ) && !editorMode ) { CInterfaceLink::splitLinkTargets(std::string((const char*)ptr), parentGroup, targets); } @@ -1010,10 +1010,12 @@ namespace NLGUI if (ptr) cond = (const char *) ptr; // create the link - CInterfaceLink *il = new CInterfaceLink; - il->init(targets, expr, action, params, cond, parentGroup); // init will add 'il' in the list of link present in 'elm' - - if( editorMode ) + if( !editorMode ) + { + CInterfaceLink *il = new CInterfaceLink; + il->init(targets, expr, action, params, cond, parentGroup); // init will add 'il' in the list of link present in 'elm' + } + else { SLinkData linkData; linkData.parent = parentGroup->getId(); @@ -2459,6 +2461,8 @@ namespace NLGUI void CInterfaceParser::removeAllLinks() { _LinkMap.clear(); + links.clear(); + linkId = 0; } // *************************************************************************** @@ -2832,9 +2836,42 @@ namespace NLGUI return true; } - void CInterfaceParser::addLinkData( const SLinkData &linkData ) + uint32 CInterfaceParser::addLinkData( SLinkData &linkData ) { - links[ ++linkId ] = linkData; + linkData.id = ++linkId; + links[ linkData.id ] = linkData; + return linkId; + } + + void CInterfaceParser::removeLinkData( uint32 id ) + { + std::map< uint32, SLinkData >::iterator itr = + links.find( id ); + if( itr == links.end() ) + return; + + links.erase( itr ); + } + + bool CInterfaceParser::getLinkData( uint32 id, SLinkData &linkData ) + { + std::map< uint32, SLinkData >::iterator itr = + links.find( id ); + if( itr == links.end() ) + return false; + + linkData = itr->second; + + return true; + } + + void CInterfaceParser::updateLinkData( uint32 id, const SLinkData &linkData ) + { + std::map< uint32, SLinkData >::iterator itr = + links.find( id ); + if( itr == links.end() ) + return; + itr->second = linkData; } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.cpp index a0dd8e78e..61db9ee84 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.cpp @@ -26,7 +26,7 @@ namespace GUIEditor { setupUi( this ); setup(); - connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); + connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKButtonClicked() ) ); connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); } @@ -37,15 +37,10 @@ namespace GUIEditor void LinkEditor::setup() { expressionEdit->clear(); - groupCB->setCheckable( true ); - groupCB->setChecked( false ); - groupCB->setDisabled( true ); - ahCB->setCheckable( true ); - ahCB->setChecked( false ); - ahCB->setDisabled( true ); + targetEdit->clear(); ahEdit->clear(); ahParamEdit->clear(); - ahParamEdit->setDisabled( true ); + condEdit->clear(); } void LinkEditor::setLinkId( uint32 linkId ) @@ -53,30 +48,34 @@ namespace GUIEditor setup(); currentLinkId = linkId; - const std::map< uint32, SLinkData > &linkMap = - CWidgetManager::getInstance()->getParser()->getLinkMap(); + IParser *parser = CWidgetManager::getInstance()->getParser(); + SLinkData data; - std::map< uint32, SLinkData >::const_iterator itr = - linkMap.find( currentLinkId ); - - if( itr == linkMap.end() ) + if( !parser->getLinkData( currentLinkId, data ) ) return; - SLinkData data = itr->second; expressionEdit->setPlainText( data.expr.c_str() ); - if( !data.target.empty() ) - { - groupCB->setEnabled( true ); - groupCB->setChecked( true ); - ahEdit->setText( data.target.c_str() ); - } - else - { - ahCB->setEnabled( true ); - ahCB->setChecked( true ); - ahEdit->setText( data.action.c_str() ); - ahParamEdit->setEnabled( true ); - ahParamEdit->setText( data.params.c_str() ); - } + targetEdit->setText( data.target.c_str() ); + ahEdit->setText( data.action.c_str() ); + ahParamEdit->setText( data.params.c_str() ); + condEdit->setText( data.cond.c_str() ); + } + + void LinkEditor::onOKButtonClicked() + { + IParser *parser = CWidgetManager::getInstance()->getParser(); + SLinkData data; + + if( !parser->getLinkData( currentLinkId, data ) ) + return; + + data.expr = expressionEdit->toPlainText().toStdString(); + data.target = targetEdit->text().toStdString(); + data.action = ahEdit->text().toStdString(); + data.params = ahParamEdit->text().toStdString(); + data.cond = condEdit->text().toStdString(); + parser->updateLinkData( data.id, data ); + + hide(); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.h index ca6286022..2d3e630c0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.h @@ -32,6 +32,9 @@ namespace GUIEditor void setup(); void setLinkId( uint32 linkId ); + private Q_SLOTS: + void onOKButtonClicked(); + private: uint32 currentLinkId; }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.ui index 328a85709..13a6e7d7e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.ui @@ -9,14 +9,14 @@ 0 0 - 545 - 348 + 540 + 430 Link Editor - + @@ -27,46 +27,63 @@ - expression + - - - - When the expression is evaluated - - + + + + + + Target group(s) + + + + + + + + + + Action handler + + + + + + + + + + Parameter(s) + + + + + + + + + + + + + + Condition + + + + + + + + + + + - - - Pass result to targeted group(s) - - - - - - - Run Action Handler - - - - - - - Targeted group(s) or action handler - - - - - - - Action Handler parameters - - - - Qt::Horizontal @@ -79,14 +96,14 @@ - + OK - + Cancel diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.cpp index 94e808196..4a7643246 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.cpp @@ -17,6 +17,8 @@ #include "link_list.h" #include "link_editor.h" +#include +#include #include "nel/gui/interface_group.h" #include "nel/gui/widget_manager.h" #include "nel/gui/link_data.h" @@ -33,7 +35,12 @@ namespace GUIEditor linkEditor = new LinkEditor(); connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); + connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddButtonClicked() ) ); + connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveButtonClicked() ) ); connect( editButton, SIGNAL( clicked( bool ) ), this, SLOT( onEditButtonClicked() ) ); + + connect( linkTree, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), + this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) ); } LinkList::~LinkList() @@ -59,6 +66,63 @@ namespace GUIEditor linkTree->sortByColumn( 0 ); } + void LinkList::onAddButtonClicked() + { + bool ok; + QString parent = + QInputDialog::getText( this, + tr( "Adding a new link" ), + tr( "Please specify the parent group's full id" ), + QLineEdit::Normal, + QString(), + &ok ); + if( ok ) + { + if( CWidgetManager::getInstance()->getElementFromId( parent.toStdString() ) == NULL ) + { + QMessageBox::critical( this, + tr( "Parent group doesn't exist" ), + tr( "The specified parent group '%1' doesn't exist!" ).arg( parent ) ); + return; + } + SLinkData data; + data.parent = parent.toStdString(); + + uint32 id = CWidgetManager::getInstance()->getParser()->addLinkData( data ); + + QTreeWidgetItem *item = new QTreeWidgetItem( linkTree ); + item->setText( 0, parent ); + item->setData( 3, Qt::UserRole, id ); + linkTree->addTopLevelItem( item ); + } + } + + void LinkList::onRemoveButtonClicked() + { + QTreeWidgetItem *item = + linkTree->currentItem(); + if( item == NULL ) + return; + + bool ok; + uint32 id = item->data( 3, Qt::UserRole ).toUInt( &ok ); + if( !ok ) + return; + + QMessageBox::StandardButton reply = + QMessageBox::question( this, + tr( "Removing a link" ), + tr( "Are you sure you want to remove this link?" ), + QMessageBox::Yes | QMessageBox::Cancel ); + + if( reply != QMessageBox::Yes ) + return; + + CWidgetManager::getInstance()->getParser()->removeLinkData( id ); + linkTree->takeTopLevelItem( linkTree->indexOfTopLevelItem( item ) ); + delete item; + } + void LinkList::onEditButtonClicked() { @@ -75,5 +139,16 @@ namespace GUIEditor linkEditor->setLinkId( id ); linkEditor->show(); } + + void LinkList::onItemDblClicked( QTreeWidgetItem *item ) + { + bool ok; + uint32 id = item->data( 3, Qt::UserRole ).toUInt( &ok ); + if( !ok ) + return; + + linkEditor->setLinkId( id ); + linkEditor->show(); + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.h index ef4111712..895ea3b69 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.h @@ -35,7 +35,10 @@ namespace GUIEditor void onGUILoaded(); private Q_SLOTS: + void onAddButtonClicked(); + void onRemoveButtonClicked(); void onEditButtonClicked(); + void onItemDblClicked( QTreeWidgetItem *item ); private: LinkEditor *linkEditor;