summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Klots <andreasklots@gmail.com>2020-10-05 16:19:11 +0200
committerLars Knoll <lars.knoll@qt.io>2020-10-06 08:26:57 +0000
commit40874625f996899ca1e976f0240da697e784c2c6 (patch)
treef2a3f77dfc3eeed49559737ba7a66a9f71f98bba
parent62fed23fefef0738ef55a17f96efd49e30313152 (diff)
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 <lars.knoll@qt.io>
-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