There are more than 1 slots available now.

--HG--
branch : dfighter-tools
This commit is contained in:
dfighter1985 2014-09-13 23:54:25 +02:00
parent 275095107b
commit 2e6a5bb1d6
5 changed files with 50 additions and 21 deletions

View file

@ -87,7 +87,12 @@ void ExpressionEditor::onDeleteSelection()
ExpressionNode *node = dynamic_cast< ExpressionNode* >( item ); ExpressionNode *node = dynamic_cast< ExpressionNode* >( item );
if( node != NULL ) if( node != NULL )
{ {
ExpressionLink *link = node->link(); ExpressionLink *link = NULL;
int c = node->slotCount();
for( int i = 0; i < c; i++ )
{
link = node->link( i );
if( link != NULL ) if( link != NULL )
{ {
link->unlink(); link->unlink();
@ -95,6 +100,7 @@ void ExpressionEditor::onDeleteSelection()
delete link; delete link;
} }
} }
}
m_scene->removeItem( item ); m_scene->removeItem( item );
delete item; delete item;
@ -113,7 +119,7 @@ void ExpressionEditor::onLinkItems()
ExpressionNode *from = static_cast< ExpressionNode* >( l[ 0 ] ); ExpressionNode *from = static_cast< ExpressionNode* >( l[ 0 ] );
ExpressionNode *to = static_cast< ExpressionNode* >( l[ 1 ] ); ExpressionNode *to = static_cast< ExpressionNode* >( l[ 1 ] );
if( ( from->link() != NULL ) || ( to->link() != NULL ) ) if( ( from->link( 0 ) != NULL ) || ( to->link( 0 ) != NULL ) )
{ {
QMessageBox::information( this, QMessageBox::information( this,
tr( "Failed to link nodes" ), tr( "Failed to link nodes" ),
@ -122,7 +128,7 @@ void ExpressionEditor::onLinkItems()
} }
ExpressionLink *link = new ExpressionLink(); ExpressionLink *link = new ExpressionLink();
link->link( from, to ); link->link( from, to, 0, 0 );
m_scene->addItem( link ); m_scene->addItem( link );
} }

View file

@ -35,20 +35,23 @@ ExpressionLink::~ExpressionLink()
unlink(); unlink();
} }
void ExpressionLink::link( ExpressionNode *from, ExpressionNode *to ) void ExpressionLink::link( ExpressionNode *from, ExpressionNode *to, int fromSlot, int toSlot )
{ {
m_from = from; m_from = from;
m_to = to; m_to = to;
m_from->setLink( this ); m_from->setLink( this, fromSlot );
m_to->setLink( this ); m_to->setLink( this, toSlot );
m_fromSlot = fromSlot;
m_toSlot = toSlot;
nodeMoved(); nodeMoved();
} }
void ExpressionLink::unlink() void ExpressionLink::unlink()
{ {
m_from->setLink( NULL ); m_from->setLink( NULL, m_fromSlot );
m_to->setLink( NULL ); m_to->setLink( NULL, m_toSlot );
} }
void ExpressionLink::nodeMoved() void ExpressionLink::nodeMoved()

View file

@ -29,7 +29,7 @@ public:
ExpressionLink( QGraphicsItem *parent = NULL ); ExpressionLink( QGraphicsItem *parent = NULL );
~ExpressionLink(); ~ExpressionLink();
void link( ExpressionNode *from, ExpressionNode *to ); void link( ExpressionNode *from, ExpressionNode *to, int fromSlot, int toSlot );
void unlink(); void unlink();
void nodeMoved(); void nodeMoved();
@ -40,6 +40,8 @@ private:
ExpressionNode *m_from; ExpressionNode *m_from;
ExpressionNode *m_to; ExpressionNode *m_to;
int m_fromSlot;
int m_toSlot;
}; };
#endif #endif

View file

@ -98,12 +98,13 @@ private:
ExpressionNode::ExpressionNode( QGraphicsItem *parent ) : ExpressionNode::ExpressionNode( QGraphicsItem *parent ) :
QGraphicsItem( parent ) QGraphicsItem( parent )
{ {
m_link = NULL;
m_w = 100; m_w = 100;
m_h = 100; m_h = 100;
createSlots(); createSlots();
for( int i = 0; i < 4; i++ )
m_links.push_back( NULL );
} }
ExpressionNode::~ExpressionNode() ExpressionNode::~ExpressionNode()
@ -168,10 +169,26 @@ QPointF ExpressionNode::slotPos( int slot ) const
return mp; return mp;
} }
void ExpressionNode::setLink( ExpressionLink *link, int slot )
{
m_links[ slot ] = link;
}
ExpressionLink* ExpressionNode::link( int slot ) const
{
return m_links[ slot ];
}
void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e ) void ExpressionNode::mouseMoveEvent( QGraphicsSceneMouseEvent *e )
{ {
if( m_link != NULL ) for( int i = 0; i < 4; i++ )
m_link->nodeMoved(); {
ExpressionLink *link = m_links[ i ];
if( link == NULL )
continue;
link->nodeMoved();
}
QGraphicsItem::mouseMoveEvent( e ); QGraphicsItem::mouseMoveEvent( e );
} }

View file

@ -35,11 +35,13 @@ public:
QRectF boundingRect() const; QRectF boundingRect() const;
void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ); void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
void setLink( ExpressionLink *link ){ m_link = link; } void setLink( ExpressionLink *link, int slot );
ExpressionLink* link() const{ return m_link; } ExpressionLink* link( int slot ) const;
QPointF slotPos( int slot ) const; QPointF slotPos( int slot ) const;
int slotCount() const{ return m_slots.count(); }
protected: protected:
void mouseMoveEvent( QGraphicsSceneMouseEvent *e ); void mouseMoveEvent( QGraphicsSceneMouseEvent *e );
@ -47,12 +49,11 @@ private:
void createSlots(); void createSlots();
void paintSlots( QPainter *painter ); void paintSlots( QPainter *painter );
ExpressionLink *m_link;
qreal m_w; qreal m_w;
qreal m_h; qreal m_h;
QList< NodeSlot* > m_slots; QList< NodeSlot* > m_slots;
QList< ExpressionLink* > m_links;
}; };
#endif #endif