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();
}
/*!
*/
void LightApp_Application::loadDockWindowsState()
{
+ if ( !desktop() )
+ return;
+
bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
if( !store )
return;
for ( QList<QToolBar*>::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()] );
}
for ( QList<QDockWidget*>::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()] );
}
*/
void LightApp_Application::saveDockWindowsState()
{
+ if ( !desktop() )
+ return;
+
bool store = resourceMgr()->booleanValue( "Study", "store_positions", true );
if( !store )
return;
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.
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 );
bool isVisible() const;
protected:
+ enum { Update = QEvent::User, Remove };
+
virtual void customEvent( QEvent* );
private:
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 )
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 )
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;
}
\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;
+ }
}
/*!
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 )