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>
This commit is contained in:
parent
62fed23fef
commit
40874625f9
@ -190,7 +190,7 @@ void QGraphicsSceneBspTree::initialize(const QRectF &rect, int depth, int index)
|
|||||||
Node *node = &nodes[index];
|
Node *node = &nodes[index];
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
node->type = Node::Horizontal;
|
node->type = Node::Horizontal;
|
||||||
node->offset = rect.center().x();
|
node->offset = rect.center().y();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (depth) {
|
if (depth) {
|
||||||
@ -272,7 +272,7 @@ QRectF QGraphicsSceneBspTree::rectForIndex(int index) const
|
|||||||
QRectF rect = rectForIndex(parentIdx);
|
QRectF rect = rectForIndex(parentIdx);
|
||||||
const Node *parent = &nodes.at(parentIdx);
|
const Node *parent = &nodes.at(parentIdx);
|
||||||
|
|
||||||
if (parent->type == Node::Horizontal) {
|
if (parent->type == Node::Vertical) {
|
||||||
if (index & 1)
|
if (index & 1)
|
||||||
rect.setRight(parent->offset);
|
rect.setRight(parent->offset);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user