From eb70ac61990ac2016d8fc407b06e18b33963d7c2 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 14 Sep 2014 16:43:45 +0200 Subject: [PATCH] A little refactoring. --- .../plugins/gui_editor/expression_editor.cpp | 18 ++++++++-------- .../plugins/gui_editor/expression_editor.h | 1 + .../plugins/gui_editor/expression_node.cpp | 21 ++++++++----------- .../src/plugins/gui_editor/expression_node.h | 4 ++-- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index 14bf69600..c821ceb6d 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -167,25 +167,25 @@ void ExpressionEditor::onUnLinkItems() } } +void ExpressionEditor::addNode( int slotCount ) +{ + QGraphicsItem *item = new ExpressionNode( slotCount ); + item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); + m_scene->addItem( item ); +} void ExpressionEditor::onAddNode1() { - QGraphicsItem *item = new ExpressionNode( 1 ); - item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); - m_scene->addItem( item ); + addNode( 1 ); } void ExpressionEditor::onAddNode2() { - QGraphicsItem *item = new ExpressionNode( 2 ); - item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); - m_scene->addItem( item ); + addNode( 2 ); } void ExpressionEditor::onAddNode3() { - QGraphicsItem *item = new ExpressionNode( 3 ); - item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); - m_scene->addItem( item ); + addNode( 3 ); } diff --git a/code/studio/src/plugins/gui_editor/expression_editor.h b/code/studio/src/plugins/gui_editor/expression_editor.h index 2346f42cf..91bb5d851 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.h +++ b/code/studio/src/plugins/gui_editor/expression_editor.h @@ -39,6 +39,7 @@ private Q_SLOTS: void onSelectionChanged(); void onLinkItems(); void onUnLinkItems(); + void addNode( int slotCount ); void onAddNode1(); void onAddNode2(); void onAddNode3(); diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp index 049acfbb9..86469314a 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.cpp +++ b/code/studio/src/plugins/gui_editor/expression_node.cpp @@ -97,19 +97,13 @@ private: -ExpressionNode::ExpressionNode( int nodes, QGraphicsItem *parent ) : +ExpressionNode::ExpressionNode( int slotCount, QGraphicsItem *parent ) : QGraphicsItem( parent ) { m_w = 100; m_h = 100; - // Out nodes - m_links.push_back( NULL ); - - for( int i = 0; i < nodes; i++ ) - m_links.push_back( NULL ); - - createSlots(); + createSlots( slotCount ); } ExpressionNode::~ExpressionNode() @@ -223,10 +217,14 @@ void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e ) QGraphicsItem::mouseMoveEvent( e ); } -void ExpressionNode::createSlots() +void ExpressionNode::createSlots( int count) { - int nodes = m_links.count(); + // Out nodes + m_links.push_back( NULL ); + for( int i = 0; i < count; i++ ) + m_links.push_back( NULL ); + // First create the "Out" slot NodeSlotInfo info; info.tw = 25.0; @@ -243,10 +241,9 @@ void ExpressionNode::createSlots() info.text = "Out"; m_slots.push_back( new NodeSlot( info ) ); - nodes--; // Then the rest of them - for( int i = 0; i < nodes; i++ ) + for( int i = 0; i < count; i++ ) { x = m_w - info.wh; y = 30 + i * 20.0; diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h index efecea818..654329dd5 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.h +++ b/code/studio/src/plugins/gui_editor/expression_node.h @@ -30,7 +30,7 @@ class NodeSlot; class ExpressionNode : public QGraphicsItem { public: - ExpressionNode( int nodes = 3, QGraphicsItem *parent = NULL ); + ExpressionNode( int slotCount = 3, QGraphicsItem *parent = NULL ); ~ExpressionNode(); QRectF boundingRect() const; @@ -53,7 +53,7 @@ protected: void mouseMoveEvent( QGraphicsSceneMouseEvent *e ); private: - void createSlots(); + void createSlots( int count = 3 ); void paintSlots( QPainter *painter ); qreal m_w;