Slot count can now be changed.

This commit is contained in:
dfighter1985 2014-09-15 01:25:01 +02:00
parent 79e205c6d8
commit 8314fd5c6b
4 changed files with 51 additions and 3 deletions

View file

@ -28,6 +28,7 @@
#include "expr_link_dlg.h"
#include <QMessageBox>
#include <QInputDialog>
ExpressionEditor::ExpressionEditor( QWidget *parent ) :
QMainWindow( parent )
@ -70,6 +71,12 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e )
a = menu.addAction( "Remove" );
connect( a, SIGNAL( triggered() ), this, SLOT( onDeleteSelection() ) );
if( m_selectionCount == 1 )
{
a = menu.addAction( "Change slot count" );
connect( a, SIGNAL( triggered() ), this, SLOT( onChangeSlotCount() ) );
}
else
if( m_selectionCount == 2 )
{
a = menu.addAction( "Link" );
@ -203,4 +210,22 @@ void ExpressionEditor::onItemDblClicked( QTreeWidgetItem *item )
addNode( name, 3 );
}
void ExpressionEditor::onChangeSlotCount()
{
QList< QGraphicsItem* > l = m_scene->selectedItems();
ExpressionNode *node = static_cast< ExpressionNode* >( l[ 0 ] );
int oldc = node->slotCount();
int c = QInputDialog::getInt( this,
tr( "Change slot count" ),
tr( "Enter new slot count" ),
oldc,
1,
26 );
if( oldc == c )
return;
node->changeSlotCount( c );
}

View file

@ -44,6 +44,7 @@ private Q_SLOTS:
void onAddNode2();
void onAddNode3();
void onItemDblClicked( QTreeWidgetItem *item );
void onChangeSlotCount();
private:

View file

@ -115,9 +115,7 @@ QGraphicsItem( parent )
ExpressionNode::~ExpressionNode()
{
clearLinks();
qDeleteAll( m_slots );
m_slots.clear();
clearSlots();
}
QRectF ExpressionNode::boundingRect() const
@ -176,6 +174,28 @@ QPointF ExpressionNode::slotPos( int slot ) const
return mp;
}
void ExpressionNode::changeSlotCount( int count )
{
clearSlots();
clearLinks();
m_links.clear();
if( count <= 3 )
m_h = 100.0;
else
m_h = 100.0 + 20.0 * ( count - 3 );
createSlots( count );
update();
}
void ExpressionNode::clearSlots()
{
qDeleteAll( m_slots );
m_slots.clear();
}
bool ExpressionNode::slotEmpty( int slot ) const
{
if( m_links[ 0 ] == NULL )

View file

@ -42,6 +42,8 @@ public:
QPointF slotPos( int slot ) const;
int slotCount() const{ return m_slots.count(); }
void changeSlotCount( int count );
void clearSlots();
bool slotEmpty( int slot ) const;