summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspositioners.cpp21
-rw-r--r--src/declarative/graphicsitems/qmlgraphicspositioners_p.h1
-rw-r--r--src/declarative/qml/qmlengine.cpp5
-rw-r--r--tests/auto/declarative/layouts/data/grid-animated.qml55
-rw-r--r--tests/auto/declarative/layouts/data/horizontal-animated.qml42
-rw-r--r--tests/auto/declarative/layouts/data/repeater.qml20
-rw-r--r--tests/auto/declarative/layouts/data/vertical-animated.qml42
-rw-r--r--tests/auto/declarative/layouts/tst_layouts.cpp229
8 files changed, 407 insertions, 8 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
index f599025..b4544c5 100644
--- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp
@@ -209,7 +209,12 @@ void QmlGraphicsBasePositioner::prePositioning()
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
}
QSet<QmlGraphicsItem *> allItems;
+ //Need to order children by creation order modified by stacking order
+ //###can we avoid using the QGraphicsItemPrivate?
QList<QGraphicsItem *> children = childItems();
+ qSort(children.begin(), children.end(), d->insertionOrder);
+ positionedItems = QList<QmlGraphicsItem*>();
+
for (int ii = 0; ii < children.count(); ++ii) {
QmlGraphicsItem *child = qobject_cast<QmlGraphicsItem *>(children.at(ii));
if (!child)
@@ -234,6 +239,7 @@ void QmlGraphicsBasePositioner::prePositioning()
d->_newItems+=child;
}
allItems += child;
+ positionedItems << child;
}
QSet<QmlGraphicsItem *> deletedItems = d->_items - allItems;
foreach(QmlGraphicsItem *child, d->_items){
@@ -497,9 +503,9 @@ void QmlGraphicsColumn::doPositioning()
}
}
- QList<QGraphicsItem *> children = childItems();
+ QList<QmlGraphicsItem *> children = positionedItems;
for (int ii = 0; ii < children.count(); ++ii) {
- QmlGraphicsItem *child = qobject_cast<QmlGraphicsItem *>(children.at(ii));
+ QmlGraphicsItem *child = children.at(ii);
if (!child || isInvisible(child))
continue;
@@ -653,9 +659,9 @@ void QmlGraphicsRow::doPositioning()
applyRemove(changes, item);
}
}
- QList<QGraphicsItem *> children = childItems();
+ QList<QmlGraphicsItem *> children = positionedItems;
for (int ii = 0; ii < children.count(); ++ii) {
- QmlGraphicsItem *child = qobject_cast<QmlGraphicsItem *>(children.at(ii));
+ QmlGraphicsItem *child = children.at(ii);
if (!child || isInvisible(child))
continue;
@@ -859,7 +865,7 @@ void QmlGraphicsGrid::doPositioning()
QList<int> maxColWidth;
QList<int> maxRowHeight;
int childIndex =0;
- QList<QGraphicsItem *> children = childItems();
+ QList<QmlGraphicsItem *> children = positionedItems;
for (int i=0; i<r; i++){
for (int j=0; j<c; j++){
if (j==0)
@@ -869,7 +875,7 @@ void QmlGraphicsGrid::doPositioning()
if (childIndex == children.count())
continue;
- QmlGraphicsItem *child = qobject_cast<QmlGraphicsItem *>(children.at(childIndex++));
+ QmlGraphicsItem *child = children.at(childIndex++);
if (!child || isInvisible(child))
continue;
if (child->width() > maxColWidth[j])
@@ -889,8 +895,7 @@ void QmlGraphicsGrid::doPositioning()
applyRemove(changes, item);
}
}
- foreach(QGraphicsItem* schild, children){
- QmlGraphicsItem *child = qobject_cast<QmlGraphicsItem *>(schild);
+ foreach(QmlGraphicsItem* child, children){
if (!child || isInvisible(child))
continue;
bool needMove = (child->x()!=xoffset)||(child->y()!=yoffset);
diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h
index 0011ec5..56adc8b 100644
--- a/src/declarative/graphicsitems/qmlgraphicspositioners_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p.h
@@ -104,6 +104,7 @@ private Q_SLOTS:
protected:
QmlGraphicsBasePositioner(QmlGraphicsBasePositionerPrivate &dd, AutoUpdateType at, QmlGraphicsItem *parent);
void setMovingItem(QmlGraphicsItem *);
+ QList<QmlGraphicsItem *> positionedItems;
private:
void applyTransition(const QList<QPair<QString, QVariant> >& changes, QmlGraphicsItem* target,
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 2926791..f81f2ed 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -626,6 +626,11 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi
url = QUrl(ctxt->argument(2).toString());
QObject *parentArg = activeEnginePriv->objectClass->toQObject(ctxt->argument(1));
QmlContext *qmlCtxt = qmlContext(parentArg);
+ if(!parentArg || !qmlCtxt){
+ //TODO: Could use a qmlInfo() like function for script functions
+ qWarning() << "createQmlObject called with invalid parent object";
+ return engine->nullValue();
+ }
if (url.isEmpty()) {
url = qmlCtxt->resolvedUrl(QUrl(QLatin1String("<Unknown File>")));
} else {
diff --git a/tests/auto/declarative/layouts/data/grid-animated.qml b/tests/auto/declarative/layouts/data/grid-animated.qml
new file mode 100644
index 0000000..9edccaf
--- /dev/null
+++ b/tests/auto/declarative/layouts/data/grid-animated.qml
@@ -0,0 +1,55 @@
+import Qt 4.6
+
+Item {
+ width: 640
+ height: 480
+ Grid {
+ columns: 3
+ add: Transition {
+ NumberAnimation {
+ properties: "x,y"; from: -100
+ }
+ }
+ remove: Transition {
+ NumberAnimation {
+ properties: "x,y"; to: -100
+ }
+ }
+ move: Transition {
+ NumberAnimation {
+ properties: "x,y";
+ }
+ }
+ Rectangle {
+ objectName: "one"
+ color: "red"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "two"
+ opacity: 0
+ color: "green"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "three"
+ color: "blue"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "four"
+ color: "cyan"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "five"
+ color: "magenta"
+ width: 50
+ height: 50
+ }
+ }
+}
diff --git a/tests/auto/declarative/layouts/data/horizontal-animated.qml b/tests/auto/declarative/layouts/data/horizontal-animated.qml
new file mode 100644
index 0000000..f757d18
--- /dev/null
+++ b/tests/auto/declarative/layouts/data/horizontal-animated.qml
@@ -0,0 +1,42 @@
+import Qt 4.6
+
+Item {
+ width: 640
+ height: 480
+ Row {
+ add: Transition {
+ NumberAnimation {
+ properties: "x"; from: -100
+ }
+ }
+ remove: Transition {
+ NumberAnimation {
+ properties: "x"; to: -100
+ }
+ }
+ move: Transition {
+ NumberAnimation {
+ properties: "x";
+ }
+ }
+ Rectangle {
+ objectName: "one"
+ color: "red"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "two"
+ color: "blue"
+ opacity: 0
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "three"
+ color: "red"
+ width: 50
+ height: 50
+ }
+ }
+}
diff --git a/tests/auto/declarative/layouts/data/repeater.qml b/tests/auto/declarative/layouts/data/repeater.qml
new file mode 100644
index 0000000..2bc5e94
--- /dev/null
+++ b/tests/auto/declarative/layouts/data/repeater.qml
@@ -0,0 +1,20 @@
+import Qt 4.6
+
+Item {
+ width: 640
+ height: 480
+ Row {
+ Repeater{ model: 3;
+ delegate: Component {
+ Rectangle {
+ color: "red"
+ width: 50
+ height: 50
+ z: {if(index == 0){2;}else if(index == 1){1;} else{3;}}
+ objectName: {if(index == 0){"one";}else if(index == 1){"two";} else{"three";}}
+
+ }
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/layouts/data/vertical-animated.qml b/tests/auto/declarative/layouts/data/vertical-animated.qml
new file mode 100644
index 0000000..f52a78a
--- /dev/null
+++ b/tests/auto/declarative/layouts/data/vertical-animated.qml
@@ -0,0 +1,42 @@
+import Qt 4.6
+
+Item {
+ width: 640
+ height: 480
+ Column {
+ add: Transition {
+ NumberAnimation {
+ properties: "y"; from: -100
+ }
+ }
+ remove: Transition {
+ NumberAnimation {
+ properties: "y"; to: -100
+ }
+ }
+ move: Transition {
+ NumberAnimation {
+ properties: "y";
+ }
+ }
+ Rectangle {
+ objectName: "one"
+ color: "red"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "two"
+ color: "blue"
+ opacity: 0
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "three"
+ color: "red"
+ width: 50
+ height: 50
+ }
+ }
+}
diff --git a/tests/auto/declarative/layouts/tst_layouts.cpp b/tests/auto/declarative/layouts/tst_layouts.cpp
index b0df57ea..c0c067a 100644
--- a/tests/auto/declarative/layouts/tst_layouts.cpp
+++ b/tests/auto/declarative/layouts/tst_layouts.cpp
@@ -53,11 +53,15 @@ public:
private slots:
void test_horizontal();
void test_horizontal_spacing();
+ void test_horizontal_animated();
void test_vertical();
void test_vertical_spacing();
+ void test_vertical_animated();
void test_grid();
void test_grid_spacing();
+ void test_grid_animated();
+ void test_repeater();
private:
QmlView *createView(const QString &filename);
};
@@ -114,6 +118,57 @@ void tst_QmlGraphicsLayouts::test_horizontal_spacing()
QCOMPARE(three->y(), 0.0);
}
+void tst_QmlGraphicsLayouts::test_horizontal_animated()
+{
+ QmlView *canvas = createView(SRCDIR "/data/horizontal-animated.qml");
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QTest::qWait(0);//Let the animation start
+ //Note that one and three animate in
+ QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one");
+ QVERIFY(one != 0);
+ QCOMPARE(one->x(), -100.0);
+
+ QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two");
+ QVERIFY(two != 0);
+ QCOMPARE(two->x(), 0.0);
+
+ QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three");
+ QVERIFY(three != 0);
+ QCOMPARE(three->x(), -100.0);
+
+ QTest::qWait(300);//Let the animation complete
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->opacity(), 0.0);
+ QCOMPARE(two->x(), 0.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 50.0);
+ QCOMPARE(three->y(), 0.0);
+
+ //Add 'two'
+ two->setOpacity(1.0);
+ QCOMPARE(two->opacity(), 1.0);
+ QTest::qWait(0);//Let the animation start
+ QCOMPARE(two->x(), -100.0);
+ QCOMPARE(three->x(), 50.0);
+ QTest::qWait(300);//Let the animation complete
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(three->x(), 100.0);
+
+ //Remove 'two'
+ two->setOpacity(0.0);
+ QCOMPARE(two->opacity(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(three->x(), 100.0);
+ QTest::qWait(300);//Let the animation complete
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(three->x(), 50.0);
+}
+
void tst_QmlGraphicsLayouts::test_vertical()
{
QmlView *canvas = createView(SRCDIR "/data/vertical.qml");
@@ -162,6 +217,57 @@ void tst_QmlGraphicsLayouts::test_vertical_spacing()
QCOMPARE(three->y(), 80.0);
}
+void tst_QmlGraphicsLayouts::test_vertical_animated()
+{
+ QmlView *canvas = createView(SRCDIR "/data/vertical-animated.qml");
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QTest::qWait(0);//Let the animation start
+ //Note that one and three animate in
+ QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one");
+ QVERIFY(one != 0);
+ QCOMPARE(one->y(), -100.0);
+
+ QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two");
+ QVERIFY(two != 0);
+ QCOMPARE(two->y(), 0.0);
+
+ QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three");
+ QVERIFY(three != 0);
+ QCOMPARE(three->y(), -100.0);
+
+ QTest::qWait(300);//Let the animation complete
+
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(two->opacity(), 0.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(two->x(), 0.0);
+ QCOMPARE(three->y(), 50.0);
+ QCOMPARE(three->x(), 0.0);
+
+ //Add 'two'
+ two->setOpacity(1.0);
+ QCOMPARE(two->opacity(), 1.0);
+ QTest::qWait(0);//Let the animation start
+ QCOMPARE(two->y(), -100.0);
+ QCOMPARE(three->y(), 50.0);
+ QTest::qWait(300);//Let the animation complete
+ QCOMPARE(two->y(), 50.0);
+ QCOMPARE(three->y(), 100.0);
+
+ //Remove 'two'
+ two->setOpacity(0.0);
+ QCOMPARE(two->opacity(), 0.0);
+ QCOMPARE(two->y(), 50.0);
+ QCOMPARE(three->y(), 100.0);
+ QTest::qWait(300);//Let the animation complete
+ QCOMPARE(two->y(), 50.0);
+ QCOMPARE(three->y(), 50.0);
+}
+
void tst_QmlGraphicsLayouts::test_grid()
{
QmlView *canvas = createView("data/grid.qml");
@@ -222,6 +328,129 @@ void tst_QmlGraphicsLayouts::test_grid_spacing()
QCOMPARE(five->y(), 54.0);
}
+void tst_QmlGraphicsLayouts::test_grid_animated()
+{
+ QmlView *canvas = createView(SRCDIR "/data/grid-animated.qml");
+ canvas->execute();
+ qApp->processEvents();
+
+ QTest::qWait(0);//Let the animation start
+ //Note that all but two animate in
+ QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one");
+ QVERIFY(one != 0);
+ QCOMPARE(one->x(), -100.0);
+ QCOMPARE(one->y(), -100.0);
+
+ QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two");
+ QVERIFY(two != 0);
+ QCOMPARE(two->x(), 0.0);
+ QCOMPARE(two->y(), 0.0);
+
+ QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three");
+ QVERIFY(three != 0);
+ QCOMPARE(three->x(), -100.0);
+ QCOMPARE(three->y(), -100.0);
+
+ QmlGraphicsRectangle *four = canvas->root()->findChild<QmlGraphicsRectangle*>("four");
+ QVERIFY(four != 0);
+ QCOMPARE(four->x(), -100.0);
+ QCOMPARE(four->y(), -100.0);
+
+ QmlGraphicsRectangle *five = canvas->root()->findChild<QmlGraphicsRectangle*>("five");
+ QVERIFY(five != 0);
+ QCOMPARE(five->x(), -100.0);
+ QCOMPARE(five->y(), -100.0);
+
+ QTest::qWait(300);//Let the animation complete
+
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(two->opacity(), 0.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(two->x(), 0.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(three->x(), 50.0);
+ QCOMPARE(four->y(), 0.0);
+ QCOMPARE(four->x(), 100.0);
+ QCOMPARE(five->y(), 50.0);
+ QCOMPARE(five->x(), 0.0);
+
+ //Add 'two'
+ two->setOpacity(1.0);
+ QCOMPARE(two->opacity(), 1.0);
+ QTest::qWait(0);//Let the animation start
+ QCOMPARE(two->x(), -100.0);
+ QCOMPARE(two->y(), -100.0);
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(three->x(), 50.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 100.0);
+ QCOMPARE(four->y(), 0.0);
+ QCOMPARE(five->x(), 0.0);
+ QCOMPARE(five->y(), 50.0);
+ QTest::qWait(300);//Let the animation complete
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(three->x(), 100.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 0.0);
+ QCOMPARE(four->y(), 50.0);
+ QCOMPARE(five->x(), 50.0);
+ QCOMPARE(five->y(), 50.0);
+
+ //Remove 'two'
+ two->setOpacity(0.0);
+ QCOMPARE(two->opacity(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(three->x(), 100.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 0.0);
+ QCOMPARE(four->y(), 50.0);
+ QCOMPARE(five->x(), 50.0);
+ QCOMPARE(five->y(), 50.0);
+ QTest::qWait(300);//Let the animation complete
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(three->x(), 50.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 100.0);
+ QCOMPARE(four->y(), 0.0);
+ QCOMPARE(five->x(), 0.0);
+ QCOMPARE(five->y(), 50.0);
+}
+
+void tst_QmlGraphicsLayouts::test_repeater()
+{
+ QmlView *canvas = createView("data/repeater.qml");
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QmlGraphicsRectangle *one = canvas->root()->findChild<QmlGraphicsRectangle*>("one");
+ QVERIFY(one != 0);
+
+ QmlGraphicsRectangle *two = canvas->root()->findChild<QmlGraphicsRectangle*>("two");
+ QVERIFY(two != 0);
+
+ QmlGraphicsRectangle *three = canvas->root()->findChild<QmlGraphicsRectangle*>("three");
+ QVERIFY(three != 0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 50.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 100.0);
+ QCOMPARE(three->y(), 0.0);
+}
+
QmlView *tst_QmlGraphicsLayouts::createView(const QString &filename)
{
QmlView *canvas = new QmlView(0);