From 40874625f996899ca1e976f0240da697e784c2c6 Mon Sep 17 00:00:00 2001 From: Andreas Klots Date: Mon, 5 Oct 2020 16:19:11 +0200 Subject: [PATCH] Fix a bug in the initialization (and debug-output) of BSP trees On a horizontal split the current rectangle is split along the y-axis, creating two children with the dimensions [x, y, width, height / 2] and [x, y + height / 2, width, height / 2] respectively. When the BSP tree is initialized, the type of the root node is set to "Horizontal". However, the offset of the root node is wrongly initialized with a split along the x-axis instead of the y-axis. This leads to wrong behavior on QGraphicsScenes with a non square aspect ratio. E.g on a QGraphicsScene with an apsect ratio favoring the y-axis, every item between yItem = sceneWidth/2 and yItem = sceneHeight/2 will be added to the wrong leaf. [ChangeLog][QWidgets][QGraphicsScene] Fixed a bug in the initialization of BSP trees to increase the performance of QGraphicsScenes with non quadratic scene rectangles. Fixes: QTBUG-87174 Pick-to: 5.15 Change-Id: I360033e94e22eb961f820278993754d10bfc1e45 Reviewed-by: Lars Knoll --- src/widgets/graphicsview/qgraphicsscene_bsp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/graphicsview/qgraphicsscene_bsp.cpp b/src/widgets/graphicsview/qgraphicsscene_bsp.cpp index 75eb50a3ac0..9b05428c0a2 100644 --- a/src/widgets/graphicsview/qgraphicsscene_bsp.cpp +++ b/src/widgets/graphicsview/qgraphicsscene_bsp.cpp @@ -190,7 +190,7 @@ void QGraphicsSceneBspTree::initialize(const QRectF &rect, int depth, int index) Node *node = &nodes[index]; if (index == 0) { node->type = Node::Horizontal; - node->offset = rect.center().x(); + node->offset = rect.center().y(); } if (depth) { @@ -272,7 +272,7 @@ QRectF QGraphicsSceneBspTree::rectForIndex(int index) const QRectF rect = rectForIndex(parentIdx); const Node *parent = &nodes.at(parentIdx); - if (parent->type == Node::Horizontal) { + if (parent->type == Node::Vertical) { if (index & 1) rect.setRight(parent->offset); else