#include "SUPERVGUI_ManagePortsDlg.h"
#include "SUPERVGUI_CanvasNode.h"
#include "SUPERVGUI_CanvasPort.h"
+#include "SUPERVGUI_CanvasControlNode.h"
#include "SUPERVGUI.h"
#include <qlayout.h>
{
myNode = theNode;
myLastItem = 0;
- myFromItemChanged = false;
init();
}
connect( myTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(typeChanged(const QString&)));
myNode->getMain()->lockedGraph( true );
+
+ // asv : 11.01.05 : if a node is a loop node, then only INPUT ports can be added/removed
+ if ( myNode->getNodeType() == SUPERV::LoopNode ) {
+ myOutList->setEnabled( false );
+ anAddOutputBtn->setEnabled( false );
+ aDeleteOutputBtn->setEnabled( false );
+ anUpOutputBtn->setEnabled( false );
+ aDownOutputBtn->setEnabled( false );
+ }
+
}
/**
SUPERV_INode aINode = myNode->getInlineNode();
if ( !SUPERV_isNull( aINode ) ) {
int i;
+ const bool isLoop = ( myNode->getNodeType() == SUPERV::LoopNode );
// 1.1 delete all ports (delete CanvasPorts, they delete SUPERV_Ports)
QObjectList* oldPorts = myNode->queryList("SUPERVGUI_CanvasPort");
QObjectListIt it( *oldPorts ); // iterate over the old ports
QObject *obj;
+ // asv : 11.01.05 : fix for a bug: for Loop node, removal of an Input Port
+ // automatically removes the corresponding Output Port. So for Loops the
+ // oldPorts list should be filtered to include only Input Ports.
+ // But I'll filter Gate-s as well..
+ QObjectList portsToRemove;
while ( (obj = it.current()) != 0 ) {
++it;
- if ( !((SUPERVGUI_CanvasPort*)obj)->getEngine()->IsGate() ) // never do anything with Gate ports
- ((SUPERVGUI_CanvasPort*)obj)->remove();
+ SUPERV::Port_var aPort = ((SUPERVGUI_CanvasPort*)obj)->getEngine();
+ if ( !aPort->IsGate() && ( !isLoop || aPort->IsInput() ) )
+ portsToRemove.append( obj );
}
delete oldPorts; // delete the list, not the objects
+
+ // portsToRemove list contains:
+ // for Loop node: all INPUT ports except Gates
+ // for other Inline: all INPUT and OUTPUT ports except Gates
+ it = QObjectListIt( portsToRemove );
+ while ( (obj = it.current()) != 0 ) {
+ ++it;
+ ((SUPERVGUI_CanvasPort*)obj)->remove();
+ }
// 1.2 create new ports in INode and CanvasPort in myNode
PortListItem* item;
item = (PortListItem*)myInList->item( i );
aPort = aINode->InPort( item->PortName.latin1(), item->PortType.latin1() );
myNode->createPort( aPort.in() );
+ // asv : 11.01.05 : for Loop nodes do the same as in SUPERVGUI_CanvasStartNode::addInputPort()
+ if ( isLoop ) {
+ SUPERVGUI_CanvasStartNode* aStartLoopNode = (SUPERVGUI_CanvasStartNode*)myNode;
+ aStartLoopNode->merge();
+ aStartLoopNode->getCoupled()->merge();
+ }
}
- for ( i = 0; i < myOutList->count(); i++ ) {
+ // creating Out-ports, except LoopNode-s
+ for ( i = 0; i < myOutList->count() && !isLoop; i++ ) {
item = (PortListItem*)myOutList->item( i );
aPort = aINode->OutPort( item->PortName.latin1(), item->PortType.latin1() );
myNode->createPort( aPort.in() );
}
}
+/**
+ * called on 'X' button press - remove selected port item
+ */
void SUPERVGUI_ManagePortsDlg::removePort( QListBox* theLB ) {
if ( !theLB )
return;
delete theLB->item( i );
}
-void moveItem( QListBox* theLB, const int from, const int to ) {
+/**
+ * called on up/down key press - move the selected list box item from position 'from' to position 'to'
+ */
+void SUPERVGUI_ManagePortsDlg::moveItem( QListBox* theLB, const int from, const int to ) {
if ( !theLB )
return;
+
+ // disconnect itemChanged - it leads to crash if there was only 1 item left
+ disconnect( theLB, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(itemChanged(QListBoxItem*)));
+
if ( from >= 0 && from < theLB->count() && to >=0 && to < theLB->count() ) {
QListBoxItem* item = theLB->item( from );
theLB->takeItem( item );
theLB->setCurrentItem( item );
theLB->setSelected( item, true );
}
+
+ // connect back..
+ connect( theLB, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(itemChanged(QListBoxItem*)));
}
+/**
+ * move the selected item UP
+ */
void SUPERVGUI_ManagePortsDlg::moveUp( QListBox* theLB ) {
if ( !theLB )
return;
moveItem( theLB, i, i-1 );
}
+/**
+ * move the selected item DOWN
+ */
void SUPERVGUI_ManagePortsDlg::moveDown( QListBox* theLB ) {
if ( !theLB )
return;
* the last selected by user item in myInList or myOutList (myLastItem)
*/
void SUPERVGUI_ManagePortsDlg::nameChanged( const QString& name ) {
- if ( myFromItemChanged ) return;
if ( isEditingItem( myLastItem, myInList ) || isEditingItem( myLastItem, myOutList ) ) {
((PortListItem*)myLastItem)->PortName = name;
//myLastItem->listBox()->repaint( true );
* of the last selected by user item in myInList or myOutList (myLastItem)
*/
void SUPERVGUI_ManagePortsDlg::typeChanged( const QString& type ) {
- if ( myFromItemChanged ) return;
if ( isEditingItem( myLastItem, myInList ) || isEditingItem( myLastItem, myOutList ) ) {
((PortListItem*)myLastItem)->PortType = type;
//myLastItem->listBox()->repaint( true );
* called when new item became "currentItem" in any myInList or myOutList listboxes.
*/
void SUPERVGUI_ManagePortsDlg::itemChanged( QListBoxItem * item ) {
- myFromItemChanged = true; // to disable nameChanged, typeChanged callbacks
+ if ( !item ) // after remove, etc..
+ return;
+
+ // disable nameChanged, typeChanged callbacks
+ disconnect( myNameEdt, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)));
+ disconnect( myTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(typeChanged(const QString&)));
+
myLastItem = item;
myNameEdt->setText( ((PortListItem*)item)->PortName );
for ( int i = 0; i < myTypeCombo->count(); i++ )
myTypeCombo->setCurrentItem( i );
break;
}
- myFromItemChanged = false; // to enable nameChanged, typeChanged callbacks
+
+ // connect back nameChanged, typeChanged
+ connect( myNameEdt, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)));
+ connect( myTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(typeChanged(const QString&)));
}
/*!
* Port parameters dialog definition (taken from SUPERVGUI_Node.cxx without change)
*/
-
SUPERVGUI_PortParamsDlg::SUPERVGUI_PortParamsDlg(const QStringList& thePortsNames)
: QDialog(QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
myPortsNames( thePortsNames )