Don't show bogus empty window when calling QMainWindow::restoreState()
Qt doesn't create the actual QDockWidgets when restoring, the user must ensure they are created before restoring state. So lets not create an empty QDockWidgetGroupWindow which you can't close and with no tabs. Change-Id: If0a6aa7cf6f3932ff4274e03f787e27aef8fa53d Task-Id: QTBUG-57492 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
64666b9ee0
commit
461549c35a
@ -266,6 +266,16 @@ bool QDockAreaLayoutInfo::isEmpty() const
|
||||
return next(-1) == -1;
|
||||
}
|
||||
|
||||
bool QDockAreaLayoutInfo::onlyHasPlaceholders() const
|
||||
{
|
||||
for (const QDockAreaLayoutItem &item : item_list) {
|
||||
if (!item.placeHolderItem)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QSize QDockAreaLayoutInfo::minimumSize() const
|
||||
{
|
||||
if (isEmpty())
|
||||
|
@ -167,6 +167,7 @@ public:
|
||||
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
bool onlyHasPlaceholders() const;
|
||||
bool hasFixedSize() const;
|
||||
QList<int> findSeparator(const QPoint &pos) const;
|
||||
int next(int idx) const;
|
||||
|
@ -1030,11 +1030,18 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream,
|
||||
Qt::Horizontal, QTabBar::RoundedSouth, mainWindow);
|
||||
QRect geometry;
|
||||
stream >> geometry;
|
||||
if (!floatingTab->layoutInfo()->restoreState(stream, dockWidgets, false))
|
||||
QDockAreaLayoutInfo *info = floatingTab->layoutInfo();
|
||||
if (!info->restoreState(stream, dockWidgets, false))
|
||||
return false;
|
||||
geometry = QDockAreaLayout::constrainedRect(geometry, floatingTab);
|
||||
floatingTab->move(geometry.topLeft());
|
||||
floatingTab->resize(geometry.size());
|
||||
|
||||
// Don't show an empty QDockWidgetGroupWindow if no dock widget is available yet.
|
||||
// reparentWidgets() would be triggered by show(), so do it explicitly here.
|
||||
if (info->onlyHasPlaceholders())
|
||||
info->reparentWidgets(floatingTab);
|
||||
else
|
||||
floatingTab->show();
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user