From 89aaa52703e2b4dc804b67ca345e96e90d7b6f3a Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 16 Sep 2014 03:38:21 +0200 Subject: [PATCH] Set the number of slots and their names from the data loaded from XMLs. --HG-- branch : dfighter-tools --- .../plugins/gui_editor/expression_editor.cpp | 34 +++++-------------- .../plugins/gui_editor/expression_editor.h | 5 +-- .../plugins/gui_editor/expression_node.cpp | 11 ++++++ .../src/plugins/gui_editor/expression_node.h | 2 ++ 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index 773191afc..81bd22373 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -205,37 +205,21 @@ void ExpressionEditor::onUnLinkItems() } } -void ExpressionEditor::addNode( const QString &name, int slotCount ) +void ExpressionEditor::onItemDblClicked( QTreeWidgetItem *item ) { + QString name = item->text( 0 ); + + const ExpressionInfo *info = m_pvt->store.getInfo( name ); + QString n = name; n += " #"; n += QString::number( m_nodeCount ); m_nodeCount++; - QGraphicsItem *item = new ExpressionNode( n, slotCount ); - item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); - m_scene->addItem( item ); -} - -void ExpressionEditor::onAddNode1() -{ - addNode( "node", 1 ); -} - -void ExpressionEditor::onAddNode2() -{ - addNode( "node", 2 ); -} - -void ExpressionEditor::onAddNode3() -{ - addNode( "node", 3 ); -} - -void ExpressionEditor::onItemDblClicked( QTreeWidgetItem *item ) -{ - QString name = item->text( 0 ); - addNode( name, 3 ); + ExpressionNode *node = new ExpressionNode( n, info->slotNames.count() ); + node->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); + node->setSlotNames( info->slotNames ); + m_scene->addItem( node ); } void ExpressionEditor::onChangeSlotCount() diff --git a/code/studio/src/plugins/gui_editor/expression_editor.h b/code/studio/src/plugins/gui_editor/expression_editor.h index 21f247249..79ff908f1 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.h +++ b/code/studio/src/plugins/gui_editor/expression_editor.h @@ -23,6 +23,7 @@ #include "ui_expression_editor.h" class QGraphicsScene; +class QGraphicsItem; class ExpressionEditorPvt; class ExpressionInfo; @@ -43,10 +44,6 @@ private Q_SLOTS: void onSelectionChanged(); void onLinkItems(); void onUnLinkItems(); - void addNode( const QString &name, int slotCount ); - void onAddNode1(); - void onAddNode2(); - void onAddNode3(); void onItemDblClicked( QTreeWidgetItem *item ); void onChangeSlotCount(); diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp index 026857ee3..bb2eb451f 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.cpp +++ b/code/studio/src/plugins/gui_editor/expression_node.cpp @@ -90,6 +90,7 @@ public: } QString text() const{ return m_info.text; } + void setText( const QString &text ){ m_info.text = text; } private: NodeSlotInfo m_info; @@ -229,6 +230,16 @@ ExpressionLink* ExpressionNode::link( int slot ) const return m_links[ slot ]; } +void ExpressionNode::setSlotNames( const QList< QString > &l ) +{ + int c = l.count(); + for( int i = 0; i < c; i++ ) + { + // "Out" slot is at position 0, so set the names with an offset of 1 + m_slots[ i + 1 ]->setText( l[ i ] ); + } +} + void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e ) { for( int i = 0; i < m_links.count(); i++ ) diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h index cf49c212f..e43e717bb 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.h +++ b/code/studio/src/plugins/gui_editor/expression_node.h @@ -53,6 +53,8 @@ public: QString name() const{ return m_name; } + void setSlotNames( const QList< QString > &l ); + protected: void mouseMoveEvent( QGraphicsSceneMouseEvent *e );