Update item anchors when the baseline offset changes.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Mon, 26 Mar 2012 02:04:00 +0000 (12:04 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 26 Mar 2012 02:42:15 +0000 (04:42 +0200)
Task-number: QTBUG-24303
Change-Id: I75fb8eb8afb48a3f40fa159d914ac12ab6bc9ffe
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>

src/quick/items/qquickitem.cpp
tests/auto/quick/qquickanchors/data/baselineOffset.qml [new file with mode: 0644]
tests/auto/quick/qquickanchors/tst_qquickanchors.cpp

index 201496c..9eae661 100644 (file)
@@ -3312,6 +3312,10 @@ void QQuickItem::setBaselineOffset(qreal offset)
                 anchor->updateVerticalAnchors();
         }
     }
+
+    if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
+        QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
+
     emit baselineOffsetChanged(offset);
 }
 
diff --git a/tests/auto/quick/qquickanchors/data/baselineOffset.qml b/tests/auto/quick/qquickanchors/data/baselineOffset.qml
new file mode 100644 (file)
index 0000000..8bae61d
--- /dev/null
@@ -0,0 +1,15 @@
+import QtQuick 2.0
+
+Item {
+    width: 200
+    height: 200
+
+    Item {
+        objectName: "baselineAnchored"
+
+        width: 200
+        height: 10
+
+        anchors.baseline: parent.verticalCenter
+    }
+}
index dd1f9f7..7b748f6 100644 (file)
@@ -84,6 +84,7 @@ private slots:
     void margins();
     void marginsRTL();
     void stretch();
+    void baselineOffset();
 };
 
 void tst_qquickanchors::basicAnchors()
@@ -705,6 +706,29 @@ void tst_qquickanchors::stretch()
     delete view;
 }
 
+void tst_qquickanchors::baselineOffset()
+{
+    QQmlEngine engine;
+    QQmlComponent component(&engine, testFileUrl("baselineOffset.qml"));
+    QScopedPointer<QObject> object(component.create());
+
+    QQuickItem *item = qobject_cast<QQuickItem  *>(object.data());
+    QVERIFY(item);
+
+    QQuickItem *anchoredItem = findItem<QQuickItem>(item, QLatin1String("baselineAnchored"));
+
+    QCOMPARE(anchoredItem->baselineOffset(), 0.0);
+    QCOMPARE(anchoredItem->y(), 100.0);
+
+    anchoredItem->setBaselineOffset(5);
+    QCOMPARE(anchoredItem->baselineOffset(), 5.0);
+    QCOMPARE(anchoredItem->y(), 95.0);
+
+    anchoredItem->setBaselineOffset(10);
+    QCOMPARE(anchoredItem->baselineOffset(), 10.0);
+    QCOMPARE(anchoredItem->y(), 90.0);
+}
+
 QTEST_MAIN(tst_qquickanchors)
 
 #include "tst_qquickanchors.moc"