From a7db67ce4217ef3996e0fe20ecb9d26e15c9209c Mon Sep 17 00:00:00 2001 From: stv Date: Thu, 24 Aug 2006 04:48:02 +0000 Subject: [PATCH] Unnecessary construction "dynamic_cast" was replaced by "qt_cast". Construction "dynamic_cast" not work when Qt library was compiled without RTTI support. Function "qt_cast" should be used for QObject's descendants if it possible. --- src/Qtx/QtxAction.cxx | 13 ++++++---- src/Qtx/QtxActionMenuMgr.cxx | 47 +++++++++++++++++++++++------------- src/Qtx/QtxWorkstack.cxx | 17 +++++++------ 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/Qtx/QtxAction.cxx b/src/Qtx/QtxAction.cxx index 06f87329c..dbae4819f 100755 --- a/src/Qtx/QtxAction.cxx +++ b/src/Qtx/QtxAction.cxx @@ -238,14 +238,17 @@ void QtxAction::setPopup( QWidget* w, const int id, QPopupMenu* subPopup ) const if ( !w ) return; - if ( !w->inherits( "QPopupMenu" ) && !w->inherits( "QMenuBar" ) ) - return; // unsupported widget type + QMenuData* pmd = 0; + + if ( w->inherits( "QPopupMenu" ) ) + pmd = ::qt_cast( w ); + else if ( w->inherits( "QMenuBar" ) ) + pmd = ::qt_cast( w ); - QMenuData* md = 0; - QMenuData* pmd = dynamic_cast( w ); if ( !pmd ) return; // bad widget - + + QMenuData* md = 0; QMenuItem* item = pmd->findItem( id, &md ); if ( !item || md != pmd ) return; // item is not found diff --git a/src/Qtx/QtxActionMenuMgr.cxx b/src/Qtx/QtxActionMenuMgr.cxx index b87289a33..94f7050a0 100644 --- a/src/Qtx/QtxActionMenuMgr.cxx +++ b/src/Qtx/QtxActionMenuMgr.cxx @@ -48,12 +48,12 @@ namespace { QValueList l; const QMenuData* md = 0; if ( w->inherits( "QMenuBar" ) ) - md = dynamic_cast( w ); + md = ::qt_cast( w ); else if ( w->inherits( "QPopupMenu" ) ) - md = dynamic_cast( w ); + md = ::qt_cast( w ); if ( md ) { - for ( int i=0; i < md->count(); i++ ) - l.append( md->idAt( i ) ); + for ( uint i = 0; i < md->count(); i++ ) + l.append( md->idAt( i ) ); } return l; } @@ -62,25 +62,38 @@ namespace { { const QMenuData* md = 0; if ( w->inherits( "QMenuBar" ) ) - md = dynamic_cast( w ); + md = ::qt_cast( w ); else if ( w->inherits( "QPopupMenu" ) ) - md = dynamic_cast( w ); - if ( md ) { - for ( int i=0, j=0; i < md->count() && j < l.count(); i++, j++ ) - if ( md->idAt( i ) != l[ j ] ) return retId ? md->idAt( i ) : i; - if ( md->count() > l.count() ) return retId ? md->idAt( md->count()-1 ) : md->count()-1; + md = ::qt_cast( w ); + if ( md ) + { + for ( uint i = 0, j = 0; i < md->count() && j < l.count(); i++, j++ ) + if ( md->idAt( i ) != l[ j ] ) + return retId ? md->idAt( i ) : i; + if ( md->count() > l.count() ) + return retId ? md->idAt( md->count()-1 ) : md->count() - 1; } return -1; } void dumpMenu( QWidget* w, bool before ) { - QMenuData* md = dynamic_cast( w ); - if ( !w ) return; - printf(">>> start dump menu (%s) >>>\n", before ? "before" : "after" ); - for( int i = 0; i < md->count(); i++ ) - printf("%d: %d: %s\n",i,md->idAt(i),md->text(md->idAt(i)).latin1() ); - printf("<<< end dump menu (%s) <<<\n", before ? "before" : "after" ); + if ( !w ) + return; + + QMenuData* md = 0; + if ( w->inherits( "QMenuBar" ) ) + md = ::qt_cast( w ); + else if ( w->inherits( "QPopupMenu" ) ) + md = ::qt_cast( w ); + + if ( !md ) + return; + + printf( ">>> start dump menu (%s) >>>\n", before ? "before" : "after" ); + for ( uint i = 0; i < md->count(); i++ ) + printf( "%d: %d: %s\n", i, md->idAt( i ), md->text( md->idAt( i ) ).latin1() ); + printf( "<<< end dump menu (%s) <<<\n", before ? "before" : "after" ); } }; @@ -914,7 +927,7 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo { NodeList& lst = idMap[it2.current()->group]; int idx = it2.current()->idx; - if ( idx < 0 || idx >= lst.count() ) + if ( idx < 0 || idx >= (int)lst.count() ) lst.append( it2.current() ); else lst.insert( idx, it2.current() ); diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index 0c4ff08d3..ac9779ce7 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -919,7 +919,7 @@ void QtxWorkstack::onDeactivated( QtxWorkstackArea* area ) */ void QtxWorkstack::onContextMenuRequested( QWidget* w, QPoint p ) { - QtxWorkstackArea* anArea = dynamic_cast( (QObject*)sender() ); + QtxWorkstackArea* anArea = ::qt_cast( (QObject*)sender() ); if ( !anArea ) anArea = activeArea(); @@ -1362,16 +1362,19 @@ QStringList getChildren( const QString& str ) int i = 1, nOpen = 1, // count brackets: '(' increments nOpen, ')' decrements start = 0; - while ( i < str.length() ) { - if ( str[i] == '(' ) { + while ( i < (int)str.length() ) + { + if ( str[i] == '(' ) + { nOpen++; if ( nOpen == 1 ) - start = i; + start = i; } - else if ( str[i] == ')' ) { + else if ( str[i] == ')' ) + { nOpen--; if ( nOpen == 0 ) - lst.append( str.mid( start, i-start+1 ) ); + lst.append( str.mid( start, i-start+1 ) ); } i++; } @@ -1403,7 +1406,7 @@ QWidget* getView( const QWidget* parent, const QString& aName ) QWidget* view = 0; QObjectList *l = parent->topLevelWidget()->queryList( "QWidget", aName, false, true ); if ( !l->isEmpty() ) - view = dynamic_cast( l->first() ); + view = ::qt_cast( l->first() ); delete l; return view; } -- 2.39.2