diff options
author | Axel Spoerl <axel.spoerl@qt.io> | 2023-11-08 16:50:35 +0100 |
---|---|---|
committer | Axel Spoerl <axel.spoerl@qt.io> | 2023-11-09 14:59:41 +0000 |
commit | c93ab8c2a015b40b9a487ed9f23a72aebea8d52a (patch) | |
tree | 3aab74d5cda5c14ebe3f9bedf81767996de4e8dc /src/widgets/widgets/qmainwindowlayout.cpp | |
parent | c02f8b9d4d9a6578bb2017bafbb963d09641383f (diff) |
QDockWidget: Remove "group" bool trap
The unplug() and startDrag() functions of QMainWindowLayout and
QDockWidget used a boolean argument specifying whether a single dock
widget or a group of dock widgets should be unplugged. The argument
defaulted to true.
That has lead to inconsistent unplug operations, broken item_lists and
crashes, especially when the methods were called without an argument.
To improve code readability, replace bool trap with a meaningful
enum. Remove default arguments, in order to force explicit calls.
This patch does not change behavior, it is just carved out to
facilitate reviews.
Task-number: QTBUG-118578
Task-number: QTBUG-118579
Pick-to: 6.6 6.5
Change-Id: I50341b055f0bb76c2797b2fb1126a10de1fee7dd
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/widgets/qmainwindowlayout.cpp')
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index f51fc41494..fc0bb07e86 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -1792,7 +1792,7 @@ void QMainWindowTabBar::mouseMoveEvent(QMouseEvent *e) QDockWidgetPrivate *dockPriv = static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(draggingDock)); QDockWidgetLayout *dwlayout = static_cast<QDockWidgetLayout *>(draggingDock->layout()); dockPriv->initDrag(dwlayout->titleArea().center(), true); - dockPriv->startDrag(false); + dockPriv->startDrag(QDockWidgetPrivate::DragScope::Widget); if (dockPriv->state) dockPriv->state->ctrlDrag = e->modifiers() & Qt::ControlModifier; } @@ -2552,25 +2552,25 @@ static QTabBar::Shape tabwidgetPositionToTabBarShape(QWidget *w) Returns the QLayoutItem of the dragged element. The layout item is kept in the layout but set as a gap item. */ -QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) +QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, QDockWidgetPrivate::DragScope scope) { #if QT_CONFIG(dockwidget) && QT_CONFIG(tabwidget) auto *groupWindow = qobject_cast<const QDockWidgetGroupWindow *>(widget->parentWidget()); if (!widget->isWindow() && groupWindow) { - if (group && groupWindow->tabLayoutInfo()) { + if (scope == QDockWidgetPrivate::DragScope::Group && groupWindow->tabLayoutInfo()) { // We are just dragging a floating window as it, not need to do anything, we just have to // look up the corresponding QWidgetItem* if it exists if (QDockAreaLayoutInfo *info = dockInfo(widget->parentWidget())) { QList<int> groupWindowPath = info->indexOf(widget->parentWidget()); return groupWindowPath.isEmpty() ? nullptr : info->item(groupWindowPath).widgetItem; } - qCDebug(lcQpaDockWidgets) << "Drag only:" << widget << "Group:" << group; + qCDebug(lcQpaDockWidgets) << "Drag only:" << widget << "Group:" << (scope == QDockWidgetPrivate::DragScope::Group); return nullptr; } QList<int> path = groupWindow->layoutInfo()->indexOf(widget); QDockAreaLayoutItem parentItem = groupWindow->layoutInfo()->item(path); QLayoutItem *item = parentItem.widgetItem; - if (group && path.size() > 1 + if (scope == QDockWidgetPrivate::DragScope::Group && path.size() > 1 && unplugGroup(this, &item, parentItem)) { qCDebug(lcQpaDockWidgets) << "Unplugging:" << widget << "from" << item; return item; @@ -2663,7 +2663,7 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { Q_ASSERT(path.constFirst() == 1); #if QT_CONFIG(tabwidget) - if (group && (dockOptions & QMainWindow::GroupedDragging) && path.size() > 3 + if (scope == QDockWidgetPrivate::DragScope::Group && (dockOptions & QMainWindow::GroupedDragging) && path.size() > 3 && unplugGroup(this, &item, layoutState.dockAreaLayout.item(path.mid(1, path.size() - 2)))) { path.removeLast(); |