Salome HOME
Copyright update 2022
[modules/gui.git] / src / Qtx / QtxActionMenuMgr.cxx
index a4972a755060fa82bab86a716c7ed6f4c6886332..de7e5bbab0da28e09705f4781788fa184cb00021 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -874,8 +874,6 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo
   if ( !mw )
     return;
 
-  bool filled = checkWidget( mw );
-
   // first remove all own actions and collect foreign ones
   QMap< QAction*, QList<QAction*> > foreign;
   QAction* a;
@@ -966,13 +964,14 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo
     foreach( a, formapit.value() )
       mw->insertAction( preva, a );
   }
-  
+
   // remove extra separators
   simplifySeparators( mw );
 
   // update parent menu if necessary
-  if ( updParent && node->parent && filled != checkWidget( mw ) )
+  if ( updParent && node->parent ) {
     updateMenu( node->parent, false );
+  }
 }
 
 /*!
@@ -1019,7 +1018,12 @@ bool QtxActionMenuMgr::checkWidget( QWidget* wid ) const
   if ( !wid )
     return false;
 
-  return !wid->actions().isEmpty();
+  bool res = false;
+  QList<QAction*> lst = wid->actions();
+  for ( QList<QAction*>::const_iterator it = lst.begin(); it != lst.end() && !res; ++it ) {
+    res = !(*it)->isSeparator() && (*it)->isVisible();
+  }
+  return res;
 }
 
 /*!
@@ -1200,6 +1204,25 @@ void QtxActionMenuMgr::triggerUpdate( const int id, const bool rec )
   QtxActionMgr::triggerUpdate();
 }
 
+/*!
+  \brief Called when action is changed.
+
+  Schedule delayed update for parent menu of changed action.
+*/
+void QtxActionMenuMgr::actionChanged( int id )
+{
+  NodeList aNodes;
+  find( id, aNodes );
+
+  for ( NodeList::iterator it = aNodes.begin(); it != aNodes.end(); ++it )
+  {
+    MenuNode* node = *it;
+    if ( node->visible ) {
+      triggerUpdate( node->parent ? node->parent->id : myRoot->id, false );
+    }
+  }
+}
+
 /*!
   \brief Called when delayed content update is performed.