1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SUPERVGUI_ManagePortsDlg.cxx
8 // Author : Alexander SLADKOV
11 #include "SUIT_Desktop.h"
12 #include "SUIT_Session.h"
14 #include "SUPERVGUI_ManagePortsDlg.h"
15 #include "SUPERVGUI_CanvasNode.h"
16 #include "SUPERVGUI_CanvasPort.h"
17 #include "SUPERVGUI_CanvasControlNode.h"
18 #include "SUPERVGUI_CanvasLink.h"
22 #include <qpushbutton.h>
24 #include <qgroupbox.h>
26 static const char* gTypes[] =
27 {"string", "boolean", "char", "short", "int", "long", "float", "double", "objref"};
29 static const char* const add_pix_data[] = {
35 "....................",
36 "....................",
37 "....................",
38 "....................",
39 "........##a.........",
40 "........##b.........",
41 "........##b.........",
42 "........##b.........",
43 "........##b.........",
44 "...############a....",
45 "...############b....",
46 "...abbbb##bbbbbb....",
47 "........##b.........",
48 "........##b.........",
49 "........##b.........",
50 "........##b.........",
51 "........abb.........",
52 "....................",
53 "....................",
54 "...................."};
56 static const char* const del_pix_data[] = {
78 static const char* const up_pix_data[] = {
102 static const char* const down_pix_data[] = {
130 SUPERVGUI_ManagePortsDlg::SUPERVGUI_ManagePortsDlg( SUPERVGUI_CanvasNode* theNode )
131 : QDialog( SUIT_Session::session()->activeApplication()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
138 void SUPERVGUI_ManagePortsDlg::init()
140 setName( "SUPERVGUI_ManagePortsDlg" );
142 SUPERV_CNode aCNode = myNode->getEngine();
143 setCaption( tr( "TIT_MANAGE_PORTS" ) + aCNode->Name() );
145 QGridLayout* aBaseLayout = new QGridLayout( this );
146 aBaseLayout->setMargin( 11 );
147 aBaseLayout->setSpacing( 6 );
149 // -- name and type upper line widgets --
150 QLabel* aNameLbl = new QLabel( tr( "NAME_LBL") , this );
151 myNameEdt = new QLineEdit( this );
152 QLabel* aTypeLbl = new QLabel( tr( "TYPE_LBL" ), this );
153 myTypeCombo = new QComboBox( false, this ); // input field not editable
155 aBaseLayout->addWidget( aNameLbl, 0, 0 );
156 aBaseLayout->addWidget( myNameEdt, 0, 1 );
157 aBaseLayout->addWidget( aTypeLbl, 0, 2 );
158 aBaseLayout->addWidget( myTypeCombo, 0, 3 );
159 aBaseLayout->setColStretch( 1, 1 );
160 aBaseLayout->setColStretch( 3, 1 );
162 // -- common Input/Output variables --
163 QPixmap adPix( (const char**) add_pix_data );
164 QPixmap rmPix( (const char**) del_pix_data );
165 QPixmap upPix( (const char**) up_pix_data );
166 QPixmap dnPix( (const char**) down_pix_data );
168 // -- Input ports group box --
169 QGroupBox* anInputGr = new QGroupBox( 1, Qt::Vertical, tr( "INPUT" ), this );
170 anInputGr->layout()->setSpacing( 6 );
171 anInputGr->layout()->setMargin( 11 );
173 myInList = new QListBox( anInputGr );
174 myInList->setSelectionMode( QListBox::Single );
176 QGroupBox* anInputBtnGr = new QGroupBox( 0, Qt::Vertical, anInputGr );
177 anInputBtnGr->setFrameStyle( QFrame::NoFrame );
178 anInputBtnGr->layout()->setSpacing( 0 );
179 anInputBtnGr->layout()->setMargin( 0 );
181 QVBoxLayout* anInputBtnLay = new QVBoxLayout( anInputBtnGr->layout() );
182 anInputBtnLay->layout()->setSpacing( 6 );
183 anInputBtnLay->layout()->setMargin( 0 );
185 QPushButton* anAddInputBtn = new QPushButton( anInputBtnGr );
186 anAddInputBtn->setPixmap( adPix );
187 QPushButton* aDeleteInputBtn = new QPushButton( anInputBtnGr );
188 aDeleteInputBtn->setPixmap( rmPix );
189 QPushButton* anUpInputBtn = new QPushButton( anInputBtnGr );
190 anUpInputBtn->setPixmap( upPix );
191 QPushButton* aDownInputBtn = new QPushButton( anInputBtnGr );
192 aDownInputBtn->setPixmap( dnPix );
194 connect( anAddInputBtn, SIGNAL( clicked() ), this, SLOT( addInput() ) );
195 connect( aDeleteInputBtn, SIGNAL( clicked() ), this, SLOT( removeInput() ) );
196 connect( anUpInputBtn, SIGNAL( clicked() ), this, SLOT( upInput() ) );
197 connect( aDownInputBtn, SIGNAL( clicked() ), this, SLOT( downInput() ) );
199 anInputBtnLay->addWidget( anAddInputBtn );
200 anInputBtnLay->addWidget( aDeleteInputBtn );
201 anInputBtnLay->addItem( new QSpacerItem( 1, 16, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding ) );
202 anInputBtnLay->addWidget( anUpInputBtn );
203 anInputBtnLay->addWidget( aDownInputBtn );
204 anInputBtnLay->addItem( new QSpacerItem( 1, 16, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding ) );
206 aBaseLayout->addMultiCellWidget( anInputGr, 1, 1, 0, 1 );
208 // -- Output ports group box --
209 QGroupBox* anOutputGr = new QGroupBox( 1, Qt::Vertical, tr( "OUTPUT" ), this );
210 anOutputGr->layout()->setSpacing( 6 );
211 anOutputGr->layout()->setMargin( 11 );
213 myOutList = new QListBox( anOutputGr );
214 myOutList->setSelectionMode( QListBox::Single );
216 QGroupBox* anOutputBtnGr = new QGroupBox( 0, Qt::Vertical, anOutputGr );
217 anOutputBtnGr->setFrameStyle( QFrame::NoFrame );
218 anOutputBtnGr->layout()->setSpacing( 0 );
219 anOutputBtnGr->layout()->setMargin( 0 );
221 QVBoxLayout* anOutputBtnLay = new QVBoxLayout( anOutputBtnGr->layout() );
222 anOutputBtnLay->layout()->setSpacing( 6 );
223 anOutputBtnLay->layout()->setMargin( 0 );
225 QPushButton* anAddOutputBtn = new QPushButton( anOutputBtnGr );
226 anAddOutputBtn->setPixmap( adPix );
227 QPushButton* aDeleteOutputBtn = new QPushButton( anOutputBtnGr );
228 aDeleteOutputBtn->setPixmap( rmPix );
229 QPushButton* anUpOutputBtn = new QPushButton( anOutputBtnGr );
230 anUpOutputBtn->setPixmap( upPix );
231 QPushButton* aDownOutputBtn = new QPushButton( anOutputBtnGr );
232 aDownOutputBtn->setPixmap( dnPix );
234 connect( anAddOutputBtn, SIGNAL( clicked() ), this, SLOT( addOutput() ) );
235 connect( aDeleteOutputBtn, SIGNAL( clicked() ), this, SLOT( removeOutput() ) );
236 connect( anUpOutputBtn, SIGNAL( clicked() ), this, SLOT( upOutput() ) );
237 connect( aDownOutputBtn, SIGNAL( clicked() ), this, SLOT( downOutput() ) );
239 anOutputBtnLay->addWidget( anAddOutputBtn );
240 anOutputBtnLay->addWidget( aDeleteOutputBtn );
241 anOutputBtnLay->addItem( new QSpacerItem( 1, 16, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding ) );
242 anOutputBtnLay->addWidget( anUpOutputBtn );
243 anOutputBtnLay->addWidget( aDownOutputBtn );
244 anOutputBtnLay->addItem( new QSpacerItem( 1, 16, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding ) );
246 aBaseLayout->addMultiCellWidget( anOutputGr, 1, 1, 2, 3 );
248 // -- Ok / Cancel buttons line at the bottom of dialog --
249 QGroupBox* aBtnBox = new QGroupBox( this );
250 aBtnBox->setColumnLayout( 0, Qt::Vertical );
251 aBtnBox->layout()->setSpacing( 0 );
252 aBtnBox->layout()->setMargin( 0 );
254 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
255 aBtnLayout->setAlignment( Qt::AlignTop );
256 aBtnLayout->setSpacing( 6 );
257 aBtnLayout->setMargin( 11 );
259 QPushButton* aOkBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
260 QPushButton* aCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), aBtnBox );
261 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
262 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
264 aBtnLayout->addWidget( aOkBtn );
265 aBtnLayout->addStretch();
266 aBtnLayout->addWidget( aCancelBtn );
268 aBaseLayout->addMultiCellWidget( aBtnBox, 2, 2, 0, 3 );
271 connect( myInList,SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(itemChanged(QListBoxItem*)));
272 connect( myOutList, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(itemChanged(QListBoxItem*)));
273 connect( myNameEdt, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)));
274 connect( myTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(typeChanged(const QString&)));
276 myNode->getMain()->lockedGraph( true );
278 // asv : 11.01.05 : if a node is a loop node, then only INPUT ports can be added/removed
279 if ( myNode->getNodeType() == SUPERV::LoopNode ) {
280 myOutList->setEnabled( false );
281 anAddOutputBtn->setEnabled( false );
282 aDeleteOutputBtn->setEnabled( false );
283 anUpOutputBtn->setEnabled( false );
284 aDownOutputBtn->setEnabled( false );
292 SUPERVGUI_ManagePortsDlg::~SUPERVGUI_ManagePortsDlg() {
296 void SUPERVGUI_ManagePortsDlg::createLinkEngine( SUPERV::Port_ptr thePort,
297 QValueList< QPair< QString,QString > >& theOwnList,
298 QValueList< QPair< QString,QString > >& theCorrespList ) {
299 // pair <NodeName, PortName> for the given port
300 QPair<QString, QString> anOwnPair(QString(thePort->Node()->Name()), QString(thePort->Name()));
301 int aNum = theOwnList.contains(anOwnPair);
303 int anId = theOwnList.findIndex(anOwnPair); // get index in theOwnList
304 QPair<QString, QString> aCorrespPair = theCorrespList[anId]; // corresponding pair in theCorrespList
306 theOwnList.remove(theOwnList.at(anId));
307 theCorrespList.remove(theCorrespList.at(anId));
309 SUPERV_Port aCorrespPort = myNode->getMain()->getDataflow()->Node(aCorrespPair.first)->Port(aCorrespPair.second);
310 SUPERV_Link aLinkEngine;
311 if ( thePort->IsInput() )
312 aLinkEngine = myNode->getMain()->getDataflow()->Link(aCorrespPort, thePort);
314 aLinkEngine = myNode->getMain()->getDataflow()->Link(thePort, aCorrespPort);
315 SUPERVGUI_CanvasLink* aLink = new SUPERVGUI_CanvasLink(myNode->getMain()->getCanvas(), myNode->getMain(), aLinkEngine);
323 * Set the ports as entered by user (order, name/type, etc.) and close the dialog
325 void SUPERVGUI_ManagePortsDlg::accept() {
326 myNode->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
327 // 1. set the ports to Engine's CNode
328 SUPERV_INode aINode = myNode->getInlineNode();
329 if ( !SUPERV_isNull( aINode ) ) {
331 const bool isLoop = ( myNode->getNodeType() == SUPERV::LoopNode );
333 // 1.1 delete all ports (delete CanvasPorts, they delete SUPERV_Ports)
334 QObjectList* oldPorts = myNode->queryList("SUPERVGUI_CanvasPort");
335 QObjectListIt it( *oldPorts ); // iterate over the old ports
338 // asv : 11.01.05 : fix for a bug: for Loop node, removal of an Input Port
339 // automatically removes the corresponding Output Port. So for Loops the
340 // oldPorts list should be filtered to include only Input Ports.
341 // But I'll filter Gate-s as well..
342 bool isAnyLinked = false; // check if any port from old ports is linked
343 // map PortName <-> (PortType, PortInputValue) for non linked input ports, which have input
344 QMap< QString, QPair< QString,QString > > InNameInput;
345 QObjectList portsToRemove;
346 while ( (obj = it.current()) != 0 ) {
348 SUPERV::Port_var aPort = ((SUPERVGUI_CanvasPort*)obj)->getEngine();
349 if ( !aPort->IsGate() && ( !isLoop || aPort->IsInput() ) ) {
350 portsToRemove.append( obj );
352 // check if port has a link (output porst of Loop node are also checked)
353 if ( !aPort->IsGate() && aPort->IsLinked() && !isAnyLinked)
355 // check if input port has an input value
356 if ( !aPort->IsGate() && aPort->IsInput() && aPort->HasInput() )
357 InNameInput.insert( QString(aPort->Name()),
358 QPair<QString, QString>(QString(aPort->Type()),QString(aPort->ToString())) );
360 delete oldPorts; // delete the list, not the objects
363 QString aNodeName = myNode->getEngine()->Name();
364 QValueList< QPair< QString,QString > > InPortsL, OutPortsL;
366 // if myNode has linked port(s), create two lists of In/Out ports (InPortsL, OutPortsL) to identify all links for myNode
367 QObjectList* list = myNode->getMain()->getCanvas()->queryList("SUPERVGUI_CanvasLink");
368 QObjectListIt listit( *list );
370 while ( (listobj = listit.current()) != 0 ) {
372 SUPERV::Link_var aLink = ((SUPERVGUI_CanvasLink*)listobj)->getEngine();
373 if ( aNodeName.compare(aLink->InPort()->Node()->Name()) == 0
375 aNodeName.compare(aLink->OutPort()->Node()->Name()) == 0 ) {
376 QPair<QString, QString> InPair(QString(aLink->InPort()->Node()->Name()), QString(aLink->InPort()->Name()));
377 QPair<QString, QString> OutPair(QString(aLink->OutPort()->Node()->Name()), QString(aLink->OutPort()->Name()));
378 InPortsL.append(InPair);
379 OutPortsL.append(OutPair);
383 // put into In/Out lists all links for corresponding EndLoop node
384 QString aCoupledNodeName = ((SUPERVGUI_CanvasStartNode*)myNode)->getCoupled()->getEngine()->Name();
385 if ( aCoupledNodeName.compare(aLink->InPort()->Node()->Name()) == 0
387 aCoupledNodeName.compare(aLink->OutPort()->Node()->Name()) == 0 ) {
388 QPair<QString, QString> InPair(QString(aLink->InPort()->Node()->Name()), QString(aLink->InPort()->Name()));
389 QPair<QString, QString> OutPair(QString(aLink->OutPort()->Node()->Name()), QString(aLink->OutPort()->Name()));
390 InPortsL.append(InPair);
391 OutPortsL.append(OutPair);
398 // portsToRemove list contains:
399 // for Loop node: all INPUT ports except Gates
400 // for other Inline: all INPUT and OUTPUT ports except Gates
401 it = QObjectListIt( portsToRemove );
402 while ( (obj = it.current()) != 0 ) {
404 ((SUPERVGUI_CanvasPort*)obj)->remove();
407 // 1.2 create new ports in INode and CanvasPort in myNode
410 for ( i = 0; i < myInList->count(); i++ ) {
411 item = (PortListItem*)myInList->item( i );
412 aPort = aINode->InPort( item->PortName.latin1(), item->PortType.latin1() );
413 if ( InNameInput.contains( item->PortName )
415 item->PortType.compare(InNameInput[item->PortName].first) == 0 ) {
416 // i.e. aPort is input and had a value (not linked!)
417 // if ports' name and type didn't change and ports had an input value => set this value again
418 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
420 aPort->Input( aSupMod->getEngine()->StringValue( InNameInput[item->PortName].second ) );
421 myNode->createPort( aPort.in() );
424 myNode->createPort( aPort.in() );
426 if ( !InPortsL.isEmpty() && !OutPortsL.isEmpty() )
427 // create links for those input ports, which had links earlier
428 createLinkEngine( aPort, InPortsL, OutPortsL );
433 // asv : 11.01.05 : for Loop nodes do the same as in SUPERVGUI_CanvasStartNode::addInputPort()
434 SUPERVGUI_CanvasStartNode* aStartLoopNode = (SUPERVGUI_CanvasStartNode*)myNode;
435 aStartLoopNode->merge();
436 aStartLoopNode->getCoupled()->merge();
439 if ( !InPortsL.isEmpty() && !OutPortsL.isEmpty() ) {
441 // 1) create old links for output ports of Loop node
442 QObjectList* aPortsOut = aStartLoopNode->queryList("SUPERVGUI_CanvasPortOut");
443 QObjectListIt aPorstOutit( *aPortsOut );
445 while ( (listobj = aPorstOutit.current()) != 0 ) {
448 SUPERV::Port_var aPortOut = ((SUPERVGUI_CanvasPort*)listobj)->getEngine();
449 createLinkEngine( aPortOut, OutPortsL, InPortsL );
452 // 2) create old links for input ports of EndLoop node
453 QObjectList* aPortsIn = aStartLoopNode->getCoupled()->queryList("SUPERVGUI_CanvasPortIn");
454 QObjectListIt aPorstInit( *aPortsIn );
455 while ( (listobj = aPorstInit.current()) != 0 ) {
458 SUPERV::Port_var aPortIn = ((SUPERVGUI_CanvasPort*)listobj)->getEngine();
459 createLinkEngine( aPortIn, InPortsL, OutPortsL );
462 // 3) create old links for output ports of EndLoop node
463 aPortsOut = aStartLoopNode->getCoupled()->queryList("SUPERVGUI_CanvasPortOut");
464 aPorstOutit = QObjectListIt( *aPortsOut );
465 while ( (listobj = aPorstOutit.current()) != 0 ) {
468 SUPERV::Port_var aPortOut = ((SUPERVGUI_CanvasPort*)listobj)->getEngine();
469 createLinkEngine( aPortOut, OutPortsL, InPortsL );
475 // creating Out-ports, except LoopNode-s
476 for ( i = 0; i < myOutList->count() && !isLoop; i++ ) {
477 item = (PortListItem*)myOutList->item( i );
478 aPort = aINode->OutPort( item->PortName.latin1(), item->PortType.latin1() );
479 myNode->createPort( aPort.in() );
482 if ( !InPortsL.isEmpty() && !OutPortsL.isEmpty() )
483 // create links for those output ports, which had links earlier
484 createLinkEngine( aPort, OutPortsL, InPortsL );
487 // 2. update the node's presentation
488 myNode->getMain()->getCanvas()->update();
491 // 3. close the dialog
492 myNode->getMain()->lockedGraph( false );
498 * Simply close the dialog
500 void SUPERVGUI_ManagePortsDlg::reject() {
501 myNode->getMain()->lockedGraph( false );
507 * Update current values on show event
509 void SUPERVGUI_ManagePortsDlg::showEvent( QShowEvent* theEvent ) {
511 QDialog::showEvent( theEvent );
515 * Initialize In/Out tables with values from the given node
517 void SUPERVGUI_ManagePortsDlg::init( const SUPERVGUI_CanvasNode* theNode ) {
519 MESSAGE("ERROR: SUPERVGUI_ManagePortsDlg: the CanvasNode is nil!");
523 SUPERV_INode aINode = myNode->getInlineNode();
524 if ( SUPERV_isNull( aINode ) ) {
525 MESSAGE("ERROR: SUPERVGUI_ManagePortsDlg: the node of wrong type is found (not InLine node)!");
529 // 1. fill myTypeCombo with all available types
530 myTypeCombo->insertStrList( gTypes );
532 // 2. fill Input and Output listboxes with Ports' names/types
534 SUPERV_Ports aPorts = aINode->Ports();
535 for ( int i=0; i < aPorts->length(); i++ ) {
536 if ( aPorts[i]->IsGate() )
538 if ( aPorts[i]->IsInput()
540 !myInList->findItem( QString( "%1 (%2)" ).arg( aPorts[i]->Name() ).arg( aPorts[i]->Type() ) ) ) // mkr : PAL11332
541 new PortListItem( myInList, aPorts[i]->Name(), aPorts[i]->Type() );
542 if ( !aPorts[i]->IsInput()
544 !myOutList->findItem( QString( "%1 (%2)" ).arg( aPorts[i]->Name() ).arg( aPorts[i]->Type() ) ) ) // mkr : PAL11332
545 new PortListItem( myOutList, aPorts[i]->Name(), aPorts[i]->Type() );
549 void SUPERVGUI_ManagePortsDlg::addPort( QListBox* theLB ) {
552 QString name = myNameEdt->text();
553 if ( !name.isNull() && name.length() ) {
554 bool found = false; // check if already exists -- and don't allow if yes
555 for ( int i = 0; i < theLB->count(); i++ ) {
556 if ( ((PortListItem*)theLB->item(i))->PortName == name ) {
562 QMessageBox::warning( this, tr("ERROR"), tr("MSG_PORT_EXIST") ); // mkr : IPAL10386
564 new PortListItem( theLB, name, myTypeCombo->currentText() );
569 * called on 'X' button press - remove selected port item
571 void SUPERVGUI_ManagePortsDlg::removePort( QListBox* theLB ) {
575 const int i = theLB->currentItem();
577 delete theLB->item( i );
581 * called on up/down key press - move the selected list box item from position 'from' to position 'to'
583 void SUPERVGUI_ManagePortsDlg::moveItem( QListBox* theLB, const int from, const int to ) {
587 // disconnect itemChanged - it leads to crash if there was only 1 item left
588 disconnect( theLB, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(itemChanged(QListBoxItem*)));
590 if ( from >= 0 && from < theLB->count() && to >=0 && to < theLB->count() ) {
591 QListBoxItem* item = theLB->item( from );
592 theLB->takeItem( item );
593 theLB->insertItem( item, to );
594 theLB->setCurrentItem( item );
595 theLB->setSelected( item, true );
599 connect( theLB, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(itemChanged(QListBoxItem*)));
603 * move the selected item UP
605 void SUPERVGUI_ManagePortsDlg::moveUp( QListBox* theLB ) {
608 const int i = theLB->currentItem();
609 moveItem( theLB, i, i-1 );
613 * move the selected item DOWN
615 void SUPERVGUI_ManagePortsDlg::moveDown( QListBox* theLB ) {
618 const int i = theLB->currentItem();
619 moveItem( theLB, i, i+1 );
624 * returns true if there is a current and selected item in the given listbox and it
625 * equals to the given item.
627 bool isEditingItem( const QListBoxItem* item, const QListBox* theLB ) {
628 return item && item == theLB->item( theLB->currentItem() ) && theLB->isSelected( item );
632 * called when name is changed. Tries to change name of the item, which was
633 * the last selected by user item in myInList or myOutList (myLastItem)
635 void SUPERVGUI_ManagePortsDlg::nameChanged( const QString& name ) {
636 if ( isEditingItem( myLastItem, myInList ) || isEditingItem( myLastItem, myOutList ) ) {
637 ((PortListItem*)myLastItem)->PortName = name;
638 //myLastItem->listBox()->repaint( true );
639 // it would be much better to change the item and repaint it -- but -- repaint()
640 // is done only after a while, which is not good.. so -- "cheating" around
641 const int i = myLastItem->listBox()->index( myLastItem );
642 moveItem( myLastItem->listBox(), i, i );
647 * called when type item in myTypeCombo is changed. Tries to change type
648 * of the last selected by user item in myInList or myOutList (myLastItem)
650 void SUPERVGUI_ManagePortsDlg::typeChanged( const QString& type ) {
651 if ( isEditingItem( myLastItem, myInList ) || isEditingItem( myLastItem, myOutList ) ) {
652 ((PortListItem*)myLastItem)->PortType = type;
653 //myLastItem->listBox()->repaint( true );
654 // it would be much better to change the item and repaint it -- but -- repaint()
655 // is done only after a while, which is not good.. so -- "cheating" around
656 const int i = myLastItem->listBox()->index( myLastItem );
657 moveItem( myLastItem->listBox(), i, i );
662 * called when new item became "currentItem" in any myInList or myOutList listboxes.
664 void SUPERVGUI_ManagePortsDlg::itemChanged( QListBoxItem * item ) {
665 if ( !item ) // after remove, etc..
668 // disable nameChanged, typeChanged callbacks
669 disconnect( myNameEdt, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)));
670 disconnect( myTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(typeChanged(const QString&)));
673 myNameEdt->setText( ((PortListItem*)item)->PortName );
674 for ( int i = 0; i < myTypeCombo->count(); i++ )
675 if ( myTypeCombo->text( i ) == ((PortListItem*)item)->PortType ) {
676 myTypeCombo->setCurrentItem( i );
680 // connect back nameChanged, typeChanged
681 connect( myNameEdt, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)));
682 connect( myTypeCombo, SIGNAL(activated(const QString&)), this, SLOT(typeChanged(const QString&)));
689 * Port parameters dialog definition (taken from SUPERVGUI_Node.cxx without change)
691 SUPERVGUI_PortParamsDlg::SUPERVGUI_PortParamsDlg(const QStringList& thePortsNames)
692 : QDialog(SUIT_Session::session()->activeApplication()->desktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
693 myPortsNames( thePortsNames )
695 setSizeGripEnabled( true );
696 setCaption("Port parameters");
698 QGridLayout* aBaseLayout = new QGridLayout( this );
699 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
701 QLabel* aNameLbl = new QLabel("Port Name", this );
702 aBaseLayout->addWidget(aNameLbl, 0, 0);
704 myNameTxt = new QLineEdit( this );
705 aNameLbl->setBuddy( myNameTxt );
706 aBaseLayout->addWidget(myNameTxt, 0, 1);
708 QLabel* aTypeLbl = new QLabel("Value Type", this );
709 aBaseLayout->addWidget(aTypeLbl, 1, 0);
711 myTypeTxt = new QComboBox( this );
712 aTypeLbl->setBuddy( myTypeTxt );
713 myTypeTxt->insertStrList( gTypes );
714 aBaseLayout->addWidget(myTypeTxt, 1, 1);
716 QGroupBox* aBtnBox = new QGroupBox( this );
717 aBtnBox->setColumnLayout( 0, Qt::Vertical );
718 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
719 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
720 aBtnLayout->setAlignment( Qt::AlignTop );
721 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
723 aBaseLayout->addMultiCellWidget( aBtnBox, 2, 2, 0, 1 );
725 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
726 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
727 aBtnLayout->addWidget( aOKBtn );
729 aBtnLayout->addStretch();
731 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
732 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
733 aBtnLayout->addWidget( aCancelBtn );
736 void SUPERVGUI_PortParamsDlg::clickOnOk()
738 if (getName().isEmpty() || getType().isEmpty())
739 QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_CANT_CREATE_PORT" ) );
740 else if (myPortsNames.contains(getName()))
741 QMessageBox::warning( this, tr("ERROR"), tr("MSG_PORT_EXIST") ); // mkr : IPAL10386