Added unlinking support.

--HG--
branch : dfighter-tools
This commit is contained in:
dfighter1985 2014-09-14 15:36:41 +02:00
parent 875cad3f72
commit aa67011381
4 changed files with 22 additions and 1 deletions

View file

@ -65,6 +65,9 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
a = menu.addAction( "Link" ); a = menu.addAction( "Link" );
connect( a, SIGNAL( triggered() ), this, SLOT( onLinkItems() ) ); connect( a, SIGNAL( triggered() ), this, SLOT( onLinkItems() ) );
} }
a = menu.addAction( "Unlink" );
connect( a, SIGNAL( triggered() ), this, SLOT( onUnLinkItems() ) );
} }
menu.exec( e->globalPos() ); menu.exec( e->globalPos() );
@ -150,4 +153,18 @@ void ExpressionEditor::onLinkItems()
m_scene->addItem( link ); m_scene->addItem( link );
} }
void ExpressionEditor::onUnLinkItems()
{
QList< QGraphicsItem* > l = m_scene->selectedItems();
for( int i = 0; i < l.count(); i++ )
{
ExpressionNode *node = dynamic_cast< ExpressionNode* >( l[ i ] );
if( node == NULL )
continue;
node->clearLinks();
}
}

View file

@ -39,6 +39,7 @@ private Q_SLOTS:
void onDeleteSelection(); void onDeleteSelection();
void onSelectionChanged(); void onSelectionChanged();
void onLinkItems(); void onLinkItems();
void onUnLinkItems();
private: private:

View file

@ -58,6 +58,8 @@ void ExpressionLink::unlink()
m_from = NULL; m_from = NULL;
m_to = NULL; m_to = NULL;
delete this;
} }
void ExpressionLink::nodeMoved() void ExpressionLink::nodeMoved()

View file

@ -47,13 +47,14 @@ public:
void getSlots( QList< SlotInfo > &l ); void getSlots( QList< SlotInfo > &l );
void clearLinks();
protected: protected:
void mouseMoveEvent( QGraphicsSceneMouseEvent *e ); void mouseMoveEvent( QGraphicsSceneMouseEvent *e );
private: private:
void createSlots(); void createSlots();
void paintSlots( QPainter *painter ); void paintSlots( QPainter *painter );
void clearLinks();
qreal m_w; qreal m_w;
qreal m_h; qreal m_h;