if ( items.isEmpty() )
return;
- QList<QAction*> toRemove;
- for ( int i = 1; i < items.count(); i++ )
+ bool action = false;
+ for ( int i = 0; i < items.count(); i++ )
{
- if ( items[i]->isSeparator() && items[i - 1]->isSeparator() )
- toRemove.append( items[i] );
-
- if ( recursive && items[i]->menu() )
- simplifySeparators( items[i]->menu(), recursive );
+ QAction* a = items[i];
+ if ( a->isSeparator() ) {
+ a->setVisible(action);
+ action = false;
+ }
+ else if ( a->isVisible() ) {
+ action = true;
+ if ( recursive && a->menu() )
+ simplifySeparators( a->menu(), recursive );
+ }
}
- for ( QList<QAction*>::iterator it = toRemove.begin(); it != toRemove.end(); ++it )
- wid->removeAction( *it );
-
- items = wid->actions();
- if ( !items.isEmpty() && items[0]->isSeparator() )
- wid->removeAction( items[0] );
-
- items = wid->actions();
- if ( !items.isEmpty() && items[items.count() - 1]->isSeparator() )
- wid->removeAction( items[items.count() - 1] );
+ action = false;
+ for ( int i = items.count() - 1; i > 0; i-- ) {
+ QAction* a = items[i];
+ if ( a->isSeparator() ) {
+ a->setVisible(action);
+ action = false;
+ }
+ else if ( a->isVisible() )
+ action = true;
+ }
}
/*!
if ( !mw )
return;
- bool filled = checkWidget( mw );
-
// first remove all own actions and collect foreign ones
QMap< QAction*, QList<QAction*> > foreign;
QAction* a;
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 );
+ }
}
/*!
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;
}
/*!
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.
void updateMenu( MenuNode* = 0, const bool = true, const bool = true );
virtual void internalUpdate();
virtual void updateContent();
+ virtual void actionChanged( int );
private:
bool ownAction( QAction*, MenuNode* ) const;
myActions.insert( theId, a );
+ connect( a, SIGNAL( changed() ), this, SLOT( onActionChanged() ) );
+
return theId;
}
*/
void QtxActionMgr::unRegisterAction( const int id )
{
- if( contains( id ) )
+ if ( contains( id ) ) {
+ disconnect( myActions[id], SIGNAL( changed() ),
+ this, SLOT( onActionChanged() ) );
myActions.remove( id );
+ }
}
/*!
{
}
+/*!
+ \brief Internal action changing response operation.
+*/
+void QtxActionMgr::actionChanged( int )
+{
+}
+
/*!
\brief Called when delayed update is performed (via timer event).
updateContent();
}
+/*!
+ \brief Called when one of the registered actions changed.
+
+ Calls virtual method actionChanged() which can be redefined in the
+ subclasses to customize reaction on this.
+*/
+void QtxActionMgr::onActionChanged()
+{
+ QAction* a = ::qobject_cast<QAction*>( sender() );
+
+ int id = actionId( a );
+ if ( id != -1 )
+ actionChanged( id );
+}
+
/*!
\class QtxActionMgr::Reader
\brief Generic actions description files reader class.
void triggerUpdate();
virtual void updateContent();
+ virtual void actionChanged( int );
private slots:
+ void onActionChanged();
void onUpdateContent();
private: