aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCornelius Mika <cornelius.mika@gmail.com>2015-09-20 17:53:57 +0200
committerCornelius Mika <cornelius.mika@gmail.com>2015-10-31 18:42:49 +0000
commiteab47802925acb34a6785639bb34bfa97e58643f (patch)
tree389b30b09652b05d5adb4fcf80b943f9b98ba263
parent388e85f18b7f79c733c9b684de6907378f7a108a (diff)
Fix childrenRect calculation
Because the 'bottom' and 'right' variables were both initialized to 0, the bottom right corner of the children rect was clamped to coordinates >= (0, 0). Additionally, replace FLT_MAX with the more appropriate std::numeric_limits<qreal>::max(). Task-number: QTBUG-38732 Change-Id: I073b0b44737cf1faed5e4f6a5d466dd830d451bf Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/quick/items/qquickitem.cpp10
-rw-r--r--tests/auto/quick/qquickitem2/data/childrenRectBottomRightCorner.qml47
-rw-r--r--tests/auto/quick/qquickitem2/tst_qquickitem.cpp17
3 files changed, 69 insertions, 5 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index b6f35ad638..fd1b74d32d 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -72,7 +72,7 @@
#endif
#include <algorithm>
-#include <float.h>
+#include <limits>
// XXX todo Check that elements that create items handle memory correctly after visual ownership change
@@ -217,8 +217,8 @@ bool QQuickContents::calcHeight(QQuickItem *changed)
m_y = top;
m_height = bottom - top;
} else {
- qreal top = FLT_MAX;
- qreal bottom = 0;
+ qreal top = std::numeric_limits<qreal>::max();
+ qreal bottom = -std::numeric_limits<qreal>::max();
QList<QQuickItem *> children = m_item->childItems();
for (int i = 0; i < children.count(); ++i) {
QQuickItem *child = children.at(i);
@@ -252,8 +252,8 @@ bool QQuickContents::calcWidth(QQuickItem *changed)
m_x = left;
m_width = right - left;
} else {
- qreal left = FLT_MAX;
- qreal right = 0;
+ qreal left = std::numeric_limits<qreal>::max();
+ qreal right = -std::numeric_limits<qreal>::max();
QList<QQuickItem *> children = m_item->childItems();
for (int i = 0; i < children.count(); ++i) {
QQuickItem *child = children.at(i);
diff --git a/tests/auto/quick/qquickitem2/data/childrenRectBottomRightCorner.qml b/tests/auto/quick/qquickitem2/data/childrenRectBottomRightCorner.qml
new file mode 100644
index 0000000000..0b83e20b20
--- /dev/null
+++ b/tests/auto/quick/qquickitem2/data/childrenRectBottomRightCorner.qml
@@ -0,0 +1,47 @@
+import QtQuick 2.0
+
+Item {
+ width: 300
+ height: 300
+
+ Item {
+ anchors.centerIn: parent
+
+ Rectangle {
+ objectName: "childrenRectProxy"
+ x: container.childrenRect.x
+ y: container.childrenRect.y
+ width: container.childrenRect.width
+ height: container.childrenRect.height
+ color: "red"
+ opacity: 0.5
+ }
+
+ Item {
+ id: container
+
+ Rectangle {
+ x: -100
+ y: -100
+ width: 10
+ height: 10
+ color: "red"
+ }
+
+ Rectangle {
+ x: -60
+ y: -60
+ width: 10
+ height: 10
+ color: "red"
+ }
+ }
+
+ Rectangle {
+ id: origin
+ width: 5
+ height: 5
+ color: "black"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
index a31f7ab9ce..c7717b9cca 100644
--- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
@@ -104,6 +104,7 @@ private slots:
void childrenRectBug();
void childrenRectBug2();
void childrenRectBug3();
+ void childrenRectBottomRightCorner();
void childrenProperty();
void resourcesProperty();
@@ -2595,6 +2596,22 @@ void tst_QQuickItem::childrenRectBug3()
delete window;
}
+// QTBUG-38732
+void tst_QQuickItem::childrenRectBottomRightCorner()
+{
+ QQuickView *window = new QQuickView(0);
+ window->setSource(testFileUrl("childrenRectBottomRightCorner.qml"));
+ window->show();
+
+ QQuickItem *rect = window->rootObject()->findChild<QQuickItem*>("childrenRectProxy");
+ QCOMPARE(rect->x(), qreal(-100));
+ QCOMPARE(rect->y(), qreal(-100));
+ QCOMPARE(rect->width(), qreal(50));
+ QCOMPARE(rect->height(), qreal(50));
+
+ delete window;
+}
+
// QTBUG-13893
void tst_QQuickItem::transformCrash()
{