diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2016-06-24 10:57:10 +0200 |
---|---|---|
committer | Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> | 2016-08-30 11:42:18 +0000 |
commit | 17e5d9d7cadb4fceb39cfc875162add57e962db8 (patch) | |
tree | c74432a231bf4e74be89693f6d1030f0163c152f /src/widgets/widgets/qmainwindowlayout.cpp | |
parent | 55ab276700b9631f230d15d2c2edc16371191c45 (diff) |
Fix QMainWindow::restoreDockWidget() with GroupedDragging
We need to account for the fact that the placeholder might be in a
floating tab.
Task-number: QTBUG-50491
Change-Id: I03d8e49cc40f58691154f5c3984f3b0670a974d5
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Sérgio Martins <sergio.martins@kdab.com>
Diffstat (limited to 'src/widgets/widgets/qmainwindowlayout.cpp')
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout.cpp | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 6b247d8d11..f581fe4d88 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -215,11 +215,10 @@ public: } void setGeometry(const QRect&r) Q_DECL_OVERRIDE { + static_cast<QDockWidgetGroupWindow *>(parent())->destroyOrHideIfEmpty(); QDockAreaLayoutInfo *li = layoutInfo(); - if (li->isEmpty()) { - static_cast<QDockWidgetGroupWindow *>(parent())->destroyIfEmpty(); + if (li->isEmpty()) return; - } int fw = frameWidth(); li->reparentWidgets(parentWidget()); li->rect = r.adjusted(fw, fw, -fw, -fw); @@ -272,6 +271,10 @@ bool QDockWidgetGroupWindow::event(QEvent *e) if (qobject_cast<QDockWidget *>(static_cast<QChildEvent*>(e)->child())) adjustFlags(); break; + case QEvent::LayoutRequest: + // We might need to show the widget again + destroyOrHideIfEmpty(); + break; default: break; } @@ -325,34 +328,43 @@ QDockWidget *QDockWidgetGroupWindow::topDockWidget() const } /*! \internal - Destroy this window if there is no more QDockWidget in it. + Destroy or hide this window if there is no more QDockWidget in it. + Otherwise make sure it is shown. */ -void QDockWidgetGroupWindow::destroyIfEmpty() -{ - if (layoutInfo()->isEmpty()) { - // Make sure to reparent the possibly floating or hidden QDockWidgets to the parent - foreach (QDockWidget *dw, - findChildren<QDockWidget *>(QString(), Qt::FindDirectChildrenOnly)) { - bool wasFloating = dw->isFloating(); - bool wasHidden = dw->isHidden(); - dw->setParent(parentWidget()); - if (wasFloating) { - dw->setFloating(true); - } else { - // maybe it was hidden, we still have to put it back in the main layout. - QMainWindowLayout *ml = qt_mainwindow_layout(static_cast<QMainWindow*>(parentWidget())); - Qt::DockWidgetArea area = ml->dockWidgetArea(this); - if (area == Qt::NoDockWidgetArea) - area = Qt::LeftDockWidgetArea; - static_cast<QMainWindow*>(parentWidget())->addDockWidget(area, dw); - } - if (!wasHidden) - dw->show(); +void QDockWidgetGroupWindow::destroyOrHideIfEmpty() +{ + if (!layoutInfo()->isEmpty()) { + show(); // It might have been hidden, + return; + } + // There might still be placeholders + if (!layoutInfo()->item_list.isEmpty()) { + hide(); + return; + } + + // Make sure to reparent the possibly floating or hidden QDockWidgets to the parent + foreach (QDockWidget *dw, findChildren<QDockWidget *>(QString(), Qt::FindDirectChildrenOnly)) { + bool wasFloating = dw->isFloating(); + bool wasHidden = dw->isHidden(); + dw->setParent(parentWidget()); + if (wasFloating) { + dw->setFloating(true); + } else { + // maybe it was hidden, we still have to put it back in the main layout. + QMainWindowLayout *ml = + qt_mainwindow_layout(static_cast<QMainWindow *>(parentWidget())); + Qt::DockWidgetArea area = ml->dockWidgetArea(this); + if (area == Qt::NoDockWidgetArea) + area = Qt::LeftDockWidgetArea; + static_cast<QMainWindow *>(parentWidget())->addDockWidget(area, dw); } - foreach (QTabBar *tb, findChildren<QTabBar *>(QString(), Qt::FindDirectChildrenOnly)) - tb->setParent(parentWidget()); - deleteLater(); + if (!wasHidden) + dw->show(); } + foreach (QTabBar *tb, findChildren<QTabBar *>(QString(), Qt::FindDirectChildrenOnly)) + tb->setParent(parentWidget()); + deleteLater(); } /*! \internal @@ -2075,7 +2087,7 @@ void QMainWindowLayout::animationFinished(QWidget *widget) item.subinfo->reparentWidgets(parentWidget()); item.subinfo->setTabBarShape(parentInfo->tabBarShape); } - dwgw->destroyIfEmpty(); + dwgw->destroyOrHideIfEmpty(); } if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { |