Add Frame::detachTab()

The tab widget will be an implementation detail of FrameWidget and
not accessed by anyone
This commit is contained in:
Sergio Martins
2020-06-03 21:18:38 +01:00
parent e418725c13
commit 0a75d89848
5 changed files with 15 additions and 6 deletions

View File

@@ -254,14 +254,14 @@ void DockWidgetBase::setFloating(bool floats)
if (floats) {
d->saveTabIndex();
if (isTabbed()) {
TabWidget *tabWidget= d->parentTabWidget();
if (!tabWidget) {
qWarning() << "DockWidget::setFloating: Tabbed but no tabbar exists"
auto frame = this->frame();
if (!frame) {
qWarning() << "DockWidget::setFloating: Tabbed but no frame exists"
<< this;
Q_ASSERT(false);
}
tabWidget->detachTab(this);
frame->detachTab(this);
} else {
frame()->titleBar()->makeWindow();
}

View File

@@ -85,6 +85,9 @@ public:
///@brief removes a dockwidget from the frame
void removeWidget(DockWidgetBase *);
///@brief detaches this dock widget
virtual void detachTab(DockWidgetBase *) = 0;
void updateTitleAndIcon();
void updateTitleBarVisibility();
bool containsMouse(QPoint globalPos) const;

View File

@@ -83,6 +83,11 @@ QSize FrameWidget::maxSizeHint() const
return waste + biggestDockWidgetMaxSize();
}
void FrameWidget::detachTab(DockWidgetBase *dw)
{
tabWidget()->detachTab(dw);
}
QTabBar *FrameWidget::tabBar() const
{
auto tw = static_cast<QTabWidget*>(tabWidget()->asWidget());

View File

@@ -42,6 +42,7 @@ public:
protected:
void paintEvent(QPaintEvent *) override;
QSize maxSizeHint() const override;
void detachTab(DockWidgetBase *) override;
};

View File

@@ -2367,7 +2367,7 @@ void TestDocks::tst_setFloatingAfterDraggedFromTabToSideBySide()
// Detach tab
dock1->frame()->m_tabWidget->detachTab(dock2);
dock1->frame()->detachTab(dock2);
QVERIFY(layout->checkSanity());
auto fw2 = dock2->floatingWindow();
QVERIFY(fw2);
@@ -4345,7 +4345,7 @@ void TestDocks::tst_invalidLayoutAfterRestore()
// Detach dock2
QPointer<Frame> f2 = dock2->frame();
f2->m_tabWidget->detachTab(dock2);
f2->detachTab(dock2);
QVERIFY(!f2.data());
QTest::qWait(200); // Not sure why. Some event we're waiting for. TODO: Investigate
auto fw2 = dock2->floatingWindow();