summaryrefslogtreecommitdiff
path: root/src/widgets/graphicsview/qgraphicsscene_bsp.cpp
diff options
context:
space:
mode:
authorAndreas Klots <andreasklots@gmail.com>2020-10-05 16:19:11 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-10-06 10:48:20 +0000
commita8ad90665201218fa02b55ef2ed626c23c291036 (patch)
treed677af825c9fa5377ddfec3900b950306fa745f2 /src/widgets/graphicsview/qgraphicsscene_bsp.cpp
parent9714921fc16b74f0c467b6eaf3d6dc385d3f5970 (diff)
downloadqtbase-a8ad90665201218fa02b55ef2ed626c23c291036.tar.gz
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 Change-Id: I360033e94e22eb961f820278993754d10bfc1e45 Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 40874625f996899ca1e976f0240da697e784c2c6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/widgets/graphicsview/qgraphicsscene_bsp.cpp')
-rw-r--r--src/widgets/graphicsview/qgraphicsscene_bsp.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/widgets/graphicsview/qgraphicsscene_bsp.cpp b/src/widgets/graphicsview/qgraphicsscene_bsp.cpp
index 75eb50a3ac..9b05428c0a 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