There are more than 1 slots available now.

This commit is contained in:
dfighter1985 2014-09-13 23:54:25 +02:00
parent 594443ce3b
commit dfe108cb82
5 changed files with 50 additions and 21 deletions

View file

@ -87,7 +87,12 @@ void ExpressionEditor::onDeleteSelection()
ExpressionNode *node = dynamic_cast< ExpressionNode* >( item );
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 )
{
link->unlink();
@ -95,6 +100,7 @@ void ExpressionEditor::onDeleteSelection()
delete link;
}
}
}
m_scene->removeItem( item );
delete item;
@ -113,7 +119,7 @@ void ExpressionEditor::onLinkItems()
ExpressionNode *from = static_cast< ExpressionNode* >( l[ 0 ] );
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,
tr( "Failed to link nodes" ),
@ -122,7 +128,7 @@ void ExpressionEditor::onLinkItems()
}
ExpressionLink *link = new ExpressionLink();
link->link( from, to );
link->link( from, to, 0, 0 );
m_scene->addItem( link );
}

View file

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

View file

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

View file

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

View file

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