summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeanchors
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2010-04-14 03:18:03 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2010-04-14 03:21:55 (GMT)
commit37581fa549c5cbe56afc68c71fa97d8f933512c0 (patch)
tree621a068e2a786eec416facdce9aa2eccd92e36f2 /tests/auto/declarative/qdeclarativeanchors
parent298335af52cd39ad6683198674e799799d5b6d6f (diff)
downloadQt-37581fa549c5cbe56afc68c71fa97d8f933512c0.zip
Qt-37581fa549c5cbe56afc68c71fa97d8f933512c0.tar.gz
Qt-37581fa549c5cbe56afc68c71fa97d8f933512c0.tar.bz2
Bring support of anchors in QML for QGraphicsWidget derived classes.
This commit add a extension object to bring the anchors property for a QGraphicsWidget. The actual implement uses a separate object for storing the anchor pointer. In the future it would be nice if the extension object is the anchor itself. Also there are two connects extra for QGraphicsWidget one can perhaps disappear with a later commit. Only baseline case is not supported because QGraphicsWidget don't have any concept of baseline. Reviewed-by:akennedy
Diffstat (limited to 'tests/auto/declarative/qdeclarativeanchors')
-rw-r--r--tests/auto/declarative/qdeclarativeanchors/data/anchorsqgraphicswidget.qml163
-rw-r--r--tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp90
2 files changed, 253 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeanchors/data/anchorsqgraphicswidget.qml b/tests/auto/declarative/qdeclarativeanchors/data/anchorsqgraphicswidget.qml
new file mode 100644
index 0000000..ba424b9
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeanchors/data/anchorsqgraphicswidget.qml
@@ -0,0 +1,163 @@
+import Qt 4.6
+import Qt.widgets 4.7
+
+Rectangle {
+ color: "white"
+ width: 240
+ height: 320
+ Rectangle { id: masterRect; objectName: "masterRect"; x: 26; width: 96; height: 20; color: "red" }
+ QGraphicsWidget {
+ id: rect1; objectName: "rect1"
+ y: 20; width: 10; height: 10
+ anchors.left: masterRect.left
+ }
+ QGraphicsWidget {
+ id: rect2; objectName: "rect2"
+ y: 20; width: 10; height: 10
+ anchors.left: masterRect.right
+ }
+ QGraphicsWidget {
+ id: rect3; objectName: "rect3"
+ y: 20; width: 10; height: 10
+ anchors.left: masterRect.horizontalCenter
+ }
+ QGraphicsWidget {
+ id: rect4; objectName: "rect4"
+ y: 30; width: 10; height: 10
+ anchors.right: masterRect.left
+ }
+ QGraphicsWidget {
+ id: rect5; objectName: "rect5"
+ y: 30; width: 10; height: 10
+ anchors.right: masterRect.right
+ }
+ QGraphicsWidget {
+ id: rect6; objectName: "rect6"
+ y: 30; width: 10; height: 10
+ anchors.right: masterRect.horizontalCenter
+ }
+ QGraphicsWidget {
+ id: rect7; objectName: "rect7"
+ y: 50; width: 10; height: 10
+ anchors.left: parent.left
+ }
+ QGraphicsWidget {
+ id: rect8; objectName: "rect8"
+ y: 50; width: 10; height: 10
+ anchors.left: parent.right
+ }
+ QGraphicsWidget {
+ id: rect9; objectName: "rect9"
+ y: 50; width: 10; height: 10
+ anchors.left: parent.horizontalCenter
+ }
+ QGraphicsWidget {
+ id: rect10; objectName: "rect10"
+ y: 60; width: 10; height: 10
+ anchors.right: parent.left
+ }
+ QGraphicsWidget {
+ id: rect11; objectName: "rect11"
+ y: 60; width: 10; height: 10
+ anchors.right: parent.right
+ }
+ QGraphicsWidget {
+ id: rect12; objectName: "rect12"
+ y: 60; width: 10; height: 10
+ anchors.right: parent.horizontalCenter
+ }
+ QGraphicsWidget {
+ id: rect13; objectName: "rect13"
+ x: 200; width: 10; height: 10
+ anchors.top: masterRect.bottom
+ }
+ QGraphicsWidget {
+ id: rect14; objectName: "rect14"
+ width: 10; height: 10;
+ anchors.verticalCenter: parent.verticalCenter
+ }
+ QGraphicsWidget {
+ id: rect15; objectName: "rect15"
+ y: 200; height: 10
+ anchors.left: masterRect.left
+ anchors.right: masterRect.right
+ }
+ QGraphicsWidget {
+ id: rect16; objectName: "rect16"
+ y: 220; height: 10
+ anchors.left: masterRect.left
+ anchors.horizontalCenter: masterRect.right
+ }
+ QGraphicsWidget {
+ id: rect17; objectName: "rect17"
+ y: 240; height: 10
+ anchors.right: masterRect.right
+ anchors.horizontalCenter: masterRect.left
+ }
+ QGraphicsWidget {
+ id: rect18; objectName: "rect18"
+ x: 180; width: 10
+ anchors.top: masterRect.bottom
+ anchors.bottom: rect12.top
+ }
+ QGraphicsWidget {
+ id: rect19; objectName: "rect19"
+ y: 70; width: 10; height: 10
+ anchors.horizontalCenter: parent.horizontalCenter
+ }
+ QGraphicsWidget {
+ id: rect20; objectName: "rect20"
+ y: 70; width: 10; height: 10
+ anchors.horizontalCenter: parent.right
+ }
+ QGraphicsWidget {
+ id: rect21; objectName: "rect21"
+ y: 70; width: 10; height: 10
+ anchors.horizontalCenter: parent.left
+ }
+ QGraphicsWidget {
+ id: rect22; objectName: "rect22"
+ width: 10; height: 10
+ anchors.centerIn: masterRect
+ }
+ QGraphicsWidget {
+ id: rect23; objectName: "rect23"
+ anchors.left: masterRect.left
+ anchors.leftMargin: 5
+ anchors.right: masterRect.right
+ anchors.rightMargin: 5
+ anchors.top: masterRect.top
+ anchors.topMargin: 5
+ anchors.bottom: masterRect.bottom
+ anchors.bottomMargin: 5
+ }
+ QGraphicsWidget {
+ id: rect24; objectName: "rect24"
+ width: 10; height: 10
+ anchors.horizontalCenter: masterRect.left
+ anchors.horizontalCenterOffset: width/2
+ }
+ QGraphicsWidget {
+ id: rect25; objectName: "rect25"
+ width: 10; height: 10
+ anchors.verticalCenter: rect12.top
+ anchors.verticalCenterOffset: height/2
+ }
+ Rectangle {
+ id: rect26; objectName: "rect26"
+ width: 10; height: 10
+ anchors.baseline: masterRect.top
+ anchors.baselineOffset: height/2
+ }
+ Text {
+ id: text1; objectName: "text1"
+ y: 200;
+ text: "Hello"
+ }
+ Text {
+ id: text2; objectName: "text2"
+ anchors.baseline: text1.baseline
+ anchors.left: text1.right
+ text: "World"
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp
index 9eaa400..05974aa 100644
--- a/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp
+++ b/tests/auto/declarative/qdeclarativeanchors/tst_qdeclarativeanchors.cpp
@@ -40,6 +40,8 @@
****************************************************************************/
#include <qtest.h>
#include <QSignalSpy>
+#include <QtGui/QGraphicsWidget>
+#include <private/qgraphicsitem_p.h>
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
#include <QtDeclarative/qdeclarativeview.h>
@@ -59,9 +61,11 @@ public:
template<typename T>
T *findItem(QGraphicsObject *parent, const QString &id);
+ QGraphicsObject *findObject(QGraphicsObject *parent, const QString &objectName);
private slots:
void basicAnchors();
+ void basicAnchorsQGraphicsWidget();
void loops();
void illegalSets();
void illegalSets_data();
@@ -99,6 +103,25 @@ T *tst_qdeclarativeanchors::findItem(QGraphicsObject *parent, const QString &obj
return 0;
}
+QGraphicsObject *tst_qdeclarativeanchors::findObject(QGraphicsObject *parent, const QString &objectName)
+{
+ QList<QGraphicsItem *> children = parent->childItems();
+ for (int i = 0; i < children.count(); ++i) {
+ QGraphicsObject *item = children.at(i)->toGraphicsObject();
+ if (item) {
+ if (objectName.isEmpty() || item->objectName() == objectName) {
+ return item;
+ }
+ item = findObject(item, objectName);
+ if (item)
+ return item;
+ }
+ }
+
+ return 0;
+}
+
+
void tst_qdeclarativeanchors::basicAnchors()
{
QDeclarativeView *view = new QDeclarativeView;
@@ -166,6 +189,73 @@ void tst_qdeclarativeanchors::basicAnchors()
delete view;
}
+void tst_qdeclarativeanchors::basicAnchorsQGraphicsWidget()
+{
+ QDeclarativeView *view = new QDeclarativeView;
+ view->setSource(QUrl::fromLocalFile(SRCDIR "/data/anchorsqgraphicswidget.qml"));
+
+ qApp->processEvents();
+
+ //sibling horizontal
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect1"))->x(), 26.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect2"))->x(), 122.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect3"))->x(), 74.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect4"))->x(), 16.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect5"))->x(), 112.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect6"))->x(), 64.0);
+
+ //parent horizontal
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect7"))->x(), 0.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect8"))->x(), 240.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect9"))->x(), 120.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect10"))->x(), -10.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect11"))->x(), 230.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect12"))->x(), 110.0);
+
+ //vertical
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect13"))->y(), 20.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect14"))->y(), 155.0);
+
+ //stretch
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect15"))->x(), 26.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect15"))->property("width").toReal(), 96.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect16"))->x(), 26.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect16"))->property("width").toReal(), 192.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect17"))->x(), -70.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect17"))->property("width").toReal(), 192.0);
+
+ //vertical stretch
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect18"))->y(), 20.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect18"))->property("height").toReal(), 40.0);
+
+ //more parent horizontal
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect19"))->x(), 115.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect20"))->x(), 235.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect21"))->x(), -5.0);
+
+ //centerIn
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect22"))->x(), 69.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect22"))->y(), 5.0);
+
+ //margins
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect23"))->x(), 31.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect23"))->y(), 5.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect23"))->property("width").toReal(), 86.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect23"))->property("height").toReal(), 10.0);
+
+ // offsets
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect24"))->x(), 26.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect25"))->y(), 60.0);
+ QCOMPARE(findObject(view->rootObject(), QLatin1String("rect26"))->y(), 5.0);
+
+ //baseline
+ QDeclarativeText *text1 = findItem<QDeclarativeText>(view->rootObject(), QLatin1String("text1"));
+ QDeclarativeText *text2 = findItem<QDeclarativeText>(view->rootObject(), QLatin1String("text2"));
+ QCOMPARE(text1->y(), text2->y());
+
+ delete view;
+}
+
// mostly testing that we don't crash
void tst_qdeclarativeanchors::loops()
{