From 24fc8e7a9afb10b55bd7b9749e0a189e819c80bf Mon Sep 17 00:00:00 2001 From: asv Date: Tue, 14 Dec 2004 06:50:49 +0000 Subject: [PATCH] Bugs that lead to crashes were fixed (addressed zero item in itemChanged()). --- src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.cxx | 25 ++++++++++++++++------ src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.h | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.cxx b/src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.cxx index e887e1f..d0410f6 100644 --- a/src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.cxx +++ b/src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.cxx @@ -130,7 +130,6 @@ SUPERVGUI_ManagePortsDlg::SUPERVGUI_ManagePortsDlg( SUPERVGUI_CanvasNode* theNod { myNode = theNode; myLastItem = 0; - myFromItemChanged = false; init(); } @@ -402,9 +401,13 @@ void SUPERVGUI_ManagePortsDlg::removePort( QListBox* theLB ) { delete theLB->item( i ); } -void moveItem( QListBox* theLB, const int from, const int 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 ); @@ -412,6 +415,9 @@ void moveItem( QListBox* theLB, const int from, const int to ) { theLB->setCurrentItem( item ); theLB->setSelected( item, true ); } + + // connect back.. + connect( theLB, SIGNAL(currentChanged(QListBoxItem*)), this, SLOT(itemChanged(QListBoxItem*))); } void SUPERVGUI_ManagePortsDlg::moveUp( QListBox* theLB ) { @@ -442,7 +448,6 @@ bool isEditingItem( const QListBoxItem* item, const QListBox* theLB ) { * 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 ); @@ -458,7 +463,6 @@ void SUPERVGUI_ManagePortsDlg::nameChanged( const QString& name ) { * 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 ); @@ -473,7 +477,13 @@ void SUPERVGUI_ManagePortsDlg::typeChanged( const QString& type ) { * 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++ ) @@ -481,7 +491,10 @@ void SUPERVGUI_ManagePortsDlg::itemChanged( QListBoxItem * item ) { 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&))); } diff --git a/src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.h b/src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.h index 23ca2cb..345d1cb 100644 --- a/src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.h +++ b/src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.h @@ -67,6 +67,7 @@ protected: void removePort( QListBox* ); void moveUp( QListBox* ); void moveDown( QListBox* ); + void moveItem( QListBox* theLB, const int from, const int to ); private: void init(); @@ -79,7 +80,6 @@ private: QListBox* myInList; QListBox* myOutList; QListBoxItem* myLastItem; - bool myFromItemChanged; }; /*! -- 2.39.2