CHANGED: #1471 LinkList and LinkEditor are now fully implemented.

This commit is contained in:
dfighter1985 2012-07-25 21:51:05 +02:00
parent 070e892393
commit f608e3a780
9 changed files with 220 additions and 78 deletions

View file

@ -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; }
};

View file

@ -17,6 +17,7 @@
#ifndef LINKDATA_H
#define LINKDATA_H
#include "nel/misc/types_nl.h"
#include <string>
namespace NLGUI
@ -25,6 +26,7 @@ namespace NLGUI
struct SLinkData
{
public:
uint32 id;
std::string parent;
std::string expr;
std::string target;

View file

@ -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;
};
}

View file

@ -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
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'
if( editorMode )
}
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;
}
}

View file

@ -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 );
targetEdit->setText( data.target.c_str() );
ahEdit->setText( data.action.c_str() );
ahParamEdit->setEnabled( true );
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();
}
}

View file

@ -32,6 +32,9 @@ namespace GUIEditor
void setup();
void setLinkId( uint32 linkId );
private Q_SLOTS:
void onOKButtonClicked();
private:
uint32 currentLinkId;
};

View file

@ -9,14 +9,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>348</height>
<width>540</width>
<height>430</height>
</rect>
</property>
<property name="windowTitle">
<string>Link Editor</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
@ -27,46 +27,63 @@
<item row="1" column="0" colspan="3">
<widget class="QPlainTextEdit" name="expressionEdit">
<property name="plainText">
<string>expression</string>
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="2" column="0" colspan="3">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>When the expression is evaluated</string>
<string>Target group(s)</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="targetEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Action handler</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="condEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Parameter(s)</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="ahEdit">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="groupCB">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Pass result to targeted group(s)</string>
<string>Condition</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QRadioButton" name="ahCB">
<property name="text">
<string>Run Action Handler</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="QLineEdit" name="ahEdit">
<property name="text">
<string>Targeted group(s) or action handler</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<item row="3" column="1">
<widget class="QLineEdit" name="ahParamEdit">
<property name="text">
<string>Action Handler parameters</string>
<string/>
</property>
</widget>
</item>
<item row="7" column="0">
</layout>
</item>
<item row="3" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -79,14 +96,14 @@
</property>
</spacer>
</item>
<item row="7" column="1">
<item row="3" column="1">
<widget class="QPushButton" name="okButton">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item row="7" column="2">
<item row="3" column="2">
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>

View file

@ -17,6 +17,8 @@
#include "link_list.h"
#include "link_editor.h"
#include <QMessageBox>
#include <QInputDialog>
#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();
}
}

View file

@ -35,7 +35,10 @@ namespace GUIEditor
void onGUILoaded();
private Q_SLOTS:
void onAddButtonClicked();
void onRemoveButtonClicked();
void onEditButtonClicked();
void onItemDblClicked( QTreeWidgetItem *item );
private:
LinkEditor *linkEditor;