From 855680d24ee5e2e84d6f237bc7f95b6e08234157 Mon Sep 17 00:00:00 2001 From: stv Date: Tue, 5 Feb 2008 10:43:59 +0000 Subject: [PATCH] Bug fix for IPAL18646 --- src/LightApp/LightApp_Application.cxx | 26 ++++++++++++++-- src/Qtx/Qtx.cxx | 27 ++++++++++++++++ src/Qtx/Qtx.h | 1 + src/Qtx/QtxDockWidget.cxx | 45 +++++++++++++++++++-------- 4 files changed, 84 insertions(+), 15 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index af93f023e..6b7947f2c 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -2290,10 +2290,16 @@ void LightApp_Application::updateWindows() for ( WinMap::ConstIterator it = myWin.begin(); it != myWin.end(); ++it ) { QWidget* wid = it.value(); - wid->setVisible( activeStudy() && winMap.contains( it.key() ) ); + if ( activeStudy() ) + wid->setVisible( winMap.contains( it.key() ) ); + else + delete wid; } - loadDockWindowsState(); + if ( activeStudy() ) + loadDockWindowsState(); + else + myWin.clear(); } /*! @@ -2313,6 +2319,9 @@ void LightApp_Application::updateViewManagers() */ void LightApp_Application::loadDockWindowsState() { + if ( !desktop() ) + return; + bool store = resourceMgr()->booleanValue( "Study", "store_positions", true ); if( !store ) return; @@ -2334,6 +2343,11 @@ void LightApp_Application::loadDockWindowsState() for ( QList::iterator tit = tbList.begin(); tit != tbList.end(); ++tit ) { QToolBar* tb = *tit; + + QObject* po = Qtx::findParent( tb, "QMainWindow" ); + if ( po != desktop() ) + continue; + if ( tbMap.contains( tb->objectName() ) ) tb->setVisible( tbMap[tb->objectName()] ); } @@ -2342,6 +2356,11 @@ void LightApp_Application::loadDockWindowsState() for ( QList::iterator dit = dwList.begin(); dit != dwList.end(); ++dit ) { QDockWidget* dw = *dit; + + QObject* po = Qtx::findParent( dw, "QMainWindow" ); + if ( po != desktop() ) + continue; + if ( dwMap.contains( dw->objectName() ) ) dw->setVisible( dwMap[dw->objectName()] ); } @@ -2352,6 +2371,9 @@ void LightApp_Application::loadDockWindowsState() */ void LightApp_Application::saveDockWindowsState() { + if ( !desktop() ) + return; + bool store = resourceMgr()->booleanValue( "Study", "store_positions", true ); if( !store ) return; diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index a60911fd7..2a061c642 100755 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -303,6 +303,33 @@ bool Qtx::isParent( QObject* child, QObject* parent ) return res; } +/*! + \brief Find the parent object of class specified by \a className (in terms of QObject). + + \param obj current object + \param className class name of the parent + \return parent object or null pointer if the parent not found +*/ +QObject* Qtx::findParent( QObject* obj, const char* className ) +{ + if ( !obj ) + return 0; + + if ( !className || !strlen( className ) ) + return obj->parent(); + + QObject* res = 0; + QObject* p = obj->parent(); + while ( p && !res ) + { + if ( p->inherits( className ) ) + res = p; + p = p->parent(); + } + + return res; +} + /*! \brief Return directory part of the file path. diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index e13edd281..49ab74cae 100755 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -108,6 +108,7 @@ public: static void simplifySeparators( QWidget*, const bool = true ); static bool isParent( QObject*, QObject* ); + static QObject* findParent( QObject*, const char* ); static QString dir( const QString&, const bool = true ); static QString file( const QString&, const bool = true ); diff --git a/src/Qtx/QtxDockWidget.cxx b/src/Qtx/QtxDockWidget.cxx index fedca585d..5c39d9f1c 100644 --- a/src/Qtx/QtxDockWidget.cxx +++ b/src/Qtx/QtxDockWidget.cxx @@ -47,6 +47,8 @@ public: bool isVisible() const; protected: + enum { Update = QEvent::User, Remove }; + virtual void customEvent( QEvent* ); private: @@ -96,7 +98,7 @@ bool QtxDockWidget::Watcher::eventFilter( QObject* o, QEvent* e ) e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) { installFilters(); - QApplication::postEvent( this, new QEvent( QEvent::User ) ); + QApplication::postEvent( this, new QEvent( (QEvent::Type)Update ) ); } if ( o == myCont && e->type() == QEvent::ChildAdded ) @@ -105,7 +107,7 @@ bool QtxDockWidget::Watcher::eventFilter( QObject* o, QEvent* e ) if ( ce->child()->isWidgetType() ) ce->child()->installEventFilter( this ); - QApplication::postEvent( this, new QEvent( QEvent::User ) ); + QApplication::postEvent( this, new QEvent( (QEvent::Type)Update ) ); } if ( o != myCont && e->type() == QEvent::WindowIconChange ) @@ -115,10 +117,14 @@ bool QtxDockWidget::Watcher::eventFilter( QObject* o, QEvent* e ) updateCaption(); if ( ( o != myCont && ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) || - ( o == myCont && ( e->type() == QEvent::ChildRemoved ) ) || ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) ) updateVisibility(); + if ( o == myCont && e->type() == QEvent::ChildRemoved ) + { + QApplication::postEvent( this, new QEvent( (QEvent::Type)Remove ) ); + } + return false; } @@ -215,11 +221,19 @@ void QtxDockWidget::Watcher::hideContainer() \brief Proces custom events. \param e custom event (not used) */ -void QtxDockWidget::Watcher::customEvent( QEvent* /*e*/ ) +void QtxDockWidget::Watcher::customEvent( QEvent* e ) { - updateIcon(); - updateCaption(); - updateVisibility(); + if ( e->type() == Update ) + { + updateIcon(); + updateCaption(); + updateVisibility(); + } + else if ( myCont && e->type() == Remove && !myCont->widget() ) + { + myCont->deleteLater(); + myCont = 0; + } } /*! @@ -251,13 +265,18 @@ void QtxDockWidget::Watcher::updateVisibility() if ( !myCont ) return; - QLayout* l = myCont->layout(); - if ( !l ) - return; - bool vis = false; - for ( int i = 0; i < (int)l->count() && !vis; i++ ) - vis = l->itemAt( i ) && l->itemAt( i )->widget() && l->itemAt( i )->widget()->isVisibleTo( myCont ); + if ( myCont->widget() ) + vis = myCont->widget()->isVisibleTo( myCont ); + else + { + QLayout* l = myCont->layout(); + if ( l ) + { + for ( int i = 0; i < (int)l->count() && !vis; i++ ) + vis = l->itemAt( i ) && l->itemAt( i )->widget() && l->itemAt( i )->widget()->isVisibleTo( myCont ); + } + } bool empty = isEmpty(); if ( empty == vis ) -- 2.39.2