Fix QDockWidget's dock area permissions after hovering

When a QDockWidget's dock areas are restricted by setAllowedAreas(...)
and a second QDockWidget is hovered over it, the first QDockWidget can
be docked to any dock area of the main window. Area restrictions will
be ignored.
That is due to the first QDockWidget being implicitely mutated into a
QDockWidgetGroupWindow upon hovering. By definition, the latter has no
docking restricitons.
This fix adds a check if a QDockWidgetGroupWindow has a single QDockWidget child.
In that case, the single child's area permissions will restrict docking.

Fixes: QTBUG-100670
Pick-to: 6.3 6.2 5.15
Change-Id: I903b074739953791634f482c9cf4b9a95a1d93d3
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Axel Spoerl 2022-03-10 16:47:26 +01:00 committed by Axel Spoerl
parent 7d77deb281
commit dfe5f99120

View File

@ -2725,8 +2725,18 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos)
if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget))
allowed = dw->isAreaAllowed(toDockWidgetArea(path.at(1)));
if (qobject_cast<QDockWidgetGroupWindow *>(widget))
allowed = true;
// Read permissions from a DockWidgetGroupWindow depending on its DockWidget children
if (QDockWidgetGroupWindow* dwgw = qobject_cast<QDockWidgetGroupWindow *>(widget)) {
const QList<QDockWidget*> children = dwgw->findChildren<QDockWidget*>(QString(), Qt::FindDirectChildrenOnly);
if (children.count() == 1) {
// Group window has a single child => read its permissions
allowed = children.at(0)->isAreaAllowed(toDockWidgetArea(path.at(1)));
} else {
// Group window has more than one or no children => dock it anywhere
allowed = true;
}
}
#endif
#if QT_CONFIG(toolbar)
if (QToolBar *tb = qobject_cast<QToolBar*>(widget))