From c1aecad69c6f15106ea48dba6f47e313920aa88e Mon Sep 17 00:00:00 2001 From: ptv Date: Tue, 7 Nov 2006 08:40:24 +0000 Subject: [PATCH] debug and improve menuMgrand toolbarMgr updates --- src/Qtx/Qtx.cxx | 25 +++++++++++++-------- src/Qtx/QtxActionMenuMgr.cxx | 42 +++++++++++++++++++++++++++--------- src/Qtx/QtxActionMenuMgr.h | 4 ++++ src/Qtx/QtxActionMgr.cxx | 42 +++++++++++++++++++++++++++++++++--- src/Qtx/QtxActionMgr.h | 10 ++++++++- src/Qtx/QtxActionToolMgr.cxx | 29 ++++++++++++++++++++----- src/Qtx/QtxActionToolMgr.h | 5 +++++ 7 files changed, 129 insertions(+), 28 deletions(-) diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index 5e03c6168..d31830063 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -180,27 +180,34 @@ void Qtx::simplifySeparators( QToolBar* toolbar ) QObjectList delList; bool isPrevSep = true; + QObject* lastVis = 0; // last visible for ( QObjectListIt it( *objList ); it.current(); ++it ) { QObject* obj = it.current(); + /*/ if ( !obj || !obj->isWidgetType() || !((QWidget*)obj)->isVisibleTo( toolbar ) ) continue; bool isSep = obj->isA( "QToolBarSeparator" ); + */ + if ( !obj || !obj->isWidgetType() ) + continue; + bool isSep = obj->isA( "QToolBarSeparator" ); + if ( !isSep && !((QWidget*)obj)->isVisibleTo( toolbar ) ) + continue; if ( isPrevSep && isSep ) delList.append( obj ); - isPrevSep = isSep; + else + { + isPrevSep = isSep; + lastVis = obj; + } } + // remove last visible separator + if ( lastVis && lastVis->isA( "QToolBarSeparator" ) ) + delList.append( lastVis ); for ( QObjectListIt itr( delList ); itr.current(); ++itr ) delete itr.current(); - - if ( toolbar->children() && !toolbar->children()->isEmpty() && - toolbar->children()->getFirst()->isA( "QToolBarSeparator" ) ) - delete toolbar->children()->getFirst(); - - if ( toolbar->children() && !toolbar->children()->isEmpty() && - toolbar->children()->getLast()->isA( "QToolBarSeparator" ) ) - delete toolbar->children()->getLast(); } /*! diff --git a/src/Qtx/QtxActionMenuMgr.cxx b/src/Qtx/QtxActionMenuMgr.cxx index 94f7050a0..b82aaa80f 100644 --- a/src/Qtx/QtxActionMenuMgr.cxx +++ b/src/Qtx/QtxActionMenuMgr.cxx @@ -404,7 +404,8 @@ int QtxActionMenuMgr::insert( const int id, const int pId, const int group, cons pNode->children.append( node ); - updateMenu( pNode, false ); + triggerUpdate( pNode->id, false ); + return node->id; } @@ -464,7 +465,7 @@ int QtxActionMenuMgr::insert( const QString& title, const int pId, const int gro pNode->children.append( node ); - updateMenu( pNode, false ); + triggerUpdate( pNode->id, false ); return node->id; } @@ -608,7 +609,7 @@ void QtxActionMenuMgr::remove( const int id, const int pId, const int group ) for ( NodeListIterator itr( delNodes ); itr.current(); ++itr ) pNode->children.remove( itr.current() ); - updateMenu( pNode, false ); + triggerUpdate( pNode->id, false ); } /*! @@ -652,18 +653,14 @@ void QtxActionMenuMgr::setShown( const int id, const bool on ) NodeList aNodes; find( id, aNodes ); - QMap updMap; for ( NodeListIterator it( aNodes ); it.current(); ++it ) { if ( it.current()->visible != on ) { it.current()->visible = on; - updMap.insert( it.current()->parent, 0 ); + triggerUpdate( it.current()->parent ? it.current()->parent->id : myRoot.id, false ); } } - - for ( QMap::ConstIterator itr = updMap.begin(); itr != updMap.end(); ++itr ) - updateMenu( itr.key(), false ); } /*! @@ -697,7 +694,7 @@ void QtxActionMenuMgr::onHighlighted( int id ) setUpdatesEnabled( false ); emit menuHighlighted( pid, realId ); setUpdatesEnabled( updatesEnabled ); - updateMenu( find( realId ) ); + triggerUpdate( realId ); } } } @@ -949,7 +946,7 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo { MenuNode* par = iter.current()->parent; if ( !isVisible( iter.current()->id, par ? par->id : -1 ) ) - continue; + continue; if ( rec ) updateMenu( iter.current(), rec, false ); @@ -1090,6 +1087,31 @@ bool QtxActionMenuMgr::containsMenu( const int id, const int pid ) const return (bool)find( id, pid, false ); } +/*! + \Sets trigger for delayed update +*/ +void QtxActionMenuMgr::triggerUpdate( const int id, const bool rec ) +{ + bool isRec = rec; + if ( myUpdateIds.contains( id ) ) + isRec = isRec || myUpdateIds[ id ]; + myUpdateIds.insert( id, isRec ); + QtxActionMgr::triggerUpdate(); +} + +/*! + \Sets trigger for delayed update +*/ +void QtxActionMenuMgr::updateContent() +{ + for ( QMap::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it ) + { + MenuNode* node = find( it.key(), 0 ); + if ( node ) + updateMenu( node, it.data() ); + } + myUpdateIds.clear(); +} /*! Constructor diff --git a/src/Qtx/QtxActionMenuMgr.h b/src/Qtx/QtxActionMenuMgr.h index bdbe139a4..8f310611d 100644 --- a/src/Qtx/QtxActionMenuMgr.h +++ b/src/Qtx/QtxActionMenuMgr.h @@ -148,6 +148,7 @@ protected: void updateMenu( MenuNode* = 0, const bool = true, const bool = true ); virtual void internalUpdate(); + virtual void updateContent(); private: bool checkWidget( QWidget* ) const; @@ -156,6 +157,8 @@ private: QString clearTitle( const QString& ) const; int createMenu( const QStringList&, const int ); + void triggerUpdate( const int, const bool rec = true ); + private: typedef QMap MenuMap; @@ -163,6 +166,7 @@ private: MenuNode myRoot; QWidget* myMenu; MenuMap myMenus; + QMap myUpdateIds; }; /*! diff --git a/src/Qtx/QtxActionMgr.cxx b/src/Qtx/QtxActionMgr.cxx index b157b835e..78b8f2efc 100644 --- a/src/Qtx/QtxActionMgr.cxx +++ b/src/Qtx/QtxActionMgr.cxx @@ -23,13 +23,14 @@ #include "QtxActionMgr.h" #include "QtxAction.h" +#include +#include +#include #include #include #include #include #include -#include -#include static QAction* qtx_separator_action = 0; @@ -159,7 +160,8 @@ bool QtxActionMgr::SeparatorAction::removeFrom( QWidget* wid ) */ QtxActionMgr::QtxActionMgr( QObject* parent ) : QObject( parent ), -myUpdate( true ) +myUpdate( true ), +myUpdTimer( 0 ) { } @@ -375,6 +377,40 @@ QAction* QtxActionMgr::separator( const bool individual ) return qtx_separator_action; } +/*! + \initialise timer for delayed update +*/ +void QtxActionMgr::triggerUpdate() +{ + if ( !isUpdatesEnabled() ) + return; + + if ( !myUpdTimer ) + { + myUpdTimer = new QTimer( this ); + connect( myUpdTimer, SIGNAL( timeout() ), this, SLOT( onUpdateContent() ) ); + } + myUpdTimer->stop(); + // add timer event to event list + myUpdTimer->start( 0, true ); +} + +/*! + \perform delayed update + \default implementation is empty +*/ +void QtxActionMgr::updateContent() +{} + +/*! + \perform delayed update + \default implementation is empty +*/ +void QtxActionMgr::onUpdateContent() +{ + updateContent(); +} + /*! Class: QtxActionMgr::Reader Level: Public diff --git a/src/Qtx/QtxActionMgr.h b/src/Qtx/QtxActionMgr.h index e0ba1d0e6..1404d0dee 100644 --- a/src/Qtx/QtxActionMgr.h +++ b/src/Qtx/QtxActionMgr.h @@ -28,10 +28,10 @@ #include #include +class QTimer; class QAction; class QDomNode; - #ifdef WIN32 #pragma warning( disable:4251 ) #endif @@ -87,6 +87,13 @@ protected: virtual void internalUpdate(); int generateId() const; + //! initialise timer for delayed update + void triggerUpdate(); + virtual void updateContent(); + +private slots: + void onUpdateContent(); + private: typedef QGuardedPtr ActionPtr; typedef QMap ActionMap; @@ -94,6 +101,7 @@ private: private: bool myUpdate; ActionMap myActions; + QTimer* myUpdTimer; }; diff --git a/src/Qtx/QtxActionToolMgr.cxx b/src/Qtx/QtxActionToolMgr.cxx index 6d33cd902..2b36b4602 100644 --- a/src/Qtx/QtxActionToolMgr.cxx +++ b/src/Qtx/QtxActionToolMgr.cxx @@ -158,7 +158,7 @@ int QtxActionToolMgr::insert( const int id, const int tid, const int idx ) NodeList& list = myToolBars[tid].nodes; int index = idx < 0 ? list.count() : QMIN( idx, (int)list.count() ); list.insert( list.at( index ), node ); - updateToolBar( tid ); + triggerUpdate( tid ); return id; } @@ -296,7 +296,7 @@ void QtxActionToolMgr::remove( const int id, const int tid ) myToolBars[tid].nodes = newList; - updateToolBar( tid ); + triggerUpdate( tid ); } /*! @@ -562,7 +562,7 @@ void QtxActionToolMgr::setVisible( const int id, const int tId, const bool on ) } if ( changed ) - updateToolBar( tId ); + triggerUpdate( tId ); } /*! @@ -576,6 +576,27 @@ bool QtxActionToolMgr::load( const QString& fname, QtxActionMgr::Reader& r ) return r.read( fname, cr ); } +/*! + \Perform delayed update +*/ +void QtxActionToolMgr::updateContent() +{ + if ( !isUpdatesEnabled() ) + return; + + for ( QMap::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it ) + updateToolBar( it.key() ); + myUpdateIds.clear(); +} + +/*! + \ Sets trigger to update +*/ +void QtxActionToolMgr::triggerUpdate( const int id ) +{ + myUpdateIds.insert( id, 0 ); + QtxActionMgr::triggerUpdate(); +} /*! Constructor @@ -644,5 +665,3 @@ int QtxActionToolMgr::ToolCreator::append( const QString& tag, const bool subMen return res; } - - diff --git a/src/Qtx/QtxActionToolMgr.h b/src/Qtx/QtxActionToolMgr.h index 9300ec22a..bc59b4c61 100644 --- a/src/Qtx/QtxActionToolMgr.h +++ b/src/Qtx/QtxActionToolMgr.h @@ -24,6 +24,7 @@ #include "Qtx.h" +#include #include #include "QtxActionMgr.h" @@ -122,8 +123,11 @@ protected: virtual void internalUpdate(); void updateToolBar( const int ); + virtual void updateContent(); + private: void simplifySeparators( QToolBar* ); + void triggerUpdate( const int ); private: typedef struct { NodeList nodes; QToolBar* toolBar; } ToolBarInfo; @@ -132,6 +136,7 @@ private: private: ToolBarMap myToolBars; QMainWindow* myMainWindow; + QMap myUpdateIds; }; /*! -- 2.39.2