mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-27 17:46:18 +00:00
CHANGED: #1471 LinkList and LinkEditor are now fully implemented.
This commit is contained in:
parent
5817e07468
commit
63c6788273
9 changed files with 220 additions and 78 deletions
|
@ -348,7 +348,10 @@ namespace NLGUI
|
||||||
bool removeProc( const std::string &name );
|
bool removeProc( const std::string &name );
|
||||||
|
|
||||||
const std::map< uint32, SLinkData >& getLinkMap() const{ return links; }
|
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; }
|
void setEditorMode( bool b ){ editorMode = b; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#ifndef LINKDATA_H
|
#ifndef LINKDATA_H
|
||||||
#define LINKDATA_H
|
#define LINKDATA_H
|
||||||
|
|
||||||
|
#include "nel/misc/types_nl.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace NLGUI
|
namespace NLGUI
|
||||||
|
@ -25,6 +26,7 @@ namespace NLGUI
|
||||||
struct SLinkData
|
struct SLinkData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
uint32 id;
|
||||||
std::string parent;
|
std::string parent;
|
||||||
std::string expr;
|
std::string expr;
|
||||||
std::string target;
|
std::string target;
|
||||||
|
|
|
@ -74,7 +74,10 @@ namespace NLGUI
|
||||||
virtual bool removeProc( const std::string &name ) = 0;
|
virtual bool removeProc( const std::string &name ) = 0;
|
||||||
virtual void setEditorMode( bool b ) = 0;
|
virtual void setEditorMode( bool b ) = 0;
|
||||||
virtual const std::map< uint32, SLinkData >& getLinkMap() const = 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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -994,7 +994,7 @@ namespace NLGUI
|
||||||
|
|
||||||
ptr = (char*) xmlGetProp (cur, (xmlChar*)"target");
|
ptr = (char*) xmlGetProp (cur, (xmlChar*)"target");
|
||||||
std::string target = ptr;
|
std::string target = ptr;
|
||||||
if (ptr)
|
if( ( ptr != NULL ) && !editorMode )
|
||||||
{
|
{
|
||||||
CInterfaceLink::splitLinkTargets(std::string((const char*)ptr), parentGroup, targets);
|
CInterfaceLink::splitLinkTargets(std::string((const char*)ptr), parentGroup, targets);
|
||||||
}
|
}
|
||||||
|
@ -1010,10 +1010,12 @@ namespace NLGUI
|
||||||
if (ptr) cond = (const char *) ptr;
|
if (ptr) cond = (const char *) ptr;
|
||||||
|
|
||||||
// create the link
|
// create the link
|
||||||
CInterfaceLink *il = new CInterfaceLink;
|
if( !editorMode )
|
||||||
il->init(targets, expr, action, params, cond, parentGroup); // init will add 'il' in the list of link present in 'elm'
|
{
|
||||||
|
CInterfaceLink *il = new CInterfaceLink;
|
||||||
if( editorMode )
|
il->init(targets, expr, action, params, cond, parentGroup); // init will add 'il' in the list of link present in 'elm'
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
SLinkData linkData;
|
SLinkData linkData;
|
||||||
linkData.parent = parentGroup->getId();
|
linkData.parent = parentGroup->getId();
|
||||||
|
@ -2459,6 +2461,8 @@ namespace NLGUI
|
||||||
void CInterfaceParser::removeAllLinks()
|
void CInterfaceParser::removeAllLinks()
|
||||||
{
|
{
|
||||||
_LinkMap.clear();
|
_LinkMap.clear();
|
||||||
|
links.clear();
|
||||||
|
linkId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
|
@ -2832,9 +2836,42 @@ namespace NLGUI
|
||||||
return true;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace GUIEditor
|
||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
setup();
|
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() ) );
|
connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,15 +37,10 @@ namespace GUIEditor
|
||||||
void LinkEditor::setup()
|
void LinkEditor::setup()
|
||||||
{
|
{
|
||||||
expressionEdit->clear();
|
expressionEdit->clear();
|
||||||
groupCB->setCheckable( true );
|
targetEdit->clear();
|
||||||
groupCB->setChecked( false );
|
|
||||||
groupCB->setDisabled( true );
|
|
||||||
ahCB->setCheckable( true );
|
|
||||||
ahCB->setChecked( false );
|
|
||||||
ahCB->setDisabled( true );
|
|
||||||
ahEdit->clear();
|
ahEdit->clear();
|
||||||
ahParamEdit->clear();
|
ahParamEdit->clear();
|
||||||
ahParamEdit->setDisabled( true );
|
condEdit->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinkEditor::setLinkId( uint32 linkId )
|
void LinkEditor::setLinkId( uint32 linkId )
|
||||||
|
@ -53,30 +48,34 @@ namespace GUIEditor
|
||||||
setup();
|
setup();
|
||||||
currentLinkId = linkId;
|
currentLinkId = linkId;
|
||||||
|
|
||||||
const std::map< uint32, SLinkData > &linkMap =
|
IParser *parser = CWidgetManager::getInstance()->getParser();
|
||||||
CWidgetManager::getInstance()->getParser()->getLinkMap();
|
SLinkData data;
|
||||||
|
|
||||||
std::map< uint32, SLinkData >::const_iterator itr =
|
if( !parser->getLinkData( currentLinkId, data ) )
|
||||||
linkMap.find( currentLinkId );
|
|
||||||
|
|
||||||
if( itr == linkMap.end() )
|
|
||||||
return;
|
return;
|
||||||
SLinkData data = itr->second;
|
|
||||||
|
|
||||||
expressionEdit->setPlainText( data.expr.c_str() );
|
expressionEdit->setPlainText( data.expr.c_str() );
|
||||||
if( !data.target.empty() )
|
targetEdit->setText( data.target.c_str() );
|
||||||
{
|
ahEdit->setText( data.action.c_str() );
|
||||||
groupCB->setEnabled( true );
|
ahParamEdit->setText( data.params.c_str() );
|
||||||
groupCB->setChecked( true );
|
condEdit->setText( data.cond.c_str() );
|
||||||
ahEdit->setText( data.target.c_str() );
|
}
|
||||||
}
|
|
||||||
else
|
void LinkEditor::onOKButtonClicked()
|
||||||
{
|
{
|
||||||
ahCB->setEnabled( true );
|
IParser *parser = CWidgetManager::getInstance()->getParser();
|
||||||
ahCB->setChecked( true );
|
SLinkData data;
|
||||||
ahEdit->setText( data.action.c_str() );
|
|
||||||
ahParamEdit->setEnabled( true );
|
if( !parser->getLinkData( currentLinkId, data ) )
|
||||||
ahParamEdit->setText( data.params.c_str() );
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,9 @@ namespace GUIEditor
|
||||||
void setup();
|
void setup();
|
||||||
void setLinkId( uint32 linkId );
|
void setLinkId( uint32 linkId );
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onOKButtonClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 currentLinkId;
|
uint32 currentLinkId;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,14 +9,14 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>545</width>
|
<width>540</width>
|
||||||
<height>348</height>
|
<height>430</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Link Editor</string>
|
<string>Link Editor</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -27,46 +27,63 @@
|
||||||
<item row="1" column="0" colspan="3">
|
<item row="1" column="0" colspan="3">
|
||||||
<widget class="QPlainTextEdit" name="expressionEdit">
|
<widget class="QPlainTextEdit" name="expressionEdit">
|
||||||
<property name="plainText">
|
<property name="plainText">
|
||||||
<string>expression</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0" colspan="3">
|
||||||
<widget class="QLabel" name="label_2">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="text">
|
<item row="0" column="0">
|
||||||
<string>When the expression is evaluated</string>
|
<widget class="QLabel" name="label_2">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<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="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Condition</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QLineEdit" name="ahParamEdit">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QRadioButton" name="groupCB">
|
|
||||||
<property name="text">
|
|
||||||
<string>Pass result to targeted group(s)</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">
|
|
||||||
<widget class="QLineEdit" name="ahParamEdit">
|
|
||||||
<property name="text">
|
|
||||||
<string>Action Handler parameters</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="7" column="0">
|
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
|
@ -79,14 +96,14 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QPushButton" name="okButton">
|
<widget class="QPushButton" name="okButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>OK</string>
|
<string>OK</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="2">
|
<item row="3" column="2">
|
||||||
<widget class="QPushButton" name="cancelButton">
|
<widget class="QPushButton" name="cancelButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Cancel</string>
|
<string>Cancel</string>
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#include "link_list.h"
|
#include "link_list.h"
|
||||||
#include "link_editor.h"
|
#include "link_editor.h"
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QInputDialog>
|
||||||
#include "nel/gui/interface_group.h"
|
#include "nel/gui/interface_group.h"
|
||||||
#include "nel/gui/widget_manager.h"
|
#include "nel/gui/widget_manager.h"
|
||||||
#include "nel/gui/link_data.h"
|
#include "nel/gui/link_data.h"
|
||||||
|
@ -33,7 +35,12 @@ namespace GUIEditor
|
||||||
linkEditor = new LinkEditor();
|
linkEditor = new LinkEditor();
|
||||||
|
|
||||||
connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) );
|
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( editButton, SIGNAL( clicked( bool ) ), this, SLOT( onEditButtonClicked() ) );
|
||||||
|
|
||||||
|
connect( linkTree, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ),
|
||||||
|
this, SLOT( onItemDblClicked( QTreeWidgetItem* ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkList::~LinkList()
|
LinkList::~LinkList()
|
||||||
|
@ -59,6 +66,63 @@ namespace GUIEditor
|
||||||
linkTree->sortByColumn( 0 );
|
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()
|
void LinkList::onEditButtonClicked()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -75,5 +139,16 @@ namespace GUIEditor
|
||||||
linkEditor->setLinkId( id );
|
linkEditor->setLinkId( id );
|
||||||
linkEditor->show();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,10 @@ namespace GUIEditor
|
||||||
void onGUILoaded();
|
void onGUILoaded();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
void onAddButtonClicked();
|
||||||
|
void onRemoveButtonClicked();
|
||||||
void onEditButtonClicked();
|
void onEditButtonClicked();
|
||||||
|
void onItemDblClicked( QTreeWidgetItem *item );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LinkEditor *linkEditor;
|
LinkEditor *linkEditor;
|
||||||
|
|
Loading…
Reference in a new issue