-// Copyright (C) 2007-2008 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
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
// File: QtxActionMenuMgr.cxx
// Author: Alexander SOLOVYOV, Sergey TELKOV
//
\param _group menu node group ID
*/
QtxActionMenuMgr::MenuNode::MenuNode( MenuNode* p,
- const int _id,
- const int _idx,
- const int _group )
+ const int _id,
+ const int _idx,
+ const int _group )
: parent( p ), id( _id ), idx( _idx ), group( _group ), visible( true ), emptyEnabled( 0 )
{
if ( p )
\param idx menu index inside the menu group
\return action ID
*/
-int QtxActionMenuMgr::insert( const QString& title, const int pId, const int group, const int id, const int idx )
+int QtxActionMenuMgr::insert( const QString& title, const int pId, const int group,
+ const int id, const int idx, QMenu* _menu)
{
MenuNode* pNode = pId == -1 ? myRoot : find( pId );
if ( !pNode )
int gid = (id == -1 || eNode ) ? generateId() : id;
- QMenu* menu = new QMenu( 0 );
+ QMenu* menu;
+ if (_menu)
+ menu = _menu;
+ else
+ menu = new QMenu( 0 );
QAction* ma = menu->menuAction();
ma->setText( title );
delNodes.append( *it );
}
+ QWidget* mW = menuWidget( pNode );
for ( NodeList::iterator itr = delNodes.begin(); itr != delNodes.end(); ++itr )
+ {
+ int id = (*itr)->id;
+ if( mW && menuAction( id ) )
+ {
+ mW->removeAction( menuAction( id ) );
+ myMenus.remove( id );
+ }
+ else if( mW && itemAction( id ) )
+ mW->removeAction( itemAction( id ) );
pNode->children.removeAll( *itr );
+ }
triggerUpdate( pNode->id, false );
}
if ( !mw )
return;
- bool filled = checkWidget( mw );
-
// first remove all own actions and collect foreign ones
QMap< QAction*, QList<QAction*> > foreign;
QAction* a;
{
a = foralit.next();
if ( !mw->actions().contains( a ) )
- foralit.remove();
+ foralit.remove();
}
}
QList<QAction*> alist = mw->actions();
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 );
+ }
}
/*!
for ( NodeList::const_iterator iter = node->children.begin(); iter != node->children.end(); ++iter )
{
QAction* mya = itemAction( (*iter)->id );
- if ( !mya ) mya = menuAction( (*iter)->id );
- if ( mya && mya == a ) return true;
+ if ( !mya )
+ mya = menuAction( (*iter)->id );
+ if ( mya && mya == a )
+ return true;
}
return false;
}
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;
}
/*!
if ( node && menuAction( id ) ) {
int old = node->emptyEnabled;
node->emptyEnabled += enable ? 1 : -1;
- if ( old <= 0 && enable || old > 0 && !enable ) // update menu only if enabled state has been changed
+ if ( ( old <= 0 && enable ) || ( old > 0 && !enable ) ) // update menu only if enabled state has been changed
updateMenu( node, true, true );
}
}
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.