diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview')
5 files changed, 32 insertions, 45 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro b/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro index 88526144fc..ae6de48195 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro @@ -1,6 +1,6 @@ CONFIG += testcase TARGET = tst_qgraphicsitem -QT += widgets widgets-private testlib +QT += widgets widgets-private testlib testlib-private QT += core-private gui-private SOURCES += tst_qgraphicsitem.cpp DEFINES += QT_NO_CAST_TO_ASCII diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 2abb6e3515..2220ef8d2f 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -28,10 +28,12 @@ #include <QtTest/QtTest> +#include <QtTest/private/qtesthelpers_p.h> #include <private/qgraphicsitem_p.h> #include <private/qgraphicsview_p.h> #include <private/qgraphicsscene_p.h> +#include <QRandomGenerator> #include <QStyleOptionGraphicsItem> #include <QAbstractTextDocumentLayout> #include <QBitmap> @@ -127,17 +129,6 @@ static void sendKeyClick(QGraphicsScene *scene, Qt::Key key) sendKeyRelease(scene, key); } -static inline void centerOnScreen(QWidget *w, const QSize &size) -{ - const QPoint offset = QPoint(size.width() / 2, size.height() / 2); - w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset); -} - -static inline void centerOnScreen(QWidget *w) -{ - centerOnScreen(w, w->geometry().size()); -} - class EventSpy : public QGraphicsWidget { Q_OBJECT @@ -3595,12 +3586,12 @@ void tst_QGraphicsItem::group() QList<QGraphicsItem *> newItems; for (int i = 0; i < 100; ++i) { QGraphicsItem *item = scene.addRect(QRectF(-25, -25, 50, 50), QPen(Qt::black, 0), - QBrush(QColor(rand() % 255, rand() % 255, - rand() % 255, rand() % 255))); + QBrush(QColor(QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255), + QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255)))); newItems << item; - item->setPos(-1000 + rand() % 2000, - -1000 + rand() % 2000); - item->setTransform(QTransform().rotate(rand() % 90), true); + item->setPos(-1000 + QRandomGenerator::global()->bounded(2000), + -1000 + QRandomGenerator::global()->bounded(2000)); + item->setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(90)), true); } view.fitInView(scene.itemsBoundingRect()); @@ -4143,8 +4134,8 @@ void tst_QGraphicsItem::ensureVisible() for (int x = -100; x < 100; x += 25) { for (int y = -100; y < 100; y += 25) { - int xmargin = rand() % 75; - int ymargin = rand() % 75; + int xmargin = QRandomGenerator::global()->bounded(75); + int ymargin = QRandomGenerator::global()->bounded(75); item->ensureVisible(x, y, 25, 25, xmargin, ymargin); QApplication::processEvents(); @@ -4211,7 +4202,7 @@ void tst_QGraphicsItem::cursor() QWidget topLevel; topLevel.resize(250, 150); - centerOnScreen(&topLevel); + QTestPrivate::centerOnScreen(&topLevel); QGraphicsView view(&scene,&topLevel); view.setFixedSize(200, 100); topLevel.show(); @@ -7137,7 +7128,7 @@ public: : QGraphicsRectItem(QRectF(-10, -10, 20, 20)) { setPen(QPen(Qt::black, 0)); - setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); + setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); } QTransform x; diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 7615c5e821..968233438a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -1507,10 +1507,10 @@ void tst_QGraphicsScene::mouseGrabberItem() QCOMPARE(scene.mouseGrabberItem(), topMostItem); // Geometrical changes should not affect the mouse grabber. - item->setZValue(rand() % 500); - item2->setZValue(rand() % 500); - item->setPos(rand() % 50000, rand() % 50000); - item2->setPos(rand() % 50000, rand() % 50000); + item->setZValue(QRandomGenerator::global()->bounded(500)); + item2->setZValue(QRandomGenerator::global()->bounded(500)); + item->setPos(QRandomGenerator::global()->bounded(50000), QRandomGenerator::global()->bounded(50000)); + item2->setPos(QRandomGenerator::global()->bounded(50000), QRandomGenerator::global()->bounded(50000)); } QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease); @@ -3424,7 +3424,7 @@ void tst_QGraphicsScene::task139710_bspTreeCrash() // add 1000 more items - the BSP tree is now resized for (int i = 0; i < 1000; ++i) { QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200)); - item->setPos(qrand() % 10000, qrand() % 10000); + item->setPos(QRandomGenerator::global()->bounded(10000), QRandomGenerator::global()->bounded(10000)); } // trigger delayed item indexing for the first 1000 items @@ -3433,7 +3433,7 @@ void tst_QGraphicsScene::task139710_bspTreeCrash() // add 1000 more items - the BSP tree is now resized for (int i = 0; i < 1000; ++i) { QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 200, 200)); - item->setPos(qrand() % 10000, qrand() % 10000); + item->setPos(QRandomGenerator::global()->bounded(10000), QRandomGenerator::global()->bounded(10000)); } // get items from the BSP tree and use them. there was junk in the tree @@ -3543,15 +3543,15 @@ void tst_QGraphicsScene::sorting() QGraphicsRectItem *c_2_1 = new QGraphicsRectItem(0, 0, 30, 30, c_2); QGraphicsRectItem *c_2_1_1 = new QGraphicsRectItem(0, 0, 20, 20, c_2_1); QGraphicsRectItem *c_2_2 = new QGraphicsRectItem(0, 0, 30, 30, c_2); - t_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); - c_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); - c_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); - c_1_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); - c_1_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); - c_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); - c_2_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); - c_2_1_1->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); - c_2_2->setBrush(QColor(qrand() % 256, qrand() % 256, qrand() % 256)); + t_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); + c_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); + c_1_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); + c_1_1_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); + c_1_2->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); + c_2->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); + c_2_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); + c_2_1_1->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); + c_2_2->setBrush(QColor(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))); c_1->setPos(23, 18); c_1_1->setPos(24, 28); diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro b/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro index 258b5e0e14..8ed19697a4 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro +++ b/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro @@ -3,7 +3,7 @@ testcase.timeout = 500 # this test is slow TARGET = tst_qgraphicsview QT += widgets widgets-private testlib -QT += core-private gui-private +QT += core-private gui-private testlib-private SOURCES += tst_qgraphicsview.cpp tst_qgraphicsview_2.cpp HEADERS += tst_qgraphicsview.h diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index ac38819385..f624bb6a5f 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -61,6 +61,10 @@ #include "tst_qgraphicsview.h" +#include <QtTest/private/qtesthelpers_p.h> + +using namespace QTestPrivate; + Q_DECLARE_METATYPE(ExpectedValueDescription) Q_DECLARE_METATYPE(QList<int>) Q_DECLARE_METATYPE(QList<QRectF>) @@ -130,14 +134,6 @@ class FriendlyGraphicsScene : public QGraphicsScene }; #endif -static inline void setFrameless(QWidget *w) -{ - Qt::WindowFlags flags = w->windowFlags(); - flags |= Qt::FramelessWindowHint; - flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); - w->setWindowFlags(flags); -} - class tst_QGraphicsView : public QObject { Q_OBJECT |