aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickitem2
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquickitem2')
-rw-r--r--tests/auto/quick/qquickitem2/data/grabToImage.qml29
-rw-r--r--tests/auto/quick/qquickitem2/data/keysforward.qml29
-rw-r--r--tests/auto/quick/qquickitem2/data/mapCoordinates.qml29
-rw-r--r--tests/auto/quick/qquickitem2/data/mapCoordinatesRect.qml29
-rw-r--r--tests/auto/quick/qquickitem2/data/standardkeys.qml29
-rw-r--r--tests/auto/quick/qquickitem2/qquickitem2.pro1
-rw-r--r--tests/auto/quick/qquickitem2/tst_qquickitem.cpp277
7 files changed, 314 insertions, 109 deletions
diff --git a/tests/auto/quick/qquickitem2/data/grabToImage.qml b/tests/auto/quick/qquickitem2/data/grabToImage.qml
index 00535d8ee7..502472f120 100644
--- a/tests/auto/quick/qquickitem2/data/grabToImage.qml
+++ b/tests/auto/quick/qquickitem2/data/grabToImage.qml
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2014 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/tests/auto/quick/qquickitem2/data/keysforward.qml b/tests/auto/quick/qquickitem2/data/keysforward.qml
index 3b40c72322..3497eb06b7 100644
--- a/tests/auto/quick/qquickitem2/data/keysforward.qml
+++ b/tests/auto/quick/qquickitem2/data/keysforward.qml
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/tests/auto/quick/qquickitem2/data/mapCoordinates.qml b/tests/auto/quick/qquickitem2/data/mapCoordinates.qml
index a9c5030e12..4874a51ebb 100644
--- a/tests/auto/quick/qquickitem2/data/mapCoordinates.qml
+++ b/tests/auto/quick/qquickitem2/data/mapCoordinates.qml
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/tests/auto/quick/qquickitem2/data/mapCoordinatesRect.qml b/tests/auto/quick/qquickitem2/data/mapCoordinatesRect.qml
index c127407eae..2b856a27fc 100644
--- a/tests/auto/quick/qquickitem2/data/mapCoordinatesRect.qml
+++ b/tests/auto/quick/qquickitem2/data/mapCoordinatesRect.qml
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/tests/auto/quick/qquickitem2/data/standardkeys.qml b/tests/auto/quick/qquickitem2/data/standardkeys.qml
index aec2bdb143..c8a5923fe2 100644
--- a/tests/auto/quick/qquickitem2/data/standardkeys.qml
+++ b/tests/auto/quick/qquickitem2/data/standardkeys.qml
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
diff --git a/tests/auto/quick/qquickitem2/qquickitem2.pro b/tests/auto/quick/qquickitem2/qquickitem2.pro
index ac4200a8a3..37bfb68f1c 100644
--- a/tests/auto/quick/qquickitem2/qquickitem2.pro
+++ b/tests/auto/quick/qquickitem2/qquickitem2.pro
@@ -9,4 +9,3 @@ include (../../shared/util.pri)
TESTDATA = data/*
QT += core-private gui-private qml-private quick-private testlib
-DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
index 58dca5c1a3..a087efd6b8 100644
--- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -40,6 +35,7 @@
#include <QtGui/private/qinputmethod_p.h>
#include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquicktextinput_p.h>
+#include <QtQuick/private/qquickitemchangelistener_p.h>
#include <QtGui/qstylehints.h>
#include <private/qquickitem_p.h>
#include "../../shared/util.h"
@@ -112,6 +108,7 @@ private slots:
void childrenProperty();
void resourcesProperty();
+ void changeListener();
void transformCrash();
void implicitSize();
void qtbug_16871();
@@ -120,6 +117,7 @@ private slots:
void contains_data();
void contains();
void childAt();
+ void isAncestorOf();
void grab();
@@ -2339,8 +2337,8 @@ void tst_QQuickItem::mapCoordinates()
Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y)));
QCOMPARE(result.value<QPointF>(), qobject_cast<QQuickItem*>(a)->mapFromScene(QPointF(x, y)));
- QString warning1 = testFileUrl("mapCoordinates.qml").toString() + ":40:5: QML Item: mapToItem() given argument \"1122\" which is neither null nor an Item";
- QString warning2 = testFileUrl("mapCoordinates.qml").toString() + ":40:5: QML Item: mapFromItem() given argument \"1122\" which is neither null nor an Item";
+ QString warning1 = testFileUrl("mapCoordinates.qml").toString() + ":35:5: QML Item: mapToItem() given argument \"1122\" which is neither null nor an Item";
+ QString warning2 = testFileUrl("mapCoordinates.qml").toString() + ":35:5: QML Item: mapFromItem() given argument \"1122\" which is neither null nor an Item";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QVERIFY(QMetaObject::invokeMethod(root, "checkMapAToInvalid",
@@ -2402,8 +2400,8 @@ void tst_QQuickItem::mapCoordinatesRect()
Q_RETURN_ARG(QVariant, result), Q_ARG(QVariant, x), Q_ARG(QVariant, y), Q_ARG(QVariant, width), Q_ARG(QVariant, height)));
QCOMPARE(result.value<QRectF>(), qobject_cast<QQuickItem*>(a)->mapRectFromScene(QRectF(x, y, width, height)));
- QString warning1 = testFileUrl("mapCoordinatesRect.qml").toString() + ":40:5: QML Item: mapToItem() given argument \"1122\" which is neither null nor an Item";
- QString warning2 = testFileUrl("mapCoordinatesRect.qml").toString() + ":40:5: QML Item: mapFromItem() given argument \"1122\" which is neither null nor an Item";
+ QString warning1 = testFileUrl("mapCoordinatesRect.qml").toString() + ":35:5: QML Item: mapToItem() given argument \"1122\" which is neither null nor an Item";
+ QString warning2 = testFileUrl("mapCoordinatesRect.qml").toString() + ":35:5: QML Item: mapFromItem() given argument \"1122\" which is neither null nor an Item";
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
QVERIFY(QMetaObject::invokeMethod(root, "checkMapAToInvalid",
@@ -2698,6 +2696,202 @@ void tst_QQuickItem::childrenRectBottomRightCorner()
delete window;
}
+struct TestListener : public QQuickItemChangeListener
+{
+ TestListener(bool remove = false) : remove(remove) { reset(); }
+
+ void itemGeometryChanged(QQuickItem *, const QRectF &newGeometry, const QRectF &) override { ++itemGeometryChanges; value = newGeometry; }
+ void itemSiblingOrderChanged(QQuickItem *) override { ++itemSiblingOrderChanges; }
+ void itemVisibilityChanged(QQuickItem *) override { ++itemVisibilityChanges; }
+ void itemOpacityChanged(QQuickItem *) override { ++itemOpacityChanges; }
+ void itemRotationChanged(QQuickItem *) override { ++itemRotationChanges; }
+ void itemImplicitWidthChanged(QQuickItem *) override { ++itemImplicitWidthChanges; }
+ void itemImplicitHeightChanged(QQuickItem *) override { ++itemImplicitHeightChanges; }
+
+ void itemDestroyed(QQuickItem *item) override
+ {
+ ++itemDestructions;
+ // QTBUG-53453
+ if (remove)
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed);
+ }
+ void itemChildAdded(QQuickItem *item, QQuickItem *child) override
+ {
+ ++itemChildAdditions;
+ value = QVariant::fromValue(child);
+ // QTBUG-53453
+ if (remove)
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Children);
+ }
+ void itemChildRemoved(QQuickItem *item, QQuickItem *child) override
+ {
+ ++itemChildRemovals;
+ value = QVariant::fromValue(child);
+ // QTBUG-53453
+ if (remove)
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Children);
+ }
+ void itemParentChanged(QQuickItem *item, QQuickItem *parent) override
+ {
+ ++itemParentChanges;
+ value = QVariant::fromValue(parent);
+ // QTBUG-53453
+ if (remove)
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent);
+ }
+
+ QQuickAnchorsPrivate *anchorPrivate() override { return nullptr; }
+
+ void reset()
+ {
+ value = QVariant();
+ itemGeometryChanges = 0;
+ itemSiblingOrderChanges = 0;
+ itemVisibilityChanges = 0;
+ itemOpacityChanges = 0;
+ itemDestructions = 0;
+ itemChildAdditions = 0;
+ itemChildRemovals = 0;
+ itemParentChanges = 0;
+ itemRotationChanges = 0;
+ itemImplicitWidthChanges = 0;
+ itemImplicitHeightChanges = 0;
+ }
+
+ bool remove;
+ QVariant value;
+ int itemGeometryChanges;
+ int itemSiblingOrderChanges;
+ int itemVisibilityChanges;
+ int itemOpacityChanges;
+ int itemDestructions;
+ int itemChildAdditions;
+ int itemChildRemovals;
+ int itemParentChanges;
+ int itemRotationChanges;
+ int itemImplicitWidthChanges;
+ int itemImplicitHeightChanges;
+};
+
+void tst_QQuickItem::changeListener()
+{
+ QQuickItem item;
+ TestListener itemListener;
+ QQuickItemPrivate::get(&item)->addItemChangeListener(&itemListener, QQuickItemPrivate::Geometry | QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight |
+ QQuickItemPrivate::Opacity | QQuickItemPrivate::Rotation);
+
+ item.setImplicitWidth(50);
+ QCOMPARE(itemListener.itemImplicitWidthChanges, 1);
+ QCOMPARE(itemListener.itemGeometryChanges, 1);
+ QCOMPARE(itemListener.value, QVariant(QRectF(0,0,50,0)));
+
+ item.setImplicitHeight(50);
+ QCOMPARE(itemListener.itemImplicitHeightChanges, 1);
+ QCOMPARE(itemListener.itemGeometryChanges, 2);
+ QCOMPARE(itemListener.value, QVariant(QRectF(0,0,50,50)));
+
+ item.setWidth(100);
+ QCOMPARE(itemListener.itemGeometryChanges, 3);
+ QCOMPARE(itemListener.value, QVariant(QRectF(0,0,100,50)));
+
+ item.setHeight(100);
+ QCOMPARE(itemListener.itemGeometryChanges, 4);
+ QCOMPARE(itemListener.value, QVariant(QRectF(0,0,100,100)));
+
+ item.setOpacity(0.5);
+ QCOMPARE(itemListener.itemOpacityChanges, 1);
+
+ item.setRotation(90);
+ QCOMPARE(itemListener.itemRotationChanges, 1);
+
+ QQuickItem *parent = new QQuickItem;
+ TestListener parentListener;
+ QQuickItemPrivate::get(parent)->addItemChangeListener(&parentListener, QQuickItemPrivate::Children);
+
+ QQuickItem *child1 = new QQuickItem;
+ QQuickItem *child2 = new QQuickItem;
+ TestListener child1Listener;
+ TestListener child2Listener;
+ QQuickItemPrivate::get(child1)->addItemChangeListener(&child1Listener, QQuickItemPrivate::Parent | QQuickItemPrivate::SiblingOrder | QQuickItemPrivate::Destroyed);
+ QQuickItemPrivate::get(child2)->addItemChangeListener(&child2Listener, QQuickItemPrivate::Parent | QQuickItemPrivate::SiblingOrder | QQuickItemPrivate::Destroyed);
+
+ child1->setParentItem(parent);
+ QCOMPARE(parentListener.itemChildAdditions, 1);
+ QCOMPARE(parentListener.value, QVariant::fromValue(child1));
+ QCOMPARE(child1Listener.itemParentChanges, 1);
+ QCOMPARE(child1Listener.value, QVariant::fromValue(parent));
+
+ child2->setParentItem(parent);
+ QCOMPARE(parentListener.itemChildAdditions, 2);
+ QCOMPARE(parentListener.value, QVariant::fromValue(child2));
+ QCOMPARE(child2Listener.itemParentChanges, 1);
+ QCOMPARE(child2Listener.value, QVariant::fromValue(parent));
+
+ child2->stackBefore(child1);
+ QCOMPARE(child1Listener.itemSiblingOrderChanges, 1);
+ QCOMPARE(child2Listener.itemSiblingOrderChanges, 1);
+
+ child1->setParentItem(nullptr);
+ QCOMPARE(parentListener.itemChildRemovals, 1);
+ QCOMPARE(parentListener.value, QVariant::fromValue(child1));
+ QCOMPARE(child1Listener.itemParentChanges, 2);
+ QCOMPARE(child1Listener.value, QVariant::fromValue<QQuickItem *>(nullptr));
+
+ delete child1;
+ QCOMPARE(child1Listener.itemDestructions, 1);
+
+ delete child2;
+ QCOMPARE(parentListener.itemChildRemovals, 2);
+ QCOMPARE(parentListener.value, QVariant::fromValue(child2));
+ QCOMPARE(child2Listener.itemParentChanges, 2);
+ QCOMPARE(child2Listener.value, QVariant::fromValue<QQuickItem *>(nullptr));
+ QCOMPARE(child2Listener.itemDestructions, 1);
+
+ QQuickItemPrivate::get(parent)->removeItemChangeListener(&parentListener, QQuickItemPrivate::Children);
+ QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0);
+
+ // QTBUG-53453: all listeners should get invoked even if they remove themselves while iterating the listeners
+ QList<TestListener *> listeners;
+ for (int i = 0; i < 5; ++i)
+ listeners << new TestListener(true);
+
+ // itemChildAdded() x 5
+ foreach (TestListener *listener, listeners)
+ QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Children);
+ QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count());
+ child1 = new QQuickItem(parent);
+ foreach (TestListener *listener, listeners)
+ QCOMPARE(listener->itemChildAdditions, 1);
+ QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0);
+
+ // itemParentChanged() x 5
+ foreach (TestListener *listener, listeners)
+ QQuickItemPrivate::get(child1)->addItemChangeListener(listener, QQuickItemPrivate::Parent);
+ QCOMPARE(QQuickItemPrivate::get(child1)->changeListeners.count(), listeners.count());
+ child1->setParentItem(nullptr);
+ foreach (TestListener *listener, listeners)
+ QCOMPARE(listener->itemParentChanges, 1);
+ QCOMPARE(QQuickItemPrivate::get(child1)->changeListeners.count(), 0);
+
+ // itemChildRemoved() x 5
+ child1->setParentItem(parent);
+ foreach (TestListener *listener, listeners)
+ QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Children);
+ QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count());
+ delete child1;
+ foreach (TestListener *listener, listeners)
+ QCOMPARE(listener->itemChildRemovals, 1);
+ QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0);
+
+ // itemDestroyed() x 5
+ foreach (TestListener *listener, listeners)
+ QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Destroyed);
+ QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count());
+ delete parent;
+ foreach (TestListener *listener, listeners)
+ QCOMPARE(listener->itemDestructions, 1);
+}
+
// QTBUG-13893
void tst_QQuickItem::transformCrash()
{
@@ -2999,12 +3193,12 @@ void tst_QQuickItem::childAt()
child3.setParentItem(&parent);
QCOMPARE(parent.childAt(0, 0), &child1);
- QCOMPARE(parent.childAt(0, 100), &child1);
+ QCOMPARE(parent.childAt(0, 99), &child1);
QCOMPARE(parent.childAt(25, 25), &child1);
QCOMPARE(parent.childAt(25, 75), &child1);
QCOMPARE(parent.childAt(75, 25), &child1);
QCOMPARE(parent.childAt(75, 75), &child2);
- QCOMPARE(parent.childAt(150, 150), &child2);
+ QCOMPARE(parent.childAt(149, 149), &child2);
QCOMPARE(parent.childAt(25, 200), &child3);
QCOMPARE(parent.childAt(0, 150), static_cast<QQuickItem *>(0));
QCOMPARE(parent.childAt(300, 300), static_cast<QQuickItem *>(0));
@@ -3045,6 +3239,43 @@ void tst_QQuickItem::grab()
}
+void tst_QQuickItem::isAncestorOf()
+{
+ QQuickItem parent;
+
+ QQuickItem sub1;
+ sub1.setParentItem(&parent);
+
+ QQuickItem child1;
+ child1.setParentItem(&sub1);
+ QQuickItem child2;
+ child2.setParentItem(&sub1);
+
+ QQuickItem sub2;
+ sub2.setParentItem(&parent);
+
+ QQuickItem child3;
+ child3.setParentItem(&sub2);
+ QQuickItem child4;
+ child4.setParentItem(&sub2);
+
+ QVERIFY(parent.isAncestorOf(&sub1));
+ QVERIFY(parent.isAncestorOf(&sub2));
+ QVERIFY(parent.isAncestorOf(&child1));
+ QVERIFY(parent.isAncestorOf(&child2));
+ QVERIFY(parent.isAncestorOf(&child3));
+ QVERIFY(parent.isAncestorOf(&child4));
+ QVERIFY(sub1.isAncestorOf(&child1));
+ QVERIFY(sub1.isAncestorOf(&child2));
+ QVERIFY(!sub1.isAncestorOf(&child3));
+ QVERIFY(!sub1.isAncestorOf(&child4));
+ QVERIFY(sub2.isAncestorOf(&child3));
+ QVERIFY(sub2.isAncestorOf(&child4));
+ QVERIFY(!sub2.isAncestorOf(&child1));
+ QVERIFY(!sub2.isAncestorOf(&child2));
+ QVERIFY(!sub1.isAncestorOf(&sub1));
+ QVERIFY(!sub2.isAncestorOf(&sub2));
+}
QTEST_MAIN(tst_QQuickItem)