Salome HOME
Fix for bug 10438: Crash during Explode on Blocks operation (Global selection on...
[modules/gui.git] / src / Qtx / QtxDockAction.cxx
index a4c95128ed8c70bc2692770b9f34a3cbb062b11e..f126120ed745787712bd8e0310c98a549131d5bf 100755 (executable)
@@ -150,7 +150,11 @@ bool QtxDockAction::isSeparate() const
 
 void QtxDockAction::setSeparate( const bool on )
 {
+  if ( mySeparate == on )
+    return;
+
   mySeparate = on;
+  updateMenus();
 }
 
 /*!
@@ -232,6 +236,15 @@ bool QtxDockAction::removeFrom( QWidget* wid )
   return QtxAction::removeFrom( wid );
 }
 
+void QtxDockAction::setMenuText( const QString& txt )
+{
+  if ( menuText() == txt )
+    return;
+
+  QtxAction::setMenuText( txt );
+  updateMenus();
+}
+
 /*!
        Name: addDockWindow [public]
        Desc: Add dock window to internal data structures. Action will be include all added
@@ -415,7 +428,7 @@ void QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& section
     collectNames( i, that->myNames );
 
   if ( clear )
-    resMgr->removeSection( sec );
+    resMgr->remove( sec );
 
   resMgr->setValue( sec, "windows_list", myNames.join( "|" ) );
 
@@ -798,7 +811,7 @@ void QtxDockAction::loadPlaceInfo() const
     winList.append( mIt.data() );
 
   QMap<int, DockWinList> winMap;
-  QMap<QDockWindow*, GeomInfo> geomMap;
+  QMap<QDockWindow*, GeomInfo*> geomMap;
 
   for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
   {
@@ -809,11 +822,12 @@ void QtxDockAction::loadPlaceInfo() const
     if ( !myGeom.contains( name ) )
       continue;
 
-    GeomInfo inf( myGeom[name] );
+    //! collect pointer of info to have fresh info data after processEvents();
+    GeomInfo* inf = (GeomInfo*)&( myGeom[name] );
     geomMap.insert( it.current(), inf );
-    if ( !winMap.contains( inf.place ) )
-      winMap.insert( inf.place, DockWinList() );
-    winMap[inf.place].append( it.current() );
+    if ( !winMap.contains( inf->place ) )
+      winMap.insert( inf->place, DockWinList() );
+    winMap[inf->place].append( it.current() );
   }
 
   loadPlaceArea( DockMinimized, mw, 0,
@@ -831,15 +845,15 @@ void QtxDockAction::loadPlaceInfo() const
 
 void QtxDockAction::loadPlaceArea( const int place, QMainWindow* mw, QDockArea* area,
                                    const QPtrList<QDockWindow>& dockList,
-                                   const QMap<QDockWindow*, GeomInfo>& geomMap ) const
+                                   const QMap<QDockWindow*, GeomInfo*>& geomMap ) const
 {
   for ( QPtrListIterator<QDockWindow> it( dockList ); it.current(); ++it )
   {
     if ( !geomMap.contains( it.current() ) )
       continue;
 
-    const GeomInfo& inf = geomMap[it.current()];
-    mw->moveDockWindow( it.current(), (Qt::Dock)place, inf.newLine, inf.index, inf.offset );
+    GeomInfo* inf = geomMap[it.current()];
+    mw->moveDockWindow( it.current(), (Qt::Dock)place, inf->newLine, inf->index, inf->offset );
   }
 
   if ( !area )
@@ -853,17 +867,17 @@ void QtxDockAction::loadPlaceArea( const int place, QMainWindow* mw, QDockArea*
     if ( !geomMap.contains( dw ) )
       continue;
 
-    const GeomInfo& inf = geomMap[dw];
+    GeomInfo* inf = geomMap[dw];
     if ( place != DockTornOff )
     {
-      dw->setNewLine( inf.newLine );
-                 dw->setOffset( inf.offset );
-                 dw->setFixedExtentWidth( inf.fixW );
-                 dw->setFixedExtentHeight( inf.fixH );
+      dw->setNewLine( inf->newLine );
+                 dw->setOffset( inf->offset );
+                 dw->setFixedExtentWidth( inf->fixW );
+                 dw->setFixedExtentHeight( inf->fixH );
     }
-    dw->setGeometry( inf.x, inf.y, inf.w, inf.h );
+    dw->setGeometry( inf->x, inf->y, inf->w, inf->h );
 
-    inf.vis ? dw->show() : dw->hide();
+    inf->vis ? dw->show() : dw->hide();
   }
 
   QWidget* wid = area;
@@ -1166,3 +1180,43 @@ void QtxDockAction::collectNames( const int place, QStringList& lst ) const
     lst.append( name );
   }
 }
+
+void QtxDockAction::updateMenus()
+{
+  for ( MenuMap::Iterator it = myMenu.begin(); it != myMenu.end(); ++it )
+  {
+    QPopupMenu* pm = it.key();
+    MenuInfo& inf = it.data();
+
+    int toolId = findId( pm, inf.tool );
+    int dockId = findId( pm, inf.dock );
+
+    int index = pm->indexOf( dockId );
+
+    if ( isSeparate() && !inf.tool )
+      inf.tool = new QPopupMenu( pm );
+
+    pm->removeItem( dockId );
+    pm->removeItem( toolId );
+
+    if ( !isSeparate() && inf.tool )
+    {
+      delete inf.tool;
+      inf.tool = 0;
+    }
+
+    QString dock, tool;
+    splitMenuText( dock, tool );
+
+    if ( inf.dock )
+      iconSet().isNull() ? pm->insertItem ( dock, inf.dock, -1, index ) :
+                           pm->insertItem ( iconSet(), dock, inf.dock, -1, index );
+
+    if ( index >= 0 )
+      index++;
+
+    if ( inf.tool )
+      iconSet().isNull() ? pm->insertItem ( tool, inf.tool, -1, index ) :
+                          pm->insertItem ( iconSet(), tool, inf.tool, -1, index );
+  }
+}