Improve code readability of QDockAreaLayout::separatorMove()

Constify variables where possible.
Store conditions in const booleans with meaningful names.
Rename local variable "index" to "dockPosition" and type it
accordingly.
Add code comments to explain code paths for internal and
external separators.

Task-number: QTBUG-136716
Pick-to: 6.8 6.5
Change-Id: I21b950f6790cfa49c822dcd4de2eaadfa2ffdce9
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit ca41ace3578e6e49e5e85dc951a336e8d1832b1a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Axel Spoerl 2025-05-13 09:56:38 +02:00 committed by Qt Cherry-pick Bot
parent 6ef8da2c41
commit 2e72ce2971

View File

@ -3322,36 +3322,45 @@ int QDockAreaLayout::separatorMove(const QList<int> &separator, const QPoint &or
const QPoint &dest)
{
int delta = 0;
int index = separator.last();
const auto dockPosition = static_cast<QInternal::DockPosition>(separator.last());
const bool isHorizontal = dockPosition == QInternal::LeftDock || dockPosition == QInternal::TopDock;
const bool isLeftOrTop = dockPosition == QInternal::LeftDock || dockPosition == QInternal::TopDock;
const bool separatorIsWithinDock = separator.size() > 1;
if (separator.size() > 1) {
if (separatorIsWithinDock) {
// The dock area contains more than one dock widget and therefore an internal separator,
// which is being moved. The move changes the sizes of the dock widgets docked in the dock area.
// The dock area's geometry remains unchanged.
QDockAreaLayoutInfo *info = this->info(separator);
delta = pick(info->o, dest - origin);
if (delta != 0)
delta = info->separatorMove(index, delta);
info->apply(false);
delta = info->separatorMove(dockPosition, delta);
info->apply(/* animate = */ false);
return delta;
}
// The dock area's external separator is moved. The move changes the size of the contained
// dock widgets, as well as the size of neighbouring dock areas and their docked dock widgets.
// If the move shrinks the contained dock widgets to their minimum size,
// the entire dock area will attempted to be moved, retaining the minumum size.
// If the contained dock widgets have to be shrunk below minimum size, they will be collapsed.
QList<QLayoutStruct> list;
if (index == QInternal::LeftDock || index == QInternal::RightDock)
if (isHorizontal)
getGrid(nullptr, &list);
else
getGrid(&list, nullptr);
int sep_index = index == QInternal::LeftDock || index == QInternal::TopDock
? 0 : 1;
Qt::Orientation o = index == QInternal::LeftDock || index == QInternal::RightDock
? Qt::Horizontal
: Qt::Vertical;
const int sep_index = isLeftOrTop ? 0 : 1;
const Qt::Orientation o = isHorizontal ? Qt::Horizontal : Qt::Vertical;
delta = pick(o, dest - origin);
delta = separatorMoveHelper(list, sep_index, delta, sep);
fallbackToSizeHints = false;
if (index == QInternal::LeftDock || index == QInternal::RightDock)
if (isHorizontal)
setGrid(nullptr, &list);
else
setGrid(&list, nullptr);