]> SALOME platform Git repositories - modules/superv.git/commitdiff
Salome HOME
Bugs that lead to crashes were fixed (addressed zero item in itemChanged()).
authorasv <asv@opencascade.com>
Tue, 14 Dec 2004 06:50:49 +0000 (06:50 +0000)
committerasv <asv@opencascade.com>
Tue, 14 Dec 2004 06:50:49 +0000 (06:50 +0000)
src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.cxx
src/SUPERVGUI/SUPERVGUI_ManagePortsDlg.h

index e887e1fd06272302e479cdbd71b2a9f069acd844..d0410f6dbc707d49056782952e969404128abf78 100644 (file)
@@ -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&)));
 }
 
 
index 23ca2cbec968c8646b0af329504ee1e2e135c4cc..345d1cb424f8b3819e5476761b41638aaa50d810 100644 (file)
@@ -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;
 };
 
 /*!