From: ptv Date: Wed, 15 Nov 2006 10:43:45 +0000 (+0000) Subject: fixes on managers X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9e3e206344a55fd9395c65678ca494c16b421bd9;p=modules%2Fgui.git fixes on managers --- diff --git a/src/Qtx/QtxAction.cxx b/src/Qtx/QtxAction.cxx index 28173344b..0dfba4cda 100755 --- a/src/Qtx/QtxAction.cxx +++ b/src/Qtx/QtxAction.cxx @@ -21,9 +21,8 @@ #include "QtxAction.h" - -#include #include +#include /*! Name: QtxAction [public] @@ -32,7 +31,7 @@ */ QtxAction::QtxAction( QObject* parent, const char* name, bool toggle ) - : QAction( parent, name, toggle ) +: QAction( parent, name, toggle ) { } @@ -48,7 +47,7 @@ QtxAction::QtxAction( QObject* parent, const char* name, bool toggle ) QtxAction::QtxAction( const QString& text, const QIconSet& icon, const QString& menuText, int accel, QObject* parent, const char* name, bool toggle ) - : QAction( text, icon, menuText, accel, parent, name, toggle ) +: QAction( text, icon, menuText, accel, parent, name, toggle ) { } @@ -62,7 +61,7 @@ QtxAction::QtxAction( const QString& text, const QIconSet& icon, QtxAction::QtxAction( const QString& text, const QString& menuText, int accel, QObject* parent, const char* name, bool toggle ) - : QAction( text, menuText, accel, parent, name, toggle ) +: QAction( text, menuText, accel, parent, name, toggle ) { } @@ -83,43 +82,41 @@ QtxAction::~QtxAction() bool QtxAction::addTo( QWidget* w ) { - if ( w->inherits( "QMenuBar" ) ) { - - - // --- Add action to the QMenuBar --- - // n.b. currently for the actions inserted to the menu bar - // the following properties are not supported: - // * tooltips - // * what's this info - // * toggle mode - QMenuBar* mb = (QMenuBar*)w; - if ( myMenuIds.find( w ) != myMenuIds.end() ) + if ( !w->inherits( "QMenuBar" ) ) + return QAction::addTo( w ); + + // --- Add action to the QMenuBar --- + // n.b. currently for the actions inserted to the menu bar + // the following properties are not supported: + // * tooltips + // * what's this info + // * toggle mode + QMenuBar* mb = (QMenuBar*)w; + if ( myMenuIds.contains( w ) ) return false; // already added - - - - - - - - - - - - - if ( name() == "qt_separator_action" ) // separator - myMenuIds[ w ] = mb->insertSeparator(); - else if ( iconSet().isNull() ) // has no icon - myMenuIds[ w ] = mb->insertItem( menuText(), this, SIGNAL( activated() ), accel() ); - else // has icon - myMenuIds[ w ] = mb->insertItem( iconSet(), menuText(), this, SIGNAL( activated() ), accel() ); - mb->setItemEnabled( myMenuIds[ w ], isEnabled() ); - mb->setItemVisible( myMenuIds[ w ], isVisible() ); - - return true; + QMenuData* mData = mb; + int idx = mData->count(); + while ( idx > 0 ) + { + QMenuData* md = 0; + QMenuItem* mItem = mb->findItem( mb->idAt( idx - 1 ), &md ); + if ( md == mData && mItem && mItem->isSeparator() && mItem->widget() && qstrcmp( mItem->widget()->name(), "qt_maxtools" ) ) + idx--; + else + break; } - return QAction::addTo( w ); + + if ( name() == "qt_separator_action" ) // separator + myMenuIds.insert( w, mb->insertSeparator( idx ) ); + else if ( iconSet().isNull() ) // has no icon + myMenuIds.insert( w, mb->insertItem( menuText(), this, SIGNAL( activated() ), accel(), -1, idx ) ); + else // has icon + myMenuIds.insert( w, mb->insertItem( iconSet(), menuText(), this, SIGNAL( activated() ), accel(), -1, idx ) ); + + mb->setItemEnabled( myMenuIds[w], isEnabled() ); + mb->setItemVisible( myMenuIds[w], isVisible() ); + return true; } /*! @@ -134,109 +131,109 @@ bool QtxAction::addTo( QWidget* w, const int index ) if ( !addTo( w ) ) return false; - if ( w->inherits( "QPopupMenu" ) ) { - + if ( w->inherits( "QPopupMenu" ) ) + { // --- Add action to the QPopupMenu --- QPopupMenu* popup = (QPopupMenu*)w; - if ( index >= 0 && index < (int)popup->count() - 1 ) { - + if ( index >= 0 && index < (int)popup->count() - 1 ) + { int id = popup->idAt( popup->count() - 1 ); - if ( id != -1 ) { - - QMenuItem* item = popup->findItem( id ); - if ( item && item->isSeparator() ) { - - popup->removeItem( id ); - popup->insertSeparator( index ); - } - else { - - QPopupMenu* p = item ? item->popup() : 0; - int accel = popup->accel( id ); - bool isOn = popup->isItemEnabled( id ); - bool isVisible = popup->isItemVisible( id ); - bool isChecked = popup->isItemChecked( id ); - QString text = popup->text( id ); - QIconSet icon; - if ( popup->iconSet( id ) ) - icon = *popup->iconSet( id ); - popup->removeItem( id ); - int pos; - if ( icon.isNull() ) - - if ( p ) - pos = popup->indexOf( popup->insertItem( text, p, id, index ) ); - else - pos = popup->indexOf( popup->insertItem( text, id, index ) ); - - else - - if ( p ) - pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) ); - else - pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) ); - - popup->setId( pos, id ); - popup->setAccel( accel, id ); - popup->setItemEnabled( id, isOn ); - popup->setItemVisible( id, isVisible ); - popup->setItemChecked( id, isChecked ); - if ( !whatsThis().isEmpty() ) - popup->setWhatsThis( id, whatsThis() ); - if ( !p ) - popup->connectItem( id, this, SLOT( internalActivation() ) ); - } + if ( id != -1 ) + { + QMenuItem* item = popup->findItem( id ); + if ( item && item->isSeparator() ) + { + popup->removeItem( id ); + popup->insertSeparator( index ); + } + else + { + QPopupMenu* p = item ? item->popup() : 0; + int accel = popup->accel( id ); + bool isOn = popup->isItemEnabled( id ); + bool isVisible = popup->isItemVisible( id ); + bool isChecked = popup->isItemChecked( id ); + QString text = popup->text( id ); + QIconSet icon; + if ( popup->iconSet( id ) ) + icon = *popup->iconSet( id ); + popup->removeItem( id ); + int pos; + if ( icon.isNull() ) + { + if ( p ) + pos = popup->indexOf( popup->insertItem( text, p, id, index ) ); + else + pos = popup->indexOf( popup->insertItem( text, id, index ) ); + } + else + { + if ( p ) + pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) ); + else + pos = popup->indexOf( popup->insertItem( icon, text, p, id, index ) ); + } + popup->setId( pos, id ); + popup->setAccel( accel, id ); + popup->setItemEnabled( id, isOn ); + popup->setItemVisible( id, isVisible ); + popup->setItemChecked( id, isChecked ); + if ( !whatsThis().isEmpty() ) + popup->setWhatsThis( id, whatsThis() ); + if ( !p ) + popup->connectItem( id, this, SLOT( internalActivation() ) ); + } } } } - else if ( w->inherits( "QMenuBar" ) ) { - + else if ( w->inherits( "QMenuBar" ) ) + { // --- Add action to the QMenuBar --- QMenuBar* mb = (QMenuBar*)w; - if ( index >= 0 && index < (int)mb->count() - 1 ) { - + if ( index >= 0 && index < (int)mb->count() - 1 ) + { int id = mb->idAt( mb->count() - 1 ); - if ( id != -1 ) { - - QMenuItem* item = mb->findItem( id ); - if ( item && item->isSeparator() ) { - - mb->removeItem( id ); - mb->insertSeparator( index ); - } - else { - - QPopupMenu* p = item ? item->popup() : 0; - int accel = mb->accel( id ); - bool isOn = mb->isItemEnabled( id ); - bool isVisible = mb->isItemVisible( id ); - QString text = mb->text( id ); - QIconSet icon; - if ( mb->iconSet( id ) ) - icon = *mb->iconSet( id ); - mb->removeItem( id ); - int pos; - if ( icon.isNull() ) - - if ( p ) - pos = mb->indexOf( mb->insertItem( text, p, id, index ) ); - else - pos = mb->indexOf( mb->insertItem( text, id, index ) ); - - else - - if ( p ) - pos = mb->indexOf( mb->insertItem( icon, text, p, id, index ) ); - else - pos = mb->indexOf( mb->insertItem( icon, text, p, id, index ) ); - - mb->setId( pos, id ); - mb->setAccel( accel, id ); - mb->setItemEnabled( id, isOn ); - mb->setItemVisible( id, isVisible ); - if ( !p ) - mb->connectItem( id, this, SIGNAL( activated() ) ); - } + if ( id != -1 ) + { + QMenuItem* item = mb->findItem( id ); + if ( item && item->isSeparator() ) + { + mb->removeItem( id ); + mb->insertSeparator( index ); + } + else + { + QPopupMenu* p = item ? item->popup() : 0; + int accel = mb->accel( id ); + bool isOn = mb->isItemEnabled( id ); + bool isVisible = mb->isItemVisible( id ); + QString text = mb->text( id ); + QIconSet icon; + if ( mb->iconSet( id ) ) + icon = *mb->iconSet( id ); + mb->removeItem( id ); + int pos; + if ( icon.isNull() ) + { + if ( p ) + pos = mb->indexOf( mb->insertItem( text, p, id, index ) ); + else + pos = mb->indexOf( mb->insertItem( text, id, index ) ); + } + else + { + if ( p ) + pos = mb->indexOf( mb->insertItem( icon, text, p, id, index ) ); + else + pos = mb->indexOf( mb->insertItem( icon, text, p, id, index ) ); + } + mb->setId( pos, id ); + mb->setAccel( accel, id ); + mb->setItemEnabled( id, isOn ); + mb->setItemVisible( id, isVisible ); + if ( !p ) + mb->connectItem( id, this, SIGNAL( activated() ) ); + } } } } @@ -251,21 +248,21 @@ bool QtxAction::addTo( QWidget* w, const int index ) bool QtxAction::removeFrom( QWidget* w ) { - + bool res = false; // check if widget is QMenuBar - if ( w->inherits( "QMenuBar" ) ) { - + if ( w->inherits( "QMenuBar" ) ) + { QMenuBar* mb = (QMenuBar*)w; - if ( myMenuIds.find( w ) == myMenuIds.end() ) - return false; // not yet added - mb->removeItem( myMenuIds[ w ] ); - myMenuIds.remove( w ); - return true; - + if ( myMenuIds.find( w ) != myMenuIds.end() ) + { + mb->removeItem( myMenuIds[ w ] ); + myMenuIds.remove( w ); + res = true; + } } - return QAction::removeFrom( w ); - - + else + res = QAction::removeFrom( w ); + return res; } /*! @@ -311,27 +308,27 @@ void QtxAction::setPopup( QWidget* w, const int id, QPopupMenu* subPopup ) const pmd->removeItem( id ); // add new item - if ( w->inherits( "QPopupMenu" ) ) { - + if ( w->inherits( "QPopupMenu" ) ) + { // --- QPopupMenu --- QPopupMenu* popup = (QPopupMenu*)w; if ( icon.isNull() ) pos = popup->indexOf( subPopup ? popup->insertItem( text, subPopup, id, pos ) : - popup->insertItem( text, id, pos ) ); + popup->insertItem( text, id, pos ) ); else pos = popup->indexOf( subPopup ? popup->insertItem( icon, text, subPopup, id, pos ) : - popup->insertItem( icon, text, id, pos ) ); + popup->insertItem( icon, text, id, pos ) ); } - else { - + else + { // --- QMenuBar --- QMenuBar* mb = (QMenuBar*)w; if ( icon.isNull() ) pos = mb->indexOf( subPopup ? mb->insertItem( text, subPopup, id, pos ) : - mb->insertItem( text, id, pos ) ); + mb->insertItem( text, id, pos ) ); else pos = mb->indexOf( subPopup ? mb->insertItem( icon, text, subPopup, id, pos ) : - mb->insertItem( icon, text, id, pos ) ); + mb->insertItem( icon, text, id, pos ) ); } // restore properties @@ -343,5 +340,3 @@ void QtxAction::setPopup( QWidget* w, const int id, QPopupMenu* subPopup ) const // delete old popup delete oldPopup; } - - diff --git a/src/Qtx/QtxActionMenuMgr.cxx b/src/Qtx/QtxActionMenuMgr.cxx index 3b5cef89a..aa49bd8bd 100644 --- a/src/Qtx/QtxActionMenuMgr.cxx +++ b/src/Qtx/QtxActionMenuMgr.cxx @@ -115,13 +115,12 @@ public: QPopupMenu* popup() const; private: - int myId; - QPopupMenu* myPopup; - bool myEmptyEnabled; - QMap myIds; + int myId; + QPopupMenu* myPopup; + bool myEmptyEnabled; + QMap myIds; }; - /*! Constructor for menu action \param text - description text @@ -131,15 +130,12 @@ private: \param allowEmpty - if it is true, it makes possible to add this action with empty popup to menu */ -QtxActionMenuMgr::MenuAction::MenuAction( const QString& text, - const QString& menuText, - QObject* parent, - const int id, - const bool allowEmpty ) +QtxActionMenuMgr::MenuAction::MenuAction( const QString& text, const QString& menuText, + QObject* parent, const int id, const bool allowEmpty ) : QtxAction( text, menuText, 0, parent ), - myId( id ), - myPopup( 0 ), - myEmptyEnabled( allowEmpty ) +myId( id ), +myPopup( 0 ), +myEmptyEnabled( allowEmpty ) { myPopup = new QPopupMenu(); } @@ -172,29 +168,29 @@ bool QtxActionMenuMgr::MenuAction::addTo( QWidget* w ) if ( !myEmptyEnabled && !myPopup->count() ) return false; // not allowed empty menu - if ( w->inherits( "QPopupMenu" ) ) { - + if ( w->inherits( "QPopupMenu" ) ) + { QValueList l = prepareIds( w ); int idx; - if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) { - + if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) + { QPopupMenu* pm = (QPopupMenu*)w; myIds[ w ] = pm->idAt( idx ); if ( myId != -1 ) - pm->setId( idx, myId ); + pm->setId( idx, myId ); setPopup( pm, myId != -1 ? myId : myIds[ w ], myPopup ); } } - else if ( w->inherits( "QMenuBar" ) ) { - + else if ( w->inherits( "QMenuBar" ) ) + { QValueList l = prepareIds( w ); int idx; - if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) { - + if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) + { QMenuBar* mb = (QMenuBar*)w; myIds[ w ] = mb->idAt( idx ); if ( myId != -1 ) - mb->setId( idx, myId ); + mb->setId( idx, myId ); setPopup( mb, myId != -1 ? myId : myIds[ w ], myPopup ); } } @@ -218,26 +214,26 @@ bool QtxActionMenuMgr::MenuAction::removeFrom( QWidget* w ) if ( myIds.find( w ) == myIds.end() ) return false; // not yet added - if ( w->inherits( "QPopupMenu" ) ) { - if ( myId != -1 ) { - - + if ( w->inherits( "QPopupMenu" ) ) + { + if ( myId != -1 ) + { QPopupMenu* pm = (QPopupMenu*)w; int idx = pm->indexOf( myId ); - if ( idx != -1 ) pm->setId( idx, myIds[ w ] ); - + if ( idx != -1 ) + pm->setId( idx, myIds[ w ] ); } myIds.remove( w ); return QtxAction::removeFrom( w );; } else if ( w->inherits( "QMenuBar" ) ) { - if ( myId != -1 ) { - + if ( myId != -1 ) + { QMenuBar* mb = (QMenuBar*)w; int idx = mb->indexOf( myId ); - if ( idx != -1 ) mb->setId( idx, myIds[ w ] ); - + if ( idx != -1 ) + mb->setId( idx, myIds[ w ] ); } myIds.remove( w ); return QtxAction::removeFrom( w ); @@ -259,7 +255,7 @@ QPopupMenu* QtxActionMenuMgr::MenuAction::popup() const */ QtxActionMenuMgr::QtxActionMenuMgr( QMainWindow* p ) : QtxActionMgr( p ), - myMenu( p ? p->menuBar() : 0 ) +myMenu( p ? p->menuBar() : 0 ) { myRoot.id = -1; myRoot.group = -1; @@ -278,7 +274,7 @@ QtxActionMenuMgr::QtxActionMenuMgr( QMainWindow* p ) */ QtxActionMenuMgr::QtxActionMenuMgr( QWidget* mw, QObject* p ) : QtxActionMgr( p ), - myMenu( mw ) +myMenu( mw ) { myRoot.id = -1; myRoot.group = -1; @@ -411,7 +407,7 @@ int QtxActionMenuMgr::insert( const int id, const int pId, const int group, cons node->idx = idx; node->group = group; - pNode->children.append( node ); + pNode->children.append( node ); triggerUpdate( pNode->id, false ); @@ -472,7 +468,7 @@ int QtxActionMenuMgr::insert( const QString& title, const int pId, const int gro node->idx = idx; node->id = myMenus.insert( gid, ma ).key(); - pNode->children.append( node ); + pNode->children.append( node ); triggerUpdate( pNode->id, false ); @@ -923,15 +919,15 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo a->removeFrom( mw ); } /* VSR: commented to allow direct creating of menus by calling insertItem() methods - if ( mw->inherits( "QMenuBar" ) ) - ((QMenuBar*)mw)->clear(); - else if ( mw->inherits( "QPopupMenu" ) ) - ((QPopupMenu*)mw)->clear(); + if ( mw->inherits( "QMenuBar" ) ) + ((QMenuBar*)mw)->clear(); + else if ( mw->inherits( "QPopupMenu" ) ) + ((QPopupMenu*)mw)->clear(); */ QMap idMap; for ( NodeListIterator it2( node->children ); it2.current(); ++it2 ) { - NodeList& lst = idMap[it2.current()->group]; + NodeList& lst = idMap[it2.current()->group]; int idx = it2.current()->idx; if ( idx < 0 || idx >= (int)lst.count() ) lst.append( it2.current() ); @@ -953,21 +949,18 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo const NodeList& lst = idMap[*gIt]; for ( NodeListIterator iter( lst ); iter.current(); ++iter ) { - - + if ( rec ) + updateMenu( iter.current(), rec, false ); MenuNode* par = iter.current()->parent; if ( !isVisible( iter.current()->id, par ? par->id : -1 ) ) continue; - if ( rec ) - updateMenu( iter.current(), rec, false ); - QAction* a = itemAction( iter.current()->id ); if ( !a ) a = menuAction( iter.current()->id ); if ( a ) - a->addTo( mw ); + a->addTo( mw ); } } @@ -982,11 +975,11 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo */ void QtxActionMenuMgr::internalUpdate() { - if ( isUpdatesEnabled() ) - - - updateMenu(); + if ( !isUpdatesEnabled() ) + return; + updateMenu(); + myUpdateIds.clear(); } /*! @@ -1120,16 +1113,16 @@ void QtxActionMenuMgr::triggerUpdate( const int id, const bool rec ) */ void QtxActionMenuMgr::updateContent() { - - - - - - - + // Warning: For correct updating it is necessary to update the most enclosed submenu firstly + // because not updated empty submenu will be skipped. Now the submenu are iterated in + // ascending order their identifiers. For a submenu with automatically generated identifiers + // will work correctly as the uppermost submenu have the biggest number (identifiers generated + // reduction from -1). Generally when any submenu will have positive identifiers are obviously + // appropriated can to work not truly. In this case it is required to improve the given method + // and to add preliminary sorting a submenu on depth of an enclosure. for ( QMap::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it ) { - MenuNode* node = find( it.key(), 0 ); + MenuNode* node = it.key() == -1 ? &myRoot : find( it.key() ); if ( node ) updateMenu( node, it.data() ); } @@ -1141,10 +1134,9 @@ void QtxActionMenuMgr::updateContent() \param r - menu reader \param mgr - menu manager */ -QtxActionMenuMgr::MenuCreator::MenuCreator( QtxActionMgr::Reader* r, - QtxActionMenuMgr* mgr ) +QtxActionMenuMgr::MenuCreator::MenuCreator( QtxActionMgr::Reader* r, QtxActionMenuMgr* mgr ) : QtxActionMgr::Creator( r ), - myMgr( mgr ) +myMgr( mgr ) { } diff --git a/src/Qtx/QtxActionMgr.cxx b/src/Qtx/QtxActionMgr.cxx index 11bd7c4bf..b4acf9880 100644 --- a/src/Qtx/QtxActionMgr.cxx +++ b/src/Qtx/QtxActionMgr.cxx @@ -314,12 +314,12 @@ void QtxActionMgr::setVisible( const int, const int, const bool ) */ void QtxActionMgr::update() { - if ( isUpdatesEnabled() ) - - - internalUpdate(); - + if ( !isUpdatesEnabled() ) + return; + internalUpdate(); + if ( myUpdTimer ) + myUpdTimer->stop(); } /*! @@ -467,8 +467,8 @@ void QtxActionMgr::Reader::setOption( const QString& name, const QString& value /*! - Constructor - + Class: QtxActionMgr::XMLReader + Level: Public */ QtxActionMgr::XMLReader::XMLReader( const QString& root, const QString& item, @@ -609,11 +609,11 @@ bool QtxActionMgr::XMLReader::isNodeSimilar( const QDomNode& node, /*! + Class: QtxActionMgr::Creator + Level: Public +*/ - - - - +/*! \return integer value by attributes \param attrs - attributes \param name - name of attribute @@ -697,4 +697,3 @@ bool QtxActionMgr::Creator::loadPixmap( const QString& fname, QPixmap& pix ) con return res; } - diff --git a/src/Qtx/QtxActionToolMgr.cxx b/src/Qtx/QtxActionToolMgr.cxx index e1727f189..4202b438f 100644 --- a/src/Qtx/QtxActionToolMgr.cxx +++ b/src/Qtx/QtxActionToolMgr.cxx @@ -447,13 +447,13 @@ void QtxActionToolMgr::updateToolBar( const int tId ) */ void QtxActionToolMgr::internalUpdate() { - - + if ( !isUpdatesEnabled() ) + return; for ( ToolBarMap::ConstIterator it1 = myToolBars.begin(); it1 != myToolBars.end(); ++it1 ) updateToolBar( it1.key() ); - + myUpdateIds.clear(); } /*! @@ -604,8 +604,8 @@ void QtxActionToolMgr::triggerUpdate( const int id ) } /*! - Constructor - + Class: QtxActionToolMgr::ToolCreator + Level: Public */ QtxActionToolMgr::ToolCreator::ToolCreator( QtxActionMgr::Reader* r, QtxActionToolMgr* mgr ) diff --git a/src/Qtx/QtxLogoMgr.cxx b/src/Qtx/QtxLogoMgr.cxx index 2103eccae..aa1189152 100644 --- a/src/Qtx/QtxLogoMgr.cxx +++ b/src/Qtx/QtxLogoMgr.cxx @@ -14,7 +14,7 @@ // 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/ // #include "QtxLogoMgr.h" @@ -27,9 +27,6 @@ #include #include -/*! - Constructor -*/ QtxLogoMgr::QtxLogoMgr( QMenuBar* mb ) : QObject( mb ), myMenus( mb ), @@ -37,9 +34,6 @@ myId( 0 ) { } -/*! - Destructor -*/ QtxLogoMgr::~QtxLogoMgr() { } @@ -112,9 +106,6 @@ void QtxLogoMgr::clear() generate(); } -/*! - Inserts logo to menu bar -*/ void QtxLogoMgr::generate() { if ( !menuBar() ) @@ -178,16 +169,12 @@ void QtxLogoMgr::generate() QApplication::sendPostedEvents( cnt, QEvent::ChildInserted ); cnt->addSpacing( 2 ); - myId = menuBar()->insertItem( cnt ); + myId = menuBar()->insertItem( cnt, INT_MAX ); QApplication::sendPostedEvents( menuBar()->parentWidget(), QEvent::LayoutHint ); QApplication::postEvent( menuBar()->parentWidget(), new QEvent( QEvent::LayoutHint ) ); } -/*! - \return index of found logo - \param id - logo id -*/ int QtxLogoMgr::find( const QString& id ) const { int idx = -1; diff --git a/src/Qtx/QtxPopupMgr.cxx b/src/Qtx/QtxPopupMgr.cxx index 3b3dc8131..7de68d2b2 100644 --- a/src/Qtx/QtxPopupMgr.cxx +++ b/src/Qtx/QtxPopupMgr.cxx @@ -553,19 +553,27 @@ bool QtxPopupMgr::isSatisfied( QAction* act, bool visibility ) const QMap,int> aCorteges; QValueList c; - if( specific.count()>0 ) - if( myCurrentSelection ) + if ( specific.count() ) + { + if ( myCurrentSelection ) { - res = false; - - for( int i=0, n=myCurrentSelection->count(); iparam( i, *anIt1 ) ); - aCorteges.insert( c, 0 ); - } + res = false; + if ( myCurrentSelection->count() ) + { + for( int i = 0, n = myCurrentSelection->count(); i < n && !res; i++ ) + { + c.clear(); + for ( QStringList::const_iterator anIt1 = specific.begin(); anIt1 != specific.end(); anIt1++ ) + c.append( myCurrentSelection->param( i, *anIt1 ) ); + aCorteges.insert( c, 0 ); + } + } + else + { + for ( QStringList::const_iterator anIt1 = specific.begin(); anIt1 != specific.end(); anIt1++ ) + c.append( QtxValue() ); + aCorteges.insert( c, 0 ); + } //qDebug( QString( "%1 corteges" ).arg( aCorteges.count() ) ); QMap,int>::const_iterator anIt = aCorteges.begin(), aLast = aCorteges.end(); @@ -589,7 +597,8 @@ bool QtxPopupMgr::isSatisfied( QAction* act, bool visibility ) const }*/ } else - res = false; + res = false; + } else res = result( p ); } @@ -623,12 +632,13 @@ void QtxPopupMgr::updatePopup( QPopupMenu* p, Selection* sel ) if( !p || !sel ) return; - myCurrentSelection = new QtxCacheSelection( sel ); - RulesMap::iterator anIt = myToggle.begin(), - aLast = myToggle.end(); - for( ; anIt!=aLast; anIt++ ) - if( anIt.key()->isToggleAction() && hasRule( anIt.key(), false ) ) + setSelection( sel ); + + for ( RulesMap::iterator anIt = myToggle.begin(); anIt != myToggle.end(); anIt++ ) + { + if ( anIt.key()->isToggleAction() && hasRule( anIt.key(), false ) ) anIt.key()->setOn( isSatisfied( anIt.key(), false ) ); + } setWidget( ( QWidget* )p ); updateMenu(); @@ -636,8 +646,19 @@ void QtxPopupMgr::updatePopup( QPopupMenu* p, Selection* sel ) qDebug( QString( "update popup time = %1 msecs" ).arg( t1.msecsTo( t2 ) ) ); qDebug( QString( "number of objects = %1" ).arg( myCurrentSelection->count() ) ); + setSelection( 0 ); +} + +void QtxPopupMgr::setSelection( Selection* s ) +{ + if ( myCurrentSelection == s ) + return; + delete myCurrentSelection; myCurrentSelection = 0; + + if ( s ) + myCurrentSelection = new QtxCacheSelection( s ); } /*! diff --git a/src/Qtx/QtxPopupMgr.h b/src/Qtx/QtxPopupMgr.h index 7bc260b3b..454ddc558 100644 --- a/src/Qtx/QtxPopupMgr.h +++ b/src/Qtx/QtxPopupMgr.h @@ -98,6 +98,7 @@ protected: typedef QMap< QAction*, QtxParser* > RulesMap; protected: + void setSelection( Selection* ); virtual bool isSatisfied( QAction*, bool visibility ) const; void setParams( QtxParser*, QStringList& ) const; RulesMap& map( bool visibility ) const;