diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp | 108 |
1 files changed, 41 insertions, 67 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp b/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp index 4f2c310135..b6d48b52d5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp @@ -1,38 +1,14 @@ -/**************************************************************************** -** -** 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: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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** 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$ -** -****************************************************************************/ - - -#include <QtTest/QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include <QTest> #include <QtGui/QPainterPath> #include <QtWidgets/qgraphicsscene.h> #include <private/qgraphicsscenebsptreeindex_p.h> #include <private/qgraphicssceneindex_p.h> #include <private/qgraphicsscenelinearindex_p.h> +#include <QtWidgets/private/qapplication_p.h> class tst_QGraphicsSceneIndex : public QObject { @@ -73,7 +49,7 @@ void tst_QGraphicsSceneIndex::common_data() QGraphicsSceneIndex *tst_QGraphicsSceneIndex::createIndex(const QString &indexMethod) { - QGraphicsSceneIndex *index = 0; + QGraphicsSceneIndex *index = nullptr; QGraphicsScene *scene = new QGraphicsScene(); if (indexMethod == "bsp") index = new QGraphicsSceneBspTreeIndex(scene); @@ -99,13 +75,13 @@ void tst_QGraphicsSceneIndex::scatteredItems() for (int i = 0; i < 10; ++i) scene.addRect(i*50, i*50, 40, 35); - QCOMPARE(scene.items(QPointF(5, 5)).count(), 1); - QCOMPARE(scene.items(QPointF(55, 55)).count(), 1); - QCOMPARE(scene.items(QPointF(-100, -100)).count(), 0); + QCOMPARE(scene.items(QPointF(5, 5)).size(), 1); + QCOMPARE(scene.items(QPointF(55, 55)).size(), 1); + QCOMPARE(scene.items(QPointF(-100, -100)).size(), 0); - QCOMPARE(scene.items(QRectF(0, 0, 10, 10)).count(), 1); - QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 10); - QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).count(), 0); + QCOMPARE(scene.items(QRectF(0, 0, 10, 10)).size(), 1); + QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).size(), 10); + QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).size(), 0); } void tst_QGraphicsSceneIndex::overlappedItems_data() @@ -124,17 +100,17 @@ void tst_QGraphicsSceneIndex::overlappedItems() for (int j = 0; j < 10; ++j) scene.addRect(i*50, j*50, 200, 200)->setPen(QPen(Qt::black, 0)); - QCOMPARE(scene.items(QPointF(5, 5)).count(), 1); - QCOMPARE(scene.items(QPointF(55, 55)).count(), 4); - QCOMPARE(scene.items(QPointF(105, 105)).count(), 9); - QCOMPARE(scene.items(QPointF(-100, -100)).count(), 0); - - QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 100); - QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).count(), 0); - QCOMPARE(scene.items(QRectF(0, 0, 200, 200)).count(), 16); - QCOMPARE(scene.items(QRectF(0, 0, 100, 100)).count(), 4); - QCOMPARE(scene.items(QRectF(0, 0, 1, 100)).count(), 2); - QCOMPARE(scene.items(QRectF(0, 0, 1, 1000)).count(), 10); + QCOMPARE(scene.items(QPointF(5, 5)).size(), 1); + QCOMPARE(scene.items(QPointF(55, 55)).size(), 4); + QCOMPARE(scene.items(QPointF(105, 105)).size(), 9); + QCOMPARE(scene.items(QPointF(-100, -100)).size(), 0); + + QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).size(), 100); + QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).size(), 0); + QCOMPARE(scene.items(QRectF(0, 0, 200, 200)).size(), 16); + QCOMPARE(scene.items(QRectF(0, 0, 100, 100)).size(), 4); + QCOMPARE(scene.items(QRectF(0, 0, 1, 100)).size(), 2); + QCOMPARE(scene.items(QRectF(0, 0, 1, 1000)).size(), 10); } void tst_QGraphicsSceneIndex::movingItems_data() @@ -153,20 +129,20 @@ void tst_QGraphicsSceneIndex::movingItems() scene.addRect(i*50, i*50, 40, 35); QGraphicsRectItem *box = scene.addRect(0, 0, 10, 10); - QCOMPARE(scene.items(QPointF(5, 5)).count(), 2); - QCOMPARE(scene.items(QPointF(-1, -1)).count(), 0); - QCOMPARE(scene.items(QRectF(0, 0, 5, 5)).count(), 2); + QCOMPARE(scene.items(QPointF(5, 5)).size(), 2); + QCOMPARE(scene.items(QPointF(-1, -1)).size(), 0); + QCOMPARE(scene.items(QRectF(0, 0, 5, 5)).size(), 2); box->setPos(10, 10); - QCOMPARE(scene.items(QPointF(9, 9)).count(), 1); - QCOMPARE(scene.items(QPointF(15, 15)).count(), 2); - QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).count(), 1); + QCOMPARE(scene.items(QPointF(9, 9)).size(), 1); + QCOMPARE(scene.items(QPointF(15, 15)).size(), 2); + QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).size(), 1); box->setPos(-5, -5); - QCOMPARE(scene.items(QPointF(-1, -1)).count(), 1); - QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).count(), 2); + QCOMPARE(scene.items(QPointF(-1, -1)).size(), 1); + QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).size(), 2); - QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 11); + QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).size(), 11); } void tst_QGraphicsSceneIndex::connectedToSceneRectChanged() @@ -228,9 +204,9 @@ class CustomShapeItem : public QGraphicsItem public: CustomShapeItem(const QPainterPath &shape) : QGraphicsItem(0), mShape(shape) {} - QPainterPath shape() const { return mShape; } - QRectF boundingRect() const { return mShape.boundingRect(); } - void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) {} + QPainterPath shape() const override { return mShape; } + QRectF boundingRect() const override { return mShape.boundingRect(); } + void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override {} private: QPainterPath mShape; }; @@ -277,11 +253,11 @@ class RectWidget : public QGraphicsWidget { Q_OBJECT public: - RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) + RectWidget(QGraphicsItem *parent = nullptr) : QGraphicsWidget(parent) { } - void paint(QPainter *painter, const QStyleOptionGraphicsItem * /* option */, QWidget * /* widget */) + void paint(QPainter *painter, const QStyleOptionGraphicsItem * /* option */, QWidget * /* widget */) override { painter->setBrush(brush); painter->drawRect(boundingRect()); @@ -315,7 +291,6 @@ void tst_QGraphicsSceneIndex::removeItems() QGraphicsView view(&scene); view.resize(600, 600); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); scene.removeItem(widgetChild1); @@ -333,11 +308,11 @@ void tst_QGraphicsSceneIndex::clear() class MyItem : public QGraphicsItem { public: - MyItem(QGraphicsItem *parent = 0) : QGraphicsItem(parent), numPaints(0) {} + MyItem(QGraphicsItem *parent = nullptr) : QGraphicsItem(parent), numPaints(0) {} int numPaints; protected: - QRectF boundingRect() const { return QRectF(0, 0, 10, 10); } - void paint(QPainter * /* painter */, const QStyleOptionGraphicsItem *, QWidget *) + QRectF boundingRect() const override { return QRectF(0, 0, 10, 10); } + void paint(QPainter * /* painter */, const QStyleOptionGraphicsItem *, QWidget *) override { ++numPaints; } }; @@ -347,7 +322,6 @@ void tst_QGraphicsSceneIndex::clear() QGraphicsView view(&scene); view.show(); - qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); scene.clear(); |