A little refactoring.

This commit is contained in:
dfighter1985 2014-09-14 16:43:45 +02:00
parent 892ca16ae3
commit eb70ac6199
4 changed files with 21 additions and 23 deletions

View file

@ -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() void ExpressionEditor::onAddNode1()
{ {
QGraphicsItem *item = new ExpressionNode( 1 ); addNode( 1 );
item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable );
m_scene->addItem( item );
} }
void ExpressionEditor::onAddNode2() void ExpressionEditor::onAddNode2()
{ {
QGraphicsItem *item = new ExpressionNode( 2 ); addNode( 2 );
item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable );
m_scene->addItem( item );
} }
void ExpressionEditor::onAddNode3() void ExpressionEditor::onAddNode3()
{ {
QGraphicsItem *item = new ExpressionNode( 3 ); addNode( 3 );
item->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable );
m_scene->addItem( item );
} }

View file

@ -39,6 +39,7 @@ private Q_SLOTS:
void onSelectionChanged(); void onSelectionChanged();
void onLinkItems(); void onLinkItems();
void onUnLinkItems(); void onUnLinkItems();
void addNode( int slotCount );
void onAddNode1(); void onAddNode1();
void onAddNode2(); void onAddNode2();
void onAddNode3(); void onAddNode3();

View file

@ -97,19 +97,13 @@ private:
ExpressionNode::ExpressionNode( int nodes, QGraphicsItem *parent ) : ExpressionNode::ExpressionNode( int slotCount, QGraphicsItem *parent ) :
QGraphicsItem( parent ) QGraphicsItem( parent )
{ {
m_w = 100; m_w = 100;
m_h = 100; m_h = 100;
// Out nodes createSlots( slotCount );
m_links.push_back( NULL );
for( int i = 0; i < nodes; i++ )
m_links.push_back( NULL );
createSlots();
} }
ExpressionNode::~ExpressionNode() ExpressionNode::~ExpressionNode()
@ -223,9 +217,13 @@ void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e )
QGraphicsItem::mouseMoveEvent( 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 // First create the "Out" slot
NodeSlotInfo info; NodeSlotInfo info;
@ -243,10 +241,9 @@ void ExpressionNode::createSlots()
info.text = "Out"; info.text = "Out";
m_slots.push_back( new NodeSlot( info ) ); m_slots.push_back( new NodeSlot( info ) );
nodes--;
// Then the rest of them // Then the rest of them
for( int i = 0; i < nodes; i++ ) for( int i = 0; i < count; i++ )
{ {
x = m_w - info.wh; x = m_w - info.wh;
y = 30 + i * 20.0; y = 30 + i * 20.0;

View file

@ -30,7 +30,7 @@ class NodeSlot;
class ExpressionNode : public QGraphicsItem class ExpressionNode : public QGraphicsItem
{ {
public: public:
ExpressionNode( int nodes = 3, QGraphicsItem *parent = NULL ); ExpressionNode( int slotCount = 3, QGraphicsItem *parent = NULL );
~ExpressionNode(); ~ExpressionNode();
QRectF boundingRect() const; QRectF boundingRect() const;
@ -53,7 +53,7 @@ protected:
void mouseMoveEvent( QGraphicsSceneMouseEvent *e ); void mouseMoveEvent( QGraphicsSceneMouseEvent *e );
private: private:
void createSlots(); void createSlots( int count = 3 );
void paintSlots( QPainter *painter ); void paintSlots( QPainter *painter );
qreal m_w; qreal m_w;