summaryrefslogtreecommitdiff
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-10-14 17:46:16 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-10-14 17:46:34 +0200
commit440286655e0ca271506cf7cc02ad0dbf4baef9ca (patch)
tree896fa81adb8b14a69355a3a6cf64d06ec8173c9a /tests/auto/widgets
parent1e27ad1697187549151657ba187928e439300db7 (diff)
parente164d61ca8263fc4b46fdd916e1ea77c7dd2b735 (diff)
downloadqtbase-440286655e0ca271506cf7cc02ad0dbf4baef9ca.tar.gz
Merge remote-tracking branch 'origin/dev' into wip/cmake
Change-Id: I4a78428a8ea273b6960792e3b8043f816fa37fcf
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp9
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp1847
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp11
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp664
-rw-r--r--tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp260
-rw-r--r--tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp2
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp687
-rw-r--r--tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp141
-rw-r--r--tests/auto/widgets/itemviews/qitemview/viewstotest.cpp21
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp860
-rw-r--r--tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp444
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp1371
-rw-r--r--tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp411
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp1027
-rw-r--r--tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp853
-rw-r--r--tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp189
-rw-r--r--tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp10
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp14
-rw-r--r--tests/auto/widgets/styles/qstyle/tst_qstyle.cpp262
-rw-r--r--tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp407
-rw-r--r--tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp15
-rw-r--r--tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp6
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp4
-rw-r--r--tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp5
-rw-r--r--tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp12
-rw-r--r--tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp17
26 files changed, 4591 insertions, 4958 deletions
diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
index 243cb6483e..6091975acb 100644
--- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
+++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
@@ -2712,13 +2712,8 @@ void tst_QWizard::taskQTBUG_46894_nextButtonShortcut()
wizard.show();
QVERIFY(QTest::qWaitForWindowExposed(&wizard));
- if (wizard.button(QWizard::NextButton)->text() == "&Next") {
- QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(),
- QKeySequence(Qt::ALT | Qt::Key_Right));
- } else {
- QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(),
- QKeySequence::mnemonic(wizard.button(QWizard::NextButton)->text()));
- }
+ QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(),
+ QKeySequence::mnemonic(wizard.button(QWizard::NextButton)->text()));
}
}
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
index 72ea2ae31a..5d380c899b 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -56,9 +56,16 @@
#include <QLineEdit>
#include <QGraphicsLinearLayout>
#include <QTransform>
+#include <QSharedPointer>
#include <float.h>
#include <QStyleHints>
+using AbstractGraphicsShapeItemPtr = QSharedPointer<QAbstractGraphicsShapeItem>;
+using GraphicsItems = QVector<QGraphicsItem *>;
+using GraphicsItemsList = QList<QGraphicsItem *>;
+
+Q_DECLARE_METATYPE(AbstractGraphicsShapeItemPtr)
+Q_DECLARE_METATYPE(QGraphicsItem::GraphicsItemFlags)
Q_DECLARE_METATYPE(QPainterPath)
Q_DECLARE_METATYPE(QSizeF)
Q_DECLARE_METATYPE(QTransform)
@@ -88,17 +95,17 @@ static void sendMousePress(QGraphicsScene *scene, const QPointF &point, Qt::Mous
event.setScenePos(point);
event.setButton(button);
event.setButtons(button);
- QApplication::sendEvent(scene, &event);
+ QCoreApplication::sendEvent(scene, &event);
}
static void sendMouseMove(QGraphicsScene *scene, const QPointF &point,
- Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons /* buttons */ = 0)
+ Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons /* buttons */ = {})
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setScenePos(point);
event.setButton(button);
event.setButtons(button);
- QApplication::sendEvent(scene, &event);
+ QCoreApplication::sendEvent(scene, &event);
}
static void sendMouseRelease(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton)
@@ -106,7 +113,7 @@ static void sendMouseRelease(QGraphicsScene *scene, const QPointF &point, Qt::Mo
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease);
event.setScenePos(point);
event.setButton(button);
- QApplication::sendEvent(scene, &event);
+ QCoreApplication::sendEvent(scene, &event);
}
static void sendMouseClick(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton)
@@ -118,13 +125,13 @@ static void sendMouseClick(QGraphicsScene *scene, const QPointF &point, Qt::Mous
static void sendKeyPress(QGraphicsScene *scene, Qt::Key key)
{
QKeyEvent keyEvent(QEvent::KeyPress, key, Qt::NoModifier);
- QApplication::sendEvent(scene, &keyEvent);
+ QCoreApplication::sendEvent(scene, &keyEvent);
}
static void sendKeyRelease(QGraphicsScene *scene, Qt::Key key)
{
QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier);
- QApplication::sendEvent(scene, &keyEvent);
+ QCoreApplication::sendEvent(scene, &keyEvent);
}
static void sendKeyClick(QGraphicsScene *scene, Qt::Key key)
@@ -138,13 +145,13 @@ class EventSpy : public QGraphicsWidget
Q_OBJECT
public:
EventSpy(QObject *watched, QEvent::Type type)
- : _count(0), spied(type)
+ : spied(type)
{
watched->installEventFilter(this);
}
EventSpy(QGraphicsScene *scene, QGraphicsItem *watched, QEvent::Type type)
- : _count(0), spied(type)
+ : spied(type)
{
scene->addItem(this);
watched->installSceneEventFilter(this);
@@ -153,7 +160,7 @@ public:
int count() const { return _count; }
protected:
- bool eventFilter(QObject *watched, QEvent *event)
+ bool eventFilter(QObject *watched, QEvent *event) override
{
Q_UNUSED(watched);
if (event->type() == spied)
@@ -161,7 +168,7 @@ protected:
return false;
}
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
{
Q_UNUSED(watched);
if (event->type() == spied)
@@ -169,8 +176,8 @@ protected:
return false;
}
- int _count;
- QEvent::Type spied;
+ int _count = 0;
+ const QEvent::Type spied;
};
class EventSpy2 : public QGraphicsWidget
@@ -191,14 +198,14 @@ public:
QMap<QEvent::Type, int> counts;
protected:
- bool eventFilter(QObject *watched, QEvent *event)
+ bool eventFilter(QObject *watched, QEvent *event) override
{
Q_UNUSED(watched);
++counts[event->type()];
return false;
}
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
{
Q_UNUSED(watched);
++counts[event->type()];
@@ -209,8 +216,7 @@ protected:
class EventTester : public QGraphicsItem
{
public:
- EventTester(QGraphicsItem *parent = 0) : QGraphicsItem(parent), repaints(0)
- { br = QRectF(-10, -10, 20, 20); }
+ using QGraphicsItem::QGraphicsItem;
void setGeometry(const QRectF &rect)
{
@@ -219,10 +225,10 @@ public:
update();
}
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{ return br; }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *) override
{
hints = painter->renderHints();
painter->setBrush(brush);
@@ -231,7 +237,7 @@ public:
++repaints;
}
- bool sceneEvent(QEvent *event)
+ bool sceneEvent(QEvent *event) override
{
events << event->type();
return QGraphicsItem::sceneEvent(event);
@@ -240,32 +246,39 @@ public:
void reset()
{
events.clear();
- hints = QPainter::RenderHints(0);
+ hints = QPainter::RenderHints{};
repaints = 0;
lastExposedRect = QRectF();
}
- QList<QEvent::Type> events;
+ QVector<QEvent::Type> events;
QPainter::RenderHints hints;
- int repaints;
- QRectF br;
+ int repaints = 0;
+ QRectF br = QRectF(-10, -10, 20, 20);
QRectF lastExposedRect;
QBrush brush;
};
class MyGraphicsView : public QGraphicsView
{
+ Q_OBJECT
public:
- int repaints;
QRegion paintedRegion;
- MyGraphicsView(QGraphicsScene *scene, QWidget *parent=0) : QGraphicsView(scene,parent), repaints(0) {}
- void paintEvent(QPaintEvent *e)
+ int repaints = 0;
+
+ using QGraphicsView::QGraphicsView;
+
+ void paintEvent(QPaintEvent *e) override
{
paintedRegion += e->region();
++repaints;
QGraphicsView::paintEvent(e);
}
- void reset() { repaints = 0; paintedRegion = QRegion(); }
+ void reset()
+ {
+ repaints = 0;
+ paintedRegion = QRegion();
+ }
};
class tst_QGraphicsItem : public QObject
@@ -276,6 +289,7 @@ public:
static void initMain();
private slots:
+ void cleanup();
void construction();
void constructionWithParent();
void destruction();
@@ -473,7 +487,7 @@ private slots:
void QTBUG_21618_untransformable_sceneTransform();
private:
- QList<QGraphicsItem *> paintedItems;
+ GraphicsItems paintedItems;
QTouchDevice *m_touchDevice = nullptr;
};
@@ -485,69 +499,76 @@ void tst_QGraphicsItem::initMain()
#endif
}
+void tst_QGraphicsItem::cleanup()
+{
+ QVERIFY(QApplication::topLevelWidgets().isEmpty());
+}
+
+template <class I>
+static inline I *createBlackShapeItem()
+{
+ auto result = new I;
+ result->setPen(QPen(Qt::black, 0));
+ return result;
+}
+
void tst_QGraphicsItem::construction()
{
for (int i = 0; i < 7; ++i) {
QGraphicsItem *item = nullptr;
switch (i) {
case 0:
- item = new QGraphicsEllipseItem;
- ((QGraphicsEllipseItem *)item)->setPen(QPen(Qt::black, 0));
- QCOMPARE(int(item->type()), int(QGraphicsEllipseItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsEllipseItem *>(item), (QGraphicsEllipseItem *)item);
+ item = createBlackShapeItem<QGraphicsEllipseItem>();
+ QCOMPARE(item->type(), int(QGraphicsEllipseItem::Type));
+ QCOMPARE(qgraphicsitem_cast<QGraphicsEllipseItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 1:
- item = new QGraphicsLineItem;
- ((QGraphicsLineItem *)item)->setPen(QPen(Qt::black, 0));
+ item = createBlackShapeItem<QGraphicsLineItem>();
QCOMPARE(int(item->type()), int(QGraphicsLineItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), (QGraphicsLineItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 2:
- item = new QGraphicsPathItem;
- ((QGraphicsPathItem *)item)->setPen(QPen(Qt::black, 0));
+ item = createBlackShapeItem<QGraphicsPathItem>();
QCOMPARE(int(item->type()), int(QGraphicsPathItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsPathItem *>(item), (QGraphicsPathItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsPathItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 3:
item = new QGraphicsPixmapItem;
QCOMPARE(int(item->type()), int(QGraphicsPixmapItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsPixmapItem *>(item), (QGraphicsPixmapItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsPixmapItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 4:
- item = new QGraphicsPolygonItem;
- ((QGraphicsPolygonItem *)item)->setPen(QPen(Qt::black, 0));
+ item = createBlackShapeItem<QGraphicsPolygonItem>();
QCOMPARE(int(item->type()), int(QGraphicsPolygonItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsPolygonItem *>(item), (QGraphicsPolygonItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsPolygonItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 5:
- item = new QGraphicsRectItem;
- ((QGraphicsRectItem *)item)->setPen(QPen(Qt::black, 0));
+ item = createBlackShapeItem<QGraphicsRectItem>();
QCOMPARE(int(item->type()), int(QGraphicsRectItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 6:
item = new QGraphicsTextItem;
QCOMPARE(int(item->type()), int(QGraphicsTextItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsTextItem *>(item), (QGraphicsTextItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsTextItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
// This is the only item that uses an extended style option.
QCOMPARE(item->flags(), QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemUsesExtendedStyleOption));
break;
default:
qFatal("You broke the logic, please fix!");
- break;
}
QCOMPARE(item->scene(), nullptr);
@@ -569,10 +590,10 @@ void tst_QGraphicsItem::construction()
QCOMPARE(item->sceneBoundingRect(), QRectF());
QCOMPARE(item->shape(), QPainterPath());
QVERIFY(!item->contains(QPointF(0, 0)));
- QVERIFY(!item->collidesWithItem(0));
+ QVERIFY(!item->collidesWithItem(nullptr));
QVERIFY(item->collidesWithItem(item));
QVERIFY(!item->collidesWithPath(QPainterPath()));
- QVERIFY(!item->isAncestorOf(0));
+ QVERIFY(!item->isAncestorOf(nullptr));
QVERIFY(!item->isAncestorOf(item));
QCOMPARE(item->data(0), QVariant());
delete item;
@@ -582,17 +603,18 @@ void tst_QGraphicsItem::construction()
class BoundingRectItem : public QGraphicsRectItem
{
public:
- BoundingRectItem(QGraphicsItem *parent = 0)
+ BoundingRectItem(QGraphicsItem *parent = nullptr)
: QGraphicsRectItem(0, 0, parent ? 200 : 100, parent ? 200 : 100,
parent)
{
setPen(QPen(Qt::black, 0));
}
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{
QRectF tmp = QGraphicsRectItem::boundingRect();
- foreach (QGraphicsItem *child, childItems())
+ const auto children = childItems();
+ for (QGraphicsItem *child : children)
tmp |= child->boundingRect(); // <- might be pure virtual
return tmp;
}
@@ -608,11 +630,11 @@ void tst_QGraphicsItem::constructionWithParent()
scene.addItem(item0);
scene.addItem(item1);
QGraphicsItem *item2 = new BoundingRectItem(item1);
- QCOMPARE(item1->childItems(), QList<QGraphicsItem *>() << item2);
+ QCOMPARE(item1->childItems(), GraphicsItemsList{item2});
QCOMPARE(item1->boundingRect(), QRectF(0, 0, 200, 200));
item2->setParentItem(item0);
- QCOMPARE(item0->childItems(), QList<QGraphicsItem *>() << item2);
+ QCOMPARE(item0->childItems(), GraphicsItemsList{item2});
QCOMPARE(item0->boundingRect(), QRectF(0, 0, 200, 200));
}
@@ -760,7 +782,7 @@ void tst_QGraphicsItem::destruction()
QGraphicsScene scene;
QGraphicsItem *root = new QGraphicsRectItem;
QGraphicsItem *parent = root;
- QGraphicsItem *middleItem = 0;
+ QGraphicsItem *middleItem = nullptr;
for (int i = 0; i < 99; ++i) {
Item *child = new Item;
child->setParentItem(parent);
@@ -801,7 +823,7 @@ void tst_QGraphicsItem::deleteChildItem()
QGraphicsItem *child3 = new QGraphicsRectItem(rect);
Q_UNUSED(child3);
delete child1;
- child2->setParentItem(0);
+ child2->setParentItem(nullptr);
delete child2;
}
@@ -812,11 +834,11 @@ void tst_QGraphicsItem::scene()
QGraphicsScene scene;
scene.addItem(item);
- QCOMPARE(item->scene(), (QGraphicsScene *)&scene);
+ QCOMPARE(item->scene(), &scene);
QGraphicsScene scene2;
scene2.addItem(item);
- QCOMPARE(item->scene(), (QGraphicsScene *)&scene2);
+ QCOMPARE(item->scene(), &scene2);
scene2.removeItem(item);
QCOMPARE(item->scene(), nullptr);
@@ -830,10 +852,10 @@ void tst_QGraphicsItem::parentItem()
QCOMPARE(item.parentItem(), nullptr);
QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(), &item);
- QCOMPARE(item2->parentItem(), (QGraphicsItem *)&item);
+ QCOMPARE(item2->parentItem(), &item);
item2->setParentItem(&item);
- QCOMPARE(item2->parentItem(), (QGraphicsItem *)&item);
- item2->setParentItem(0);
+ QCOMPARE(item2->parentItem(), &item);
+ item2->setParentItem(nullptr);
QCOMPARE(item2->parentItem(), nullptr);
delete item2;
@@ -853,7 +875,7 @@ void tst_QGraphicsItem::setParentItem()
QCOMPARE(child->scene(), &scene);
// This just makes it a toplevel
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QCOMPARE(child->scene(), &scene);
// Add the child back to the parent, then remove the parent from the scene
@@ -869,7 +891,7 @@ void tst_QGraphicsItem::children()
QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(), &item);
QCOMPARE(item.childItems().size(), 1);
- QCOMPARE(item.childItems().first(), (QGraphicsItem *)item2);
+ QCOMPARE(item.childItems().constFirst(), item2);
QVERIFY(item2->childItems().isEmpty());
delete item2;
@@ -883,7 +905,7 @@ void tst_QGraphicsItem::flags()
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(item);
@@ -925,20 +947,20 @@ void tst_QGraphicsItem::flags()
event.setScenePos(QPointF(0, 0));
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(scene.mouseGrabberItem(), nullptr); // mouse grabber is reset
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove);
event2.setScenePos(QPointF(10, 10));
event2.setButton(Qt::LeftButton);
event2.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event2);
+ QCoreApplication::sendEvent(&scene, &event2);
QCOMPARE(item->pos(), QPointF());
QGraphicsSceneMouseEvent event3(QEvent::GraphicsSceneMouseRelease);
event3.setScenePos(QPointF(10, 10));
- event3.setButtons(0);
- QApplication::sendEvent(&scene, &event3);
+ event3.setButtons({});
+ QCoreApplication::sendEvent(&scene, &event3);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
item->setFlag(QGraphicsItem::ItemIsMovable, true);
@@ -946,13 +968,13 @@ void tst_QGraphicsItem::flags()
event4.setScenePos(QPointF(0, 0));
event4.setButton(Qt::LeftButton);
event4.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event4);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCoreApplication::sendEvent(&scene, &event4);
+ QCOMPARE(scene.mouseGrabberItem(), item);
QGraphicsSceneMouseEvent event5(QEvent::GraphicsSceneMouseMove);
event5.setScenePos(QPointF(10, 10));
event5.setButton(Qt::LeftButton);
event5.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event5);
+ QCoreApplication::sendEvent(&scene, &event5);
QCOMPARE(item->pos(), QPointF(10, 10));
}
{
@@ -975,8 +997,8 @@ void tst_QGraphicsItem::flags()
class ImhTester : public QGraphicsItem
{
- QRectF boundingRect() const { return QRectF(); }
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
+ QRectF boundingRect() const override { return QRectF(); }
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override {}
};
void tst_QGraphicsItem::inputMethodHints()
@@ -996,6 +1018,7 @@ void tst_QGraphicsItem::inputMethodHints()
scene.addItem(item2);
QGraphicsView view(&scene);
QApplication::setActiveWindow(&view);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -1045,6 +1068,7 @@ void tst_QGraphicsItem::toolTip()
scene.addItem(item);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(200, 200);
view.show();
QApplication::setActiveWindow(&view);
@@ -1053,12 +1077,13 @@ void tst_QGraphicsItem::toolTip()
{
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(),
view.viewport()->mapToGlobal(view.viewport()->rect().topLeft()));
- QApplication::sendEvent(view.viewport(), &helpEvent);
+ QCoreApplication::sendEvent(view.viewport(), &helpEvent);
QTest::qWait(250);
bool foundView = false;
bool foundTipLabel = false;
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ const auto topLevels = QApplication::topLevelWidgets();
+ for (auto widget : topLevels) {
if (widget == &view)
foundView = true;
if (widget->inherits("QTipLabel"))
@@ -1071,12 +1096,13 @@ void tst_QGraphicsItem::toolTip()
{
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().center(),
view.viewport()->mapToGlobal(view.viewport()->rect().center()));
- QApplication::sendEvent(view.viewport(), &helpEvent);
+ QCoreApplication::sendEvent(view.viewport(), &helpEvent);
QTest::qWait(250);
bool foundView = false;
bool foundTipLabel = false;
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ const auto topLevels = QApplication::topLevelWidgets();
+ for (auto widget : topLevels) {
if (widget == &view)
foundView = true;
if (widget->inherits("QTipLabel"))
@@ -1089,12 +1115,13 @@ void tst_QGraphicsItem::toolTip()
{
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(),
view.viewport()->mapToGlobal(view.viewport()->rect().topLeft()));
- QApplication::sendEvent(view.viewport(), &helpEvent);
+ QCoreApplication::sendEvent(view.viewport(), &helpEvent);
QTest::qWait(1000);
bool foundView = false;
bool foundTipLabel = false;
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ const auto topLevels = QApplication::topLevelWidgets();
+ for (auto widget : topLevels) {
if (widget == &view)
foundView = true;
if (widget->inherits("QTipLabel") && widget->isVisible())
@@ -1117,7 +1144,7 @@ void tst_QGraphicsItem::visible()
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(item);
QVERIFY(item->isVisible());
@@ -1130,7 +1157,7 @@ void tst_QGraphicsItem::visible()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
event.setButton(Qt::LeftButton);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(scene.mouseGrabberItem(), item);
item->setVisible(false);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
@@ -1161,14 +1188,14 @@ void tst_QGraphicsItem::isVisibleTo()
QVERIFY(grandChild->isVisibleTo(grandChild));
QVERIFY(grandChild->isVisibleTo(child));
QVERIFY(grandChild->isVisibleTo(parent));
- QVERIFY(grandChild->isVisibleTo(0));
+ QVERIFY(grandChild->isVisibleTo(nullptr));
QVERIFY(child->isVisible());
QVERIFY(child->isVisibleTo(child));
QVERIFY(child->isVisibleTo(parent));
- QVERIFY(child->isVisibleTo(0));
+ QVERIFY(child->isVisibleTo(nullptr));
QVERIFY(parent->isVisible());
QVERIFY(parent->isVisibleTo(parent));
- QVERIFY(parent->isVisibleTo(0));
+ QVERIFY(parent->isVisibleTo(nullptr));
QVERIFY(!parent->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(stranger));
@@ -1185,14 +1212,14 @@ void tst_QGraphicsItem::isVisibleTo()
QVERIFY(grandChild->isVisibleTo(grandChild));
QVERIFY(grandChild->isVisibleTo(child));
QVERIFY(grandChild->isVisibleTo(parent));
- QVERIFY(!grandChild->isVisibleTo(0));
+ QVERIFY(!grandChild->isVisibleTo(nullptr));
QVERIFY(!child->isVisible());
QVERIFY(child->isVisibleTo(child));
QVERIFY(child->isVisibleTo(parent));
- QVERIFY(!child->isVisibleTo(0));
+ QVERIFY(!child->isVisibleTo(nullptr));
QVERIFY(!parent->isVisible());
QVERIFY(!parent->isVisibleTo(parent));
- QVERIFY(!parent->isVisibleTo(0));
+ QVERIFY(!parent->isVisibleTo(nullptr));
QVERIFY(!parent->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(stranger));
@@ -1210,14 +1237,14 @@ void tst_QGraphicsItem::isVisibleTo()
QVERIFY(grandChild->isVisibleTo(grandChild));
QVERIFY(grandChild->isVisibleTo(child));
QVERIFY(!grandChild->isVisibleTo(parent));
- QVERIFY(!grandChild->isVisibleTo(0));
+ QVERIFY(!grandChild->isVisibleTo(nullptr));
QVERIFY(!child->isVisible());
QVERIFY(!child->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(parent));
- QVERIFY(!child->isVisibleTo(0));
+ QVERIFY(!child->isVisibleTo(nullptr));
QVERIFY(parent->isVisible());
QVERIFY(parent->isVisibleTo(parent));
- QVERIFY(parent->isVisibleTo(0));
+ QVERIFY(parent->isVisibleTo(nullptr));
QVERIFY(!parent->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(stranger));
@@ -1235,14 +1262,14 @@ void tst_QGraphicsItem::isVisibleTo()
QVERIFY(!grandChild->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(child));
QVERIFY(!grandChild->isVisibleTo(parent));
- QVERIFY(!grandChild->isVisibleTo(0));
+ QVERIFY(!grandChild->isVisibleTo(nullptr));
QVERIFY(child->isVisible());
QVERIFY(child->isVisibleTo(child));
QVERIFY(child->isVisibleTo(parent));
- QVERIFY(child->isVisibleTo(0));
+ QVERIFY(child->isVisibleTo(nullptr));
QVERIFY(parent->isVisible());
QVERIFY(parent->isVisibleTo(parent));
- QVERIFY(parent->isVisibleTo(0));
+ QVERIFY(parent->isVisibleTo(nullptr));
QVERIFY(!parent->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(stranger));
@@ -1349,7 +1376,7 @@ void tst_QGraphicsItem::explicitlyVisible()
// Reparent implicitly hidden child to root.
parent2->hide();
QVERIFY(!child->isVisible());
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QVERIFY(child->isVisible());
// Reparent an explicitly hidden child to root.
@@ -1357,7 +1384,7 @@ void tst_QGraphicsItem::explicitlyVisible()
child->setParentItem(parent2);
parent2->show();
QVERIFY(!child->isVisible());
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QVERIFY(!child->isVisible());
}
@@ -1374,7 +1401,7 @@ void tst_QGraphicsItem::enabled()
item->setFlag(QGraphicsItem::ItemIsFocusable);
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(item);
item->setFocus();
@@ -1388,11 +1415,11 @@ void tst_QGraphicsItem::enabled()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
event.setButton(Qt::LeftButton);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
item->setEnabled(true);
- QApplication::sendEvent(&scene, &event);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCoreApplication::sendEvent(&scene, &event);
+ QCOMPARE(scene.mouseGrabberItem(), item);
item->setEnabled(false);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
}
@@ -1493,7 +1520,7 @@ void tst_QGraphicsItem::explicitlyEnabled()
// Reparent implicitly hidden child to root.
parent2->setEnabled(false);
QVERIFY(!child->isEnabled());
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QVERIFY(child->isEnabled());
// Reparent an explicitly hidden child to root.
@@ -1501,7 +1528,7 @@ void tst_QGraphicsItem::explicitlyEnabled()
child->setParentItem(parent2);
parent2->setEnabled(true);
QVERIFY(!child->isEnabled());
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QVERIFY(!child->isEnabled());
}
@@ -1509,10 +1536,10 @@ class SelectChangeItem : public QGraphicsRectItem
{
public:
SelectChangeItem() : QGraphicsRectItem(-50, -50, 100, 100) { setBrush(Qt::blue); }
- QList<bool> values;
+ QVector<bool> values;
protected:
- QVariant itemChange(GraphicsItemChange change, const QVariant &value)
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
{
if (change == ItemSelectedChange)
values << value.toBool();
@@ -1528,70 +1555,71 @@ void tst_QGraphicsItem::selected()
QVERIFY(item->values.isEmpty());
item->setSelected(true);
QCOMPARE(item->values.size(), 1);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
item->setSelected(false);
QCOMPARE(item->values.size(), 2);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
item->setSelected(true);
QCOMPARE(item->values.size(), 3);
item->setEnabled(false);
QCOMPARE(item->values.size(), 4);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
item->setEnabled(true);
QCOMPARE(item->values.size(), 4);
item->setSelected(true);
QCOMPARE(item->values.size(), 5);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
item->setVisible(false);
QCOMPARE(item->values.size(), 6);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
item->setVisible(true);
QCOMPARE(item->values.size(), 6);
item->setSelected(true);
QCOMPARE(item->values.size(), 7);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
QGraphicsScene scene(-100, -100, 200, 200);
scene.addItem(item);
- QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << item);
+ QCOMPARE(scene.selectedItems(), GraphicsItemsList{item});
item->setSelected(false);
QVERIFY(scene.selectedItems().isEmpty());
item->setSelected(true);
- QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << item);
+ QCOMPARE(scene.selectedItems(), GraphicsItemsList{item});
item->setSelected(false);
QVERIFY(scene.selectedItems().isEmpty());
// Interactive selection
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(250, 250);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
scene.clearSelection();
QCOMPARE(item->values.size(), 10);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
// Click inside and check that it's selected
QTest::mouseMove(view.viewport());
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos()));
QCOMPARE(item->values.size(), 11);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
// Click outside and check that it's not selected
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos() + QPointF(item->boundingRect().width(), item->boundingRect().height())));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos() + QPointF(item->boundingRect().width(), item->boundingRect().height())));
QCOMPARE(item->values.size(), 12);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
SelectChangeItem *item2 = new SelectChangeItem;
@@ -1600,18 +1628,18 @@ void tst_QGraphicsItem::selected()
scene.addItem(item2);
// Click inside and check that it's selected
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos()));
QCOMPARE(item->values.size(), 13);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
// Click inside item2 and check that it's selected, and item is not
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos()));
QCOMPARE(item->values.size(), 14);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
QCOMPARE(item2->values.size(), 1);
- QCOMPARE(item2->values.last(), true);
+ QCOMPARE(item2->values.constLast(), true);
QVERIFY(item2->isSelected());
}
@@ -1632,7 +1660,7 @@ void tst_QGraphicsItem::selected2()
QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress);
mousePress.setScenePos(QPointF(50, 50));
mousePress.setButton(Qt::LeftButton);
- QApplication::sendEvent(&scene, &mousePress);
+ QCoreApplication::sendEvent(&scene, &mousePress);
QVERIFY(mousePress.isAccepted());
}
{
@@ -1640,7 +1668,7 @@ void tst_QGraphicsItem::selected2()
mouseMove.setScenePos(QPointF(60, 60));
mouseMove.setButton(Qt::LeftButton);
mouseMove.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &mouseMove);
+ QCoreApplication::sendEvent(&scene, &mouseMove);
QVERIFY(mouseMove.isAccepted());
}
}
@@ -1657,10 +1685,11 @@ void tst_QGraphicsItem::selected_group()
leaf->setFlag(QGraphicsItem::ItemIsSelectable);
leaf->setParentItem(item2);
- QGraphicsItemGroup *group = scene.createItemGroup(QList<QGraphicsItem *>() << item1 << item2);
+ QGraphicsItemGroup *group = scene.createItemGroup(GraphicsItemsList{item1, item2});
QCOMPARE(group->scene(), &scene);
group->setFlag(QGraphicsItem::ItemIsSelectable);
- foreach (QGraphicsItem *item, scene.items()) {
+ const auto items = scene.items();
+ for (QGraphicsItem *item : items) {
if (item == group)
QVERIFY(!item->group());
else
@@ -1673,18 +1702,16 @@ void tst_QGraphicsItem::selected_group()
QVERIFY(!group->isSelected());
group->setSelected(true);
QVERIFY(group->isSelected());
- foreach (QGraphicsItem *item, scene.items())
- QVERIFY(item->isSelected());
+
+ const auto itemIsSelected = [](const QGraphicsItem *item) { return item->isSelected(); };
+ QVERIFY(std::all_of(items.cbegin(), items.cend(), itemIsSelected));
group->setSelected(false);
QVERIFY(!group->isSelected());
- foreach (QGraphicsItem *item, scene.items())
- QVERIFY(!item->isSelected());
+ QVERIFY(std::none_of(items.cbegin(), items.cend(), itemIsSelected));
leaf->setSelected(true);
- foreach (QGraphicsItem *item, scene.items())
- QVERIFY(item->isSelected());
+ QVERIFY(std::all_of(items.cbegin(), items.cend(), itemIsSelected));
leaf->setSelected(false);
- foreach (QGraphicsItem *item, scene.items())
- QVERIFY(!item->isSelected());
+ QVERIFY(std::none_of(items.cbegin(), items.cend(), itemIsSelected));
leaf->setSelected(true);
QGraphicsScene scene2;
@@ -1700,18 +1727,19 @@ void tst_QGraphicsItem::selected_textItem()
text->setFlag(QGraphicsItem::ItemIsSelectable);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QTRY_VERIFY(!text->isSelected());
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0,
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
view.mapFromScene(text->mapToScene(0, 0)));
QTRY_VERIFY(text->isSelected());
text->setSelected(false);
text->setTextInteractionFlags(Qt::TextEditorInteraction);
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0,
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
view.mapFromScene(text->mapToScene(0, 0)));
QTRY_VERIFY(text->isSelected());
}
@@ -1733,6 +1761,7 @@ void tst_QGraphicsItem::selected_multi()
// Create and show a view
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
view.fitInView(scene.sceneRect());
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -1741,12 +1770,12 @@ void tst_QGraphicsItem::selected_multi()
QVERIFY(!item2->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
// Click on item2
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos()));
QVERIFY(item2->isSelected());
QVERIFY(!item1->isSelected());
@@ -1766,17 +1795,17 @@ void tst_QGraphicsItem::selected_multi()
QVERIFY(!item1->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
// Click on scene
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(0, 0));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(0, 0));
QVERIFY(!item1->isSelected());
QVERIFY(!item2->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
@@ -1786,27 +1815,27 @@ void tst_QGraphicsItem::selected_multi()
QVERIFY(!item2->isSelected());
// Click on scene
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(0, 0));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(0, 0));
QVERIFY(!item1->isSelected());
QVERIFY(!item2->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
// Press on item2
- QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos()));
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos()));
QVERIFY(!item1->isSelected());
QVERIFY(item2->isSelected());
// Release on item2
- QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos()));
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos()));
QVERIFY(!item1->isSelected());
QVERIFY(item2->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
@@ -1824,7 +1853,7 @@ void tst_QGraphicsItem::selected_multi()
// Ctrl-move on item1
const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0);
QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier);
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(!item1->isSelected());
QVERIFY(!item2->isSelected());
}
@@ -1846,7 +1875,7 @@ void tst_QGraphicsItem::selected_multi()
// Ctrl-move on item1
const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0);
QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier);
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
}
@@ -1873,33 +1902,30 @@ void tst_QGraphicsItem::acceptedMouseButtons()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
event.setButton(Qt::LeftButton);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item2);
- item2->setAcceptedMouseButtons(0);
+ QCoreApplication::sendEvent(&scene, &event);
+ QCOMPARE(scene.mouseGrabberItem(), item2);
+ item2->setAcceptedMouseButtons(nullptr);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
- QApplication::sendEvent(&scene, &event);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item1);
+ QCoreApplication::sendEvent(&scene, &event);
+ QCOMPARE(scene.mouseGrabberItem(), item1);
}
class HoverItem : public QGraphicsRectItem
{
public:
- HoverItem(const QRectF &rect)
- : QGraphicsRectItem(rect), hoverInCount(0),
- hoverMoveCount(0), hoverOutCount(0)
- { }
+ HoverItem(const QRectF &rect) : QGraphicsRectItem(rect) { }
- int hoverInCount;
- int hoverMoveCount;
- int hoverOutCount;
+ int hoverInCount = 0;
+ int hoverMoveCount = 0;
+ int hoverOutCount = 0;
protected:
- void hoverEnterEvent(QGraphicsSceneHoverEvent *)
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
{ ++hoverInCount; }
- void hoverMoveEvent(QGraphicsSceneHoverEvent *)
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
{ ++hoverMoveCount; }
- void hoverLeaveEvent(QGraphicsSceneHoverEvent *)
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
{ ++hoverOutCount; }
};
@@ -1919,9 +1945,9 @@ void tst_QGraphicsItem::acceptHoverEvents()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
event.setScenePos(QPointF(-2.5, -2.5));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item1->hoverInCount, 0);
QCOMPARE(item2->hoverInCount, 1);
@@ -1930,9 +1956,9 @@ void tst_QGraphicsItem::acceptHoverEvents()
item2->setAcceptHoverEvents(false);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
event.setScenePos(QPointF(-2.5, -2.5));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item1->hoverInCount, 0);
QCOMPARE(item2->hoverInCount, 1);
@@ -1941,9 +1967,9 @@ void tst_QGraphicsItem::acceptHoverEvents()
item2->setAcceptHoverEvents(false);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
event.setScenePos(QPointF(-2.5, -2.5));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item1->hoverInCount, 1);
QCOMPARE(item2->hoverInCount, 1);
@@ -1962,7 +1988,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 0);
QCOMPARE(item2->hoverMoveCount, 0);
QCOMPARE(item2->hoverOutCount, 0);
@@ -1971,7 +1997,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QCOMPARE(item1->hoverOutCount, 0);
event.setScenePos(QPointF(-2.5, -2.5));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 1);
QCOMPARE(item2->hoverMoveCount, 1);
@@ -1981,7 +2007,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QCOMPARE(item1->hoverOutCount, 0);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 1);
QCOMPARE(item2->hoverMoveCount, 2);
@@ -1991,7 +2017,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QCOMPARE(item1->hoverOutCount, 0);
event.setScenePos(QPointF(-7, -7));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 1);
QCOMPARE(item2->hoverMoveCount, 2);
@@ -2001,7 +2027,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QCOMPARE(item1->hoverOutCount, 0);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 2);
QCOMPARE(item2->hoverMoveCount, 3);
@@ -2016,10 +2042,10 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
item0->setAcceptHoverEvents(true);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
event.setScenePos(QPointF(-15, -15));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 2);
QCOMPARE(item2->hoverMoveCount, 3);
@@ -2041,7 +2067,7 @@ void tst_QGraphicsItem::hasFocus()
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(line);
@@ -2052,7 +2078,7 @@ void tst_QGraphicsItem::hasFocus()
QVERIFY(line->hasFocus());
QGraphicsScene scene2;
- QApplication::sendEvent(&scene2, &activate);
+ QCoreApplication::sendEvent(&scene2, &activate);
scene2.addItem(line);
QVERIFY(!line->hasFocus());
@@ -2193,13 +2219,13 @@ void tst_QGraphicsItem::sceneTransform()
void tst_QGraphicsItem::setTransform()
{
QGraphicsScene scene;
- QSignalSpy spy(&scene, SIGNAL(changed(QList<QRectF>)));
+ QSignalSpy spy(&scene, &QGraphicsScene::changed);
QRectF unrotatedRect(-12, -34, 56, 78);
- QGraphicsRectItem item(unrotatedRect, 0);
+ QGraphicsRectItem item(unrotatedRect, nullptr);
item.setPen(QPen(Qt::black, 0));
scene.addItem(&item);
scene.update(scene.sceneRect());
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(spy.count(), 1);
@@ -2207,14 +2233,14 @@ void tst_QGraphicsItem::setTransform()
QRectF rotatedRect = scene.sceneRect();
QVERIFY(unrotatedRect != rotatedRect);
scene.update(scene.sceneRect());
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(spy.count(), 2);
item.setTransform(QTransform());
scene.update(scene.sceneRect());
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(spy.count(), 3);
QList<QRectF> rlist = qvariant_cast<QList<QRectF> >(spy.last().at(0));
@@ -2226,15 +2252,18 @@ void tst_QGraphicsItem::setTransform()
QCOMPARE(rlist.at(1), unrotatedRect); // From post-update (update current state)
}
-static QList<QGraphicsItem *> _paintedItems;
+static GraphicsItems _paintedItems;
class PainterItem : public QGraphicsItem
{
protected:
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{ return QRectF(-10, -10, 20, 20); }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
- { _paintedItems << this; painter->fillRect(boundingRect(), Qt::red); }
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
+ {
+ _paintedItems << this;
+ painter->fillRect(boundingRect(), Qt::red);
+ }
};
void tst_QGraphicsItem::zValue()
@@ -2257,6 +2286,7 @@ void tst_QGraphicsItem::zValue()
item3->setZValue(0);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -2467,12 +2497,12 @@ void tst_QGraphicsItem::collidesWith_item()
{
QGraphicsScene scene;
- QGraphicsRectItem rect(20, 20, 100, 100, 0);
+ QGraphicsRectItem rect(20, 20, 100, 100, nullptr);
scene.addItem(&rect);
- QGraphicsRectItem rect2(40, 40, 50, 50, 0);
+ QGraphicsRectItem rect2(40, 40, 50, 50, nullptr);
scene.addItem(&rect2);
rect2.setZValue(1);
- QGraphicsLineItem line(0, 0, 200, 200, 0);
+ QGraphicsLineItem line(0, 0, 200, 200, nullptr);
scene.addItem(&line);
line.setZValue(2);
@@ -2480,18 +2510,18 @@ void tst_QGraphicsItem::collidesWith_item()
QList<QGraphicsItem *> col1 = rect.collidingItems();
QCOMPARE(col1.size(), 2);
- QCOMPARE(col1.first(), static_cast<QGraphicsItem *>(&line));
- QCOMPARE(col1.last(), static_cast<QGraphicsItem *>(&rect2));
+ QCOMPARE(col1.constFirst(), &line);
+ QCOMPARE(col1.constLast(), &rect2);
QList<QGraphicsItem *> col2 = rect2.collidingItems();
QCOMPARE(col2.size(), 2);
- QCOMPARE(col2.first(), static_cast<QGraphicsItem *>(&line));
- QCOMPARE(col2.last(), static_cast<QGraphicsItem *>(&rect));
+ QCOMPARE(col2.constFirst(), &line);
+ QCOMPARE(col2.constLast(), &rect);
QList<QGraphicsItem *> col3 = line.collidingItems();
QCOMPARE(col3.size(), 2);
- QCOMPARE(col3.first(), static_cast<QGraphicsItem *>(&rect2));
- QCOMPARE(col3.last(), static_cast<QGraphicsItem *>(&rect));
+ QCOMPARE(col3.constFirst(), &rect2);
+ QCOMPARE(col3.constLast(), &rect);
}
}
@@ -2574,42 +2604,35 @@ void tst_QGraphicsItem::collidesWithItemWithClip()
class MyItem : public QGraphicsEllipseItem
{
public:
- bool isObscuredBy(const QGraphicsItem *item) const
- {
- const MyItem *myItem = qgraphicsitem_cast<const MyItem *>(item);
- if (myItem) {
- if (item->zValue() > zValue()) {
- QRectF r = rect();
- QPointF topMid = (r.topRight()+r.topLeft())/2;
- QPointF botMid = (r.bottomRight()+r.bottomLeft())/2;
- QPointF leftMid = (r.topLeft()+r.bottomLeft())/2;
- QPointF rightMid = (r.topRight()+r.bottomRight())/2;
-
- QPainterPath mappedShape = item->mapToItem(this, item->opaqueArea());
-
- if (mappedShape.contains(topMid) &&
- mappedShape.contains(botMid) &&
- mappedShape.contains(leftMid) &&
- mappedShape.contains(rightMid))
- return true;
- else
- return false;
- }
- else return false;
- }
- else
- return QGraphicsItem::isObscuredBy(item);
+ bool isObscuredBy(const QGraphicsItem *item) const override
+ {
+ auto myItem = qgraphicsitem_cast<const MyItem *>(item);
+ if (!myItem)
+ return QGraphicsEllipseItem::isObscuredBy(item);
+
+ if (item->zValue() <= zValue())
+ return false;
+
+ QRectF r = rect();
+ QPointF topMid = (r.topRight() + r.topLeft()) / 2;
+ QPointF botMid = (r.bottomRight() + r.bottomLeft()) / 2;
+ QPointF leftMid = (r.topLeft() + r.bottomLeft()) / 2;
+ QPointF rightMid = (r.topRight() + r.bottomRight()) / 2;
+
+ QPainterPath mappedShape = item->mapToItem(this, item->opaqueArea());
+
+ return mappedShape.contains(topMid) && mappedShape.contains(botMid)
+ && mappedShape.contains(leftMid) && mappedShape.contains(rightMid);
}
- QPainterPath opaqueArea() const
+ QPainterPath opaqueArea() const override
{
return shape();
}
- enum {
- Type = UserType+1
- };
- int type() const { return Type; }
+ enum { Type = UserType + 1 };
+
+ int type() const override { return Type; }
};
void tst_QGraphicsItem::isObscuredBy()
@@ -2662,7 +2685,7 @@ void tst_QGraphicsItem::isObscuredBy()
class OpaqueItem : public QGraphicsRectItem
{
protected:
- QPainterPath opaqueArea() const
+ QPainterPath opaqueArea() const override
{
return shape();
}
@@ -2977,14 +3000,14 @@ void tst_QGraphicsItem::mapFromToItem()
QCOMPARE(item3->mapFromItem(item2, 10, -5), QPointF(-190, -5));
QCOMPARE(item4->mapFromItem(item3, 10, -5), QPointF(10, -205));
- QCOMPARE(item1->mapFromItem(0, 10, -5), item1->mapFromScene(10, -5));
- QCOMPARE(item2->mapFromItem(0, 10, -5), item2->mapFromScene(10, -5));
- QCOMPARE(item3->mapFromItem(0, 10, -5), item3->mapFromScene(10, -5));
- QCOMPARE(item4->mapFromItem(0, 10, -5), item4->mapFromScene(10, -5));
- QCOMPARE(item1->mapToItem(0, 10, -5), item1->mapToScene(10, -5));
- QCOMPARE(item2->mapToItem(0, 10, -5), item2->mapToScene(10, -5));
- QCOMPARE(item3->mapToItem(0, 10, -5), item3->mapToScene(10, -5));
- QCOMPARE(item4->mapToItem(0, 10, -5), item4->mapToScene(10, -5));
+ QCOMPARE(item1->mapFromItem(nullptr, 10, -5), item1->mapFromScene(10, -5));
+ QCOMPARE(item2->mapFromItem(nullptr, 10, -5), item2->mapFromScene(10, -5));
+ QCOMPARE(item3->mapFromItem(nullptr, 10, -5), item3->mapFromScene(10, -5));
+ QCOMPARE(item4->mapFromItem(nullptr, 10, -5), item4->mapFromScene(10, -5));
+ QCOMPARE(item1->mapToItem(nullptr, 10, -5), item1->mapToScene(10, -5));
+ QCOMPARE(item2->mapToItem(nullptr, 10, -5), item2->mapToScene(10, -5));
+ QCOMPARE(item3->mapToItem(nullptr, 10, -5), item3->mapToScene(10, -5));
+ QCOMPARE(item4->mapToItem(nullptr, 10, -5), item4->mapToScene(10, -5));
delete item1;
delete item2;
@@ -3079,8 +3102,8 @@ void tst_QGraphicsItem::isAncestorOf()
QGraphicsItem *parent = new QGraphicsRectItem;
QGraphicsItem *child = new QGraphicsRectItem;
- QVERIFY(!parent->isAncestorOf(0));
- QVERIFY(!child->isAncestorOf(0));
+ QVERIFY(!parent->isAncestorOf(nullptr));
+ QVERIFY(!child->isAncestorOf(nullptr));
QVERIFY(!parent->isAncestorOf(child));
QVERIFY(!child->isAncestorOf(parent));
QVERIFY(!parent->isAncestorOf(parent));
@@ -3098,7 +3121,7 @@ void tst_QGraphicsItem::isAncestorOf()
QVERIFY(!parent->isAncestorOf(parent));
QVERIFY(!grandPa->isAncestorOf(grandPa));
- parent->setParentItem(0);
+ parent->setParentItem(nullptr);
delete child;
delete parent;
@@ -3126,7 +3149,7 @@ void tst_QGraphicsItem::commonAncestorItem()
grandPa->setParentItem(ancestor);
QCOMPARE(grandMa->commonAncestorItem(grandMa), grandMa);
- QCOMPARE(grandMa->commonAncestorItem(0), nullptr);
+ QCOMPARE(grandMa->commonAncestorItem(nullptr), nullptr);
QCOMPARE(grandMa->commonAncestorItem(grandPa), ancestor);
QCOMPARE(grandPa->commonAncestorItem(grandMa), ancestor);
QCOMPARE(grandPa->commonAncestorItem(husband), grandPa);
@@ -3230,7 +3253,7 @@ void tst_QGraphicsItem::graphicsitem_cast()
QVERIFY(!qgraphicsitem_cast<const QGraphicsTextItem *>(pPolygonItem));
// and this shouldn't crash
- QGraphicsItem *ptr = 0;
+ QGraphicsItem *ptr = nullptr;
QVERIFY(!qgraphicsitem_cast<QGraphicsTextItem *>(ptr));
QVERIFY(!qgraphicsitem_cast<QGraphicsItem *>(ptr));
}
@@ -3241,6 +3264,7 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints()
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -3256,48 +3280,48 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints()
QGraphicsSceneHoverEvent hoverEnterEvent(QEvent::GraphicsSceneHoverEnter);
hoverEnterEvent.setScenePos(QPointF(0, 0));
hoverEnterEvent.setPos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &hoverEnterEvent);
+ QCoreApplication::sendEvent(&scene, &hoverEnterEvent);
// Check that we get a repaint
int npaints = tester->repaints;
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(tester->events.size(), 2); // enter + move
QCOMPARE(tester->repaints, npaints + 1);
- QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove);
+ QCOMPARE(tester->events.constLast(), QEvent::GraphicsSceneHoverMove);
// Send a hover move event
QGraphicsSceneHoverEvent hoverMoveEvent(QEvent::GraphicsSceneHoverMove);
hoverMoveEvent.setScenePos(QPointF(0, 0));
hoverMoveEvent.setPos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &hoverMoveEvent);
+ QCoreApplication::sendEvent(&scene, &hoverMoveEvent);
// Check that we don't get a repaint
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(tester->events.size(), 3);
QCOMPARE(tester->repaints, npaints + 1);
- QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove);
+ QCOMPARE(tester->events.constLast(), QEvent::GraphicsSceneHoverMove);
// Send a hover leave event
QGraphicsSceneHoverEvent hoverLeaveEvent(QEvent::GraphicsSceneHoverLeave);
hoverLeaveEvent.setScenePos(QPointF(-100, -100));
hoverLeaveEvent.setPos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &hoverLeaveEvent);
+ QCoreApplication::sendEvent(&scene, &hoverLeaveEvent);
// Check that we get a repaint
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(tester->events.size(), 4);
QCOMPARE(tester->repaints, npaints + 2);
- QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverLeave);
+ QCOMPARE(tester->events.constLast(), QEvent::GraphicsSceneHoverLeave);
}
void tst_QGraphicsItem::boundingRects_data()
{
- QTest::addColumn<QGraphicsItem *>("item");
+ QTest::addColumn<AbstractGraphicsShapeItemPtr>("item");
QTest::addColumn<QRectF>("boundingRect");
QRectF rect(0, 0, 100, 100);
@@ -3306,18 +3330,18 @@ void tst_QGraphicsItem::boundingRects_data()
QRectF adjustedRect(-0.5, -0.5, 101, 101);
- QTest::newRow("path") << (QGraphicsItem *)new QGraphicsPathItem(path) << adjustedRect;
- QTest::newRow("rect") << (QGraphicsItem *)new QGraphicsRectItem(rect) << adjustedRect;
- QTest::newRow("ellipse") << (QGraphicsItem *)new QGraphicsEllipseItem(rect) << adjustedRect;
- QTest::newRow("polygon") << (QGraphicsItem *)new QGraphicsPolygonItem(rect) << adjustedRect;
+ QTest::newRow("path") << AbstractGraphicsShapeItemPtr(new QGraphicsPathItem(path)) << adjustedRect;
+ QTest::newRow("rect") << AbstractGraphicsShapeItemPtr(new QGraphicsRectItem(rect)) << adjustedRect;
+ QTest::newRow("ellipse") << AbstractGraphicsShapeItemPtr(new QGraphicsEllipseItem(rect)) << adjustedRect;
+ QTest::newRow("polygon") << AbstractGraphicsShapeItemPtr(new QGraphicsPolygonItem(rect)) << adjustedRect;
}
void tst_QGraphicsItem::boundingRects()
{
- QFETCH(QGraphicsItem *, item);
+ QFETCH(AbstractGraphicsShapeItemPtr, item);
QFETCH(QRectF, boundingRect);
- ((QAbstractGraphicsShapeItem *)item)->setPen(QPen(Qt::black, 1));
+ item->setPen(QPen(Qt::black, 1));
QCOMPARE(item->boundingRect(), boundingRect);
}
@@ -3373,6 +3397,7 @@ void tst_QGraphicsItem::childrenBoundingRect()
scene.addPolygon(parent->mapToScene(parent->boundingRect() | parent->childrenBoundingRect()))->setPen(QPen(Qt::red));;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3488,6 +3513,7 @@ void tst_QGraphicsItem::childrenBoundingRect4()
rect3->setParentItem(rect);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3515,6 +3541,7 @@ void tst_QGraphicsItem::childrenBoundingRect5()
child->setPen(QPen(Qt::black, 0));
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3551,6 +3578,7 @@ void tst_QGraphicsItem::group()
QCOMPARE(child->group(), nullptr);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3563,7 +3591,7 @@ void tst_QGraphicsItem::group()
QCOMPARE(parent->group(), group);
QCOMPARE(parent->sceneBoundingRect(), parentSceneBoundingRect);
- QCOMPARE(parent->parentItem(), (QGraphicsItem *)group);
+ QCOMPARE(parent->parentItem(), group);
QCOMPARE(group->childItems().size(), 1);
QCOMPARE(scene.items().size(), 4);
QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 3);
@@ -3574,12 +3602,13 @@ void tst_QGraphicsItem::group()
QCOMPARE(parent2->group(), group);
QCOMPARE(parent2->sceneBoundingRect(), parent2SceneBoundingRect);
- QCOMPARE(parent2->parentItem(), (QGraphicsItem *)group);
+ QCOMPARE(parent2->parentItem(), group);
QCOMPARE(group->childItems().size(), 2);
QCOMPARE(scene.items().size(), 4);
QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 4);
- QList<QGraphicsItem *> newItems;
+ GraphicsItems newItems;
+ newItems.reserve(100);
for (int i = 0; i < 100; ++i) {
QGraphicsItem *item = scene.addRect(QRectF(-25, -25, 50, 50), QPen(Qt::black, 0),
QBrush(QColor(QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255),
@@ -3592,7 +3621,7 @@ void tst_QGraphicsItem::group()
view.fitInView(scene.itemsBoundingRect());
- foreach (QGraphicsItem *item, newItems) {
+ for (QGraphicsItem *item : qAsConst(newItems)) {
group->addToGroup(item);
QCOMPARE(item->group(), group);
}
@@ -3608,11 +3637,11 @@ void tst_QGraphicsItem::setGroup()
QCOMPARE(rect->parentItem(), nullptr);
rect->setGroup(&group1);
QCOMPARE(rect->group(), &group1);
- QCOMPARE(rect->parentItem(), (QGraphicsItem *)&group1);
+ QCOMPARE(rect->parentItem(), &group1);
rect->setGroup(&group2);
QCOMPARE(rect->group(), &group2);
- QCOMPARE(rect->parentItem(), (QGraphicsItem *)&group2);
- rect->setGroup(0);
+ QCOMPARE(rect->parentItem(), &group2);
+ rect->setGroup(nullptr);
QCOMPARE(rect->group(), nullptr);
QCOMPARE(rect->parentItem(), nullptr);
}
@@ -3642,7 +3671,7 @@ void tst_QGraphicsItem::setGroup2()
rect->setScale(0.8);
oldSceneTransform = rect->sceneTransform();
- rect->setGroup(0);
+ rect->setGroup(nullptr);
qFuzzyCompare(rect->sceneTransform(), oldSceneTransform);
}
@@ -3715,21 +3744,22 @@ void tst_QGraphicsItem::removeFromGroup()
rect2->setSelected(true);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
- qApp->processEvents(); // index items
- qApp->processEvents(); // emit changed
+ QCoreApplication::processEvents(); // index items
+ QCoreApplication::processEvents(); // emit changed
QGraphicsItemGroup *group = scene.createItemGroup(scene.selectedItems());
QVERIFY(group);
QCOMPARE(group->childItems().size(), 2);
- qApp->processEvents(); // index items
- qApp->processEvents(); // emit changed
+ QCoreApplication::processEvents(); // index items
+ QCoreApplication::processEvents(); // emit changed
scene.destroyItemGroup(group); // calls removeFromGroup.
- qApp->processEvents(); // index items
- qApp->processEvents(); // emit changed
+ QCoreApplication::processEvents(); // index items
+ QCoreApplication::processEvents(); // emit changed
QCOMPARE(scene.items().size(), 2);
QVERIFY(!rect1->group());
@@ -3739,20 +3769,18 @@ void tst_QGraphicsItem::removeFromGroup()
class ChildEventTester : public QGraphicsRectItem
{
public:
- ChildEventTester(const QRectF &rect, QGraphicsItem *parent = 0)
- : QGraphicsRectItem(rect, parent), counter(0)
- { }
+ using QGraphicsRectItem::QGraphicsRectItem;
- int counter;
+ int counter = 0;
protected:
- void focusInEvent(QFocusEvent *event)
+ void focusInEvent(QFocusEvent *event) override
{ ++counter; QGraphicsRectItem::focusInEvent(event); }
- void mousePressEvent(QGraphicsSceneMouseEvent *)
+ void mousePressEvent(QGraphicsSceneMouseEvent *) override
{ ++counter; }
- void mouseMoveEvent(QGraphicsSceneMouseEvent *)
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
{ ++counter; }
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
{ ++counter; }
};
@@ -3782,16 +3810,17 @@ void tst_QGraphicsItem::handlesChildEvents()
scene.addItem(blue);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
// Pull out the items, closest item first
QList<QGraphicsItem *> items = scene.items(scene.itemsBoundingRect());
- QCOMPARE(items.at(0), (QGraphicsItem *)yellow);
- QCOMPARE(items.at(1), (QGraphicsItem *)gray);
- QCOMPARE(items.at(2), (QGraphicsItem *)green);
- QCOMPARE(items.at(3), (QGraphicsItem *)red);
- QCOMPARE(items.at(4), (QGraphicsItem *)blue);
+ QCOMPARE(items.at(0), yellow);
+ QCOMPARE(items.at(1), gray);
+ QCOMPARE(items.at(2), green);
+ QCOMPARE(items.at(3), red);
+ QCOMPARE(items.at(4), blue);
QCOMPARE(blue->counter, 0);
@@ -3805,8 +3834,8 @@ void tst_QGraphicsItem::handlesChildEvents()
releaseEvent.setButton(Qt::LeftButton);
releaseEvent.setScenePos(blue->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 2);
@@ -3815,8 +3844,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(red->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 2);
QCOMPARE(red->counter, 2);
@@ -3826,8 +3855,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(green->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 2);
QCOMPARE(red->counter, 2);
@@ -3840,8 +3869,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(red->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 4);
QCOMPARE(red->counter, 2);
@@ -3851,8 +3880,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(green->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 6);
QCOMPARE(red->counter, 2);
@@ -3865,8 +3894,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(red->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 6);
QCOMPARE(red->counter, 4);
@@ -3876,8 +3905,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(green->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 6);
QCOMPARE(red->counter, 4);
@@ -3905,13 +3934,14 @@ void tst_QGraphicsItem::handlesChildEvents2()
scene.addItem(root);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QApplication::processEvents();
QMouseEvent event(QEvent::MouseButtonPress, view.mapFromScene(5, 5),
- view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
QTRY_COMPARE(root->counter, 1);
}
@@ -3920,9 +3950,9 @@ void tst_QGraphicsItem::handlesChildEvents3()
{
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
- ChildEventTester *group2 = new ChildEventTester(QRectF(), 0);
+ ChildEventTester *group2 = new ChildEventTester(QRectF(), nullptr);
ChildEventTester *group1 = new ChildEventTester(QRectF(), group2);
ChildEventTester *leaf = new ChildEventTester(QRectF(), group1);
scene.addItem(group2);
@@ -3962,14 +3992,14 @@ void tst_QGraphicsItem::handlesChildEvents3()
class ChildEventFilterTester : public ChildEventTester
{
public:
- ChildEventFilterTester(const QRectF &rect, QGraphicsItem *parent = 0)
- : ChildEventTester(rect, parent), filter(QEvent::None)
+ ChildEventFilterTester(const QRectF &rect, QGraphicsItem *parent = nullptr)
+ : ChildEventTester(rect, parent)
{ }
- QEvent::Type filter;
+ QEvent::Type filter = QEvent::None;
protected:
- bool sceneEventFilter(QGraphicsItem *item, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *item, QEvent *event) override
{
Q_UNUSED(item);
if (event->type() == filter) {
@@ -3994,6 +4024,7 @@ void tst_QGraphicsItem::filtersChildEvents()
scene.addItem(root);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -4007,8 +4038,8 @@ void tst_QGraphicsItem::filtersChildEvents()
releaseEvent.setButton(Qt::LeftButton);
releaseEvent.setScenePos(QPointF(25, 25));//child->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QTRY_COMPARE(child->counter, 1); // mouse release is not filtered
QCOMPARE(filter->counter, 1); // mouse press is filtered
@@ -4019,8 +4050,8 @@ void tst_QGraphicsItem::filtersChildEvents()
root->filter = QEvent::GraphicsSceneMouseRelease;
// send event to child
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(child->counter, 1);
QCOMPARE(filter->counter, 2); // mouse press is filtered
@@ -4031,8 +4062,8 @@ void tst_QGraphicsItem::filtersChildEvents()
child->setParentItem(parent);
// send event to child
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(child->counter, 2); // mouse press is _not_ filtered
QCOMPARE(parent->counter, 0);
@@ -4063,14 +4094,15 @@ void tst_QGraphicsItem::filtersChildEvents2()
scene.addItem(root);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QApplication::processEvents();
QMouseEvent event(QEvent::MouseButtonPress, view.mapFromScene(5, 5),
- view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
QTRY_COMPARE(root->counter, 1);
QCOMPARE(child->counter, 0);
@@ -4082,10 +4114,10 @@ void tst_QGraphicsItem::filtersChildEvents2()
class CustomItem : public QGraphicsItem
{
public:
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{ return QRectF(-110, -110, 220, 220); }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
for (int x = -100; x <= 100; x += 25)
painter->drawLine(x, -100, x, 100);
@@ -4111,6 +4143,7 @@ void tst_QGraphicsItem::ensureVisible()
scene.addItem(item);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(300, 300);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -4198,37 +4231,37 @@ void tst_QGraphicsItem::cursor()
QPoint item2Center = view.mapFromScene(item2->sceneBoundingRect().center());
{
- QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), viewportShape);
{
- QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), item1->cursor().shape());
{
- QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), item2->cursor().shape());
{
- QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), viewportShape);
item1->setEnabled(false);
{
- QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), viewportShape);
@@ -4342,7 +4375,7 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem()
QVERIFY(!text->openExternalLinks());
QVERIFY(text->textCursor().isNull());
QCOMPARE(text->defaultTextColor(), QPalette().color(QPalette::Text));
- QVERIFY(text->document() != 0);
+ QVERIFY(text->document() != nullptr);
QCOMPARE(text->font(), QApplication::font());
QCOMPARE(text->textInteractionFlags(), Qt::TextInteractionFlags(Qt::NoTextInteraction));
QCOMPARE(text->textWidth(), -1.0);
@@ -4358,12 +4391,12 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem()
event.setScenePos(QPointF(1, 1));
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove);
event2.setScenePos(QPointF(11, 11));
event2.setButton(Qt::LeftButton);
event2.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event2);
+ QCoreApplication::sendEvent(&scene, &event2);
}
QCOMPARE(text->pos(), QPointF(10, 10));
@@ -4379,7 +4412,7 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem()
event2.setScenePos(QPointF(21, 21));
event2.setButton(Qt::LeftButton);
event2.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event2);
+ QCoreApplication::sendEvent(&scene, &event2);
}
QCOMPARE(text->pos(), QPointF(20, 20)); // clicked on edge, item moved
@@ -4420,15 +4453,16 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsEllipseItem()
class ItemChangeTester : public QGraphicsRectItem
{
public:
- ItemChangeTester()
- { setFlag(ItemSendsGeometryChanges); clear(); }
- ItemChangeTester(QGraphicsItem *parent) : QGraphicsRectItem(parent)
- { setFlag(ItemSendsGeometryChanges); clear(); }
+ ItemChangeTester(QGraphicsItem *parent = nullptr) : QGraphicsRectItem(parent)
+ {
+ setFlag(ItemSendsGeometryChanges);
+ clear();
+ }
void clear()
{
itemChangeReturnValue = QVariant();
- itemSceneChangeTargetScene = 0;
+ itemSceneChangeTargetScene = nullptr;
changes.clear();
values.clear();
oldValues.clear();
@@ -4437,11 +4471,11 @@ public:
QVariant itemChangeReturnValue;
QGraphicsScene *itemSceneChangeTargetScene;
- QList<GraphicsItemChange> changes;
- QList<QVariant> values;
- QList<QVariant> oldValues;
+ QVector<GraphicsItemChange> changes;
+ QVariantList values;
+ QVariantList oldValues;
protected:
- QVariant itemChange(GraphicsItemChange change, const QVariant &value)
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
{
changes << change;
values << value;
@@ -4451,6 +4485,7 @@ protected:
break;
case QGraphicsItem::ItemPositionHasChanged:
break;
+#if QT_DEPRECATED_SINCE(5, 14)
case QGraphicsItem::ItemMatrixChange: {
#if QT_DEPRECATED_SINCE(5, 13)
QT_WARNING_PUSH
@@ -4462,6 +4497,7 @@ QT_WARNING_POP
#endif
}
break;
+#endif
case QGraphicsItem::ItemTransformChange: {
QVariant variant;
variant.setValue<QTransform>(transform());
@@ -4558,7 +4594,7 @@ QT_WARNING_POP
void tst_QGraphicsItem::itemChange()
{
ItemChangeTester tester;
- tester.itemSceneChangeTargetScene = 0;
+ tester.itemSceneChangeTargetScene = nullptr;
ItemChangeTester testerHelper;
QVERIFY(tester.changes.isEmpty());
@@ -4576,7 +4612,7 @@ void tst_QGraphicsItem::itemChange()
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemEnabledHasChanged);
QCOMPARE(tester.values.at(tester.values.size() - 2), QVariant(false));
QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant(true));
- QCOMPARE(tester.oldValues.last(), QVariant(true));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(true));
QCOMPARE(tester.isEnabled(), true);
}
#if QT_DEPRECATED_SINCE(5, 13)
@@ -4592,10 +4628,10 @@ QT_WARNING_DISABLE_DEPRECATED // QDesktopWidget::screen()
QCOMPARE(int(tester.changes.last()), int(QGraphicsItem::ItemTransformHasChanged));
QCOMPARE(qvariant_cast<QMatrix>(tester.values.at(tester.values.size() - 2)),
QMatrix().translate(50, 0));
- QCOMPARE(tester.values.last(), QVariant(QTransform(QMatrix().rotate(90))));
+ QCOMPARE(tester.values.constLast(), QVariant(QTransform(QMatrix().rotate(90))));
QVariant variant;
variant.setValue<QMatrix>(QMatrix());
- QCOMPARE(tester.oldValues.last(), variant);
+ QCOMPARE(tester.oldValues.constLast(), variant);
QCOMPARE(tester.matrix(), QMatrix().rotate(90));
QT_WARNING_POP
}
@@ -4619,7 +4655,7 @@ QT_WARNING_POP
QTransform().rotate(90));
QVariant variant;
variant.setValue<QTransform>(QTransform());
- QCOMPARE(tester.oldValues.last(), variant);
+ QCOMPARE(tester.oldValues.constLast(), variant);
QCOMPARE(tester.transform(), QTransform().rotate(90));
}
{
@@ -4633,7 +4669,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemPositionHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(QPointF(0, 42)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(QPointF(42, 0)));
- QCOMPARE(tester.oldValues.last(), QVariant(QPointF()));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(QPointF()));
QCOMPARE(tester.pos(), QPointF(42, 0));
}
{
@@ -4647,7 +4683,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemZValueHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(1.0)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(2.0)));
- QCOMPARE(tester.oldValues.last(), QVariant(qreal(0.0)));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(qreal(0.0)));
QCOMPARE(tester.zValue(), qreal(2.0));
}
{
@@ -4661,7 +4697,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemRotationHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(10.0)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(15.0)));
- QCOMPARE(tester.oldValues.last(), QVariant(qreal(0.0)));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(qreal(0.0)));
QCOMPARE(tester.rotation(), qreal(15.0));
}
{
@@ -4675,7 +4711,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemScaleHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(1.5)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(2.0)));
- QCOMPARE(tester.oldValues.last(), QVariant(qreal(1.0)));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(qreal(1.0)));
QCOMPARE(tester.scale(), qreal(2.0));
}
{
@@ -4689,7 +4725,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemTransformOriginPointHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(QPointF(1.0, 1.0)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(QPointF(2.0, 2.0)));
- QCOMPARE(tester.oldValues.last(), QVariant(QPointF(0.0, 0.0)));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(QPointF(0.0, 0.0)));
QCOMPARE(tester.transformOriginPoint(), QPointF(2.0, 2.0));
}
{
@@ -4705,7 +4741,8 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemFlagsHaveChanged);
QVariant expectedFlags = QVariant::fromValue<quint32>(QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges));
QCOMPARE(tester.values.at(tester.values.size() - 2), expectedFlags);
- QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant::fromValue<quint32>((quint32)QGraphicsItem::ItemIsSelectable));
+ QCOMPARE(tester.values.at(tester.values.size() - 1),
+ QVariant::fromValue<quint32>(quint32(QGraphicsItem::ItemIsSelectable)));
}
{
// ItemSelectedChange
@@ -4720,7 +4757,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSelectedHasChanged);
QCOMPARE(tester.values.at(tester.values.size() - 2), QVariant(true));
QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant(true));
- QCOMPARE(tester.oldValues.last(), QVariant(false));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(false));
QCOMPARE(tester.isSelected(), true);
tester.itemChangeReturnValue = false;
@@ -4752,11 +4789,11 @@ QT_WARNING_POP
}
{
// ItemParentChange
- tester.itemChangeReturnValue.setValue<QGraphicsItem *>(0);
+ tester.itemChangeReturnValue.setValue<QGraphicsItem *>(nullptr);
tester.setParentItem(&testerHelper);
QCOMPARE(tester.changes.size(), ++changeCount);
- QCOMPARE(tester.changes.last(), QGraphicsItem::ItemParentChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper);
+ QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemParentChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), &testerHelper);
QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.oldValues.last()), nullptr);
QCOMPARE(tester.parentItem(), nullptr);
}
@@ -4765,7 +4802,7 @@ QT_WARNING_POP
tester.itemChangeReturnValue = 1.0;
tester.setOpacity(0.7);
QCOMPARE(tester.changes.size(), ++changeCount);
- QCOMPARE(tester.changes.last(), QGraphicsItem::ItemOpacityChange);
+ QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemOpacityChange);
QVERIFY(qFuzzyCompare(qreal(tester.values.last().toDouble()), qreal(0.7)));
QCOMPARE(tester.oldValues.last().toDouble(), double(1.0));
QCOMPARE(tester.opacity(), qreal(1.0));
@@ -4783,19 +4820,19 @@ QT_WARNING_POP
tester.itemChangeReturnValue.clear();
testerHelper.setParentItem(&tester);
QCOMPARE(tester.changes.size(), ++changeCount);
- QCOMPARE(tester.changes.last(), QGraphicsItem::ItemChildAddedChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper);
+ QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemChildAddedChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), &testerHelper);
}
{
// ItemChildRemovedChange 1
- testerHelper.setParentItem(0);
+ testerHelper.setParentItem(nullptr);
QCOMPARE(tester.changes.size(), ++changeCount);
- QCOMPARE(tester.changes.last(), QGraphicsItem::ItemChildRemovedChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper);
+ QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemChildRemovedChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), &testerHelper);
// ItemChildRemovedChange 1
ItemChangeTester *test = new ItemChangeTester;
- test->itemSceneChangeTargetScene = 0;
+ test->itemSceneChangeTargetScene = nullptr;
int count = 0;
QGraphicsScene *scene = new QGraphicsScene;
scene->addItem(test);
@@ -4804,11 +4841,11 @@ QT_WARNING_POP
QGraphicsRectItem *child = new QGraphicsRectItem(test);
//We received ItemChildAddedChange
QCOMPARE(test->changes.size(), ++count);
- QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildAddedChange);
+ QCOMPARE(test->changes.constLast(), QGraphicsItem::ItemChildAddedChange);
delete child;
- child = 0;
+ child = nullptr;
QCOMPARE(test->changes.size(), ++count);
- QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange);
+ QCOMPARE(test->changes.constLast(), QGraphicsItem::ItemChildRemovedChange);
ItemChangeTester *childTester = new ItemChangeTester(test);
//Changes contains all sceneHasChanged and so on, we don't want to test that
@@ -4818,12 +4855,12 @@ QT_WARNING_POP
child = new QGraphicsRectItem(childTester);
//We received ItemChildAddedChange
QCOMPARE(childTester->changes.size(), ++childCount);
- QCOMPARE(childTester->changes.last(), QGraphicsItem::ItemChildAddedChange);
+ QCOMPARE(childTester->changes.constLast(), QGraphicsItem::ItemChildAddedChange);
//Delete the child of the top level with all its children
delete childTester;
//Only one removal
QCOMPARE(test->changes.size(), ++count);
- QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange);
+ QCOMPARE(test->changes.constLast(), QGraphicsItem::ItemChildRemovedChange);
delete scene;
}
{
@@ -4831,11 +4868,11 @@ QT_WARNING_POP
ItemChangeTester parent;
ItemChangeTester *child = new ItemChangeTester;
child->setParentItem(&parent);
- QCOMPARE(parent.changes.last(), QGraphicsItem::ItemChildAddedChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), (QGraphicsItem *)child);
+ QCOMPARE(parent.changes.constLast(), QGraphicsItem::ItemChildAddedChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), child);
delete child;
- QCOMPARE(parent.changes.last(), QGraphicsItem::ItemChildRemovedChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), (QGraphicsItem *)child);
+ QCOMPARE(parent.changes.constLast(), QGraphicsItem::ItemChildRemovedChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), child);
}
{
// !!! Note: If this test crashes because of double-deletion, there's
@@ -4855,7 +4892,7 @@ QT_WARNING_POP
// Item's old value was 0
// Item's current value is scene
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), nullptr);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), (QGraphicsScene *)&scene);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), &scene);
scene2.addItem(&tester);
++changeCount; // ItemSceneChange (0) was: (scene)
++changeCount; // ItemSceneHasChanged (0)
@@ -4871,16 +4908,16 @@ QT_WARNING_POP
// Item's last old value was scene
// Item's last current value is 0
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 2)), (QGraphicsScene *)&scene);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 2)), &scene);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 1)), nullptr);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 4)), nullptr);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), nullptr);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), (QGraphicsScene *)&scene2);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), (QGraphicsScene *)&scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), &scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), &scene2);
// Item's last old value was 0
// Item's last current value is scene2
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), nullptr);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), (QGraphicsScene *)&scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), &scene2);
scene2.removeItem(&tester);
++changeCount; // ItemSceneChange (0) was: (scene2)
@@ -4892,7 +4929,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSceneHasChanged);
// Item's last old value was scene2
// Item's last current value is 0
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), (QGraphicsScene *)&scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), &scene2);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), nullptr);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), nullptr);
@@ -4903,12 +4940,12 @@ QT_WARNING_POP
++changeCount; // ItemSceneHasChanged (scene)
QCOMPARE(tester.values.size(), changeCount);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), (QGraphicsScene *)&scene2);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), (QGraphicsScene *)&scene);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), (QGraphicsScene *)&scene);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), &scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), &scene);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), &scene);
QCOMPARE(tester.scene(), &scene);
- tester.itemSceneChangeTargetScene = 0;
+ tester.itemSceneChangeTargetScene = nullptr;
tester.itemChangeReturnValue = QVariant();
scene.removeItem(&tester);
++changeCount; // ItemSceneChange
@@ -4936,23 +4973,20 @@ QT_WARNING_POP
class EventFilterTesterItem : public QGraphicsLineItem
{
public:
- QList<QEvent::Type> filteredEvents;
- QList<QGraphicsItem *> filteredEventReceivers;
- bool handlesSceneEvents;
-
- QList<QEvent::Type> receivedEvents;
-
- EventFilterTesterItem() : handlesSceneEvents(false) {}
+ QVector<QEvent::Type> filteredEvents;
+ GraphicsItems filteredEventReceivers;
+ QVector<QEvent::Type> receivedEvents;
+ bool handlesSceneEvents = false;
protected:
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
{
filteredEvents << event->type();
filteredEventReceivers << watched;
return handlesSceneEvents;
}
- bool sceneEvent(QEvent *event)
+ bool sceneEvent(QEvent *event) override
{
return QGraphicsLineItem::sceneEvent(event);
}
@@ -4963,6 +4997,7 @@ void tst_QGraphicsItem::sceneEventFilter()
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -5064,16 +5099,16 @@ void tst_QGraphicsItem::prepareGeometryChange()
class PaintTester : public QGraphicsRectItem
{
public:
- PaintTester() : widget(NULL), painted(0) { setRect(QRectF(10, 10, 20, 20));}
+ PaintTester() { setRect(QRectF(10, 10, 20, 20));}
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *w)
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *w) override
{
widget = w;
painted++;
}
- QWidget* widget;
- int painted;
+ QWidget *widget = nullptr;
+ int painted = 0;
};
void tst_QGraphicsItem::paint()
@@ -5084,6 +5119,7 @@ void tst_QGraphicsItem::paint()
scene.addItem(&paintTester);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QApplication::processEvents();
@@ -5100,6 +5136,7 @@ void tst_QGraphicsItem::paint()
QGraphicsScene scene2;
QGraphicsView view2(&scene2);
+ view2.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view2.show();
QVERIFY(QTest::qWaitForWindowExposed(&view2));
QCoreApplication::processEvents(); // Process all queued paint events
@@ -5133,194 +5170,194 @@ class HarakiriItem : public QGraphicsRectItem
public:
HarakiriItem(int harakiriPoint)
: QGraphicsRectItem(QRectF(0, 0, 100, 100)), harakiri(harakiriPoint)
- { dead = 0; }
+ { dead = false; }
- static int dead;
+ static bool dead;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
QGraphicsRectItem::paint(painter, option, widget);
if (harakiri == 0) {
// delete unsupported since 4.5
/*
- dead = 1;
+ dead = true;
delete this;
*/
}
}
- void advance(int n)
+ void advance(int n) override
{
if (harakiri == 1 && n == 0) {
// delete unsupported
/*
- dead = 1;
+ dead = true;
delete this;
*/
}
if (harakiri == 2 && n == 1) {
- dead = 1;
+ dead = true;
delete this;
}
}
protected:
#ifndef QT_NO_CONTEXTMENU
- void contextMenuEvent(QGraphicsSceneContextMenuEvent *)
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent *) override
{
if (harakiri == 3) {
- dead = 1;
+ dead = true;
delete this;
}
}
#endif // QT_NO_CONTEXTMENU
- void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
+ void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override
{
// ??
QGraphicsRectItem::dragEnterEvent(event);
}
- void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
+ void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override
{
// ??
QGraphicsRectItem::dragLeaveEvent(event);
}
- void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
+ void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override
{
// ??
QGraphicsRectItem::dragMoveEvent(event);
}
- void dropEvent(QGraphicsSceneDragDropEvent *event)
+ void dropEvent(QGraphicsSceneDragDropEvent *event) override
{
// ??
QGraphicsRectItem::dropEvent(event);
}
- void focusInEvent(QFocusEvent *)
+ void focusInEvent(QFocusEvent *) override
{
if (harakiri == 4) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void focusOutEvent(QFocusEvent *)
+ void focusOutEvent(QFocusEvent *) override
{
if (harakiri == 5) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void hoverEnterEvent(QGraphicsSceneHoverEvent *)
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
{
if (harakiri == 6) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void hoverLeaveEvent(QGraphicsSceneHoverEvent *)
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
{
if (harakiri == 7) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void hoverMoveEvent(QGraphicsSceneHoverEvent *)
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
{
if (harakiri == 8) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void inputMethodEvent(QInputMethodEvent *event)
+ void inputMethodEvent(QInputMethodEvent *event) override
{
// ??
QGraphicsRectItem::inputMethodEvent(event);
}
- QVariant inputMethodQuery(Qt::InputMethodQuery query) const
+ QVariant inputMethodQuery(Qt::InputMethodQuery query) const override
{
// ??
return QGraphicsRectItem::inputMethodQuery(query);
}
- QVariant itemChange(GraphicsItemChange change, const QVariant &value)
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
{
// deletion not supported
return QGraphicsRectItem::itemChange(change, value);
}
- void keyPressEvent(QKeyEvent *)
+ void keyPressEvent(QKeyEvent *) override
{
if (harakiri == 9) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void keyReleaseEvent(QKeyEvent *)
+ void keyReleaseEvent(QKeyEvent *) override
{
if (harakiri == 10) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *)
+ void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override
{
if (harakiri == 11) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void mouseMoveEvent(QGraphicsSceneMouseEvent *)
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
{
if (harakiri == 12) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void mousePressEvent(QGraphicsSceneMouseEvent *)
+ void mousePressEvent(QGraphicsSceneMouseEvent *) override
{
if (harakiri == 13) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
{
if (harakiri == 14) {
- dead = 1;
+ dead = true;
delete this;
}
}
- bool sceneEvent(QEvent *event)
+ bool sceneEvent(QEvent *event) override
{
// deletion not supported
return QGraphicsRectItem::sceneEvent(event);
}
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
{
// deletion not supported
return QGraphicsRectItem::sceneEventFilter(watched, event);
}
- void wheelEvent(QGraphicsSceneWheelEvent *)
+ void wheelEvent(QGraphicsSceneWheelEvent *) override
{
if (harakiri == 16) {
- dead = 1;
+ dead = true;
delete this;
}
}
@@ -5329,7 +5366,7 @@ private:
int harakiri;
};
-int HarakiriItem::dead;
+bool HarakiriItem::dead;
void tst_QGraphicsItem::deleteItemInEventHandlers()
{
@@ -5344,44 +5381,45 @@ void tst_QGraphicsItem::deleteItemInEventHandlers()
item->installSceneEventFilter(item); // <- ehey!
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
- if (!item->dead)
+ if (!HarakiriItem::dead)
scene.advance();
#ifndef QT_NO_CONTEXTMENU
- if (!item->dead) {
+ if (!HarakiriItem::dead) {
QContextMenuEvent event(QContextMenuEvent::Other,
view.mapFromScene(item->scenePos()));
QCoreApplication::sendEvent(view.viewport(), &event);
}
#endif // QT_NO_CONTEXTMENU
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos()));
- if (!item->dead)
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos()));
- if (!item->dead)
- QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos()));
- if (!item->dead)
- QTest::mouseClick(view.viewport(), Qt::RightButton, 0, view.mapFromScene(item->scenePos()));
- if (!item->dead)
+ if (!HarakiriItem::dead)
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos()));
+ if (!HarakiriItem::dead)
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos()));
+ if (!HarakiriItem::dead)
+ QTest::mouseClick(view.viewport(), Qt::RightButton, {}, view.mapFromScene(item->scenePos()));
+ if (!HarakiriItem::dead)
QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos() + QPointF(20, -20)));
- if (!item->dead)
+ if (!HarakiriItem::dead)
item->setFocus();
- if (!item->dead)
+ if (!HarakiriItem::dead)
item->clearFocus();
- if (!item->dead)
+ if (!HarakiriItem::dead)
item->setFocus();
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::keyPress(view.viewport(), Qt::Key_A);
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::keyRelease(view.viewport(), Qt::Key_A);
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::keyPress(view.viewport(), Qt::Key_A);
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::keyRelease(view.viewport(), Qt::Key_A);
}
}
@@ -5389,12 +5427,12 @@ void tst_QGraphicsItem::deleteItemInEventHandlers()
class ItemPaintsOutsideShape : public QGraphicsItem
{
public:
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{
return QRectF(0, 0, 100, 100);
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
painter->fillRect(-50, -50, 200, 200, Qt::red);
painter->fillRect(0, 0, 100, 100, Qt::blue);
@@ -5490,16 +5528,16 @@ void tst_QGraphicsItem::itemClipsChildrenToShape2()
QGraphicsScene scene;
scene.addItem(parent);
- QCOMPARE(scene.items(QPointF(5, 5)).value(0, nullptr), (QGraphicsItem *)parent);
+ QCOMPARE(scene.items(QPointF(5, 5)).value(0, nullptr), parent);
QVERIFY(scene.items(QPointF(15, 5)).isEmpty());
QVERIFY(scene.items(QPointF(5, 15)).isEmpty());
QVERIFY(scene.items(QPointF(60, 60)).isEmpty());
QVERIFY(scene.items(QPointF(140, 60)).isEmpty());
QVERIFY(scene.items(QPointF(60, 140)).isEmpty());
QVERIFY(scene.items(QPointF(140, 140)).isEmpty());
- QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), (QGraphicsItem *)child2);
- QCOMPARE(scene.items(QPointF(75, 100)).value(0, nullptr), (QGraphicsItem *)child1);
- QCOMPARE(scene.items(QPointF(100, 75)).value(0, nullptr), (QGraphicsItem *)child1);
+ QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), child2);
+ QCOMPARE(scene.items(QPointF(75, 100)).value(0, nullptr), child1);
+ QCOMPARE(scene.items(QPointF(100, 75)).value(0, nullptr), child1);
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied);
image.fill(0);
@@ -5534,9 +5572,9 @@ void tst_QGraphicsItem::itemClipsChildrenToShape3()
grandchild->setPos( 50, 50 );
parent->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
- QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), (QGraphicsItem *)parent);
- QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), (QGraphicsItem *)child);
- QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), (QGraphicsItem *)grandchild);
+ QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), parent);
+ QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), child);
+ QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), grandchild);
QVERIFY(scene.items(QPointF(175, 175)).isEmpty());
// Move child to fully overlap the parent. The grandchild should
@@ -5544,26 +5582,24 @@ void tst_QGraphicsItem::itemClipsChildrenToShape3()
child->prepareGeometryChange();
child->setPos( 0, 0 );
- QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), (QGraphicsItem *)child);
- QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), (QGraphicsItem *)grandchild);
- QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), (QGraphicsItem *)grandchild);
+ QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), child);
+ QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), grandchild);
+ QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), grandchild);
QVERIFY(scene.items(QPointF(175, 175)).isEmpty());
}
class MyProxyWidget : public QGraphicsProxyWidget
{
public:
- MyProxyWidget(QGraphicsItem *parent) : QGraphicsProxyWidget(parent)
- {
- painted = false;
- }
+ using QGraphicsProxyWidget::QGraphicsProxyWidget;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
QGraphicsProxyWidget::paint(painter, option, widget);
painted = true;
}
- bool painted;
+
+ bool painted = false;
};
void tst_QGraphicsItem::itemClipsChildrenToShape4()
@@ -5584,8 +5620,9 @@ void tst_QGraphicsItem::itemClipsChildrenToShape4()
//now the label is shown
outerWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false );
QApplication::setActiveWindow(&view);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
- QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view);
+ QTRY_COMPARE(QApplication::activeWindow(), &view);
QTRY_COMPARE(innerWidget->painted, true);
}
@@ -5608,10 +5645,9 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5()
class ParentItem : public QGraphicsRectItem
{
public:
- ParentItem(qreal x, qreal y, qreal width, qreal height)
- : QGraphicsRectItem(x, y, width, height) {}
+ using QGraphicsRectItem::QGraphicsRectItem;
- QPainterPath shape() const
+ QPainterPath shape() const override
{
QPainterPath path;
path.addRect(50, 50, 200, 200);
@@ -5666,12 +5702,12 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5()
bottomRightChild->setPos(200, 200);
childRegion += QRect(200, 200, 100, 100);
- QPoint controlPoints[17] = {
- QPoint(5, 5) , QPoint(95, 5) , QPoint(205, 5) , QPoint(295, 5) ,
- QPoint(5, 95) , QPoint(95, 95) , QPoint(205, 95) , QPoint(295, 95) ,
- QPoint(150, 150),
- QPoint(5, 205), QPoint(95, 205), QPoint(205, 205), QPoint(295, 205),
- QPoint(5, 295), QPoint(95, 295), QPoint(205, 295), QPoint(295, 295),
+ const QPoint controlPoints[17] = {
+ {5, 5}, {95, 5}, {205, 5}, {295, 5},
+ {5, 95}, {95, 95}, {205, 95}, {295, 95},
+ {150, 150},
+ {5, 205}, {95, 205}, {205, 205}, {295, 205},
+ {5, 295}, {95, 295}, {205, 295}, {295, 295},
};
const QRegion clippedChildRegion = childRegion & QRect(50, 50, 200, 200);
@@ -5682,8 +5718,7 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5()
QImage sceneImage(300, 300, QImage::Format_ARGB32);
#define VERIFY_CONTROL_POINTS(pRegion, cRegion, gRegion) \
- for (int i = 0; i < 17; ++i) { \
- QPoint controlPoint = controlPoints[i]; \
+ for (const QPoint &controlPoint : controlPoints) { \
QRgb pixel = sceneImage.pixel(controlPoint.x(), controlPoint.y()); \
if (pRegion.contains(controlPoint)) \
QVERIFY(qBlue(pixel) != 0); \
@@ -5709,13 +5744,13 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5()
case 0:
// All children stacked in front.
childString = QLatin1String("ChildrenInFront.png");
- foreach (QGraphicsItem *child, children)
+ for (QGraphicsItem *child : children)
child->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
break;
case 1:
// All children stacked behind.
childString = QLatin1String("ChildrenBehind.png");
- foreach (QGraphicsItem *child, children)
+ for (QGraphicsItem *child : children)
child->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
break;
case 2:
@@ -5819,8 +5854,8 @@ void tst_QGraphicsItem::itemClippingDiscovery()
rightRectItem->setParentItem(clipItem);
// The rects item are both visible at these points.
- QCOMPARE(scene.items(QPointF(10, 10)).value(0, nullptr), (QGraphicsItem *)leftRectItem);
- QCOMPARE(scene.items(QPointF(90, 90)).value(0, nullptr), (QGraphicsItem *)rightRectItem);
+ QCOMPARE(scene.items(QPointF(10, 10)).value(0, nullptr), leftRectItem);
+ QCOMPARE(scene.items(QPointF(90, 90)).value(0, nullptr), rightRectItem);
// The ellipse clips the rects now.
clipItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
@@ -5835,13 +5870,15 @@ void tst_QGraphicsItem::itemClippingDiscovery()
class ItemCountsBoundingRectCalls : public QGraphicsRectItem
{
public:
- ItemCountsBoundingRectCalls(const QRectF & rect, QGraphicsItem *parent = 0)
- : QGraphicsRectItem(rect, parent), boundingRectCalls(0) {}
- QRectF boundingRect () const {
+ using QGraphicsRectItem::QGraphicsRectItem;
+
+ QRectF boundingRect () const override
+ {
++boundingRectCalls;
return QGraphicsRectItem::boundingRect();
}
- mutable int boundingRectCalls;
+
+ mutable int boundingRectCalls = 0;
};
void tst_QGraphicsItem::itemContainsChildrenInShape()
@@ -6004,7 +6041,7 @@ void tst_QGraphicsItem::ancestorFlags()
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1);
// Reparent the child to root
- level21->setParentItem(0);
+ level21->setParentItem(nullptr);
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0);
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0);
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1);
@@ -6028,7 +6065,7 @@ void tst_QGraphicsItem::ancestorFlags()
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1);
// Reparenting level31 back to level21.
- level31->setParentItem(0);
+ level31->setParentItem(nullptr);
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0);
level31->setParentItem(level21);
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0);
@@ -6067,7 +6104,6 @@ void tst_QGraphicsItem::ancestorFlags()
break;
default:
qFatal("Unknown ancestor flag, please fix!");
- break;
}
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0);
@@ -6134,7 +6170,7 @@ void tst_QGraphicsItem::ancestorFlags()
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag);
// Reparent the child to root
- level21->setParentItem(0);
+ level21->setParentItem(nullptr);
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0);
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0);
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag);
@@ -6158,7 +6194,7 @@ void tst_QGraphicsItem::ancestorFlags()
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag);
// Reparenting level31 back to level21.
- level31->setParentItem(0);
+ level31->setParentItem(nullptr);
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0);
level31->setParentItem(level21);
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0);
@@ -6189,28 +6225,29 @@ void tst_QGraphicsItem::ancestorFlags()
void tst_QGraphicsItem::untransformable()
{
- QGraphicsItem *item1 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
+ auto item1 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
item1->setZValue(1);
item1->setFlag(QGraphicsItem::ItemIgnoresTransformations);
item1->setTransform(QTransform().rotate(45), true);
- ((QGraphicsEllipseItem *)item1)->setBrush(Qt::red);
+ item1->setBrush(Qt::red);
- QGraphicsItem *item2 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
+ auto item2 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
item2->setParentItem(item1);
item2->setTransform(QTransform().rotate(45), true);
item2->setPos(100, 0);
- ((QGraphicsEllipseItem *)item2)->setBrush(Qt::green);
+ item2->setBrush(Qt::green);
- QGraphicsItem *item3 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
+ auto item3 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
item3->setParentItem(item2);
item3->setPos(100, 0);
- ((QGraphicsEllipseItem *)item3)->setBrush(Qt::blue);
+ item3->setBrush(Qt::blue);
QGraphicsScene scene(-500, -500, 1000, 1000);
scene.addItem(item1);
QWidget topLevel;
QGraphicsView view(&scene,&topLevel);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.resize(300, 300);
topLevel.show();
view.scale(8, 8);
@@ -6255,14 +6292,14 @@ void tst_QGraphicsItem::untransformable()
class ContextMenuItem : public QGraphicsRectItem
{
public:
- ContextMenuItem()
- : ignoreEvent(true), gotEvent(false), eventWasAccepted(false)
- { }
- bool ignoreEvent;
- bool gotEvent;
- bool eventWasAccepted;
+ using QGraphicsRectItem::QGraphicsRectItem;
+
+ bool ignoreEvent = true;
+ bool gotEvent = false;
+ bool eventWasAccepted = false;
+
protected:
- void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
{
gotEvent = true;
eventWasAccepted = event->isAccepted();
@@ -6282,6 +6319,7 @@ void tst_QGraphicsItem::contextMenuEventPropagation()
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setAlignment(Qt::AlignLeft | Qt::AlignTop);
view.show();
view.resize(200, 200);
@@ -6290,14 +6328,14 @@ void tst_QGraphicsItem::contextMenuEventPropagation()
QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(10, 10),
view.viewport()->mapToGlobal(QPoint(10, 10)));
event.ignore();
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(!event.isAccepted());
scene.addItem(bottomItem);
topItem->ignoreEvent = true;
bottomItem->ignoreEvent = true;
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(!event.isAccepted());
QCOMPARE(topItem->gotEvent, true);
QCOMPARE(topItem->eventWasAccepted, true);
@@ -6308,7 +6346,7 @@ void tst_QGraphicsItem::contextMenuEventPropagation()
topItem->gotEvent = false;
bottomItem->gotEvent = false;
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(event.isAccepted());
QCOMPARE(topItem->gotEvent, true);
QCOMPARE(bottomItem->gotEvent, false);
@@ -6328,34 +6366,34 @@ void tst_QGraphicsItem::itemIsMovable()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
QCOMPARE(rect->pos(), QPointF(0, 0));
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setButtons(Qt::LeftButton);
event.setScenePos(QPointF(10, 10));
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
QCOMPARE(rect->pos(), QPointF(10, 10));
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setButtons(Qt::RightButton);
event.setScenePos(QPointF(20, 20));
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
QCOMPARE(rect->pos(), QPointF(10, 10));
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setButtons(Qt::LeftButton);
event.setScenePos(QPointF(30, 30));
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
QCOMPARE(rect->pos(), QPointF(30, 30));
}
@@ -6366,14 +6404,14 @@ class ItemAddScene : public QGraphicsScene
public:
ItemAddScene()
{
- QTimer::singleShot(500, this, SLOT(newTextItem()));
+ QTimer::singleShot(500, this, &ItemAddScene::newTextItem);
}
public slots:
void newTextItem()
{
// Add a text item
- QGraphicsItem *item = new QGraphicsTextItem("This item will not ensure that it's visible", 0);
+ QGraphicsItem *item = addText("This item will not ensure that it's visible");
item->setPos(.0, .0);
item->show();
}
@@ -6385,6 +6423,7 @@ void tst_QGraphicsItem::task141694_textItemEnsureVisible()
scene.setSceneRect(-1000, -1000, 2000, 2000);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(200, 200);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -6412,6 +6451,7 @@ void tst_QGraphicsItem::task128696_textItemEnsureMovable()
scene.addItem(item);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(200, 200);
view.show();
@@ -6419,14 +6459,14 @@ void tst_QGraphicsItem::task128696_textItemEnsureMovable()
event1.setScenePos(QPointF(0, 0));
event1.setButton(Qt::LeftButton);
event1.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCoreApplication::sendEvent(&scene, &event1);
+ QCOMPARE(scene.mouseGrabberItem(), item);
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove);
event2.setScenePos(QPointF(10, 10));
event2.setButton(Qt::LeftButton);
event2.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event2);
+ QCoreApplication::sendEvent(&scene, &event2);
QCOMPARE(item->pos(), QPointF(10, 10));
}
@@ -6445,33 +6485,45 @@ void tst_QGraphicsItem::task177918_lineItemUndetected()
void tst_QGraphicsItem::task240400_clickOnTextItem_data()
{
- QTest::addColumn<int>("flags");
- QTest::addColumn<int>("textFlags");
- QTest::newRow("editor, noflags") << 0 << int(Qt::TextEditorInteraction);
- QTest::newRow("editor, movable") << int(QGraphicsItem::ItemIsMovable) << int(Qt::TextEditorInteraction);
- QTest::newRow("editor, selectable") << int(QGraphicsItem::ItemIsSelectable) << int(Qt::TextEditorInteraction);
- QTest::newRow("editor, movable | selectable") << int(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
- << int(Qt::TextEditorInteraction);
- QTest::newRow("noninteractive, noflags") << 0 << int(Qt::NoTextInteraction);
- QTest::newRow("noninteractive, movable") << int(QGraphicsItem::ItemIsMovable) << int(Qt::NoTextInteraction);
- QTest::newRow("noninteractive, selectable") << int(QGraphicsItem::ItemIsSelectable) << int(Qt::NoTextInteraction);
- QTest::newRow("noninteractive, movable | selectable") << int(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
- << int(Qt::NoTextInteraction);
+ using Flags = QGraphicsItem::GraphicsItemFlags;
+ QTest::addColumn<Flags>("flags");
+ QTest::addColumn<Qt::TextInteractionFlags>("textFlags");
+ QTest::newRow("editor, noflags")
+ << Flags{}
+ << Qt::TextInteractionFlags(Qt::TextEditorInteraction);
+ QTest::newRow("editor, movable")
+ << Flags(QGraphicsItem::ItemIsMovable)
+ << Qt::TextInteractionFlags(Qt::TextEditorInteraction);
+ QTest::newRow("editor, selectable")
+ << Flags(QGraphicsItem::ItemIsSelectable)
+ << Qt::TextInteractionFlags(Qt::TextEditorInteraction);
+ QTest::newRow("editor, movable | selectable")
+ << Flags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
+ << Qt::TextInteractionFlags(Qt::TextEditorInteraction);
+ QTest::newRow("noninteractive, noflags")
+ << Flags{} << Qt::TextInteractionFlags(Qt::NoTextInteraction);
+ QTest::newRow("noninteractive, movable")
+ << Flags(QGraphicsItem::ItemIsMovable) << Qt::TextInteractionFlags(Qt::NoTextInteraction);
+ QTest::newRow("noninteractive, selectable")
+ << Flags(QGraphicsItem::ItemIsSelectable) << Qt::TextInteractionFlags(Qt::NoTextInteraction);
+ QTest::newRow("noninteractive, movable | selectable")
+ << Flags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
+ << Qt::TextInteractionFlags(Qt::NoTextInteraction);
}
void tst_QGraphicsItem::task240400_clickOnTextItem()
{
- QFETCH(int, flags);
- QFETCH(int, textFlags);
+ QFETCH(QGraphicsItem::GraphicsItemFlags, flags);
+ QFETCH(Qt::TextInteractionFlags, textFlags);
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QGraphicsTextItem *item = scene.addText("Hello");
- item->setFlags(QGraphicsItem::GraphicsItemFlags(flags));
- item->setTextInteractionFlags(Qt::TextInteractionFlags(textFlags));
- bool focusable = (item->flags() & QGraphicsItem::ItemIsFocusable);
+ item->setFlags(flags);
+ item->setTextInteractionFlags(textFlags);
+ const bool focusable = item->flags().testFlag(QGraphicsItem::ItemIsFocusable);
QVERIFY(textFlags ? focusable : !focusable);
int column = item->textCursor().columnNumber();
@@ -6485,25 +6537,25 @@ void tst_QGraphicsItem::task240400_clickOnTextItem()
event.setScenePos(item->sceneBoundingRect().topLeft() + QPointF(0.1, 0.1));
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
if (flags || textFlags)
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCOMPARE(scene.mouseGrabberItem(), item);
else
QCOMPARE(scene.mouseGrabberItem(), nullptr);
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease);
event.setScenePos(item->sceneBoundingRect().topLeft() + QPointF(0.1, 0.1));
event.setButton(Qt::LeftButton);
- event.setButtons(0);
- QApplication::sendEvent(&scene, &event);
+ event.setButtons({});
+ QCoreApplication::sendEvent(&scene, &event);
}
if (textFlags)
QVERIFY(item->hasFocus());
else
QVERIFY(!item->hasFocus());
QVERIFY(!scene.mouseGrabberItem());
- bool selectable = (flags & QGraphicsItem::ItemIsSelectable);
+ bool selectable = flags.testFlag(QGraphicsItem::ItemIsSelectable);
QVERIFY(selectable ? item->isSelected() : !item->isSelected());
// Now click in the middle and check that the cursor moved.
@@ -6512,18 +6564,18 @@ void tst_QGraphicsItem::task240400_clickOnTextItem()
event.setScenePos(item->sceneBoundingRect().center());
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
if (flags || textFlags)
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCOMPARE(scene.mouseGrabberItem(), item);
else
QCOMPARE(scene.mouseGrabberItem(), nullptr);
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease);
event.setScenePos(item->sceneBoundingRect().center());
event.setButton(Qt::LeftButton);
- event.setButtons(0);
- QApplication::sendEvent(&scene, &event);
+ event.setButtons({});
+ QCoreApplication::sendEvent(&scene, &event);
}
if (textFlags)
QVERIFY(item->hasFocus());
@@ -6534,7 +6586,7 @@ void tst_QGraphicsItem::task240400_clickOnTextItem()
QVERIFY(selectable ? item->isSelected() : !item->isSelected());
//
- if (textFlags & Qt::TextEditorInteraction)
+ if (textFlags.testFlag(Qt::TextEditorInteraction))
QVERIFY(item->textCursor().columnNumber() > column);
else
QCOMPARE(item->textCursor().columnNumber(), 0);
@@ -6543,24 +6595,22 @@ void tst_QGraphicsItem::task240400_clickOnTextItem()
class TextItem : public QGraphicsSimpleTextItem
{
public:
- TextItem(const QString& text) : QGraphicsSimpleTextItem(text)
- {
- updates = 0;
- }
+ using QGraphicsSimpleTextItem::QGraphicsSimpleTextItem;
- void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
+ void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) override
{
updates++;
QGraphicsSimpleTextItem::paint(painter, option, widget);
}
- int updates;
+ int updates = 0;
};
void tst_QGraphicsItem::ensureUpdateOnTextItem()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QCoreApplication::processEvents(); // Process all queued paint events
@@ -6834,6 +6884,7 @@ void tst_QGraphicsItem::opacity2()
scene.addItem(parent);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -6908,6 +6959,7 @@ void tst_QGraphicsItem::opacityZeroUpdates()
scene.addItem(parent);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -6937,18 +6989,18 @@ void tst_QGraphicsItem::opacityZeroUpdates()
class StacksBehindParentHelper : public QGraphicsRectItem
{
public:
- StacksBehindParentHelper(QList<QGraphicsItem *> *paintedItems, const QRectF &rect, QGraphicsItem *parent = 0)
- : QGraphicsRectItem(rect, parent), paintedItems(paintedItems)
+ StacksBehindParentHelper(GraphicsItems *paintedItems, const QRectF &rect, QGraphicsItem *parent = nullptr)
+ : QGraphicsRectItem(rect, parent), m_paintedItems(paintedItems)
{ }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
QGraphicsRectItem::paint(painter, option, widget);
- paintedItems->append(this);
+ m_paintedItems->append(this);
}
private:
- QList<QGraphicsItem *> *paintedItems;
+ GraphicsItems *m_paintedItems;
};
void tst_QGraphicsItem::itemStacksBehindParent()
@@ -6986,6 +7038,7 @@ void tst_QGraphicsItem::itemStacksBehindParent()
scene.addItem(parent2);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QTRY_VERIFY(!paintedItems.isEmpty());
@@ -6993,55 +7046,47 @@ void tst_QGraphicsItem::itemStacksBehindParent()
view.viewport()->update();
QApplication::processEvents();
QRectF rect(0, 0, 100, 100);
- QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>()
- << grandChild111 << child11
- << grandChild121 << child12 << parent1
- << grandChild211 << child21
- << grandChild221 << child22 << parent2));
- QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>()
- << parent2 << child22 << grandChild221
- << child21 << grandChild211
- << parent1 << child12 << grandChild121
- << child11 << grandChild111);
+ const GraphicsItemsList expected1{grandChild111, child11, grandChild121, child12, parent1,
+ grandChild211, child21, grandChild221, child22, parent2};
+ QTRY_COMPARE(scene.items(rect), expected1);
+
+ const GraphicsItems expected2{parent2, child22, grandChild221, child21, grandChild211,
+ parent1, child12, grandChild121, child11, grandChild111};
+ QTRY_COMPARE(paintedItems, expected2);
child11->setFlag(QGraphicsItem::ItemStacksBehindParent);
scene.update();
paintedItems.clear();
- QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>()
- << grandChild121 << child12 << parent1
- << grandChild111 << child11
- << grandChild211 << child21
- << grandChild221 << child22 << parent2));
- QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>()
- << parent2 << child22 << grandChild221
- << child21 << grandChild211
- << child11 << grandChild111
- << parent1 << child12 << grandChild121);
+ const GraphicsItemsList expected3{grandChild121, child12, parent1, grandChild111, child11,
+ grandChild211, child21, grandChild221, child22, parent2};
+
+ QTRY_COMPARE(scene.items(rect), expected3);
+ const GraphicsItems expected4{parent2, child22, grandChild221, child21, grandChild211, child11, grandChild111,
+ parent1, child12, grandChild121};
+ QTRY_COMPARE(paintedItems, expected4);
child12->setFlag(QGraphicsItem::ItemStacksBehindParent);
paintedItems.clear();
scene.update();
- QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>()
- << parent1 << grandChild111 << child11
- << grandChild121 << child12
- << grandChild211 << child21
- << grandChild221 << child22 << parent2));
- QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>()
- << parent2 << child22 << grandChild221
- << child21 << grandChild211
- << child12 << grandChild121
- << child11 << grandChild111 << parent1);
+ const GraphicsItemsList expected5{parent1, grandChild111, child11, grandChild121, child12,
+ grandChild211, child21, grandChild221, child22, parent2};
+ QTRY_COMPARE(scene.items(rect), expected5);
+
+ const GraphicsItems expected6{parent2, child22, grandChild221, child21, grandChild211,
+ child12, grandChild121, child11, grandChild111, parent1};
+ QTRY_COMPARE(paintedItems, expected6);
}
class ClippingAndTransformsScene : public QGraphicsScene
{
+ Q_OBJECT
public:
- QList<QGraphicsItem *> drawnItems;
+ GraphicsItems drawnItems;
protected:
void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[],
- const QStyleOptionGraphicsItem options[], QWidget *widget = 0)
+ const QStyleOptionGraphicsItem options[], QWidget *widget = nullptr) override
{
drawnItems.clear();
for (int i = 0; i < numItems; ++i)
@@ -7082,11 +7127,11 @@ void tst_QGraphicsItem::nestedClipping()
QGraphicsView view(&scene);
view.setOptimizationFlag(QGraphicsView::IndirectPainting);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QList<QGraphicsItem *> expected;
- expected << root << l1 << l2 << l3;
+ GraphicsItems expected{root, l1, l2, l3};
QTRY_COMPARE(scene.drawnItems, expected);
QImage image(200, 200, QImage::Format_ARGB32_Premultiplied);
@@ -7124,7 +7169,7 @@ public:
QTransform x;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget = 0)
+ QWidget *widget = nullptr) override
{
x = painter->worldTransform();
QGraphicsRectItem::paint(painter, option, widget);
@@ -7193,6 +7238,7 @@ void tst_QGraphicsItem::sceneTransformCache()
rect2->setTransform(QTransform().rotate(90), true);
rect->setTransform(QTransform::fromTranslate(0, 50), true);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
rect->setTransform(QTransform::fromTranslate(0, 100), true);
@@ -7269,6 +7315,7 @@ void tst_QGraphicsItem::tabChangesFocus()
layout->addWidget(dial2);
QWidget widget;
+ widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
widget.setLayout(layout);
widget.show();
QVERIFY(QTest::qWaitForWindowActive(&widget));
@@ -7299,6 +7346,7 @@ void tst_QGraphicsItem::cacheMode()
{
QGraphicsScene scene(0, 0, 100, 100);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.resize(150, 150);
view.show();
QApplication::setActiveWindow(&view);
@@ -7479,6 +7527,7 @@ void tst_QGraphicsItem::cacheMode2()
{
QGraphicsScene scene(0, 0, 100, 100);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.resize(150, 150);
view.show();
QApplication::setActiveWindow(&view);
@@ -7550,6 +7599,7 @@ void tst_QGraphicsItem::updateCachedItemAfterMove()
QGraphicsScene scene;
scene.addItem(tester);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -7587,7 +7637,7 @@ public:
setAcceptHoverEvents(true);
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override
{
QGraphicsRectItem::paint(painter, option, widget);
const QString text = QString::number(p.x()) + QLatin1Char('x') + QString::number(p.y())
@@ -7596,7 +7646,7 @@ public:
}
protected:
- void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
{
p = event->pos();
sp = event->widget()->mapFromGlobal(event->screenPos());
@@ -7693,6 +7743,7 @@ void tst_QGraphicsItem::update()
QGraphicsScene scene;
scene.setSceneRect(-100, -100, 200, 200);
QWidget topLevel;
+ topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
MyGraphicsView view(&scene,&topLevel);
topLevel.resize(300, 300);
@@ -7730,7 +7781,7 @@ void tst_QGraphicsItem::update()
view.reset();
item->repaints = 0;
item->update(-15, -15, 5, 5); // Item's brect: (-10, -10, 20, 20)
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 0);
@@ -7739,7 +7790,7 @@ void tst_QGraphicsItem::update()
item->repaints = 0;
item->update(); // Full update; all sub-sequent update requests are discarded.
item->hide(); // visible set to 0. ignoreVisible must be set to 1; the item won't be processed otherwise.
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 1);
// The entire item's bounding rect (adjusted for antialiasing) should have been painted.
@@ -7749,7 +7800,7 @@ void tst_QGraphicsItem::update()
view.reset();
item->repaints = 0;
item->show();
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 1);
QCOMPARE(view.repaints, 1);
// The entire item's bounding rect (adjusted for antialiasing) should have been painted.
@@ -7757,21 +7808,21 @@ void tst_QGraphicsItem::update()
item->repaints = 0;
item->hide();
- qApp->processEvents();
+ QCoreApplication::processEvents();
view.reset();
const QPointF originalPos = item->pos();
item->setPos(5000, 5000);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 0);
- qApp->processEvents();
+ QCoreApplication::processEvents();
item->setPos(originalPos);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 0);
item->show();
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 1);
QCOMPARE(view.repaints, 1);
// The entire item's bounding rect (adjusted for antialiasing) should have been painted.
@@ -7802,14 +7853,14 @@ void tst_QGraphicsItem::update()
view.reset();
item->repaints = 0;
parent->setTransform(QTransform::fromTranslate(-400, 0), true);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 1);
QCOMPARE(view.paintedRegion, expectedRegion);
view.reset();
item->repaints = 0;
parent->setTransform(QTransform::fromTranslate(400, 0), true);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 1);
QCOMPARE(view.repaints, 1);
QCOMPARE(view.paintedRegion, expectedRegion);
@@ -7931,11 +7982,9 @@ void tst_QGraphicsItem::setTransformProperties()
class MyStyleOptionTester : public QGraphicsRectItem
{
public:
- MyStyleOptionTester(const QRectF &rect)
- : QGraphicsRectItem(rect), startTrack(false)
- {}
+ using QGraphicsRectItem::QGraphicsRectItem;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override
{
++repaints;
if (startTrack) {
@@ -7951,7 +8000,7 @@ public:
}
QGraphicsRectItem::paint(painter, option, widget);
}
- bool startTrack;
+ bool startTrack = false;
int repaints = 0;
};
@@ -7969,6 +8018,7 @@ void tst_QGraphicsItem::itemUsesExtendedStyleOption()
scene.addItem(rect);
rect->setPos(200, 200);
QWidget topLevel;
+ topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
topLevel.resize(200, 200);
QGraphicsView view(&scene, &topLevel);
topLevel.setWindowFlags(Qt::X11BypassWindowManagerHint);
@@ -7996,7 +8046,7 @@ void tst_QGraphicsItem::itemUsesExtendedStyleOption()
void tst_QGraphicsItem::itemSendsGeometryChanges()
{
ItemChangeTester item;
- item.setFlags(0);
+ item.setFlags(nullptr);
item.clear();
QTransform x = QTransform().rotate(45);
@@ -8036,21 +8086,21 @@ void tst_QGraphicsItem::itemSendsGeometryChanges()
QCOMPARE(item.scale(), qreal(1.0));
QCOMPARE(item.transformOriginPoint(), QPointF(0.0, 0.0));
- QCOMPARE(item.changes, QList<QGraphicsItem::GraphicsItemChange>()
- << QGraphicsItem::ItemOpacityChange
- << QGraphicsItem::ItemOpacityHasChanged
- << QGraphicsItem::ItemFlagsChange
- << QGraphicsItem::ItemFlagsHaveChanged
- << QGraphicsItem::ItemTransformChange
- << QGraphicsItem::ItemTransformHasChanged
- << QGraphicsItem::ItemPositionChange
- << QGraphicsItem::ItemPositionHasChanged
- << QGraphicsItem::ItemRotationChange
- << QGraphicsItem::ItemRotationHasChanged
- << QGraphicsItem::ItemScaleChange
- << QGraphicsItem::ItemScaleHasChanged
- << QGraphicsItem::ItemTransformOriginPointChange
- << QGraphicsItem::ItemTransformOriginPointHasChanged);
+ const QVector<QGraphicsItem::GraphicsItemChange> expected{QGraphicsItem::ItemOpacityChange,
+ QGraphicsItem::ItemOpacityHasChanged,
+ QGraphicsItem::ItemFlagsChange,
+ QGraphicsItem::ItemFlagsHaveChanged,
+ QGraphicsItem::ItemTransformChange,
+ QGraphicsItem::ItemTransformHasChanged,
+ QGraphicsItem::ItemPositionChange,
+ QGraphicsItem::ItemPositionHasChanged,
+ QGraphicsItem::ItemRotationChange,
+ QGraphicsItem::ItemRotationHasChanged,
+ QGraphicsItem::ItemScaleChange,
+ QGraphicsItem::ItemScaleHasChanged,
+ QGraphicsItem::ItemTransformOriginPointChange,
+ QGraphicsItem::ItemTransformOriginPointHasChanged};
+ QCOMPARE(item.changes, expected);
}
// Make sure we update moved items correctly.
@@ -8060,6 +8110,7 @@ void tst_QGraphicsItem::moveItem()
scene.setSceneRect(-50, -50, 200, 200);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QCoreApplication::processEvents(); // Process all queued paint events
@@ -8086,7 +8137,7 @@ void tst_QGraphicsItem::moveItem()
.adjusted(-2, -2, 2, 2); // Adjusted for antialiasing.
parent->setPos(20, 20);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(parent->repaints, 1);
QCOMPARE(view.repaints, 1);
QRegion expectedParentRegion = parentDeviceBoundingRect; // old position
@@ -8097,7 +8148,7 @@ void tst_QGraphicsItem::moveItem()
RESET_COUNTERS
child->setPos(20, 20);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(parent->repaints, 1);
QCOMPARE(child->repaints, 1);
QCOMPARE(view.repaints, 1);
@@ -8107,7 +8158,7 @@ void tst_QGraphicsItem::moveItem()
RESET_COUNTERS
grandChild->setPos(20, 20);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(parent->repaints, 1);
QCOMPARE(child->repaints, 1);
QCOMPARE(grandChild->repaints, 1);
@@ -8118,7 +8169,7 @@ void tst_QGraphicsItem::moveItem()
RESET_COUNTERS
parent->setTransform(QTransform::fromTranslate(20, 20), true);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(parent->repaints, 1);
QCOMPARE(child->repaints, 1);
QCOMPARE(grandChild->repaints, 1);
@@ -8138,6 +8189,7 @@ void tst_QGraphicsItem::moveLineItem()
scene.addItem(item);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -8146,9 +8198,9 @@ void tst_QGraphicsItem::moveLineItem()
QRectF brect = item->boundingRect();
// Do same adjustments as in qgraphicsscene.cpp
- if (!brect.width())
+ if (qFuzzyIsNull(brect.width()))
brect.adjust(qreal(-0.00001), 0, qreal(0.00001), 0);
- if (!brect.height())
+ if (qFuzzyIsNull(brect.height()))
brect.adjust(0, qreal(-0.00001), 0, qreal(0.00001));
const QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform())
.mapRect(brect).toAlignedRect();
@@ -8204,6 +8256,7 @@ void tst_QGraphicsItem::sorting()
scene.addItem(item2);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
// Use Qt::Tool as fully decorated windows have a minimum width of 160 on Windows.
view.setWindowFlags(view.windowFlags() | Qt::Tool);
view.setResizeAnchor(QGraphicsView::NoAnchor);
@@ -8225,13 +8278,13 @@ void tst_QGraphicsItem::sorting()
QTest::qWait(100);
#endif
- QCOMPARE(_paintedItems, QList<QGraphicsItem *>()
- << grid[0][0] << grid[0][1] << grid[0][2] << grid[0][3]
- << grid[1][0] << grid[1][1] << grid[1][2] << grid[1][3]
- << grid[2][0] << grid[2][1] << grid[2][2] << grid[2][3]
- << grid[3][0] << grid[3][1] << grid[3][2] << grid[3][3]
- << grid[4][0] << grid[4][1] << grid[4][2] << grid[4][3]
- << item1 << item2);
+ const GraphicsItems expected{grid[0][0], grid[0][1], grid[0][2], grid[0][3],
+ grid[1][0], grid[1][1], grid[1][2], grid[1][3],
+ grid[2][0], grid[2][1], grid[2][2], grid[2][3],
+ grid[3][0], grid[3][1], grid[3][2], grid[3][3],
+ grid[4][0], grid[4][1], grid[4][2], grid[4][3],
+ item1, item2};
+ QCOMPARE(_paintedItems, expected);
}
void tst_QGraphicsItem::itemHasNoContents()
@@ -8247,6 +8300,7 @@ void tst_QGraphicsItem::itemHasNoContents()
scene.addItem(item1);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -8262,7 +8316,7 @@ void tst_QGraphicsItem::itemHasNoContents()
QTest::qWait(10);
#endif
- QTRY_COMPARE(_paintedItems, QList<QGraphicsItem *>() << item2);
+ QTRY_COMPARE(_paintedItems, GraphicsItems{item2});
}
void tst_QGraphicsItem::hitTestUntransformableItem()
@@ -8271,6 +8325,7 @@ void tst_QGraphicsItem::hitTestUntransformableItem()
scene.setSceneRect(-100, -100, 200, 200);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -8301,7 +8356,7 @@ void tst_QGraphicsItem::hitTestUntransformableItem()
QList<QGraphicsItem *> items = scene.items(QPointF(80, 80));
QCOMPARE(items.size(), 1);
- QCOMPARE(items.at(0), static_cast<QGraphicsItem*>(item3));
+ QCOMPARE(items.at(0), item3);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
QTest::qWait(100);
@@ -8317,6 +8372,7 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem()
scene.setSceneRect(-100, -100, 200, 200);
QWidget toplevel;
+ toplevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
QGraphicsView view(&scene, &toplevel);
toplevel.resize(300, 300);
@@ -8377,7 +8433,7 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem()
QVERIFY(items.isEmpty());
items = scene.items(QPointF(80, 80));
QCOMPARE(items.size(), 1);
- QCOMPARE(items.at(0), static_cast<QGraphicsItem *>(item3));
+ QCOMPARE(items.at(0), item3);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
QTest::qWait(100);
@@ -8393,7 +8449,7 @@ void tst_QGraphicsItem::focusProxy()
{
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QGraphicsItem *item = scene.addRect(0, 0, 10, 10);
item->setFlag(QGraphicsItem::ItemIsFocusable);
@@ -8412,27 +8468,27 @@ void tst_QGraphicsItem::focusProxy()
QString err;
QTextStream stream(&err);
stream << "QGraphicsItem::setFocusProxy: "
- << (void*)item << " is already in the focus proxy chain" << Qt::flush;
+ << static_cast<const void*>(item) << " is already in the focus proxy chain" << Qt::flush;
QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData());
item2->setFocusProxy(item); // fails
- QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2);
+ QCOMPARE(item->focusProxy(), item2);
QCOMPARE(item2->focusProxy(), nullptr);
// Try to assign self as focus proxy
QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::setFocusProxy: cannot assign self as focus proxy");
item->setFocusProxy(item); // fails
- QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2);
+ QCOMPARE(item->focusProxy(), item2);
QCOMPARE(item2->focusProxy(), nullptr);
// Reset the focus proxy
- item->setFocusProxy(0);
+ item->setFocusProxy(nullptr);
QCOMPARE(item->focusProxy(), nullptr);
QVERIFY(!item->hasFocus());
QVERIFY(item2->hasFocus());
// Test deletion
item->setFocusProxy(item2);
- QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2);
+ QCOMPARE(item->focusProxy(), item2);
delete item2;
QCOMPARE(item->focusProxy(), nullptr);
@@ -8483,7 +8539,7 @@ void tst_QGraphicsItem::subFocus()
QVERIFY(!text->hasFocus());
text->setFocus();
QVERIFY(!text->hasFocus());
- QCOMPARE(text->focusItem(), (QGraphicsItem *)text);
+ QCOMPARE(text->focusItem(), text);
// Add a sibling.
QGraphicsTextItem *text2 = new QGraphicsTextItem("Hi");
@@ -8494,7 +8550,7 @@ void tst_QGraphicsItem::subFocus()
// got input focus.
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(text);
scene.addItem(text2);
@@ -8508,10 +8564,10 @@ void tst_QGraphicsItem::subFocus()
scene.removeItem(text2);
text2->setFocus();
scene.addItem(text2);
- QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2);
+ QCOMPARE(text2->focusItem(), text2);
text2->setParentItem(text);
- QCOMPARE(text->focusItem(), (QGraphicsItem *)text2);
- QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2);
+ QCOMPARE(text->focusItem(), text2);
+ QCOMPARE(text2->focusItem(), text2);
QVERIFY(!text->hasFocus());
QVERIFY(text2->hasFocus());
@@ -8522,12 +8578,12 @@ void tst_QGraphicsItem::subFocus()
QCOMPARE(text->focusItem(), nullptr);
QCOMPARE(text2->focusItem(), nullptr);
text2->setFocus();
- QCOMPARE(text->focusItem(), (QGraphicsItem *)text2);
- QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2);
+ QCOMPARE(text->focusItem(), text2);
+ QCOMPARE(text2->focusItem(), text2);
scene.addItem(text);
// Hiding and showing text should pass focus to text2.
- QCOMPARE(text->focusItem(), (QGraphicsItem *)text2);
+ QCOMPARE(text->focusItem(), text2);
QVERIFY(text2->hasFocus());
// Subfocus should repropagate to root when reparenting.
@@ -8544,15 +8600,15 @@ void tst_QGraphicsItem::subFocus()
rect3->setFocus();
QVERIFY(!rect3->hasFocus());
- QCOMPARE(rect->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect2->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect3->focusItem(), (QGraphicsItem *)rect3);
+ QCOMPARE(rect->focusItem(), rect3);
+ QCOMPARE(rect2->focusItem(), rect3);
+ QCOMPARE(rect3->focusItem(), rect3);
rect->setParentItem(text2);
- QCOMPARE(text->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(text2->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect2->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect3->focusItem(), (QGraphicsItem *)rect3);
+ QCOMPARE(text->focusItem(), rect3);
+ QCOMPARE(text2->focusItem(), rect3);
+ QCOMPARE(rect->focusItem(), rect3);
+ QCOMPARE(rect2->focusItem(), rect3);
+ QCOMPARE(rect3->focusItem(), rect3);
QVERIFY(!rect->hasFocus());
QVERIFY(!rect2->hasFocus());
QVERIFY(rect3->hasFocus());
@@ -8568,7 +8624,7 @@ void tst_QGraphicsItem::focusProxyDeletion()
QGraphicsRectItem *rect = new QGraphicsRectItem;
QGraphicsRectItem *rect2 = new QGraphicsRectItem;
rect->setFocusProxy(rect2);
- QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2);
+ QCOMPARE(rect->focusProxy(), rect2);
delete rect2;
QCOMPARE(rect->focusProxy(), nullptr);
@@ -8593,13 +8649,13 @@ void tst_QGraphicsItem::focusProxyDeletion()
QCOMPARE(rect->focusProxy(), nullptr);
scene->addItem(rect2);
rect->setFocusProxy(rect2);
- QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2);
+ QCOMPARE(rect->focusProxy(), rect2);
delete rect; // don't crash
rect = new QGraphicsRectItem;
rect2 = new QGraphicsRectItem;
rect->setFocusProxy(rect2);
- QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2);
+ QCOMPARE(rect->focusProxy(), rect2);
scene->addItem(rect);
scene->addItem(rect2);
rect->setFocusProxy(rect2);
@@ -8671,7 +8727,7 @@ void tst_QGraphicsItem::setGraphicsEffect()
// Ensure the existing effect is uninstalled and deleted when setting a null effect
blurEffect = new QGraphicsBlurEffect;
item->setGraphicsEffect(blurEffect);
- item->setGraphicsEffect(0);
+ item->setGraphicsEffect(nullptr);
QVERIFY(!item->graphicsEffect());
QVERIFY(!blurEffect);
@@ -8731,11 +8787,11 @@ void tst_QGraphicsItem::panel()
QEvent activate(QEvent::WindowActivate);
QEvent deactivate(QEvent::WindowDeactivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
// No previous activation, so the scene is active.
QVERIFY(scene.isActive());
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)panel1);
+ QCOMPARE(scene.activePanel(), panel1);
QVERIFY(panel1->isActive());
QVERIFY(!panel2->isActive());
QVERIFY(!panel3->isActive());
@@ -8750,7 +8806,7 @@ void tst_QGraphicsItem::panel()
QCOMPARE(spy_activate_panel4.count(), 0);
// Switch back to scene.
- scene.setActivePanel(0);
+ scene.setActivePanel(nullptr);
QVERIFY(!scene.activePanel());
QVERIFY(!panel1->isActive());
QVERIFY(!panel2->isActive());
@@ -8762,7 +8818,7 @@ void tst_QGraphicsItem::panel()
QCOMPARE(spy_activate_notPanel2.count(), 1);
// Deactivate the scene
- QApplication::sendEvent(&scene, &deactivate);
+ QCoreApplication::sendEvent(&scene, &deactivate);
QVERIFY(!scene.activePanel());
QVERIFY(!panel1->isActive());
QVERIFY(!panel2->isActive());
@@ -8774,7 +8830,7 @@ void tst_QGraphicsItem::panel()
QCOMPARE(spy_deactivate_notPanel2.count(), 1);
// Reactivate the scene
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(!scene.activePanel());
QVERIFY(!panel1->isActive());
QVERIFY(!panel2->isActive());
@@ -8793,23 +8849,23 @@ void tst_QGraphicsItem::panel()
QCOMPARE(spy_activate_panel1.count(), 2);
// Deactivate the scene
- QApplication::sendEvent(&scene, &deactivate);
+ QCoreApplication::sendEvent(&scene, &deactivate);
QVERIFY(!panel1->isActive());
QCOMPARE(spy_deactivate_panel1.count(), 2);
// Reactivate the scene
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(panel1->isActive());
QCOMPARE(spy_activate_panel1.count(), 3);
// Deactivate the scene
- QApplication::sendEvent(&scene, &deactivate);
+ QCoreApplication::sendEvent(&scene, &deactivate);
QVERIFY(!panel1->isActive());
QVERIFY(!scene.activePanel());
- scene.setActivePanel(0);
+ scene.setActivePanel(nullptr);
// Reactivate the scene
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(!panel1->isActive());
}
@@ -8819,12 +8875,18 @@ void tst_QGraphicsItem::panelWithFocusItems()
{
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
bool widget = (i == 1);
- QGraphicsItem *parentPanel = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *parentPanelFocusItem = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *parentPanelFocusItemSibling = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
+ auto parentPanel = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto parentPanelFocusItem = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto parentPanelFocusItemSibling = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
parentPanel->setFlag(QGraphicsItem::ItemIsPanel);
parentPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable);
parentPanelFocusItemSibling->setFlag(QGraphicsItem::ItemIsFocusable);
@@ -8839,21 +8901,28 @@ void tst_QGraphicsItem::panelWithFocusItems()
QVERIFY(parentPanel->isActive());
QVERIFY(parentPanelFocusItem->hasFocus());
- QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
-
- QGraphicsItem *childPanel = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *childPanelFocusItem = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *grandChildPanelFocusItem = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *grandChildPanelFocusItem2 = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
+ QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem);
+ QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem);
+
+ auto childPanel = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto childPanelFocusItem = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto grandChildPanelFocusItem = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto grandChildPanelFocusItem2 = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
childPanel->setFlag(QGraphicsItem::ItemIsPanel);
childPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable);
grandChildPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable);
grandChildPanelFocusItem2->setFlag(QGraphicsItem::ItemIsFocusable);
- if (widget)
- {
+ if (widget) {
static_cast<QGraphicsWidget *>(childPanelFocusItem)->setFocusPolicy(Qt::StrongFocus);
static_cast<QGraphicsWidget *>(grandChildPanelFocusItem)->setFocusPolicy(Qt::StrongFocus);
static_cast<QGraphicsWidget *>(grandChildPanelFocusItem2)->setFocusPolicy(Qt::StrongFocus);
@@ -8864,45 +8933,45 @@ void tst_QGraphicsItem::panelWithFocusItems()
grandChildPanelFocusItem->setFocus();
QVERIFY(!grandChildPanelFocusItem->hasFocus());
- QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(grandChildPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(childPanelFocusItem->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(grandChildPanelFocusItem->focusItem(), grandChildPanelFocusItem);
childPanel->setParentItem(parentPanel);
QVERIFY(!parentPanel->isActive());
QVERIFY(!parentPanelFocusItem->hasFocus());
- QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
+ QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem);
+ QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem);
QVERIFY(childPanel->isActive());
QVERIFY(!childPanelFocusItem->hasFocus());
QVERIFY(grandChildPanelFocusItem->hasFocus());
- QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(childPanelFocusItem->focusItem(), grandChildPanelFocusItem);
childPanel->hide();
- QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem);
QVERIFY(!childPanel->focusItem()->hasFocus());
QVERIFY(parentPanel->isActive());
QVERIFY(parentPanelFocusItem->hasFocus());
- QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(grandChildPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem);
+ QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem);
+ QCOMPARE(grandChildPanelFocusItem->focusItem(), grandChildPanelFocusItem);
childPanel->show();
QVERIFY(childPanel->isActive());
QVERIFY(grandChildPanelFocusItem->hasFocus());
- QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(grandChildPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(childPanelFocusItem->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(grandChildPanelFocusItem->focusItem(), grandChildPanelFocusItem);
childPanel->hide();
QVERIFY(parentPanel->isActive());
QVERIFY(parentPanelFocusItem->hasFocus());
- QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
+ QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem);
+ QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem);
}
}
@@ -8919,7 +8988,7 @@ void tst_QGraphicsItem::addPanelToActiveScene()
QEvent activate(QEvent::WindowActivate);
QEvent deactivate(QEvent::WindowDeactivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(scene.isActive());
scene.addItem(rect);
QVERIFY(rect->isActive());
@@ -8928,12 +8997,12 @@ void tst_QGraphicsItem::addPanelToActiveScene()
rect->setFlag(QGraphicsItem::ItemIsPanel);
scene.addItem(rect);
QVERIFY(rect->isActive());
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect);
+ QCOMPARE(scene.activePanel(), rect);
QGraphicsRectItem *rect2 = new QGraphicsRectItem;
scene.addItem(rect2);
QVERIFY(rect->isActive());
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect);
+ QCOMPARE(scene.activePanel(), rect);
}
void tst_QGraphicsItem::activate()
@@ -8945,7 +9014,7 @@ void tst_QGraphicsItem::activate()
QEvent activate(QEvent::WindowActivate);
QEvent deactivate(QEvent::WindowDeactivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
// Non-panel item (active when scene is active).
QVERIFY(rect->isActive());
@@ -8991,14 +9060,14 @@ void tst_QGraphicsItem::activate()
QGraphicsRectItem *rect5 = new QGraphicsRectItem(rect4);
QGraphicsRectItem *rect6 = new QGraphicsRectItem(rect5);
scene.addItem(rect4);
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect3);
+ QCOMPARE(scene.activePanel(), rect3);
scene.removeItem(rect4);
rect6->setActive(true);
scene.addItem(rect4);
QVERIFY(rect4->isActive());
QVERIFY(rect5->isActive());
QVERIFY(rect6->isActive());
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect4);
+ QCOMPARE(scene.activePanel(), rect4);
scene.removeItem(rect4); // no active panel
rect6->setActive(false);
scene.addItem(rect4);
@@ -9009,11 +9078,11 @@ void tst_QGraphicsItem::activate()
// Controlling auto-activation when the scene changes activation.
rect4->setActive(true);
- QApplication::sendEvent(&scene, &deactivate);
+ QCoreApplication::sendEvent(&scene, &deactivate);
QVERIFY(!scene.isActive());
QVERIFY(!rect4->isActive());
rect4->setActive(false);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(scene.isActive());
QVERIFY(!scene.activePanel());
QVERIFY(!rect4->isActive());
@@ -9045,7 +9114,7 @@ void tst_QGraphicsItem::activationOnShowHide()
{
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QGraphicsRectItem *rootPanel = scene.addRect(QRectF());
rootPanel->setFlag(QGraphicsItem::ItemIsPanel);
@@ -9107,18 +9176,19 @@ void tst_QGraphicsItem::activationOnShowHide()
class MoveWhileDying : public QGraphicsRectItem
{
public:
- MoveWhileDying(QGraphicsItem *parent = 0)
- : QGraphicsRectItem(parent)
- { }
+ using QGraphicsRectItem::QGraphicsRectItem;
+
~MoveWhileDying()
{
- foreach (QGraphicsItem *c, childItems()) {
- foreach (QGraphicsItem *cc, c->childItems()) {
+ const auto children = childItems();
+ for (QGraphicsItem *c : children) {
+ const auto grandChildren = c->childItems();
+ for (QGraphicsItem *cc : grandChildren)
cc->moveBy(10, 10);
- }
c->moveBy(10, 10);
}
- if (QGraphicsItem *p = parentItem()) { p->moveBy(10, 10); }
+ if (QGraphicsItem *p = parentItem())
+ p->moveBy(10, 10);
}
};
@@ -9132,7 +9202,7 @@ void tst_QGraphicsItem::deactivateInactivePanel()
panel2->setFlag(QGraphicsItem::ItemIsPanel);
QEvent event(QEvent::WindowActivate);
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
panel1->setActive(true);
QVERIFY(scene.isActive());
@@ -9170,6 +9240,7 @@ void tst_QGraphicsItem::moveWhileDeleting()
child = new QGraphicsRectItem(silly);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -9198,12 +9269,9 @@ class MyRectItem : public QGraphicsWidget
{
Q_OBJECT
public:
- MyRectItem(QGraphicsItem *parent = 0) : QGraphicsWidget(parent)
- {
+ using QGraphicsWidget::QGraphicsWidget;
- }
-
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
painter->setBrush(brush);
painter->drawRect(boundingRect());
@@ -9214,7 +9282,7 @@ public:
topLevel->collidingItems(Qt::IntersectsItemBoundingRect);
}
public:
- QGraphicsItem *topLevel;
+ QGraphicsItem *topLevel = nullptr;
QBrush brush;
};
@@ -9256,6 +9324,7 @@ void tst_QGraphicsItem::ensureDirtySceneTransform()
child3->brush = QBrush(QColor(Qt::gray));
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -9290,7 +9359,7 @@ void tst_QGraphicsItem::focusScope()
scope3->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
scope3->setFocus();
QVERIFY(!scope3->focusScopeItem());
- QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope3->focusItem(), scope3);
QGraphicsRectItem *scope2 = new QGraphicsRectItem;
scope2->setData(0, "scope2");
@@ -9298,8 +9367,8 @@ void tst_QGraphicsItem::focusScope()
scope2->setFocus();
QVERIFY(!scope2->focusScopeItem());
scope3->setParentItem(scope2);
- QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope2->focusScopeItem(), scope3);
+ QCOMPARE(scope2->focusItem(), scope3);
QGraphicsRectItem *scope1 = new QGraphicsRectItem;
scope1->setData(0, "scope1");
@@ -9308,11 +9377,11 @@ void tst_QGraphicsItem::focusScope()
QVERIFY(!scope1->focusScopeItem());
scope2->setParentItem(scope1);
- QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope1->focusScopeItem(), (QGraphicsItem *)scope2);
- QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope1->focusItem(), scope3);
+ QCOMPARE(scope2->focusItem(), scope3);
+ QCOMPARE(scope3->focusItem(), scope3);
+ QCOMPARE(scope1->focusScopeItem(), scope2);
+ QCOMPARE(scope2->focusScopeItem(), scope3);
QCOMPARE(scope3->focusScopeItem(), nullptr);
scene.addItem(scope1);
@@ -9321,11 +9390,11 @@ void tst_QGraphicsItem::focusScope()
qApp->sendEvent(&scene, &windowActivate);
scene.setFocus();
- QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope1->focusScopeItem(), (QGraphicsItem *)scope2);
- QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope1->focusItem(), scope3);
+ QCOMPARE(scope2->focusItem(), scope3);
+ QCOMPARE(scope3->focusItem(), scope3);
+ QCOMPARE(scope1->focusScopeItem(), scope2);
+ QCOMPARE(scope2->focusScopeItem(), scope3);
QCOMPARE(scope3->focusScopeItem(), nullptr);
QVERIFY(scope3->hasFocus());
@@ -9403,10 +9472,10 @@ void tst_QGraphicsItem::focusScope()
rect5->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
rect5->setFocus();
rect5->setParentItem(rect4);
- QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)rect5);
+ QCOMPARE(scope3->focusScopeItem(), rect5);
QVERIFY(rect5->hasFocus());
- rect4->setParentItem(0);
+ rect4->setParentItem(nullptr);
QVERIFY(rect5->hasFocus());
QCOMPARE(scope3->focusScopeItem(), nullptr);
QCOMPARE(scope3->focusItem(), nullptr);
@@ -9426,7 +9495,7 @@ void tst_QGraphicsItem::focusScope()
scopeA->setFocus();
QVERIFY(scopeB->hasFocus());
- QCOMPARE(scopeB->focusItem(), (QGraphicsItem *)scopeB);
+ QCOMPARE(scopeB->focusItem(), scopeB);
}
void tst_QGraphicsItem::focusScope2()
@@ -9434,7 +9503,7 @@ void tst_QGraphicsItem::focusScope2()
QGraphicsRectItem *child1 = new QGraphicsRectItem;
child1->setFlags(QGraphicsItem::ItemIsFocusable);
child1->setFocus();
- QCOMPARE(child1->focusItem(), (QGraphicsItem *)child1);
+ QCOMPARE(child1->focusItem(), child1);
QGraphicsRectItem *child2 = new QGraphicsRectItem;
child2->setFlags(QGraphicsItem::ItemIsFocusable);
@@ -9442,13 +9511,13 @@ void tst_QGraphicsItem::focusScope2()
QGraphicsRectItem *rootFocusScope = new QGraphicsRectItem;
rootFocusScope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
rootFocusScope->setFocus();
- QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)rootFocusScope);
+ QCOMPARE(rootFocusScope->focusItem(), rootFocusScope);
child1->setParentItem(rootFocusScope);
child2->setParentItem(rootFocusScope);
- QCOMPARE(rootFocusScope->focusScopeItem(), (QGraphicsItem *)child1);
- QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)child1);
+ QCOMPARE(rootFocusScope->focusScopeItem(), child1);
+ QCOMPARE(rootFocusScope->focusItem(), child1);
QGraphicsRectItem *siblingChild1 = new QGraphicsRectItem;
siblingChild1->setFlags(QGraphicsItem::ItemIsFocusable);
@@ -9463,14 +9532,14 @@ void tst_QGraphicsItem::focusScope2()
siblingChild1->setParentItem(siblingFocusScope);
siblingChild2->setParentItem(siblingFocusScope);
- QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild1);
+ QCOMPARE(siblingFocusScope->focusScopeItem(), siblingChild1);
QCOMPARE(siblingFocusScope->focusItem(), nullptr);
QGraphicsItem *root = new QGraphicsRectItem;
rootFocusScope->setParentItem(root);
siblingFocusScope->setParentItem(root);
- QCOMPARE(root->focusItem(), (QGraphicsItem *)child1);
+ QCOMPARE(root->focusItem(), child1);
QGraphicsScene scene;
scene.addItem(root);
@@ -9479,7 +9548,7 @@ void tst_QGraphicsItem::focusScope2()
qApp->sendEvent(&scene, &activate);
scene.setFocus();
- QCOMPARE(scene.focusItem(), (QGraphicsItem *)child1);
+ QCOMPARE(scene.focusItem(), child1);
// You cannot set focus on a descendant of a focus scope directly;
// this will only change the scope's focus scope item pointer. If
@@ -9488,15 +9557,15 @@ void tst_QGraphicsItem::focusScope2()
siblingChild2->setFocus();
QVERIFY(!siblingChild2->hasFocus());
QVERIFY(!siblingChild2->focusItem());
- QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2);
+ QCOMPARE(siblingFocusScope->focusScopeItem(), siblingChild2);
QCOMPARE(siblingFocusScope->focusItem(), nullptr);
// Set focus on the scope; focus is forwarded to the focus scope item.
siblingFocusScope->setFocus();
QVERIFY(siblingChild2->hasFocus());
QVERIFY(siblingChild2->focusItem());
- QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2);
- QCOMPARE(siblingFocusScope->focusItem(), (QGraphicsItem *)siblingChild2);
+ QCOMPARE(siblingFocusScope->focusScopeItem(), siblingChild2);
+ QCOMPARE(siblingFocusScope->focusItem(), siblingChild2);
}
class FocusScopeItemPrivate;
@@ -9504,11 +9573,11 @@ class FocusScopeItem : public QGraphicsItem
{
Q_DECLARE_PRIVATE(FocusScopeItem)
public:
- FocusScopeItem(QGraphicsItem *parent = 0);
- QRectF boundingRect() const { return QRectF(); }
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) { }
+ FocusScopeItem(QGraphicsItem *parent = nullptr);
+ QRectF boundingRect() const override { return QRectF(); }
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override { }
- int focusScopeChanged;
+ int focusScopeChanged = 0;
FocusScopeItemPrivate *d_ptr;
};
@@ -9516,12 +9585,12 @@ class FocusScopeItemPrivate : QGraphicsItemPrivate
{
Q_DECLARE_PUBLIC(FocusScopeItem)
public:
- void focusScopeItemChange(bool)
+ void focusScopeItemChange(bool) override
{ ++q_func()->focusScopeChanged; }
};
FocusScopeItem::FocusScopeItem(QGraphicsItem *parent)
- : QGraphicsItem(*new FocusScopeItemPrivate, parent), focusScopeChanged(0)
+ : QGraphicsItem(*new FocusScopeItemPrivate, parent)
{
setFlag(ItemIsFocusable);
}
@@ -9538,15 +9607,15 @@ void tst_QGraphicsItem::focusScopeItemChangedWhileScopeDoesntHaveFocus()
QCOMPARE(child1->focusScopeChanged, 0);
QCOMPARE(child2->focusScopeChanged, 0);
child1->setFocus();
- QCOMPARE(rect.focusScopeItem(), (QGraphicsItem *)child1);
+ QCOMPARE(rect.focusScopeItem(), child1);
QCOMPARE(child1->focusScopeChanged, 1);
QCOMPARE(child2->focusScopeChanged, 0);
child2->setFocus();
- QCOMPARE(rect.focusScopeItem(), (QGraphicsItem *)child2);
+ QCOMPARE(rect.focusScopeItem(), child2);
QCOMPARE(child1->focusScopeChanged, 2);
QCOMPARE(child2->focusScopeChanged, 1);
child1->setFocus();
- QCOMPARE(rect.focusScopeItem(), (QGraphicsItem *)child1);
+ QCOMPARE(rect.focusScopeItem(), child1);
QCOMPARE(child1->focusScopeChanged, 3);
QCOMPARE(child2->focusScopeChanged, 2);
child1->clearFocus();
@@ -9562,75 +9631,81 @@ void tst_QGraphicsItem::stackBefore()
QGraphicsRectItem *child2 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent);
QGraphicsRectItem *child3 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent);
QGraphicsRectItem *child4 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent);
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ const GraphicsItemsList expected1234{child1, child2, child3, child4};
+ QCOMPARE(parent.childItems(), expected1234);
child1->setData(0, "child1");
child2->setData(0, "child2");
child3->setData(0, "child3");
child4->setData(0, "child4");
// Remove and append
- child2->setParentItem(0);
+ child2->setParentItem(nullptr);
child2->setParentItem(&parent);
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2));
+ const GraphicsItemsList expected1342{child1, child3, child4, child2};
+ QCOMPARE(parent.childItems(), expected1342);
// Move child2 before child1
child2->stackBefore(child1); // 2134
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
+ const GraphicsItemsList expected2134{child2, child1, child3, child4};
+ QCOMPARE(parent.childItems(), expected2134);
child2->stackBefore(child2); // 2134
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
+ QCOMPARE(parent.childItems(), expected2134);
child1->setZValue(1); // 2341
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
+ const GraphicsItemsList expected2341{child2, child3, child4, child1};
+ QCOMPARE(parent.childItems(), expected2341);
child1->stackBefore(child2); // 2341
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
+ QCOMPARE(parent.childItems(), expected2341);
child1->setZValue(0); // 1234
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(parent.childItems(), expected1234);
child4->stackBefore(child1); // 4123
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3));
+ const GraphicsItemsList expected4123{child4, child1, child2, child3};
+ QCOMPARE(parent.childItems(), expected4123);
child4->setZValue(1); // 1234 (4123)
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(parent.childItems(), expected1234);
child3->stackBefore(child1); // 3124 (4312)
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4));
+ const GraphicsItemsList expected3124{child3, child1, child2, child4};
+ QCOMPARE(parent.childItems(), expected3124);
child4->setZValue(0); // 4312
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2));
+ const GraphicsItemsList expected4312{child4, child3, child1, child2};
+ QCOMPARE(parent.childItems(), expected4312);
// Make them all toplevels
- child1->setParentItem(0);
- child2->setParentItem(0);
- child3->setParentItem(0);
- child4->setParentItem(0);
+ child1->setParentItem(nullptr);
+ child2->setParentItem(nullptr);
+ child3->setParentItem(nullptr);
+ child4->setParentItem(nullptr);
QGraphicsScene scene;
scene.addItem(child1);
scene.addItem(child2);
scene.addItem(child3);
scene.addItem(child4);
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder),
- (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1234);
// Remove and append
scene.removeItem(child2);
scene.addItem(child2);
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1342);
// Move child2 before child1
child2->stackBefore(child1); // 2134
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2134);
child2->stackBefore(child2); // 2134
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2134);
child1->setZValue(1); // 2341
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2341);
child1->stackBefore(child2); // 2341
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2341);
child1->setZValue(0); // 1234
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1234);
child4->stackBefore(child1); // 4123
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected4123);
child4->setZValue(1); // 1234 (4123)
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1234);
child3->stackBefore(child1); // 3124 (4312)
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected3124);
child4->setZValue(0); // 4312
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected4312);
}
void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect()
@@ -9643,24 +9718,25 @@ void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect()
scene.setSceneRect(-100, -100, 200, 200); // contains the tester item
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(QApplication::activeWindow(), (QWidget *)&view);
+ QCOMPARE(QApplication::activeWindow(), &view);
QTRY_COMPARE(tester->repaints, 1);
scene.update(); // triggers "updateAll" optimization
- qApp->processEvents();
- qApp->processEvents(); // in 4.6 only one processEvents is necessary
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents(); // in 4.6 only one processEvents is necessary
QCOMPARE(tester->repaints, 1);
scene.update(); // triggers "updateAll" optimization
tester->update();
- qApp->processEvents();
- qApp->processEvents(); // in 4.6 only one processEvents is necessary
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents(); // in 4.6 only one processEvents is necessary
QCOMPARE(tester->repaints, 2);
}
@@ -10201,7 +10277,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.mouseGrabberItem(), rect1);
// grab lost when rect1 is modally shadowed
rect2->setPanelModality(QGraphicsItem::SceneModal);
@@ -10241,7 +10317,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.mouseGrabberItem(), rect1);
// grab lost to rect2 when rect1 is modally shadowed
rect2->setPanelModality(QGraphicsItem::SceneModal);
@@ -10281,7 +10357,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.mouseGrabberItem(), rect1);
// grab lost when rect1 is modally shadowed
rect2->setPanelModality(QGraphicsItem::PanelModal);
@@ -10321,7 +10397,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.mouseGrabberItem(), rect1);
// grab lost to rect2 when rect1 is modally shadowed
rect2->setPanelModality(QGraphicsItem::PanelModal);
@@ -10373,7 +10449,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1);
QCOMPARE(rect3Spy.counts[QEvent::GraphicsSceneMousePress], 1);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// grab is *not* lost when rect1 is modally shadowed by rect2
rect2->setPanelModality(QGraphicsItem::PanelModal);
@@ -10383,7 +10459,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// releasing goes to rect3
sendMouseRelease(&scene, QPoint(150, 50));
@@ -10406,7 +10482,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// grab is not lost
rect2->setPanelModality(QGraphicsItem::PanelModal);
@@ -10416,7 +10492,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// grab stays on rect3
rect2->setPanelModality(QGraphicsItem::NonModal);
@@ -10426,7 +10502,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// release goes to rect3
sendMouseRelease(&scene, QPoint(150, 50));
@@ -10456,18 +10532,18 @@ void tst_QGraphicsItem::modality_clickFocus()
rect2->setData(0, "rect2");
QEvent windowActivateEvent(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &windowActivateEvent);
+ QCoreApplication::sendEvent(&scene, &windowActivateEvent);
EventSpy2 rect1Spy(&scene, rect1);
EventSpy2 rect2Spy(&scene, rect2);
// activate rect1, it should get focus
rect1->setActive(true);
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.focusItem(), rect1);
// focus stays when rect2 becomes modal
rect2->setPanelModality(QGraphicsItem::SceneModal);
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.focusItem(), rect1);
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1);
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0);
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0);
@@ -10485,7 +10561,7 @@ void tst_QGraphicsItem::modality_clickFocus()
// clicking on rect2 gives it focus
rect2->setActive(true);
sendMouseClick(&scene, QPointF(75, 75));
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect2);
+ QCOMPARE(scene.focusItem(), rect2);
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1);
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 1);
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1);
@@ -10511,7 +10587,7 @@ void tst_QGraphicsItem::modality_clickFocus()
// click on rect1, it should get focus now
sendMouseClick(&scene, QPointF(-25, -25));
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.focusItem(), rect1);
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 3);
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 2);
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1);
@@ -10544,7 +10620,7 @@ void tst_QGraphicsItem::modality_keyEvents()
rect2child->setData(0, "rect2child1");
QEvent windowActivateEvent(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &windowActivateEvent);
+ QCoreApplication::sendEvent(&scene, &windowActivateEvent);
EventSpy2 rect1Spy(&scene, rect1);
EventSpy2 rect1childSpy(&scene, rect1child);
@@ -10554,11 +10630,11 @@ void tst_QGraphicsItem::modality_keyEvents()
// activate rect1 and give it rect1child focus
rect1->setActive(true);
rect1child->setFocus();
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child);
+ QCOMPARE(scene.focusItem(), rect1child);
// focus stays on rect1child when rect2 becomes modal
rect2->setPanelModality(QGraphicsItem::SceneModal);
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child);
+ QCOMPARE(scene.focusItem(), rect1child);
// but key events to rect1child should be neither delivered nor propagated
sendKeyClick(&scene, Qt::Key_A);
@@ -10572,7 +10648,7 @@ void tst_QGraphicsItem::modality_keyEvents()
// change to panel modality, rect1child1 keeps focus
rect2->setPanelModality(QGraphicsItem::PanelModal);
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child);
+ QCOMPARE(scene.focusItem(), rect1child);
// still no key events
sendKeyClick(&scene, Qt::Key_J);
@@ -10627,14 +10703,7 @@ void tst_QGraphicsItem::itemIsInFront()
QCOMPARE(qt_closestItemFirst(rect1child1_2, rect2child1), false);
}
-class ScenePosChangeTester : public ItemChangeTester
-{
-public:
- ScenePosChangeTester()
- { }
- ScenePosChangeTester(QGraphicsItem *parent) : ItemChangeTester(parent)
- { }
-};
+using ScenePosChangeTester = ItemChangeTester;
void tst_QGraphicsItem::scenePosChange()
{
@@ -10693,7 +10762,7 @@ void tst_QGraphicsItem::scenePosChange()
// remove
scene.removeItem(grandChild1.data());
- delete grandChild2; grandChild2 = 0;
+ delete grandChild2; grandChild2 = nullptr;
QCoreApplication::processEvents(); // QGraphicsScenePrivate::_q_updateScenePosDescendants()
root->moveBy(1.0, 1.0);
QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 4);
@@ -10714,13 +10783,13 @@ void tst_QGraphicsItem::scenePosChange()
void tst_QGraphicsItem::textItem_shortcuts()
{
QWidget w;
- QVBoxLayout l;
- w.setLayout(&l);
+ w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
+ auto l = new QVBoxLayout(&w);
QGraphicsScene scene;
QGraphicsView view(&scene);
- l.addWidget(&view);
+ l->addWidget(&view);
QPushButton b("Push Me");
- l.addWidget(&b);
+ l->addWidget(&b);
QGraphicsTextItem *item = scene.addText("Troll Text");
item->setFlag(QGraphicsItem::ItemIsFocusable);
@@ -10774,6 +10843,7 @@ void tst_QGraphicsItem::scroll()
scene.addItem(item2);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFrameStyle(0);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -10857,7 +10927,7 @@ void tst_QGraphicsItem::focusHandling()
{
public:
MyItem() : QGraphicsRectItem(0, 0, 100, 100) {}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
painter->fillRect(boundingRect(), hasFocus() ? QBrush(Qt::red) : brush());
}
@@ -10922,6 +10992,8 @@ void tst_QGraphicsItem::focusHandling()
class TouchEventTestee : public QGraphicsRectItem
{
public:
+ using TouchPoints = QVector<QTouchEvent::TouchPoint>;
+
TouchEventTestee(const QSizeF &size = QSizeF(100, 100)) :
QGraphicsRectItem(QRectF(QPointF(), size))
{
@@ -10929,10 +11001,10 @@ public:
setFlag(QGraphicsItem::ItemIsFocusable, false);
}
- QList<QTouchEvent::TouchPoint> touchBeginPoints() const { return m_touchBeginPoints; }
+ TouchPoints touchBeginPoints() const { return m_touchBeginPoints; }
int touchBeginEventCount() const { return m_touchBeginPoints.size(); }
- QList<QTouchEvent::TouchPoint> touchUpdatePoints() const { return m_touchUpdatePoints; }
+ TouchPoints touchUpdatePoints() const { return m_touchUpdatePoints; }
int touchUpdateEventCount() const { return m_touchUpdatePoints.size(); }
protected:
@@ -10955,8 +11027,8 @@ protected:
}
private:
- QList<QTouchEvent::TouchPoint> m_touchBeginPoints;
- QList<QTouchEvent::TouchPoint> m_touchUpdatePoints;
+ TouchPoints m_touchBeginPoints;
+ TouchPoints m_touchUpdatePoints;
};
static QList<QTouchEvent::TouchPoint>
@@ -11155,6 +11227,7 @@ void tst_QGraphicsItem::deviceCoordinateCache_simpleRotations()
scene.addItem(item);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QTRY_VERIFY(view.repaints > 0);
@@ -11222,7 +11295,7 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor()
struct Item : public QGraphicsTextItem
{
int painted;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) override
{
painted++;
QGraphicsTextItem::paint(painter, opt, wid);
@@ -11235,6 +11308,7 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor()
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
scene.addItem(i);
@@ -11262,9 +11336,9 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor()
for (int x = 0; x < image.width(); ++x) {
// Because of antialiasing we allow a certain range of errors here.
QRgb pixel = image.pixel(x, y);
- if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) +
- qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) +
- qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) {
+ if (qAbs(int(pixel & 0xff) - int(rgb & 0xff)) +
+ qAbs(int((pixel & 0xff00) >> 8) - int((rgb & 0xff00) >> 8)) +
+ qAbs(int((pixel & 0xff0000) >> 16) - int((rgb & 0xff0000) >> 16)) <= 50) {
if (++numRedPixel >= 10) {
return;
}
@@ -11297,6 +11371,7 @@ void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent()
scene.addItem(parent);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -11330,6 +11405,7 @@ void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate()
{
QGraphicsScene scene(0, 0, 200, 200);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
EventTester *parentGreen = new EventTester();
parentGreen->setGeometry(QRectF(20, 20, 100, 100));
@@ -11371,6 +11447,7 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2()
{
QGraphicsScene scene(0, 0, 200, 200);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
MyGraphicsView origView(&scene);
EventTester *parentGreen = new EventTester();
@@ -11421,26 +11498,26 @@ void tst_QGraphicsItem::QT_2649_focusScope()
QGraphicsRectItem *subFocusItem = new QGraphicsRectItem;
subFocusItem->setFlags(QGraphicsItem::ItemIsFocusable);
subFocusItem->setFocus();
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QGraphicsRectItem *scope = new QGraphicsRectItem;
scope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
scope->setFocus();
subFocusItem->setParentItem(scope);
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusItem(), subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
QGraphicsRectItem *rootItem = new QGraphicsRectItem;
rootItem->setFlags(QGraphicsItem::ItemIsFocusable);
scope->setParentItem(rootItem);
- QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(rootItem->focusItem(), subFocusItem);
QCOMPARE(rootItem->focusScopeItem(), nullptr);
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusItem(), subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
scene->addItem(rootItem);
@@ -11448,11 +11525,11 @@ void tst_QGraphicsItem::QT_2649_focusScope()
qApp->sendEvent(scene, &windowActivate);
scene->setFocus();
- QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(rootItem->focusItem(), subFocusItem);
+ QCOMPARE(scope->focusItem(), subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QCOMPARE(rootItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
QVERIFY(subFocusItem->hasFocus());
@@ -11462,17 +11539,17 @@ void tst_QGraphicsItem::QT_2649_focusScope()
QCOMPARE(scope->focusItem(), nullptr);
QCOMPARE(subFocusItem->focusItem(), nullptr);
QCOMPARE(rootItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
QVERIFY(!subFocusItem->hasFocus());
scope->show();
- QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(rootItem->focusItem(), subFocusItem);
+ QCOMPARE(scope->focusItem(), subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QCOMPARE(rootItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
QVERIFY(subFocusItem->hasFocus());
@@ -11484,16 +11561,14 @@ void tst_QGraphicsItem::QT_2649_focusScope()
class MyGraphicsItemWithItemChange : public QGraphicsWidget
{
public:
- MyGraphicsItemWithItemChange(QGraphicsItem *parent = 0) : QGraphicsWidget(parent)
- {}
+ using QGraphicsWidget::QGraphicsWidget;
- QVariant itemChange(GraphicsItemChange change, const QVariant &value)
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
{
if (change == QGraphicsItem::ItemSceneHasChanged) {
- foreach (QGraphicsView *view, scene()->views()) {
- //We trigger a sort of unindexed items in the BSP
+ const auto views = scene()->views();
+ for (QGraphicsView *view : views) // We trigger a sort of unindexed items in the BSP
view->sceneRect();
- }
}
return QGraphicsWidget::itemChange(change, value);
}
@@ -11518,8 +11593,8 @@ void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene()
{
struct Item : public QGraphicsTextItem
{
- int painted;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid)
+ int painted = 0;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) override
{
painted++;
QGraphicsTextItem::paint(painter, opt, wid);
@@ -11527,15 +11602,13 @@ void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene()
};
QGraphicsScene scene;
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
Item *item = new Item;
- item->painted = 0;
item->setPlainText("Grandparent");
Item *item2 = new Item;
item2->setPlainText("parent");
- item2->painted = 0;
Item *item3 = new Item;
item3->setPlainText("child");
- item3->painted = 0;
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect;
effect->setOpacity(0.5);
item2->setGraphicsEffect(effect);
@@ -11570,6 +11643,7 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100));
item->setFlag(QGraphicsItem::ItemIsMovable);
item->setAcceptDrops(true);
@@ -11578,13 +11652,13 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation()
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(QApplication::activeWindow(), (QWidget *)&view);
+ QCOMPARE(QApplication::activeWindow(), &view);
QGraphicsSceneDragDropEvent dragEnter(QEvent::GraphicsSceneDragEnter);
dragEnter.setScenePos(item->boundingRect().center());
- QApplication::sendEvent(&scene, &dragEnter);
+ QCoreApplication::sendEvent(&scene, &dragEnter);
QGraphicsSceneDragDropEvent event(QEvent::GraphicsSceneDragMove);
event.setScenePos(item->boundingRect().center());
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(QGraphicsScenePrivate::get(&scene)->dragDropItem, item);
delete item;
QVERIFY(!QGraphicsScenePrivate::get(&scene)->dragDropItem);
@@ -11594,6 +11668,7 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, 20, 20);
item1->setFlag(QGraphicsItem::ItemIsFocusable);
QGraphicsRectItem *item2 = new QGraphicsRectItem(20, 20, 20, 20);
@@ -11606,7 +11681,7 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem()
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(QApplication::activeWindow(), (QWidget *)&view);
+ QCOMPARE(QApplication::activeWindow(), &view);
QVERIFY(item1->focusItem());
QVERIFY(!item2->focusItem());
@@ -11642,11 +11717,11 @@ void tst_QGraphicsItem::QTBUG_13473_sceneposchange()
QCOMPARE(child->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 2);
}
-class MyGraphicsWidget : public QGraphicsWidget {
-Q_OBJECT
+class MyGraphicsWidget : public QGraphicsWidget
+{
+ Q_OBJECT
public:
- MyGraphicsWidget()
- : QGraphicsWidget(0)
+ MyGraphicsWidget() : QGraphicsWidget(nullptr)
{
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(Qt::Vertical);
QLatin1String wiseWords("AZ BUKI VEDI");
@@ -11658,21 +11733,19 @@ public:
proxy->setWidget(label);
proxy->setFocusPolicy(Qt::StrongFocus);
proxy->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true);
- if (i%2 == 0)
+ if (i % 2 == 0)
proxy->setVisible(false);
proxy->setFocus();
lay->addItem(proxy);
}
setLayout(lay);
}
-
};
class MyWidgetWindow : public QGraphicsWidget
{
public:
- MyWidgetWindow()
- : QGraphicsWidget(0, Qt::Window)
+ MyWidgetWindow() : QGraphicsWidget(nullptr, Qt::Window)
{
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(Qt::Vertical);
MyGraphicsWidget *widget = new MyGraphicsWidget();
@@ -11685,6 +11758,7 @@ void tst_QGraphicsItem::QTBUG_16374_crashInDestructor()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
MyWidgetWindow win;
scene.addItem(&win);
@@ -11697,6 +11771,7 @@ void tst_QGraphicsItem::QTBUG_20699_focusScopeCrash()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
QGraphicsPixmapItem fs;
fs.setFlags(QGraphicsItem::ItemIsFocusScope | QGraphicsItem::ItemIsFocusable);
scene.addItem(&fs);
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index 5ac3834aef..e21b1b889a 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -2610,11 +2610,6 @@ void tst_QGraphicsView::optimizationFlags()
QGraphicsView view;
QVERIFY(!view.optimizationFlags());
- view.setOptimizationFlag(QGraphicsView::DontClipPainter);
- QVERIFY(view.optimizationFlags() & QGraphicsView::DontClipPainter);
- view.setOptimizationFlag(QGraphicsView::DontClipPainter, false);
- QVERIFY(!view.optimizationFlags());
-
view.setOptimizationFlag(QGraphicsView::DontSavePainterState);
QVERIFY(view.optimizationFlags() & QGraphicsView::DontSavePainterState);
view.setOptimizationFlag(QGraphicsView::DontSavePainterState, false);
@@ -2625,10 +2620,8 @@ void tst_QGraphicsView::optimizationFlags()
view.setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing, false);
QVERIFY(!view.optimizationFlags());
- view.setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing
- | QGraphicsView::DontClipPainter);
- QCOMPARE(view.optimizationFlags(), QGraphicsView::OptimizationFlags(QGraphicsView::DontAdjustForAntialiasing
- | QGraphicsView::DontClipPainter));
+ view.setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing);
+ QCOMPARE(view.optimizationFlags(), QGraphicsView::OptimizationFlags(QGraphicsView::DontAdjustForAntialiasing));
}
class MessUpPainterItem : public QGraphicsRectItem
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index bcfc477733..3316c8ab93 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -26,39 +26,32 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
+#include <QAbstractItemView>
+#include <QDialog>
+#include <QHeaderView>
+#include <QIdentityProxyModel>
+#include <QItemDelegate>
+#include <QLineEdit>
+#include <QListWidget>
+#include <QProxyStyle>
+#include <QPushButton>
+#include <QScrollBar>
+#include <QSignalSpy>
+#include <QSortFilterProxyModel>
+#include <QSpinBox>
+#include <QStandardItemModel>
+#include <QStringListModel>
+#include <QStyledItemDelegate>
+#include <QTableWidget>
+#include <QTreeWidget>
+#include <QTest>
+#include <QVBoxLayout>
#include <QtTest/private/qtesthelpers_p.h>
-#include <qabstractitemview.h>
-#include <qstandarditemmodel.h>
-#include <qapplication.h>
-#include <qevent.h>
-#include <qlistview.h>
-#include <qlistwidget.h>
-#include <qtableview.h>
-#include <qtablewidget.h>
-#include <qtreeview.h>
-#include <qtreewidget.h>
-#include <qheaderview.h>
-#include <qspinbox.h>
-#include <qitemdelegate.h>
-#include <qpushbutton.h>
-#include <qscrollbar.h>
-#include <qboxlayout.h>
-#include <qitemdelegate.h>
-#include <qlineedit.h>
-#include <qscreen.h>
-#include <qscopedpointer.h>
-#include <qstyleditemdelegate.h>
-#include <qstringlistmodel.h>
-#include <qsortfilterproxymodel.h>
-#include <qproxystyle.h>
-#include <qdialog.h>
-
Q_DECLARE_METATYPE(Qt::ItemFlags);
using namespace QTestPrivate;
+using IntList = QVector<int>;
// Move cursor out of widget area to avoid undesired interaction on Mac.
static inline void moveCursorAway(const QWidget *topLevel)
@@ -74,8 +67,9 @@ class GeometriesTestView : public QTableView
{
Q_OBJECT
public:
- GeometriesTestView() : QTableView(), updateGeometriesCalled(false) {}
- bool updateGeometriesCalled;
+ using QTableView::QTableView;
+ using QTableView::selectedIndexes;
+ bool updateGeometriesCalled = false;
protected slots:
void updateGeometries() override { updateGeometriesCalled = true; QTableView::updateGeometries(); }
};
@@ -151,34 +145,48 @@ private slots:
void currentFollowsIndexWidget();
void checkFocusAfterActivationChanges_data();
void checkFocusAfterActivationChanges();
+private:
+ static QAbstractItemView *viewFromString(const QByteArray &viewType, QWidget *parent = nullptr)
+ {
+ if (viewType == "QListView")
+ return new QListView(parent);
+ if (viewType == "QTableView")
+ return new QTableView(parent);
+ if (viewType == "QTreeView")
+ return new QTreeView(parent);
+ if (viewType == "QHeaderView")
+ return new QHeaderView(Qt::Vertical, parent);
+ Q_ASSERT(false);
+ return nullptr;
+ }
};
class MyAbstractItemDelegate : public QAbstractItemDelegate
{
public:
- MyAbstractItemDelegate() : QAbstractItemDelegate() { calledVirtualDtor = false; }
- void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const {}
- QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const { return size; }
- QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
+ using QAbstractItemDelegate::QAbstractItemDelegate;
+ void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override {}
+ QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override { return size; }
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const override
{
openedEditor = new QWidget(parent);
return openedEditor;
}
- void destroyEditor(QWidget *editor, const QModelIndex &) const
+ void destroyEditor(QWidget *editor, const QModelIndex &) const override
{
calledVirtualDtor = true;
editor->deleteLater();
}
void changeSize() { size = QSize(50, 50); emit sizeHintChanged(QModelIndex()); }
- mutable bool calledVirtualDtor;
- mutable QWidget *openedEditor;
+ mutable QWidget *openedEditor = nullptr;
QSize size;
+ mutable bool calledVirtualDtor = false;
};
class DialogItemDelegate : public QStyledItemDelegate
{
public:
- DialogItemDelegate() : QStyledItemDelegate() { }
+ using QStyledItemDelegate::QStyledItemDelegate;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
{
openedEditor = new QDialog(parent);
@@ -194,8 +202,8 @@ public:
result = static_cast<QDialog::DialogCode>(dialog->result());
}
- mutable QDialog::DialogCode result;
- mutable QDialog *openedEditor;
+ mutable QDialog *openedEditor = nullptr;
+ mutable QDialog::DialogCode result = QDialog::Rejected;
};
// Testing get/set functions
@@ -207,27 +215,27 @@ void tst_QAbstractItemView::getSetCheck()
// void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *)
MyAbstractItemDelegate *var1 = new MyAbstractItemDelegate;
obj1->setItemDelegate(var1);
- QCOMPARE((QAbstractItemDelegate*)var1, obj1->itemDelegate());
- obj1->setItemDelegate((QAbstractItemDelegate *)0);
- QCOMPARE((QAbstractItemDelegate *)0, obj1->itemDelegate());
+ QCOMPARE(var1, obj1->itemDelegate());
+ obj1->setItemDelegate(nullptr);
+ QCOMPARE(obj1->itemDelegate(), nullptr);
delete var1;
- // EditTriggers QAbstractItemView::editTriggers()
+ // EditTriggers )
// void QAbstractItemView::setEditTriggers(EditTriggers)
- obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::NoEditTriggers));
- QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::NoEditTriggers), obj1->editTriggers());
- obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::CurrentChanged));
- QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::CurrentChanged), obj1->editTriggers());
- obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::DoubleClicked));
- QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::DoubleClicked), obj1->editTriggers());
- obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::SelectedClicked));
- QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::SelectedClicked), obj1->editTriggers());
- obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::EditKeyPressed));
- QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::EditKeyPressed), obj1->editTriggers());
- obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::AnyKeyPressed));
- QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::AnyKeyPressed), obj1->editTriggers());
- obj1->setEditTriggers(QAbstractItemView::EditTriggers(QAbstractItemView::AllEditTriggers));
- QCOMPARE(QAbstractItemView::EditTriggers(QAbstractItemView::AllEditTriggers), obj1->editTriggers());
+ obj1->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ QCOMPARE(obj1->editTriggers(), QAbstractItemView::NoEditTriggers);
+ obj1->setEditTriggers(QAbstractItemView::CurrentChanged);
+ QCOMPARE(obj1->editTriggers(), QAbstractItemView::CurrentChanged);
+ obj1->setEditTriggers(QAbstractItemView::DoubleClicked);
+ QCOMPARE(obj1->editTriggers(), QAbstractItemView::DoubleClicked);
+ obj1->setEditTriggers(QAbstractItemView::SelectedClicked);
+ QCOMPARE(obj1->editTriggers(), QAbstractItemView::SelectedClicked);
+ obj1->setEditTriggers(QAbstractItemView::EditKeyPressed);
+ QCOMPARE(obj1->editTriggers(), QAbstractItemView::EditKeyPressed);
+ obj1->setEditTriggers(QAbstractItemView::AnyKeyPressed);
+ QCOMPARE(obj1->editTriggers(), QAbstractItemView::AnyKeyPressed);
+ obj1->setEditTriggers(QAbstractItemView::AllEditTriggers);
+ QCOMPARE(obj1->editTriggers(), QAbstractItemView::AllEditTriggers);
// bool QAbstractItemView::tabKeyNavigation()
// void QAbstractItemView::setTabKeyNavigation(bool)
@@ -286,29 +294,18 @@ void tst_QAbstractItemView::cleanup()
void tst_QAbstractItemView::emptyModels_data()
{
- QTest::addColumn<QString>("viewType");
+ QTest::addColumn<QByteArray>("viewType");
- QTest::newRow("QListView") << "QListView";
- QTest::newRow("QTableView") << "QTableView";
- QTest::newRow("QTreeView") << "QTreeView";
- QTest::newRow("QHeaderView") << "QHeaderView";
+ const QVector<QByteArray> widgets{ "QListView", "QTreeView", "QTableView", "QHeaderView" };
+ for (const QByteArray &widget : widgets)
+ QTest::newRow(widget) << widget;
}
void tst_QAbstractItemView::emptyModels()
{
- QFETCH(QString, viewType);
-
- QScopedPointer<QAbstractItemView> view;
- if (viewType == "QListView")
- view.reset(new QListView());
- else if (viewType == "QTableView")
- view.reset(new QTableView());
- else if (viewType == "QTreeView")
- view.reset(new QTreeView());
- else if (viewType == "QHeaderView")
- view.reset(new QHeaderView(Qt::Vertical));
- else
- QVERIFY(0);
+ QFETCH(QByteArray, viewType);
+
+ QScopedPointer<QAbstractItemView> view(viewFromString(viewType));
centerOnScreen(view.data());
moveCursorAway(view.data());
view->show();
@@ -323,37 +320,21 @@ void tst_QAbstractItemView::emptyModels()
void tst_QAbstractItemView::setModel_data()
{
- QTest::addColumn<QString>("viewType");
-
- QTest::newRow("QListView") << "QListView";
- QTest::newRow("QTableView") << "QTableView";
- QTest::newRow("QTreeView") << "QTreeView";
- QTest::newRow("QHeaderView") << "QHeaderView";
+ emptyModels_data();
}
void tst_QAbstractItemView::setModel()
{
- QFETCH(QString, viewType);
-
- QScopedPointer<QAbstractItemView> view;
+ QFETCH(QByteArray, viewType);
- if (viewType == "QListView")
- view.reset(new QListView());
- else if (viewType == "QTableView")
- view.reset(new QTableView());
- else if (viewType == "QTreeView")
- view.reset(new QTreeView());
- else if (viewType == "QHeaderView")
- view.reset(new QHeaderView(Qt::Vertical));
- else
- QVERIFY(0);
+ QScopedPointer<QAbstractItemView> view(viewFromString(viewType));
centerOnScreen(view.data());
moveCursorAway(view.data());
view->show();
QVERIFY(QTest::qWaitForWindowExposed(view.data()));
QStandardItemModel model(20,20);
- view->setModel(0);
+ view->setModel(nullptr);
view->setModel(&model);
basic_tests(view.data());
}
@@ -463,11 +444,11 @@ void tst_QAbstractItemView::basic_tests(QAbstractItemView *view)
QCOMPARE(view->sizeHintForIndex(QModelIndex()), QSize());
QCOMPARE(view->indexAt(QPoint(-1, -1)), QModelIndex());
- if (!view->model()){
+ if (!view->model()) {
QCOMPARE(view->indexAt(QPoint(10, 10)), QModelIndex());
QCOMPARE(view->sizeHintForRow(0), -1);
QCOMPARE(view->sizeHintForColumn(0), -1);
- }else if (view->itemDelegate()){
+ } else if (view->itemDelegate()) {
view->sizeHintForRow(0);
view->sizeHintForColumn(0);
}
@@ -487,7 +468,7 @@ void tst_QAbstractItemView::basic_tests(QAbstractItemView *view)
view->rowsInserted(QModelIndex(), -1, -1);
view->rowsAboutToBeRemoved(QModelIndex(), -1, -1);
view->selectionChanged(QItemSelection(), QItemSelection());
- if (view->model()){
+ if (view->model()) {
view->currentChanged(QModelIndex(), QModelIndex());
view->currentChanged(QModelIndex(), view->model()->index(0,0));
}
@@ -498,9 +479,9 @@ void tst_QAbstractItemView::basic_tests(QAbstractItemView *view)
view->horizontalScrollbarAction(QAbstractSlider::SliderSingleStepAdd);
view->verticalScrollbarValueChanged(10);
view->horizontalScrollbarValueChanged(10);
- view->closeEditor(0, QAbstractItemDelegate::NoHint);
- view->commitData(0);
- view->editorDestroyed(0);
+ view->closeEditor(nullptr, QAbstractItemDelegate::NoHint);
+ view->commitData(nullptr);
+ view->editorDestroyed(nullptr);
// Will assert as it should
// view->setIndexWidget(QModelIndex(), 0);
@@ -510,7 +491,7 @@ void tst_QAbstractItemView::basic_tests(QAbstractItemView *view)
view->verticalOffset();
// view->isIndexHidden(QModelIndex()); // will (correctly) assert
- if(view->model())
+ if (view->model())
view->isIndexHidden(view->model()->index(0,0));
view->setSelection(QRect(0, 0, 10, 10), QItemSelectionModel::ClearAndSelect);
@@ -518,9 +499,9 @@ void tst_QAbstractItemView::basic_tests(QAbstractItemView *view)
view->visualRegionForSelection(QItemSelection());
view->selectedIndexes();
- view->edit(QModelIndex(), QAbstractItemView::NoEditTriggers, 0);
+ view->edit(QModelIndex(), QAbstractItemView::NoEditTriggers, nullptr);
- view->selectionCommand(QModelIndex(), 0);
+ view->selectionCommand(QModelIndex(), nullptr);
#if QT_CONFIG(draganddrop)
if (!view->model())
@@ -529,17 +510,17 @@ void tst_QAbstractItemView::basic_tests(QAbstractItemView *view)
view->viewOptions();
view->setState(QAbstractItemView::NoState);
- QVERIFY(view->state()==QAbstractItemView::NoState);
+ QCOMPARE(view->state(), QAbstractItemView::NoState);
view->setState(QAbstractItemView::DraggingState);
- QVERIFY(view->state()==QAbstractItemView::DraggingState);
+ QCOMPARE(view->state(), QAbstractItemView::DraggingState);
view->setState(QAbstractItemView::DragSelectingState);
- QVERIFY(view->state()==QAbstractItemView::DragSelectingState);
+ QCOMPARE(view->state(), QAbstractItemView::DragSelectingState);
view->setState(QAbstractItemView::EditingState);
- QVERIFY(view->state()==QAbstractItemView::EditingState);
+ QCOMPARE(view->state(), QAbstractItemView::EditingState);
view->setState(QAbstractItemView::ExpandingState);
- QVERIFY(view->state()==QAbstractItemView::ExpandingState);
+ QCOMPARE(view->state(), QAbstractItemView::ExpandingState);
view->setState(QAbstractItemView::CollapsingState);
- QVERIFY(view->state()==QAbstractItemView::CollapsingState);
+ QCOMPARE(view->state(), QAbstractItemView::CollapsingState);
#endif
view->startAutoScroll();
@@ -575,7 +556,7 @@ void tst_QAbstractItemView::noModel()
view.scrollTo(view.model()->index(10,10));
QApplication::processEvents();
- view.setModel(0);
+ view.setModel(nullptr);
// Due to the model is removed, this will generate a valueChanged signal on both scrollbars. (value to 0)
QApplication::processEvents();
QCOMPARE(view.model(), nullptr);
@@ -585,7 +566,7 @@ void tst_QAbstractItemView::dragSelect()
{
// From task #86108
- QStandardItemModel model(64,64);
+ QStandardItemModel model(64, 64);
QTableView view;
view.setModel(&model);
@@ -607,7 +588,7 @@ void tst_QAbstractItemView::dragSelect()
void tst_QAbstractItemView::rowDelegate()
{
- QStandardItemModel model(4,4);
+ QStandardItemModel model(4, 4);
MyAbstractItemDelegate delegate;
QTableView view;
@@ -629,7 +610,7 @@ void tst_QAbstractItemView::rowDelegate()
void tst_QAbstractItemView::columnDelegate()
{
- QStandardItemModel model(4,4);
+ QStandardItemModel model(4, 4);
MyAbstractItemDelegate delegate;
QTableView view;
@@ -665,42 +646,35 @@ void tst_QAbstractItemView::sizeHintChangeTriggersLayout()
QVERIFY(QTest::qWaitForWindowExposed(&view));
view.updateGeometriesCalled = false;
delegate.changeSize();
- QCoreApplication::sendPostedEvents();
- QVERIFY(view.updateGeometriesCalled);
+ QTRY_VERIFY(view.updateGeometriesCalled);
view.updateGeometriesCalled = false;
rowDelegate.changeSize();
- QCoreApplication::sendPostedEvents();
- QVERIFY(view.updateGeometriesCalled);
+ QTRY_VERIFY(view.updateGeometriesCalled);
view.updateGeometriesCalled = false;
columnDelegate.changeSize();
- QCoreApplication::sendPostedEvents();
- QVERIFY(view.updateGeometriesCalled);
+ QTRY_VERIFY(view.updateGeometriesCalled);
}
void tst_QAbstractItemView::selectAll()
{
- QStandardItemModel model(4,4);
- QTableView view;
+ QStandardItemModel model(4, 4);
+ GeometriesTestView view;
view.setModel(&model);
- QAbstractItemView *tst_view = &view;
-
- QCOMPARE(tst_view->selectedIndexes().count(), 0);
+ QCOMPARE(view.selectedIndexes().count(), 0);
view.selectAll();
- QCOMPARE(tst_view->selectedIndexes().count(), 4*4);
+ QCOMPARE(view.selectedIndexes().count(), 4 * 4);
}
void tst_QAbstractItemView::ctrlA()
{
- QStandardItemModel model(4,4);
- QTableView view;
+ QStandardItemModel model(4, 4);
+ GeometriesTestView view;
view.setModel(&model);
- QAbstractItemView *tst_view = &view;
-
- QCOMPARE(tst_view->selectedIndexes().count(), 0);
+ QCOMPARE(view.selectedIndexes().count(), 0);
QTest::keyClick(&view, Qt::Key_A, Qt::ControlModifier);
- QCOMPARE(tst_view->selectedIndexes().count(), 4*4);
+ QCOMPARE(view.selectedIndexes().count(), 4 * 4);
}
void tst_QAbstractItemView::persistentEditorFocus()
@@ -716,7 +690,7 @@ void tst_QAbstractItemView::persistentEditorFocus()
view.openPersistentEditor(model.index(0, 2));
//these are spinboxes because we put numbers inside
- QList<QSpinBox*> list = view.viewport()->findChildren<QSpinBox*>();
+ const QList<QSpinBox*> list = view.viewport()->findChildren<QSpinBox*>();
QCOMPARE(list.count(), 2); //these should be the 2 editors
view.setCurrentIndex(model.index(0, 0));
@@ -726,15 +700,15 @@ void tst_QAbstractItemView::persistentEditorFocus()
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- for (int i = 0; i < list.count(); ++i) {
- QTRY_VERIFY(list.at(i)->isVisible());
- QPoint p = QPoint(5, 5);
+ const QPoint p(5, 5);
+ for (QSpinBox *sb : list) {
+ QTRY_VERIFY(sb->isVisible());
QMouseEvent mouseEvent(QEvent::MouseButtonPress, p, Qt::LeftButton,
Qt::LeftButton, Qt::NoModifier);
- qApp->sendEvent(list.at(i), &mouseEvent);
- if (!qApp->focusWidget())
+ QCoreApplication::sendEvent(sb, &mouseEvent);
+ if (!QApplication::focusWidget())
QSKIP("Some window managers don't handle focus that well");
- QTRY_COMPARE(qApp->focusWidget(), static_cast<QWidget *>(list.at(i)));
+ QTRY_COMPARE(QApplication::focusWidget(), sb);
}
}
@@ -960,65 +934,63 @@ void tst_QAbstractItemView::dragAndDropOnChild()
class TestModel : public QStandardItemModel
{
+ Q_OBJECT
public:
- TestModel(int rows, int columns) : QStandardItemModel(rows, columns)
- {
- setData_count = 0;
- }
-
- virtual bool setData(const QModelIndex &/*index*/, const QVariant &/*value*/, int /*role = Qt::EditRole*/)
+ using QStandardItemModel::QStandardItemModel;
+ bool setData(const QModelIndex &, const QVariant &, int) override
{
++setData_count;
return true;
}
+ void emitDataChanged()
+ {
+ emit dataChanged(index(0, 0), index(0, 1));
+ }
- int setData_count;
+ int setData_count = 0;
};
-typedef QList<int> IntList;
-
void tst_QAbstractItemView::setItemDelegate_data()
{
// default is rows, a -1 will switch to columns
QTest::addColumn<IntList>("rowsOrColumnsWithDelegate");
QTest::addColumn<QPoint>("cellToEdit");
QTest::newRow("4 columndelegates")
- << (IntList() << -1 << 0 << 1 << 2 << 3)
+ << (IntList{ -1, 0, 1, 2, 3 })
<< QPoint(0, 0);
QTest::newRow("2 identical rowdelegates on the same row")
- << (IntList() << 0 << 0)
+ << (IntList{ 0, 0 })
<< QPoint(0, 0);
QTest::newRow("2 identical columndelegates on the same column")
- << (IntList() << -1 << 2 << 2)
+ << (IntList{ -1, 2, 2 })
<< QPoint(2, 0);
QTest::newRow("2 duplicate delegates, 1 row and 1 column")
- << (IntList() << 0 << -1 << 2)
+ << (IntList{ 0, -1, 2 })
<< QPoint(2, 0);
QTest::newRow("4 duplicate delegates, 2 row and 2 column")
- << (IntList() << 0 << 0 << -1 << 2 << 2)
+ << (IntList{ 0, 0, -1, 2, 2 })
<< QPoint(2, 0);
}
void tst_QAbstractItemView::setItemDelegate()
{
- QFETCH(IntList, rowsOrColumnsWithDelegate);
+ QFETCH(const IntList, rowsOrColumnsWithDelegate);
QFETCH(QPoint, cellToEdit);
QTableView v;
- QItemDelegate *delegate = new QItemDelegate(&v);
+ QStyledItemDelegate *delegate = new QStyledItemDelegate(&v);
TestModel model(5, 5);
v.setModel(&model);
bool row = true;
- foreach (int rc, rowsOrColumnsWithDelegate) {
+ for (int rc : rowsOrColumnsWithDelegate) {
if (rc == -1) {
row = !row;
} else {
- if (row) {
+ if (row)
v.setItemDelegateForRow(rc, delegate);
- } else {
+ else
v.setItemDelegateForColumn(rc, delegate);
- }
}
}
centerOnScreen(&v);
@@ -1070,45 +1042,32 @@ void tst_QAbstractItemView::noFallbackToRoot()
void tst_QAbstractItemView::setCurrentIndex_data()
{
- QTest::addColumn<QString>("viewType");
- QTest::addColumn<int>("itemFlags");
+ QTest::addColumn<QByteArray>("viewType");
+ QTest::addColumn<Qt::ItemFlags>("itemFlags");
QTest::addColumn<bool>("result");
- QStringList widgets;
- widgets << "QListView" << "QTreeView" << "QHeaderView" << "QTableView";
-
- foreach(QString widget, widgets) {
- QTest::newRow((widget+QLatin1String(": no flags")).toLocal8Bit().constData())
- << widget << (int)0 << false;
- QTest::newRow((widget+QLatin1String(": checkable")).toLocal8Bit().constData())
- << widget << (int)Qt::ItemIsUserCheckable << false;
- QTest::newRow((widget+QLatin1String(": selectable")).toLocal8Bit().constData())
- << widget << (int)Qt::ItemIsSelectable << false;
- QTest::newRow((widget+QLatin1String(": enabled")).toLocal8Bit().constData())
- << widget << (int)Qt::ItemIsEnabled << true;
- QTest::newRow((widget+QLatin1String(": enabled|selectable")).toLocal8Bit().constData())
- << widget << (int)(Qt::ItemIsSelectable|Qt::ItemIsEnabled) << true;
+ const QVector<QByteArray> widgets{ "QListView", "QTreeView", "QTableView", "QHeaderView" };
+ for (const QByteArray &widget : widgets) {
+ QTest::newRow(widget + ": no flags")
+ << widget << Qt::ItemFlags(Qt::NoItemFlags) << false;
+ QTest::newRow(widget + ": checkable")
+ << widget << Qt::ItemFlags(Qt::ItemIsUserCheckable) << false;
+ QTest::newRow(widget + ": selectable")
+ << widget << Qt::ItemFlags(Qt::ItemIsSelectable) << false;
+ QTest::newRow(widget + ": enabled")
+ << widget << Qt::ItemFlags(Qt::ItemIsEnabled) << true;
+ QTest::newRow(widget + ": enabled|selectable")
+ << widget << (Qt::ItemIsSelectable|Qt::ItemIsEnabled) << true;
}
}
void tst_QAbstractItemView::setCurrentIndex()
{
- QFETCH(QString, viewType);
- QFETCH(int, itemFlags);
+ QFETCH(QByteArray, viewType);
+ QFETCH(Qt::ItemFlags, itemFlags);
QFETCH(bool, result);
- QScopedPointer<QAbstractItemView> view;
-
- if (viewType == "QListView")
- view.reset(new QListView());
- else if (viewType == "QTableView")
- view.reset(new QTableView());
- else if (viewType == "QTreeView")
- view.reset(new QTreeView());
- else if (viewType == "QHeaderView")
- view.reset(new QHeaderView(Qt::Vertical));
- else
- QVERIFY(0);
+ QScopedPointer<QAbstractItemView> view(viewFromString(viewType));
centerOnScreen(view.data());
moveCursorAway(view.data());
@@ -1121,31 +1080,30 @@ void tst_QAbstractItemView::setCurrentIndex()
model->appendRow(item);
item = new QStandardItem("test item");
- item->setFlags(Qt::ItemFlags(itemFlags));
+ item->setFlags(itemFlags);
model->appendRow(item);
view->setModel(model);
- view->setCurrentIndex(model->index(0,0));
- QCOMPARE(view->currentIndex(), model->index(0,0));
- view->setCurrentIndex(model->index(1,0));
- QVERIFY(view->currentIndex() == model->index(result ? 1 : 0,0));
+ view->setCurrentIndex(model->index(0, 0));
+ QCOMPARE(view->currentIndex(), model->index(0, 0));
+ view->setCurrentIndex(model->index(1, 0));
+ QVERIFY(view->currentIndex() == model->index(result ? 1 : 0, 0));
}
void tst_QAbstractItemView::task221955_selectedEditor()
{
- QPushButton *button;
-
QTreeWidget tree;
tree.setColumnCount(2);
- tree.addTopLevelItem(new QTreeWidgetItem(QStringList() << "Foo" <<"1"));
- tree.addTopLevelItem(new QTreeWidgetItem(QStringList() << "Bar" <<"2"));
- tree.addTopLevelItem(new QTreeWidgetItem(QStringList() << "Baz" <<"3"));
+ tree.addTopLevelItem(new QTreeWidgetItem({"Foo", "1"}));
+ tree.addTopLevelItem(new QTreeWidgetItem({"Bar", "2"}));
+ tree.addTopLevelItem(new QTreeWidgetItem({"Baz", "3"}));
QTreeWidgetItem *dummy = new QTreeWidgetItem();
tree.addTopLevelItem(dummy);
- tree.setItemWidget(dummy, 0, button = new QPushButton("More..."));
+ QPushButton *button = new QPushButton("More...");
+ tree.setItemWidget(dummy, 0, button);
button->setAutoFillBackground(true); // as recommended in doc
centerOnScreen(&tree);
@@ -1185,10 +1143,10 @@ void tst_QAbstractItemView::task250754_fontChange()
QVBoxLayout *vLayout = new QVBoxLayout(&w);
vLayout->addWidget(&tree);
- QStandardItemModel *m = new QStandardItemModel(this);
- for (int i=0; i<20; ++i) {
+ QStandardItemModel *m = new QStandardItemModel(&w);
+ for (int i = 0; i < 20; ++i) {
QStandardItem *item = new QStandardItem(QStringLiteral("Item number ") + QString::number(i));
- for (int j=0; j<5; ++j) {
+ for (int j = 0; j < 5; ++j) {
QStandardItem *child = new QStandardItem(QStringLiteral("Child Item number ") + QString::number(j));
item->setChild(j, 0, child);
}
@@ -1222,7 +1180,7 @@ void tst_QAbstractItemView::task200665_itemEntered()
{
//we test that view will emit entered
//when the scrollbar move but not the mouse itself
- QStandardItemModel model(1000,1);
+ QStandardItemModel model(1000, 1);
QListView view;
view.setModel(&model);
centerOnScreen(&view);
@@ -1231,7 +1189,7 @@ void tst_QAbstractItemView::task200665_itemEntered()
QVERIFY(QTest::qWaitForWindowExposed(&view));
QCursor::setPos(view.geometry().center());
QTRY_COMPARE(QCursor::pos(), view.geometry().center());
- QSignalSpy spy(&view, SIGNAL(entered(QModelIndex)));
+ QSignalSpy spy(&view, &QAbstractItemView::entered);
view.verticalScrollBar()->setValue(view.verticalScrollBar()->maximum());
QTRY_COMPARE(spy.count(), 1);
@@ -1239,13 +1197,13 @@ void tst_QAbstractItemView::task200665_itemEntered()
void tst_QAbstractItemView::task257481_emptyEditor()
{
- QIcon icon = qApp->style()->standardIcon(QStyle::SP_ComputerIcon);
+ QIcon icon = QApplication::style()->standardIcon(QStyle::SP_ComputerIcon);
QStandardItemModel model;
- model.appendRow( new QStandardItem(icon, QString()) );
- model.appendRow( new QStandardItem(icon, "Editor works") );
- model.appendRow( new QStandardItem( QString() ) );
+ model.appendRow(new QStandardItem(icon, QString()));
+ model.appendRow(new QStandardItem(icon, "Editor works"));
+ model.appendRow(new QStandardItem(QString()));
QTreeView treeView;
treeView.setRootIsDecorated(false);
@@ -1255,29 +1213,27 @@ void tst_QAbstractItemView::task257481_emptyEditor()
treeView.show();
QVERIFY(QTest::qWaitForWindowExposed(&treeView));
- treeView.edit(model.index(0,0));
+ treeView.edit(model.index(0, 0));
QList<QLineEdit *> lineEditors = treeView.viewport()->findChildren<QLineEdit *>();
QCOMPARE(lineEditors.count(), 1);
- QVERIFY(!lineEditors.first()->size().isEmpty());
+ QVERIFY(!lineEditors.constFirst()->size().isEmpty());
- treeView.edit(model.index(1,0));
+ treeView.edit(model.index(1, 0));
lineEditors = treeView.viewport()->findChildren<QLineEdit *>();
QCOMPARE(lineEditors.count(), 1);
- QVERIFY(!lineEditors.first()->size().isEmpty());
+ QVERIFY(!lineEditors.constFirst()->size().isEmpty());
- treeView.edit(model.index(2,0));
+ treeView.edit(model.index(2, 0));
lineEditors = treeView.viewport()->findChildren<QLineEdit *>();
QCOMPARE(lineEditors.count(), 1);
- QVERIFY(!lineEditors.first()->size().isEmpty());
+ QVERIFY(!lineEditors.constFirst()->size().isEmpty());
}
void tst_QAbstractItemView::shiftArrowSelectionAfterScrolling()
{
QStandardItemModel model;
- for (int i=0; i<10; ++i) {
- QStandardItem *item = new QStandardItem(QString::number(i));
- model.setItem(i, 0, item);
- }
+ for (int i = 0; i < 10; ++i)
+ model.setItem(i, 0, new QStandardItem(QString::number(i)));
QListView view;
view.setFixedSize(160, 250); // Minimum width for windows with frame on Windows 8
@@ -1311,10 +1267,8 @@ void tst_QAbstractItemView::shiftArrowSelectionAfterScrolling()
void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection()
{
QStandardItemModel model;
- for (int i=0; i<3; ++i) {
- QStandardItem *item = new QStandardItem(QString::number(i));
- model.setItem(i, 0, item);
- }
+ for (int i = 0; i < 3; ++i)
+ model.setItem(i, 0, new QStandardItem(QString::number(i)));
QListView view;
view.setFixedSize(160, 450); // Minimum width for windows with frame on Windows 8
@@ -1388,10 +1342,8 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection()
void tst_QAbstractItemView::ctrlRubberbandSelection()
{
QStandardItemModel model;
- for (int i=0; i<3; ++i) {
- QStandardItem *item = new QStandardItem(QString::number(i));
- model.setItem(i, 0, item);
- }
+ for (int i = 0; i < 3; ++i)
+ model.setItem(i, 0, new QStandardItem(QString::number(i)));
QListView view;
view.setFixedSize(160, 450); // Minimum width for windows with frame on Windows 8
@@ -1435,7 +1387,7 @@ void tst_QAbstractItemView::QTBUG6407_extendedSelection()
{
QListWidget view;
view.setSelectionMode(QAbstractItemView::ExtendedSelection);
- for(int i = 0; i < 50; ++i)
+ for (int i = 0; i < 50; ++i)
view.addItem(QString::number(i));
QFont font = view.font();
@@ -1448,14 +1400,14 @@ void tst_QAbstractItemView::QTBUG6407_extendedSelection()
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow());
+ QCOMPARE(&view, QApplication::activeWindow());
view.verticalScrollBar()->setValue(view.verticalScrollBar()->maximum());
QModelIndex index49 = view.model()->index(49,0);
QPoint p = view.visualRect(index49).center();
QVERIFY(view.viewport()->rect().contains(p));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, p);
QCOMPARE(view.currentIndex(), index49);
QCOMPARE(view.selectedItems().count(), 1);
@@ -1478,9 +1430,10 @@ void tst_QAbstractItemView::QTBUG6407_extendedSelection()
void tst_QAbstractItemView::QTBUG6753_selectOnSelection()
{
QTableWidget table(5, 5);
- for (int i = 0; i < table.rowCount(); ++i)
+ for (int i = 0; i < table.rowCount(); ++i) {
for (int j = 0; j < table.columnCount(); ++j)
table.setItem(i, j, new QTableWidgetItem("choo-be-doo-wah"));
+ }
centerOnScreen(&table);
moveCursorAway(&table);
@@ -1520,69 +1473,47 @@ void tst_QAbstractItemView::testClickedSignal()
view.showNormal();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow());
+ QCOMPARE(&view, QApplication::activeWindow());
QModelIndex index49 = view.model()->index(49,0);
QPoint p = view.visualRect(index49).center();
QVERIFY(view.viewport()->rect().contains(p));
- QSignalSpy clickedSpy(&view, SIGNAL(clicked(QModelIndex)));
+ QSignalSpy clickedSpy(&view, &QTableWidget::clicked);
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, p);
#ifdef Q_OS_WINRT
QEXPECT_FAIL("", "Fails on WinRT - QTBUG-68297", Abort);
#endif
QCOMPARE(clickedSpy.count(), 1);
- QTest::mouseClick(view.viewport(), Qt::RightButton, 0, p);
+ QTest::mouseClick(view.viewport(), Qt::RightButton, {}, p);
// We expect that right-clicks do not cause the clicked() signal to
// be emitted.
QCOMPARE(clickedSpy.count(), 1);
}
-class StateChangeDelegate : public QItemDelegate {
- Q_OBJECT
-
-public:
- explicit StateChangeDelegate(QObject* parent = 0) :
- QItemDelegate(parent)
- {}
-
- void setEditorData(QWidget *editor, const QModelIndex &index) const override {
- Q_UNUSED(index);
- static bool w = true;
- editor->setEnabled(w);
- w = !w;
- }
-};
-
-class StateChangeModel : public QStandardItemModel {
- Q_OBJECT
-
+class StateChangeDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
public:
- explicit StateChangeModel(QObject *parent = 0) :
- QStandardItemModel(parent)
- {}
-
- void emitDataChanged() {
- emit dataChanged(index(0, 0), index(0, 1));
- }
+ using QStyledItemDelegate::QStyledItemDelegate;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const override
+ {
+ Q_UNUSED(index);
+ static bool w = true;
+ editor->setEnabled(w);
+ w = !w;
+ }
};
-
void tst_QAbstractItemView::testChangeEditorState()
{
// Test for QTBUG-25370
- StateChangeModel model;
- {
- QStandardItem* item = new QStandardItem("a");
- model.setItem(0, 0, item);
- }
- {
- QStandardItem* item = new QStandardItem("b");
- model.setItem(0, 1, item);
- }
+ TestModel model;
+ model.setItem(0, 0, new QStandardItem("a"));
+ model.setItem(0, 1, new QStandardItem("b"));
QTableView view;
view.setEditTriggers(QAbstractItemView::CurrentChanged);
@@ -1593,7 +1524,7 @@ void tst_QAbstractItemView::testChangeEditorState()
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow());
+ QCOMPARE(&view, QApplication::activeWindow());
model.emitDataChanged();
// No segfault - the test passes.
@@ -1659,12 +1590,12 @@ void tst_QAbstractItemView::testNoActivateOnDisabledItem()
QApplication::setActiveWindow(&treeView);
QVERIFY(QTest::qWaitForWindowActive(&treeView));
- QSignalSpy activatedSpy(&treeView, SIGNAL(activated(QModelIndex)));
+ QSignalSpy activatedSpy(&treeView, &QAbstractItemView::activated);
// Ensure clicking on a disabled item doesn't emit itemActivated.
QModelIndex itemIndex = treeView.model()->index(0, 0);
QPoint clickPos = treeView.visualRect(itemIndex).center();
- QTest::mouseClick(treeView.viewport(), Qt::LeftButton, 0, clickPos);
+ QTest::mouseClick(treeView.viewport(), Qt::LeftButton, {}, clickPos);
QCOMPARE(activatedSpy.count(), 0);
}
@@ -1706,18 +1637,18 @@ void tst_QAbstractItemView::testFocusPolicy()
// itemview accepts focus => editor is closed => return focus to the itemview
QPoint clickpos = table->visualRect(model.index(1, 1)).center();
QTest::mouseDClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos);
- QWidget *editor = qApp->focusWidget();
+ QWidget *editor = QApplication::focusWidget();
QVERIFY(editor);
QTest::keyClick(editor, Qt::Key_Escape, Qt::NoModifier);
- QCOMPARE(qApp->focusWidget(), table);
+ QCOMPARE(QApplication::focusWidget(), table);
// itemview doesn't accept focus => editor is closed => clear the focus
table->setFocusPolicy(Qt::NoFocus);
QTest::mouseDClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos);
- editor = qApp->focusWidget();
+ editor = QApplication::focusWidget();
QVERIFY(editor);
QTest::keyClick(editor, Qt::Key_Escape, Qt::NoModifier);
- QVERIFY(!qApp->focusWidget());
+ QVERIFY(!QApplication::focusWidget());
}
void tst_QAbstractItemView::QTBUG31411_noSelection()
@@ -1742,18 +1673,18 @@ void tst_QAbstractItemView::QTBUG31411_noSelection()
QVERIFY(QTest::qWaitForWindowActive(&window));
qRegisterMetaType<QItemSelection>();
- QSignalSpy selectionChangeSpy(table->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)));
+ QSignalSpy selectionChangeSpy(table->selectionModel(), &QItemSelectionModel::selectionChanged);
QVERIFY(selectionChangeSpy.isValid());
QPoint clickpos = table->visualRect(model.index(1, 1)).center();
QTest::mouseClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos);
QTest::mouseDClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos);
- QPointer<QWidget> editor1 = qApp->focusWidget();
+ QPointer<QWidget> editor1 = QApplication::focusWidget();
QVERIFY(editor1);
QTest::keyClick(editor1, Qt::Key_Tab, Qt::NoModifier);
- QPointer<QWidget> editor2 = qApp->focusWidget();
+ QPointer<QWidget> editor2 = QApplication::focusWidget();
QVERIFY(editor2);
QTest::keyClick(editor2, Qt::Key_Escape, Qt::NoModifier);
@@ -1762,26 +1693,22 @@ void tst_QAbstractItemView::QTBUG31411_noSelection()
void tst_QAbstractItemView::QTBUG39324_settingSameInstanceOfIndexWidget()
{
- QStringList list;
- list << "FOO" << "bar";
- QScopedPointer<QStringListModel> model(new QStringListModel(list));
+ QStringListModel model({ "FOO", "bar" });
QScopedPointer<QTableView> table(new QTableView());
- table->setModel(model.data());
+ table->setModel(&model);
- QModelIndex index = model->index(0,0);
+ QModelIndex index = model.index(0,0);
QLineEdit *lineEdit = new QLineEdit();
table->setIndexWidget(index, lineEdit);
table->setIndexWidget(index, lineEdit);
- QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
table->show();
}
void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
{
- QStringList list;
- list << "A" << "B" << "C" << "D" << "E" << "F";
- QStringListModel model(list);
+ QStringListModel model({ "A", "B", "C", "D", "E", "F" });
QSortFilterProxyModel proxyModel;
proxyModel.setSourceModel(&model);
proxyModel.sort(0, Qt::AscendingOrder);
@@ -1838,9 +1765,8 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
QVERIFY(selected.contains(indexF));
// Move to "A" by pressing "Up" repeatedly
- while (view.currentIndex() != indexA) {
+ while (view.currentIndex() != indexA)
QTest::keyClick(&view, Qt::Key_Up);
- }
selected = view.selectionModel()->selectedIndexes();
QCOMPARE(selected.count(), 1);
QVERIFY(selected.contains(indexA));
@@ -1895,22 +1821,22 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
void tst_QAbstractItemView::QTBUG48968_reentrant_updateEditorGeometries()
{
-
- QStandardItemModel *m = new QStandardItemModel(this);
- for (int i=0; i<10; ++i) {
+ QTreeView tree;
+ QStandardItemModel *m = new QStandardItemModel(&tree);
+ for (int i = 0; i < 10; ++i) {
QStandardItem *item = new QStandardItem(QString("Item number %1").arg(i));
item->setEditable(true);
- for (int j=0; j<5; ++j) {
+ for (int j = 0; j < 5; ++j) {
QStandardItem *child = new QStandardItem(QString("Child Item number %1").arg(j));
item->setChild(j, 0, child);
}
m->setItem(i, 0, item);
}
- QTreeView tree;
tree.setModel(m);
tree.setRootIsDecorated(false);
- QObject::connect(&tree, SIGNAL(doubleClicked(QModelIndex)), &tree, SLOT(setRootIndex(QModelIndex)));
+ connect(&tree, &QTreeView::doubleClicked,
+ &tree, &QTreeView::setRootIndex);
tree.show();
QVERIFY(QTest::qWaitForWindowActive(&tree));
@@ -1922,7 +1848,7 @@ void tst_QAbstractItemView::QTBUG48968_reentrant_updateEditorGeometries()
// Add more children to idx
QStandardItem *item = m->itemFromIndex(idx);
- for (int j=5; j<10; ++j) {
+ for (int j = 5; j < 10; ++j) {
QStandardItem *child = new QStandardItem(QString("Child Item number %1").arg(j));
item->setChild(j, 0, child);
}
@@ -1932,14 +1858,16 @@ void tst_QAbstractItemView::QTBUG48968_reentrant_updateEditorGeometries()
class ScrollModeProxyStyle: public QProxyStyle
{
+ Q_OBJECT
public:
- ScrollModeProxyStyle(QAbstractItemView::ScrollMode sm, QStyle *style = 0)
+ ScrollModeProxyStyle(QAbstractItemView::ScrollMode sm, QStyle *style = nullptr)
: QProxyStyle(style)
, scrollMode(sm == QAbstractItemView::ScrollPerItem ?
QAbstractItemView::ScrollPerPixel : QAbstractItemView::ScrollPerItem)
{ }
- int styleHint(QStyle::StyleHint hint, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *returnData) const override
+ int styleHint(QStyle::StyleHint hint, const QStyleOption *opt,
+ const QWidget *w, QStyleHintReturn *returnData) const override
{
if (hint == SH_ItemView_ScrollMode)
return scrollMode;
@@ -1955,14 +1883,16 @@ void tst_QAbstractItemView::QTBUG50102_SH_ItemView_ScrollMode()
QListView view;
// Default comes from the style
- auto styleScrollMode = static_cast<QAbstractItemView::ScrollMode>(view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, &view, 0));
+ auto styleScrollMode = static_cast<QAbstractItemView::ScrollMode>(
+ view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, nullptr, &view, nullptr));
QCOMPARE(view.verticalScrollMode(), styleScrollMode);
QCOMPARE(view.horizontalScrollMode(), styleScrollMode);
// Change style, get new value
ScrollModeProxyStyle proxyStyle1(styleScrollMode);
view.setStyle(&proxyStyle1);
- auto proxyScrollMode = static_cast<QAbstractItemView::ScrollMode>(view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, &view, 0));
+ auto proxyScrollMode = static_cast<QAbstractItemView::ScrollMode>(
+ view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, nullptr, &view, nullptr));
QVERIFY(styleScrollMode != proxyScrollMode);
QCOMPARE(view.verticalScrollMode(), proxyScrollMode);
QCOMPARE(view.horizontalScrollMode(), proxyScrollMode);
@@ -1988,10 +1918,7 @@ void tst_QAbstractItemView::QTBUG50535_update_on_new_selection_model()
class ListView : public QListView
{
public:
- ListView()
- : m_paintEventsCount(0), m_deselectedMustBeEmpty(false), m_selectionChangedOk(true)
- {
- }
+ using QListView::QListView;
void setSelectionModel(QItemSelectionModel *model) override
{
@@ -1999,7 +1926,7 @@ void tst_QAbstractItemView::QTBUG50535_update_on_new_selection_model()
QListView::setSelectionModel(model);
m_deselectedMustBeEmpty = false;
}
- int m_paintEventsCount;
+ int m_paintEventsCount = 0;
bool selectionChangedOk() const { return m_selectionChangedOk; }
protected:
@@ -2017,16 +1944,17 @@ void tst_QAbstractItemView::QTBUG50535_update_on_new_selection_model()
m_selectionChangedOk = false;
// Make sure both selections belong to the same model
- foreach (const QModelIndex &nmi, selected.indexes()) {
- foreach (const QModelIndex &omi, deselected.indexes()) {
+ const auto selIndexes = selected.indexes();
+ const auto deselIndexes = deselected.indexes();
+ for (const QModelIndex &nmi : selIndexes) {
+ for (const QModelIndex &omi : deselIndexes)
m_selectionChangedOk = m_selectionChangedOk && (nmi.model() == omi.model());
- }
}
QListView::selectionChanged(selected, deselected);
}
private:
- bool m_deselectedMustBeEmpty;
- bool m_selectionChangedOk;
+ bool m_deselectedMustBeEmpty = false;
+ bool m_selectionChangedOk = true;
};
// keep the current/selected row in the "low range", i.e. be sure it's visible, otherwise we
@@ -2074,7 +2002,7 @@ void tst_QAbstractItemView::testSelectionModelInSyncWithView()
{
QStandardItemModel model;
for (int i = 0; i < 10; ++i)
- model.appendRow(new QStandardItem(QStringLiteral("%1").arg(i)));
+ model.appendRow(new QStandardItem(QString::number(i)));
class ListView : public QListView
{
@@ -2128,8 +2056,7 @@ class SetSelectionTestView : public QListView
{
Q_OBJECT
public:
- SetSelectionTestView() : QListView() {}
-
+ using QListView::QListView;
signals:
void setSelectionCalled(const QRect &rect);
@@ -2147,9 +2074,7 @@ void tst_QAbstractItemView::testClickToSelect()
// to the virtual method QAbstractItemView::setSelection(const QRect &, SelectionFlags)
// is the 1x1 rect which conains exactly the clicked pixel if no modifiers are pressed.
- QStringList list;
- list << "A" << "B" << "C";
- QStringListModel model(list);
+ QStringListModel model({ "A", "B", "C" });
SetSelectionTestView view;
view.setModel(&model);
@@ -2207,28 +2132,24 @@ void tst_QAbstractItemView::testDialogAsEditor()
QCOMPARE(delegate.result, QDialog::Accepted);
}
-class HoverItemDelegate : public QItemDelegate
+class HoverItemDelegate : public QStyledItemDelegate
{
public:
- HoverItemDelegate()
- : QItemDelegate()
- , m_paintedWithoutHover(false)
- { }
-
- void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const override
+ using QStyledItemDelegate::QStyledItemDelegate;
+ void paint(QPainter *painter, const QStyleOptionViewItem &opt,
+ const QModelIndex &index) const override
{
Q_UNUSED(painter);
if (!(opt.state & QStyle::State_MouseOver)) {
// We don't want to set m_paintedWithoutHover for any item so check for the item at 0,0
- if (index.row() == 0 && index.column() == 0) {
+ if (index.row() == 0 && index.column() == 0)
m_paintedWithoutHover = true;
- }
}
}
- mutable bool m_paintedWithoutHover;
+ mutable bool m_paintedWithoutHover = false;
};
void tst_QAbstractItemView::QTBUG46785_mouseout_hover_state()
@@ -2249,7 +2170,7 @@ void tst_QAbstractItemView::QTBUG46785_mouseout_hover_state()
// Move the mouse into the center of the item at 0,0 to cause a paint event to occur
QTest::mouseMove(table.viewport(), itemRect.center());
- QTest::mouseClick(table.viewport(), Qt::LeftButton, 0, itemRect.center());
+ QTest::mouseClick(table.viewport(), Qt::LeftButton, {}, itemRect.center());
delegate.m_paintedWithoutHover = false;
@@ -2263,14 +2184,13 @@ void tst_QAbstractItemView::QTBUG46785_mouseout_hover_state()
void tst_QAbstractItemView::testClearModelInClickedSignal()
{
- QStringList list{"A", "B"};
- QStringListModel model(list);
+ QStringListModel model({"A", "B"});
QListView view;
view.setModel(&model);
view.show();
- QWidget::connect(&view, &QListView::clicked, [&view](const QModelIndex &index)
+ connect(&view, &QListView::clicked, [&view](const QModelIndex &index)
{
view.setModel(nullptr);
QCOMPARE(index.data().toString(), QStringLiteral("B"));
@@ -2291,14 +2211,16 @@ void tst_QAbstractItemView::inputMethodEnabled_data()
QTest::addColumn<Qt::ItemFlags>("itemFlags");
QTest::addColumn<bool>("result");
- QList<QByteArray> widgets;
- widgets << "QListView" << "QTreeView" << "QTableView";
-
- for (const QByteArray &widget : qAsConst(widgets)) {
- QTest::newRow(widget + ": no flags") << widget << Qt::ItemFlags(Qt::NoItemFlags) << false;
- QTest::newRow(widget + ": checkable") << widget << Qt::ItemFlags(Qt::ItemIsUserCheckable) << false;
- QTest::newRow(widget + ": selectable") << widget << Qt::ItemFlags(Qt::ItemIsSelectable) << false;
- QTest::newRow(widget + ": enabled") << widget << Qt::ItemFlags(Qt::ItemIsEnabled) << false;
+ const QVector<QByteArray> widgets{ "QListView", "QTreeView", "QTableView" };
+ for (const QByteArray &widget : widgets) {
+ QTest::newRow(widget + ": no flags")
+ << widget << Qt::ItemFlags(Qt::NoItemFlags) << false;
+ QTest::newRow(widget + ": checkable")
+ << widget << Qt::ItemFlags(Qt::ItemIsUserCheckable) << false;
+ QTest::newRow(widget + ": selectable")
+ << widget << Qt::ItemFlags(Qt::ItemIsSelectable) << false;
+ QTest::newRow(widget + ": enabled")
+ << widget << Qt::ItemFlags(Qt::ItemIsEnabled) << false;
QTest::newRow(widget + ": selectable|enabled")
<< widget << Qt::ItemFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled) << false;
QTest::newRow(widget + ": editable|enabled")
@@ -2314,15 +2236,7 @@ void tst_QAbstractItemView::inputMethodEnabled()
QFETCH(Qt::ItemFlags, itemFlags);
QFETCH(bool, result);
- QScopedPointer<QAbstractItemView> view;
- if (viewType == "QListView")
- view.reset(new QListView());
- else if (viewType == "QTableView")
- view.reset(new QTableView());
- else if (viewType == "QTreeView")
- view.reset(new QTreeView());
- else
- QVERIFY(0);
+ QScopedPointer<QAbstractItemView> view(viewFromString(viewType));
centerOnScreen(view.data());
view->show();
@@ -2349,14 +2263,14 @@ void tst_QAbstractItemView::inputMethodEnabled()
// Check focus by switching the activation of the window to force a focus in
view->setCurrentIndex(model->index(1, 0));
- QApplication::setActiveWindow(0);
+ QApplication::setActiveWindow(nullptr);
QApplication::setActiveWindow(view.data());
QVERIFY(QTest::qWaitForWindowActive(view.data()));
QCOMPARE(view->testAttribute(Qt::WA_InputMethodEnabled), result);
view->setCurrentIndex(QModelIndex());
QVERIFY(!view->testAttribute(Qt::WA_InputMethodEnabled));
- QApplication::setActiveWindow(0);
+ QApplication::setActiveWindow(nullptr);
QApplication::setActiveWindow(view.data());
QVERIFY(QTest::qWaitForWindowActive(view.data()));
QModelIndex index = model->index(1, 0);
@@ -2367,7 +2281,7 @@ void tst_QAbstractItemView::inputMethodEnabled()
QCOMPARE(view->testAttribute(Qt::WA_InputMethodEnabled), result);
index = model->index(0, 0);
- QApplication::setActiveWindow(0);
+ QApplication::setActiveWindow(nullptr);
QApplication::setActiveWindow(view.data());
QVERIFY(QTest::qWaitForWindowActive(view.data()));
p = view->visualRect(index).center();
@@ -2378,7 +2292,7 @@ void tst_QAbstractItemView::inputMethodEnabled()
// There is a case when it goes to the first visible item so we
// make the flags of the first item match the ones we are testing
// to check the attribute correctly
- QApplication::setActiveWindow(0);
+ QApplication::setActiveWindow(nullptr);
view->setCurrentIndex(QModelIndex());
view->reset();
item->setFlags(Qt::ItemFlags(itemFlags));
@@ -2391,9 +2305,8 @@ void tst_QAbstractItemView::currentFollowsIndexWidget_data()
{
QTest::addColumn<QByteArray>("viewType");
- QList<QByteArray> widgets;
- widgets << "QListView" << "QTreeView" << "QTableView";
- for (const QByteArray &widget : qAsConst(widgets))
+ const QVector<QByteArray> widgets{ "QListView", "QTreeView", "QTableView" };
+ for (const QByteArray &widget : widgets)
QTest::newRow(widget) << widget;
}
@@ -2401,15 +2314,7 @@ void tst_QAbstractItemView::currentFollowsIndexWidget()
{
QFETCH(QByteArray, viewType);
- QScopedPointer<QAbstractItemView> view;
- if (viewType == "QListView")
- view.reset(new QListView());
- else if (viewType == "QTableView")
- view.reset(new QTableView());
- else if (viewType == "QTreeView")
- view.reset(new QTreeView());
- else
- QVERIFY(0);
+ QScopedPointer<QAbstractItemView> view(viewFromString(viewType));
centerOnScreen(view.data());
view->show();
@@ -2438,17 +2343,18 @@ void tst_QAbstractItemView::currentFollowsIndexWidget()
QCOMPARE(view->currentIndex(), item1->index());
}
-class EditorItemDelegate : public QItemDelegate
+class EditorItemDelegate : public QStyledItemDelegate
{
+ Q_OBJECT
public:
- EditorItemDelegate() : QItemDelegate(), openedEditor(nullptr) { }
+ using QStyledItemDelegate::QStyledItemDelegate;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
const QModelIndex &) const override
{
openedEditor = new QLineEdit(parent);
return openedEditor;
}
- mutable QPointer<QWidget> openedEditor;
+ mutable QPointer<QWidget> openedEditor = nullptr;
};
// Testing the case reported in QTBUG-62253.
@@ -2458,18 +2364,14 @@ public:
// on the original window.
void tst_QAbstractItemView::checkFocusAfterActivationChanges_data()
{
- QTest::addColumn<QString>("viewType");
-
- QTest::newRow("QListView") << "QListView";
- QTest::newRow("QTableView") << "QTableView";
- QTest::newRow("QTreeView") << "QTreeView";
+ currentFollowsIndexWidget_data();
}
void tst_QAbstractItemView::checkFocusAfterActivationChanges()
{
- QFETCH(QString, viewType);
+ QFETCH(QByteArray, viewType);
- const QRect availableGeo = qApp->primaryScreen()->availableGeometry();
+ const QRect availableGeo = QGuiApplication::primaryScreen()->availableGeometry();
const int halfWidth = availableGeo.width() / 2;
QWidget otherTopLevel;
otherTopLevel.setGeometry(availableGeo.x(), availableGeo.y(),
@@ -2480,13 +2382,7 @@ void tst_QAbstractItemView::checkFocusAfterActivationChanges()
w.setGeometry(availableGeo.x() + halfWidth, availableGeo.y(),
halfWidth, availableGeo.height());
QLineEdit *le = new QLineEdit(&w);
- QAbstractItemView *view = 0;
- if (viewType == "QListView")
- view = new QListView(&w);
- else if (viewType == "QTableView")
- view = new QTableView(&w);
- else if (viewType == "QTreeView")
- view = new QTreeView(&w);
+ QAbstractItemView *view = viewFromString(viewType, &w);
QStandardItemModel model(5, 5);
view->setModel(&model);
diff --git a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp
index c58dbf599c..8264d71e83 100644
--- a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp
+++ b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp
@@ -26,25 +26,21 @@
**
****************************************************************************/
-#include "../../../../shared/fakedirmodel.h"
-#include <QtTest/QtTest>
+#include <QColumnView>
+#include <QScrollBar>
+#include <QSignalSpy>
+#include <QStringListModel>
+#include <QStyledItemDelegate>
+#include <QTest>
#include <QtTest/private/qtesthelpers_p.h>
-#include <qitemdelegate.h>
-#include <qcolumnview.h>
-#include <private/qcolumnviewgrip_p.h>
-#include <private/qfilesystemmodel_p.h>
-#include <qstringlistmodel.h>
-#include <qdebug.h>
-#include <qitemdelegate.h>
-#include <qscrollbar.h>
-#include <private/qcolumnview_p.h>
-#include <qscreen.h>
+#include <QtWidgets/private/qcolumnviewgrip_p.h>
+#include "../../../../shared/fakedirmodel.h"
#define ANIMATION_DELAY 300
-class tst_QColumnView : public QObject {
- Q_OBJECT
-
+class tst_QColumnView : public QObject
+{
+ Q_OBJECT
public:
tst_QColumnView();
@@ -98,6 +94,7 @@ private:
class TreeModel : public QStandardItemModel
{
+ Q_OBJECT
public:
TreeModel()
{
@@ -122,51 +119,31 @@ public:
inline QModelIndex thirdLevel() { return index(0, 0, secondLevel()); }
};
-class ColumnView : public QColumnView {
-
+class ColumnView : public QColumnView
+{
+ Q_OBJECT
public:
- ColumnView(QWidget *parent = 0) : QColumnView(parent){}
-
- QList<QPointer<QAbstractItemView> > createdColumns;
- void ScrollContentsBy(int x, int y) {scrollContentsBy(x,y); }
- int HorizontalOffset() const { return horizontalOffset(); }
- void emitClicked() { emit clicked(QModelIndex()); }
-
- enum PublicCursorAction {
- MoveUp = QAbstractItemView::MoveUp,
- MoveDown = QAbstractItemView::MoveDown,
- MoveLeft = QAbstractItemView::MoveLeft,
- MoveRight = QAbstractItemView::MoveRight,
- MoveHome = QAbstractItemView::MoveHome,
- MoveEnd = QAbstractItemView::MoveEnd,
- MovePageUp = QAbstractItemView::MovePageUp,
- MovePageDown = QAbstractItemView::MovePageDown,
- MoveNext = QAbstractItemView::MoveNext,
- MovePrevious = QAbstractItemView::MovePrevious
- };
-
- inline QModelIndex MoveCursor(PublicCursorAction ca, Qt::KeyboardModifiers kbm)
- { return QColumnView::moveCursor((CursorAction)ca, kbm); }
- bool IsIndexHidden(const QModelIndex&index) const
- { return isIndexHidden(index); }
-
- void setSelection(const QRect & rect, QItemSelectionModel::SelectionFlags command )
- {
- QColumnView::setSelection(rect, command);
- }
+ using QColumnView::QColumnView;
+ using QColumnView::horizontalOffset;
+ using QColumnView::clicked;
+ using QColumnView::isIndexHidden;
+ using QColumnView::moveCursor;
+ using QColumnView::scrollContentsBy;
+ using QColumnView::setSelection;
+ using QColumnView::visualRegionForSelection;
+
+ friend class tst_QColumnView;
+
+ QVector<QPointer<QAbstractItemView>> createdColumns;
- // visualRegionForSelection() is protected in QColumnView.
- QRegion getVisualRegionForSelection(const QItemSelection &selection){
- return QColumnView::visualRegionForSelection(selection);
- }
protected:
- QAbstractItemView *createColumn(const QModelIndex &index) {
+ QAbstractItemView *createColumn(const QModelIndex &index) override
+ {
QAbstractItemView *view = QColumnView::createColumn(index);
QPointer<QAbstractItemView> savedView = view;
createdColumns.append(savedView);
return view;
}
-
};
tst_QColumnView::tst_QColumnView()
@@ -183,7 +160,7 @@ void tst_QColumnView::initTestCase()
void tst_QColumnView::init()
{
- qApp->setLayoutDirection(Qt::LeftToRight);
+ QGuiApplication::setLayoutDirection(Qt::LeftToRight);
}
void tst_QColumnView::rootIndex()
@@ -199,7 +176,7 @@ void tst_QColumnView::rootIndex()
QModelIndex drive = model.firstLevel();
QVERIFY(view.visualRect(drive).isValid());
view.setRootIndex(QModelIndex());
- QCOMPARE(view.HorizontalOffset(), 0);
+ QCOMPARE(view.horizontalOffset(), 0);
QCOMPARE(view.rootIndex(), QModelIndex());
QVERIFY(view.visualRect(drive).isValid());
@@ -210,7 +187,7 @@ void tst_QColumnView::rootIndex()
while (i < model.rowCount(home) - 1 && !model.hasChildren(homeFile))
homeFile = model.index(++i, 0, home);
view.setRootIndex(home);
- QCOMPARE(view.HorizontalOffset(), 0);
+ QCOMPARE(view.horizontalOffset(), 0);
QCOMPARE(view.rootIndex(), home);
QVERIFY(!view.visualRect(drive).isValid());
QVERIFY(!view.visualRect(home).isValid());
@@ -221,7 +198,7 @@ void tst_QColumnView::rootIndex()
view.setRootIndex(home);
view.setCurrentIndex(homeFile);
view.scrollTo(model.index(0,0, homeFile));
- QCOMPARE(view.HorizontalOffset(), 0);
+ QCOMPARE(view.horizontalOffset(), 0);
QCOMPARE(view.rootIndex(), home);
QVERIFY(!view.visualRect(drive).isValid());
QVERIFY(!view.visualRect(home).isValid());
@@ -238,17 +215,15 @@ void tst_QColumnView::rootIndex()
QModelIndex two = model.index(0, 0, homeFile);
while (i < model.rowCount(homeFile) - 1 && !model.hasChildren(two))
two = model.index(++i, 0, homeFile);
- qApp->processEvents();
QTest::qWait(ANIMATION_DELAY);
view.setCurrentIndex(two);
view.scrollTo(two);
QTest::qWait(ANIMATION_DELAY);
- qApp->processEvents();
QVERIFY(two.isValid());
- QVERIFY(view.HorizontalOffset() != 0);
+ QVERIFY(view.horizontalOffset() != 0);
view.setRootIndex(homeFile);
- QCOMPARE(view.HorizontalOffset(), 0);
+ QCOMPARE(view.horizontalOffset(), 0);
}
void tst_QColumnView::grips()
@@ -262,9 +237,9 @@ void tst_QColumnView::grips()
{
const QObjectList list = view.viewport()->children();
- for (int i = 0 ; i < list.count(); ++i) {
- if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(list.at(i)))
- QVERIFY(view->cornerWidget() != 0);
+ for (QObject *obj : list) {
+ if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(obj))
+ QVERIFY(view->cornerWidget() != nullptr);
}
}
view.setResizeGripsVisible(false);
@@ -272,8 +247,8 @@ void tst_QColumnView::grips()
{
const QObjectList list = view.viewport()->children();
- for (int i = 0 ; i < list.count(); ++i) {
- if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(list.at(i))) {
+ for (QObject *obj : list) {
+ if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(obj)) {
if (view->isVisible())
QVERIFY(!view->cornerWidget());
}
@@ -288,9 +263,9 @@ void tst_QColumnView::isIndexHidden()
{
ColumnView view;
QModelIndex idx;
- QCOMPARE(view.IsIndexHidden(idx), false);
+ QCOMPARE(view.isIndexHidden(idx), false);
view.setModel(&m_fakeDirModel);
- QCOMPARE(view.IsIndexHidden(idx), false);
+ QCOMPARE(view.isIndexHidden(idx), false);
}
void tst_QColumnView::indexAt()
@@ -319,7 +294,6 @@ void tst_QColumnView::indexAt()
view.selectionModel()->select(child, QItemSelectionModel::SelectCurrent);
view.setCurrentIndex(child);
- qApp->processEvents();
QTest::qWait(200);
// test that the second row doesn't start at 0
@@ -348,17 +322,17 @@ void tst_QColumnView::scrollContentsBy()
ColumnView view;
if (reverse)
view.setLayoutDirection(Qt::RightToLeft);
- view.ScrollContentsBy(-1, -1);
- view.ScrollContentsBy(0, 0);
+ view.scrollContentsBy(-1, -1);
+ view.scrollContentsBy(0, 0);
TreeModel model;
view.setModel(&model);
- view.ScrollContentsBy(0, 0);
+ view.scrollContentsBy(0, 0);
QModelIndex home = model.thirdLevel();
view.setCurrentIndex(home);
QTest::qWait(ANIMATION_DELAY);
- view.ScrollContentsBy(0, 0);
+ view.scrollContentsBy(0, 0);
}
void tst_QColumnView::scrollTo_data()
@@ -385,7 +359,7 @@ void tst_QColumnView::scrollTo()
QVERIFY(QTest::qWaitForWindowActive(&topLevel));
view.scrollTo(QModelIndex(), QAbstractItemView::EnsureVisible);
- QCOMPARE(view.HorizontalOffset(), 0);
+ QCOMPARE(view.horizontalOffset(), 0);
TreeModel model;
view.setModel(&model);
@@ -400,45 +374,44 @@ void tst_QColumnView::scrollTo()
QModelIndex index = model.index(0, 0, home);
view.scrollTo(index, QAbstractItemView::EnsureVisible);
- QCOMPARE(view.HorizontalOffset(), 0);
+ QCOMPARE(view.horizontalOffset(), 0);
// Embedded requires that at least one widget have focus
QWidget w;
w.show();
- QCOMPARE(view.HorizontalOffset(), 0);
+ QCOMPARE(view.horizontalOffset(), 0);
if (giveFocus)
view.setFocus(Qt::OtherFocusReason);
else
view.clearFocus();
- QCOMPARE(view.HorizontalOffset(), 0);
- qApp->processEvents();
- QCOMPARE(view.HorizontalOffset(), 0);
+ QCOMPARE(view.horizontalOffset(), 0);
+ QCoreApplication::processEvents();
+ QCOMPARE(view.horizontalOffset(), 0);
QTRY_COMPARE(view.hasFocus(), giveFocus);
// scroll to the right
int level = 0;
- int last = view.HorizontalOffset();
- while(model.hasChildren(index) && level < 5) {
+ int last = view.horizontalOffset();
+ while (model.hasChildren(index) && level < 5) {
view.setCurrentIndex(index);
QTest::qWait(ANIMATION_DELAY);
view.scrollTo(index, QAbstractItemView::EnsureVisible);
QTest::qWait(ANIMATION_DELAY);
- qApp->processEvents();
index = model.index(0, 0, index);
level++;
if (level >= 2) {
if (!reverse) {
- QTRY_VERIFY(view.HorizontalOffset() < 0);
+ QTRY_VERIFY(view.horizontalOffset() < 0);
qDebug() << "last=" << last
- << " ; HorizontalOffset= " << view.HorizontalOffset();
- QTRY_VERIFY(last > view.HorizontalOffset());
+ << " ; horizontalOffset= " << view.horizontalOffset();
+ QTRY_VERIFY(last > view.horizontalOffset());
} else {
- QTRY_VERIFY(view.HorizontalOffset() > 0);
- QTRY_VERIFY(last < view.HorizontalOffset());
+ QTRY_VERIFY(view.horizontalOffset() > 0);
+ QTRY_VERIFY(last < view.horizontalOffset());
}
}
- last = view.HorizontalOffset();
+ last = view.horizontalOffset();
}
// scroll to the left
@@ -450,17 +423,17 @@ void tst_QColumnView::scrollTo()
index = index.parent();
if (start != level) {
if (!reverse) {
- QTRY_VERIFY(last < view.HorizontalOffset());
+ QTRY_VERIFY(last < view.horizontalOffset());
} else {
- if (last <= view.HorizontalOffset()) {
+ if (last <= view.horizontalOffset()) {
qDebug() << "Test failure. last=" << last
- << " ; HorizontalOffset= " << view.HorizontalOffset();
+ << " ; horizontalOffset= " << view.horizontalOffset();
}
- QTRY_VERIFY(last > view.HorizontalOffset());
+ QTRY_VERIFY(last > view.horizontalOffset());
}
}
level--;
- last = view.HorizontalOffset();
+ last = view.horizontalOffset();
}
// It shouldn't automatically steal focus if it doesn't have it
QTRY_COMPARE(view.hasFocus(), giveFocus);
@@ -490,20 +463,20 @@ void tst_QColumnView::moveCursor()
if (reverse)
view.setLayoutDirection(Qt::RightToLeft);
// don't crash
- view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier);
+ view.moveCursor(ColumnView::MoveUp, Qt::NoModifier);
// don't do anything
- QCOMPARE(view.MoveCursor(ColumnView::MoveEnd, Qt::NoModifier), QModelIndex());
+ QCOMPARE(view.moveCursor(ColumnView::MoveEnd, Qt::NoModifier), QModelIndex());
view.setModel(&m_fakeDirModel);
QModelIndex ci = view.currentIndex();
- QCOMPARE(view.MoveCursor(ColumnView::MoveUp, Qt::NoModifier), QModelIndex());
- QCOMPARE(view.MoveCursor(ColumnView::MoveDown, Qt::NoModifier), QModelIndex());
+ QCOMPARE(view.moveCursor(ColumnView::MoveUp, Qt::NoModifier), QModelIndex());
+ QCOMPARE(view.moveCursor(ColumnView::MoveDown, Qt::NoModifier), QModelIndex());
// left at root
view.setCurrentIndex(m_fakeDirModel.index(0,0));
- ColumnView::PublicCursorAction action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
- QCOMPARE(view.MoveCursor(action, Qt::NoModifier), m_fakeDirModel.index(0,0));
+ ColumnView::CursorAction action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
+ QCOMPARE(view.moveCursor(action, Qt::NoModifier), m_fakeDirModel.index(0,0));
// left shouldn't move up
int i = 0;
@@ -513,30 +486,29 @@ void tst_QColumnView::moveCursor()
QVERIFY(m_fakeDirModel.hasChildren(ci));
view.setCurrentIndex(ci);
action = reverse ? ColumnView::MoveRight : ColumnView::MoveLeft;
- QCOMPARE(view.MoveCursor(action, Qt::NoModifier), ci);
+ QCOMPARE(view.moveCursor(action, Qt::NoModifier), ci);
// now move to the left (i.e. move over one column)
view.setCurrentIndex(m_fakeDirHomeIndex);
- QCOMPARE(view.MoveCursor(action, Qt::NoModifier), m_fakeDirHomeIndex.parent());
+ QCOMPARE(view.moveCursor(action, Qt::NoModifier), m_fakeDirHomeIndex.parent());
// right
action = reverse ? ColumnView::MoveLeft : ColumnView::MoveRight;
view.setCurrentIndex(ci);
- QModelIndex mc = view.MoveCursor(action, Qt::NoModifier);
+ QModelIndex mc = view.moveCursor(action, Qt::NoModifier);
QCOMPARE(mc, m_fakeDirModel.index(0,0, ci));
// for empty directories (no way to go 'right'), next one should move down
QModelIndex idx = m_fakeDirModel.index(0, 0, ci);
const int rowCount = m_fakeDirModel.rowCount(ci);
- while (m_fakeDirModel.hasChildren(idx) && rowCount > idx.row() + 1) {
+ while (m_fakeDirModel.hasChildren(idx) && rowCount > idx.row() + 1)
idx = idx.sibling(idx.row() + 1, idx.column());
- }
static const char error[] = "This test requires an empty directory followed by another directory.";
QVERIFY2(idx.isValid(), error);
QVERIFY2(!m_fakeDirModel.hasChildren(idx), error);
QVERIFY2(idx.row() + 1 < rowCount, error);
view.setCurrentIndex(idx);
- mc = view.MoveCursor(action, Qt::NoModifier);
+ mc = view.moveCursor(action, Qt::NoModifier);
QCOMPARE(mc, idx.sibling(idx.row() + 1, idx.column()));
}
@@ -554,11 +526,12 @@ void tst_QColumnView::selectAll()
QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);
QModelIndex file;
- for (int i = 0; i < m_fakeDirModel.rowCount(m_fakeDirHomeIndex); ++i)
+ for (int i = 0; i < m_fakeDirModel.rowCount(m_fakeDirHomeIndex); ++i) {
if (!m_fakeDirModel.hasChildren(m_fakeDirModel.index(i, 0, m_fakeDirHomeIndex))) {
file = m_fakeDirModel.index(i, 0, m_fakeDirHomeIndex);
break;
}
+ }
view.setCurrentIndex(file);
view.selectAll();
QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);
@@ -572,7 +545,7 @@ void tst_QColumnView::clicked()
ColumnView view;
view.setModel(&m_fakeDirModel);
- view.resize(800,300);
+ view.resize(800, 300);
view.show();
view.setCurrentIndex(m_fakeDirHomeIndex);
@@ -581,12 +554,12 @@ void tst_QColumnView::clicked()
QModelIndex parent = m_fakeDirHomeIndex.parent();
QVERIFY(parent.isValid());
- QSignalSpy clickedSpy(&view, SIGNAL(clicked(QModelIndex)));
+ QSignalSpy clickedSpy(&view, &QAbstractItemView::clicked);
QPoint localPoint = view.visualRect(m_fakeDirHomeIndex).center();
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, localPoint);
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, localPoint);
QCOMPARE(clickedSpy.count(), 1);
- qApp->processEvents();
+ QCoreApplication::processEvents();
if (sizeof(qreal) != sizeof(double))
QSKIP("Skipped due to rounding errors");
@@ -653,21 +626,21 @@ void tst_QColumnView::visualRegionForSelection()
{
ColumnView view;
QItemSelection emptyItemSelection;
- QCOMPARE(QRegion(), view.getVisualRegionForSelection(emptyItemSelection));
+ QCOMPARE(QRegion(), view.visualRegionForSelection(emptyItemSelection));
// a region that isn't empty
view.setModel(&m_fakeDirModel);
QItemSelection itemSelection(m_fakeDirModel.index(0, 0, m_fakeDirHomeIndex), m_fakeDirModel.index(m_fakeDirModel.rowCount(m_fakeDirHomeIndex) - 1, 0, m_fakeDirHomeIndex));
- QVERIFY(QRegion() != view.getVisualRegionForSelection(itemSelection));
+ QVERIFY(QRegion() != view.visualRegionForSelection(itemSelection));
}
void tst_QColumnView::moveGrip_basic()
{
QColumnView view;
QColumnViewGrip *grip = new QColumnViewGrip(&view);
- QSignalSpy spy(grip, SIGNAL(gripMoved(int)));
+ QSignalSpy spy(grip, &QColumnViewGrip::gripMoved);
view.setCornerWidget(grip);
int oldX = view.width();
grip->moveGrip(10);
@@ -707,12 +680,11 @@ void tst_QColumnView::moveGrip()
int columnNum = view.createdColumns.count() - 2;
QVERIFY(columnNum >= 0);
- QObjectList list = view.createdColumns[columnNum]->children();
- QColumnViewGrip *grip = 0;
- for (int i = 0; i < list.count(); ++i) {
- if ((grip = qobject_cast<QColumnViewGrip *>(list[i]))) {
+ const QObjectList list = view.createdColumns[columnNum]->children();
+ QColumnViewGrip *grip = nullptr;
+ for (QObject *obj : list) {
+ if ((grip = qobject_cast<QColumnViewGrip *>(obj)))
break;
- }
}
if (!grip)
return;
@@ -728,7 +700,7 @@ void tst_QColumnView::doubleClick()
{
QColumnView view;
QColumnViewGrip *grip = new QColumnViewGrip(&view);
- QSignalSpy spy(grip, SIGNAL(gripMoved(int)));
+ QSignalSpy spy(grip, &QColumnViewGrip::gripMoved);
view.setCornerWidget(grip);
view.resize(200, 200);
QCOMPARE(view.width(), 200);
@@ -741,24 +713,24 @@ void tst_QColumnView::gripMoved()
{
QColumnView view;
QColumnViewGrip *grip = new QColumnViewGrip(&view);
- QSignalSpy spy(grip, SIGNAL(gripMoved(int)));
+ QSignalSpy spy(grip, &QColumnViewGrip::gripMoved);
view.setCornerWidget(grip);
view.move(300, 300);
view.resize(200, 200);
- qApp->processEvents();
+ QCoreApplication::processEvents();
int oldWidth = view.width();
- QTest::mousePress(grip, Qt::LeftButton, 0, QPoint(1,1));
+ QTest::mousePress(grip, Qt::LeftButton, {}, QPoint(1, 1));
//QTest::mouseMove(grip, QPoint(grip->globalX()+50, y));
- QPoint posNew = QPoint(grip->mapToGlobal(QPoint(1,1)).x() + 65, 0);
+ QPoint posNew = QPoint(grip->mapToGlobal(QPoint(1, 1)).x() + 65, 0);
QMouseEvent *event = new QMouseEvent(QEvent::MouseMove, posNew, posNew, Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
QCoreApplication::postEvent(grip, event);
QCoreApplication::processEvents();
QTest::mouseRelease(grip, Qt::LeftButton);
- QCOMPARE(spy.count(), 1);
+ QTRY_COMPARE(spy.count(), 1);
QCOMPARE(view.width(), oldWidth + 65);
}
@@ -785,12 +757,12 @@ void tst_QColumnView::preview()
}
QVERIFY(file.isValid());
view.setCurrentIndex(file);
- QVERIFY(view.previewWidget() != (QWidget*)0);
+ QVERIFY(view.previewWidget() != nullptr);
QWidget *previewWidget = new QWidget(&view);
view.setPreviewWidget(previewWidget);
QCOMPARE(view.previewWidget(), previewWidget);
- QVERIFY(previewWidget->parent() != ((QWidget*)&view));
+ QVERIFY(previewWidget->parent() != &view);
view.setCurrentIndex(home);
// previewWidget should be marked for deletion
@@ -803,21 +775,21 @@ void tst_QColumnView::swapPreview()
{
// swap the preview widget in updatePreviewWidget
QColumnView view;
- QStringList sl;
- sl << QLatin1String("test");
- QStringListModel model(sl);
+ QStringListModel model({ QLatin1String("test") });
view.setModel(&model);
view.setCurrentIndex(view.indexAt(QPoint(1, 1)));
- connect(&view, SIGNAL(updatePreviewWidget(QModelIndex)),
- this, SLOT(setPreviewWidget()));
+ connect(&view, &QColumnView::updatePreviewWidget,
+ this, &tst_QColumnView::setPreviewWidget);
view.setCurrentIndex(view.indexAt(QPoint(1, 1)));
QTest::qWait(ANIMATION_DELAY);
- qApp->processEvents();
+ QCoreApplication::processEvents();
}
void tst_QColumnView::setPreviewWidget()
{
- ((QColumnView*)sender())->setPreviewWidget(new QWidget);
+ auto ptr = qobject_cast<QColumnView *>(sender());
+ QVERIFY(ptr);
+ ptr->setPreviewWidget(new QWidget);
}
void tst_QColumnView::sizes()
@@ -825,8 +797,7 @@ void tst_QColumnView::sizes()
QColumnView view;
QCOMPARE(view.columnWidths().count(), 0);
- QList<int> newSizes;
- newSizes << 10 << 4 << 50 << 6;
+ const QList<int> newSizes{ 10, 4, 50, 6 };
QList<int> visibleSizes;
view.setColumnWidths(newSizes);
@@ -839,8 +810,7 @@ void tst_QColumnView::sizes()
QCOMPARE(postSizes, newSizes.mid(0, postSizes.count()));
QVERIFY(view.columnWidths().count() > 1);
- QList<int> smallerSizes;
- smallerSizes << 6;
+ QList<int> smallerSizes{ 6 };
view.setColumnWidths(smallerSizes);
QList<int> expectedSizes = newSizes;
expectedSizes[0] = 6;
@@ -851,13 +821,13 @@ void tst_QColumnView::sizes()
void tst_QColumnView::rowDelegate()
{
ColumnView view;
- QItemDelegate *d = new QItemDelegate;
+ QStyledItemDelegate *d = new QStyledItemDelegate;
view.setItemDelegateForRow(3, d);
view.setModel(&m_fakeDirModel);
for (int i = 0; i < view.createdColumns.count(); ++i) {
QAbstractItemView *column = view.createdColumns.at(i);
- QCOMPARE(column->itemDelegateForRow(3), (QAbstractItemDelegate*)d);
+ QCOMPARE(column->itemDelegateForRow(3), d);
}
delete d;
}
@@ -900,7 +870,7 @@ void tst_QColumnView::changeSameColumn()
}
QVERIFY(second.isValid());
- QList<QPointer<QAbstractItemView> > old = view.createdColumns;
+ const auto old = view.createdColumns;
view.setCurrentIndex(second);
QCOMPARE(old, view.createdColumns);
@@ -973,7 +943,7 @@ void tst_QColumnView::pullRug()
QModelIndex home = model.thirdLevel();
view.setCurrentIndex(home);
if (removeModel)
- view.setModel(0);
+ view.setModel(nullptr);
else
view.setCurrentIndex(QModelIndex());
QTest::qWait(ANIMATION_DELAY);
@@ -982,19 +952,19 @@ void tst_QColumnView::pullRug()
void tst_QColumnView::dynamicModelChanges()
{
- struct MyItemDelegate : public QItemDelegate
+ struct MyItemDelegate : public QStyledItemDelegate
{
void paint(QPainter *painter,
const QStyleOptionViewItem &option,
- const QModelIndex &index) const
+ const QModelIndex &index) const override
{
paintedIndexes += index;
- QItemDelegate::paint(painter, option, index);
+ QStyledItemDelegate::paint(painter, option, index);
}
mutable QSet<QModelIndex> paintedIndexes;
- } delegate;;
+ } delegate;
QStandardItemModel model;
ColumnView view;
view.setModel(&model);
@@ -1008,8 +978,6 @@ void tst_QColumnView::dynamicModelChanges()
QVERIFY(QTest::qWaitForWindowExposed(&view)); //let the time for painting to occur
QTRY_COMPARE(delegate.paintedIndexes.count(), 1);
QCOMPARE(*delegate.paintedIndexes.begin(), model.index(0,0));
-
-
}
diff --git a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp
index d401154228..5097f2e356 100644
--- a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp
+++ b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp
@@ -34,6 +34,8 @@
#include <qdebug.h>
#include "emulationdetector.h"
+QT_WARNING_DISABLE_DEPRECATED
+
class tst_QDirModel : public QObject
{
Q_OBJECT
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index df02815eb2..df1b271f2a 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -27,32 +27,28 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
+#include <QDesktopWidget>
+#include <QHeaderView>
+#include <QProxyStyle>
+#include <QSignalSpy>
+#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QStringListModel>
-#include <QSortFilterProxyModel>
#include <QTableView>
-#include <QProxyStyle>
+#include <QTest>
+#include <QTreeWidget>
+#include <QtWidgets/private/qheaderview_p.h>
-#include <qabstractitemmodel.h>
-#include <qapplication.h>
-#include <qheaderview.h>
-#include <private/qheaderview_p.h>
-#include <qitemdelegate.h>
-#include <qtreewidget.h>
-#include <qdebug.h>
-#include <qscreen.h>
-#include <qdesktopwidget.h>
-
-typedef QList<int> IntList;
-
-typedef QList<bool> BoolList;
+using BoolList = QVector<bool>;
+using IntList = QVector<int>;
+using ResizeVec = QVector<QHeaderView::ResizeMode>;
class TestStyle : public QProxyStyle
{
+ Q_OBJECT
public:
- void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
+ void drawControl(ControlElement element, const QStyleOption *option,
+ QPainter *painter, const QWidget *widget) const override
{
if (element == CE_HeaderSection) {
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option))
@@ -60,16 +56,17 @@ public:
}
QProxyStyle::drawControl(element, option, painter, widget);
}
- mutable QStyleOptionHeader::SectionPosition lastPosition;
+ mutable QStyleOptionHeader::SectionPosition lastPosition = QStyleOptionHeader::Beginning;
};
class protected_QHeaderView : public QHeaderView
{
Q_OBJECT
public:
- protected_QHeaderView(Qt::Orientation orientation) : QHeaderView(orientation) {
+ protected_QHeaderView(Qt::Orientation orientation) : QHeaderView(orientation)
+ {
resizeSections();
- };
+ }
void testEvent();
void testhorizontalOffset();
@@ -80,7 +77,9 @@ public:
class XResetModel : public QStandardItemModel
{
- virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
+ Q_OBJECT
+public:
+ bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override
{
blockSignals(true);
bool r = QStandardItemModel::removeRows(row, count, parent);
@@ -89,7 +88,7 @@ class XResetModel : public QStandardItemModel
endResetModel();
return r;
}
- virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex())
+ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override
{
blockSignals(true);
bool r = QStandardItemModel::insertRows(row, count, parent);
@@ -276,16 +275,14 @@ void tst_QHeaderView::initMain()
class QtTestModel: public QAbstractTableModel
{
-
-Q_OBJECT
-
+ Q_OBJECT
public:
- QtTestModel(QObject *parent = 0): QAbstractTableModel(parent),
- cols(0), rows(0), wrongIndex(false), m_bMultiLine(false) {}
- int rowCount(const QModelIndex&) const override { return rows; }
- int columnCount(const QModelIndex&) const override { return cols; }
+ QtTestModel(int rc, int cc, QObject *parent = nullptr)
+ : QAbstractTableModel(parent), rows(rc), cols(cc) {}
+ int rowCount(const QModelIndex &) const override { return rows; }
+ int columnCount(const QModelIndex &) const override { return cols; }
bool isEditable(const QModelIndex &) const { return true; }
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
{
if (section < 0 || (role != Qt::DisplayRole && role != Qt::StatusTipRole))
return QVariant();
@@ -394,9 +391,10 @@ public:
endResetModel();
}
- int cols, rows;
- mutable bool wrongIndex;
- bool m_bMultiLine;
+ int rows = 0;
+ int cols = 0;
+ mutable bool wrongIndex = false;
+ bool m_bMultiLine = false;
};
// Testing get/set functions
@@ -442,16 +440,16 @@ void tst_QHeaderView::getSetCheck()
// void QHeaderView::setOffset(int)
obj1.setOffset(0);
QCOMPARE(0, obj1.offset());
- obj1.setOffset(INT_MIN);
- QCOMPARE(INT_MIN, obj1.offset());
- obj1.setOffset(INT_MAX);
- QCOMPARE(INT_MAX, obj1.offset());
+ obj1.setOffset(std::numeric_limits<int>::min());
+ QCOMPARE(std::numeric_limits<int>::min(), obj1.offset());
+ obj1.setOffset(std::numeric_limits<int>::max());
+ QCOMPARE(std::numeric_limits<int>::max(), obj1.offset());
}
tst_QHeaderView::tst_QHeaderView()
{
- qRegisterMetaType<int>("Qt::SortOrder");
+ qRegisterMetaType<Qt::SortOrder>("Qt::SortOrder");
}
void tst_QHeaderView::initTestCase()
@@ -472,8 +470,8 @@ void tst_QHeaderView::cleanupTestCase()
void tst_QHeaderView::init()
{
- topLevel = new QWidget();
- view = new QHeaderView(Qt::Vertical,topLevel);
+ topLevel = new QWidget;
+ view = new QHeaderView(Qt::Vertical, topLevel);
// Some initial value tests before a model is added
QCOMPARE(view->length(), 0);
QCOMPARE(view->sizeHint(), QSize(0,0));
@@ -499,7 +497,7 @@ void tst_QHeaderView::init()
}
*/
- QSignalSpy spy(view, SIGNAL(sectionCountChanged(int,int)));
+ QSignalSpy spy(view, &QHeaderView::sectionCountChanged);
view->setModel(model);
QCOMPARE(spy.count(), 1);
view->resize(200,200);
@@ -510,11 +508,11 @@ void tst_QHeaderView::cleanup()
m_tableview->setUpdatesEnabled(true);
if (view && view->parent() != m_tableview)
delete view;
- view = 0;
+ view = nullptr;
delete model;
- model = 0;
+ model = nullptr;
delete topLevel;
- topLevel = 0;
+ topLevel = nullptr;
}
void tst_QHeaderView::noModel()
@@ -525,7 +523,7 @@ void tst_QHeaderView::noModel()
void tst_QHeaderView::emptyModel()
{
- QtTestModel testmodel;
+ QtTestModel testmodel(0, 0);
view->setModel(&testmodel);
QVERIFY(!testmodel.wrongIndex);
QCOMPARE(view->count(), testmodel.rows);
@@ -534,8 +532,7 @@ void tst_QHeaderView::emptyModel()
void tst_QHeaderView::removeRows()
{
- QtTestModel model;
- model.rows = model.cols = 10;
+ QtTestModel model(10, 10);
QHeaderView vertical(Qt::Vertical);
QHeaderView horizontal(Qt::Horizontal);
@@ -561,8 +558,7 @@ void tst_QHeaderView::removeRows()
void tst_QHeaderView::removeCols()
{
- QtTestModel model;
- model.rows = model.cols = 10;
+ QtTestModel model(10, 10);
QHeaderView vertical(Qt::Vertical);
QHeaderView horizontal(Qt::Horizontal);
@@ -644,14 +640,12 @@ void tst_QHeaderView::hidden()
view->setSectionHidden(i, true);
view->setModel(&model2);
QVERIFY(view->sectionsHidden());
- for (int i = 0; i < model2.rowCount(); ++i) {
+ for (int i = 0; i < model2.rowCount(); ++i)
QVERIFY(view->isSectionHidden(i));
- }
view->setModel(model);
- for (int i = 0; i < model2.rowCount(); ++i) {
+ for (int i = 0; i < model2.rowCount(); ++i)
QVERIFY(view->isSectionHidden(i));
- }
QCOMPARE(view->isSectionHidden(model->rowCount() - 1), false);
for (int i = 0; i < model->rowCount(); ++i)
view->setSectionHidden(i, false);
@@ -680,14 +674,12 @@ void tst_QHeaderView::oneSectionSize()
{
//this ensures that if there is only one section, it gets a correct width (more than 0)
QHeaderView view (Qt::Vertical);
- QtTestModel model;
- model.cols = 1;
- model.rows = 1;
+ QtTestModel model(1, 1);
view.setSectionResizeMode(QHeaderView::Interactive);
view.setModel(&model);
-
view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(view.sectionSize(0) > 0);
}
@@ -695,15 +687,15 @@ void tst_QHeaderView::oneSectionSize()
void tst_QHeaderView::sectionSize_data()
{
- QTest::addColumn<QList<int> >("boundsCheck");
- QTest::addColumn<QList<int> >("defaultSizes");
+ QTest::addColumn<IntList>("boundsCheck");
+ QTest::addColumn<IntList>("defaultSizes");
QTest::addColumn<int>("initialDefaultSize");
QTest::addColumn<int>("lastVisibleSectionSize");
QTest::addColumn<int>("persistentSectionSize");
QTest::newRow("data set one")
- << (QList<int>() << -1 << 0 << 4 << 9999)
- << (QList<int>() << 10 << 30 << 30)
+ << (IntList{ -1, 0, 4, 9999 })
+ << (IntList{ 10, 30, 30 })
<< 30
<< 300
<< 20;
@@ -716,19 +708,19 @@ void tst_QHeaderView::sectionSize()
#elif defined Q_OS_WINRT
QSKIP("Fails on WinRT - QTBUG-68297");
#endif
- QFETCH(QList<int>, boundsCheck);
- QFETCH(QList<int>, defaultSizes);
+ QFETCH(const IntList, boundsCheck);
+ QFETCH(const IntList, defaultSizes);
QFETCH(int, initialDefaultSize);
QFETCH(int, lastVisibleSectionSize);
QFETCH(int, persistentSectionSize);
// bounds check
- foreach (int val, boundsCheck)
+ for (int val : boundsCheck)
view->sectionSize(val);
// default size
QCOMPARE(view->defaultSectionSize(), initialDefaultSize);
- foreach (int def, defaultSizes) {
+ for (int def : defaultSizes) {
view->setDefaultSectionSize(def);
QCOMPARE(view->defaultSectionSize(), def);
}
@@ -757,9 +749,7 @@ void tst_QHeaderView::sectionSize()
int sectionCount = view->count();
for (int i = 0; i < sectionCount; ++i)
view->resizeSection(i, persistentSectionSize);
- QtTestModel model;
- model.cols = sectionCount * 2;
- model.rows = sectionCount * 2;
+ QtTestModel model(sectionCount * 2, sectionCount * 2);
view->setModel(&model);
for (int j = 0; j < sectionCount; ++j)
QCOMPARE(view->sectionSize(j), persistentSectionSize);
@@ -784,35 +774,34 @@ void tst_QHeaderView::visualIndex()
void tst_QHeaderView::visualIndexAt_data()
{
- QTest::addColumn<QList<int> >("hidden");
- QTest::addColumn<QList<int> >("from");
- QTest::addColumn<QList<int> >("to");
- QTest::addColumn<QList<int> >("coordinate");
- QTest::addColumn<QList<int> >("visual");
+ QTest::addColumn<IntList>("hidden");
+ QTest::addColumn<IntList>("from");
+ QTest::addColumn<IntList>("to");
+ QTest::addColumn<IntList>("coordinate");
+ QTest::addColumn<IntList>("visual");
- QList<int> coordinateList;
- coordinateList << -1 << 0 << 31 << 91 << 99999;
+ const IntList coordinateList{ -1, 0, 31, 91, 99999 };
QTest::newRow("no hidden, no moved sections")
- << QList<int>()
- << QList<int>()
- << QList<int>()
+ << IntList()
+ << IntList()
+ << IntList()
<< coordinateList
- << (QList<int>() << -1 << 0 << 1 << 3 << -1);
+ << (IntList{ -1, 0, 1, 3, -1 });
QTest::newRow("no hidden, moved sections")
- << QList<int>()
- << (QList<int>() << 0)
- << (QList<int>() << 1)
+ << IntList()
+ << (IntList{ 0 })
+ << (IntList{ 1 })
<< coordinateList
- << (QList<int>() << -1 << 0 << 1 << 3 << -1);
+ << (IntList{ -1, 0, 1, 3, -1 });
QTest::newRow("hidden, no moved sections")
- << (QList<int>() << 0)
- << QList<int>()
- << QList<int>()
+ << (IntList{ 0 })
+ << IntList()
+ << IntList()
<< coordinateList
- << (QList<int>() << -1 << 1 << 2 << 3 << -1);
+ << (IntList{ -1, 1, 2, 3, -1 });
}
void tst_QHeaderView::visualIndexAt()
@@ -822,26 +811,24 @@ void tst_QHeaderView::visualIndexAt()
#elif defined Q_OS_WINRT
QSKIP("Fails on WinRT - QTBUG-68297");
#endif
- QFETCH(QList<int>, hidden);
- QFETCH(QList<int>, from);
- QFETCH(QList<int>, to);
- QFETCH(QList<int>, coordinate);
- QFETCH(QList<int>, visual);
+ QFETCH(const IntList, hidden);
+ QFETCH(const IntList, from);
+ QFETCH(const IntList, to);
+ QFETCH(const IntList, coordinate);
+ QFETCH(const IntList, visual);
view->setStretchLastSection(true);
topLevel->show();
QVERIFY(QTest::qWaitForWindowExposed(topLevel));
- for (int i = 0; i < hidden.count(); ++i)
- view->setSectionHidden(hidden.at(i), true);
+ for (int i : hidden)
+ view->setSectionHidden(i, true);
for (int j = 0; j < from.count(); ++j)
view->moveSection(from.at(j), to.at(j));
- QTest::qWait(100);
-
for (int k = 0; k < coordinate.count(); ++k)
- QCOMPARE(view->visualIndexAt(coordinate.at(k)), visual.at(k));
+ QTRY_COMPARE(view->visualIndexAt(coordinate.at(k)), visual.at(k));
}
void tst_QHeaderView::length()
@@ -852,9 +839,8 @@ void tst_QHeaderView::length()
//minimumSectionSize should be the size of the last section of the widget is not tall enough
int length = view->minimumSectionSize();
- for (int i=0; i < view->count()-1; i++) {
+ for (int i = 0; i < view->count() - 1; i++)
length += view->sectionSize(i);
- }
length = qMax(length, view->viewport()->height());
QCOMPARE(length, view->length());
@@ -866,9 +852,7 @@ void tst_QHeaderView::length()
QVERIFY(length != view->length());
// layoutChanged might mean rows have been removed
- QtTestModel model;
- model.cols = 10;
- model.rows = 10;
+ QtTestModel model(10, 10);
view->setModel(&model);
int oldLength = view->length();
model.cleanup();
@@ -942,9 +926,9 @@ void tst_QHeaderView::swapSections()
view->swapSections(1, -1);
view->swapSections(1, 99999);
- QVector<int> logical = (QVector<int>() << 0 << 1 << 2 << 3);
+ IntList logical{ 0, 1, 2, 3 };
- QSignalSpy spy1(view, SIGNAL(sectionMoved(int,int,int)));
+ QSignalSpy spy1(view, &QHeaderView::sectionMoved);
QCOMPARE(view->sectionsMoved(), false);
view->swapSections(1, 1);
@@ -957,7 +941,7 @@ void tst_QHeaderView::swapSections()
QCOMPARE(view->logicalIndex(i), logical.at(i));
QCOMPARE(spy1.count(), 4);
- logical = (QVector<int>() << 3 << 1 << 2 << 0);
+ logical = { 3, 1, 2, 0 };
view->swapSections(3, 0);
QCOMPARE(view->sectionsMoved(), true);
for (int j = 0; j < view->count(); ++j)
@@ -967,56 +951,56 @@ void tst_QHeaderView::swapSections()
void tst_QHeaderView::moveSection_data()
{
- QTest::addColumn<QList<int> >("hidden");
- QTest::addColumn<QList<int> >("from");
- QTest::addColumn<QList<int> >("to");
- QTest::addColumn<QList<bool> >("moved");
- QTest::addColumn<QList<int> >("logical");
+ QTest::addColumn<IntList>("hidden");
+ QTest::addColumn<IntList>("from");
+ QTest::addColumn<IntList>("to");
+ QTest::addColumn<BoolList>("moved");
+ QTest::addColumn<IntList>("logical");
QTest::addColumn<int>("count");
QTest::newRow("bad args, no hidden")
- << QList<int>()
- << (QList<int>() << -1 << 1 << 99999 << 1)
- << (QList<int>() << 1 << -1 << 1 << 99999)
- << (QList<bool>() << false << false << false << false)
- << (QList<int>() << 0 << 1 << 2 << 3)
+ << IntList()
+ << (IntList{ -1, 1, 99999, 1 })
+ << (IntList{ 1, -1, 1, 99999 })
+ << (BoolList{ false, false, false, false })
+ << (IntList{ 0, 1, 2, 3 })
<< 0;
QTest::newRow("good args, no hidden")
- << QList<int>()
- << (QList<int>() << 1 << 1 << 2 << 1)
- << (QList<int>() << 1 << 2 << 1 << 2)
- << (QList<bool>() << false << true << true << true)
- << (QList<int>() << 0 << 2 << 1 << 3)
+ << IntList()
+ << (IntList{ 1, 1, 2, 1 })
+ << (IntList{ 1, 2, 1, 2 })
+ << (BoolList{ false, true, true, true })
+ << (IntList{ 0, 2, 1, 3 })
<< 3;
QTest::newRow("hidden sections")
- << (QList<int>() << 0 << 3)
- << (QList<int>() << 1 << 1 << 2 << 1)
- << (QList<int>() << 1 << 2 << 1 << 2)
- << (QList<bool>() << false << true << true << true)
- << (QList<int>() << 0 << 2 << 1 << 3)
+ << (IntList{ 0, 3 })
+ << (IntList{ 1, 1, 2, 1 })
+ << (IntList{ 1, 2, 1, 2 })
+ << (BoolList{ false, true, true, true })
+ << (IntList{ 0, 2, 1, 3 })
<< 3;
}
void tst_QHeaderView::moveSection()
{
- QFETCH(QList<int>, hidden);
- QFETCH(QList<int>, from);
- QFETCH(QList<int>, to);
- QFETCH(QList<bool>, moved);
- QFETCH(QList<int>, logical);
+ QFETCH(const IntList, hidden);
+ QFETCH(const IntList, from);
+ QFETCH(const IntList, to);
+ QFETCH(const BoolList, moved);
+ QFETCH(const IntList, logical);
QFETCH(int, count);
QCOMPARE(from.count(), to.count());
QCOMPARE(from.count(), moved.count());
QCOMPARE(view->count(), logical.count());
- QSignalSpy spy1(view, SIGNAL(sectionMoved(int,int,int)));
+ QSignalSpy spy1(view, &QHeaderView::sectionMoved);
QCOMPARE(view->sectionsMoved(), false);
- for (int h = 0; h < hidden.count(); ++h)
- view->setSectionHidden(hidden.at(h), true);
+ for (int h : hidden)
+ view->setSectionHidden(h, true);
for (int i = 0; i < from.count(); ++i) {
view->moveSection(from.at(i), to.at(i));
@@ -1037,42 +1021,42 @@ void tst_QHeaderView::resizeAndMoveSection_data()
QTest::addColumn<int>("logicalTo");
QTest::newRow("resizeAndMove-1")
- << (IntList() << 0 << 1)
- << (IntList() << 20 << 40)
+ << (IntList{ 0, 1 })
+ << (IntList{ 20, 40 })
<< 0 << 1;
QTest::newRow("resizeAndMove-2")
- << (IntList() << 0 << 1 << 2 << 3)
- << (IntList() << 20 << 60 << 10 << 80)
+ << (IntList{ 0, 1, 2, 3 })
+ << (IntList{ 20, 60, 10, 80 })
<< 0 << 2;
QTest::newRow("resizeAndMove-3")
- << (IntList() << 0 << 1 << 2 << 3)
- << (IntList() << 100 << 60 << 40 << 10)
+ << (IntList{ 0, 1, 2, 3 })
+ << (IntList{ 100, 60, 40, 10 })
<< 0 << 3;
QTest::newRow("resizeAndMove-4")
- << (IntList() << 0 << 1 << 2 << 3)
- << (IntList() << 10 << 40 << 80 << 30)
+ << (IntList{ 0, 1, 2, 3 })
+ << (IntList{ 10, 40, 80, 30 })
<< 1 << 2;
QTest::newRow("resizeAndMove-5")
- << (IntList() << 2 << 3)
- << (IntList() << 100 << 200)
+ << (IntList{ 2, 3 })
+ << (IntList{ 100, 200})
<< 3 << 2;
}
void tst_QHeaderView::resizeAndMoveSection()
{
- QFETCH(IntList, logicalIndexes);
- QFETCH(IntList, sizes);
+ QFETCH(const IntList, logicalIndexes);
+ QFETCH(const IntList, sizes);
QFETCH(int, logicalFrom);
QFETCH(int, logicalTo);
// Save old visual indexes and sizes
IntList oldVisualIndexes;
IntList oldSizes;
- foreach (int logical, logicalIndexes) {
+ for (int logical : logicalIndexes) {
oldVisualIndexes.append(view->visualIndex(logical));
oldSizes.append(view->sectionSize(logical));
}
@@ -1188,31 +1172,32 @@ void tst_QHeaderView::resizeAndInsertSection()
void tst_QHeaderView::resizeWithResizeModes_data()
{
QTest::addColumn<int>("size");
- QTest::addColumn<QList<int> >("sections");
- QTest::addColumn<QList<int> >("modes");
- QTest::addColumn<QList<int> >("expected");
+ QTest::addColumn<IntList>("sections");
+ QTest::addColumn<ResizeVec>("modes");
+ QTest::addColumn<IntList>("expected");
QTest::newRow("stretch first section")
<< 600
- << (QList<int>() << 100 << 100 << 100 << 100)
- << (QList<int>() << ((int)QHeaderView::Stretch)
- << ((int)QHeaderView::Interactive)
- << ((int)QHeaderView::Interactive)
- << ((int)QHeaderView::Interactive))
- << (QList<int>() << 300 << 100 << 100 << 100);
+ << (IntList{ 100, 100, 100, 100 })
+ << (ResizeVec
+ { QHeaderView::Stretch,
+ QHeaderView::Interactive,
+ QHeaderView::Interactive,
+ QHeaderView::Interactive })
+ << (IntList{ 300, 100, 100, 100 });
}
void tst_QHeaderView::resizeWithResizeModes()
{
QFETCH(int, size);
- QFETCH(QList<int>, sections);
- QFETCH(QList<int>, modes);
- QFETCH(QList<int>, expected);
+ QFETCH(const IntList, sections);
+ QFETCH(const ResizeVec, modes);
+ QFETCH(const IntList, expected);
view->setStretchLastSection(false);
for (int i = 0; i < sections.count(); ++i) {
view->resizeSection(i, sections.at(i));
- view->setSectionResizeMode(i, (QHeaderView::ResizeMode)modes.at(i));
+ view->setSectionResizeMode(i, modes.at(i));
}
topLevel->show();
QVERIFY(QTest::qWaitForWindowExposed(topLevel));
@@ -1226,10 +1211,10 @@ void tst_QHeaderView::moveAndInsertSection_data()
QTest::addColumn<int>("from");
QTest::addColumn<int>("to");
QTest::addColumn<int>("insert");
- QTest::addColumn<QList<int> >("mapping");
+ QTest::addColumn<IntList>("mapping");
QTest::newRow("move from 1 to 3, insert 0")
- << 1 << 3 << 0 <<(QList<int>() << 0 << 1 << 3 << 4 << 2);
+ << 1 << 3 << 0 <<(IntList{ 0, 1, 3, 4, 2 });
}
@@ -1238,12 +1223,10 @@ void tst_QHeaderView::moveAndInsertSection()
QFETCH(int, from);
QFETCH(int, to);
QFETCH(int, insert);
- QFETCH(QList<int>, mapping);
+ QFETCH(IntList, mapping);
view->setStretchLastSection(false);
-
view->moveSection(from, to);
-
model->insertRow(insert);
for (int i = 0; i < mapping.count(); ++i)
@@ -1266,12 +1249,12 @@ void tst_QHeaderView::resizeMode()
// test when sections have been moved
view->setStretchLastSection(false);
- for (int i=0; i < (view->count() - 1); ++i)
+ for (int i = 0; i < (view->count() - 1); ++i)
view->setSectionResizeMode(i, QHeaderView::Interactive);
int logicalIndex = view->count() / 2;
view->setSectionResizeMode(logicalIndex, QHeaderView::Stretch);
view->moveSection(view->visualIndex(logicalIndex), 0);
- for (int i=0; i < (view->count() - 1); ++i) {
+ for (int i = 0; i < (view->count() - 1); ++i) {
if (i == logicalIndex)
QCOMPARE(view->sectionResizeMode(i), QHeaderView::Stretch);
else
@@ -1282,34 +1265,33 @@ void tst_QHeaderView::resizeMode()
void tst_QHeaderView::resizeSection_data()
{
QTest::addColumn<int>("initial");
- QTest::addColumn<QList<int> >("logical");
- QTest::addColumn<QList<int> >("size");
- QTest::addColumn<QList<int> >("mode");
+ QTest::addColumn<IntList>("logical");
+ QTest::addColumn<IntList>("size");
+ QTest::addColumn<ResizeVec>("mode");
QTest::addColumn<int>("resized");
- QTest::addColumn<QList<int> >("expected");
+ QTest::addColumn<IntList>("expected");
QTest::newRow("bad args")
<< 100
- << (QList<int>() << -1 << -1 << 99999 << 99999 << 4)
- << (QList<int>() << -1 << 0 << 99999 << -1 << -1)
- << (QList<int>()
- << int(QHeaderView::Interactive)
- << int(QHeaderView::Interactive)
- << int(QHeaderView::Interactive)
- << int(QHeaderView::Interactive))
+ << (IntList{ -1, -1, 99999, 99999, 4 })
+ << (IntList{ -1, 0, 99999, -1, -1 })
+ << (ResizeVec{
+ QHeaderView::Interactive,
+ QHeaderView::Interactive,
+ QHeaderView::Interactive,
+ QHeaderView::Interactive })
<< 0
- << (QList<int>() << 0 << 0 << 0 << 0 << 0);
+ << (IntList{ 0, 0, 0, 0, 0 });
}
void tst_QHeaderView::resizeSection()
{
-
QFETCH(int, initial);
- QFETCH(QList<int>, logical);
- QFETCH(QList<int>, size);
- QFETCH(QList<int>, mode);
+ QFETCH(const IntList, logical);
+ QFETCH(const IntList, size);
+ QFETCH(const ResizeVec, mode);
QFETCH(int, resized);
- QFETCH(QList<int>, expected);
+ QFETCH(const IntList, expected);
view->resize(400, 400);
@@ -1320,12 +1302,12 @@ void tst_QHeaderView::resizeSection()
for (int i = 0; i < logical.count(); ++i)
if (logical.at(i) > -1 && logical.at(i) < view->count()) // for now
- view->setSectionResizeMode(logical.at(i), (QHeaderView::ResizeMode)mode.at(i));
+ view->setSectionResizeMode(logical.at(i), mode.at(i));
for (int j = 0; j < logical.count(); ++j)
view->resizeSection(logical.at(j), initial);
- QSignalSpy spy(view, SIGNAL(sectionResized(int,int,int)));
+ QSignalSpy spy(view, &QHeaderView::sectionResized);
for (int k = 0; k < logical.count(); ++k)
view->resizeSection(logical.at(k), size.at(k));
@@ -1366,9 +1348,7 @@ void tst_QHeaderView::showSortIndicator()
void tst_QHeaderView::sortIndicatorTracking()
{
- QtTestModel model;
- model.rows = model.cols = 10;
-
+ QtTestModel model(10, 10);
QHeaderView hv(Qt::Horizontal);
hv.setModel(&model);
@@ -1399,51 +1379,44 @@ void tst_QHeaderView::removeAndInsertRow()
{
// Check if logicalIndex returns the correct value after we have removed a row
// we might as well te
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
while (model->removeRow(0)) {
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
}
- int pass = 0;
- for (pass = 0; pass < 5; pass++) {
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int pass = 0; pass < 5; pass++) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
model->insertRow(0);
}
while (model->removeRows(0, 2)) {
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
}
- for (pass = 0; pass < 3; pass++) {
+ for (int pass = 0; pass < 3; pass++) {
model->insertRows(0, 2);
for (int i = 0; i < model->rowCount(); ++i) {
QCOMPARE(i, view->logicalIndex(i));
}
}
- for (pass = 0; pass < 3; pass++) {
+ for (int pass = 0; pass < 3; pass++) {
model->insertRows(3, 2);
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
}
// Insert at end
- for (pass = 0; pass < 3; pass++) {
+ for (int pass = 0; pass < 3; pass++) {
int rowCount = model->rowCount();
model->insertRows(rowCount, 1);
- for (int i = 0; i < rowCount; ++i) {
+ for (int i = 0; i < rowCount; ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
}
}
@@ -1490,7 +1463,7 @@ void protected_QHeaderView::testEvent()
void tst_QHeaderView::headerDataChanged()
{
- // This shouldn't asserver because view is Vertical
+ // This shouldn't assert because view is Vertical
view->headerDataChanged(Qt::Horizontal, -1, -1);
#if 0
// This will assert
@@ -1525,19 +1498,18 @@ void tst_QHeaderView::verticalOffset()
void protected_QHeaderView::testhorizontalOffset()
{
- if(orientation() == Qt::Horizontal){
+ if (orientation() == Qt::Horizontal) {
QCOMPARE(horizontalOffset(), 0);
setOffset(10);
QCOMPARE(horizontalOffset(), 10);
}
else
QCOMPARE(horizontalOffset(), 0);
-
}
void protected_QHeaderView::testverticalOffset()
{
- if(orientation() == Qt::Vertical){
+ if (orientation() == Qt::Vertical) {
QCOMPARE(verticalOffset(), 0);
setOffset(10);
QCOMPARE(verticalOffset(), 10);
@@ -1562,7 +1534,7 @@ void tst_QHeaderView::hiddenSectionCount()
model->clear();
model->insertRows(0, 10);
// Hide every other one
- for (int i=0; i<10; i++)
+ for (int i = 0; i < 10; i++)
view->setSectionHidden(i, (i & 1) == 0);
QCOMPARE(view->hiddenSectionCount(), 5);
@@ -1577,7 +1549,7 @@ void tst_QHeaderView::hiddenSectionCount()
model->removeRow(6);
QCOMPARE(view->count(), 6);
QCOMPARE(view->hiddenSectionCount(), 3);
- model->removeRows(0,5);
+ model->removeRows(0, 5);
QCOMPARE(view->count(), 1);
QCOMPARE(view->hiddenSectionCount(), 0);
QVERIFY(view->count() >= view->hiddenSectionCount());
@@ -1610,8 +1582,8 @@ void tst_QHeaderView::focusPolicy()
QTest::keyPress(&widget, Qt::Key_Tab);
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
QVERIFY(!widget.hasFocus());
QVERIFY(!widget.header()->hasFocus());
@@ -1621,47 +1593,37 @@ class SimpleModel : public QAbstractItemModel
{
Q_OBJECT
public:
-
- SimpleModel( QObject* parent=0)
- : QAbstractItemModel(parent),
- m_col_count(3) {}
-
- QModelIndex parent(const QModelIndex &/*child*/) const
+ using QAbstractItemModel::QAbstractItemModel;
+ QModelIndex parent(const QModelIndex &/*child*/) const override
{
return QModelIndex();
}
- QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
{
return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
}
- int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const
+ int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const override
{
return 8;
}
- int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const
+ int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const override
{
return m_col_count;
}
-
- QVariant data(const QModelIndex &index, int role) const
+ QVariant data(const QModelIndex &index, int role) const override
{
if (!index.isValid())
- {
return QVariant();
- }
- if (role == Qt::DisplayRole) {
+ if (role == Qt::DisplayRole)
return QString::number(index.row()) + QLatin1Char(',') + QString::number(index.column());
- }
return QVariant();
}
-
- void setColumnCount( int c )
+ void setColumnCount(int c)
{
m_col_count = c;
}
-
private:
- int m_col_count;
+ int m_col_count = 3;
};
void tst_QHeaderView::moveSectionAndReset()
@@ -1678,9 +1640,8 @@ void tst_QHeaderView::moveSectionAndReset()
v.moveSection(movefrom, moveto);
m.setColumnCount(cc - 1);
v.reset();
- for (int i = 0; i < cc - 1; ++i) {
+ for (int i = 0; i < cc - 1; ++i)
QCOMPARE(v.logicalIndex(v.visualIndex(i)), i);
- }
}
}
}
@@ -1719,7 +1680,7 @@ void tst_QHeaderView::saveRestore()
const QByteArray s1 = savedState();
QHeaderView h2(Qt::Vertical);
- QSignalSpy spy(&h2, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)));
+ QSignalSpy spy(&h2, &QHeaderView::sortIndicatorChanged);
h2.setModel(&m);
QVERIFY(h2.restoreState(s1));
@@ -1745,6 +1706,7 @@ void tst_QHeaderView::saveRestore()
void tst_QHeaderView::restoreQt4State()
{
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// QTBUG-40462
// Setting from Qt4, where information about multiple sections were grouped together in one
// sectionItem object
@@ -1777,6 +1739,9 @@ void tst_QHeaderView::restoreQt4State()
// Check nothing has been actually restored
QCOMPARE(h2.length(), old_length);
QCOMPARE(h2.saveState(), old_state);
+#else
+ QSKIP("Qt4 compatibility no longer needed in Qt6");
+#endif
}
void tst_QHeaderView::restoreToMoreColumns()
@@ -1910,16 +1875,18 @@ void tst_QHeaderView::defaultSectionSizeTest()
class TestHeaderViewStyle : public QProxyStyle
{
+ Q_OBJECT
public:
- TestHeaderViewStyle() : horizontalSectionSize(100) {}
- int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const override
+ using QProxyStyle::QProxyStyle;
+ int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
+ const QWidget *widget = nullptr) const override
{
if (metric == QStyle::PM_HeaderDefaultSectionSizeHorizontal)
return horizontalSectionSize;
else
return QProxyStyle::pixelMetric(metric, option, widget);
}
- int horizontalSectionSize;
+ int horizontalSectionSize = 100;
};
void tst_QHeaderView::defaultSectionSizeTestStyles()
@@ -1946,107 +1913,107 @@ void tst_QHeaderView::defaultSectionSizeTestStyles()
void tst_QHeaderView::defaultAlignment_data()
{
- QTest::addColumn<int>("direction");
- QTest::addColumn<int>("initial");
- QTest::addColumn<int>("alignment");
+ QTest::addColumn<Qt::Orientation>("direction");
+ QTest::addColumn<Qt::Alignment>("initial");
+ QTest::addColumn<Qt::Alignment>("alignment");
QTest::newRow("horizontal right aligned")
- << int(Qt::Horizontal)
- << int(Qt::AlignCenter)
- << int(Qt::AlignRight);
+ << Qt::Horizontal
+ << Qt::Alignment(Qt::AlignCenter)
+ << Qt::Alignment(Qt::AlignRight);
QTest::newRow("horizontal left aligned")
- << int(Qt::Horizontal)
- << int(Qt::AlignCenter)
- << int(Qt::AlignLeft);
+ << Qt::Horizontal
+ << Qt::Alignment(Qt::AlignCenter)
+ << Qt::Alignment(Qt::AlignLeft);
QTest::newRow("vertical right aligned")
- << int(Qt::Vertical)
- << int(Qt::AlignLeft|Qt::AlignVCenter)
- << int(Qt::AlignRight);
+ << Qt::Vertical
+ << Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter)
+ << Qt::Alignment(Qt::AlignRight);
QTest::newRow("vertical left aligned")
- << int(Qt::Vertical)
- << int(Qt::AlignLeft|Qt::AlignVCenter)
- << int(Qt::AlignLeft);
+ << Qt::Vertical
+ << Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter)
+ << Qt::Alignment(Qt::AlignLeft);
}
void tst_QHeaderView::defaultAlignment()
{
- QFETCH(int, direction);
- QFETCH(int, initial);
- QFETCH(int, alignment);
+ QFETCH(Qt::Orientation, direction);
+ QFETCH(Qt::Alignment, initial);
+ QFETCH(Qt::Alignment, alignment);
SimpleModel m;
- QHeaderView header((Qt::Orientation)direction);
+ QHeaderView header(direction);
header.setModel(&m);
- QCOMPARE(header.defaultAlignment(), (Qt::Alignment)initial);
- header.setDefaultAlignment((Qt::Alignment)alignment);
- QCOMPARE(header.defaultAlignment(), (Qt::Alignment)alignment);
+ QCOMPARE(header.defaultAlignment(), initial);
+ header.setDefaultAlignment(alignment);
+ QCOMPARE(header.defaultAlignment(), alignment);
}
void tst_QHeaderView::globalResizeMode_data()
{
- QTest::addColumn<int>("direction");
- QTest::addColumn<int>("mode");
+ QTest::addColumn<Qt::Orientation>("direction");
+ QTest::addColumn<QHeaderView::ResizeMode>("mode");
QTest::addColumn<int>("insert");
QTest::newRow("horizontal ResizeToContents 0")
- << int(Qt::Horizontal)
- << int(QHeaderView::ResizeToContents)
+ << Qt::Horizontal
+ << QHeaderView::ResizeToContents
<< 0;
}
void tst_QHeaderView::globalResizeMode()
{
- QFETCH(int, direction);
- QFETCH(int, mode);
+ QFETCH(Qt::Orientation, direction);
+ QFETCH(QHeaderView::ResizeMode, mode);
QFETCH(int, insert);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
+ QHeaderView h(direction);
h.setModel(&m);
- h.setSectionResizeMode((QHeaderView::ResizeMode)mode);
+ h.setSectionResizeMode(mode);
m.insertRow(insert);
for (int i = 0; i < h.count(); ++i)
- QCOMPARE(h.sectionResizeMode(i), (QHeaderView::ResizeMode)mode);
+ QCOMPARE(h.sectionResizeMode(i), mode);
}
void tst_QHeaderView::sectionPressedSignal_data()
{
- QTest::addColumn<int>("direction");
+ QTest::addColumn<Qt::Orientation>("direction");
QTest::addColumn<bool>("clickable");
QTest::addColumn<int>("count");
QTest::newRow("horizontal unclickable 0")
- << int(Qt::Horizontal)
+ << Qt::Horizontal
<< false
<< 0;
QTest::newRow("horizontal clickable 1")
- << int(Qt::Horizontal)
+ << Qt::Horizontal
<< true
<< 1;
}
void tst_QHeaderView::sectionPressedSignal()
{
- QFETCH(int, direction);
+ QFETCH(Qt::Orientation, direction);
QFETCH(bool, clickable);
QFETCH(int, count);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
+ QHeaderView h(direction);
h.setModel(&m);
h.show();
h.setSectionsClickable(clickable);
- QSignalSpy spy(&h, SIGNAL(sectionPressed(int)));
+ QSignalSpy spy(&h, &QHeaderView::sectionPressed);
QCOMPARE(spy.count(), 0);
QTest::mousePress(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
@@ -2055,20 +2022,20 @@ void tst_QHeaderView::sectionPressedSignal()
void tst_QHeaderView::sectionClickedSignal()
{
- QFETCH(int, direction);
+ QFETCH(Qt::Orientation, direction);
QFETCH(bool, clickable);
QFETCH(int, count);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
+ QHeaderView h(direction);
h.setModel(&m);
h.show();
h.setSectionsClickable(clickable);
h.setSortIndicatorShown(true);
- QSignalSpy spy(&h, SIGNAL(sectionClicked(int)));
- QSignalSpy spy2(&h, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)));
+ QSignalSpy spy(&h, &QHeaderView::sectionClicked);
+ QSignalSpy spy2(&h, &QHeaderView::sortIndicatorChanged);
QCOMPARE(spy.count(), 0);
QCOMPARE(spy2.count(), 0);
@@ -2087,24 +2054,24 @@ void tst_QHeaderView::sectionClickedSignal()
void tst_QHeaderView::defaultSectionSize_data()
{
- QTest::addColumn<int>("direction");
+ QTest::addColumn<Qt::Orientation>("direction");
QTest::addColumn<int>("oldDefaultSize");
QTest::addColumn<int>("newDefaultSize");
//QTest::newRow("horizontal,-5") << int(Qt::Horizontal) << 100 << -5;
- QTest::newRow("horizontal, 0") << int(Qt::Horizontal) << 100 << 0;
- QTest::newRow("horizontal, 5") << int(Qt::Horizontal) << 100 << 5;
- QTest::newRow("horizontal,25") << int(Qt::Horizontal) << 100 << 5;
+ QTest::newRow("horizontal, 0") << Qt::Horizontal << 100 << 0;
+ QTest::newRow("horizontal, 5") << Qt::Horizontal << 100 << 5;
+ QTest::newRow("horizontal,25") << Qt::Horizontal << 100 << 5;
}
void tst_QHeaderView::defaultSectionSize()
{
- QFETCH(int, direction);
+ QFETCH(Qt::Orientation, direction);
QFETCH(int, oldDefaultSize);
QFETCH(int, newDefaultSize);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
+ QHeaderView h(direction);
h.setModel(&m);
h.setMinimumSectionSize(0);
@@ -2119,26 +2086,24 @@ void tst_QHeaderView::defaultSectionSize()
void tst_QHeaderView::hideAndInsert_data()
{
- QTest::addColumn<int>("direction");
+ QTest::addColumn<Qt::Orientation>("direction");
QTest::addColumn<int>("hide");
QTest::addColumn<int>("insert");
QTest::addColumn<int>("hidden");
- QTest::newRow("horizontal, 0, 0") << int(Qt::Horizontal) << 0 << 0 << 1;
+ QTest::newRow("horizontal, 0, 0") << Qt::Horizontal << 0 << 0 << 1;
}
void tst_QHeaderView::hideAndInsert()
{
- QFETCH(int, direction);
+ QFETCH(Qt::Orientation, direction);
QFETCH(int, hide);
QFETCH(int, insert);
QFETCH(int, hidden);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
-
+ QHeaderView h(direction);
h.setModel(&m);
-
h.setSectionHidden(hide, true);
if (direction == Qt::Vertical)
@@ -2147,20 +2112,14 @@ void tst_QHeaderView::hideAndInsert()
m.insertColumn(insert);
for (int i = 0; i < h.count(); ++i)
- if (i != hidden)
- QCOMPARE(h.isSectionHidden(i), false);
- else
- QCOMPARE(h.isSectionHidden(i), true);
+ QCOMPARE(h.isSectionHidden(i), i == hidden);
}
void tst_QHeaderView::removeSection()
{
-//test that removing a hidden section gives the expected result: the next row should be hidden
-//(see task
const int hidden = 3; //section that will be hidden
- const QStringList list = QStringList() << "0" << "1" << "2" << "3" << "4" << "5" << "6";
- QStringListModel model( list );
+ QStringListModel model({ "0", "1", "2", "3", "4", "5", "6" });
QHeaderView view(Qt::Vertical);
view.setModel(&model);
view.hideSection(hidden);
@@ -2169,7 +2128,7 @@ void tst_QHeaderView::removeSection()
view.show();
for(int i = 0; i < view.count(); i++) {
- if (i == (hidden-1)) { //-1 because we removed a row in the meantime
+ if (i == (hidden - 1)) { //-1 because we removed a row in the meantime
QCOMPARE(view.sectionSize(i), 0);
QVERIFY(view.isSectionHidden(i));
} else {
@@ -2181,9 +2140,7 @@ void tst_QHeaderView::removeSection()
void tst_QHeaderView::preserveHiddenSectionWidth()
{
- const QStringList list = QStringList() << "0" << "1" << "2" << "3";
-
- QStringListModel model( list );
+ QStringListModel model({ "0", "1", "2", "3" });
QHeaderView view(Qt::Vertical);
view.setModel(&model);
view.resizeSection(0, 100);
@@ -2249,38 +2206,36 @@ void tst_QHeaderView::emptySectionSpan()
void tst_QHeaderView::task236450_hidden_data()
{
- QTest::addColumn<QList<int> >("hide1");
- QTest::addColumn<QList<int> >("hide2");
+ QTest::addColumn<IntList>("hide1");
+ QTest::addColumn<IntList>("hide2");
- QTest::newRow("set 1") << (QList<int>() << 1 << 3)
- << (QList<int>() << 1 << 5);
+ QTest::newRow("set 1") << (IntList{ 1, 3 })
+ << (IntList{ 1, 5 });
- QTest::newRow("set 2") << (QList<int>() << 2 << 3)
- << (QList<int>() << 1 << 5);
+ QTest::newRow("set 2") << (IntList{ 2, 3 })
+ << (IntList{ 1, 5 });
- QTest::newRow("set 3") << (QList<int>() << 0 << 2 << 4)
- << (QList<int>() << 2 << 3 << 5);
+ QTest::newRow("set 3") << (IntList{ 0, 2, 4 })
+ << (IntList{ 2, 3, 5 });
}
void tst_QHeaderView::task236450_hidden()
{
- QFETCH(QList<int>, hide1);
- QFETCH(QList<int>, hide2);
- const QStringList list = QStringList() << "0" << "1" << "2" << "3" << "4" << "5";
+ QFETCH(const IntList, hide1);
+ QFETCH(const IntList, hide2);
- QStringListModel model( list );
+ QStringListModel model({ "0", "1", "2", "3", "4", "5" });
protected_QHeaderView view(Qt::Vertical);
view.setModel(&model);
view.show();
- foreach (int i, hide1)
+ for (int i : hide1)
view.hideSection(i);
QCOMPARE(view.hiddenSectionCount(), hide1.count());
- for (int i = 0; i < 6; i++) {
+ for (int i = 0; i < 6; i++)
QCOMPARE(!view.isSectionHidden(i), !hide1.contains(i));
- }
view.setDefaultSectionSize(2);
view.scheduleDelayedItemsLayout();
@@ -2293,10 +2248,8 @@ void tst_QHeaderView::task236450_hidden()
}
QCOMPARE(view.hiddenSectionCount(), hide2.count());
- for (int i = 0; i < 6; i++) {
+ for (int i = 0; i < 6; i++)
QCOMPARE(!view.isSectionHidden(i), !hide2.contains(i));
- }
-
}
void tst_QHeaderView::task248050_hideRow()
@@ -2324,7 +2277,7 @@ void tst_QHeaderView::task248050_hideRow()
//returns 0 if everything is fine.
-static int checkHeaderViewOrder(QHeaderView *view, const QVector<int> &expected)
+static int checkHeaderViewOrder(const QHeaderView *view, const IntList &expected)
{
if (view->count() != expected.count())
return 1;
@@ -2341,8 +2294,8 @@ static int checkHeaderViewOrder(QHeaderView *view, const QVector<int> &expected)
void tst_QHeaderView::QTBUG6058_reset()
{
- QStringListModel model1( QStringList() << "0" << "1" << "2" << "3" << "4" << "5" );
- QStringListModel model2( QStringList() << "a" << "b" << "c" );
+ QStringListModel model1({ "0", "1", "2", "3", "4", "5" });
+ QStringListModel model2({ "a", "b", "c" });
QSortFilterProxyModel proxy;
QHeaderView view(Qt::Vertical);
@@ -2352,9 +2305,9 @@ void tst_QHeaderView::QTBUG6058_reset()
QVERIFY(QTest::qWaitForWindowActive(&view));
proxy.setSourceModel(&model1);
- view.swapSections(0,2);
- view.swapSections(1,4);
- QVector<int> expectedOrder{2, 4, 0, 3, 1, 5};
+ view.swapSections(0, 2);
+ view.swapSections(1, 4);
+ IntList expectedOrder{2, 4, 0, 3, 1, 5};
QTRY_COMPARE(checkHeaderViewOrder(&view, expectedOrder) , 0);
proxy.setSourceModel(&model2);
@@ -2376,11 +2329,11 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
QList<QStandardItem *> row;
- for (int i = 0; i < 12; i++)
+ for (char i = 0; i < 12; i++)
row.append(new QStandardItem(QString(QLatin1Char('A' + i))));
sim->appendRow(row);
row.clear();
- for (int i = 12; i > 0; i--)
+ for (char i = 12; i > 0; i--)
row.append(new QStandardItem(QString(QLatin1Char('A' + i))));
sim->appendRow(row);
@@ -2410,19 +2363,21 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
QCOMPARE(tv.horizontalHeader()->sectionSize(5), section5Size);
tv.setColumnHidden(5, true);
- QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int)));
- QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int)));
+ QSignalSpy clickedSpy(tv.horizontalHeader(), &QHeaderView::sectionClicked);
+ QSignalSpy pressedSpy(tv.horizontalHeader(), &QHeaderView::sectionPressed);
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
- QPoint(tv.horizontalHeader()->sectionViewportPosition(11) + tv.horizontalHeader()->sectionSize(11)/2, 5));
+ QPoint(tv.horizontalHeader()->sectionViewportPosition(11) +
+ tv.horizontalHeader()->sectionSize(11) / 2, 5));
QCOMPARE(clickedSpy.count(), 1);
QCOMPARE(pressedSpy.count(), 1);
QCOMPARE(clickedSpy.at(0).at(0).toInt(), 11);
QCOMPARE(pressedSpy.at(0).at(0).toInt(), 11);
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
- QPoint(tv.horizontalHeader()->sectionViewportPosition(8) + tv.horizontalHeader()->sectionSize(0)/2, 5));
+ QPoint(tv.horizontalHeader()->sectionViewportPosition(8) +
+ tv.horizontalHeader()->sectionSize(0) / 2, 5));
QCOMPARE(clickedSpy.count(), 2);
QCOMPARE(pressedSpy.count(), 2);
@@ -2430,7 +2385,8 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
QCOMPARE(pressedSpy.at(1).at(0).toInt(), 8);
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
- QPoint(tv.horizontalHeader()->sectionViewportPosition(0) + tv.horizontalHeader()->sectionSize(0)/2, 5));
+ QPoint(tv.horizontalHeader()->sectionViewportPosition(0) +
+ tv.horizontalHeader()->sectionSize(0) / 2, 5));
QCOMPARE(clickedSpy.count(), 3);
QCOMPARE(pressedSpy.count(), 3);
@@ -2440,8 +2396,7 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
void tst_QHeaderView::checkLayoutChangeEmptyModel()
{
- QtTestModel tm;
- tm.cols = 11;
+ QtTestModel tm(0, 11);
QTableView tv;
tv.verticalHeader()->setStretchLastSection(true);
tv.setModel(&tm);
@@ -2488,14 +2443,12 @@ void tst_QHeaderView::QTBUG8650_crashOnInsertSections()
{
QStringList headerLabels;
QHeaderView view(Qt::Horizontal);
- QStandardItemModel model(2,2);
+ QStandardItemModel model(2, 2);
view.setModel(&model);
view.moveSection(1, 0);
view.hideSection(0);
- QList<QStandardItem *> items;
- items << new QStandardItem("c");
- model.insertColumn(0, items);
+ model.insertColumn(0, { new QStandardItem("c") });
}
static void setModelTexts(QStandardItemModel *model)
@@ -2511,9 +2464,9 @@ static void setModelTexts(QStandardItemModel *model)
void tst_QHeaderView::QTBUG12268_hiddenMovedSectionSorting()
{
QTableView view; // ### this test fails on QTableView &view = *m_tableview; !? + shadowing view member
- QStandardItemModel *model = new QStandardItemModel(4,3, &view);
- setModelTexts(model);
- view.setModel(model);
+ QStandardItemModel model(4, 3);
+ setModelTexts(&model);
+ view.setModel(&model);
view.horizontalHeader()->setSectionsMovable(true);
view.setSortingEnabled(true);
view.sortByColumn(1, Qt::AscendingOrder);
@@ -2549,9 +2502,7 @@ void tst_QHeaderView::QTBUG14242_hideSectionAutoSize()
void tst_QHeaderView::QTBUG50171_visualRegionForSwappedItems()
{
protected_QHeaderView headerView(Qt::Horizontal);
- QtTestModel model;
- model.rows = 2;
- model.cols = 3;
+ QtTestModel model(2, 3);
headerView.setModel(&model);
headerView.swapSections(1, 2);
headerView.hideSection(0);
@@ -2560,17 +2511,17 @@ void tst_QHeaderView::QTBUG50171_visualRegionForSwappedItems()
class QTBUG53221_Model : public QAbstractItemModel
{
+ Q_OBJECT
public:
void insertRowAtBeginning()
{
Q_EMIT layoutAboutToBeChanged();
m_displayNames.insert(0, QStringLiteral("Item %1").arg(m_displayNames.count()));
// Rows are always inserted at the beginning, so move all others.
- foreach (const QModelIndex &persIndex, persistentIndexList())
- {
- // The vertical header view will have a persistent index stored here on the second call to insertRowAtBeginning.
+ const auto pl = persistentIndexList();
+ // The vertical header view will have a persistent index stored here on the second call to insertRowAtBeginning.
+ for (const QModelIndex &persIndex : pl)
changePersistentIndex(persIndex, index(persIndex.row() + 1, persIndex.column(), persIndex.parent()));
- }
Q_EMIT layoutChanged();
}
@@ -2653,15 +2604,15 @@ void tst_QHeaderView::offsetConsistent()
void tst_QHeaderView::initialSortOrderRole()
{
QTableView view; // ### Shadowing member view (of type QHeaderView)
- QStandardItemModel *model = new QStandardItemModel(4, 3, &view);
- setModelTexts(model);
+ QStandardItemModel model(4, 3);
+ setModelTexts(&model);
QStandardItem *ascendingItem = new QStandardItem();
QStandardItem *descendingItem = new QStandardItem();
ascendingItem->setData(Qt::AscendingOrder, Qt::InitialSortOrderRole);
descendingItem->setData(Qt::DescendingOrder, Qt::InitialSortOrderRole);
- model->setHorizontalHeaderItem(1, ascendingItem);
- model->setHorizontalHeaderItem(2, descendingItem);
- view.setModel(model);
+ model.setHorizontalHeaderItem(1, ascendingItem);
+ model.setHorizontalHeaderItem(2, descendingItem);
+ view.setModel(&model);
view.setSortingEnabled(true);
view.sortByColumn(0, Qt::AscendingOrder);
view.show();
@@ -2687,7 +2638,7 @@ const bool block_some_signals = true; // The test should also work with this set
const int rowcount = 500;
const int colcount = 10;
-QString istr(int n, bool comma = true)
+static inline QString istr(int n, bool comma = true)
{
QString s;
s.setNum(n);
@@ -3433,9 +3384,7 @@ void tst_QHeaderView::testMinMaxSectionSize()
void tst_QHeaderView::testResetCachedSizeHint()
{
- QtTestModel model;
- model.rows = model.cols = 10;
-
+ QtTestModel model(10, 10);
QTableView tv;
tv.setModel(&model);
tv.show();
@@ -3453,13 +3402,13 @@ void tst_QHeaderView::testResetCachedSizeHint()
class StatusTipHeaderView : public QHeaderView
{
+ Q_OBJECT
public:
- StatusTipHeaderView(Qt::Orientation orientation = Qt::Horizontal, QWidget *parent = 0) :
- QHeaderView(orientation, parent), gotStatusTipEvent(false) {}
- bool gotStatusTipEvent;
+ using QHeaderView::QHeaderView;
QString statusTipText;
+ bool gotStatusTipEvent = false;
protected:
- bool event(QEvent *e)
+ bool event(QEvent *e) override
{
if (e->type() == QEvent::StatusTip) {
gotStatusTipEvent = true;
@@ -3471,15 +3420,14 @@ protected:
void tst_QHeaderView::statusTips()
{
- StatusTipHeaderView headerView;
- QtTestModel model;
- model.rows = model.cols = 5;
+ StatusTipHeaderView headerView(Qt::Horizontal);
+ QtTestModel model(5, 5);
headerView.setModel(&model);
headerView.viewport()->setMouseTracking(true);
headerView.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),
QSize(500, 500)));
headerView.show();
- qApp->setActiveWindow(&headerView);
+ QApplication::setActiveWindow(&headerView);
QVERIFY(QTest::qWaitForWindowActive(&headerView));
// Ensure it is moved away first and then moved to the relevant section
@@ -3504,8 +3452,7 @@ void tst_QHeaderView::testRemovingColumnsViaLayoutChanged()
{
const int persistentSectionSize = 101;
- QtTestModel model;
- model.rows = model.cols = 5;
+ QtTestModel model(5, 5);
view->setModel(&model);
for (int i = 0; i < model.cols; ++i)
view->resizeSection(i, persistentSectionSize + i);
diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
index 071665a5e3..10beacbe75 100644
--- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
+++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
@@ -26,9 +26,10 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QtCore/QtCore>
+#include <QRandomGenerator>
+#include <QStack>
+#include <QStandardItemModel>
+#include <QTest>
#include "viewstotest.cpp"
/*!
@@ -89,17 +90,19 @@ class CheckerModel : public QStandardItemModel
Q_OBJECT
public:
- CheckerModel() : QStandardItemModel() {};
+ using QStandardItemModel::QStandardItemModel;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const {
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
+ {
if (!index.isValid()) {
qWarning("%s: index is not valid", Q_FUNC_INFO);
return QVariant();
}
return QStandardItemModel::data(index, role);
- };
+ }
- Qt::ItemFlags flags(const QModelIndex & index) const {
+ Qt::ItemFlags flags(const QModelIndex &index) const override
+ {
if (!index.isValid()) {
qWarning("%s: index is not valid", Q_FUNC_INFO);
return Qt::ItemFlags();
@@ -107,21 +110,24 @@ public:
if (index.row() == 2 || index.row() == rowCount() - 3
|| index.column() == 2 || index.column() == columnCount() - 3) {
Qt::ItemFlags f = QStandardItemModel::flags(index);
- f &= ~Qt::ItemIsEnabled;
+ f.setFlag(Qt::ItemIsEnabled, false);
return f;
}
return QStandardItemModel::flags(index);
- };
+ }
- QModelIndex parent ( const QModelIndex & child ) const {
+ QModelIndex parent(const QModelIndex &child) const override
+ {
if (!child.isValid()) {
qWarning("%s: child index is not valid", Q_FUNC_INFO);
return QModelIndex();
}
return QStandardItemModel::parent(child);
- };
+ }
- QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const {
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const override
+ {
if (orientation == Qt::Horizontal
&& (section < 0 || section > columnCount())) {
qWarning("%s: invalid section %d, must be in range 0..%d",
@@ -137,11 +143,9 @@ public:
return QStandardItemModel::headerData(section, orientation, role);
}
- QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const {
- return QStandardItemModel::index(row, column, parent);
- };
-
- bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) {
+ bool setData(const QModelIndex &index, const QVariant &value,
+ int role = Qt::EditRole) override
+ {
if (!index.isValid()) {
qWarning("%s: index is not valid", Q_FUNC_INFO);
return false;
@@ -149,15 +153,19 @@ public:
return QStandardItemModel::setData(index, value, role);
}
- void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) {
+ void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override
+ {
if (column < 0 || column > columnCount())
qWarning("%s: invalid column %d, must be in range 0..%d",
Q_FUNC_INFO, column, columnCount());
else
QStandardItemModel::sort(column, order);
- };
+ }
- QModelIndexList match ( const QModelIndex & start, int role, const QVariant & value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags( Qt::MatchStartsWith | Qt::MatchWrap ) ) const {
+ QModelIndexList match(const QModelIndex &start, int role,
+ const QVariant &value, int hits = 1,
+ Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override
+ {
if (hits <= 0) {
qWarning("%s: hits must be greater than zero", Q_FUNC_INFO);
return QModelIndexList();
@@ -167,9 +175,11 @@ public:
return QModelIndexList();
}
return QAbstractItemModel::match(start, role, value, hits, flags);
- };
+ }
- bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole ) {
+ bool setHeaderData(int section, Qt::Orientation orientation,
+ const QVariant &value, int role = Qt::EditRole) override
+ {
if (orientation == Qt::Horizontal
&& (section < 0 || section > columnCount())) {
qWarning("%s: invalid section %d, must be in range 0..%d",
@@ -183,7 +193,7 @@ public:
return false;
}
return QAbstractItemModel::setHeaderData(section, orientation, value, role);
- };
+ }
};
void tst_QItemView::init()
@@ -197,9 +207,9 @@ void tst_QItemView::cleanup()
delete testViews;
delete view;
delete treeModel;
- view = 0;
- testViews = 0;
- treeModel = 0;
+ view = nullptr;
+ testViews = nullptr;
+ treeModel = nullptr;
}
void tst_QItemView::setupWithNoTestData()
@@ -207,15 +217,15 @@ void tst_QItemView::setupWithNoTestData()
ViewsToTest testViews;
QTest::addColumn<QString>("viewType");
QTest::addColumn<bool>("displays");
- QTest::addColumn<int>("vscroll");
- QTest::addColumn<int>("hscroll");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("vscroll");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("hscroll");
for (int i = 0; i < testViews.tests.size(); ++i) {
QString view = testViews.tests.at(i).viewType;
QString test = view + " ScrollPerPixel";
bool displayIndexes = (testViews.tests.at(i).display == ViewsToTest::DisplayRoot);
QTest::newRow(test.toLatin1().data()) << view << displayIndexes
- << (int)QAbstractItemView::ScrollPerPixel
- << (int)QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
;
}
for (int i = 0; i < testViews.tests.size(); ++i) {
@@ -223,8 +233,8 @@ void tst_QItemView::setupWithNoTestData()
QString test = view + " ScrollPerItem";
bool displayIndexes = (testViews.tests.at(i).display == ViewsToTest::DisplayRoot);
QTest::newRow(test.toLatin1().data()) << view << displayIndexes
- << (int)QAbstractItemView::ScrollPerItem
- << (int)QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
;
}
}
@@ -267,13 +277,13 @@ void tst_QItemView::nonDestructiveBasicTest_data()
void tst_QItemView::nonDestructiveBasicTest()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
// setSelectionModel() will assert
//view->setSelectionModel(0);
@@ -396,7 +406,8 @@ void tst_QItemView::spider_data()
setupWithNoTestData();
}
-void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress){
+void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress)
+{
int width = widget->width();
int height = widget->height();
for (int i = 0; i < 5; ++i) {
@@ -409,7 +420,7 @@ void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress){
QTest::mousePress(widget, Qt::LeftButton, modifier, press);
QTest::mouseMove(widget, releasePoint);
if (QRandomGenerator::global()->bounded(1) == 0)
- QTest::mouseRelease(widget, Qt::LeftButton, 0, releasePoint);
+ QTest::mouseRelease(widget, Qt::LeftButton, {}, releasePoint);
else
QTest::mouseRelease(widget, Qt::LeftButton, modifier, releasePoint);
QTest::keyClick(widget, keyPress);
@@ -425,13 +436,13 @@ void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress){
void tst_QItemView::spider()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
view->setModel(treeModel);
view->show();
QVERIFY(QTest::qWaitForWindowActive(view));
@@ -454,21 +465,21 @@ void tst_QItemView::resize()
QSKIP("This test needs to be re-thought out, it takes too long and doesn't really catch the problem.");
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
view->setModel(treeModel);
view->show();
- for (int w = 100; w < 400; w+=10) {
- for (int h = 100; h < 400; h+=10) {
+ for (int w = 100; w < 400; w += 10) {
+ for (int h = 100; h < 400; h += 10) {
view->resize(w, h);
QTest::qWait(1);
- qApp->processEvents();
+ QCoreApplication::processEvents();
}
}
}
@@ -481,13 +492,13 @@ void tst_QItemView::visualRect_data()
void tst_QItemView::visualRect()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
QCOMPARE(view->visualRect(QModelIndex()), QRect());
// Add model
@@ -617,13 +628,13 @@ void tst_QItemView::indexAt_data()
void tst_QItemView::indexAt()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
view->show();
view->setModel(treeModel);
checkChildren(view);
@@ -648,13 +659,13 @@ void tst_QItemView::scrollTo_data()
void tst_QItemView::scrollTo()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
view->setModel(treeModel);
view->show();
@@ -682,10 +693,10 @@ void tst_QItemView::moveCursor_data()
setupWithNoTestData();
}
-class Event {
-public:
- Event(){}
- Event(Qt::Key k, QModelIndex s, QModelIndex e, QString n) : key(k), start(s), end(e), name(n){}
+struct Event
+{
+ Event(Qt::Key k, const QModelIndex &s, const QModelIndex &e, const QString &n)
+ : key(k), start(s), end(e), name(n){}
Qt::Key key;
QModelIndex start;
QModelIndex end;
diff --git a/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp b/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp
index f1da2f4fe7..c55cc865fc 100644
--- a/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp
+++ b/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp
@@ -26,11 +26,10 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QtCore/QtCore>
-#include <QtGui/QtGui>
-#include <QtWidgets/QtWidgets>
+#include <QHeaderView>
+#include <QListView>
+#include <QTableView>
+#include <QTreeView>
/*
To add a view to be tested add the header file to the includes
@@ -54,12 +53,12 @@ public:
enum Display { DisplayNone, DisplayRoot };
struct test {
- test(QString m, Display d) : viewType(m), display(d){};
+ test(const QString &m, Display d) : viewType(m), display(d) {}
QString viewType;
Display display;
};
- QList<test> tests;
+ QVector<test> tests;
};
@@ -84,7 +83,7 @@ ViewsToTest::ViewsToTest()
*/
QAbstractItemView *ViewsToTest::createView(const QString &viewType)
{
- QAbstractItemView *view = 0;
+ QAbstractItemView *view = nullptr;
if (viewType == "QListView_ScrollPerItem") {
view = new QListView();
view->setObjectName("QListView");
@@ -137,16 +136,16 @@ void ViewsToTest::hideIndexes(QAbstractItemView *view)
if (QTableView *tableView = qobject_cast<QTableView *>(view)) {
tableView->setColumnHidden(1, true);
tableView->setRowHidden(1, true);
- tableView->setRowHidden(tableView->model()->rowCount()-2, true);
+ tableView->setRowHidden(tableView->model()->rowCount() - 2, true);
}
if (QTreeView *treeView = qobject_cast<QTreeView *>(view)) {
treeView->setColumnHidden(1, true);
treeView->setRowHidden(1, QModelIndex(), true);
- treeView->setRowHidden(treeView->model()->rowCount()-2, QModelIndex(), true);
+ treeView->setRowHidden(treeView->model()->rowCount() - 2, QModelIndex(), true);
}
if (QListView *listView = qobject_cast<QListView *>(view)) {
listView->setRowHidden(1, true);
- listView->setRowHidden(listView->model()->rowCount()-2, true);
+ listView->setRowHidden(listView->model()->rowCount() - 2, true);
}
}
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index 3a60b3b7c6..aef2d26137 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -27,32 +27,27 @@
****************************************************************************/
-#include <QtTest/QtTest>
-
-#include <qabstractitemmodel.h>
-#include <qapplication.h>
-#include <qlistview.h>
-#include <private/qlistview_p.h>
-#include <private/qcoreapplication_p.h>
-#include <qlistwidget.h>
-#include <qitemdelegate.h>
-#include <qstandarditemmodel.h>
-#include <qstringlistmodel.h>
-#include <cmath>
-#include <math.h>
-#include <QtWidgets/QScrollBar>
-#include <QtWidgets/QDialog>
-#include <QtWidgets/QStyledItemDelegate>
-#include <QtWidgets/QStyleFactory>
-#include <QtWidgets/QVBoxLayout>
+#include <QListWidget>
+#include <QScrollBar>
+#include <QSignalSpy>
+#include <QStandardItemModel>
+#include <QStringListModel>
+#include <QStyledItemDelegate>
+#include <QStyleFactory>
+#include <QTest>
+#include <QTimer>
+#include <QtMath>
#include <QtTest/private/qtesthelpers_p.h>
+#include <QtWidgets/private/qlistview_p.h>
using namespace QTestPrivate;
#if defined(Q_OS_WIN)
# include <windows.h>
-# include <QtGui/QGuiApplication>
+# include <QDialog>
+# include <QGuiApplication>
+# include <QVBoxLayout>
#include <qpa/qplatformnativeinterface.h>
#endif // Q_OS_WIN
@@ -67,6 +62,7 @@ static inline HWND getHWNDForWidget(const QWidget *widget)
Q_DECLARE_METATYPE(QAbstractItemView::ScrollMode)
Q_DECLARE_METATYPE(QMargins)
Q_DECLARE_METATYPE(QSize)
+using IntList = QVector<int>;
static QStringList generateList(const QString &prefix, int size)
{
@@ -77,6 +73,26 @@ static QStringList generateList(const QString &prefix, int size)
return result;
}
+class PublicListView : public QListView
+{
+public:
+ using QListView::QListView;
+ using QListView::contentsSize;
+ using QListView::moveCursor;
+ using QListView::selectedIndexes;
+ using QListView::setPositionForIndex;
+ using QListView::setSelection;
+ using QListView::setViewportMargins;
+ using QListView::startDrag;
+ using QListView::viewOptions;
+ QRegion getVisualRegionForSelection() const
+ {
+ return QListView::visualRegionForSelection(selectionModel()->selection());
+ }
+
+ friend class tst_QListView;
+};
+
class tst_QListView : public QObject
{
Q_OBJECT
@@ -160,57 +176,57 @@ void tst_QListView::getSetCheck()
QListView obj1;
// Movement QListView::movement()
// void QListView::setMovement(Movement)
- obj1.setMovement(QListView::Movement(QListView::Static));
- QCOMPARE(QListView::Movement(QListView::Static), obj1.movement());
- obj1.setMovement(QListView::Movement(QListView::Free));
- QCOMPARE(QListView::Movement(QListView::Free), obj1.movement());
- obj1.setMovement(QListView::Movement(QListView::Snap));
- QCOMPARE(QListView::Movement(QListView::Snap), obj1.movement());
+ obj1.setMovement(QListView::Static);
+ QCOMPARE(QListView::Static, obj1.movement());
+ obj1.setMovement(QListView::Free);
+ QCOMPARE(QListView::Free, obj1.movement());
+ obj1.setMovement(QListView::Snap);
+ QCOMPARE(QListView::Snap, obj1.movement());
// Flow QListView::flow()
// void QListView::setFlow(Flow)
- obj1.setFlow(QListView::Flow(QListView::LeftToRight));
- QCOMPARE(QListView::Flow(QListView::LeftToRight), obj1.flow());
- obj1.setFlow(QListView::Flow(QListView::TopToBottom));
- QCOMPARE(QListView::Flow(QListView::TopToBottom), obj1.flow());
+ obj1.setFlow(QListView::LeftToRight);
+ QCOMPARE(QListView::LeftToRight, obj1.flow());
+ obj1.setFlow(QListView::TopToBottom);
+ QCOMPARE(QListView::TopToBottom, obj1.flow());
// ResizeMode QListView::resizeMode()
// void QListView::setResizeMode(ResizeMode)
- obj1.setResizeMode(QListView::ResizeMode(QListView::Fixed));
- QCOMPARE(QListView::ResizeMode(QListView::Fixed), obj1.resizeMode());
- obj1.setResizeMode(QListView::ResizeMode(QListView::Adjust));
- QCOMPARE(QListView::ResizeMode(QListView::Adjust), obj1.resizeMode());
+ obj1.setResizeMode(QListView::Fixed);
+ QCOMPARE(QListView::Fixed, obj1.resizeMode());
+ obj1.setResizeMode(QListView::Adjust);
+ QCOMPARE(QListView::Adjust, obj1.resizeMode());
// LayoutMode QListView::layoutMode()
// void QListView::setLayoutMode(LayoutMode)
- obj1.setLayoutMode(QListView::LayoutMode(QListView::SinglePass));
- QCOMPARE(QListView::LayoutMode(QListView::SinglePass), obj1.layoutMode());
- obj1.setLayoutMode(QListView::LayoutMode(QListView::Batched));
- QCOMPARE(QListView::LayoutMode(QListView::Batched), obj1.layoutMode());
+ obj1.setLayoutMode(QListView::SinglePass);
+ QCOMPARE(QListView::SinglePass, obj1.layoutMode());
+ obj1.setLayoutMode(QListView::Batched);
+ QCOMPARE(QListView::Batched, obj1.layoutMode());
// int QListView::spacing()
// void QListView::setSpacing(int)
obj1.setSpacing(0);
QCOMPARE(0, obj1.spacing());
- obj1.setSpacing(INT_MIN);
- QCOMPARE(INT_MIN, obj1.spacing());
- obj1.setSpacing(INT_MAX);
- QCOMPARE(INT_MAX, obj1.spacing());
+ obj1.setSpacing(std::numeric_limits<int>::min());
+ QCOMPARE(std::numeric_limits<int>::min(), obj1.spacing());
+ obj1.setSpacing(std::numeric_limits<int>::max());
+ QCOMPARE(std::numeric_limits<int>::max(), obj1.spacing());
// ViewMode QListView::viewMode()
// void QListView::setViewMode(ViewMode)
- obj1.setViewMode(QListView::ViewMode(QListView::ListMode));
- QCOMPARE(QListView::ViewMode(QListView::ListMode), obj1.viewMode());
- obj1.setViewMode(QListView::ViewMode(QListView::IconMode));
- QCOMPARE(QListView::ViewMode(QListView::IconMode), obj1.viewMode());
+ obj1.setViewMode(QListView::ListMode);
+ QCOMPARE(QListView::ListMode, obj1.viewMode());
+ obj1.setViewMode(QListView::IconMode);
+ QCOMPARE(QListView::IconMode, obj1.viewMode());
// int QListView::modelColumn()
// void QListView::setModelColumn(int)
obj1.setModelColumn(0);
QCOMPARE(0, obj1.modelColumn());
- obj1.setModelColumn(INT_MIN);
+ obj1.setModelColumn(std::numeric_limits<int>::min());
QCOMPARE(0, obj1.modelColumn()); // Less than 0 => 0
- obj1.setModelColumn(INT_MAX);
+ obj1.setModelColumn(std::numeric_limits<int>::max());
QCOMPARE(0, obj1.modelColumn()); // No model => 0
// bool QListView::uniformItemSizes()
@@ -234,23 +250,21 @@ void tst_QListView::getSetCheck()
class QtTestModel: public QAbstractListModel
{
+ Q_OBJECT
public:
- QtTestModel(QObject *parent = 0): QAbstractListModel(parent),
- colCount(0), rCount(0), wrongIndex(false) {}
- int rowCount(const QModelIndex&) const { return rCount; }
- int columnCount(const QModelIndex&) const { return colCount; }
- bool isEditable(const QModelIndex &) const { return true; }
+ QtTestModel(int rc, int cc, QObject *parent = nullptr)
+ : QAbstractListModel(parent), rCount(rc), cCount(cc) {}
+ int rowCount(const QModelIndex &) const override { return rCount; }
+ int columnCount(const QModelIndex &) const override { return cCount; }
- QVariant data(const QModelIndex &idx, int role) const
+ QVariant data(const QModelIndex &idx, int role) const override
{
-
- if (!m_icon.isNull() && role == Qt::DecorationRole) {
+ if (!m_icon.isNull() && role == Qt::DecorationRole)
return m_icon;
- }
if (role != Qt::DisplayRole)
return QVariant();
- if (idx.row() < 0 || idx.column() < 0 || idx.column() >= colCount
+ if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cCount
|| idx.row() >= rCount) {
wrongIndex = true;
qWarning("got invalid modelIndex %d/%d", idx.row(), idx.column());
@@ -277,13 +291,14 @@ public:
m_icon = icon;
}
- int colCount, rCount;
QIcon m_icon;
- mutable bool wrongIndex;
+ int rCount, cCount;
+ mutable bool wrongIndex = false;
};
class ScrollPerItemListView : public QListView
{
+ Q_OBJECT
public:
explicit ScrollPerItemListView(QWidget *parent = nullptr)
: QListView(parent)
@@ -301,12 +316,12 @@ void tst_QListView::cleanup()
void tst_QListView::noDelegate()
{
- QtTestModel model(0);
- model.rCount = model.colCount = 10;
+ QtTestModel model(10, 10);
QListView view;
view.setModel(&model);
- view.setItemDelegate(0);
+ view.setItemDelegate(nullptr);
view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
}
void tst_QListView::noModel()
@@ -314,11 +329,13 @@ void tst_QListView::noModel()
QListView view;
view.show();
view.setRowHidden(0, true);
+ // no model -> not able to hide a row
+ QVERIFY(!view.isRowHidden(0));
}
void tst_QListView::emptyModel()
{
- QtTestModel model(0);
+ QtTestModel model(0, 0);
QListView view;
view.setModel(&model);
view.show();
@@ -327,9 +344,7 @@ void tst_QListView::emptyModel()
void tst_QListView::removeRows()
{
- QtTestModel model(0);
- model.rCount = model.colCount = 10;
-
+ QtTestModel model(10, 10);
QListView view;
view.setModel(&model);
view.show();
@@ -358,8 +373,7 @@ void tst_QListView::cursorMove()
QModelIndex index = model.index(i, j);
model.setData(index, QLatin1Char('[') + QString::number(i) + postfix);
view.setCurrentIndex(index);
- QApplication::processEvents();
- QCOMPARE(view.currentIndex(), index);
+ QTRY_COMPARE(view.currentIndex(), index);
}
}
@@ -375,11 +389,12 @@ void tst_QListView::cursorMove()
view.doItemsLayout();
topLevel.show();
- QVector<Qt::Key> keymoves;
- keymoves << Qt::Key_Up << Qt::Key_Up << Qt::Key_Right << Qt::Key_Right << Qt::Key_Up
- << Qt::Key_Left << Qt::Key_Left << Qt::Key_Up << Qt::Key_Down << Qt::Key_Up
- << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up
- << Qt::Key_Left << Qt::Key_Left << Qt::Key_Up << Qt::Key_Down;
+ static const Qt::Key keymoves[] {
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Right, Qt::Key_Right, Qt::Key_Up,
+ Qt::Key_Left, Qt::Key_Left, Qt::Key_Up, Qt::Key_Down, Qt::Key_Up,
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Up,
+ Qt::Key_Left, Qt::Key_Left, Qt::Key_Up, Qt::Key_Down
+ };
int lastRow = rows / displayColumns - 1;
int lastColumn = displayColumns - 1;
@@ -387,9 +402,8 @@ void tst_QListView::cursorMove()
int displayRow = lastRow;
int displayColumn = lastColumn - (rows % displayColumns);
- QApplication::instance()->processEvents();
- for (int i = 0; i < keymoves.size(); ++i) {
- Qt::Key key = keymoves.at(i);
+ QCoreApplication::processEvents();
+ for (Qt::Key key : keymoves) {
QTest::keyClick(&view, key);
switch (key) {
case Qt::Key_Up:
@@ -422,7 +436,7 @@ void tst_QListView::cursorMove()
QVERIFY(false);
}
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
int row = displayRow * displayColumns + displayColumn;
int column = columns - 1;
@@ -435,9 +449,7 @@ void tst_QListView::cursorMove()
void tst_QListView::hideRows()
{
- QtTestModel model(0);
- model.rCount = model.colCount = 10;
-
+ QtTestModel model(10, 10);
QListView view;
view.setModel(&model);
view.show();
@@ -471,9 +483,9 @@ void tst_QListView::hideRows()
view.setRowHidden(0, false);
QVERIFY(!view.isRowHidden(0));
- QStandardItemModel sim(0);
+ QStandardItemModel sim;
QStandardItem *root = new QStandardItem("Root row");
- for (int i=0;i<5;i++)
+ for (int i = 0;i < 5; i++)
root->appendRow(new QStandardItem(QLatin1String("Row ") + QString::number(i)));
sim.appendRow(root);
view.setModel(&sim);
@@ -488,15 +500,13 @@ void tst_QListView::hideRows()
void tst_QListView::moveCursor()
{
- QtTestModel model(0);
- model.rCount = model.colCount = 10;
-
+ QtTestModel model(10, 10);
QListView view;
view.setModel(&model);
QTest::keyClick(&view, Qt::Key_Down);
- view.setModel(0);
+ view.setModel(nullptr);
view.setModel(&model);
view.setRowHidden(0, true);
@@ -504,38 +514,20 @@ void tst_QListView::moveCursor()
QCOMPARE(view.selectionModel()->currentIndex(), model.index(1, 0));
}
-class QMoveCursorListView : public QListView
-{
-public:
- QMoveCursorListView() : QListView() {}
-
- // enum CursorAction and moveCursor() are protected in QListView.
- enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight,
- MoveHome, MoveEnd, MovePageUp, MovePageDown,
- MoveNext, MovePrevious };
-
- QModelIndex doMoveCursor(QMoveCursorListView::CursorAction action, Qt::KeyboardModifiers modifiers)
- {
- return QListView::moveCursor((QListView::CursorAction)action, modifiers);
- }
-};
-
void tst_QListView::moveCursor2()
{
- QtTestModel model(0);
- model.colCount = 1;
- model.rCount = 100;
+ QtTestModel model(100, 1);
QPixmap pm(32, 32);
pm.fill(Qt::green);
model.setDataIcon(QIcon(pm));
- QMoveCursorListView vu;
+ PublicListView vu;
vu.setModel(&model);
vu.setIconSize(QSize(36,48));
vu.setGridSize(QSize(34,56));
//Standard framesize is 1. If Framesize > 2 increase size
int frameSize = qApp->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
- vu.resize(300 + frameSize * 2,300);
+ vu.resize(300 + frameSize * 2, 300);
vu.setFlow(QListView::LeftToRight);
vu.setMovement(QListView::Static);
vu.setWrapping(true);
@@ -545,10 +537,10 @@ void tst_QListView::moveCursor2()
vu.selectionModel()->setCurrentIndex(model.index(0,0), QItemSelectionModel::SelectCurrent);
QCoreApplication::processEvents();
- QModelIndex idx = vu.doMoveCursor(QMoveCursorListView::MoveHome, Qt::NoModifier);
- QCOMPARE(idx, model.index(0,0));
- idx = vu.doMoveCursor(QMoveCursorListView::MoveDown, Qt::NoModifier);
- QCOMPARE(idx, model.index(8,0));
+ QModelIndex idx = vu.moveCursor(PublicListView::MoveHome, Qt::NoModifier);
+ QCOMPARE(idx, model.index(0, 0));
+ idx = vu.moveCursor(PublicListView::MoveDown, Qt::NoModifier);
+ QCOMPARE(idx, model.index(8, 0));
}
void tst_QListView::moveCursor3()
@@ -560,7 +552,7 @@ void tst_QListView::moveCursor3()
QStandardItem *i1 = new QStandardItem("First item, long name");
QStandardItem *i2 = new QStandardItem("2nd item");
QStandardItem *i3 = new QStandardItem("Third item, long name");
- i1->setSizeHint(QSize(200,32));
+ i1->setSizeHint(QSize(200, 32));
model.appendRow(i1);
model.appendRow(i2);
model.appendRow(i3);
@@ -582,46 +574,44 @@ void tst_QListView::moveCursor3()
class QListViewShowEventListener : public QListView
{
+ Q_OBJECT
public:
- QListViewShowEventListener() : QListView() { m_shown = false;}
-
- virtual void showEvent(QShowEvent * /*e*/)
+ using QListView::QListView;
+ void showEvent(QShowEvent *e) override
{
+ QListView::showEvent(e);
int columnwidth = sizeHintForColumn(0);
- QSize sz = sizeHintForIndex(model()->index(0,0));
+ QSize sz = sizeHintForIndex(model()->index(0, 0));
// This should retrieve a model index in the 2nd section
- m_index = indexAt(QPoint(columnwidth +2, sz.height()/2));
+ m_index = indexAt(QPoint(columnwidth +2, sz.height() / 2));
m_shown = true;
}
QModelIndex m_index;
- bool m_shown;
+ bool m_shown = false;
};
void tst_QListView::indexAt()
{
- QtTestModel model(0);
- model.rCount = 2;
- model.colCount = 1;
-
+ QtTestModel model(2, 1);
QListView view;
view.setModel(&model);
view.setViewMode(QListView::ListMode);
view.setFlow(QListView::TopToBottom);
- QSize sz = view.sizeHintForIndex(model.index(0,0));
+ QSize sz = view.sizeHintForIndex(model.index(0, 0));
QModelIndex index;
- index = view.indexAt(QPoint(20,0));
+ index = view.indexAt(QPoint(20, 0));
QVERIFY(index.isValid());
QCOMPARE(index.row(), 0);
- index = view.indexAt(QPoint(20,sz.height()));
+ index = view.indexAt(QPoint(20, sz.height()));
QVERIFY(index.isValid());
QCOMPARE(index.row(), 1);
- index = view.indexAt(QPoint(20,2 * sz.height()));
+ index = view.indexAt(QPoint(20, 2 * sz.height()));
QVERIFY(!index.isValid());
// Check when peeking out of the viewport bounds
@@ -637,7 +627,7 @@ void tst_QListView::indexAt()
model.rCount = 30;
QListViewShowEventListener view2;
// Set the height to a small enough value so that it wraps to a new section.
- view2.resize(300,100);
+ view2.resize(300, 100);
view2.setModel(&model);
view2.setFlow(QListView::TopToBottom);
view2.setViewMode(QListView::ListMode);
@@ -653,15 +643,11 @@ void tst_QListView::indexAt()
void tst_QListView::clicked()
{
- QtTestModel model;
- model.rCount = 10;
- model.colCount = 2;
-
+ QtTestModel model(10, 2);
QListView view;
view.setModel(&model);
-
view.show();
- QApplication::processEvents();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
QModelIndex firstIndex = model.index(0, 0, QModelIndex());
QVERIFY(firstIndex.isValid());
@@ -673,7 +659,7 @@ void tst_QListView::clicked()
QModelIndex index = view.indexAt(p);
if (!index.isValid())
continue;
- QSignalSpy spy(&view, SIGNAL(clicked(QModelIndex)));
+ QSignalSpy spy(&view, &QListView::clicked);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p);
QCOMPARE(spy.count(), 1);
}
@@ -681,10 +667,7 @@ void tst_QListView::clicked()
void tst_QListView::singleSelectionRemoveRow()
{
- QStringList items;
- items << "item1" << "item2" << "item3" << "item4";
- QStringListModel model(items);
-
+ QStringListModel model({"item1", "item2", "item3", "item4"});
QListView view;
view.setModel(&model);
view.show();
@@ -764,7 +747,7 @@ void tst_QListView::modelColumn()
// Out of bound cases should not modify the modelColumn
view.setModelColumn(-1);
QCOMPARE(view.modelColumn(), 2);
- view.setModelColumn(INT_MAX);
+ view.setModelColumn(std::numeric_limits<int>::max());
QCOMPARE(view.modelColumn(), 2);
@@ -788,15 +771,12 @@ void tst_QListView::modelColumn()
void tst_QListView::hideFirstRow()
{
- QStringList items;
- for (int i=0; i <100; ++i)
- items << "item";
- QStringListModel model(items);
+ QStringListModel model(generateList(QLatin1String("item"), 100));
QListView view;
view.setModel(&model);
view.setUniformItemSizes(true);
- view.setRowHidden(0,true);
+ view.setRowHidden(0, true);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
}
@@ -828,7 +808,7 @@ void tst_QListView::batchedMode()
view.setViewMode(QListView::ListMode);
view.setLayoutMode(QListView::Batched);
view.setBatchSize(2);
- view.resize(200,400);
+ view.resize(200, 400);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -849,21 +829,18 @@ void tst_QListView::setCurrentIndex()
ScrollPerItemListView view;
view.setModel(&model);
-
view.resize(220,182);
view.show();
for (int pass = 0; pass < 2; ++pass) {
view.setFlow(pass == 0 ? QListView::TopToBottom : QListView::LeftToRight);
QScrollBar *sb = pass == 0 ? view.verticalScrollBar() : view.horizontalScrollBar();
- QList<QSize> gridsizes;
- gridsizes << QSize() << QSize(200,38);
- for (int ig = 0; ig < gridsizes.count(); ++ig) {
- if (pass == 1 && !gridsizes.at(ig).isValid()) // the width of an item varies, so it might jump two times
+ for (const QSize &gridSize : {QSize(), QSize(200, 38)}) {
+ if (pass == 1 && !gridSize.isValid()) // the width of an item varies, so it might jump two times
continue;
- view.setGridSize(gridsizes.at(ig));
+ view.setGridSize(gridSize);
- qApp->processEvents();
+ QCoreApplication::processEvents();
int offset = sb->value();
// first "scroll" down, verify that we scroll one step at a time
@@ -897,44 +874,21 @@ void tst_QListView::setCurrentIndex()
}
}
-class PublicListView : public QListView
-{
- public:
- PublicListView(QWidget *parent = 0) : QListView(parent)
- {
-
- }
- void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) {
- QListView::setSelection(rect, flags);
- }
- QSize contentsSize() const { return QListView::contentsSize(); }
-
- void setPositionForIndex(const QPoint &pos, const QModelIndex &index) {
- QListView::setPositionForIndex(pos, index);
- }
-
- QStyleOptionViewItem viewOptions() const {
- return QListView::viewOptions();
- }
-};
-
-class TestDelegate : public QItemDelegate
+class TestDelegate : public QStyledItemDelegate
{
public:
- explicit TestDelegate(QObject *parent, const QSize &sizeHint = QSize(50,50))
- : QItemDelegate(parent), m_sizeHint(sizeHint) {}
- QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const { return m_sizeHint; }
+ explicit TestDelegate(QObject *parent, const QSize &sizeHint = QSize(50, 50))
+ : QStyledItemDelegate(parent), m_sizeHint(sizeHint) {}
+ QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override { return m_sizeHint; }
const QSize m_sizeHint;
};
-typedef QList<int> IntList;
-
void tst_QListView::selection_data()
{
QTest::addColumn<int>("itemCount");
- QTest::addColumn<int>("viewMode");
- QTest::addColumn<int>("flow");
+ QTest::addColumn<QListView::ViewMode>("viewMode");
+ QTest::addColumn<QListView::Flow>("flow");
QTest::addColumn<bool>("wrapping");
QTest::addColumn<int>("spacing");
QTest::addColumn<QSize>("gridSize");
@@ -944,8 +898,8 @@ void tst_QListView::selection_data()
QTest::newRow("select all")
<< 4 // itemCount
- << int(QListView::ListMode)
- << int(QListView::TopToBottom)
+ << QListView::ListMode
+ << QListView::TopToBottom
<< false // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -955,8 +909,8 @@ void tst_QListView::selection_data()
QTest::newRow("select below, (on viewport)")
<< 4 // itemCount
- << int(QListView::ListMode)
- << int(QListView::TopToBottom)
+ << QListView::ListMode
+ << QListView::TopToBottom
<< false // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -966,8 +920,8 @@ void tst_QListView::selection_data()
QTest::newRow("select below 2, (on viewport)")
<< 4 // itemCount
- << int(QListView::ListMode)
- << int(QListView::TopToBottom)
+ << QListView::ListMode
+ << QListView::TopToBottom
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -977,8 +931,8 @@ void tst_QListView::selection_data()
QTest::newRow("select to the right, (on viewport)")
<< 40 // itemCount
- << int(QListView::ListMode)
- << int(QListView::TopToBottom)
+ << QListView::ListMode
+ << QListView::TopToBottom
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -988,8 +942,8 @@ void tst_QListView::selection_data()
QTest::newRow("select to the right 2, (on viewport)")
<< 40 // itemCount
- << int(QListView::ListMode)
- << int(QListView::TopToBottom)
+ << QListView::ListMode
+ << QListView::TopToBottom
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -999,8 +953,8 @@ void tst_QListView::selection_data()
QTest::newRow("select inside contents, (on viewport)")
<< 35 // itemCount
- << int(QListView::ListMode)
- << int(QListView::TopToBottom)
+ << QListView::ListMode
+ << QListView::TopToBottom
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -1010,8 +964,8 @@ void tst_QListView::selection_data()
QTest::newRow("select a tall rect in LeftToRight flow, wrap items")
<< 70 // itemCount
- << int(QListView::ListMode)
- << int(QListView::LeftToRight)
+ << QListView::ListMode
+ << QListView::LeftToRight
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -1024,8 +978,8 @@ void tst_QListView::selection_data()
QTest::newRow("select a wide rect in LeftToRight, wrap items")
<< 70 // itemCount
- << int(QListView::ListMode)
- << int(QListView::LeftToRight)
+ << QListView::ListMode
+ << QListView::LeftToRight
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -1036,8 +990,8 @@ void tst_QListView::selection_data()
QTest::newRow("select a wide negative rect in LeftToRight flow, wrap items")
<< 70 // itemCount
- << int(QListView::ListMode)
- << int(QListView::LeftToRight)
+ << QListView::ListMode
+ << QListView::LeftToRight
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -1048,8 +1002,8 @@ void tst_QListView::selection_data()
QTest::newRow("select a tall rect in TopToBottom flow, wrap items")
<< 70 // itemCount
- << int(QListView::ListMode)
- << int(QListView::TopToBottom)
+ << QListView::ListMode
+ << QListView::TopToBottom
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -1062,8 +1016,8 @@ void tst_QListView::selection_data()
QTest::newRow("select a tall negative rect in TopToBottom flow, wrap items")
<< 70 // itemCount
- << int(QListView::ListMode)
- << int(QListView::TopToBottom)
+ << QListView::ListMode
+ << QListView::TopToBottom
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -1076,8 +1030,8 @@ void tst_QListView::selection_data()
QTest::newRow("select a wide rect in TopToBottom, wrap items")
<< 70 // itemCount
- << int(QListView::ListMode)
- << int(QListView::TopToBottom)
+ << QListView::ListMode
+ << QListView::TopToBottom
<< true // wrapping
<< 0 // spacing
<< QSize() // gridSize
@@ -1099,20 +1053,18 @@ void tst_QListView::selection_data()
void tst_QListView::selection()
{
QFETCH(int, itemCount);
- QFETCH(int, viewMode);
- QFETCH(int, flow);
+ QFETCH(QListView::ViewMode, viewMode);
+ QFETCH(QListView::Flow, flow);
QFETCH(bool, wrapping);
QFETCH(int, spacing);
QFETCH(QSize, gridSize);
- QFETCH(IntList, hiddenRows);
+ QFETCH(const IntList, hiddenRows);
QFETCH(QRect, selectionRect);
- QFETCH(IntList, expectedItems);
+ QFETCH(const IntList, expectedItems);
QWidget topLevel;
PublicListView v(&topLevel);
- QtTestModel model;
- model.colCount = 1;
- model.rCount = itemCount;
+ QtTestModel model(itemCount, 1);
// avoid scrollbar size mismatches among different styles
v.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -1120,30 +1072,27 @@ void tst_QListView::selection()
v.setItemDelegate(new TestDelegate(&v));
v.setModel(&model);
- v.setViewMode(QListView::ViewMode(viewMode));
- v.setFlow(QListView::Flow(flow));
+ v.setViewMode(viewMode);
+ v.setFlow(flow);
v.setWrapping(wrapping);
v.setResizeMode(QListView::Adjust);
v.setSpacing(spacing);
if (gridSize.isValid())
v.setGridSize(gridSize);
- for (int j = 0; j < hiddenRows.count(); ++j) {
- v.setRowHidden(hiddenRows.at(j), true);
- }
+ for (int row : hiddenRows)
+ v.setRowHidden(row, true);
- v.resize(525,525);
+ v.resize(525, 525);
topLevel.show();
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
v.setSelection(selectionRect, QItemSelectionModel::ClearAndSelect);
- QModelIndexList selected = v.selectionModel()->selectedIndexes();
-
+ const QModelIndexList selected = v.selectionModel()->selectedIndexes();
QCOMPARE(selected.count(), expectedItems.count());
- for (int i = 0; i < selected.count(); ++i) {
- QVERIFY(expectedItems.contains(selected.at(i).row()));
- }
+ for (const auto &idx : selected)
+ QVERIFY(expectedItems.contains(idx.row()));
}
void tst_QListView::scrollTo()
@@ -1191,7 +1140,7 @@ void tst_QListView::scrollTo()
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
//by default, the list view scrolls per item and has no wrapping
- QModelIndex index = model.index(6,0);
+ QModelIndex index = model.index(6, 0);
//we save the size of the item for later comparisons
const QSize itemsize = lv.visualRect(index).size();
@@ -1202,15 +1151,14 @@ void tst_QListView::scrollTo()
QPoint p = lv.visualRect(index).center();
QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
//let's wait because the scrolling is delayed
- QTest::qWait(QApplication::doubleClickInterval() + 150);
- QTRY_COMPARE(lv.visualRect(index).y(),0);
+ QTRY_COMPARE(lv.visualRect(index).y(), 0);
//we scroll down. As the item is to tall for the view, it will disappear
QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier);
- QCOMPARE(lv.visualRect(index).y(), -itemsize.height());
+ QTRY_COMPARE(lv.visualRect(index).y(), -itemsize.height());
QTest::keyClick(lv.viewport(), Qt::Key_Up, Qt::NoModifier);
- QCOMPARE(lv.visualRect(index).y(), 0);
+ QTRY_COMPARE(lv.visualRect(index).y(), 0);
//Let's enable wrapping
@@ -1220,22 +1168,20 @@ void tst_QListView::scrollTo()
//we click the item
p = lv.visualRect(index).center();
QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
- //let's wait because the scrolling is delayed
- QTest::qWait(QApplication::doubleClickInterval() + 150);
- QTRY_COMPARE(lv.visualRect(index).x(),0);
+ QTRY_COMPARE(lv.visualRect(index).x(), 0);
//we scroll right. As the item is too wide for the view, it will disappear
QTest::keyClick(lv.viewport(), Qt::Key_Right, Qt::NoModifier);
- QCOMPARE(lv.visualRect(index).x(), -itemsize.width());
+ QTRY_COMPARE(lv.visualRect(index).x(), -itemsize.width());
QTest::keyClick(lv.viewport(), Qt::Key_Left, Qt::NoModifier);
- QCOMPARE(lv.visualRect(index).x(), 0);
+ QTRY_COMPARE(lv.visualRect(index).x(), 0);
lv.setWrapping(false);
- qApp->processEvents(); //let the layout happen
+ QCoreApplication::processEvents(); //let the layout happen
//Let's try with scrolling per pixel
- lv.setHorizontalScrollMode( QListView::ScrollPerPixel);
+ lv.setHorizontalScrollMode(QListView::ScrollPerPixel);
lv.verticalScrollBar()->setValue(0); //scrolls back to the first item
//we click the item
@@ -1243,11 +1189,11 @@ void tst_QListView::scrollTo()
QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
//let's wait because the scrolling is delayed
QTest::qWait(QApplication::doubleClickInterval() + 150);
- QTRY_COMPARE(lv.visualRect(index).y(),0);
+ QTRY_COMPARE(lv.visualRect(index).y(), 0);
//we scroll down. As the item is too tall for the view, it will partially disappear
QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier);
- QVERIFY(lv.visualRect(index).y()<0);
+ QVERIFY(lv.visualRect(index).y() < 0);
QTest::keyClick(lv.viewport(), Qt::Key_Up, Qt::NoModifier);
QCOMPARE(lv.visualRect(index).y(), 0);
@@ -1262,11 +1208,7 @@ void tst_QListView::scrollBarRanges()
QWidget topLevel;
ScrollPerItemListView lv(&topLevel);
QStringListModel model(&lv);
- QStringList list;
- for (int i = 0; i < rowCount; ++i)
- list << QLatin1String("Item ") + QString::number(i);
-
- model.setStringList(list);
+ model.setStringList(generateList(QLatin1String("Item "), rowCount));
lv.setModel(&model);
lv.resize(250, 130);
@@ -1275,10 +1217,9 @@ void tst_QListView::scrollBarRanges()
for (int h = 30; h <= 210; ++h) {
lv.resize(250, h);
- QApplication::processEvents(); // wait for the layout to be done
int visibleRowCount = lv.viewport()->size().height() / rowHeight;
int invisibleRowCount = rowCount - visibleRowCount;
- QCOMPARE(lv.verticalScrollBar()->maximum(), invisibleRowCount);
+ QTRY_COMPARE(lv.verticalScrollBar()->maximum(), invisibleRowCount);
}
}
@@ -1289,7 +1230,7 @@ void tst_QListView::scrollBarAsNeeded_data()
QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode");
QTest::addColumn<QMargins>("viewportMargins");
QTest::addColumn<QSize>("delegateSize");
- QTest::addColumn<int>("flow");
+ QTest::addColumn<QListView::Flow>("flow");
QTest::addColumn<bool>("horizontalScrollBarVisible");
QTest::addColumn<bool>("verticalScrollBarVisible");
@@ -1298,7 +1239,7 @@ void tst_QListView::scrollBarAsNeeded_data()
<< 0
<< QListView::ScrollPerItem
<< QMargins() << QSize()
- << int(QListView::TopToBottom)
+ << QListView::TopToBottom
<< false
<< false;
@@ -1307,7 +1248,7 @@ void tst_QListView::scrollBarAsNeeded_data()
<< 1
<< QListView::ScrollPerItem
<< QMargins() << QSize()
- << int(QListView::TopToBottom)
+ << QListView::TopToBottom
<< false
<< false;
@@ -1316,7 +1257,7 @@ void tst_QListView::scrollBarAsNeeded_data()
<< 20
<< QListView::ScrollPerItem
<< QMargins() << QSize()
- << int(QListView::TopToBottom)
+ << QListView::TopToBottom
<< false
<< true;
@@ -1325,7 +1266,7 @@ void tst_QListView::scrollBarAsNeeded_data()
<< 4
<< QListView::ScrollPerPixel
<< QMargins() << QSize(40, 40)
- << int(QListView::TopToBottom)
+ << QListView::TopToBottom
<< false
<< false;
@@ -1335,7 +1276,7 @@ void tst_QListView::scrollBarAsNeeded_data()
<< 4
<< QListView::ScrollPerPixel
<< QMargins(0, 50, 0, 50) << QSize(40, 40)
- << int(QListView::TopToBottom)
+ << QListView::TopToBottom
<< false
<< true;
@@ -1345,7 +1286,7 @@ void tst_QListView::scrollBarAsNeeded_data()
<< 4
<< QListView::ScrollPerPixel
<< QMargins(50, 0, 50, 0) << QSize(120, 40)
- << int(QListView::TopToBottom)
+ << QListView::TopToBottom
<< true
<< false;
@@ -1354,7 +1295,7 @@ void tst_QListView::scrollBarAsNeeded_data()
<< 0
<< QListView::ScrollPerItem
<< QMargins() << QSize()
- << int(QListView::LeftToRight)
+ << QListView::LeftToRight
<< false
<< false;
@@ -1363,7 +1304,7 @@ void tst_QListView::scrollBarAsNeeded_data()
<< 1
<< QListView::ScrollPerItem
<< QMargins() << QSize()
- << int(QListView::LeftToRight)
+ << QListView::LeftToRight
<< false
<< false;
@@ -1372,45 +1313,36 @@ void tst_QListView::scrollBarAsNeeded_data()
<< 20
<< QListView::ScrollPerItem
<< QMargins() << QSize()
- << int(QListView::LeftToRight)
+ << QListView::LeftToRight
<< true
<< false;
}
-class ScrollBarTestListView : public QListView
-{
- public:
- explicit ScrollBarTestListView(QWidget *p) : QListView(p) {}
-
- using QAbstractScrollArea::setViewportMargins;
-};
-
void tst_QListView::scrollBarAsNeeded()
{
-
QFETCH(QSize, size);
QFETCH(int, itemCount);
QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode);
QFETCH(QMargins, viewportMargins);
QFETCH(QSize, delegateSize);
- QFETCH(int, flow);
+ QFETCH(QListView::Flow, flow);
QFETCH(bool, horizontalScrollBarVisible);
QFETCH(bool, verticalScrollBarVisible);
- const int rowCounts[3] = {0, 1, 20};
+ constexpr int rowCounts[3] = {0, 1, 20};
QWidget topLevel;
topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QStringLiteral("::")
+ QLatin1String(QTest::currentDataTag()));
- ScrollBarTestListView lv(&topLevel);
+ PublicListView lv(&topLevel);
lv.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
lv.setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
lv.setVerticalScrollMode(verticalScrollMode);
lv.setViewportMargins(viewportMargins);
- lv.setFlow((QListView::Flow)flow);
+ lv.setFlow(flow);
if (!delegateSize.isEmpty())
lv.setItemDelegate(new TestDelegate(&lv, delegateSize));
@@ -1420,13 +1352,8 @@ void tst_QListView::scrollBarAsNeeded()
topLevel.show();
QVERIFY(QTest::qWaitForWindowActive(&topLevel));
- for (uint r = 0; r < sizeof(rowCounts)/sizeof(int); ++r) {
- QStringList list;
- for (int i = 0; i < rowCounts[r]; ++i)
- list << QLatin1String("Item ") + QString::number(i);
-
- model.setStringList(list);
-
+ for (uint r = 0; r < sizeof(rowCounts) / sizeof(int); ++r) {
+ model.setStringList(generateList(QLatin1String("Item "), rowCounts[r]));
model.setStringList(generateList(QLatin1String("Item "), itemCount));
QTRY_COMPARE(lv.horizontalScrollBar()->isVisible(), horizontalScrollBarVisible);
@@ -1483,7 +1410,6 @@ void tst_QListView::wordWrap()
lv.setWordWrap(true);
lv.setFixedSize(400, 150);
lv.showNormal();
- QApplication::processEvents();
QTRY_COMPARE(lv.horizontalScrollBar()->isVisible(), false);
#ifdef Q_OS_WINRT
@@ -1509,7 +1435,8 @@ public:
listView->setModel(model);
timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(buttonClicked()));
+ connect(timer, &QTimer::timeout,
+ this, &SetCurrentIndexAfterAppendRowCrashDialog::buttonClicked);
timer->start(1000);
}
@@ -1519,7 +1446,7 @@ protected:
QDialog::showEvent(event);
DWORD lParam = 0xFFFFFFFC/*OBJID_CLIENT*/;
DWORD wParam = 0;
- if (const HWND hwnd =getHWNDForWidget(this))
+ if (const HWND hwnd = getHWNDForWidget(this))
SendMessage(hwnd, WM_GETOBJECT, wParam, lParam);
}
@@ -1567,7 +1494,7 @@ void tst_QListView::task203585_selectAll()
//we make sure that "select all" doesn't select the hidden items
QListView view;
view.setSelectionMode(QAbstractItemView::ExtendedSelection);
- view.setModel(new QStringListModel(QStringList() << "foo", &view));
+ view.setModel(new QStringListModel({"foo"}, &view));
view.setRowHidden(0, true);
view.selectAll();
QVERIFY(view.selectionModel()->selectedIndexes().isEmpty());
@@ -1581,12 +1508,11 @@ void tst_QListView::task228566_infiniteRelayout()
QListView view;
QStringList list;
- for (int i = 0; i < 10; ++i) {
+ for (int i = 0; i < 10; ++i)
list << "small";
- }
- list << "BIGBIGBIGBIGBIGBIGBIGBIGBIGBIGBIGBIG";
- list << "BIGBIGBIGBIGBIGBIGBIGBIGBIGBIGBIGBIG";
+ list << "BIGBIGBIGBIGBIGBIGBIGBIGBIGBIGBIGBIG"
+ << "BIGBIGBIGBIGBIGBIGBIGBIGBIGBIGBIGBIG";
QStringListModel model(list);
view.setModel(&model);
@@ -1600,7 +1526,7 @@ void tst_QListView::task228566_infiniteRelayout()
QVERIFY(QTest::qWaitForWindowActive(&view));
QTest::qWait(100); //make sure the layout is done once
- QSignalSpy spy(view.horizontalScrollBar(), SIGNAL(rangeChanged(int,int)));
+ QSignalSpy spy(view.horizontalScrollBar(), &QScrollBar::rangeChanged);
//the layout should already have been done
//so there should be no change made to the scrollbar
@@ -1611,7 +1537,7 @@ void tst_QListView::task248430_crashWith0SizedItem()
{
QListView view;
view.setViewMode(QListView::IconMode);
- QStringListModel model(QStringList() << QLatin1String("item1") << QString());
+ QStringListModel model({QLatin1String("item1"), QString()});
view.setModel(&model);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -1630,11 +1556,10 @@ void tst_QListView::task250446_scrollChanged()
QVERIFY(QTest::qWaitForWindowExposed(&view));
const int scrollValue = view.verticalScrollBar()->maximum();
view.verticalScrollBar()->setValue(scrollValue);
- QCOMPARE(view.verticalScrollBar()->value(), scrollValue);
- QCOMPARE(view.currentIndex(), index);
+ QTRY_COMPARE(view.verticalScrollBar()->value(), scrollValue);
+ QTRY_COMPARE(view.currentIndex(), index);
view.showMinimized();
- QTest::qWait(50);
QTRY_COMPARE(view.verticalScrollBar()->value(), scrollValue);
QTRY_COMPARE(view.currentIndex(), index);
@@ -1646,18 +1571,12 @@ void tst_QListView::task250446_scrollChanged()
void tst_QListView::task196118_visualRegionForSelection()
{
- class MyListView : public QListView
- {
- public:
- QRegion getVisualRegionForSelection() const
- { return QListView::visualRegionForSelection( selectionModel()->selection()); }
- } view;
-
+ PublicListView view;
QStandardItemModel model;
QStandardItem top1("top1");
QStandardItem sub1("sub1");
- top1.appendRow(QList<QStandardItem*>() << &sub1);
- model.appendColumn(QList<QStandardItem*>() << &top1);
+ top1.appendRow(&sub1);
+ model.appendColumn({&top1});
view.setModel(&model);
view.setRootIndex(top1.index());
@@ -1670,16 +1589,9 @@ void tst_QListView::task196118_visualRegionForSelection()
void tst_QListView::task254449_draggingItemToNegativeCoordinates()
{
//we'll check that the items are painted correctly
- class MyListView : public QListView
- {
- public:
- void setPositionForIndex(const QPoint &position, const QModelIndex &index)
- { QListView::setPositionForIndex(position, index); }
-
- } list;
-
- QStandardItemModel model(1,1);
- QModelIndex index = model.index(0,0);
+ PublicListView list;
+ QStandardItemModel model(1, 1);
+ QModelIndex index = model.index(0, 0);
model.setData(index, QLatin1String("foo"));
list.setModel(&model);
list.setViewMode(QListView::IconMode);
@@ -1691,27 +1603,23 @@ void tst_QListView::task254449_draggingItemToNegativeCoordinates()
class MyItemDelegate : public QStyledItemDelegate
{
public:
- MyItemDelegate() : numPaints(0) { }
- void paint(QPainter *painter,
- const QStyleOptionViewItem &option, const QModelIndex &index) const
+ using QStyledItemDelegate::QStyledItemDelegate;
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override
{
numPaints++;
QStyledItemDelegate::paint(painter, option, index);
}
- mutable int numPaints;
+ mutable int numPaints = 0;
} delegate;
- delegate.numPaints = 0;
list.setItemDelegate(&delegate);
- QApplication::processEvents();
QTRY_VERIFY(delegate.numPaints > 0); //makes sure the layout is done
- const QPoint topLeft(-6, 0);
- list.setPositionForIndex(topLeft, index);
-
//we'll make sure the item is repainted
delegate.numPaints = 0;
- QApplication::processEvents();
+ const QPoint topLeft(-6, 0);
+ list.setPositionForIndex(topLeft, index);
QTRY_COMPARE(delegate.numPaints, 1);
QCOMPARE(list.visualRect(index).topLeft(), topLeft);
}
@@ -1719,24 +1627,23 @@ void tst_QListView::task254449_draggingItemToNegativeCoordinates()
void tst_QListView::keyboardSearch()
{
- QStringList items;
- items << "AB" << "AC" << "BA" << "BB" << "BD" << "KAFEINE" << "KONQUEROR" << "KOPETE" << "KOOKA" << "OKULAR";
- QStringListModel model(items);
+ QStringListModel model({"AB", "AC", "BA", "BB", "BD", "KAFEINE",
+ "KONQUEROR", "KOPETE", "KOOKA", "OKULAR"});
QListView view;
view.setModel(&model);
view.show();
- qApp->setActiveWindow(&view);
+ QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
QTest::keyClick(&view, Qt::Key_K);
- QTRY_COMPARE(view.currentIndex() , model.index(5,0)); //KAFEINE
+ QTRY_COMPARE(view.currentIndex() , model.index(5, 0)); //KAFEINE
QTest::keyClick(&view, Qt::Key_O);
- QTRY_COMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR
+ QTRY_COMPARE(view.currentIndex() , model.index(6, 0)); //KONQUEROR
QTest::keyClick(&view, Qt::Key_N);
- QTRY_COMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR
+ QTRY_COMPARE(view.currentIndex() , model.index(6, 0)); //KONQUEROR
}
void tst_QListView::shiftSelectionWithNonUniformItemSizes()
@@ -1744,9 +1651,7 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes()
// This checks that no items are selected unexpectedly by Shift-Arrow
// when items with non-uniform sizes are laid out in a grid
{ // First test: QListView::LeftToRight flow
- QStringList items;
- items << "Long\nText" << "Text" << "Text" << "Text";
- QStringListModel model(items);
+ QStringListModel model({"Long\nText", "Text", "Text","Text"});
QListView view;
view.setFixedSize(250, 250);
@@ -1773,9 +1678,7 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes()
QVERIFY(!selected.contains(model.index(0, 0)));
}
{ // Second test: QListView::TopToBottom flow
- QStringList items;
- items << "ab" << "a" << "a" << "a";
- QStringListModel model(items);
+ QStringListModel model({"ab", "a", "a", "a"});
QListView view;
view.setFixedSize(250, 250);
@@ -1836,7 +1739,7 @@ void tst_QListView::shiftSelectionWithItemAlignment()
QModelIndex index1 = view.model()->index(items.size() / 4, 0);
QPoint p = view.visualRect(index1).center();
QVERIFY(view.viewport()->rect().contains(p));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, p);
QCOMPARE(view.currentIndex(), index1);
QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
@@ -1850,9 +1753,7 @@ void tst_QListView::shiftSelectionWithItemAlignment()
void tst_QListView::clickOnViewportClearsSelection()
{
- QStringList items;
- items << "Text1";
- QStringListModel model(items);
+ QStringListModel model({"Text1"});
QListView view;
view.setModel(&model);
view.setSelectionMode(QListView::ExtendedSelection);
@@ -1865,12 +1766,12 @@ void tst_QListView::clickOnViewportClearsSelection()
//we try to click outside of the index
const QPoint point = view.visualRect(index).bottomRight() + QPoint(10,10);
- QTest::mousePress(view.viewport(), Qt::LeftButton, 0, point);
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, point);
//at this point, the selection shouldn't have changed
QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
QVERIFY(view.selectionModel()->isSelected(index));
- QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, point);
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, point);
//now the selection should be cleared
QVERIFY(!view.selectionModel()->hasSelection());
}
@@ -1879,9 +1780,9 @@ void tst_QListView::task262152_setModelColumnNavigate()
{
QListView view;
QStandardItemModel model(3,2);
- model.setItem(0,1,new QStandardItem("[0,1]"));
- model.setItem(1,1,new QStandardItem("[1,1]"));
- model.setItem(2,1,new QStandardItem("[2,1]"));
+ model.setItem(0, 1, new QStandardItem("[0,1]"));
+ model.setItem(1, 1, new QStandardItem("[1,1]"));
+ model.setItem(2, 1, new QStandardItem("[2,1]"));
view.setModel(&model);
view.setModelColumn(1);
@@ -1889,48 +1790,44 @@ void tst_QListView::task262152_setModelColumnNavigate()
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow());
+ QCOMPARE(&view, QApplication::activeWindow());
QTest::keyClick(&view, Qt::Key_Down);
- QTRY_COMPARE(view.currentIndex(), model.index(1,1));
+ QTRY_COMPARE(view.currentIndex(), model.index(1, 1));
QTest::keyClick(&view, Qt::Key_Down);
- QTRY_COMPARE(view.currentIndex(), model.index(2,1));
+ QTRY_COMPARE(view.currentIndex(), model.index(2, 1));
}
void tst_QListView::taskQTBUG_2233_scrollHiddenItems_data()
{
- QTest::addColumn<int>("flow");
+ QTest::addColumn<QListView::Flow>("flow");
- QTest::newRow("TopToBottom") << static_cast<int>(QListView::TopToBottom);
- QTest::newRow("LeftToRight") << static_cast<int>(QListView::LeftToRight);
+ QTest::newRow("TopToBottom") << QListView::TopToBottom;
+ QTest::newRow("LeftToRight") << QListView::LeftToRight;
}
void tst_QListView::taskQTBUG_2233_scrollHiddenItems()
{
- QFETCH(int, flow);
+ QFETCH(QListView::Flow, flow);
const int rowCount = 200;
QWidget topLevel;
setFrameless(&topLevel);
ScrollPerItemListView view(&topLevel);
QStringListModel model(&view);
- QStringList list;
- for (int i = 0; i < rowCount; ++i)
- list << QString::number(i);
-
- model.setStringList(list);
+ model.setStringList(generateList(QString(), rowCount));
view.setModel(&model);
view.setUniformItemSizes(true);
view.setViewMode(QListView::ListMode);
for (int i = 0; i < rowCount / 2; ++i)
view.setRowHidden(2 * i, true);
- view.setFlow(static_cast<QListView::Flow>(flow));
+ view.setFlow(flow);
view.resize(130, 130);
for (int i = 0; i < 10; ++i) {
(view.flow() == QListView::TopToBottom
? view.verticalScrollBar()
: view.horizontalScrollBar())->setValue(i);
- QModelIndex index = view.indexAt(QPoint(0,0));
+ QModelIndex index = view.indexAt(QPoint(0, 0));
QVERIFY(index.isValid());
QCOMPARE(index.row(), 2 * i + 1);
}
@@ -1944,10 +1841,9 @@ void tst_QListView::taskQTBUG_2233_scrollHiddenItems()
int nbVisibleItem = rowCount / 2 - bar->maximum();
bar->setValue(bar->maximum());
- for (int i = rowCount; i > rowCount / 2; i--) {
+ for (int i = rowCount; i > rowCount / 2; i--)
view.setRowHidden(i, true);
- }
- QTRY_COMPARE(bar->maximum(), rowCount/4 - nbVisibleItem);
+ QTRY_COMPARE(bar->maximum(), rowCount / 4 - nbVisibleItem);
QCOMPARE(bar->value(), bar->maximum());
}
@@ -1956,9 +1852,8 @@ void tst_QListView::taskQTBUG_633_changeModelData()
QListView view;
view.setFlow(QListView::LeftToRight);
QStandardItemModel model(5,1);
- for (int i = 0; i < model.rowCount(); ++i) {
- model.setData( model.index(i, 0), QString::number(i));
- }
+ for (int i = 0; i < model.rowCount(); ++i)
+ model.setData(model.index(i, 0), QString::number(i));
view.setModel(&model);
view.show();
@@ -1975,7 +1870,7 @@ void tst_QListView::taskQTBUG_633_changeModelData()
void tst_QListView::taskQTBUG_435_deselectOnViewportClick()
{
QListView view;
- QStringListModel model( QStringList() << "1" << "2" << "3" << "4");
+ QStringListModel model({"1", "2", "3", "4"});
view.setModel(&model);
view.setSelectionMode(QAbstractItemView::ExtendedSelection);
view.selectAll();
@@ -1985,21 +1880,21 @@ void tst_QListView::taskQTBUG_435_deselectOnViewportClick()
const QRect itemRect = view.visualRect(model.index(model.rowCount() - 1));
QPoint p = view.visualRect(model.index(model.rowCount() - 1)).center() + QPoint(0, itemRect.height());
//first the left button
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, p);
QVERIFY(!view.selectionModel()->hasSelection());
view.selectAll();
QCOMPARE(view.selectionModel()->selectedIndexes().count(), model.rowCount());
//and now the right button
- QTest::mouseClick(view.viewport(), Qt::RightButton, 0, p);
+ QTest::mouseClick(view.viewport(), Qt::RightButton, {}, p);
QVERIFY(!view.selectionModel()->hasSelection());
}
void tst_QListView::taskQTBUG_2678_spacingAndWrappedText()
{
static const QString lorem("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
- QStringListModel model(QStringList() << lorem << lorem << "foo" << lorem << "bar" << lorem << lorem);
+ QStringListModel model({lorem, lorem, "foo", lorem, "bar", lorem, lorem});
QListView w;
w.setModel(&model);
w.setViewMode(QListView::ListMode);
@@ -2012,14 +1907,11 @@ void tst_QListView::taskQTBUG_2678_spacingAndWrappedText()
void tst_QListView::taskQTBUG_5877_skippingItemInPageDownUp()
{
- QList<int> currentItemIndexes;
- QtTestModel model(0);
- model.colCount = 1;
- model.rCount = 100;
+ QtTestModel model(100, 1);
- currentItemIndexes << 0 << 6 << 16 << 25 << 34 << 42 << 57 << 68 << 77
- << 83 << 91 << 94;
- QMoveCursorListView vu;
+ static const int currentItemIndexes[] =
+ {0, 6, 16, 25, 34, 42, 57, 68, 77, 83, 91, 94};
+ PublicListView vu;
vu.setModel(&model);
vu.show();
@@ -2029,43 +1921,34 @@ void tst_QListView::taskQTBUG_5877_skippingItemInPageDownUp()
int visibleRowCount = vu.viewport()->height() / itemHeight;
int scrolledRowCount = visibleRowCount - 1;
- for (int i = 0; i < currentItemIndexes.size(); ++i) {
- vu.selectionModel()->setCurrentIndex(model.index(currentItemIndexes[i], 0),
+ for (int currentItemIndex : currentItemIndexes) {
+ vu.selectionModel()->setCurrentIndex(model.index(currentItemIndex, 0),
QItemSelectionModel::SelectCurrent);
- QModelIndex idx = vu.doMoveCursor(QMoveCursorListView::MovePageDown, Qt::NoModifier);
- int newCurrent = qMin(currentItemIndexes[i] + scrolledRowCount, 99);
+ QModelIndex idx = vu.moveCursor(PublicListView::MovePageDown, Qt::NoModifier);
+ int newCurrent = qMin(currentItemIndex + scrolledRowCount, 99);
QCOMPARE(idx, model.index(newCurrent, 0));
- idx = vu.doMoveCursor(QMoveCursorListView::MovePageUp, Qt::NoModifier);
- newCurrent = qMax(currentItemIndexes[i] - scrolledRowCount, 0);
+ idx = vu.moveCursor(PublicListView::MovePageUp, Qt::NoModifier);
+ newCurrent = qMax(currentItemIndex - scrolledRowCount, 0);
QCOMPARE(idx, model.index(newCurrent, 0));
}
}
-class ListView_9455 : public QListView
-{
-public:
- QSize contentsSize() const
- {
- return QListView::contentsSize();
- }
-};
-
void tst_QListView::taskQTBUG_9455_wrongScrollbarRanges()
{
QStringListModel model(generateList("item ", 8));
- ListView_9455 w;
+ PublicListView w;
setFrameless(&w);
w.setModel(&model);
w.setViewMode(QListView::IconMode);
w.resize(116, 132);
w.setMovement(QListView::Static);
- const int spacing = 200;
- w.setSpacing(spacing);
+ w.setSpacing(200);
w.showNormal();
QVERIFY(QTest::qWaitForWindowExposed(&w));
- QCOMPARE(w.verticalScrollBar()->maximum(), w.contentsSize().height() - w.viewport()->geometry().height());
+ QCOMPARE(w.verticalScrollBar()->maximum(),
+ w.contentsSize().height() - w.viewport()->geometry().height());
}
void tst_QListView::styleOptionViewItem()
@@ -2073,7 +1956,8 @@ void tst_QListView::styleOptionViewItem()
class MyDelegate : public QStyledItemDelegate
{
public:
- void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override
{
QStyleOptionViewItem opt(option);
initStyleOption(&opt, index);
@@ -2089,12 +1973,14 @@ void tst_QListView::styleOptionViewItem()
view.setModel(&model);
MyDelegate delegate;
view.setItemDelegate(&delegate);
- model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ model.appendRow({new QStandardItem("Beginning"),
+ new QStandardItem("Middle"),
+ new QStandardItem("Middle"),
+ new QStandardItem("End")});
// Run test
view.showMaximized();
- QApplication::processEvents();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
}
void tst_QListView::taskQTBUG_12308_artihmeticException()
@@ -2103,8 +1989,8 @@ void tst_QListView::taskQTBUG_12308_artihmeticException()
lw.setLayoutMode(QListView::Batched);
lw.setViewMode(QListView::IconMode);
for (int i = 0; i < lw.batchSize() + 1; i++) {
- QListWidgetItem *item = new QListWidgetItem();
- item->setText(QString("Item %L1").arg(i));
+ QListWidgetItem *item = new QListWidgetItem(
+ QLatin1String("Item ") + QString::number(i));
lw.addItem(item);
item->setHidden(true);
}
@@ -2117,10 +2003,9 @@ class Delegate12308 : public QStyledItemDelegate
{
Q_OBJECT
public:
- Delegate12308(QObject *parent = 0) : QStyledItemDelegate(parent)
- { }
-
- void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+ using QStyledItemDelegate::QStyledItemDelegate;
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override
{
QVERIFY(option.rect.topLeft() != QPoint(-1, -1));
QStyledItemDelegate::paint(painter, option, index);
@@ -2135,8 +2020,8 @@ void tst_QListView::taskQTBUG_12308_wrongFlowLayout()
lw.setViewMode(QListView::IconMode);
lw.setItemDelegate(&delegate);
for (int i = 0; i < lw.batchSize() + 1; i++) {
- QListWidgetItem *item = new QListWidgetItem();
- item->setText(QString("Item %L1").arg(i));
+ QListWidgetItem *item = new QListWidgetItem(
+ QLatin1String("Item ") + QString::number(i));
lw.addItem(item);
if (!item->text().contains(QLatin1Char('1')))
item->setHidden(true);
@@ -2147,27 +2032,24 @@ void tst_QListView::taskQTBUG_12308_wrongFlowLayout()
void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems_data()
{
- QTest::addColumn<int>("flow");
- QTest::newRow("flow TopToBottom") << static_cast<int>(QListView::TopToBottom);
- QTest::newRow("flow LeftToRight") << static_cast<int>(QListView::LeftToRight);
+ QTest::addColumn<QListView::Flow>("flow");
+ QTest::newRow("flow TopToBottom") << QListView::TopToBottom;
+ QTest::newRow("flow LeftToRight") << QListView::LeftToRight;
}
void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems()
{
- QFETCH(int, flow);
+ QFETCH(QListView::Flow, flow);
#ifdef Q_OS_WINRT
QSKIP("Fails on WinRT - QTBUG-68297");
#endif
ScrollPerItemListView lv;
lv.setUniformItemSizes(true);
- lv.setFlow(static_cast<QListView::Flow>(flow));
+ lv.setFlow(flow);
QStringListModel model;
- QStringList list;
- for (int i = 0; i < 30; i++)
- list << QString::number(i);
- model.setStringList(list);
+ model.setStringList(generateList(QString(), 30));
lv.setModel(&model);
lv.showNormal();
QVERIFY(QTest::qWaitForWindowExposed(&lv));
@@ -2179,8 +2061,7 @@ void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems()
QModelIndex index = model.index(2, 0);
lv.setCurrentIndex(index);
lv.scrollTo(index, QAbstractItemView::PositionAtTop);
- QApplication::processEvents();
- QCOMPARE(lv.visualRect(index), firstItemRect);
+ QTRY_COMPARE(lv.visualRect(index), firstItemRect);
// Hide some rows and scroll to selection
for (int i = 0; i < 5; i++) {
@@ -2189,8 +2070,7 @@ void tst_QListView::taskQTBUG_21115_scrollToAndHiddenItems()
lv.setRowHidden(i, true);
}
lv.scrollTo(index, QAbstractItemView::PositionAtTop);
- QApplication::processEvents();
- QCOMPARE(lv.visualRect(index), firstItemRect);
+ QTRY_COMPARE(lv.visualRect(index), firstItemRect);
}
void tst_QListView::draggablePaintPairs_data()
@@ -2208,10 +2088,7 @@ void tst_QListView::draggablePaintPairs()
QListView view;
QStringListModel model;
- QStringList list;
- for (int i = 0; i < 30; i++)
- list << QString::number(i);
- model.setStringList(list);
+ model.setStringList(generateList(QString(), 30));
view.setModel(&model);
view.show();
@@ -2220,12 +2097,11 @@ void tst_QListView::draggablePaintPairs()
QModelIndex expectedIndex = model.index(row, 0);
QListViewPrivate *privateClass = static_cast<QListViewPrivate *>(QListViewPrivate::get(&view));
QRect rect;
- QModelIndexList indexList;
- indexList << expectedIndex;
+ const QModelIndexList indexList{ expectedIndex };
view.scrollTo(expectedIndex);
- QItemViewPaintPairs pairs = privateClass->draggablePaintPairs(indexList, &rect);
+ const QItemViewPaintPairs pairs = privateClass->draggablePaintPairs(indexList, &rect);
QCOMPARE(indexList.size(), pairs.size());
- foreach (const QItemViewPaintPair &pair, pairs) {
+ for (const QItemViewPaintPair &pair : pairs) {
QCOMPARE(rect, pair.rect);
QCOMPARE(expectedIndex, pair.index);
}
@@ -2233,29 +2109,26 @@ void tst_QListView::draggablePaintPairs()
void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys_data()
{
- QTest::addColumn<int>("flow");
+ QTest::addColumn<QListView::Flow>("flow");
QTest::addColumn<int>("spacing");
- QTest::newRow("flow TopToBottom no spacing") << static_cast<int>(QListView::TopToBottom) << 0;
- QTest::newRow("flow TopToBottom with spacing") << static_cast<int>(QListView::TopToBottom) << 5;
- QTest::newRow("flow LeftToRight no spacing") << static_cast<int>(QListView::LeftToRight) << 0;
- QTest::newRow("flow LeftToRight with spacing") << static_cast<int>(QListView::LeftToRight) << 5;
+ QTest::newRow("flow TopToBottom no spacing") << QListView::TopToBottom << 0;
+ QTest::newRow("flow TopToBottom with spacing") << QListView::TopToBottom << 5;
+ QTest::newRow("flow LeftToRight no spacing") << QListView::LeftToRight << 0;
+ QTest::newRow("flow LeftToRight with spacing") << QListView::LeftToRight << 5;
}
void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
{
- QFETCH(int, flow);
+ QFETCH(QListView::Flow, flow);
QFETCH(int, spacing);
// create some items to show
QStringListModel model;
- QStringList list;
- for (int i = 0; i < 60; i++)
- list << QString::number(i);
- model.setStringList(list);
+ model.setStringList(generateList(QString(), 60));
// create listview
ScrollPerItemListView lv;
- lv.setFlow(static_cast<QListView::Flow>(flow));
+ lv.setFlow(flow);
lv.setSpacing(spacing);
lv.setModel(&model);
lv.show();
@@ -2266,7 +2139,7 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
lv.setRowHidden(i, true);
// scroll forward and check that selected item is visible always
- int visibleItemCount = model.rowCount()/2;
+ int visibleItemCount = model.rowCount() / 2;
for (int i = 0; i < visibleItemCount; i++) {
if (flow == QListView::TopToBottom)
QTest::keyClick(&lv, Qt::Key_Down);
@@ -2285,7 +2158,7 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
}
// scroll forward only half way
- for (int i = 0; i < visibleItemCount/2; i++) {
+ for (int i = 0; i < visibleItemCount / 2; i++) {
if (flow == QListView::TopToBottom)
QTest::keyClick(&lv, Qt::Key_Down);
else
@@ -2294,7 +2167,7 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
}
// scroll backward again
- for (int i = 0; i < visibleItemCount/2; i++) {
+ for (int i = 0; i < visibleItemCount / 2; i++) {
if (flow == QListView::TopToBottom)
QTest::keyClick(&lv, Qt::Key_Up);
else
@@ -2305,29 +2178,26 @@ void tst_QListView::taskQTBUG_21804_hiddenItemsAndScrollingWithKeys()
void tst_QListView::spacing_data()
{
- QTest::addColumn<int>("flow");
+ QTest::addColumn<QListView::Flow>("flow");
QTest::addColumn<int>("spacing");
- QTest::newRow("flow=TopToBottom spacing=0") << static_cast<int>(QListView::TopToBottom) << 0;
- QTest::newRow("flow=TopToBottom spacing=10") << static_cast<int>(QListView::TopToBottom) << 10;
- QTest::newRow("flow=LeftToRight spacing=0") << static_cast<int>(QListView::LeftToRight) << 0;
- QTest::newRow("flow=LeftToRight spacing=10") << static_cast<int>(QListView::LeftToRight) << 10;
+ QTest::newRow("flow=TopToBottom spacing=0") << QListView::TopToBottom << 0;
+ QTest::newRow("flow=TopToBottom spacing=10") << QListView::TopToBottom << 10;
+ QTest::newRow("flow=LeftToRight spacing=0") << QListView::LeftToRight << 0;
+ QTest::newRow("flow=LeftToRight spacing=10") << QListView::LeftToRight << 10;
}
void tst_QListView::spacing()
{
- QFETCH(int, flow);
+ QFETCH(QListView::Flow, flow);
QFETCH(int, spacing);
// create some items to show
QStringListModel model;
- QStringList list;
- for (int i = 0; i < 60; i++)
- list << QString::number(i);
- model.setStringList(list);
+ model.setStringList(generateList(QString(), 60));
// create listview
ScrollPerItemListView lv;
- lv.setFlow(static_cast<QListView::Flow>(flow));
+ lv.setFlow(flow);
lv.setModel(&model);
lv.setSpacing(spacing);
lv.show();
@@ -2352,10 +2222,7 @@ void tst_QListView::testScrollToWithHidden()
QListView lv;
QStringListModel model;
- QStringList list;
- for (int i = 0; i < 30; i++)
- list << QString::number(i);
- model.setStringList(list);
+ model.setStringList(generateList(QString(), 30));
lv.setModel(&model);
lv.setRowHidden(1, true);
@@ -2394,11 +2261,12 @@ class TempStyleSetter
{
public:
TempStyleSetter()
- : m_oldStyle(qApp->style())
+ : m_oldStyle(QApplication::style())
{
- m_oldStyle->setParent(0);
+ m_oldStyle->setParent(nullptr);
QListView tempView;
- if (QApplication::style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, tempView.horizontalScrollBar()))
+ if (QApplication::style()->styleHint(QStyle::SH_ScrollBar_Transient,
+ nullptr, tempView.horizontalScrollBar()))
QApplication::setStyle(QStyleFactory::create("Fusion"));
}
@@ -2407,17 +2275,21 @@ public:
QApplication::setStyle(m_oldStyle);
}
private:
- QStyle* m_oldStyle;
+ QStyle *m_oldStyle;
};
void tst_QListView::taskQTBUG_39902_mutualScrollBars_data()
{
QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode");
QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode");
- QTest::newRow("per item / per item") << QAbstractItemView::ScrollPerItem << QAbstractItemView::ScrollPerItem;
- QTest::newRow("per pixel / per item") << QAbstractItemView::ScrollPerPixel << QAbstractItemView::ScrollPerItem;
- QTest::newRow("per item / per pixel") << QAbstractItemView::ScrollPerItem << QAbstractItemView::ScrollPerPixel;
- QTest::newRow("per pixel / per pixel") << QAbstractItemView::ScrollPerPixel << QAbstractItemView::ScrollPerPixel;
+ QTest::newRow("per item / per item") << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem;
+ QTest::newRow("per pixel / per item") << QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerItem;
+ QTest::newRow("per item / per pixel") << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerPixel;
+ QTest::newRow("per pixel / per pixel") << QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel;
}
void tst_QListView::taskQTBUG_39902_mutualScrollBars()
@@ -2447,50 +2319,60 @@ void tst_QListView::taskQTBUG_39902_mutualScrollBars()
model.setRowCount(2);
for (int i = 0; i < model.rowCount(); ++i)
model.setData(model.index(i, 0), itemSize, Qt::SizeHintRole);
- view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2);
+ view->resize(itemSize.width() + view->frameWidth() * 2,
+ model.rowCount() * itemSize.height() + view->frameWidth() * 2);
// this will end up in a stack overflow, if QTBUG-39902 is not fixed
QTest::qWait(100);
// these tests do not apply with transient scroll bars enabled
- QVERIFY (!view->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, view->horizontalScrollBar()));
+ QVERIFY (!view->style()->styleHint(QStyle::SH_ScrollBar_Transient,
+ nullptr, view->horizontalScrollBar()));
// make it double as large, no scroll bars should be visible
- view->resize((itemSize.width() + view->frameWidth() * 2) * 2, (model.rowCount() * itemSize.height() + view->frameWidth() * 2) * 2);
+ view->resize((itemSize.width() + view->frameWidth() * 2) * 2,
+ (model.rowCount() * itemSize.height() + view->frameWidth() * 2) * 2);
QTRY_VERIFY(!view->horizontalScrollBar()->isVisible());
QTRY_VERIFY(!view->verticalScrollBar()->isVisible());
// make it half the size, both scroll bars should be visible
- view->resize((itemSize.width() + view->frameWidth() * 2) / 2, (model.rowCount() * itemSize.height() + view->frameWidth() * 2) / 2);
+ view->resize((itemSize.width() + view->frameWidth() * 2) / 2,
+ (model.rowCount() * itemSize.height() + view->frameWidth() * 2) / 2);
QTRY_VERIFY(view->horizontalScrollBar()->isVisible());
QTRY_VERIFY(view->verticalScrollBar()->isVisible());
// make it double as large, no scroll bars should be visible
- view->resize((itemSize.width() + view->frameWidth() * 2) * 2, (model.rowCount() * itemSize.height() + view->frameWidth() * 2) * 2);
+ view->resize((itemSize.width() + view->frameWidth() * 2) * 2,
+ (model.rowCount() * itemSize.height() + view->frameWidth() * 2) * 2);
QTRY_VERIFY(!view->horizontalScrollBar()->isVisible());
QTRY_VERIFY(!view->verticalScrollBar()->isVisible());
// now, coming from the double size, resize it to the exactly matching size, still no scroll bars should be visible again
- view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2);
+ view->resize(itemSize.width() + view->frameWidth() * 2,
+ model.rowCount() * itemSize.height() + view->frameWidth() * 2);
QTRY_VERIFY(!view->horizontalScrollBar()->isVisible());
QTRY_VERIFY(!view->verticalScrollBar()->isVisible());
// now remove just one single pixel in height -> both scroll bars will show up since they depend on each other
- view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2 - 1);
+ view->resize(itemSize.width() + view->frameWidth() * 2,
+ model.rowCount() * itemSize.height() + view->frameWidth() * 2 - 1);
QTRY_VERIFY(view->horizontalScrollBar()->isVisible());
QTRY_VERIFY(view->verticalScrollBar()->isVisible());
// now remove just one single pixel in width -> both scroll bars will show up since they depend on each other
- view->resize(itemSize.width() + view->frameWidth() * 2 - 1, model.rowCount() * itemSize.height() + view->frameWidth() * 2);
+ view->resize(itemSize.width() + view->frameWidth() * 2 - 1,
+ model.rowCount() * itemSize.height() + view->frameWidth() * 2);
QTRY_VERIFY(view->horizontalScrollBar()->isVisible());
QTRY_VERIFY(view->verticalScrollBar()->isVisible());
// finally, coming from a size being to small, resize back to the exactly matching size -> both scroll bars should disappear again
- view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2);
+ view->resize(itemSize.width() + view->frameWidth() * 2,
+ model.rowCount() * itemSize.height() + view->frameWidth() * 2);
QTRY_VERIFY(!view->horizontalScrollBar()->isVisible());
QTRY_VERIFY(!view->verticalScrollBar()->isVisible());
// now remove just one single pixel in height -> both scroll bars will show up since they depend on each other
- view->resize(itemSize.width() + view->frameWidth() * 2, model.rowCount() * itemSize.height() + view->frameWidth() * 2 - 1);
+ view->resize(itemSize.width() + view->frameWidth() * 2,
+ model.rowCount() * itemSize.height() + view->frameWidth() * 2 - 1);
QTRY_VERIFY(view->horizontalScrollBar()->isVisible());
QTRY_VERIFY(view->verticalScrollBar()->isVisible());
}
@@ -2503,12 +2385,8 @@ void tst_QListView::horizontalScrollingByVerticalWheelEvents()
lv.setItemDelegate(new TestDelegate(&lv, QSize(100, 100)));
- QtTestModel model;
- model.colCount = 1;
- model.rCount = 100;
-
+ QtTestModel model(100, 1);
lv.setModel(&model);
-
lv.resize(300, 300);
lv.show();
QVERIFY(QTest::qWaitForWindowExposed(&lv));
@@ -2521,23 +2399,23 @@ void tst_QListView::horizontalScrollingByVerticalWheelEvents()
QWheelEvent wheelLeftDownEvent(pos, globalPos, QPoint(0, 0), QPoint(120, -120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
int hValue = lv.horizontalScrollBar()->value();
- QApplication::sendEvent(lv.viewport(), &wheelDownEvent);
+ QCoreApplication::sendEvent(lv.viewport(), &wheelDownEvent);
QVERIFY(lv.horizontalScrollBar()->value() > hValue);
- QApplication::sendEvent(lv.viewport(), &wheelUpEvent);
+ QCoreApplication::sendEvent(lv.viewport(), &wheelUpEvent);
QCOMPARE(lv.horizontalScrollBar()->value(), hValue);
- QApplication::sendEvent(lv.viewport(), &wheelLeftDownEvent);
+ QCoreApplication::sendEvent(lv.viewport(), &wheelLeftDownEvent);
QCOMPARE(lv.horizontalScrollBar()->value(), hValue);
// ensure that vertical wheel events are not converted when vertical
// scroll bar is not visible but vertical scrolling is possible
lv.setWrapping(false);
lv.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- QApplication::processEvents();
+ QCoreApplication::processEvents();
int vValue = lv.verticalScrollBar()->value();
- QApplication::sendEvent(lv.viewport(), &wheelDownEvent);
+ QCoreApplication::sendEvent(lv.viewport(), &wheelDownEvent);
QVERIFY(lv.verticalScrollBar()->value() > vValue);
#else
QSKIP("Built with --no-feature-wheelevent");
@@ -2584,16 +2462,9 @@ void tst_QListView::taskQTBUG_7232_AllowUserToControlSingleStep()
void tst_QListView::taskQTBUG_51086_skippingIndexesInSelectedIndexes()
{
- // simple way to get access to selectedIndexes()
- class QListViewWithPublicSelectedIndexes : public QListView
- {
- public:
- using QListView::selectedIndexes;
- };
-
QStandardItemModel data(10, 1);
QItemSelectionModel selections(&data);
- QListViewWithPublicSelectedIndexes list;
+ PublicListView list;
list.setModel(&data);
list.setSelectionModel(&selections);
@@ -2640,7 +2511,7 @@ void tst_QListView::itemAlignment()
QVERIFY(w.visualRect(item1->index()).width() == w.visualRect(item2->index()).width());
w.setItemAlignment(Qt::AlignLeft);
- QApplication::processEvents();
+ QCoreApplication::processEvents();
QVERIFY(w.visualRect(item1->index()).width() < w.visualRect(item2->index()).width());
}
@@ -2653,11 +2524,6 @@ void tst_QListView::internalDragDropMove()
// on an internal move, the item was deleted which should not happen
// see QTBUG-67440
- class QListViewWithPublicStartDrag : public QListView
- {
- public:
- using QListView::startDrag;
- };
QStandardItemModel data(0, 1);
QPixmap pixmap(32, 32);
@@ -2666,7 +2532,7 @@ void tst_QListView::internalDragDropMove()
data.appendRow(new QStandardItem(QIcon(pixmap), QString::number(i)));
}
QItemSelectionModel selections(&data);
- QListViewWithPublicStartDrag list;
+ PublicListView list;
list.setWindowTitle(QTest::currentTestFunction());
list.setViewMode(QListView::IconMode);
list.setDefaultDropAction(Qt::MoveAction);
@@ -2682,10 +2548,10 @@ void tst_QListView::internalDragDropMove()
QTimer::singleShot(0, [&list]()
{
const QPoint pos = list.rect().center();
- QMouseEvent mouseMove(QEvent::MouseMove, pos, list.mapToGlobal(pos), Qt::NoButton, 0, 0);
- QApplication::sendEvent(&list, &mouseMove);
- QMouseEvent mouseRelease(QEvent::MouseButtonRelease, pos, list.mapToGlobal(pos), Qt::LeftButton, 0, 0);
- QApplication::sendEvent(&list, &mouseRelease);
+ QMouseEvent mouseMove(QEvent::MouseMove, pos, list.mapToGlobal(pos), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(&list, &mouseMove);
+ QMouseEvent mouseRelease(QEvent::MouseButtonRelease, pos, list.mapToGlobal(pos), Qt::LeftButton, {}, {});
+ QCoreApplication::sendEvent(&list, &mouseRelease);
});
const int expectedCount = data.rowCount();
list.startDrag(Qt::MoveAction|Qt::CopyAction);
diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
index fe2ede4183..befb45e683 100644
--- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
+++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
@@ -26,22 +26,23 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QtGui/QtGui>
-#include <QtWidgets/QtWidgets>
-#include <qlist.h>
+#include <QCompleter>
+#include <QHBoxLayout>
+#include <QLineEdit>
+#include <QListWidget>
#include <QSignalSpy>
-
-#include <qlistwidget.h>
+#include <QStyledItemDelegate>
+#include <QTest>
#include <private/qlistwidget_p.h>
+using IntList = QVector<int>;
+
class tst_QListWidget : public QObject
{
Q_OBJECT
public:
- tst_QListWidget();
+ tst_QListWidget() = default;
enum ModelChanged {
RowsAboutToBeInserted,
@@ -144,13 +145,18 @@ protected slots:
void columnsRemoved(const QModelIndex &parent, int first, int last)
{ modelChanged(ColumnsRemoved, parent, first, last); }
- void modelChanged(ModelChanged change, const QModelIndex &parent, int first, int last);
+ void modelChanged(ModelChanged change, const QModelIndex &parent, int first, int last)
+ {
+ rcParent[change] = parent;
+ rcFirst[change] = first;
+ rcLast[change] = last;
+ }
private:
- QListWidget *testWidget;
- QVector<QModelIndex> rcParent;
- QVector<int> rcFirst;
- QVector<int> rcLast;
+ QListWidget *testWidget = nullptr;
+ QVector<QModelIndex> rcParent{8};
+ QVector<int> rcFirst = QVector<int>(8, 0);
+ QVector<int> rcLast = QVector<int>(8, 0);
void populate();
void checkDefaultValues();
@@ -168,7 +174,7 @@ void tst_QListWidget::moveRowsInvalid_data()
const auto createWidget = []() -> QListWidget* {
QListWidget* result = new QListWidget;
- result->addItems(QStringList{"A", "B", "C", "D", "E", "F"});
+ result->addItems({"A", "B", "C", "D", "E", "F"});
return result;
};
@@ -259,35 +265,32 @@ void tst_QListWidget::moveRows()
}
-typedef QList<int> IntList;
-
-tst_QListWidget::tst_QListWidget(): testWidget(0), rcParent(8), rcFirst(8,0), rcLast(8,0)
-{
-}
-
void tst_QListWidget::initTestCase()
{
qRegisterMetaType<QListWidgetItem*>("QListWidgetItem*");
- testWidget = new QListWidget();
+ qRegisterMetaType<QList<QPersistentModelIndex>>("QList<QPersistentModelIndex>");
+ qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>("QAbstractItemModel::LayoutChangeHint");
+
+ testWidget = new QListWidget;
testWidget->show();
- connect(testWidget->model(), SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
- this, SLOT(rowsAboutToBeInserted(QModelIndex,int,int)));
- connect(testWidget->model(), SIGNAL(rowsInserted(QModelIndex,int,int)),
- this, SLOT(rowsInserted(QModelIndex,int,int)));
- connect(testWidget->model(), SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
- this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));
- connect(testWidget->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
- this, SLOT(rowsRemoved(QModelIndex,int,int)));
-
- connect(testWidget->model(), SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
- this, SLOT(columnsAboutToBeInserted(QModelIndex,int,int)));
- connect(testWidget->model(), SIGNAL(columnsInserted(QModelIndex,int,int)),
- this, SLOT(columnsInserted(QModelIndex,int,int)));
- connect(testWidget->model(), SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
- this, SLOT(columnsAboutToBeRemoved(QModelIndex,int,int)));
- connect(testWidget->model(), SIGNAL(columnsRemoved(QModelIndex,int,int)),
- this, SLOT(columnsRemoved(QModelIndex,int,int)));
+ connect(testWidget->model(), &QAbstractItemModel::rowsAboutToBeInserted,
+ this, &tst_QListWidget::rowsAboutToBeInserted);
+ connect(testWidget->model(), &QAbstractItemModel::rowsInserted,
+ this, &tst_QListWidget::rowsInserted);
+ connect(testWidget->model(), &QAbstractItemModel::rowsAboutToBeRemoved,
+ this, &tst_QListWidget::rowsAboutToBeRemoved);
+ connect(testWidget->model(), &QAbstractItemModel::rowsRemoved,
+ this, &tst_QListWidget::rowsRemoved);
+
+ connect(testWidget->model(), &QAbstractItemModel::columnsAboutToBeInserted,
+ this, &tst_QListWidget::columnsAboutToBeInserted);
+ connect(testWidget->model(), &QAbstractItemModel::columnsInserted,
+ this, &tst_QListWidget::columnsInserted);
+ connect(testWidget->model(), &QAbstractItemModel::columnsAboutToBeRemoved,
+ this, &tst_QListWidget::columnsAboutToBeRemoved);
+ connect(testWidget->model(), &QAbstractItemModel::columnsRemoved,
+ this, &tst_QListWidget::columnsRemoved);
checkDefaultValues();
}
@@ -300,7 +303,7 @@ void tst_QListWidget::cleanupTestCase()
void tst_QListWidget::init()
{
testWidget->clear();
- QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
}
void tst_QListWidget::checkDefaultValues()
@@ -317,7 +320,7 @@ void tst_QListWidget::populate()
addItems();
setItemHidden();
- testWidget->setCurrentIndex(testWidget->model()->index(0,0));
+ testWidget->setCurrentIndex(testWidget->model()->index(0, 0));
// setCurrentItem();
// setCurrentRow();
@@ -329,7 +332,7 @@ void tst_QListWidget::addItem()
const QString label = QString::number(count);
testWidget->addItem(label);
QCOMPARE(testWidget->count(), ++count);
- QCOMPARE(testWidget->item(testWidget->count()-1)->text(), label);
+ QCOMPARE(testWidget->item(testWidget->count() - 1)->text(), label);
}
void tst_QListWidget::addItem2()
@@ -337,7 +340,7 @@ void tst_QListWidget::addItem2()
int count = testWidget->count();
// Boundary Checking
- testWidget->addItem(0);
+ testWidget->addItem(nullptr);
QCOMPARE(testWidget->count(), count);
QListWidgetItem *item = new QListWidgetItem(QString::number(count));
@@ -356,12 +359,11 @@ void tst_QListWidget::addItems()
testWidget->addItems(QStringList());
QCOMPARE(testWidget->count(), count);
- QStringList stringList;
QString label = QString::number(count);
- stringList << QString::number(testWidget->count() + 1)
- << QString::number(testWidget->count() + 2)
- << QString::number(testWidget->count() + 3)
- << label;
+ const QStringList stringList{QString::number(testWidget->count() + 1),
+ QString::number(testWidget->count() + 2),
+ QString::number(testWidget->count() + 3),
+ label};
testWidget->addItems(stringList);
QCOMPARE(testWidget->count(), count + stringList.count());
QCOMPARE(testWidget->item(testWidget->count()-1)->text(), label);
@@ -371,7 +373,7 @@ void tst_QListWidget::addItems()
void tst_QListWidget::openPersistentEditor()
{
// Boundary checking
- testWidget->openPersistentEditor(0);
+ testWidget->openPersistentEditor(nullptr);
QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count()));
testWidget->openPersistentEditor(item);
@@ -385,7 +387,7 @@ void tst_QListWidget::closePersistentEditor()
{
// Boundary checking
int childCount = testWidget->viewport()->children().count();
- testWidget->closePersistentEditor(0);
+ testWidget->closePersistentEditor(nullptr);
QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count()));
testWidget->closePersistentEditor(item);
QCOMPARE(childCount, testWidget->viewport()->children().count());
@@ -397,7 +399,7 @@ void tst_QListWidget::closePersistentEditor()
// actual test
childCount = testWidget->viewport()->children().count();
testWidget->closePersistentEditor(item);
- QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QCOMPARE(testWidget->viewport()->children().count(), childCount - 1);
}
@@ -412,40 +414,33 @@ QT_WARNING_DISABLE_DEPRECATED
QT_WARNING_POP
#endif
- int totalHidden = 0;
- for (int i = 0; i < testWidget->model()->rowCount(); ++i)
- if (testWidget->item(i)->isHidden())
- totalHidden++;
-
+ auto countHidden = [](QListWidget *testWidget)
+ {
+ int totalHidden = 0;
+ for (int i = 0; i < testWidget->model()->rowCount(); ++i) {
+ if (testWidget->item(i)->isHidden())
+ totalHidden++;
+ }
+ return totalHidden;
+ };
+ const int totalHidden = countHidden(testWidget);
QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count()));
testWidget->addItem(item);
// Check that nothing else changed
- int newTotal = 0;
- for (int i = 0; i < testWidget->model()->rowCount(); ++i)
- if (testWidget->item(i)->isHidden())
- newTotal++;
- QCOMPARE(newTotal, totalHidden);
+ QCOMPARE(countHidden(testWidget), totalHidden);
item->setHidden(true);
QCOMPARE(item->isHidden(), true);
// Check that nothing else changed
- newTotal = 0;
- for (int i = 0; i < testWidget->model()->rowCount(); ++i)
- if (testWidget->item(i)->isHidden())
- newTotal++;
- QCOMPARE(newTotal, totalHidden + 1);
+ QCOMPARE(countHidden(testWidget), totalHidden + 1);
item->setHidden(false);
QCOMPARE(item->isHidden(), false);
// Check that nothing else changed
- newTotal = 0;
- for (int i = 0; i < testWidget->model()->rowCount(); ++i)
- if (testWidget->item(i)->isHidden())
- newTotal++;
- QCOMPARE(newTotal, totalHidden);
+ QCOMPARE(countHidden(testWidget), totalHidden);
item->setHidden(true);
}
@@ -466,11 +461,11 @@ void tst_QListWidget::setCurrentItem()
testWidget->addItem(QString::number(i));
// Boundary checking
- testWidget->setCurrentItem((QListWidgetItem *)0);
- QCOMPARE((QListWidgetItem *)0, testWidget->currentItem());
+ testWidget->setCurrentItem(nullptr);
+ QVERIFY(!testWidget->currentItem());
QListWidgetItem item;
testWidget->setCurrentItem(&item);
- QCOMPARE((QListWidgetItem *)0, testWidget->currentItem());
+ QVERIFY(!testWidget->currentItem());
// Make sure that currentItem changes to what is passed into setCurrentItem
for (int i = 0; i < testWidget->count(); ++i) {
@@ -555,7 +550,7 @@ void tst_QListWidget::editItem_data()
void tst_QListWidget::editItem()
{
// Boundary checking
- testWidget->editItem(0);
+ testWidget->editItem(nullptr);
QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count()));
testWidget->editItem(item);
@@ -593,8 +588,8 @@ void tst_QListWidget::findItems()
populate();
- for (int i=0; i < testWidget->count(); ++i)
- QCOMPARE(testWidget->findItems( (testWidget->item(i)->text()), Qt::MatchExactly).count(), 1);
+ for (int i = 0; i < testWidget->count(); ++i)
+ QCOMPARE(testWidget->findItems(testWidget->item(i)->text(), Qt::MatchExactly).count(), 1);
}
@@ -605,8 +600,7 @@ void tst_QListWidget::insertItem_data()
QTest::addColumn<QString>("itemLabel");
QTest::addColumn<int>("expectedIndex");
- QStringList initialItems;
- initialItems << "foo" << "bar";
+ const QStringList initialItems{"foo", "bar"};
QTest::newRow("Insert less then 0") << initialItems << -1 << "inserted" << 0;
QTest::newRow("Insert at 0") << initialItems << 0 << "inserted" << 0;
@@ -669,7 +663,7 @@ void tst_QListWidget::insertItems()
if (insertType == 3) {
QStringList strings;
- for (int i=0; i<rowCount; ++i)
+ for (int i = 0; i < rowCount; ++i)
strings << QString::number(i);
testWidget->insertItems(0, strings);
} else {
@@ -685,7 +679,7 @@ void tst_QListWidget::insertItems()
testWidget->insertItem(r, QString::number(r));
} else if (insertType == 3) {
QStringList strings;
- for (int i=0; i<rowCount; ++i)
+ for (int i = 0; i < rowCount; ++i)
strings << QString::number(i);
testWidget->insertItems(0, strings);
break;
@@ -702,7 +696,7 @@ void tst_QListWidget::insertItems()
QCOMPARE(testWidget->item(r)->text(), QString::number(r));
// make sure all items have view set correctly
- for (int i=0; i<testWidget->count(); ++i)
+ for (int i = 0; i < testWidget->count(); ++i)
QCOMPARE(testWidget->item(i)->listWidget(), testWidget);
QCOMPARE(itemChangedSpy.count(), 0);
@@ -845,19 +839,19 @@ void tst_QListWidget::selectedItems_data()
void tst_QListWidget::selectedItems()
{
QFETCH(int, itemCount);
- QFETCH(IntList, hiddenRows);
- QFETCH(IntList, selectedRows);
- QFETCH(IntList, expectedRows);
+ QFETCH(const IntList, hiddenRows);
+ QFETCH(const IntList, selectedRows);
+ QFETCH(const IntList, expectedRows);
QCOMPARE(testWidget->count(), 0);
//insert items
- for (int i=0; i<itemCount; ++i)
+ for (int i = 0; i < itemCount; ++i)
new QListWidgetItem(QStringLiteral("Item") + QString::number(i), testWidget);
//test the selection
testWidget->setSelectionMode(QListWidget::SingleSelection);
- for (int i=0; i<itemCount; ++i) {
+ for (int i = 0; i < itemCount; ++i) {
QListWidgetItem *item = testWidget->item(i);
item->setSelected(true);
QVERIFY(item->isSelected());
@@ -871,20 +865,20 @@ void tst_QListWidget::selectedItems()
//verify items are inserted
QCOMPARE(testWidget->count(), itemCount);
// hide items
- foreach (int row, hiddenRows)
+ for (int row : hiddenRows)
testWidget->item(row)->setHidden(true);
// select items
- foreach (int row, selectedRows)
+ for (int row : selectedRows)
testWidget->item(row)->setSelected(true);
// check that the correct number of items and the expected items are there
QList<QListWidgetItem *> selectedItems = testWidget->selectedItems();
QCOMPARE(selectedItems.count(), expectedRows.count());
- foreach (int row, expectedRows)
+ for (int row : expectedRows)
QVERIFY(selectedItems.contains(testWidget->item(row)));
//check that isSelected agrees with selectedItems
- for (int i=0; i<itemCount; ++i) {
+ for (int i = 0; i < itemCount; ++i) {
QListWidgetItem *item = testWidget->item(i);
if (item->isSelected())
QVERIFY(selectedItems.contains(item));
@@ -927,8 +921,6 @@ void tst_QListWidget::removeItems()
QCOMPARE(testWidget->item(r)->text(), QString::number(r));
else
QCOMPARE(testWidget->item(r)->text(), QString::number(r + removeRows));
-
-
}
void tst_QListWidget::moveItemsPriv_data()
@@ -967,8 +959,8 @@ void tst_QListWidget::moveItemsPriv()
QListModel *model = qobject_cast<QListModel *>(testWidget->model());
QVERIFY(model);
- QSignalSpy beginMoveSpy(model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
- QSignalSpy movedSpy(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)));
+ QSignalSpy beginMoveSpy(model, &QAbstractItemModel::rowsAboutToBeMoved);
+ QSignalSpy movedSpy(model, &QAbstractItemModel::rowsMoved);
model->move(srcRow, dstRow);
if (shouldHaveSignaled) {
@@ -1034,31 +1026,31 @@ void tst_QListWidget::itemStreaming()
void tst_QListWidget::sortItems_data()
{
- QTest::addColumn<int>("order");
+ QTest::addColumn<Qt::SortOrder>("order");
QTest::addColumn<QVariantList>("initialList");
QTest::addColumn<QVariantList>("expectedList");
QTest::addColumn<IntList>("expectedRows");
QTest::newRow("ascending strings")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QVariantList() << QString("c") << QString("d") << QString("a") << QString("b"))
<< (QVariantList() << QString("a") << QString("b") << QString("c") << QString("d"))
<< (IntList() << 2 << 3 << 0 << 1);
QTest::newRow("descending strings")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QVariantList() << QString("c") << QString("d") << QString("a") << QString("b"))
<< (QVariantList() << QString("d") << QString("c") << QString("b") << QString("a"))
<< (IntList() << 1 << 0 << 3 << 2);
QTest::newRow("ascending numbers")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QVariantList() << 1 << 11 << 2 << 22)
<< (QVariantList() << 1 << 2 << 11 << 22)
<< (IntList() << 0 << 2 << 1 << 3);
QTest::newRow("descending numbers")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QVariantList() << 1 << 11 << 2 << 22)
<< (QVariantList() << 22 << 11 << 2 << 1)
<< (IntList() << 3 << 1 << 2 << 0);
@@ -1066,22 +1058,22 @@ void tst_QListWidget::sortItems_data()
void tst_QListWidget::sortItems()
{
- QFETCH(int, order);
- QFETCH(QVariantList, initialList);
- QFETCH(QVariantList, expectedList);
- QFETCH(IntList, expectedRows);
+ QFETCH(Qt::SortOrder, order);
+ QFETCH(const QVariantList, initialList);
+ QFETCH(const QVariantList, expectedList);
+ QFETCH(const IntList, expectedRows);
- foreach (const QVariant &data, initialList) {
+ for (const QVariant &data : initialList) {
QListWidgetItem *item = new QListWidgetItem(testWidget);
item->setData(Qt::DisplayRole, data);
}
QAbstractItemModel *model = testWidget->model();
- QList<QPersistentModelIndex> persistent;
+ QVector<QPersistentModelIndex> persistent;
for (int j = 0; j < model->rowCount(QModelIndex()); ++j)
persistent << model->index(j, 0, QModelIndex());
- testWidget->sortItems(static_cast<Qt::SortOrder>(order));
+ testWidget->sortItems(order);
QCOMPARE(testWidget->count(), expectedList.count());
for (int i = 0; i < testWidget->count(); ++i)
@@ -1093,7 +1085,7 @@ void tst_QListWidget::sortItems()
void tst_QListWidget::sortHiddenItems_data()
{
- QTest::addColumn<int>("order");
+ QTest::addColumn<Qt::SortOrder>("order");
QTest::addColumn<QStringList>("initialList");
QTest::addColumn<QStringList>("expectedList");
QTest::addColumn<IntList>("expectedRows");
@@ -1110,21 +1102,21 @@ void tst_QListWidget::sortHiddenItems_data()
}
QTest::newRow("descending order, 20 items")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< initial
<< expected
<< rowOrder
<< visible;
QTest::newRow("ascending order")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "c" << "d" << "a" << "b")
<< (QStringList() << "a" << "b" << "c" << "d")
<< (IntList() << 2 << 3 << 0 << 1)
<< (IntList() << 1 << 0 << 1 << 0);
QTest::newRow("descending order")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QStringList() << "c" << "d" << "a" << "b")
<< (QStringList() << "d" << "c" << "b" << "a")
<< (IntList() << 1 << 0 << 3 << 2)
@@ -1133,7 +1125,7 @@ void tst_QListWidget::sortHiddenItems_data()
void tst_QListWidget::sortHiddenItems()
{
- QFETCH(int, order);
+ QFETCH(Qt::SortOrder, order);
QFETCH(QStringList, initialList);
QFETCH(QStringList, expectedList);
QFETCH(IntList, expectedRows);
@@ -1144,14 +1136,14 @@ void tst_QListWidget::sortHiddenItems()
tw->addItems(initialList);
QAbstractItemModel *model = tw->model();
- QList<QPersistentModelIndex> persistent;
+ QVector<QPersistentModelIndex> persistent;
for (int j = 0; j < model->rowCount(QModelIndex()); ++j) {
persistent << model->index(j, 0, QModelIndex());
tw->setRowHidden(j, j & 1); // every odd is hidden
}
tw->setSortingEnabled(true);
- tw->sortItems(static_cast<Qt::SortOrder>(order));
+ tw->sortItems(order);
QCOMPARE(tw->count(), expectedList.count());
for (int i = 0; i < tw->count(); ++i) {
@@ -1165,50 +1157,35 @@ void tst_QListWidget::sortHiddenItems()
delete tw;
}
-void tst_QListWidget::modelChanged(ModelChanged change, const QModelIndex &parent,
- int first, int last)
+class TestListWidget : public QListWidget
{
- rcParent[change] = parent;
- rcFirst[change] = first;
- rcLast[change] = last;
-}
-
-class TestListWidget : public QListWidget {
+ Q_OBJECT
public:
- TestListWidget() : QListWidget()
- {
-
- }
- State getState() {return QListWidget::state();}
-
- void closeEditor(QWidget *w, QAbstractItemDelegate::EndEditHint hint) {
- QListWidget::closeEditor(w, hint);
- }
+ using QListWidget::QListWidget;
+ using QListWidget::state;
+ using QListWidget::closeEditor;
+ using QListWidget::mimeData;
+ using QListWidget::indexFromItem;
- bool isEditingState(QListWidgetItem *item) {
- Q_UNUSED(item);
+ bool isEditingState() const {
return QListWidget::state() == QListWidget::EditingState;
}
-
- using QListWidget::mimeData;
- using QListWidget::indexFromItem;
};
void tst_QListWidget::closeEditor()
{
TestListWidget w;
- QStringList labels = (QStringList() << "a" << "b" << "c" << "d");
- w.addItems(labels);
+ w.addItems({"a", "b", "c", "d"});
QListWidgetItem *item = w.item(0);
item->setFlags(item->flags() | Qt::ItemIsEditable);
QVERIFY(item);
w.editItem(item);
- QVERIFY(w.isEditingState(item));
+ QVERIFY(w.isEditingState());
w.reset();
- QVERIFY(!w.isEditingState(item));
+ QVERIFY(!w.isEditingState());
}
void tst_QListWidget::setData_data()
@@ -1267,15 +1244,15 @@ void tst_QListWidget::setData()
QCOMPARE(roles.count(), values.count());
- for (int manipulateModel=0; manipulateModel<2; ++manipulateModel) {
+ for (int manipulateModel = 0; manipulateModel < 2; ++manipulateModel) {
testWidget->clear();
testWidget->insertItems(0, initialItems);
QCOMPARE(testWidget->count(), initialItems.count());
- QSignalSpy itemChanged(testWidget, SIGNAL(itemChanged(QListWidgetItem*)));
- QSignalSpy dataChanged(testWidget->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)));
+ QSignalSpy itemChanged(testWidget, &QListWidget::itemChanged);
+ QSignalSpy dataChanged(testWidget->model(), &QAbstractItemModel::dataChanged);
- for (int i=0; i < roles.count(); ++i) {
+ for (int i = 0; i < roles.count(); ++i) {
if (manipulateModel)
testWidget->model()->setData(
testWidget->model()->index(itemIndex, 0, testWidget->rootIndex()),
@@ -1286,7 +1263,7 @@ void tst_QListWidget::setData()
}
// make sure the data is actually set
- for (int i=0; i < roles.count(); ++i)
+ for (int i = 0; i < roles.count(); ++i)
QCOMPARE(testWidget->item(itemIndex)->data(roles.at(i)), values.at(i));
// make sure we get the right number of emits
@@ -1297,50 +1274,50 @@ void tst_QListWidget::setData()
void tst_QListWidget::insertItemsWithSorting_data()
{
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<QStringList>("initialItems");
QTest::addColumn<QStringList>("insertItems");
QTest::addColumn<QStringList>("expectedItems");
QTest::addColumn<IntList>("expectedRows");
QTest::newRow("() + (a) = (a)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< QStringList()
<< (QStringList() << "a")
<< (QStringList() << "a")
<< IntList();
QTest::newRow("() + (c, b, a) = (a, b, c)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< QStringList()
<< (QStringList() << "c" << "b" << "a")
<< (QStringList() << "a" << "b" << "c")
<< IntList();
QTest::newRow("() + (a, b, c) = (c, b, a)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< QStringList()
<< (QStringList() << "a" << "b" << "c")
<< (QStringList() << "c" << "b" << "a")
<< IntList();
QTest::newRow("(a) + (b) = (a, b)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< QStringList("a")
<< (QStringList() << "b")
<< (QStringList() << "a" << "b")
<< (IntList() << 0);
QTest::newRow("(a) + (b) = (b, a)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< QStringList("a")
<< (QStringList() << "b")
<< (QStringList() << "b" << "a")
<< (IntList() << 1);
QTest::newRow("(a, c, b) + (d) = (a, b, c, d)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "b")
<< (QStringList() << "d")
<< (QStringList() << "a" << "b" << "c" << "d")
<< (IntList() << 0 << 1 << 2);
QTest::newRow("(b, c, a) + (d) = (d, c, b, a)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QStringList() << "b" << "c" << "a")
<< (QStringList() << "d")
<< (QStringList() << "d" << "c" << "b" << "a")
@@ -1350,38 +1327,38 @@ void tst_QListWidget::insertItemsWithSorting_data()
IntList reverseRows;
QStringList ascendingItems;
QStringList reverseItems;
- for (int i = 'a'; i <= 'z'; ++i) {
+ for (char i = 'a'; i <= 'z'; ++i) {
ascendingItems << QString(1, QLatin1Char(i));
reverseItems << QString(1, QLatin1Char('z' - i + 'a'));
ascendingRows << i - 'a';
reverseRows << 'z' - i + 'a';
}
QTest::newRow("() + (sorted items) = (sorted items)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< QStringList()
<< ascendingItems
<< ascendingItems
<< IntList();
QTest::newRow("(sorted items) + () = (sorted items)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< ascendingItems
<< QStringList()
<< ascendingItems
<< ascendingRows;
QTest::newRow("() + (ascending items) = (reverse items)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< QStringList()
<< ascendingItems
<< reverseItems
<< IntList();
QTest::newRow("(reverse items) + () = (ascending items)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< reverseItems
<< QStringList()
<< ascendingItems
<< ascendingRows;
QTest::newRow("(reverse items) + () = (reverse items)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< reverseItems
<< QStringList()
<< reverseItems
@@ -1391,16 +1368,16 @@ void tst_QListWidget::insertItemsWithSorting_data()
void tst_QListWidget::insertItemsWithSorting()
{
- QFETCH(int, sortOrder);
- QFETCH(QStringList, initialItems);
- QFETCH(QStringList, insertItems);
- QFETCH(QStringList, expectedItems);
- QFETCH(IntList, expectedRows);
+ QFETCH(Qt::SortOrder, sortOrder);
+ QFETCH(const QStringList, initialItems);
+ QFETCH(const QStringList, insertItems);
+ QFETCH(const QStringList, expectedItems);
+ QFETCH(const IntList, expectedRows);
for (int method = 0; method < 5; ++method) {
QListWidget w;
w.setSortingEnabled(true);
- w.sortItems(static_cast<Qt::SortOrder>(sortOrder));
+ w.sortItems(sortOrder);
w.addItems(initialItems);
QAbstractItemModel *model = w.model();
@@ -1411,8 +1388,8 @@ void tst_QListWidget::insertItemsWithSorting()
switch (method) {
case 0:
// insert using item constructor
- for (int i = 0; i < insertItems.size(); ++i)
- new QListWidgetItem(insertItems.at(i), &w);
+ for (const QString &str : insertItems)
+ new QListWidgetItem(str, &w);
break;
case 1:
// insert using insertItems()
@@ -1420,8 +1397,8 @@ void tst_QListWidget::insertItemsWithSorting()
break;
case 2:
// insert using insertItem()
- for (int i = 0; i < insertItems.size(); ++i)
- w.insertItem(0, insertItems.at(i));
+ for (const QString &str : insertItems)
+ w.insertItem(0, str);
break;
case 3:
// insert using addItems()
@@ -1429,8 +1406,8 @@ void tst_QListWidget::insertItemsWithSorting()
break;
case 4:
// insert using addItem()
- for (int i = 0; i < insertItems.size(); ++i)
- w.addItem(insertItems.at(i));
+ for (const QString &str : insertItems)
+ w.addItem(str);
break;
}
QCOMPARE(w.count(), expectedItems.count());
@@ -1444,7 +1421,7 @@ void tst_QListWidget::insertItemsWithSorting()
void tst_QListWidget::changeDataWithSorting_data()
{
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<QStringList>("initialItems");
QTest::addColumn<int>("itemIndex");
QTest::addColumn<QString>("newValue");
@@ -1453,49 +1430,49 @@ void tst_QListWidget::changeDataWithSorting_data()
QTest::addColumn<bool>("reorderingExpected");
QTest::newRow("change a to b in (a)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a")
<< 0 << "b"
<< (QStringList() << "b")
<< (IntList() << 0)
<< false;
QTest::newRow("change a to b in (a, c)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c")
<< 0 << "b"
<< (QStringList() << "b" << "c")
<< (IntList() << 0 << 1)
<< false;
QTest::newRow("change a to c in (a, b)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "b")
<< 0 << "c"
<< (QStringList() << "b" << "c")
<< (IntList() << 1 << 0)
<< true;
QTest::newRow("change c to a in (c, b)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QStringList() << "c" << "b")
<< 0 << "a"
<< (QStringList() << "b" << "a")
<< (IntList() << 1 << 0)
<< true;
QTest::newRow("change e to i in (a, c, e, g)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "e" << "g")
<< 2 << "i"
<< (QStringList() << "a" << "c" << "g" << "i")
<< (IntList() << 0 << 1 << 3 << 2)
<< true;
QTest::newRow("change e to a in (c, e, g, i)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "c" << "e" << "g" << "i")
<< 1 << "a"
<< (QStringList() << "a" << "c" << "g" << "i")
<< (IntList() << 1 << 0 << 2 << 3)
<< true;
QTest::newRow("change e to f in (c, e, g, i)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "c" << "e" << "g" << "i")
<< 1 << "f"
<< (QStringList() << "c" << "f" << "g" << "i")
@@ -1539,7 +1516,7 @@ void tst_QListWidget::itemData()
void tst_QListWidget::changeDataWithSorting()
{
- QFETCH(int, sortOrder);
+ QFETCH(Qt::SortOrder, sortOrder);
QFETCH(QStringList, initialItems);
QFETCH(int, itemIndex);
QFETCH(QString, newValue);
@@ -1549,16 +1526,16 @@ void tst_QListWidget::changeDataWithSorting()
QListWidget w;
w.setSortingEnabled(true);
- w.sortItems(static_cast<Qt::SortOrder>(sortOrder));
+ w.sortItems(sortOrder);
w.addItems(initialItems);
QAbstractItemModel *model = w.model();
- QList<QPersistentModelIndex> persistent;
+ QVector<QPersistentModelIndex> persistent;
for (int j = 0; j < model->rowCount(QModelIndex()); ++j)
persistent << model->index(j, 0, QModelIndex());
- QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
- QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged()));
+ QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged);
+ QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged);
QListWidgetItem *item = w.item(itemIndex);
item->setText(newValue);
@@ -1566,7 +1543,7 @@ void tst_QListWidget::changeDataWithSorting()
QCOMPARE(w.item(i)->text(), expectedItems.at(i));
for (int j = 0; j < persistent.count(); ++j) {
if (persistent.at(j).row() == i) // the same toplevel row
- QCOMPARE(persistent.at(j).internalPointer(), (void *)w.item(i));
+ QCOMPARE(persistent.at(j).internalPointer(), static_cast<void *>(w.item(i)));
}
}
@@ -1595,13 +1572,12 @@ void tst_QListWidget::itemWidget()
#ifndef Q_OS_MAC
class MyListWidget : public QListWidget
{
+ Q_OBJECT
public:
- MyListWidget(QWidget *parent=0)
- : QListWidget(parent)
- {
- }
+ using QListWidget::QListWidget;
- void paintEvent(QPaintEvent *e) {
+ void paintEvent(QPaintEvent *e) override
+ {
painted += e->region();
QListWidget::paintEvent(e);
}
@@ -1649,7 +1625,7 @@ void tst_QListWidget::fastScroll()
void tst_QListWidget::insertUnchanged()
{
QListWidget w;
- QSignalSpy itemChangedSpy(&w, SIGNAL(itemChanged(QListWidgetItem*)));
+ QSignalSpy itemChangedSpy(&w, &QListWidget::itemChanged);
QListWidgetItem item("foo", &w);
QCOMPARE(itemChangedSpy.count(), 0);
}
@@ -1670,9 +1646,9 @@ void tst_QListWidget::task199503_crashWhenCleared()
{
//we test here for a crash that would occur if you clear the items in the currentItemChanged signal
QListWidget w;
- w.addItems( QStringList() << "item1" << "item2" << "item3");
+ w.addItems({"item1", "item2", "item3"});
w.setCurrentRow(0);
- w.connect(&w, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(clear()));
+ w.connect(&w, &QListWidget::currentItemChanged, &w, &QListWidget::clear);
w.setCurrentRow(1);
}
@@ -1680,21 +1656,22 @@ void tst_QListWidget::task217070_scrollbarsAdjusted()
{
//This task was mailing for style using SH_ScrollView_FrameOnlyAroundContents such as QMotifStyle
QListWidget v;
- for (int i = 0; i<200;i++)
+ for (int i = 0; i < 200;i++)
v.addItem(QString::number(i));
v.show();
v.setViewMode(QListView::IconMode);
v.setResizeMode(QListView::Adjust);
v.setUniformItemSizes(true);
- v.resize(160,100);
+ v.resize(160, 100);
QVERIFY(QTest::qWaitForWindowActive(&v));
QScrollBar *hbar = v.horizontalScrollBar();
QScrollBar *vbar = v.verticalScrollBar();
QVERIFY(hbar && vbar);
- for(int f=150; f>90 ; f--) {
- v.resize(f,100);
- QTest::qWait(30);
- QVERIFY(vbar->style()->styleHint(QStyle::SH_ScrollBar_Transient, 0, vbar) || vbar->isVisible());
+ const auto style = vbar->style();
+ for (int f = 150; f > 90 ; f--) {
+ v.resize(f, 100);
+ QTRY_VERIFY(style->styleHint(QStyle::SH_ScrollBar_Transient, nullptr, vbar) ||
+ vbar->isVisible());
//the horizontal scrollbar must not be visible.
QVERIFY(!hbar->isVisible());
}
@@ -1711,12 +1688,11 @@ void tst_QListWidget::task258949_keypressHangup()
}
lw.show();
- lw.setCurrentIndex(lw.model()->index(0,0));
- QCOMPARE(lw.currentIndex(), lw.model()->index(0,0));
+ lw.setCurrentIndex(lw.model()->index(0, 0));
+ QCOMPARE(lw.currentIndex(), lw.model()->index(0, 0));
QTest::qWait(30);
QTest::keyPress(&lw, '1'); //this used to freeze
- QTest::qWait(30);
- QCOMPARE(lw.currentIndex(), lw.model()->index(0,0));
+ QTRY_COMPARE(lw.currentIndex(), lw.model()->index(0, 0));
}
void tst_QListWidget::QTBUG8086_currentItemChangedOnClick()
@@ -1735,25 +1711,26 @@ void tst_QListWidget::QTBUG8086_currentItemChangedOnClick()
edit.setFocus();
win.show();
- QSignalSpy spy(&list, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)));
+ QSignalSpy spy(&list, &QListWidget::currentItemChanged);
QVERIFY(QTest::qWaitForWindowExposed(&win));
QCOMPARE(spy.count(), 0);
- QTest::mouseClick(list.viewport(), Qt::LeftButton, 0, list.visualItemRect(list.item(2)).center());
+ QTest::mouseClick(list.viewport(), Qt::LeftButton, {},
+ list.visualItemRect(list.item(2)).center());
QCOMPARE(spy.count(), 1);
-
}
-class ItemDelegate : public QItemDelegate
+class ItemDelegate : public QStyledItemDelegate
{
+ Q_OBJECT
public:
- ItemDelegate(QObject *parent = 0) : QItemDelegate(parent)
- {}
- virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
+ using QStyledItemDelegate::QStyledItemDelegate;
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
+ const QModelIndex &) const override
{
QLineEdit *lineEdit = new QLineEdit(parent);
lineEdit->setFrame(false);
@@ -1775,10 +1752,10 @@ void tst_QListWidget::QTBUG14363_completerWithAnyKeyPressedEditTriggers()
new QListWidgetItem(QLatin1String("completer"), &listWidget);
listWidget.show();
listWidget.setCurrentItem(item);
- qApp->setActiveWindow(&listWidget);
+ QApplication::setActiveWindow(&listWidget);
QVERIFY(QTest::qWaitForWindowActive(&listWidget));
listWidget.setFocus();
- QCOMPARE(qApp->focusWidget(), &listWidget);
+ QCOMPARE(QApplication::focusWidget(), &listWidget);
QTest::keyClick(listWidget.viewport(), Qt::Key_C);
@@ -1792,41 +1769,27 @@ void tst_QListWidget::mimeData()
{
TestListWidget list;
- for (int x = 0; x < 10; ++x) {
- QListWidgetItem *item = new QListWidgetItem(QStringLiteral("123"));
- list.addItem(item);
- }
+ for (int x = 0; x < 10; ++x)
+ list.addItem(new QListWidgetItem(QStringLiteral("123")));
- QList<QListWidgetItem *> tableWidgetItemList;
- QModelIndexList modelIndexList;
+ const QList<QListWidgetItem *> tableWidgetItemList{list.item(1)};
+ const QModelIndexList modelIndexList{list.indexFromItem(list.item(1))};
// do these checks more than once to ensure that the "cached indexes" work as expected
- QVERIFY(!list.mimeData(tableWidgetItemList));
- QVERIFY(!list.model()->mimeData(modelIndexList));
- QVERIFY(!list.model()->mimeData(modelIndexList));
- QVERIFY(!list.mimeData(tableWidgetItemList));
-
- tableWidgetItemList << list.item(1);
- modelIndexList << list.indexFromItem(list.item(1));
-
QMimeData *data;
+ for (int i = 0; i < 2; ++i) {
+ QVERIFY(!list.mimeData({}));
+ QVERIFY(!list.model()->mimeData({}));
- QVERIFY((data = list.mimeData(tableWidgetItemList)));
- delete data;
-
- QVERIFY((data = list.model()->mimeData(modelIndexList)));
- delete data;
-
- QVERIFY((data = list.model()->mimeData(modelIndexList)));
- delete data;
+ QVERIFY((data = list.mimeData(tableWidgetItemList)));
+ delete data;
- QVERIFY((data = list.mimeData(tableWidgetItemList)));
- delete data;
+ QVERIFY((data = list.model()->mimeData(modelIndexList)));
+ delete data;
+ }
// check the saved data is actually the same
-
QMimeData *data2;
-
data = list.mimeData(tableWidgetItemList);
data2 = list.model()->mimeData(modelIndexList);
@@ -1850,13 +1813,14 @@ void tst_QListWidget::QTBUG50891_ensureSelectionModelSignalConnectionsAreSet()
list.show();
QVERIFY(QTest::qWaitForWindowExposed(&list));
- QSignalSpy currentItemChangedSpy(&list, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)));
- QSignalSpy itemSelectionChangedSpy(&list, SIGNAL(itemSelectionChanged()));
+ QSignalSpy currentItemChangedSpy(&list, &QListWidget::currentItemChanged);
+ QSignalSpy itemSelectionChangedSpy(&list, &QListWidget::itemSelectionChanged);
QCOMPARE(currentItemChangedSpy.count(), 0);
QCOMPARE(itemSelectionChangedSpy.count(), 0);
- QTest::mouseClick(list.viewport(), Qt::LeftButton, 0, list.visualItemRect(list.item(2)).center());
+ QTest::mouseClick(list.viewport(), Qt::LeftButton, {},
+ list.visualItemRect(list.item(2)).center());
QCOMPARE(currentItemChangedSpy.count(), 1);
QCOMPARE(itemSelectionChangedSpy.count(), 1);
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
index 35c0c6c606..09990ab70a 100644
--- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
+++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
@@ -26,19 +26,24 @@
**
****************************************************************************/
-
-#include <QtGui/QtGui>
-#include <QtWidgets/QtWidgets>
+#include <QIdentityProxyModel>
+#include <QLabel>
+#include <QLineEdit>
+#include <QScrollBar>
+#include <QSignalSpy>
+#include <QSortFilterProxyModel>
+#include <QStandardItemModel>
+#include <QStringListModel>
+#include <QStyledItemDelegate>
+#include <QTableView>
+#include <QTest>
+#include <private/qapplication_p.h>
#include <private/qtablewidget_p.h>
-#include <QtTest/QtTest>
-#include "private/qapplication_p.h"
+#include <private/qtesthelpers_p.h>
#if QT_CONFIG(textmarkdownwriter)
-#include "private/qtextmarkdownwriter_p.h"
+#include <private/qtextmarkdownwriter_p.h>
#endif
-#include <algorithm>
-
-#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
@@ -49,14 +54,241 @@ using namespace QTestPrivate;
#define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) (void)false
#endif
-typedef QList<int> IntList;
+Q_DECLARE_METATYPE(Qt::Key);
+Q_DECLARE_METATYPE(Qt::KeyboardModifier);
+Q_DECLARE_METATYPE(QItemSelectionModel::SelectionFlag);
+using BoolList = QVector<bool>;
+using IntList = QVector<int>;
+using KeyList = QVector<Qt::Key>;
+using SpanList = QVector<QRect>;
+
+class QtTestTableModel: public QAbstractTableModel
+{
+ Q_OBJECT
+
+signals:
+ void invalidIndexEncountered() const;
+
+public slots:
+ bool submit() override { ++submit_count; return QAbstractTableModel::submit(); }
+
+public:
+ QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = nullptr)
+ : QAbstractTableModel(parent), row_count(rows), column_count(columns)
+ {}
+
+ int rowCount(const QModelIndex& = QModelIndex()) const override
+ {
+ return row_count;
+ }
+
+ int columnCount(const QModelIndex& = QModelIndex()) const override
+ {
+ return column_count;
+ }
+
+ bool isEditable(const QModelIndex &) const { return true; }
+
+ Qt::ItemFlags flags(const QModelIndex &index) const override
+ {
+ Qt::ItemFlags index_flags = QAbstractTableModel::flags(index);
+ if (disabled_rows.contains(index.row())
+ || disabled_columns.contains(index.column()))
+ index_flags &= ~Qt::ItemIsEnabled;
+ return index_flags;
+ }
+
+ void disableRow(int row)
+ {
+ disabled_rows.insert(row);
+ }
+
+ void enableRow(int row)
+ {
+ disabled_rows.remove(row);
+ }
+
+ void disableColumn(int column)
+ {
+ disabled_columns.insert(column);
+ }
+
+ void enableColumn(int column)
+ {
+ disabled_columns.remove(column);
+ }
+
+ QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override
+ {
+ if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) {
+ qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx;
+ emit invalidIndexEncountered();
+ return QVariant();
+ }
+
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
+ return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',')
+ + QString::number(idx.column()) + QLatin1String(",0]");
+ }
+
+ return QVariant();
+ }
+
+ bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start > row_count)
+ return false;
+
+ beginInsertRows(parent, start, start + count - 1);
+ row_count += count;
+ endInsertRows();
+ return true;
+ }
+
+ bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start >= row_count || row_count < count)
+ return false;
+
+ beginRemoveRows(parent, start, start + count - 1);
+ row_count -= count;
+ endRemoveRows();
+ return true;
+ }
+
+ void removeLastRow()
+ {
+ beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1);
+ --row_count;
+ endRemoveRows();
+ }
+
+ void removeAllRows()
+ {
+ beginRemoveRows(QModelIndex(), 0, row_count - 1);
+ row_count = 0;
+ endRemoveRows();
+ }
+
+ bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start > column_count)
+ return false;
+
+ beginInsertColumns(parent, start, start + count - 1);
+ column_count += count;
+ endInsertColumns();
+ return true;
+ }
+
+ bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start >= column_count || column_count < count)
+ return false;
+
+ beginRemoveColumns(parent, start, start + count - 1);
+ column_count -= count;
+ endRemoveColumns();
+ return true;
+ }
+
+ void removeLastColumn()
+ {
+ beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1);
+ --column_count;
+ endRemoveColumns();
+ }
+
+ void removeAllColumns()
+ {
+ beginRemoveColumns(QModelIndex(), 0, column_count - 1);
+ column_count = 0;
+ endRemoveColumns();
+ }
+
+ bool canFetchMore(const QModelIndex &) const override
+ {
+ return can_fetch_more;
+ }
+
+ void fetchMore(const QModelIndex &) override
+ {
+ ++fetch_more_count;
+ }
-typedef QList<bool> BoolList;
+ QSet<int> disabled_rows;
+ QSet<int> disabled_columns;
+ int row_count;
+ int column_count;
+ int submit_count = 0;
+ int fetch_more_count = 0;
+ bool can_fetch_more = false;
+};
+
+class QtTestTableView : public QTableView
+{
+ Q_OBJECT
+public:
+ using QTableView::QTableView;
+
+ void setModel(QAbstractItemModel *model) override
+ {
+ QTableView::setModel(model);
+ connect(selectionModel(), &QItemSelectionModel::currentChanged,
+ this, &QtTestTableView::slotCurrentChanged);
+ connect(selectionModel(), &QItemSelectionModel::selectionChanged,
+ this, &QtTestTableView::itemSelectionChanged);
+ // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes.
+ horizontalHeader()->setMinimumSectionSize(0);
+ verticalHeader()->setMinimumSectionSize(0);
+ }
+
+ using QTableView::moveCursor;
+ using QTableView::isIndexHidden;
+ using QTableView::setSelection;
+ using QTableView::selectedIndexes;
+ using QTableView::sizeHintForRow;
+ using QTableView::viewOptions;
+
+ bool checkSignalOrder = false;
+public slots:
+ void slotCurrentChanged(QModelIndex, QModelIndex) {
+ hasCurrentChanged++;
+ if (checkSignalOrder)
+ QVERIFY(hasCurrentChanged > hasSelectionChanged);
+ }
+
+ void itemSelectionChanged(QItemSelection , QItemSelection ) {
+ hasSelectionChanged++;
+ if (checkSignalOrder)
+ QVERIFY(hasCurrentChanged >= hasSelectionChanged);
+ }
+private:
+ int hasCurrentChanged = 0;
+ int hasSelectionChanged = 0;
+
+ friend class tst_QTableView;
+ friend struct QMetaTypeId<QtTestTableView::CursorAction>;
+};
+Q_DECLARE_METATYPE(QtTestTableView::CursorAction);
+
+class QtTestItemDelegate : public QStyledItemDelegate
+{
+public:
+ QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override
+ {
+ return hint;
+ }
+
+ QSize hint;
+};
class tst_QTableView : public QObject
{
Q_OBJECT
+private:
+ using CursorActionList = QVector<QtTestTableView::CursorAction>;
private slots:
void getSetCheck();
@@ -236,14 +468,14 @@ void tst_QTableView::getSetCheck()
QHeaderView *var1 = new QHeaderView(Qt::Horizontal);
obj1.setHorizontalHeader(var1);
QCOMPARE(var1, obj1.horizontalHeader());
- obj1.setHorizontalHeader((QHeaderView *)0);
+ obj1.setHorizontalHeader(nullptr);
QCOMPARE(var1, obj1.horizontalHeader());
delete var1;
QHeaderView *var2 = new QHeaderView(Qt::Vertical);
obj1.setVerticalHeader(var2);
QCOMPARE(var2, obj1.verticalHeader());
- obj1.setVerticalHeader((QHeaderView *)0);
+ obj1.setVerticalHeader(nullptr);
QCOMPARE(var2, obj1.verticalHeader());
delete var2;
@@ -251,283 +483,12 @@ void tst_QTableView::getSetCheck()
obj1.setCornerButtonEnabled(false);
QCOMPARE(obj1.isCornerButtonEnabled(), false);
}
-
-class QtTestTableModel: public QAbstractTableModel
-{
- Q_OBJECT
-
-signals:
- void invalidIndexEncountered() const;
-
-public slots:
- bool submit() { ++submit_count; return QAbstractTableModel::submit(); }
-
-public:
- QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0)
- : QAbstractTableModel(parent),
- row_count(rows),
- column_count(columns),
- submit_count(0),
- can_fetch_more(false),
- fetch_more_count(0),
- disabled_rows(),
- disabled_columns() {}
-
- int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; }
- int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; }
- bool isEditable(const QModelIndex &) const { return true; }
-
- Qt::ItemFlags flags(const QModelIndex &index) const
- {
- Qt::ItemFlags index_flags = QAbstractTableModel::flags(index);
- if (disabled_rows.contains(index.row())
- || disabled_columns.contains(index.column()))
- index_flags &= ~Qt::ItemIsEnabled;
- return index_flags;
- }
-
- void disableRow(int row)
- {
- disabled_rows.insert(row);
- }
-
- void enableRow(int row)
- {
- disabled_rows.remove(row);
- }
-
- void disableColumn(int column)
- {
- disabled_columns.insert(column);
- }
-
- void enableColumn(int column)
- {
- disabled_columns.remove(column);
- }
-
- QVariant data(const QModelIndex &idx, int role) const
- {
- if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) {
- qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx;
- emit invalidIndexEncountered();
- return QVariant();
- }
-
- if (role == Qt::DisplayRole || role == Qt::EditRole) {
- return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',')
- + QString::number(idx.column()) + QLatin1String(",0]");
- }
-
- return QVariant();
- }
-
- bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start > row_count)
- return false;
-
- beginInsertRows(parent, start, start + count - 1);
- row_count += count;
- endInsertRows();
- return true;
- }
-
- bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start >= row_count || row_count < count)
- return false;
-
- beginRemoveRows(parent, start, start + count - 1);
- row_count -= count;
- endRemoveRows();
- return true;
- }
-
- void removeLastRow()
- {
- beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1);
- --row_count;
- endRemoveRows();
- }
-
- void removeAllRows()
- {
- beginRemoveRows(QModelIndex(), 0, row_count - 1);
- row_count = 0;
- endRemoveRows();
- }
-
- bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start > column_count)
- return false;
-
- beginInsertColumns(parent, start, start + count - 1);
- column_count += count;
- endInsertColumns();
- return true;
- }
-
- bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start >= column_count || column_count < count)
- return false;
-
- beginRemoveColumns(parent, start, start + count - 1);
- column_count -= count;
- endRemoveColumns();
- return true;
- }
-
- void removeLastColumn()
- {
- beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1);
- --column_count;
- endRemoveColumns();
- }
-
- void removeAllColumns()
- {
- beginRemoveColumns(QModelIndex(), 0, column_count - 1);
- column_count = 0;
- endRemoveColumns();
- }
-
- bool canFetchMore(const QModelIndex &) const
- {
- return can_fetch_more;
- }
-
- void fetchMore(const QModelIndex &)
- {
- ++fetch_more_count;
- }
-
- void reset()
- {
- beginResetModel();
- endResetModel();
- }
-
- int row_count;
- int column_count;
- int submit_count;
- bool can_fetch_more;
- int fetch_more_count;
- QSet<int> disabled_rows;
- QSet<int> disabled_columns;
-};
-
-class QtTestTableView : public QTableView
-{
-Q_OBJECT
-
-public:
- QtTestTableView(QWidget *parent = 0) : QTableView(parent), checkSignalOrder(false), hasCurrentChanged(0), hasSelectionChanged(0) {}
-
- void setModel(QAbstractItemModel *model)
- {
- QTableView::setModel(model);
- connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
- this, SLOT(slotCurrentChanged(QModelIndex,QModelIndex)));
- connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
- this, SLOT(itemSelectionChanged(QItemSelection,QItemSelection)));
- // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes.
- horizontalHeader()->setMinimumSectionSize(0);
- verticalHeader()->setMinimumSectionSize(0);
- }
-
- // enum CursorAction and moveCursor() are protected in QTableView.
- enum CursorAction {
- MoveUp = QAbstractItemView::MoveUp,
- MoveDown = QAbstractItemView::MoveDown,
- MoveLeft = QAbstractItemView::MoveLeft,
- MoveRight = QAbstractItemView::MoveRight,
- MoveHome = QAbstractItemView::MoveHome,
- MoveEnd = QAbstractItemView::MoveEnd,
- MovePageUp = QAbstractItemView::MovePageUp,
- MovePageDown = QAbstractItemView::MovePageDown,
- MoveNext = QAbstractItemView::MoveNext,
- MovePrevious = QAbstractItemView::MovePrevious
- };
-
- QModelIndex doMoveCursor(QtTestTableView::CursorAction cursorAction,
- Qt::KeyboardModifiers modifiers)
- {
- return QTableView::moveCursor((QAbstractItemView::CursorAction)cursorAction, modifiers);
- }
-
- int columnWidthHint(int column) const
- {
- return sizeHintForColumn(column);
- }
-
- int rowHeightHint(int row) const
- {
- return sizeHintForRow(row);
- }
-
- bool isIndexHidden(const QModelIndex &index) const
- {
- return QTableView::isIndexHidden(index);
- }
-
- void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
- {
- QTableView::setSelection(rect, command);
- }
-
- QModelIndexList selectedIndexes() const
- {
- return QTableView::selectedIndexes();
- }
-
- int sizeHintForRow(int row) const
- {
- return QTableView::sizeHintForRow(row);
- }
-
- QStyleOptionViewItem viewOptions() const {
- return QTableView::viewOptions();
- }
-
- bool checkSignalOrder;
-public slots:
- void slotCurrentChanged(QModelIndex, QModelIndex) {
- hasCurrentChanged++;
- if (checkSignalOrder)
- QVERIFY(hasCurrentChanged > hasSelectionChanged);
- }
-
- void itemSelectionChanged(QItemSelection , QItemSelection ) {
- hasSelectionChanged++;
- if (checkSignalOrder)
- QVERIFY(hasCurrentChanged >= hasSelectionChanged);
- }
-private:
- int hasCurrentChanged;
- int hasSelectionChanged;
-
-};
-
-class QtTestItemDelegate : public QItemDelegate
-{
-public:
- QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const
- {
- return hint;
- }
-
- QSize hint;
-};
-
void tst_QTableView::noDelegate()
{
QtTestTableModel model(3, 3);
QTableView view;
view.setModel(&model);
- view.setItemDelegate(0);
+ view.setItemDelegate(nullptr);
view.show();
}
@@ -541,7 +502,7 @@ void tst_QTableView::emptyModel()
{
QtTestTableModel model;
QTableView view;
- QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
+ QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
view.setModel(&model);
view.show();
QCOMPARE(spy.count(), 0);
@@ -562,7 +523,7 @@ void tst_QTableView::removeRows()
QFETCH(int, columnCount);
QtTestTableModel model(rowCount, columnCount);
- QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
+ QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
QTableView view;
view.setModel(&model);
@@ -590,7 +551,7 @@ void tst_QTableView::removeColumns()
QFETCH(int, columnCount);
QtTestTableModel model(rowCount, columnCount);
- QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
+ QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
QTableView view;
view.setModel(&model);
@@ -608,58 +569,18 @@ void tst_QTableView::keyboardNavigation_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<bool>("tabKeyNavigation");
- QTest::addColumn<IntList>("keyPresses");
-
- QTest::newRow("16x16 model") << 16 << 16 << true
- << (IntList()
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Right
- << Qt::Key_Right
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Down
- << Qt::Key_Tab
- << Qt::Key_Backtab);
-
-
- QTest::newRow("no tab") << 8 << 8 << false
- << (IntList()
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Right
- << Qt::Key_Right
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Down
- << Qt::Key_Tab
- << Qt::Key_Backtab);
+ QTest::addColumn<KeyList>("keyPresses");
+
+ const KeyList keyList {
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Right, Qt::Key_Right,
+ Qt::Key_Up, Qt::Key_Left, Qt::Key_Left, Qt::Key_Up,
+ Qt::Key_Down, Qt::Key_Up, Qt::Key_Up, Qt::Key_Up,
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Left,
+ Qt::Key_Left, Qt::Key_Up, Qt::Key_Down, Qt::Key_Down,
+ Qt::Key_Tab, Qt::Key_Backtab};
+
+ QTest::newRow("16x16 model") << 16 << 16 << true << keyList;
+ QTest::newRow("no tab") << 8 << 8 << false << keyList;
}
void tst_QTableView::keyboardNavigation()
@@ -667,7 +588,7 @@ void tst_QTableView::keyboardNavigation()
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(bool, tabKeyNavigation);
- QFETCH(IntList, keyPresses);
+ QFETCH(const KeyList, keyPresses);
QtTestTableModel model(rowCount, columnCount);
QTableView view;
@@ -678,14 +599,12 @@ void tst_QTableView::keyboardNavigation()
view.setCurrentIndex(index);
view.show();
- qApp->setActiveWindow(&view);
+ QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
int row = rowCount - 1;
int column = columnCount - 1;
- for (int i = 0; i < keyPresses.count(); ++i) {
-
- Qt::Key key = (Qt::Key)keyPresses.at(i);
+ for (Qt::Key key : keyPresses) {
switch (key) {
case Qt::Key_Up:
@@ -785,8 +704,8 @@ void tst_QTableView::moveCursor_data()
QTest::addColumn<int>("startRow");
QTest::addColumn<int>("startColumn");
- QTest::addColumn<int>("cursorMoveAction");
- QTest::addColumn<int>("modifier");
+ QTest::addColumn<QtTestTableView::CursorAction>("cursorMoveAction");
+ QTest::addColumn<Qt::KeyboardModifier>("modifier");
QTest::addColumn<int>("expectedRow");
QTest::addColumn<int>("expectedColumn");
@@ -797,346 +716,346 @@ void tst_QTableView::moveCursor_data()
QTest::newRow("MoveRight (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveRight (3,0)")
<< 4 << 4 << -1 << -1
<< 3 << 0
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 3 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveRight (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); // ###
QTest::newRow("MoveRight, hidden column 1 (0,0)")
<< 4 << 4 << -1 << 1
<< 0 << 0
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveRight, hidden column 3 (0,2)")
<< 4 << 4 << -1 << 3
<< 0 << 2
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0); // ###
// MoveNext should in addition wrap
QTest::newRow("MoveNext (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext (0,2)")
<< 4 << 4 << -1 << -1
<< 0 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap (0,3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, hidden column 1 (0,0)")
<< 4 << 4 << -1 << 1
<< 0 << 0
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap, hidden column 3 (0,2)")
<< 4 << 4 << -1 << 3
<< 0 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap, hidden column 3 (3,2)")
<< 4 << 4 << -1 << 3
<< 3 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrapy, wrapx, hidden column 3, hidden row 3 (2,2)")
<< 4 << 4 << 3 << 3
<< 2 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap, hidden column 2, moved column from 3 to 0. (0,2)")
<< 4 << 4 << -1 << 2
<< 0 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 1 << 3 << IntPair(0,0) << IntPair(3,0);
// MoveLeft
QTest::newRow("MoveLeft (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft (0,3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft (1,0)")
<< 4 << 4 << -1 << -1
<< 1 << 0
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft, hidden column 0 (0,2)")
<< 4 << 4 << -1 << 1
<< 0 << 2
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft, hidden column 0 (0,1)")
<< 4 << 4 << -1 << 0
<< 0 << 1
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
// MovePrevious should in addition wrap
QTest::newRow("MovePrevious (0,3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious (0,1)")
<< 4 << 4 << -1 << -1
<< 0 << 1
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap (1,0)")
<< 4 << 4 << -1 << -1
<< 1 << 0
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, hidden column 1 (0,2)")
<< 4 << 4 << -1 << 1
<< 0 << 2
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, hidden column 3 (0,2)")
<< 4 << 4 << -1 << 3
<< 0 << 2
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrapy, hidden column 0 (0,1)")
<< 4 << 4 << -1 << 0
<< 0 << 1
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, hidden column 0, hidden row 0 (1,1)")
<< 4 << 4 << 0 << 0
<< 1 << 1
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, hidden column 1, moved column from 0 to 3. (1,2)")
<< 4 << 4 << -1 << 1
<< 1 << 2
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,3);
// MoveDown
QTest::newRow("MoveDown (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown (3,0)")
<< 4 << 4 << -1 << -1
<< 3 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 3 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown, hidden row 1 (0,0)")
<< 4 << 4 << 1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 2 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown, hidden row 3 (2,0)")
<< 4 << 4 << 3 << -1
<< 2 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 2 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown, hidden row 0 hidden column 0 (0,0)")
<< 4 << 4 << 0 << 0
<< 0 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 1 << 1 << IntPair(0,0) << IntPair(0,0);
// MoveUp
QTest::newRow("MoveUp (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp (3, 0)")
<< 4 << 4 << -1 << -1
<< 3 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 2 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp (0,1)")
<< 4 << 4 << -1 << -1
<< 0 << 1
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp, hidden row 1 (2,0)")
<< 4 << 4 << 1 << -1
<< 2 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp, hidden row (1,0)")
<< 4 << 4 << 0 << -1
<< 1 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
// MoveHome
QTest::newRow("MoveHome (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
+ << QtTestTableView::MoveHome << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
+ << QtTestTableView::MoveHome << Qt::NoModifier
<< 3 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome, hidden column 0 (3,3)")
<< 4 << 4 << -1 << 0
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
+ << QtTestTableView::MoveHome << Qt::NoModifier
<< 3 << 1 << IntPair(0,0) << IntPair(0,0);
// Use Ctrl modifier
QTest::newRow("MoveHome + Ctrl (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveHome << Qt::ControlModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome + Ctrl (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveHome << Qt::ControlModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome + Ctrl, hidden column 0, hidden row 0 (3,3)")
<< 4 << 4 << 0 << 0
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveHome << Qt::ControlModifier
<< 1 << 1 << IntPair(0,0) << IntPair(0,0);
// MoveEnd
QTest::newRow("MoveEnd (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
+ << QtTestTableView::MoveEnd << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
+ << QtTestTableView::MoveEnd << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd, hidden column (0,0)")
<< 4 << 4 << -1 << 3
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
+ << QtTestTableView::MoveEnd << Qt::NoModifier
<< 0<< 2 << IntPair(0,0) << IntPair(0,0);
// Use Ctrl modifier
QTest::newRow("MoveEnd + Ctrl (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd + Ctrl (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd + Ctrl, hidden column 3 (0,0)")
<< 4 << 4 << -1 << 3
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 3 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd + Ctrl, hidden column 3, hidden row 3 (0,0)")
<< 4 << 4 << 3 << 3
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 2 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageUp (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MovePageUp) << 0
+ << QtTestTableView::MovePageUp << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageUp (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MovePageUp) << 0
+ << QtTestTableView::MovePageUp << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageDown (3, 3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MovePageDown) << 0
+ << QtTestTableView::MovePageDown << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageDown (0, 3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MovePageDown) << 0
+ << QtTestTableView::MovePageDown << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
}
@@ -1148,8 +1067,8 @@ void tst_QTableView::moveCursor()
QFETCH(int, hideColumn);
QFETCH(int, startRow);
QFETCH(int, startColumn);
- QFETCH(int, cursorMoveAction);
- QFETCH(int, modifier);
+ QFETCH(QtTestTableView::CursorAction, cursorMoveAction);
+ QFETCH(Qt::KeyboardModifier, modifier);
QFETCH(int, expectedRow);
QFETCH(int, expectedColumn);
QFETCH(IntPair, moveRow);
@@ -1174,8 +1093,7 @@ void tst_QTableView::moveCursor()
QModelIndex index = model.index(startRow, startColumn);
view.setCurrentIndex(index);
- QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction,
- (Qt::KeyboardModifiers)modifier);
+ QModelIndex newIndex = view.moveCursor(cursorMoveAction, modifier);
// expected fails, task 119433
if(newIndex.row() == -1)
return;
@@ -1193,7 +1111,7 @@ void tst_QTableView::moveCursorStrikesBack_data()
QTest::addColumn<int>("startRow");
QTest::addColumn<int>("startColumn");
- QTest::addColumn<IntList>("cursorMoveActions");
+ QTest::addColumn<CursorActionList>("cursorMoveActions");
QTest::addColumn<int>("expectedRow");
QTest::addColumn<int>("expectedColumn");
@@ -1201,70 +1119,84 @@ void tst_QTableView::moveCursorStrikesBack_data()
<< IntList()
<< (IntList() << 6)
<< QRect()
- << 0 << 5 << (IntList() << int(QtTestTableView::MoveNext))
+ << 0 << 5
+ << CursorActionList{QtTestTableView::MoveNext}
<< 1 << 0;
QTest::newRow("Last column disabled 2. Task QTBUG-3878") << -1 << -1
<< IntList()
<< (IntList() << 6)
<< QRect()
- << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious))
+ << 1 << 0
+ << CursorActionList{QtTestTableView::MovePrevious}
<< 0 << 5;
QTest::newRow("Span, anchor column hidden") << -1 << 1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext))
+ << 2 << 0
+ << CursorActionList{QtTestTableView::MoveNext}
<< 2 << 1;
QTest::newRow("Span, anchor column disabled") << -1 << -1
<< IntList()
<< (IntList() << 1)
<< QRect(1, 2, 2, 3)
- << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext))
+ << 2 << 0
+ << CursorActionList{QtTestTableView::MoveNext}
<< 2 << 1;
QTest::newRow("Span, anchor row hidden") << 2 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown))
+ << 1 << 2
+ << CursorActionList{QtTestTableView::MoveDown}
<< 2 << 1;
QTest::newRow("Span, anchor row disabled") << -1 << -1
<< (IntList() << 2)
<< IntList()
<< QRect(1, 2, 2, 3)
- << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown))
+ << 1 << 2
+ << CursorActionList{QtTestTableView::MoveDown}
<< 2 << 1;
QTest::newRow("Move through span right") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 3 << 0 << (IntList() << int(QtTestTableView::MoveRight) << int(QtTestTableView::MoveRight))
+ << 3 << 0
+ << CursorActionList{QtTestTableView::MoveRight,
+ QtTestTableView::MoveRight}
<< 3 << 3;
QTest::newRow("Move through span left") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 3 << 3 << (IntList() << int(QtTestTableView::MoveLeft) << int(QtTestTableView::MoveLeft))
+ << 3 << 3
+ << CursorActionList{QtTestTableView::MoveLeft,
+ QtTestTableView::MoveLeft}
<< 3 << 0;
QTest::newRow("Move through span down") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown) << int(QtTestTableView::MoveDown))
+ << 1 << 2
+ << CursorActionList{QtTestTableView::MoveDown,
+ QtTestTableView::MoveDown}
<< 5 << 2;
QTest::newRow("Move through span up") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 5 << 2 << (IntList() << int(QtTestTableView::MoveUp) << int(QtTestTableView::MoveUp))
+ << 5 << 2
+ << CursorActionList{QtTestTableView::MoveUp,
+ QtTestTableView::MoveUp}
<< 1 << 2;
IntList fullList;
@@ -1275,42 +1207,48 @@ void tst_QTableView::moveCursorStrikesBack_data()
<< fullList
<< fullList
<< QRect()
- << 1 << 0 << (IntList() << int(QtTestTableView::MoveNext))
+ << 1 << 0
+ << CursorActionList{QtTestTableView::MoveNext}
<< -1 << -1;
QTest::newRow("All disabled, wrap backwards. => invalid index") << -1 << -1
<< fullList
<< fullList
<< QRect()
- << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious))
+ << 1 << 0
+ << CursorActionList{QtTestTableView::MovePrevious}
<< -1 << -1;
QTest::newRow("Last column disabled, MoveEnd. QTBUG-72400") << -1 << -1
<< IntList()
<< (IntList() << 6)
<< QRect()
- << 0 << 0 << (IntList() << int(QtTestTableView::MoveEnd))
+ << 0 << 0
+ << CursorActionList{QtTestTableView::MoveEnd}
<< 0 << 5;
QTest::newRow("First column disabled, MoveHome. QTBUG-72400") << -1 << -1
<< IntList()
<< (IntList() << 0)
<< QRect()
- << 0 << 6 << (IntList() << int(QtTestTableView::MoveHome))
+ << 0 << 6
+ << CursorActionList{QtTestTableView::MoveHome}
<< 0 << 1;
QTest::newRow("First row disabled, MovePageUp. QTBUG-72400") << -1 << -1
<< (IntList() << 0)
<< IntList()
<< QRect()
- << 2 << 0 << (IntList() << int(QtTestTableView::MovePageUp))
+ << 2 << 0
+ << CursorActionList{QtTestTableView::MovePageUp}
<< 1 << 0;
QTest::newRow("Last row disabled, MovePageDown. QTBUG-72400") << -1 << -1
<< (IntList() << 6)
<< IntList()
<< QRect()
- << 4 << 0 << (IntList() << int(QtTestTableView::MovePageDown))
+ << 4 << 0
+ << CursorActionList{QtTestTableView::MovePageDown}
<< 5 << 0;
}
@@ -1318,13 +1256,13 @@ void tst_QTableView::moveCursorStrikesBack()
{
QFETCH(int, hideRow);
QFETCH(int, hideColumn);
- QFETCH(IntList, disableRows);
- QFETCH(IntList, disableColumns);
+ QFETCH(const IntList, disableRows);
+ QFETCH(const IntList, disableColumns);
QFETCH(QRect, span);
QFETCH(int, startRow);
QFETCH(int, startColumn);
- QFETCH(IntList, cursorMoveActions);
+ QFETCH(const CursorActionList, cursorMoveActions);
QFETCH(int, expectedRow);
QFETCH(int, expectedColumn);
@@ -1344,15 +1282,15 @@ void tst_QTableView::moveCursorStrikesBack()
QModelIndex index = model.index(startRow, startColumn);
view.setCurrentIndex(index);
- foreach (int row, disableRows)
+ for (int row : disableRows)
model.disableRow(row);
- foreach (int column, disableColumns)
+ for (int column : disableColumns)
model.disableColumn(column);
int newRow = -1;
int newColumn = -1;
- foreach (int cursorMoveAction, cursorMoveActions) {
- QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction, 0);
+ for (auto cursorMoveAction : cursorMoveActions) {
+ QModelIndex newIndex = view.moveCursor(cursorMoveAction, nullptr);
view.setCurrentIndex(newIndex);
newRow = newIndex.row();
newColumn = newIndex.column();
@@ -1523,7 +1461,7 @@ void tst_QTableView::selection_data()
QTest::addColumn<int>("y");
QTest::addColumn<int>("width");
QTest::addColumn<int>("height");
- QTest::addColumn<int>("command");
+ QTest::addColumn<QItemSelectionModel::SelectionFlag>("command");
QTest::addColumn<int>("selectedCount"); // ### make this more detailed
QTest::newRow("no span, no hidden, no moved, 3x3 select")
@@ -1535,7 +1473,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("row span, no hidden, no moved, 3x3 select")
@@ -1547,7 +1485,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 8; // selected count
QTest::newRow("col span, no hidden, no moved, 3x3 select")
@@ -1559,7 +1497,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 8; // selected count
QTest::newRow("no span, row hidden, no moved, 3x3 select")
@@ -1571,7 +1509,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("no span, col hidden, no moved, 3x3 select")
@@ -1583,7 +1521,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("no span, no hidden, row moved, 3x3 select")
@@ -1595,7 +1533,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("no span, no hidden, col moved, 3x3 select")
@@ -1607,7 +1545,7 @@ void tst_QTableView::selection_data()
<< 1 << 3 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
}
@@ -1631,7 +1569,7 @@ void tst_QTableView::selection()
QFETCH(int, y);
QFETCH(int, width);
QFETCH(int, height);
- QFETCH(int, command);
+ QFETCH(QItemSelectionModel::SelectionFlag, command);
QFETCH(int, selectedCount);
QtTestTableModel model(rowCount, columnCount);
@@ -1653,8 +1591,7 @@ void tst_QTableView::selection()
for (int c = 0; c < columnCount; ++c)
view.setColumnWidth(c, columnWidth);
- view.setSelection(QRect(x, y, width, height),
- QItemSelectionModel::SelectionFlags(command));
+ view.setSelection(QRect(x, y, width, height), command);
QCOMPARE(view.selectedIndexes().count(), selectedCount);
}
@@ -1664,92 +1601,92 @@ void tst_QTableView::selectRow_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("row");
- QTest::addColumn<int>("mode");
- QTest::addColumn<int>("behavior");
+ QTest::addColumn<QAbstractItemView::SelectionMode>("mode");
+ QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior");
QTest::addColumn<int>("selectedItems");
QTest::newRow("SingleSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectItems
<< 0;
QTest::newRow("SingleSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("SingleSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectColumns
<< 0;
QTest::newRow("MultiSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("MultiSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("MultiSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectColumns
<< 0;
QTest::newRow("ExtendedSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ExtendedSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("ExtendedSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectColumns
<< 0;
QTest::newRow("ContiguousSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ContiguousSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("ContiguousSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectColumns
<< 0;
}
@@ -1758,16 +1695,16 @@ void tst_QTableView::selectRow()
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(int, row);
- QFETCH(int, mode);
- QFETCH(int, behavior);
+ QFETCH(QAbstractItemView::SelectionMode, mode);
+ QFETCH(QAbstractItemView::SelectionBehavior, behavior);
QFETCH(int, selectedItems);
QtTestTableModel model(rowCount, columnCount);
QTableView view;
view.setModel(&model);
- view.setSelectionMode((QAbstractItemView::SelectionMode)mode);
- view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior);
+ view.setSelectionMode(mode);
+ view.setSelectionBehavior(behavior);
QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
@@ -1785,92 +1722,92 @@ void tst_QTableView::selectColumn_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("column");
- QTest::addColumn<int>("mode");
- QTest::addColumn<int>("behavior");
+ QTest::addColumn<QAbstractItemView::SelectionMode>("mode");
+ QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior");
QTest::addColumn<int>("selectedItems");
QTest::newRow("SingleSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectItems
<< 0;
QTest::newRow("SingleSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("SingleSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectColumns
<< 10;
QTest::newRow("MultiSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("MultiSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("MultiSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectColumns
<< 10;
QTest::newRow("ExtendedSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ExtendedSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("ExtendedSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectColumns
<< 10;
QTest::newRow("ContiguousSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ContiguousSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("ContiguousSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectColumns
<< 10;
}
@@ -1879,16 +1816,16 @@ void tst_QTableView::selectColumn()
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(int, column);
- QFETCH(int, mode);
- QFETCH(int, behavior);
+ QFETCH(QAbstractItemView::SelectionMode, mode);
+ QFETCH(QAbstractItemView::SelectionBehavior, behavior);
QFETCH(int, selectedItems);
QtTestTableModel model(rowCount, columnCount);
QTableView view;
view.setModel(&model);
- view.setSelectionMode((QAbstractItemView::SelectionMode)mode);
- view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior);
+ view.setSelectionMode(mode);
+ view.setSelectionBehavior(behavior);
QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
@@ -1988,9 +1925,9 @@ void tst_QTableView::selectall_data()
<< 100; // selected count
}
-void QTest__keySequence(QWidget* widget, QKeySequence ks)
+void QTest__keySequence(QWidget* widget, const QKeySequence &ks)
{
- for (int i=0; i<ks.count(); ++i)
+ for (int i = 0; i < ks.count(); ++i)
{
Qt::Key key = Qt::Key(ks[i] & ~Qt::KeyboardModifierMask);
Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(ks[i] & Qt::KeyboardModifierMask);
@@ -2228,7 +2165,7 @@ void tst_QTableView::resizeRowsToContents()
QFETCH(int, cellHeight);
QFETCH(int, rowHeight);
QFETCH(int, columnWidth);
- Q_UNUSED(columnWidth);
+ Q_UNUSED(columnWidth)
QtTestTableModel model(rowCount, columnCount);
QtTestTableView view;
@@ -2240,13 +2177,12 @@ void tst_QTableView::resizeRowsToContents()
delegate.hint = QSize(cellWidth, cellHeight);
- QSignalSpy resizedSpy(view.verticalHeader(), SIGNAL(sectionResized(int,int,int)));
+ QSignalSpy resizedSpy(view.verticalHeader(), &QHeaderView::sectionResized);
view.resizeRowsToContents();
QCOMPARE(resizedSpy.count(), model.rowCount());
- for (int r = 0; r < model.rowCount(); ++r) {
+ for (int r = 0; r < model.rowCount(); ++r)
QCOMPARE(view.rowHeight(r), rowHeight);
- }
}
void tst_QTableView::resizeColumnsToContents_data()
@@ -2275,7 +2211,7 @@ void tst_QTableView::resizeColumnsToContents()
QFETCH(int, cellHeight);
QFETCH(int, rowHeight);
QFETCH(int, columnWidth);
- Q_UNUSED(rowHeight);
+ Q_UNUSED(rowHeight)
QtTestTableModel model(rowCount, columnCount);
QtTestTableView view;
@@ -2287,7 +2223,7 @@ void tst_QTableView::resizeColumnsToContents()
delegate.hint = QSize(cellWidth, cellHeight);
- QSignalSpy resizedSpy(view.horizontalHeader(), SIGNAL(sectionResized(int,int,int)));
+ QSignalSpy resizedSpy(view.horizontalHeader(), &QHeaderView::sectionResized);
view.resizeColumnsToContents();
QCOMPARE(resizedSpy.count(), model.columnCount());
@@ -2300,51 +2236,51 @@ void tst_QTableView::rowViewportPosition_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("rowHeight");
QTest::addColumn<int>("row");
- QTest::addColumn<int>("verticalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode");
QTest::addColumn<int>("verticalScrollValue");
QTest::addColumn<int>("rowViewportPosition");
QTest::newRow("row 0, scroll per item 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0;
QTest::newRow("row 1, scroll per item, 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40;
QTest::newRow("row 1, scroll per item, 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0;
QTest::newRow("row 5, scroll per item, 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40;
QTest::newRow("row 5, scroll per item, 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0;
QTest::newRow("row 9, scroll per item, 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40;
QTest::newRow("row 9, scroll per item, 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40;
QTest::newRow("row 0, scroll per pixel 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0;
QTest::newRow("row 1, scroll per pixel, 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40;
QTest::newRow("row 1, scroll per pixel, 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0;
QTest::newRow("row 5, scroll per pixel, 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40;
QTest::newRow("row 5, scroll per pixel, 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0;
QTest::newRow("row 9, scroll per pixel, 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40;
QTest::newRow("row 9, scroll per pixel, 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40;
}
void tst_QTableView::rowViewportPosition()
@@ -2352,7 +2288,7 @@ void tst_QTableView::rowViewportPosition()
QFETCH(int, rowCount);
QFETCH(int, rowHeight);
QFETCH(int, row);
- QFETCH(int, verticalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode);
QFETCH(int, verticalScrollValue);
QFETCH(int, rowViewportPosition);
@@ -2366,7 +2302,7 @@ void tst_QTableView::rowViewportPosition()
for (int r = 0; r < rowCount; ++r)
view.setRowHeight(r, rowHeight);
- view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode);
+ view.setVerticalScrollMode(verticalScrollMode);
view.verticalScrollBar()->setValue(verticalScrollValue);
#ifdef Q_OS_WINRT
@@ -2471,51 +2407,51 @@ void tst_QTableView::columnViewportPosition_data()
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("columnWidth");
QTest::addColumn<int>("column");
- QTest::addColumn<int>("horizontalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode");
QTest::addColumn<int>("horizontalScrollValue");
QTest::addColumn<int>("columnViewportPosition");
QTest::newRow("column 0, scroll per item 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0;
QTest::newRow("column 1, scroll per item, 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40;
QTest::newRow("column 1, scroll per item, 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0;
QTest::newRow("column 5, scroll per item, 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40;
QTest::newRow("column 5, scroll per item, 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0;
QTest::newRow("column 9, scroll per item, 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40;
QTest::newRow("column 9, scroll per item, 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40;
QTest::newRow("column 0, scroll per pixel 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0;
QTest::newRow("column 1, scroll per pixel 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40;
QTest::newRow("column 1, scroll per pixel 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0;
QTest::newRow("column 5, scroll per pixel 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40;
QTest::newRow("column 5, scroll per pixel 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0;
QTest::newRow("column 9, scroll per pixel 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40;
QTest::newRow("column 9, scroll per pixel 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40;
}
void tst_QTableView::columnViewportPosition()
@@ -2523,7 +2459,7 @@ void tst_QTableView::columnViewportPosition()
QFETCH(int, columnCount);
QFETCH(int, columnWidth);
QFETCH(int, column);
- QFETCH(int, horizontalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode);
QFETCH(int, horizontalScrollValue);
QFETCH(int, columnViewportPosition);
@@ -2537,7 +2473,7 @@ void tst_QTableView::columnViewportPosition()
for (int c = 0; c < columnCount; ++c)
view.setColumnWidth(c, columnWidth);
- view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode);
+ view.setHorizontalScrollMode(horizontalScrollMode);
view.horizontalScrollBar()->setValue(horizontalScrollValue);
#ifdef Q_OS_WINRT
@@ -2737,8 +2673,8 @@ void tst_QTableView::sortingEnabled()
void tst_QTableView::scrollTo_data()
{
- QTest::addColumn<int>("verticalScrollMode");
- QTest::addColumn<int>("horizontalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode");
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("rowHeight");
@@ -2751,51 +2687,51 @@ void tst_QTableView::scrollTo_data()
QTest::addColumn<int>("columnSpan");
QTest::addColumn<int>("horizontalScroll");
QTest::addColumn<int>("verticalScroll");
- QTest::addColumn<int>("scrollHint");
+ QTest::addColumn<QAbstractItemView::ScrollHint>("scrollHint");
QTest::addColumn<int>("expectedHorizontalScroll");
QTest::addColumn<int>("expectedVerticalScroll");
QTest::newRow("no hidden, no span, no scroll, per item")
- << (int)QAbstractItemView::ScrollPerItem
- << (int)QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
<< 10 << 10 // table
<< 80 << 80 // size
<< -1 << -1 // hide
<< 0 << 0 // cell
<< 1 << 1 // span
<< 0 << 0 // scroll
- << (int)QAbstractItemView::PositionAtTop
+ << QAbstractItemView::PositionAtTop
<< 0 << 0; // expected
QTest::newRow("no hidden, no span, no scroll, per pixel")
- << (int)QAbstractItemView::ScrollPerPixel
- << (int)QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
<< 10 << 10 // table
<< 80 << 80 // size
<< -1 << -1 // hide
<< 0 << 0 // cell
<< 1 << 1 // span
<< 0 << 0 // scroll
- << (int)QAbstractItemView::PositionAtTop
+ << QAbstractItemView::PositionAtTop
<< 0 << 0; // expected
QTest::newRow("hidden, no span, no scroll, per item")
- << (int)QAbstractItemView::ScrollPerItem
- << (int)QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
<< 10 << 10 // table
<< 80 << 80 // size
<< 3 << 3 // hide
<< 5 << 5 // cell
<< 1 << 1 // span
<< 0 << 0 // scroll
- << (int)QAbstractItemView::PositionAtTop
+ << QAbstractItemView::PositionAtTop
<< 4 << 4; // expected
}
void tst_QTableView::scrollTo()
{
- QFETCH(int, horizontalScrollMode);
- QFETCH(int, verticalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode);
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(int, rowHeight);
@@ -2808,7 +2744,7 @@ void tst_QTableView::scrollTo()
QFETCH(int, columnSpan);
QFETCH(int, horizontalScroll);
QFETCH(int, verticalScroll);
- QFETCH(int, scrollHint);
+ QFETCH(QAbstractItemView::ScrollHint, scrollHint);
QFETCH(int, expectedHorizontalScroll);
QFETCH(int, expectedVerticalScroll);
@@ -2828,8 +2764,8 @@ void tst_QTableView::scrollTo()
view.setSpan(row, column, rowSpan, columnSpan);
view.hideRow(hiddenRow);
view.hideColumn(hiddenColumn);
- view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode);
- view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode);
+ view.setHorizontalScrollMode(horizontalScrollMode);
+ view.setVerticalScrollMode(verticalScrollMode);
for (int r = 0; r < rowCount; ++r)
view.setRowHeight(r, rowHeight);
@@ -2841,7 +2777,7 @@ void tst_QTableView::scrollTo()
QModelIndex index = model.index(row, column);
QVERIFY(index.isValid());
- view.scrollTo(index, (QAbstractItemView::ScrollHint)scrollHint);
+ view.scrollTo(index, scrollHint);
QTRY_COMPARE(view.verticalScrollBar()->value(), expectedVerticalScroll);
QTRY_COMPARE(view.horizontalScrollBar()->value(), expectedHorizontalScroll);
}
@@ -3146,8 +3082,6 @@ void tst_QTableView::span()
VERIFY_SPANS_CONSISTENCY(&view);
}
-typedef QVector<QRect> SpanList;
-
void tst_QTableView::spans_data()
{
QTest::addColumn<int>("rows");
@@ -3275,7 +3209,7 @@ void tst_QTableView::spans()
{
QFETCH(int, rows);
QFETCH(int, columns);
- QFETCH(SpanList, spans);
+ QFETCH(const SpanList, spans);
QFETCH(bool, hideRowLastRowOfFirstSpan);
QFETCH(QPoint, pos);
QFETCH(int, expectedRowSpan);
@@ -3287,10 +3221,8 @@ void tst_QTableView::spans()
view.setModel(&model);
view.show();
- for (int i = 0; i < spans.count(); ++i) {
- QRect sp = spans.at(i);
+ for (const auto &sp : spans)
view.setSpan(sp.x(), sp.y(), sp.width(), sp.height());
- }
if (hideRowLastRowOfFirstSpan) {
view.setRowHidden(spans.at(0).bottom(), true);
@@ -3384,32 +3316,34 @@ void tst_QTableView::spansAfterRowRemoval()
QtTestTableView view;
view.setModel(&model);
- QList<QRect> spans;
- spans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 2)
- << QRect(2, 2, 1, 5)
- << QRect(2, 8, 1, 2)
- << QRect(3, 4, 1, 2)
- << QRect(4, 4, 1, 4)
- << QRect(5, 6, 1, 3)
- << QRect(6, 7, 1, 3);
- foreach (QRect span, spans)
+ static const QRect spans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 2},
+ {2, 2, 1, 5},
+ {2, 8, 1, 2},
+ {3, 4, 1, 2},
+ {4, 4, 1, 4},
+ {5, 6, 1, 3},
+ {6, 7, 1, 3}
+ };
+ for (const QRect &span : spans)
view.setSpan(span.top(), span.left(), span.height(), span.width());
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
view.model()->removeRows(3, 3);
- QList<QRect> expectedSpans;
- expectedSpans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 1)
- << QRect(2, 2, 1, 2)
- << QRect(2, 5, 1, 2)
- << QRect(3, 4, 1, 1)
- << QRect(4, 3, 1, 2)
- << QRect(5, 3, 1, 3)
- << QRect(6, 4, 1, 3);
- foreach (QRect span, expectedSpans) {
+ static const QRect expectedSpans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 1},
+ {2, 2, 1, 2},
+ {2, 5, 1, 2},
+ {3, 4, 1, 1},
+ {4, 3, 1, 2},
+ {5, 3, 1, 3},
+ {6, 4, 1, 3}
+ };
+ for (const QRect &span : expectedSpans) {
QCOMPARE(view.columnSpan(span.top(), span.left()), span.width());
QCOMPARE(view.rowSpan(span.top(), span.left()), span.height());
}
@@ -3424,32 +3358,34 @@ void tst_QTableView::spansAfterColumnRemoval()
view.setModel(&model);
// Same set as above just swapping columns and rows.
- QList<QRect> spans;
- spans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 2)
- << QRect(2, 2, 1, 5)
- << QRect(2, 8, 1, 2)
- << QRect(3, 4, 1, 2)
- << QRect(4, 4, 1, 4)
- << QRect(5, 6, 1, 3)
- << QRect(6, 7, 1, 3);
- foreach (QRect span, spans)
- view.setSpan(span.left(), span.top(), span.width(), span.height());
+ static const QRect spans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 2},
+ {2, 2, 1, 5},
+ {2, 8, 1, 2},
+ {3, 4, 1, 2},
+ {4, 4, 1, 4},
+ {5, 6, 1, 3},
+ {6, 7, 1, 3}
+ };
+ for (const QRect &span : spans)
+ view.setSpan(span.left(), span.top(), span.width(), span.height());
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
view.model()->removeColumns(3, 3);
- QList<QRect> expectedSpans;
- expectedSpans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 1)
- << QRect(2, 2, 1, 2)
- << QRect(2, 5, 1, 2)
- << QRect(3, 4, 1, 1)
- << QRect(4, 3, 1, 2)
- << QRect(5, 3, 1, 3)
- << QRect(6, 4, 1, 3);
- foreach (QRect span, expectedSpans) {
+ static const QRect expectedSpans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 1},
+ {2, 2, 1, 2},
+ {2, 5, 1, 2},
+ {3, 4, 1, 1},
+ {4, 3, 1, 2},
+ {5, 3, 1, 3},
+ {6, 4, 1, 3}
+ };
+ for (const QRect &span : expectedSpans) {
QCOMPARE(view.columnSpan(span.left(), span.top()), span.height());
QCOMPARE(view.rowSpan(span.left(), span.top()), span.width());
}
@@ -3457,12 +3393,10 @@ void tst_QTableView::spansAfterColumnRemoval()
VERIFY_SPANS_CONSISTENCY(&view);
}
-Q_DECLARE_METATYPE(Qt::Key)
-
void tst_QTableView::editSpanFromDirections_data()
{
- QTest::addColumn<QList<Qt::Key> >("keyPresses");
- QTest::addColumn<QSharedPointer<QStandardItemModel> >("model");
+ QTest::addColumn<KeyList>("keyPresses");
+ QTest::addColumn<QSharedPointer<QStandardItemModel>>("model");
QTest::addColumn<int>("row");
QTest::addColumn<int>("column");
QTest::addColumn<int>("rowSpan");
@@ -3481,8 +3415,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+
| | ^ |
+---+---+ */
- QList<Qt::Key> keyPresses;
- keyPresses << Qt::Key_Right << Qt::Key_PageDown << Qt::Key_Up;
+ KeyList keyPresses {Qt::Key_Right, Qt::Key_PageDown, Qt::Key_Up};
QSharedPointer<QStandardItemModel> model(new QStandardItemModel(4, 2));
QTest::newRow("row span, bottom up")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1);
@@ -3496,8 +3429,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+
| | |
+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_Right << Qt::Key_Down;
+ keyPresses = {Qt::Key_Right, Qt::Key_Down};
model = QSharedPointer<QStandardItemModel>::create(4, 2);
QTest::newRow("row span, top down")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1);
@@ -3509,8 +3441,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+ +---+
| | | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_End << Qt::Key_Down << Qt::Key_Left;
+ keyPresses = {Qt::Key_End, Qt::Key_Down, Qt::Key_Left};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("row span, right to left")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1);
@@ -3522,8 +3453,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+ +---+
| > | c | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_PageDown << Qt::Key_Right;
+ keyPresses = {Qt::Key_PageDown, Qt::Key_Right};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("row span, left to right")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1);
@@ -3535,8 +3465,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+
| ^ | | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_PageDown << Qt::Key_Up;
+ keyPresses = {Qt::Key_PageDown, Qt::Key_Up};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, bottom up")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 0) << model->index(1, 0);
@@ -3548,8 +3477,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+
| | ^ | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_PageDown << Qt::Key_Right << Qt::Key_Up;
+ keyPresses = {Qt::Key_PageDown, Qt::Key_Right, Qt::Key_Up};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, bottom up #2")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 1) << model->index(1, 0);
@@ -3561,8 +3489,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+
| | | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_End << Qt::Key_Down;
+ keyPresses = {Qt::Key_End, Qt::Key_Down};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, top down")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 2) << model->index(1, 0);
@@ -3571,12 +3498,10 @@ void tst_QTableView::editSpanFromDirections_data()
class TableViewWithCursorExposed : public QTableView
{
public:
- TableViewWithCursorExposed() :
- QTableView() {
- }
+ using QTableView::QTableView;
-public:
- QModelIndex visualCursorIndex() {
+ QModelIndex visualCursorIndex()
+ {
QTableViewPrivate *d = static_cast<QTableViewPrivate*>(qt_widget_private(this));
return d->model->index(d->visualCursor.y(), d->visualCursor.x());
}
@@ -3584,7 +3509,7 @@ public:
void tst_QTableView::editSpanFromDirections()
{
- QFETCH(QList<Qt::Key>, keyPresses);
+ QFETCH(const KeyList, keyPresses);
QFETCH(QSharedPointer<QStandardItemModel>, model);
QFETCH(int, row);
QFETCH(int, column);
@@ -3602,9 +3527,8 @@ void tst_QTableView::editSpanFromDirections()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- foreach (Qt::Key key, keyPresses) {
+ for (Qt::Key key : keyPresses)
QTest::keyClick(&view, key);
- }
QCOMPARE(view.visualCursorIndex(), expectedVisualCursorIndex);
QCOMPARE(view.selectionModel()->currentIndex(), expectedEditedIndex);
@@ -3613,21 +3537,21 @@ void tst_QTableView::editSpanFromDirections()
QTRY_COMPARE(view.model()->data(expectedEditedIndex).toString(), QLatin1String("x"));
}
-class Model : public QAbstractTableModel {
-
-Q_OBJECT
-
+class Model : public QAbstractTableModel
+{
+ Q_OBJECT
public:
- Model(QObject * parent = 0) : QAbstractTableModel(parent) {
- }
+ using QAbstractTableModel::QAbstractTableModel;
- int rowCount(const QModelIndex &) const {
+ int rowCount(const QModelIndex &) const override
+ {
return rows;
}
- int columnCount(const QModelIndex &) const {
+ int columnCount(const QModelIndex &) const override
+ {
return columns;
}
- QVariant data(const QModelIndex &, int) const
+ QVariant data(const QModelIndex &, int) const override
{
return QVariant();
}
@@ -3637,8 +3561,8 @@ public:
endResetModel();
}
- int rows;
- int columns;
+ int rows = 0;
+ int columns = 0;
};
void tst_QTableView::checkHeaderReset()
@@ -3662,7 +3586,7 @@ void tst_QTableView::checkHeaderMinSize()
//viewport.
QTableView view;
QStringListModel m;
- m.setStringList( QStringList() << QLatin1String("one cell is enough"));
+ m.setStringList({QLatin1String("one cell is enough")});
view.setModel(&m);
//setting the minimum height on the horizontal header
@@ -3693,31 +3617,29 @@ void tst_QTableView::resizeToContents()
table2.verticalHeader()->setVisible(false);
- for(int i = 0;i<table.columnCount();i++) {
+ for (int i = 0; i < table.columnCount(); i++)
table.resizeColumnToContents(i);
- }
- for(int i = 0;i<table.rowCount();i++) {
+ for (int i = 0; i < table.rowCount(); i++)
table.resizeRowToContents(i);
- }
table2.resizeColumnsToContents();
table2.resizeRowsToContents();
table3.resizeColumnsToContents();
table3.resizeRowsToContents();
//now let's check the row/col sizes
- for(int i = 0;i<table.columnCount();i++) {
- QCOMPARE( table.columnWidth(i), table2.columnWidth(i));
- QCOMPARE( table2.columnWidth(i), table3.columnWidth(i));
+ for (int i = 0; i < table.columnCount(); i++) {
+ QCOMPARE(table.columnWidth(i), table2.columnWidth(i));
+ QCOMPARE(table2.columnWidth(i), table3.columnWidth(i));
}
- for(int i = 0;i<table.rowCount();i++) {
- QCOMPARE( table.rowHeight(i), table2.rowHeight(i));
- QCOMPARE( table2.rowHeight(i), table3.rowHeight(i));
+ for (int i = 0; i < table.rowCount(); i++) {
+ QCOMPARE(table.rowHeight(i), table2.rowHeight(i));
+ QCOMPARE(table2.rowHeight(i), table3.rowHeight(i));
}
}
QT_BEGIN_NAMESPACE
-extern bool Q_GUI_EXPORT qt_tab_all_widgets(); // qapplication.cpp
+extern bool Q_WIDGETS_EXPORT qt_tab_all_widgets(); // qapplication.cpp
QT_END_NAMESPACE
void tst_QTableView::tabFocus()
@@ -3747,57 +3669,57 @@ void tst_QTableView::tabFocus()
for (int i = 0; i < 2; ++i) {
// tab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(!window.hasFocus());
QVERIFY(view->hasFocus());
QVERIFY(!edit->hasFocus());
// tab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
}
// backtab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(view->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!edit->hasFocus());
// backtab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
- QStandardItemModel *model = new QStandardItemModel;
- view->setModel(model);
+ QStandardItemModel model;
+ view->setModel(&model);
// backtab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(view->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!edit->hasFocus());
// backtab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
- model->insertRow(0, new QStandardItem("Hei"));
- model->insertRow(0, new QStandardItem("Hei"));
- model->insertRow(0, new QStandardItem("Hei"));
+ model.insertRow(0, new QStandardItem("Hei"));
+ model.insertRow(0, new QStandardItem("Hei"));
+ model.insertRow(0, new QStandardItem("Hei"));
// backtab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(view->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!edit->hasFocus());
// backtab to edit doesn't work
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QVERIFY(!window.hasFocus());
QVERIFY(view->hasFocus());
QVERIFY(!edit->hasFocus());
@@ -3805,41 +3727,38 @@ void tst_QTableView::tabFocus()
view->setTabKeyNavigation(false);
// backtab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(view->hasFocus());
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(edit->hasFocus());
-
- delete model;
}
class BigModel : public QAbstractTableModel
{
Q_OBJECT
public:
- virtual QVariant data(const QModelIndex &index,
- int role = Qt::DisplayRole) const
+ QVariant data(const QModelIndex &index,
+ int role = Qt::DisplayRole) const override
{
if (role == Qt::DisplayRole)
return QString::number(index.column()) + QLatin1String(" - ") + QString::number(index.row());
return QVariant();
}
-
- int rowCount(const QModelIndex & parent = QModelIndex()) const
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override
{
- Q_UNUSED(parent);
+ Q_UNUSED(parent)
return 10000000;
}
- int columnCount(const QModelIndex & parent = QModelIndex()) const
+ int columnCount(const QModelIndex &parent = QModelIndex()) const override
{
- Q_UNUSED(parent);
+ Q_UNUSED(parent)
return 20000000;
}
};
@@ -3868,7 +3787,7 @@ void tst_QTableView::selectionSignal()
view.resize(200, 200);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center());
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(model.index(2, 0)).center());
}
void tst_QTableView::setCurrentIndex()
@@ -3894,14 +3813,14 @@ void tst_QTableView::setCurrentIndex()
class task173773_EventFilter : public QObject
{
- int paintEventCount_;
+ int paintEventCount_ = 0;
public:
- task173773_EventFilter() : paintEventCount_(0) {}
+ using QObject::QObject;
int paintEventCount() const { return paintEventCount_; }
private:
- bool eventFilter(QObject *obj, QEvent *e)
+ bool eventFilter(QObject *obj, QEvent *e) override
{
- Q_UNUSED(obj);
+ Q_UNUSED(obj)
if (e->type() == QEvent::Paint)
++paintEventCount_;
return false;
@@ -4030,25 +3949,25 @@ void tst_QTableView::task248688_autoScrollNavigation()
#if QT_CONFIG(wheelevent)
void tst_QTableView::mouseWheel_data()
{
- QTest::addColumn<int>("scrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("scrollMode");
QTest::addColumn<int>("delta");
QTest::addColumn<int>("horizontalPositon");
QTest::addColumn<int>("verticalPosition");
QTest::newRow("scroll up per item")
- << int(QAbstractItemView::ScrollPerItem) << 120
- << 10 - qApp->wheelScrollLines() << 10 - qApp->wheelScrollLines();
+ << QAbstractItemView::ScrollPerItem << 120
+ << 10 - QApplication::wheelScrollLines() << 10 - QApplication::wheelScrollLines();
QTest::newRow("scroll down per item")
- << int(QAbstractItemView::ScrollPerItem) << -120
- << 10 + qApp->wheelScrollLines() << 10 + qApp->wheelScrollLines();
+ << QAbstractItemView::ScrollPerItem << -120
+ << 10 + QApplication::wheelScrollLines() << 10 + QApplication::wheelScrollLines();
QTest::newRow("scroll down per pixel")
- << int(QAbstractItemView::ScrollPerPixel) << -120
- << 10 + qApp->wheelScrollLines() * 91 << 10 + qApp->wheelScrollLines() * 46;
+ << QAbstractItemView::ScrollPerPixel << -120
+ << 10 + QApplication::wheelScrollLines() * 91 << 10 + QApplication::wheelScrollLines() * 46;
}
void tst_QTableView::mouseWheel()
{
- QFETCH(int, scrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, scrollMode);
QFETCH(int, delta);
QFETCH(int, horizontalPositon);
QFETCH(int, verticalPosition);
@@ -4068,8 +3987,8 @@ void tst_QTableView::mouseWheel()
for (int c = 0; c < 100; ++c)
view.setColumnWidth(c, 100);
- view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)scrollMode);
- view.setVerticalScrollMode((QAbstractItemView::ScrollMode)scrollMode);
+ view.setHorizontalScrollMode(scrollMode);
+ view.setVerticalScrollMode(scrollMode);
view.horizontalScrollBar()->setValue(10);
view.verticalScrollBar()->setValue(10);
@@ -4168,15 +4087,15 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *vHeaderVp = vHeader->viewport();
QPoint rowPos(cellRect.center());
QMouseEvent rowPressEvent(QEvent::MouseButtonPress, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(vHeaderVp, &rowPressEvent);
+ QCoreApplication::sendEvent(vHeaderVp, &rowPressEvent);
for (int i = 0; i < 4; ++i) {
rowPos.setY(rowPos.y() + cellRect.height());
QMouseEvent moveEvent(QEvent::MouseMove, rowPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(vHeaderVp, &moveEvent);
+ QCoreApplication::sendEvent(vHeaderVp, &moveEvent);
}
QMouseEvent rowReleaseEvent(QEvent::MouseButtonRelease, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(vHeaderVp, &rowReleaseEvent);
+ QCoreApplication::sendEvent(vHeaderVp, &rowReleaseEvent);
for (int i = 0; i < 4; ++i) {
QModelIndex index = model.index(3 + i, 0, table.rootIndex());
@@ -4190,15 +4109,15 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *hHeaderVp = hHeader->viewport();
QPoint colPos((cellRect.left() + cellRect.right()) / 2, 5);
QMouseEvent colPressEvent(QEvent::MouseButtonPress, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(hHeaderVp, &colPressEvent);
+ QCoreApplication::sendEvent(hHeaderVp, &colPressEvent);
for (int i = 0; i < 4; ++i) {
colPos.setX(colPos.x() + cellRect.width());
QMouseEvent moveEvent(QEvent::MouseMove, colPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(hHeaderVp, &moveEvent);
+ QCoreApplication::sendEvent(hHeaderVp, &moveEvent);
}
QMouseEvent colReleaseEvent(QEvent::MouseButtonRelease, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(hHeaderVp, &colReleaseEvent);
+ QCoreApplication::sendEvent(hHeaderVp, &colReleaseEvent);
for (int i = 0; i < 4; ++i) {
QModelIndex index = model.index(0, 3 + i, table.rootIndex());
@@ -4211,22 +4130,23 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *tableVp = table.viewport();
QPoint cellPos = cellRect.center();
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellPressEvent);
+ QCoreApplication::sendEvent(tableVp, &cellPressEvent);
for (int i = 0; i < 6; ++i) {
cellPos.setX(cellPos.x() + cellRect.width());
cellPos.setY(cellPos.y() + cellRect.height());
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &moveEvent);
+ QCoreApplication::sendEvent(tableVp, &moveEvent);
}
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellReleaseEvent);
+ QCoreApplication::sendEvent(tableVp, &cellReleaseEvent);
- for (int i = 0; i < 6; ++i)
+ for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 6; ++j) {
QModelIndex index = model.index(2 + i, 2 + j, table.rootIndex());
QVERIFY(table.selectionModel()->isSelected(index));
}
+ }
}
{
@@ -4234,23 +4154,24 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *tableVp = table.viewport();
QPoint cellPos = cellRect.center();
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellPressEvent);
+ QCoreApplication::sendEvent(tableVp, &cellPressEvent);
for (int i = 0; i < 6; ++i) {
cellPos.setX(cellPos.x() + cellRect.width());
cellPos.setY(cellPos.y() + cellRect.height());
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &moveEvent);
+ QCoreApplication::sendEvent(tableVp, &moveEvent);
}
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellReleaseEvent);
+ QCoreApplication::sendEvent(tableVp, &cellReleaseEvent);
QTest::qWait(200);
- for (int i = 0; i < 6; ++i)
+ for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 6; ++j) {
QModelIndex index = model.index(3 + i, 3 + j, table.rootIndex());
QVERIFY(!table.selectionModel()->isSelected(index));
}
+ }
}
}
@@ -4328,8 +4249,6 @@ void tst_QTableView::taskQTBUG_4516_clickOnRichTextLabel()
QTest::mouseClick(&label, Qt::LeftButton);
QCOMPARE(view.currentIndex(), model.index(1,1));
-
-
}
@@ -4371,14 +4290,14 @@ void tst_QTableView::taskQTBUG_5237_wheelEventOnHeader()
}
#endif
-class TestTableView : public QTableView {
-Q_OBJECT
+class TestTableView : public QTableView
+{
+ Q_OBJECT
public:
- TestTableView(QWidget *parent = 0) : QTableView(parent)
+ TestTableView(QWidget *parent = nullptr) : QTableView(parent)
{
- connect(this, SIGNAL(entered(QModelIndex)), this, SLOT(openEditor(QModelIndex)));
+ connect(this, &QTableView::entered, this, &TestTableView::openPersistentEditor);
}
- ~TestTableView(){}
public slots:
void onDataChanged()
{
@@ -4386,9 +4305,6 @@ public slots:
setRowHidden(i, model()->data(model()->index(i, 0)).toBool());
}
}
-
- void openEditor(const QModelIndex& index)
- { openPersistentEditor(index); }
};
@@ -4396,15 +4312,13 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason()
{
QStandardItemModel model;
model.insertColumn(0, QModelIndex());
- for(int i = 0; i < 20; i++)
- {
+ for (int i = 0; i < 20; i++)
model.insertRow(i);
- }
TestTableView w;
w.setMouseTracking(true);
w.setModel(&model);
- connect(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), &w, SLOT(onDataChanged()));
+ connect(&model, &QStandardItemModel::dataChanged, &w, &TestTableView::onDataChanged);
w.show();
QVERIFY(QTest::qWaitForWindowExposed(&w));
for (int i = 0; i < 10; i++)
@@ -4418,10 +4332,7 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason()
class TableView7774 : public QTableView
{
public:
- QRegion visualRegionForSelection(const QItemSelection &selection) const
- {
- return QTableView::visualRegionForSelection(selection);
- }
+ using QTableView::visualRegionForSelection;
};
void tst_QTableView::taskQTBUG_7774_RtoLVisualRegionForSelection()
diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
index 6184962d93..f640996690 100644
--- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
@@ -26,15 +26,12 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <qeventloop.h>
-#include <qlist.h>
-#include <qpair.h>
-#include <qheaderview.h>
-#include <qlineedit.h>
-
-#include <qtablewidget.h>
+#include <QHeaderView>
+#include <QLineEdit>
+#include <QMimeData>
+#include <QSignalSpy>
+#include <QTableWidget>
+#include <QTest>
class QObjectTableItem : public QObject, public QTableWidgetItem
{
@@ -46,11 +43,10 @@ class tst_QTableWidget : public QObject
Q_OBJECT
public:
- tst_QTableWidget();
+ using QObject::QObject;
private slots:
void initTestCase();
- void cleanupTestCase();
void init();
void getSetCheck();
void clear();
@@ -97,12 +93,12 @@ private slots:
#endif
private:
- QTableWidget *testWidget;
+ std::unique_ptr<QTableWidget> testWidget;
};
-typedef QPair<int, int> IntPair;
-typedef QList<int> IntList;
-typedef QList<IntPair> IntIntList;
+using IntPair = QPair<int, int>;
+using IntList = QVector<int>;
+using IntIntList = QVector<IntPair>;
Q_DECLARE_METATYPE(QTableWidgetSelectionRange)
@@ -143,45 +139,36 @@ void tst_QTableWidget::getSetCheck()
obj1.setItem(3, 3, new QTableWidgetItem("3,3"));
obj1.setCurrentItem(var3);
QCOMPARE(var3, obj1.currentItem());
- obj1.setCurrentItem((QTableWidgetItem *)0);
- QCOMPARE((QTableWidgetItem *)0, obj1.currentItem());
- obj1.setItem(0, 0, 0);
- QCOMPARE((QTableWidgetItem *)0, obj1.item(0, 0));
+ obj1.setCurrentItem(nullptr);
+ QCOMPARE(obj1.currentItem(), nullptr);
+ obj1.setItem(0, 0, nullptr);
+ QCOMPARE(obj1.item(0, 0), nullptr);
// const QTableWidgetItem * QTableWidget::itemPrototype()
// void QTableWidget::setItemPrototype(const QTableWidgetItem *)
const QTableWidgetItem *var4 = new QTableWidgetItem;
obj1.setItemPrototype(var4);
QCOMPARE(var4, obj1.itemPrototype());
- obj1.setItemPrototype((QTableWidgetItem *)0);
- QCOMPARE((const QTableWidgetItem *)0, obj1.itemPrototype());
-}
-
-tst_QTableWidget::tst_QTableWidget(): testWidget(0)
-{
+ obj1.setItemPrototype(nullptr);
+ QCOMPARE(obj1.itemPrototype(), nullptr);
}
void tst_QTableWidget::initTestCase()
{
- testWidget = new QTableWidget();
+ testWidget.reset(new QTableWidget);
testWidget->show();
QApplication::setKeyboardInputInterval(100);
}
-void tst_QTableWidget::cleanupTestCase()
-{
- delete testWidget;
-}
-
void tst_QTableWidget::init()
{
testWidget->clear();
testWidget->setRowCount(5);
testWidget->setColumnCount(5);
- for (int row=0; row < testWidget->rowCount(); ++row)
+ for (int row = 0; row < testWidget->rowCount(); ++row)
testWidget->showRow(row);
- for (int column=0; column < testWidget->columnCount(); ++column)
+ for (int column = 0; column < testWidget->columnCount(); ++column)
testWidget->showColumn(column);
}
@@ -319,13 +306,15 @@ void tst_QTableWidget::item()
QCOMPARE(testWidget->rowCount(), rowCount);
QCOMPARE(testWidget->columnCount(), columnCount);
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c)));
+ }
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
+ }
QTableWidgetItem *item = testWidget->item(row, column);
QCOMPARE(!!item, expectItem);
@@ -361,15 +350,17 @@ void tst_QTableWidget::takeItem()
QCOMPARE(testWidget->rowCount(), rowCount);
QCOMPARE(testWidget->columnCount(), columnCount);
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c)));
+ }
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
+ }
- QSignalSpy spy(testWidget, &QTableWidget::cellChanged);
+ QSignalSpy spy(testWidget.get(), &QTableWidget::cellChanged);
QTableWidgetItem *item = testWidget->takeItem(row, column);
QCOMPARE(!!item, expectItem);
if (expectItem) {
@@ -516,11 +507,11 @@ void tst_QTableWidget::selectedItems()
{
QFETCH(int, rowCount);
QFETCH(int, columnCount);
- QFETCH(IntIntList, createItems);
- QFETCH(IntList, hiddenRows);
- QFETCH(IntList, hiddenColumns);
- QFETCH(QTableWidgetSelectionRange, selectionRange);
- QFETCH(IntIntList, expectedItems);
+ QFETCH(const IntIntList, createItems);
+ QFETCH(const IntList, hiddenRows);
+ QFETCH(const IntList, hiddenColumns);
+ QFETCH(const QTableWidgetSelectionRange, selectionRange);
+ QFETCH(const IntIntList, expectedItems);
// set dimensions and test they are ok
testWidget->setRowCount(rowCount);
@@ -529,15 +520,15 @@ void tst_QTableWidget::selectedItems()
QCOMPARE(testWidget->columnCount(), columnCount);
// create and set items
- foreach (IntPair intPair, createItems) {
+ for (const auto &intPair : createItems) {
testWidget->setItem(intPair.first, intPair.second,
new QTableWidgetItem(QString("Item %1 %2")
.arg(intPair.first).arg(intPair.second)));
}
// hide rows/columns
- foreach (int row, hiddenRows)
+ for (int row : hiddenRows)
testWidget->setRowHidden(row, true);
- foreach (int column, hiddenColumns)
+ for (int column : hiddenColumns)
testWidget->setColumnHidden(column, true);
// make sure we don't have any previous selections hanging around
@@ -557,31 +548,18 @@ void tst_QTableWidget::selectedItems()
}
// check that the correct number of items and the expected items are there
- QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems();
+ const QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems();
QCOMPARE(selectedItems.count(), expectedItems.count());
- foreach (IntPair intPair, expectedItems)
+ for (const auto &intPair : expectedItems)
QVERIFY(selectedItems.contains(testWidget->item(intPair.first, intPair.second)));
// check that setItemSelected agrees with selectedItems
- for (int row = 0; row<testWidget->rowCount(); ++row) {
- bool hidden = false;
- foreach (int hiddenRow, hiddenRows){
- if(hiddenRow == row){
- hidden = true;
- break;
- }
- }
- if (hidden)
+ for (int row = 0; row < testWidget->rowCount(); ++row) {
+ if (hiddenRows.contains(row))
continue;
- for (int column = 0; column<testWidget->columnCount(); ++column) {
- foreach (int hiddenColumn, hiddenColumns){
- if(hiddenColumn == column){
- hidden = true;
- break;
- }
- }
- if (hidden)
+ for (int column = 0; column < testWidget->columnCount(); ++column) {
+ if (hiddenColumns.contains(column))
continue;
QTableWidgetItem *item = testWidget->item(row, column);
@@ -621,11 +599,13 @@ void tst_QTableWidget::removeRow()
QCOMPARE(testWidget->columnCount(), columnCount);
// fill table with items
- for (int r = 0; r < rowCount; ++r)
- for (int c = 0; c < columnCount; ++c)
+ for (int r = 0; r < rowCount; ++r) {
+ const QString rRow = QString::number(r) + QLatin1Char(':');
+ for (int c = 0; c < columnCount; ++c) {
testWidget->setItem(r, c,
- new QTableWidgetItem(
- QString::number(r) + ":" + QString::number(c)));
+ new QTableWidgetItem(rRow + QString::number(c)));
+ }
+ }
// remove and compare the results
testWidget->removeRow(row);
@@ -633,14 +613,18 @@ void tst_QTableWidget::removeRow()
QCOMPARE(testWidget->columnCount(), expectedColumnCount);
// check if the correct items were removed
- for (int r = 0; r < expectedRowCount; ++r)
- for (int c = 0; c < expectedColumnCount; ++c)
+ for (int r = 0; r < expectedRowCount; ++r) {
+ const QString rRow = QString::number(r < row ? r : r + 1) +
+ QLatin1Char(':');
+ for (int c = 0; c < expectedColumnCount; ++c) {
if (r < row)
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r) + ":" + QString::number(c));
+ rRow + QString::number(c));
else
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r + 1) + ":" + QString::number(c));
+ rRow + QString::number(c));
+ }
+ }
}
void tst_QTableWidget::removeColumn_data()
@@ -673,11 +657,14 @@ void tst_QTableWidget::removeColumn()
QCOMPARE(testWidget->columnCount(), columnCount);
// fill table with items
- for (int r = 0; r < rowCount; ++r)
- for (int c = 0; c < columnCount; ++c)
+ for (int r = 0; r < rowCount; ++r) {
+ const QString rStr = QString::number(r) + QLatin1Char(':');
+ for (int c = 0; c < columnCount; ++c) {
testWidget->setItem(r, c,
new QTableWidgetItem(
- QString::number(r) + ":" + QString::number(c)));
+ rStr + QString::number(c)));
+ }
+ }
// remove and compare the results
testWidget->removeColumn(column);
@@ -686,14 +673,17 @@ void tst_QTableWidget::removeColumn()
// check if the correct items were removed
- for (int r = 0; r < expectedRowCount; ++r)
- for (int c = 0; c < expectedColumnCount; ++c)
+ for (int r = 0; r < expectedRowCount; ++r) {
+ const QString rStr = QString::number(r) + QLatin1Char(':');
+ for (int c = 0; c < expectedColumnCount; ++c) {
if (c < column)
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r) + ":" + QString::number(c));
+ rStr + QString::number(c));
else
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r) + ":" + QString::number(c + 1));
+ rStr + QString::number(c + 1));
+ }
+ }
}
void tst_QTableWidget::insertRow_data()
@@ -819,7 +809,7 @@ void tst_QTableWidget::itemOwnership()
item = new QObjectTableItem();
testWidget->setItem(0, 0, item);
delete item;
- QCOMPARE(testWidget->item(0, 0), (QTableWidgetItem *)0);
+ QCOMPARE(testWidget->item(0, 0), nullptr);
//delete vertical headeritem from outside
headerItem = new QObjectTableItem();
@@ -887,7 +877,7 @@ void tst_QTableWidget::sortItems_data()
{
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<int>("sortColumn");
QTest::addColumn<QStringList>("initial");
QTest::addColumn<QStringList>("expected");
@@ -897,7 +887,7 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("ascending")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -915,7 +905,7 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("descending")
<< 4 << 5
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -933,154 +923,151 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("empty table")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (QStringList()
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< IntList()
<< IntList()
<< IntList();
-
QTest::newRow("half-empty table")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (IntList() << 0 << 2 << 1)
<< IntList()
<< IntList();
QTest::newRow("empty column, should not sort.")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 3
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< IntList()
<< IntList()
<< IntList();
QTest::newRow("descending with null cell, the null cell should be placed at the bottom")
<< 4 << 5
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< 0
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "3" << "d" << "k" << "o" << "6"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "3" << "d" << "k" << "o" << "6"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (QStringList()
- << "3" << "d" << "k" << "o" << "6"
- << "2" << "c" << "9" << "y" << "8"
- << "0" << "a" << "o" << "8" << "k"
- << 0 << "b" << "7" << "3" << "u")
+ << "3" << "d" << "k" << "o" << "6"
+ << "2" << "c" << "9" << "y" << "8"
+ << "0" << "a" << "o" << "8" << "k"
+ << QString() << "b" << "7" << "3" << "u")
<< (IntList() << 2 << 0 << 1)
<< IntList()
<< IntList();
QTest::newRow("ascending with null cell, the null cell should be placed at the bottom")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "3" << "d" << "k" << "o" << "6"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "3" << "d" << "k" << "o" << "6"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "2" << "c" << "9" << "y" << "8"
- << "3" << "d" << "k" << "o" << "6"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "2" << "c" << "9" << "y" << "8"
+ << "3" << "d" << "k" << "o" << "6"
+ << QString() << "b" << "7" << "3" << "u")
<< (IntList() << 0 << 2 << 1)
<< IntList()
<< IntList();
QTest::newRow("ascending with null cells, the null cells should be placed at the bottom")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << "3" << "d" << "k" << "o" << "6"
- << "0" << "a" << "o" << "8" << "k"
- << 0 << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "3" << "d" << "k" << "o" << "6"
+ << "0" << "a" << "o" << "8" << "k"
+ << QString() << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "3" << "d" << "k" << "o" << "6"
- << 0 << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "3" << "d" << "k" << "o" << "6"
+ << QString() << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (IntList() << 1 << 0)
<< IntList()
<< IntList();
QTest::newRow("ascending... Check a bug in PersistentIndexes")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
<< "3" << "c" << "9" << "y" << "8"
<< "2" << "b" << "7" << "3" << "u"
<< "4" << "d" << "k" << "o" << "6"
- << "1" << "a" << "o" << "8" << "k"
- )
+ << "1" << "a" << "o" << "8" << "k")
<< (QStringList()
<< "1" << "a" << "o" << "8" << "k"
<< "2" << "b" << "7" << "3" << "u"
<< "3" << "c" << "9" << "y" << "8"
- << "4" << "d" << "k" << "o" << "6"
- )
+ << "4" << "d" << "k" << "o" << "6")
<< (IntList() << 2 << 1 << 3 << 0)
<< IntList()
<< IntList();
QTest::newRow("ascending with some null cells inbetween")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << 0 << "a" << "o" << "8" << "k"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "d" << "k" << "o" << "6"
- << "1" << "b" << "7" << "3" << "u")
+ << QString() << "a" << "o" << "8" << "k"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "d" << "k" << "o" << "6"
+ << "1" << "b" << "7" << "3" << "u")
<< (QStringList()
- << "1" << "b" << "7" << "3" << "u"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "a" << "o" << "8" << "k"
- << 0 << "d" << "k" << "o" << "6")
+ << "1" << "b" << "7" << "3" << "u"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "a" << "o" << "8" << "k"
+ << QString() << "d" << "k" << "o" << "6")
<< (IntList() << 1 << 0)
<< IntList()
<< IntList();
QTest::newRow("ascending hidden")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -1098,7 +1085,7 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("descending hidden")
<< 4 << 5
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -1119,7 +1106,7 @@ void tst_QTableWidget::sortItems()
{
QFETCH(int, rowCount);
QFETCH(int, columnCount);
- QFETCH(int, sortOrder);
+ QFETCH(Qt::SortOrder, sortOrder);
QFETCH(int, sortColumn);
QFETCH(QStringList, initial);
QFETCH(QStringList, expected);
@@ -1131,13 +1118,13 @@ void tst_QTableWidget::sortItems()
testWidget->setColumnCount(columnCount);
QAbstractItemModel *model = testWidget->model();
- QList<QPersistentModelIndex> persistent;
+ QVector<QPersistentModelIndex> persistent;
int ti = 0;
for (int r = 0; r < rowCount; ++r) {
for (int c = 0; c < columnCount; ++c) {
- QString str = initial.at(ti++);
- if (!str.isNull()) {
+ QString str = initial.at(ti++);
+ if (!str.isEmpty()) {
testWidget->setItem(r, c, new QTableWidgetItem(str));
}
}
@@ -1150,7 +1137,7 @@ void tst_QTableWidget::sortItems()
QCOMPARE(testWidget->verticalHeader()->hiddenSectionCount(), initialHidden.count());
- testWidget->sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder));
+ testWidget->sortItems(sortColumn, sortOrder);
int te = 0;
for (int i = 0; i < rows.count(); ++i) {
@@ -1175,7 +1162,7 @@ void tst_QTableWidget::setItemWithSorting_data()
{
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<int>("sortColumn");
QTest::addColumn<QStringList>("initialValues");
QTest::addColumn<int>("row");
@@ -1187,7 +1174,7 @@ void tst_QTableWidget::setItemWithSorting_data()
QTest::newRow("2x1 no change (ascending)")
<< 2 << 1
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList() << "0" << "1")
<< 1 << 0 << "2"
<< (QStringList() << "0" << "2")
@@ -1195,7 +1182,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("2x1 no change (descending)")
<< 2 << 1
- << static_cast<int>(Qt::DescendingOrder) << 0
+ << Qt::DescendingOrder << 0
<< (QStringList() << "1" << "0")
<< 0 << 0 << "2"
<< (QStringList() << "2" << "0")
@@ -1203,7 +1190,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("2x1 reorder (ascending)")
<< 2 << 1
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList() << "0" << "1")
<< 0 << 0 << "2"
<< (QStringList() << "1" << "2")
@@ -1211,7 +1198,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x1 reorder (descending)")
<< 2 << 1
- << static_cast<int>(Qt::DescendingOrder) << 0
+ << Qt::DescendingOrder << 0
<< (QStringList() << "1" << "0")
<< 1 << 0 << "2"
<< (QStringList() << "2" << "1")
@@ -1219,7 +1206,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x2 no change (ascending)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList()
<< "0" << "00"
<< "1" << "11")
@@ -1231,7 +1218,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("2x2 reorder (ascending)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList()
<< "0" << "00"
<< "1" << "11")
@@ -1243,7 +1230,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x2 reorder (ascending, sortColumn = 1)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 1
+ << Qt::AscendingOrder << 1
<< (QStringList()
<< "00" << "0"
<< "11" << "1")
@@ -1255,7 +1242,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x2 no change (column != sortColumn)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 1
+ << Qt::AscendingOrder << 1
<< (QStringList()
<< "00" << "0"
<< "11" << "1")
@@ -1267,7 +1254,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("8x4 reorder (ascending, sortColumn = 3)")
<< 8 << 4
- << static_cast<int>(Qt::AscendingOrder) << 3
+ << Qt::AscendingOrder << 3
<< (QStringList()
<< "q" << "v" << "u" << "0"
<< "e" << "j" << "i" << "10"
@@ -1293,9 +1280,13 @@ void tst_QTableWidget::setItemWithSorting_data()
void tst_QTableWidget::setItemWithSorting()
{
+ static int dummy1 = qRegisterMetaType<QList<QPersistentModelIndex>>();
+ static int dummy2 = qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>();
+ Q_UNUSED(dummy1);
+ Q_UNUSED(dummy2);
QFETCH(int, rowCount);
QFETCH(int, columnCount);
- QFETCH(int, sortOrder);
+ QFETCH(Qt::SortOrder, sortOrder);
QFETCH(int, sortColumn);
QFETCH(QStringList, initialValues);
QFETCH(int, row);
@@ -1309,7 +1300,7 @@ void tst_QTableWidget::setItemWithSorting()
QTableWidget w(rowCount, columnCount);
QAbstractItemModel *model = w.model();
- QList<QPersistentModelIndex> persistent;
+ QVector<QPersistentModelIndex> persistent;
int ti = 0;
for (int r = 0; r < rowCount; ++r) {
@@ -1320,11 +1311,11 @@ void tst_QTableWidget::setItemWithSorting()
persistent << model->index(r, sortColumn);
}
- w.sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder));
+ w.sortItems(sortColumn, sortOrder);
w.setSortingEnabled(true);
- QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
- QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged()));
+ QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged);
+ QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged);
if (i == 0) {
// set a new item
@@ -1376,7 +1367,7 @@ public:
void tst_QTableWidget::itemData()
{
QTableWidgetDataChanged widget(2, 2);
- widget.setItem(0, 0, new QTableWidgetItem());
+ widget.setItem(0, 0, new QTableWidgetItem);
QTableWidgetItem *item = widget.item(0, 0);
QVERIFY(item);
item->setFlags(item->flags() | Qt::ItemIsEditable);
@@ -1399,7 +1390,7 @@ void tst_QTableWidget::setItemData()
{
QTableWidgetDataChanged table(10, 10);
table.setSortingEnabled(false);
- QSignalSpy dataChangedSpy(table.model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)));
+ QSignalSpy dataChangedSpy(table.model(), &QAbstractItemModel::dataChanged);
QTableWidgetItem *item = new QTableWidgetItem;
table.setItem(0, 0, item);
@@ -1432,11 +1423,11 @@ void tst_QTableWidget::cellWidget()
QTableWidget table(10, 10);
QWidget widget;
- QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0));
+ QCOMPARE(table.cellWidget(5, 5), nullptr);
table.setCellWidget(5, 5, &widget);
QCOMPARE(table.cellWidget(5, 5), &widget);
table.removeCellWidget(5, 5);
- QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0));
+ QCOMPARE(table.cellWidget(5, 5), nullptr);
}
void tst_QTableWidget::cellWidgetGeometry()
@@ -1463,27 +1454,29 @@ void tst_QTableWidget::cellWidgetGeometry()
void tst_QTableWidget::sizeHint_data()
{
- QTest::addColumn<int>("scrollBarPolicy");
+ QTest::addColumn<Qt::ScrollBarPolicy>("scrollBarPolicy");
QTest::addColumn<QSize>("viewSize");
- QTest::newRow("ScrollBarAlwaysOn") << static_cast<int>(Qt::ScrollBarAlwaysOn) << QSize();
- QTest::newRow("ScrollBarAlwaysOff") << static_cast<int>(Qt::ScrollBarAlwaysOff) << QSize();
+ QTest::newRow("ScrollBarAlwaysOn") << Qt::ScrollBarAlwaysOn << QSize();
+ QTest::newRow("ScrollBarAlwaysOff") << Qt::ScrollBarAlwaysOff << QSize();
// make sure the scrollbars are shown by resizing the view to 40x40
- QTest::newRow("ScrollBarAsNeeded (40x40)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(40, 40);
- QTest::newRow("ScrollBarAsNeeded (1000x1000)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(1000, 1000);
+ QTest::newRow("ScrollBarAsNeeded (40x40)") << Qt::ScrollBarAsNeeded << QSize(40, 40);
+ QTest::newRow("ScrollBarAsNeeded (1000x1000)") << Qt::ScrollBarAsNeeded << QSize(1000, 1000);
}
void tst_QTableWidget::sizeHint()
{
- QFETCH(int, scrollBarPolicy);
+ QFETCH(Qt::ScrollBarPolicy, scrollBarPolicy);
QFETCH(QSize, viewSize);
QTableWidget view(2, 2);
view.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
- view.setVerticalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
- view.setHorizontalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
- for (int r = 0 ; r < view.rowCount(); ++r)
+ view.setVerticalScrollBarPolicy(scrollBarPolicy);
+ view.setHorizontalScrollBarPolicy(scrollBarPolicy);
+ for (int r = 0 ; r < view.rowCount(); ++r) {
+ const QString rStr = QString::number(r) + QLatin1Char('/');
for (int c = 0 ; c < view.columnCount(); ++c)
- view.setItem(r, c, new QTableWidgetItem(QString("%1/%2").arg(r).arg(c)));
+ view.setItem(r, c, new QTableWidgetItem(rStr + QString::number(c)));
+ }
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -1520,7 +1513,7 @@ void tst_QTableWidget::task231094()
if (y == 1)
twi->setFlags(Qt::ItemIsEnabled);
else
- twi->setFlags(0);
+ twi->setFlags({});
tw.setItem(y, x, twi);
}
}
@@ -1558,15 +1551,15 @@ void tst_QTableWidget::task262056_sortDuplicate()
testWidget->setColumnCount(2);
testWidget->setRowCount(8);
testWidget->setSortingEnabled(true);
- QStringList items = (QStringList() << "AAA" << "BBB" << "CCC" << "CCC" << "DDD"\
- << "EEE" << "FFF" << "GGG");
- for (int i = 0; i<8; i++ ) {
+ const QStringList items({"AAA", "BBB", "CCC", "CCC", "DDD",
+ "EEE", "FFF", "GGG"});
+ for (int i = 0; i < 8; i++ ) {
QTableWidgetItem *twi = new QTableWidgetItem(items.at(i));
- testWidget->setItem(i,0,twi);
- testWidget->setItem(i,1,new QTableWidgetItem(QLatin1String("item ") + QString::number(i)));
+ testWidget->setItem(i, 0, twi);
+ testWidget->setItem(i, 1, new QTableWidgetItem(QLatin1String("item ") + QString::number(i)));
}
testWidget->sortItems(0, Qt::AscendingOrder);
- QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged()));
+ QSignalSpy layoutChangedSpy(testWidget->model(), &QAbstractItemModel::layoutChanged);
testWidget->item(3,0)->setBackground(Qt::red);
QCOMPARE(layoutChangedSpy.count(),0);
@@ -1586,18 +1579,14 @@ void tst_QTableWidget::itemWithHeaderItems()
QTableWidgetItem *item1_0 = new QTableWidgetItem(QTableWidgetItem::UserType);
table.setItem(1, 0, item1_0);
- QCOMPARE(table.item(0, 1), static_cast<QTableWidgetItem *>(0));
+ QCOMPARE(table.item(0, 1), nullptr);
}
class TestTableWidget : public QTableWidget
{
Q_OBJECT
public:
- TestTableWidget(int rows, int columns, QWidget *parent = 0)
- : QTableWidget(rows, columns, parent)
- {
- }
-
+ using QTableWidget::QTableWidget;
using QTableWidget::mimeData;
using QTableWidget::indexFromItem;
using QTableWidget::keyPressEvent;
@@ -1661,18 +1650,19 @@ void tst_QTableWidget::selectedRowAfterSorting()
{
TestTableWidget table(3,3);
table.setSelectionBehavior(QAbstractItemView::SelectRows);
- for (int r = 0; r < 3; r++)
+ for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++)
- table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0")));
+ table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0")));
+ }
QHeaderView *localHorizontalHeader = table.horizontalHeader();
localHorizontalHeader->setSortIndicator(1,Qt::DescendingOrder);
table.setProperty("sortingEnabled",true);
table.selectRow(1);
table.item(1,1)->setText("9");
QCOMPARE(table.selectedItems().count(),3);
- foreach (QTableWidgetItem *item, table.selectedItems()) {
- QCOMPARE(item->row(),0);
- }
+ const auto selectedItems = table.selectedItems();
+ for (QTableWidgetItem *item : selectedItems)
+ QCOMPARE(item->row(), 0);
}
void tst_QTableWidget::search()
@@ -1717,10 +1707,11 @@ void tst_QTableWidget::search()
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void tst_QTableWidget::clearItemData()
{
- QTableWidget table(3,3);
- for (int r = 0; r < 3; r++)
+ QTableWidget table(3, 3);
+ for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++)
- table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0")));
+ table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0")));
+ }
QSignalSpy dataChangeSpy(table.model(), &QAbstractItemModel::dataChanged);
QVERIFY(dataChangeSpy.isValid());
QVERIFY(!table.model()->clearItemData(QModelIndex()));
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 2a1163ec66..44195d3b25 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -27,13 +27,28 @@
****************************************************************************/
#include "../../../../shared/fakedirmodel.h"
-#include <qabstractitemview.h>
-#include <QtTest/QtTest>
-#include <QtGui/QtGui>
-#include <QtWidgets/QtWidgets>
-#include <private/qtreeview_p.h>
-#include <QtTest/private/qtesthelpers_p.h>
+#include <QDesktopWidget>
+#include <QHeaderView>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMainWindow>
+#include <QProxyStyle>
+#include <QPushButton>
+#include <QScrollBar>
+#include <QSignalSpy>
+#include <QSortFilterProxyModel>
+#include <QStatusBar>
+#include <QStringListModel>
+#include <QStyledItemDelegate>
+#include <QTextEdit>
+#include <QTimer>
+#include <QToolButton>
+#include <QTreeWidget>
+#include <QTest>
+#include <QVBoxLayout>
+#include <private/qtreeview_p.h>
+#include <private/qtesthelpers_p.h>
using namespace QTestPrivate;
@@ -43,6 +58,7 @@ Q_DECLARE_METATYPE(QAbstractItemView::DragDropMode)
Q_DECLARE_METATYPE(QAbstractItemView::EditTriggers)
Q_DECLARE_METATYPE(QAbstractItemView::EditTrigger)
+using IntBounds = std::numeric_limits<int>;
static void initStandardTreeModel(QStandardItemModel *model)
{
QStandardItem *item;
@@ -206,18 +222,11 @@ private slots:
class QtTestModel: public QAbstractItemModel
{
+ Q_OBJECT
public:
- QtTestModel(QObject *parent = 0): QAbstractItemModel(parent),
- fetched(false), rows(0), cols(0), levels(INT_MAX), wrongIndex(false) { init(); }
-
- QtTestModel(int _rows, int _cols, QObject *parent = 0): QAbstractItemModel(parent),
- fetched(false), rows(_rows), cols(_cols), levels(INT_MAX), wrongIndex(false) { init(); }
-
- void init()
- {
- decorationsEnabled = false;
- statusTipsEnabled = false;
- }
+ QtTestModel(int _rows, int _cols, QObject *parent = nullptr)
+ : QAbstractItemModel(parent), rows(_rows), cols(_cols)
+ {}
inline qint32 level(const QModelIndex &index) const
{
@@ -264,7 +273,7 @@ public:
if (row < 0 || column < 0 || (level(parent) > levels) || column >= cols || row >= rows) {
return QModelIndex();
}
- QModelIndex i = createIndex(row, column, level(parent) + 1);
+ QModelIndex i = createIndex(row, column, quintptr(level(parent) + 1));
parentHash[i] = parent;
return i;
}
@@ -361,13 +370,14 @@ public:
decorationsEnabled = enable;
}
- mutable bool fetched;
- bool decorationsEnabled;
- bool statusTipsEnabled;
- int rows, cols;
- int levels;
- mutable bool wrongIndex;
mutable QMap<QModelIndex,QModelIndex> parentHash;
+ int rows = 0;
+ int cols = 0;
+ int levels = IntBounds::max();
+ mutable bool wrongIndex = false;
+ mutable bool fetched = false;
+ bool decorationsEnabled = false;
+ bool statusTipsEnabled = false;
};
// Testing get/set functions
@@ -377,14 +387,15 @@ void tst_QTreeView::getSetCheck()
// int QTreeView::indentation()
// void QTreeView::setIndentation(int)
- const int styledIndentation = obj1.style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, &obj1);
+ const int styledIndentation = obj1.style()->pixelMetric(
+ QStyle::PM_TreeViewIndentation, nullptr, &obj1);
QCOMPARE(obj1.indentation(), styledIndentation);
obj1.setIndentation(0);
QCOMPARE(obj1.indentation(), 0);
- obj1.setIndentation(INT_MIN);
- QCOMPARE(obj1.indentation(), INT_MIN);
- obj1.setIndentation(INT_MAX);
- QCOMPARE(obj1.indentation(), INT_MAX);
+ obj1.setIndentation(IntBounds::min());
+ QCOMPARE(obj1.indentation(), IntBounds::min());
+ obj1.setIndentation(IntBounds::max());
+ QCOMPARE(obj1.indentation(), IntBounds::max());
// bool QTreeView::rootIsDecorated()
// void QTreeView::setRootIsDecorated(bool)
@@ -477,7 +488,8 @@ void tst_QTreeView::construction()
QCOMPARE(view.sizeHintForRow(1), -1);
QVERIFY(!view.tabKeyNavigation());
QCOMPARE(view.textElideMode(), Qt::ElideRight);
- QCOMPARE(static_cast<int>(view.verticalScrollMode()), view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, &view));
+ QCOMPARE(static_cast<int>(view.verticalScrollMode()),
+ view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, nullptr, &view));
QCOMPARE(view.visualRect(QModelIndex()), QRect());
// QTreeView properties
@@ -493,8 +505,8 @@ void tst_QTreeView::construction()
QCOMPARE(view.columnWidth(0), 0);
QCOMPARE(view.columnWidth(1), 0);
QVERIFY(view.header());
- const int styledIndentation = view.style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, &view);
- QCOMPARE(view.indentation(), styledIndentation);
+ QCOMPARE(view.indentation(),
+ view.style()->pixelMetric(QStyle::PM_TreeViewIndentation, nullptr, &view));
QCOMPARE(view.indexAbove(QModelIndex()), QModelIndex());
QCOMPARE(view.indexBelow(QModelIndex()), QModelIndex());
QVERIFY(!view.isAnimated());
@@ -781,17 +793,17 @@ void tst_QTreeView::editTriggers()
break;
case QAbstractItemView::DoubleClicked:
// Doubleclick the center of the current cell
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0,
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
view.visualRect(view.model()->index(0, 0)).center());
- QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0,
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, {},
view.visualRect(view.model()->index(0, 0)).center());
break;
case QAbstractItemView::SelectedClicked:
// Click the center of the current cell
view.selectionModel()->select(view.model()->index(0, 0), QItemSelectionModel::Select);
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0,
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
view.visualRect(view.model()->index(0, 0)).center());
- QTest::qWait(int(QApplication::doubleClickInterval() * 1.5));
+ QTest::qWait(qRound(QApplication::doubleClickInterval() * 1.5));
break;
case QAbstractItemView::EditKeyPressed:
view.setFocus();
@@ -808,7 +820,7 @@ void tst_QTreeView::editTriggers()
}
// Check if we got an editor
- QTRY_COMPARE(view.findChild<QLineEdit *>(QString()) != 0, editorOpened);
+ QTRY_COMPARE(view.findChild<QLineEdit *>(QString()) != nullptr, editorOpened);
}
void tst_QTreeView::hasAutoScroll()
@@ -860,11 +872,11 @@ void tst_QTreeView::horizontalScrollMode()
class RepaintTreeView : public QTreeView
{
public:
- RepaintTreeView() : repainted(false) { }
- bool repainted;
+ using QTreeView::QTreeView;
+ bool repainted = false;
protected:
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *event) override
{ repainted = true; QTreeView::paintEvent(event); }
};
@@ -902,8 +914,7 @@ void tst_QTreeView::iconSize()
void tst_QTreeView::indexAt()
{
- QtTestModel model;
- model.rows = model.cols = 5;
+ QtTestModel model(5, 5);
QTreeView view;
QCOMPARE(view.indexAt(QPoint()), QModelIndex());
@@ -985,21 +996,21 @@ void tst_QTreeView::indexWidget()
void tst_QTreeView::itemDelegate()
{
QPointer<QAbstractItemDelegate> oldDelegate;
- QPointer<QItemDelegate> otherItemDelegate;
+ QPointer<QStyledItemDelegate> otherItemDelegate;
{
QTreeView view;
QVERIFY(qobject_cast<QStyledItemDelegate *>(view.itemDelegate()));
QPointer<QAbstractItemDelegate> oldDelegate = view.itemDelegate();
- otherItemDelegate = new QItemDelegate;
+ otherItemDelegate = new QStyledItemDelegate;
view.setItemDelegate(otherItemDelegate);
QVERIFY(!otherItemDelegate->parent());
QVERIFY(oldDelegate);
- QCOMPARE(view.itemDelegate(), (QAbstractItemDelegate *)otherItemDelegate);
+ QCOMPARE(view.itemDelegate(), otherItemDelegate);
- view.setItemDelegate(0);
+ view.setItemDelegate(nullptr);
QVERIFY(!view.itemDelegate()); // <- view does its own drawing?
QVERIFY(otherItemDelegate);
}
@@ -1038,29 +1049,29 @@ void tst_QTreeView::itemDelegateForColumnOrRow()
QCOMPARE(view.itemDelegate(QModelIndex()), defaultDelegate);
QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), defaultDelegate);
- QPointer<QAbstractItemDelegate> rowDelegate = new QItemDelegate;
+ QPointer<QAbstractItemDelegate> rowDelegate = new QStyledItemDelegate;
view.setItemDelegateForRow(0, rowDelegate);
QVERIFY(!rowDelegate->parent());
- QCOMPARE(view.itemDelegateForRow(0), (QAbstractItemDelegate *)rowDelegate);
- QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), (QAbstractItemDelegate *)rowDelegate);
- QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), (QAbstractItemDelegate *)rowDelegate);
+ QCOMPARE(view.itemDelegateForRow(0), rowDelegate);
+ QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), rowDelegate);
+ QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), rowDelegate);
QCOMPARE(view.itemDelegate(view.model()->index(1, 0)), defaultDelegate);
QCOMPARE(view.itemDelegate(view.model()->index(1, 1)), defaultDelegate);
- QPointer<QAbstractItemDelegate> columnDelegate = new QItemDelegate;
+ QPointer<QAbstractItemDelegate> columnDelegate = new QStyledItemDelegate;
view.setItemDelegateForColumn(1, columnDelegate);
QVERIFY(!columnDelegate->parent());
- QCOMPARE(view.itemDelegateForColumn(1), (QAbstractItemDelegate *)columnDelegate);
- QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), (QAbstractItemDelegate *)rowDelegate);
- QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), (QAbstractItemDelegate *)rowDelegate); // row wins
+ QCOMPARE(view.itemDelegateForColumn(1), columnDelegate);
+ QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), rowDelegate);
+ QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), rowDelegate); // row wins
QCOMPARE(view.itemDelegate(view.model()->index(1, 0)), defaultDelegate);
- QCOMPARE(view.itemDelegate(view.model()->index(1, 1)), (QAbstractItemDelegate *)columnDelegate);
+ QCOMPARE(view.itemDelegate(view.model()->index(1, 1)), columnDelegate);
- view.setItemDelegateForRow(0, 0);
+ view.setItemDelegateForRow(0, nullptr);
QVERIFY(!view.itemDelegateForRow(0));
QVERIFY(rowDelegate); // <- wasn't deleted
- view.setItemDelegateForColumn(1, 0);
+ view.setItemDelegateForColumn(1, nullptr);
QVERIFY(!view.itemDelegateForColumn(1));
QVERIFY(columnDelegate); // <- wasn't deleted
@@ -1130,12 +1141,9 @@ void tst_QTreeView::keyboardSearch()
QTest::qWait(QApplication::keyboardInputInterval() * 2);
model.clear();
view.setCurrentIndex(QModelIndex());
- QList<QStandardItem *> items = { new QStandardItem("Andreas"), new QStandardItem("Alicia") };
- model.appendRow(items);
- items = { new QStandardItem("Baldrian"), new QStandardItem("Belinda") };
- model.appendRow(items);
- items = { new QStandardItem("Cecilie"), new QStandardItem("Claire") };
- model.appendRow(items);
+ model.appendRow({ new QStandardItem("Andreas"), new QStandardItem("Alicia") });
+ model.appendRow({ new QStandardItem("Baldrian"), new QStandardItem("Belinda") });
+ model.appendRow({ new QStandardItem("Cecilie"), new QStandardItem("Claire") });
QVERIFY(!view.selectionModel()->hasSelection());
QVERIFY(!view.selectionModel()->isSelected(model.index(0, 0)));
@@ -1166,8 +1174,7 @@ void tst_QTreeView::keyboardSearch()
QCOMPARE(view.currentIndex(), model.index(1, 1));
// Test that it wraps round
- items = { new QStandardItem("Andy"), new QStandardItem("Adele") };
- model.appendRow(items);
+ model.appendRow({ new QStandardItem("Andy"), new QStandardItem("Adele") });
QTest::qWait(QApplication::keyboardInputInterval() * 2);
view.keyboardSearch(QLatin1String("A"));
QVERIFY(view.selectionModel()->isSelected(model.index(3, 1)));
@@ -1202,17 +1209,16 @@ void tst_QTreeView::keyboardSearch()
void tst_QTreeView::keyboardSearchMultiColumn()
{
QTreeView view;
-
QStandardItemModel model(4, 2);
model.setItem(0, 0, new QStandardItem("1")); model.setItem(0, 1, new QStandardItem("green"));
- model.setItem(1, 0, new QStandardItem("bad")); model.setItem(1, 1, new QStandardItem("eggs"));
- model.setItem(2, 0, new QStandardItem("moof")); model.setItem(2, 1, new QStandardItem("and"));
- model.setItem(3, 0, new QStandardItem("elf")); model.setItem(3, 1, new QStandardItem("ham"));
+ model.setItem(1, 0, new QStandardItem("bad")); model.setItem(1, 1, new QStandardItem("eggs"));
+ model.setItem(2, 0, new QStandardItem("moof")); model.setItem(2, 1, new QStandardItem("and"));
+ model.setItem(3, 0, new QStandardItem("elf")); model.setItem(3, 1, new QStandardItem("ham"));
view.setModel(&model);
view.show();
- qApp->setActiveWindow(&view);
+ QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
view.setCurrentIndex(model.index(0, 1));
@@ -1240,22 +1246,22 @@ void tst_QTreeView::setModel()
for (int x = 0; x < 2; ++x) {
QtTestModel *model = new QtTestModel(10, 8);
QAbstractItemModel *oldModel = view.model();
- QSignalSpy modelDestroyedSpy(oldModel ? oldModel : model, SIGNAL(destroyed()));
+ QSignalSpy modelDestroyedSpy(oldModel ? oldModel : model, &QObject::destroyed);
// set the same model twice
for (int i = 0; i < 2; ++i) {
QItemSelectionModel *oldSelectionModel = view.selectionModel();
QItemSelectionModel *dummy = new QItemSelectionModel(model);
QSignalSpy selectionModelDestroyedSpy(
- oldSelectionModel ? oldSelectionModel : dummy, SIGNAL(destroyed()));
+ oldSelectionModel ? oldSelectionModel : dummy, &QObject::destroyed);
view.setModel(model);
// QCOMPARE(selectionModelDestroyedSpy.count(), (x == 0 || i == 1) ? 0 : 1);
- QCOMPARE(view.model(), (QAbstractItemModel *)model);
- QCOMPARE(view.header()->model(), (QAbstractItemModel *)model);
+ QCOMPARE(view.model(), model);
+ QCOMPARE(view.header()->model(), model);
QCOMPARE(view.selectionModel() != oldSelectionModel, (i == 0));
}
QTRY_COMPARE(modelDestroyedSpy.count(), 0);
- view.setModel(0);
+ view.setModel(nullptr);
QCOMPARE(view.model(), nullptr);
// ### shouldn't selectionModel also be 0 now?
// QCOMPARE(view.selectionModel(), nullptr);
@@ -1278,7 +1284,7 @@ void tst_QTreeView::openPersistentEditor()
view.closePersistentEditor(view.model()->index(0, 0));
QVERIFY(!view.viewport()->findChild<QLineEdit *>()->isVisible());
- qApp->sendPostedEvents(0, QEvent::DeferredDelete);
+ QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
QVERIFY(!view.viewport()->findChild<QLineEdit *>());
}
@@ -1300,21 +1306,20 @@ void tst_QTreeView::rootIndex()
void tst_QTreeView::setHeader()
{
QTreeView view;
- QVERIFY(view.header() != 0);
+ QVERIFY(view.header() != nullptr);
QCOMPARE(view.header()->orientation(), Qt::Horizontal);
- QCOMPARE(view.header()->parent(), (QObject *)&view);
+ QCOMPARE(view.header()->parent(), &view);
for (int x = 0; x < 2; ++x) {
- QSignalSpy destroyedSpy(view.header(), SIGNAL(destroyed()));
+ QSignalSpy destroyedSpy(view.header(), &QObject::destroyed);
Qt::Orientation orient = x ? Qt::Vertical : Qt::Horizontal;
QHeaderView *head = new QHeaderView(orient);
view.setHeader(head);
QCOMPARE(destroyedSpy.count(), 1);
- QCOMPARE(head->parent(), (QObject *)&view);
+ QCOMPARE(head->parent(), &view);
QCOMPARE(view.header(), head);
view.setHeader(head);
QCOMPARE(view.header(), head);
- // Itemviews in Qt < 4.2 have asserts for this. Qt >= 4.2 should handle this gracefully
- view.setHeader((QHeaderView *)0);
+ view.setHeader(nullptr);
QCOMPARE(view.header(), head);
}
}
@@ -1328,13 +1333,13 @@ void tst_QTreeView::columnHidden()
for (int c = 0; c < model.columnCount(); ++c)
QCOMPARE(view.isColumnHidden(c), false);
// hide even columns
- for (int c = 0; c < model.columnCount(); c+=2)
+ for (int c = 0; c < model.columnCount(); c += 2)
view.setColumnHidden(c, true);
for (int c = 0; c < model.columnCount(); ++c)
QCOMPARE(view.isColumnHidden(c), (c & 1) == 0);
view.update();
// hide odd columns too
- for (int c = 1; c < model.columnCount(); c+=2)
+ for (int c = 1; c < model.columnCount(); c += 2)
view.setColumnHidden(c, true);
for (int c = 0; c < model.columnCount(); ++c)
QCOMPARE(view.isColumnHidden(c), true);
@@ -1418,7 +1423,7 @@ void tst_QTreeView::noDelegate()
QtTestModel model(10, 7);
QTreeView view;
view.setModel(&model);
- view.setItemDelegate(0);
+ view.setItemDelegate(nullptr);
QCOMPARE(view.itemDelegate(), nullptr);
}
@@ -1427,11 +1432,13 @@ void tst_QTreeView::noModel()
QTreeView view;
view.show();
view.setRowHidden(0, QModelIndex(), true);
+ // no model -> not able to hide a row
+ QVERIFY(!view.isRowHidden(0, QModelIndex()));
}
void tst_QTreeView::emptyModel()
{
- QtTestModel model;
+ QtTestModel model(0, 0);
QTreeView view;
view.setModel(&model);
view.show();
@@ -1486,7 +1493,7 @@ void tst_QTreeView::limitedExpand()
QTreeView view;
view.setModel(&model);
- QSignalSpy spy(&view, SIGNAL(expanded(QModelIndex)));
+ QSignalSpy spy(&view, &QTreeView::expanded);
QVERIFY(spy.isValid());
view.expand(model.index(0, 0));
@@ -1500,7 +1507,7 @@ void tst_QTreeView::limitedExpand()
QTreeView view;
view.setModel(&model);
- QSignalSpy spy(&view, SIGNAL(expanded(QModelIndex)));
+ QSignalSpy spy(&view, &QTreeView::expanded);
QVERIFY(spy.isValid());
view.expand(model.index(0, 0));
@@ -1515,7 +1522,6 @@ void tst_QTreeView::expandAndCollapse_data()
QTest::addColumn<bool>("animationEnabled");
QTest::newRow("normal") << false;
QTest::newRow("animated") << true;
-
}
void tst_QTreeView::expandAndCollapse()
@@ -1533,8 +1539,8 @@ void tst_QTreeView::expandAndCollapse()
QModelIndex a = model.index(0, 0, QModelIndex());
QModelIndex b = model.index(0, 0, a);
- QSignalSpy expandedSpy(&view, SIGNAL(expanded(QModelIndex)));
- QSignalSpy collapsedSpy(&view, SIGNAL(collapsed(QModelIndex)));
+ QSignalSpy expandedSpy(&view, &QTreeView::expanded);
+ QSignalSpy collapsedSpy(&view, &QTreeView::collapsed);
QVariantList args;
for (int y = 0; y < 2; ++y) {
@@ -1744,7 +1750,7 @@ void tst_QTreeView::expandAndCollapseAll()
void tst_QTreeView::expandWithNoChildren()
{
QTreeView tree;
- QStandardItemModel model(1,1);
+ QStandardItemModel model(1, 1);
tree.setModel(&model);
tree.setAnimated(true);
tree.doItemsLayout();
@@ -1765,14 +1771,15 @@ void tst_QTreeView::keyboardNavigation()
view.setModel(&model);
view.show();
- QVector<Qt::Key> keymoves;
- keymoves << Qt::Key_Down << Qt::Key_Right << Qt::Key_Right << Qt::Key_Right
- << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down
- << Qt::Key_Right << Qt::Key_Right << Qt::Key_Right
- << Qt::Key_Left << Qt::Key_Up << Qt::Key_Left << Qt::Key_Left
- << Qt::Key_Up << Qt::Key_Down << Qt::Key_Up << Qt::Key_Up
- << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up
- << Qt::Key_Left << Qt::Key_Left << Qt::Key_Up << Qt::Key_Down;
+ const auto keymoves = {
+ Qt::Key_Down, Qt::Key_Right, Qt::Key_Right, Qt::Key_Right,
+ Qt::Key_Down, Qt::Key_Down, Qt::Key_Down, Qt::Key_Down,
+ Qt::Key_Right, Qt::Key_Right, Qt::Key_Right,
+ Qt::Key_Left, Qt::Key_Up, Qt::Key_Left, Qt::Key_Left,
+ Qt::Key_Up, Qt::Key_Down, Qt::Key_Up, Qt::Key_Up,
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Up,
+ Qt::Key_Left, Qt::Key_Left, Qt::Key_Up, Qt::Key_Down
+ };
int row = 0;
int column = 0;
@@ -1780,8 +1787,7 @@ void tst_QTreeView::keyboardNavigation()
view.setCurrentIndex(index);
QCOMPARE(view.currentIndex(), index);
- for (int i = 0; i < keymoves.size(); ++i) {
- Qt::Key key = keymoves.at(i);
+ for (Qt::Key key : keymoves) {
QTest::keyClick(&view, key);
switch (key) {
@@ -1838,10 +1844,10 @@ void tst_QTreeView::keyboardNavigation()
class Dmodel : public QtTestModel
{
+ Q_OBJECT
public:
- Dmodel() : QtTestModel(10, 10){}
-
- int columnCount(const QModelIndex &parent) const
+ using QtTestModel::QtTestModel;
+ int columnCount(const QModelIndex &parent) const override
{
if (parent.row() == 5)
return 1;
@@ -1851,7 +1857,7 @@ public:
void tst_QTreeView::headerSections()
{
- Dmodel model;
+ Dmodel model(10, 10);
QTreeView view;
QHeaderView *header = view.header();
@@ -1895,7 +1901,8 @@ void tst_QTreeView::moveCursor()
view.setColumnHidden(0, true);
QVERIFY(view.isColumnHidden(0));
view.show();
- qApp->setActiveWindow(&view);
+ QApplication::setActiveWindow(&view);
+ QVERIFY(QTest::qWaitForWindowActive(&view));
//here the first visible index should be selected
//because the view got the focus
@@ -1938,73 +1945,60 @@ void tst_QTreeView::moveCursor()
QCOMPARE(view.currentIndex(), expected);
}
-class TestDelegate : public QItemDelegate
+class TestDelegate : public QStyledItemDelegate
{
+ Q_OBJECT
public:
- TestDelegate(QObject *parent) : QItemDelegate(parent) {}
- QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const { return QSize(200, 50); }
+ using QStyledItemDelegate::QStyledItemDelegate;
+ QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override
+ { return QSize(200, 50); }
};
-typedef QList<QPoint> PointList;
+typedef QVector<QPoint> PointList;
void tst_QTreeView::setSelection_data()
{
QTest::addColumn<QRect>("selectionRect");
- QTest::addColumn<int>("selectionMode");
- QTest::addColumn<int>("selectionCommand");
+ QTest::addColumn<QAbstractItemView::SelectionMode>("selectionMode");
+ QTest::addColumn<QItemSelectionModel::SelectionFlags>("selectionCommand");
QTest::addColumn<PointList>("expectedItems");
QTest::addColumn<int>("verticalOffset");
- QTest::newRow("(0,0,50,20),rows") << QRect(0,0,50,20)
- << int(QAbstractItemView::SingleSelection)
- << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows)
- << (PointList()
- << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0)
- )
- << 0;
-
- QTest::newRow("(0,0,50,90),rows") << QRect(0,0,50,90)
- << int(QAbstractItemView::ExtendedSelection)
- << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows)
- << (PointList()
- << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0)
- << QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1)
- )
- << 0;
-
- QTest::newRow("(50,0,0,90),rows,invalid rect") << QRect(QPoint(50, 0), QPoint(0, 90))
- << int(QAbstractItemView::ExtendedSelection)
- << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows)
- << (PointList()
- << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0)
- << QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1)
- )
- << 0;
-
- QTest::newRow("(0,-20,20,50),rows") << QRect(0,-20,20,50)
- << int(QAbstractItemView::ExtendedSelection)
- << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows)
- << (PointList()
- << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0)
- << QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1)
- )
- << 1;
- QTest::newRow("(0,-50,20,90),rows") << QRect(0,-50,20,90)
- << int(QAbstractItemView::ExtendedSelection)
- << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows)
- << (PointList()
- << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0)
- << QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1)
- )
- << 1;
-
+ const PointList pl1{QPoint(0, 0), QPoint(1, 0), QPoint(2, 0), QPoint(3, 0), QPoint(4, 0)};
+ const PointList pl2{QPoint(0, 0), QPoint(1, 0), QPoint(2, 0), QPoint(3, 0), QPoint(4, 0),
+ QPoint(0, 1), QPoint(1, 1), QPoint(2, 1), QPoint(3, 1), QPoint(4, 1)};
+ const QItemSelectionModel::SelectionFlags selFlags(QItemSelectionModel::ClearAndSelect |
+ QItemSelectionModel::Rows);
+ QTest::newRow("(0,0,50,20),rows")
+ << QRect(0, 0, 50, 20)
+ << QAbstractItemView::SingleSelection
+ << selFlags << pl1 << 0;
+
+ QTest::newRow("(0,0,50,90),rows")
+ << QRect(0, 0, 50, 90)
+ << QAbstractItemView::ExtendedSelection
+ << selFlags << pl2 << 0;
+
+ QTest::newRow("(50,0,0,90),rows,invalid rect")
+ << QRect(QPoint(50, 0), QPoint(0, 90))
+ << QAbstractItemView::ExtendedSelection
+ << selFlags << pl2 << 0;
+
+ QTest::newRow("(0,-20,20,50),rows")
+ << QRect(0, -20, 20, 50)
+ << QAbstractItemView::ExtendedSelection
+ << selFlags << pl2 << 1;
+ QTest::newRow("(0,-50,20,90),rows")
+ << QRect(0, -50, 20, 90)
+ << QAbstractItemView::ExtendedSelection
+ << selFlags << pl2 << 1;
}
void tst_QTreeView::setSelection()
{
QFETCH(QRect, selectionRect);
- QFETCH(int, selectionMode);
- QFETCH(int, selectionCommand);
+ QFETCH(QAbstractItemView::SelectionMode, selectionMode);
+ QFETCH(QItemSelectionModel::SelectionFlags, selectionCommand);
QFETCH(PointList, expectedItems);
QFETCH(int, verticalOffset);
@@ -2016,25 +2010,23 @@ void tst_QTreeView::setSelection()
view.show();
view.setRootIsDecorated(false);
view.setItemDelegate(new TestDelegate(&view));
- view.setSelectionMode(QAbstractItemView::SelectionMode(selectionMode));
+ view.setSelectionMode(selectionMode);
view.setModel(&model);
view.setUniformRowHeights(true);
view.setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
view.scrollTo(model.index(verticalOffset, 0), QAbstractItemView::PositionAtTop);
- view.setSelection(selectionRect, QItemSelectionModel::SelectionFlags(selectionCommand));
+ view.setSelection(selectionRect, selectionCommand);
QItemSelectionModel *selectionModel = view.selectionModel();
QVERIFY(selectionModel);
- QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
+ const QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
#ifdef Q_OS_WINRT
QEXPECT_FAIL("(0,-20,20,50),rows", "Fails on WinRT - QTBUG-68297", Abort);
QEXPECT_FAIL("(0,-50,20,90),rows", "Fails on WinRT - QTBUG-68297", Abort);
#endif
QCOMPARE(selectedIndexes.count(), expectedItems.count());
- for (int i = 0; i < selectedIndexes.count(); ++i) {
- QModelIndex idx = selectedIndexes.at(i);
+ for (const QModelIndex &idx : selectedIndexes)
QVERIFY(expectedItems.contains(QPoint(idx.column(), idx.row())));
- }
}
void tst_QTreeView::indexAbove()
@@ -2134,7 +2126,7 @@ void tst_QTreeView::clicked()
QModelIndex index = view.indexAt(p);
if (!index.isValid())
continue;
- QSignalSpy spy(&view, SIGNAL(clicked(QModelIndex)));
+ QSignalSpy spy(&view, &QTreeView::clicked);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p);
QTRY_COMPARE(spy.count(), 1);
}
@@ -2149,9 +2141,9 @@ void tst_QTreeView::mouseDoubleClick()
for (int i = 0; i < model.rowCount(); i++) {
QModelIndex index = model.index(i, 0, QModelIndex());
model.insertRows(0, 20, index);
- model.insertColumns(0,2,index);
+ model.insertColumns(0, 2,index);
for (int i1 = 0; i1 < model.rowCount(index); i1++) {
- (void)model.index(i1, 0, index);
+ QVERIFY(model.index(i1, 0, index).isValid());
}
}
@@ -2159,8 +2151,8 @@ void tst_QTreeView::mouseDoubleClick()
view.setModel(&model);
// make sure the viewport height is smaller than the contents height.
- view.resize(200,200);
- view.move(0,0);
+ view.resize(200, 200);
+ view.move(0, 0);
view.show();
QModelIndex index = model.index(0, 0, QModelIndex());
view.setCurrentIndex(index);
@@ -2170,9 +2162,8 @@ void tst_QTreeView::mouseDoubleClick()
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
// Make sure all items are collapsed
- for (int i = 0; i < model.rowCount(QModelIndex()); i++) {
- view.setExpanded(model.index(i,0, QModelIndex()), false);
- }
+ for (int i = 0; i < model.rowCount(QModelIndex()); i++)
+ view.setExpanded(model.index(i, 0, QModelIndex()), false);
int maximum = view.verticalScrollBar()->maximum();
@@ -2210,14 +2201,13 @@ void tst_QTreeView::rowsAboutToBeRemoved()
view.setCurrentIndex(index);
view.setExpanded(model.index(0,0, QModelIndex()), true);
- for (int i = 0; i < model.rowCount(QModelIndex()); i++) {
- view.setExpanded(model.index(i,0, QModelIndex()), true);
- }
+ for (int i = 0; i < model.rowCount(QModelIndex()); i++)
+ view.setExpanded(model.index(i, 0, QModelIndex()), true);
- QSignalSpy spy1(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)));
+ QSignalSpy spy1(&model, &QAbstractItemModel::rowsAboutToBeRemoved);
model.removeRows(1,1);
- QCOMPARE(int(view.state()), 0);
+ QCOMPARE((view.state()), 0);
// Should not be 5 (or any other number for that sake :)
QCOMPARE(spy1.count(), 1);
@@ -2241,8 +2231,7 @@ void tst_QTreeView::headerSections_unhideSection()
void tst_QTreeView::columnAt()
{
- QtTestModel model;
- model.rows = model.cols = 10;
+ QtTestModel model(10, 10);
QTreeView view;
view.resize(500,500);
view.setModel(&model);
@@ -2256,8 +2245,7 @@ void tst_QTreeView::scrollTo()
#define CHECK_VISIBLE(ROW,COL) QVERIFY(QRect(QPoint(),view.viewport()->size()).contains(\
view.visualRect(model.index((ROW),(COL),QModelIndex()))))
- QtTestModel model;
- model.rows = model.cols = 100;
+ QtTestModel model(100, 100);
QTreeView view;
view.setUniformRowHeights(true);
view.scrollTo(QModelIndex(), QTreeView::PositionAtTop);
@@ -2268,19 +2256,18 @@ void tst_QTreeView::scrollTo()
// ### create a data function for this test
view.scrollTo(QModelIndex());
- view.scrollTo(model.index(0,0,QModelIndex()));
- view.scrollTo(model.index(0,0,QModelIndex()), QTreeView::PositionAtTop);
- view.scrollTo(model.index(0,0,QModelIndex()), QTreeView::PositionAtBottom);
-
- //
+ view.scrollTo(model.index(0, 0, QModelIndex()));
+ view.scrollTo(model.index(0, 0, QModelIndex()), QTreeView::PositionAtTop);
+ view.scrollTo(model.index(0, 0, QModelIndex()), QTreeView::PositionAtBottom);
view.show();
view.setVerticalScrollMode(QAbstractItemView::ScrollPerItem); //some styles change that in Polish
-
view.resize(300, 200);
+
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
//view.verticalScrollBar()->setValue(0);
- view.scrollTo(model.index(0,0,QModelIndex()));
+ view.scrollTo(model.index(0, 0, QModelIndex()));
CHECK_VISIBLE(0,0);
QCOMPARE(view.verticalScrollBar()->value(), 0);
@@ -2305,22 +2292,23 @@ void tst_QTreeView::rowsAboutToBeRemoved_move()
QTreeView view;
view.setModel(&model);
QModelIndex indexThatWantsToLiveButWillDieDieITellYou;
- QModelIndex parent = model.index(2, 0 );
+ QModelIndex parent = model.index(2, 0);
view.expand(parent);
for (int i = 0; i < 6; ++i) {
model.insertRows(0, 1, parent);
model.insertColumns(0, 1, parent);
QModelIndex index = model.index(0, 0, parent);
view.expand(index);
- if ( i == 3 )
+ if (i == 3)
indexThatWantsToLiveButWillDieDieITellYou = index;
model.setData(index, i);
parent = index;
}
view.resize(600,800);
view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
view.doItemsLayout();
- static_cast<QTreeView *>(&view)->executeDelayedItemsLayout();
+ view.executeDelayedItemsLayout();
parent = indexThatWantsToLiveButWillDieDieITellYou.parent();
QCOMPARE(view.isExpanded(indexThatWantsToLiveButWillDieDieITellYou), true);
QCOMPARE(parent.isValid(), true);
@@ -2354,7 +2342,8 @@ void tst_QTreeView::resizeColumnToContents()
QTreeView view;
view.setModel(&model);
view.show();
- qApp->processEvents(); //must have this, or else it will not scroll
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
view.scrollToBottom();
view.resizeColumnToContents(0);
int oldColumnSize = view.header()->sectionSize(0);
@@ -2365,11 +2354,12 @@ void tst_QTreeView::resizeColumnToContents()
void tst_QTreeView::insertAfterSelect()
{
- QtTestModel model;
- model.rows = model.cols = 10;
+ QtTestModel model(10, 10);
QTreeView view;
view.setModel(&model);
view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
QModelIndex firstIndex = model.index(0, 0, QModelIndex());
QVERIFY(firstIndex.isValid());
int itemOffset = view.visualRect(firstIndex).width() / 2;
@@ -2382,11 +2372,12 @@ void tst_QTreeView::insertAfterSelect()
void tst_QTreeView::removeAfterSelect()
{
- QtTestModel model;
- model.rows = model.cols = 10;
+ QtTestModel model(10, 10);
QTreeView view;
view.setModel(&model);
view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
QModelIndex firstIndex = model.index(0, 0, QModelIndex());
QVERIFY(firstIndex.isValid());
int itemOffset = view.visualRect(firstIndex).width() / 2;
@@ -2399,17 +2390,17 @@ void tst_QTreeView::removeAfterSelect()
void tst_QTreeView::hiddenItems()
{
- QtTestModel model;
- model.rows = model.cols = 10;
+ QtTestModel model(10, 10);
QTreeView view;
view.setModel(&model);
view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
QModelIndex firstIndex = model.index(1, 0, QModelIndex());
QVERIFY(firstIndex.isValid());
if (model.canFetchMore(firstIndex))
model.fetchMore(firstIndex);
- for (int i=0; i < model.rowCount(firstIndex); i++)
+ for (int i = 0; i < model.rowCount(firstIndex); i++)
view.setRowHidden(i , firstIndex, true );
int itemOffset = view.visualRect(firstIndex).width() / 2;
@@ -2419,18 +2410,18 @@ void tst_QTreeView::hiddenItems()
QTest::mouseDClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p);
QCOMPARE(view.isExpanded(firstIndex), false);
- p.setX( 5 );
+ p.setX(5);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p);
QCOMPARE(view.isExpanded(firstIndex), false);
}
void tst_QTreeView::spanningItems()
{
- QtTestModel model;
- model.rows = model.cols = 10;
+ QtTestModel model(10, 10);
QTreeView view;
view.setModel(&model);
view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
int itemWidth = view.header()->sectionSize(0);
int itemHeight = view.visualRect(model.index(0, 0, QModelIndex())).height();
@@ -2470,7 +2461,7 @@ void tst_QTreeView::spanningItems()
void tst_QTreeView::selectionOrderTest()
{
- QVERIFY(((QItemSelectionModel*)sender())->currentIndex().row() != -1);
+ QVERIFY(static_cast<QItemSelectionModel*>(sender())->currentIndex().row() != -1);
}
void tst_QTreeView::selection()
@@ -2489,12 +2480,11 @@ void tst_QTreeView::selection()
treeView.setSelectionBehavior(QAbstractItemView::SelectRows);
treeView.setSelectionMode(QAbstractItemView::ExtendedSelection);
- connect(treeView.selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
- this, SLOT(selectionOrderTest()));
-
- treeView.show();
+ connect(treeView.selectionModel(), &QItemSelectionModel::selectionChanged,
+ this, &tst_QTreeView::selectionOrderTest);
- QTest::mousePress(treeView.viewport(), Qt::LeftButton, 0, treeView.visualRect(m.index(1, 0)).center());
+ QTest::mousePress(treeView.viewport(), Qt::LeftButton, {},
+ treeView.visualRect(m.index(1, 0)).center());
QTest::keyPress(treeView.viewport(), Qt::Key_Down);
auto selectedRows = treeView.selectionModel()->selectedRows();
QCOMPARE(selectedRows.size(), 1);
@@ -2509,23 +2499,21 @@ void tst_QTreeView::selection()
void tst_QTreeView::selectionWithHiddenItems()
{
QStandardItemModel model;
- for (int i = 0; i < model.rowCount(); ++i)
- model.setData(model.index(i,0), QLatin1String("row ") + QString::number(i));
QStandardItem item0("row 0");
QStandardItem item1("row 1");
QStandardItem item2("row 2");
QStandardItem item3("row 3");
- model.appendColumn( QList<QStandardItem*>() << &item0 << &item1 << &item2 << &item3);
+ model.appendColumn({&item0, &item1, &item2, &item3});
QStandardItem child("child");
- item1.appendRow( &child);
+ item1.appendRow(&child);
QTreeView view;
view.setModel(&model);
view.setSelectionMode(QAbstractItemView::ExtendedSelection);
view.show();
- qApp->processEvents();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
//child should not be selected as it is hidden (its parent is not expanded)
view.selectAll();
@@ -2548,12 +2536,11 @@ void tst_QTreeView::selectionWithHiddenItems()
//we hide the node with a child (there should then be 3 items selected in 2 ranges)
view.setRowHidden(1, QModelIndex(), true);
QVERIFY(view.isExpanded(item1.index()));
- qApp->processEvents();
view.selectAll();
QCOMPARE(view.selectionModel()->selection().count(), 2);
QCOMPARE(view.selectionModel()->selectedRows().count(), 3);
- QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&item1)));
- QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&child)));
+ QVERIFY(!view.selectionModel()->isSelected(model.indexFromItem(&item1)));
+ QVERIFY(!view.selectionModel()->isSelected(model.indexFromItem(&child)));
view.setRowHidden(1, QModelIndex(), false);
QVERIFY(view.isExpanded(item1.index()));
@@ -2561,7 +2548,6 @@ void tst_QTreeView::selectionWithHiddenItems()
//we hide a node without children (there should then be 4 items selected in 3 ranges)
view.setRowHidden(2, QModelIndex(), true);
- qApp->processEvents();
QVERIFY(view.isExpanded(item1.index()));
view.selectAll();
QVERIFY(view.isExpanded(item1.index()));
@@ -2575,7 +2561,7 @@ void tst_QTreeView::selectionWithHiddenItems()
void tst_QTreeView::selectAll()
{
- QStandardItemModel model(4,4);
+ QStandardItemModel model(4, 4);
QTreeView view2;
view2.setModel(&model);
view2.setSelectionMode(QAbstractItemView::ExtendedSelection);
@@ -2619,7 +2605,8 @@ void tst_QTreeView::extendedSelection()
view.setModel(&model);
view.setSelectionMode(QAbstractItemView::ExtendedSelection);
topLevel.show();
- QTest::mousePress(view.viewport(), Qt::LeftButton, 0, mousePressPos);
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, mousePressPos);
QCOMPARE(view.selectionModel()->selectedIndexes().count(), selectedCount);
}
@@ -2627,21 +2614,22 @@ void tst_QTreeView::rowSizeHint()
{
//tests whether the correct visible columns are taken into account when
//calculating the height of a line
- QStandardItemModel model(1,3);
- model.setData( model.index(0,0), QSize(20,40), Qt::SizeHintRole);
- model.setData( model.index(0,1), QSize(20,10), Qt::SizeHintRole);
- model.setData( model.index(0,2), QSize(20,10), Qt::SizeHintRole);
+ QStandardItemModel model(1, 3);
+ model.setData(model.index(0, 0), QSize(20, 40), Qt::SizeHintRole);
+ model.setData(model.index(0, 1), QSize(20, 10), Qt::SizeHintRole);
+ model.setData(model.index(0, 2), QSize(20, 10), Qt::SizeHintRole);
QTreeView view;
view.setModel(&model);
view.header()->moveSection(1, 0); //the 2nd column goes to the 1st place
view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
//it must be 40 since the tallest item that defines the height of a line
- QCOMPARE( view.visualRect(model.index(0,0)).height(), 40);
- QCOMPARE( view.visualRect(model.index(0,1)).height(), 40);
- QCOMPARE( view.visualRect(model.index(0,2)).height(), 40);
+ QCOMPARE(view.visualRect(model.index(0,0)).height(), 40);
+ QCOMPARE(view.visualRect(model.index(0,1)).height(), 40);
+ QCOMPARE(view.visualRect(model.index(0,2)).height(), 40);
}
@@ -2651,7 +2639,7 @@ void tst_QTreeView::rowSizeHint()
void tst_QTreeView::setSortingEnabledTopLevel()
{
QTreeView view;
- QStandardItemModel model(1,1);
+ QStandardItemModel model(1, 1);
view.setModel(&model);
const int size = view.header()->sectionSize(0);
view.setSortingEnabled(true);
@@ -2665,7 +2653,7 @@ void tst_QTreeView::setSortingEnabledChild()
QMainWindow win;
QTreeView view;
// two columns to not get in trouble with stretchLastSection
- QStandardItemModel model(1,2);
+ QStandardItemModel model(1, 2);
view.setModel(&model);
view.header()->setDefaultSectionSize(92);
win.setCentralWidget(&view);
@@ -2690,16 +2678,18 @@ void tst_QTreeView::headerHidden()
class TestTreeViewStyle : public QProxyStyle
{
+ Q_OBJECT
public:
- TestTreeViewStyle() : indentation(20) {}
- int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const override
+ using QProxyStyle::QProxyStyle;
+ int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
+ const QWidget *widget = nullptr) const override
{
if (metric == QStyle::PM_TreeViewIndentation)
return indentation;
else
return QProxyStyle::pixelMetric(metric, option, widget);
}
- int indentation;
+ int indentation = 20;
};
void tst_QTreeView::indentation()
@@ -2745,7 +2735,7 @@ void tst_QTreeView::removeAndInsertExpandedCol0()
model.insertColumns(0, 1);
view.show();
- qApp->processEvents();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
}
void tst_QTreeView::disabledButCheckable()
@@ -2782,7 +2772,7 @@ void tst_QTreeView::sortByColumn()
{
QFETCH(bool, sortingEnabled);
QTreeView view;
- QStandardItemModel model(4,2);
+ QStandardItemModel model(4, 2);
QSortFilterProxyModel sfpm; // default QStandardItemModel does not support 'unsorted' state
sfpm.setSourceModel(&model);
model.setItem(0, 0, new QStandardItem("b"));
@@ -2825,11 +2815,13 @@ void tst_QTreeView::sortByColumn()
*/
class EvilModel: public QAbstractItemModel
{
-
+ Q_OBJECT
public:
- class Node {
+ class Node
+ {
public:
- Node(Node *p = 0, int level = 0) : parent(p), isDead(false) {
+ Node(Node *p = nullptr, int level = 0) : parent(p)
+ {
populate(level);
}
~Node()
@@ -2838,20 +2830,23 @@ public:
qDeleteAll(deadChildren.begin(), deadChildren.end());
}
- void populate(int level = 0) {
- if (level < 4)
+ void populate(int level = 0)
+ {
+ if (level < 4) {
for (int i = 0; i < 5; ++i)
children.append(new Node(this, level + 1));
+ }
}
- void kill() {
+ void kill()
+ {
for (int i = children.count() -1; i >= 0; --i) {
children.at(i)->kill();
- if (parent == 0) {
+ if (parent == nullptr) {
deadChildren.append(children.at(i));
children.removeAt(i);
}
}
- if (parent == 0) {
+ if (parent == nullptr) {
if (!children.isEmpty())
qFatal("%s: children should be empty when parent is null", Q_FUNC_INFO);
populate();
@@ -2860,17 +2855,16 @@ public:
}
}
- QList<Node*> children;
- QList<Node*> deadChildren;
+ QVector<Node *> children;
+ QVector<Node *> deadChildren;
Node *parent;
- bool isDead;
+ bool isDead = false;
};
Node *root;
- EvilModel(QObject *parent = 0): QAbstractItemModel(parent), root(new Node)
- {
- }
+ EvilModel(QObject *parent = nullptr): QAbstractItemModel(parent), root(new Node)
+ {}
~EvilModel()
{
delete root;
@@ -2880,7 +2874,7 @@ public:
{
emit layoutAboutToBeChanged();
QModelIndexList oldList = persistentIndexList();
- QList<QStack<int> > oldListPath;
+ QVector<QStack<int>> oldListPath;
for (int i = 0; i < oldList.count(); ++i) {
QModelIndex idx = oldList.at(i);
QStack<int> path;
@@ -2893,12 +2887,10 @@ public:
root->kill();
QModelIndexList newList;
- for (int i = 0; i < oldListPath.count(); ++i) {
- QStack<int> path = oldListPath[i];
+ for (auto path : qAsConst(oldListPath)) {
QModelIndex idx;
- while(!path.isEmpty()) {
+ while (!path.isEmpty())
idx = index(path.pop(), 0, idx);
- }
newList.append(idx);
}
@@ -2906,7 +2898,8 @@ public:
emit layoutChanged();
}
- int rowCount(const QModelIndex& parent = QModelIndex()) const {
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override
+ {
Node *parentNode = root;
if (parent.isValid()) {
parentNode = static_cast<Node*>(parent.internalPointer());
@@ -2915,13 +2908,12 @@ public:
}
return parentNode->children.count();
}
- int columnCount(const QModelIndex& parent = QModelIndex()) const {
- if (parent.column() > 0)
- return 0;
- return 1;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const override
+ {
+ return parent.column() > 0 ? 0 : 1;
}
- QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
{
Node *grandparentNode = static_cast<Node*>(parent.internalPointer());
Node *parentNode = root;
@@ -2935,7 +2927,7 @@ public:
return createIndex(row, column, parentNode);
}
- QModelIndex parent(const QModelIndex &index) const
+ QModelIndex parent(const QModelIndex &index) const override
{
Node *parent = static_cast<Node*>(index.internalPointer());
Node *grandparent = parent->parent;
@@ -2944,7 +2936,7 @@ public:
return createIndex(grandparent->children.indexOf(parent), 0, grandparent);
}
- QVariant data(const QModelIndex &idx, int role) const
+ QVariant data(const QModelIndex &idx, int role) const override
{
if (idx.isValid() && role == Qt::DisplayRole) {
Node *parentNode = root;
@@ -2987,7 +2979,6 @@ void tst_QTreeView::evilModel()
view.setRowHidden(0, firstLevel, true);
model.change();
- return;
view.setFirstColumnSpanned(1, QModelIndex(), true);
model.change();
@@ -3167,7 +3158,7 @@ void tst_QTreeView::filterProxyModelCrash()
QTreeView view;
view.setModel(&proxy);
view.show();
- QTest::qWait(30);
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
proxy.invalidate();
view.verticalScrollBar()->setValue(15);
QTest::qWait(20);
@@ -3190,7 +3181,7 @@ void tst_QTreeView::renderToPixmap()
QStandardItemModel model;
model.appendRow(new QStandardItem("Spanning"));
- model.appendRow(QList<QStandardItem*>() << new QStandardItem("Not") << new QStandardItem("Spanning"));
+ model.appendRow({ new QStandardItem("Not"), new QStandardItem("Spanning") });
view.setModel(&model);
view.setFirstColumnSpanned(0, QModelIndex(), true);
@@ -3211,57 +3202,60 @@ void tst_QTreeView::styleOptionViewItem()
{
class MyDelegate : public QStyledItemDelegate
{
- static QString posToString(QStyleOptionViewItem::ViewItemPosition pos) {
+ static QString posToString(QStyleOptionViewItem::ViewItemPosition pos)
+ {
static const char* s_pos[] = { "Invalid", "Beginning", "Middle", "End", "OnlyOne" };
return s_pos[pos];
}
public:
- MyDelegate()
- : QStyledItemDelegate(),
- count(0),
- allCollapsed(false)
- {}
-
- void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
- {
- QStyleOptionViewItem opt(option);
- initStyleOption(&opt, index);
+ using QStyledItemDelegate::QStyledItemDelegate;
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override
+ {
+ QStyleOptionViewItem opt(option);
+ initStyleOption(&opt, index);
- QVERIFY(!opt.text.isEmpty());
- QCOMPARE(opt.index, index);
- //qDebug() << index << opt.text;
+ QVERIFY(!opt.text.isEmpty());
+ QCOMPARE(opt.index, index);
+ //qDebug() << index << opt.text;
- if (allCollapsed)
- QCOMPARE(!(opt.features & QStyleOptionViewItem::Alternate), !(index.row() % 2));
- QCOMPARE(!(opt.features & QStyleOptionViewItem::HasCheckIndicator), !opt.text.contains("Checkable"));
+ if (allCollapsed) {
+ QCOMPARE(!opt.features.testFlag(QStyleOptionViewItem::Alternate),
+ !(index.row() % 2));
+ }
+ QCOMPARE(!opt.features.testFlag(QStyleOptionViewItem::HasCheckIndicator),
+ !opt.text.contains("Checkable"));
- if (opt.text.contains("Beginning"))
- QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItem::Beginning));
+ const QString posStr(posToString(opt.viewItemPosition));
+ if (opt.text.contains("Beginning"))
+ QCOMPARE(posStr, posToString(QStyleOptionViewItem::Beginning));
- if (opt.text.contains("Middle"))
- QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItem::Middle));
+ if (opt.text.contains("Middle"))
+ QCOMPARE(posStr, posToString(QStyleOptionViewItem::Middle));
- if (opt.text.contains("End"))
- QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItem::End));
+ if (opt.text.contains("End"))
+ QCOMPARE(posStr, posToString(QStyleOptionViewItem::End));
- if (opt.text.contains("OnlyOne"))
- QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItem::OnlyOne));
+ if (opt.text.contains("OnlyOne"))
+ QCOMPARE(posStr, posToString(QStyleOptionViewItem::OnlyOne));
- if (opt.text.contains("Checked"))
- QCOMPARE(opt.checkState, Qt::Checked);
- else
- QCOMPARE(opt.checkState, Qt::Unchecked);
+ if (opt.text.contains("Checked"))
+ QCOMPARE(opt.checkState, Qt::Checked);
+ else
+ QCOMPARE(opt.checkState, Qt::Unchecked);
- QCOMPARE(!(opt.state & QStyle::State_Children) , !opt.text.contains("HasChildren"));
- QCOMPARE(!!(opt.state & QStyle::State_Sibling) , !opt.text.contains("Last"));
+ QCOMPARE(!opt.state.testFlag(QStyle::State_Children),
+ !opt.text.contains("HasChildren"));
+ QCOMPARE(opt.state.testFlag(QStyle::State_Sibling),
+ !opt.text.contains("Last"));
- QVERIFY(!opt.text.contains("Assert"));
+ QVERIFY(!opt.text.contains("Assert"));
- QStyledItemDelegate::paint(painter, option, index);
- count++;
- }
- mutable int count;
- bool allCollapsed;
+ QStyledItemDelegate::paint(painter, option, index);
+ count++;
+ }
+ mutable int count = 0;
+ bool allCollapsed = false;
};
QTreeView view;
@@ -3269,39 +3263,68 @@ void tst_QTreeView::styleOptionViewItem()
view.setModel(&model);
MyDelegate delegate;
view.setItemDelegate(&delegate);
- model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning") << new QStandardItem("Hidden") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ model.appendRow({ new QStandardItem("Beginning"),
+ new QStandardItem("Hidden"),
+ new QStandardItem("Middle"),
+ new QStandardItem("Middle"),
+ new QStandardItem("End") });
QStandardItem *par1 = new QStandardItem("Beginning HasChildren");
- model.appendRow(QList<QStandardItem*>()
- << par1 << new QStandardItem("Hidden") << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") );
- model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("OnlyOne") << new QStandardItem("Hidden") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") );
+ model.appendRow({ par1,
+ new QStandardItem("Hidden"),
+ new QStandardItem("Middle HasChildren"),
+ new QStandardItem("Middle HasChildren"),
+ new QStandardItem("End HasChildren") });
+ model.appendRow({ new QStandardItem("OnlyOne"),
+ new QStandardItem("Hidden"),
+ new QStandardItem("Assert"),
+ new QStandardItem("Assert"),
+ new QStandardItem("Assert") });
QStandardItem *checkable = new QStandardItem("Checkable");
checkable->setCheckable(true);
QStandardItem *checked = new QStandardItem("Checkable Checked");
checked->setCheckable(true);
checked->setCheckState(Qt::Checked);
- model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning") << new QStandardItem("Hidden") << checkable << checked << new QStandardItem("End") );
- model.appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning Last") << new QStandardItem("Hidden") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
-
- par1->appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning") << new QStandardItem("Hidden") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") );
+ model.appendRow({ new QStandardItem("Beginning"),
+ new QStandardItem("Hidden"),
+ checkable, checked,
+ new QStandardItem("End") });
+ model.appendRow({ new QStandardItem("Beginning Last"),
+ new QStandardItem("Hidden"),
+ new QStandardItem("Middle Last"),
+ new QStandardItem("Middle Last"),
+ new QStandardItem("End Last") });
+ par1->appendRow({ new QStandardItem("Beginning"),
+ new QStandardItem("Hidden"),
+ new QStandardItem("Middle"),
+ new QStandardItem("Middle"),
+ new QStandardItem("End") });
QStandardItem *par2 = new QStandardItem("Beginning HasChildren");
- par1->appendRow(QList<QStandardItem*>()
- << par2 << new QStandardItem("Hidden") << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") );
- par2->appendRow(QList<QStandardItem*>()
- << new QStandardItem("Beginning Last") << new QStandardItem("Hidden") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
-
+ par1->appendRow({ par2,
+ new QStandardItem("Hidden"),
+ new QStandardItem("Middle HasChildren"),
+ new QStandardItem("Middle HasChildren"),
+ new QStandardItem("End HasChildren") });
+ par2->appendRow({ new QStandardItem("Beginning Last"),
+ new QStandardItem("Hidden"),
+ new QStandardItem("Middle Last"),
+ new QStandardItem("Middle Last"),
+ new QStandardItem("End Last") });
QStandardItem *par3 = new QStandardItem("Beginning Last");
- par1->appendRow(QList<QStandardItem*>()
- << par3 << new QStandardItem("Hidden") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") );
- par3->appendRow(QList<QStandardItem*>()
- << new QStandardItem("Assert") << new QStandardItem("Hidden") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") );
+ par1->appendRow({ par3, new QStandardItem("Hidden"),
+ new QStandardItem("Middle Last"),
+ new QStandardItem("Middle Last"),
+ new QStandardItem("End Last") });
+ par3->appendRow({ new QStandardItem("Assert"),
+ new QStandardItem("Hidden"),
+ new QStandardItem("Assert"),
+ new QStandardItem("Assert"),
+ new QStandardItem("Asser") });
view.setRowHidden(0, par3->index(), true);
- par1->appendRow(QList<QStandardItem*>()
- << new QStandardItem("Assert") << new QStandardItem("Hidden") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") );
+ par1->appendRow({ new QStandardItem("Assert"),
+ new QStandardItem("Hidden"),
+ new QStandardItem("Assert"),
+ new QStandardItem("Assert"),
+ new QStandardItem("Asser") });
view.setRowHidden(3, par1->index(), true);
view.setColumnHidden(1, true);
@@ -3331,16 +3354,14 @@ void tst_QTreeView::styleOptionViewItem()
delegate.count = 0;
delegate.allCollapsed = true;
view.showMaximized();
- QApplication::processEvents();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
QTRY_VERIFY(delegate.count >= 13);
delegate.count = 0;
delegate.allCollapsed = false;
view.expandAll();
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 13);
delegate.count = 0;
view.collapse(par2->index());
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 4);
// test that the rendering of drag pixmap sets the correct options too (QTBUG-15834)
@@ -3360,96 +3381,73 @@ void tst_QTreeView::styleOptionViewItem()
delegate.count = 0;
QStandardItemModel model2;
QStandardItem *item0 = new QStandardItem("OnlyOne Last");
- model2.appendRow(QList<QStandardItem*>() << item0);
+ model2.appendRow(item0);
view.setModel(&model2);
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 1);
- QApplication::processEvents();
QStandardItem *item00 = new QStandardItem("OnlyOne Last");
- item0->appendRow(QList<QStandardItem*>() << item00);
+ item0->appendRow(item00);
item0->setText("OnlyOne Last HasChildren");
- QApplication::processEvents();
delegate.count = 0;
view.expandAll();
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 2);
- QApplication::processEvents();
QStandardItem *item1 = new QStandardItem("OnlyOne Last");
delegate.count = 0;
item0->setText("OnlyOne HasChildren");
- model2.appendRow(QList<QStandardItem*>() << item1);
- QApplication::processEvents();
+ model2.appendRow(item1);
QTRY_VERIFY(delegate.count >= 3);
- QApplication::processEvents();
QStandardItem *item01 = new QStandardItem("OnlyOne Last");
delegate.count = 0;
item00->setText("OnlyOne");
- item0->appendRow(QList<QStandardItem*>() << item01);
- QApplication::processEvents();
+ item0->appendRow(item01);
QTRY_VERIFY(delegate.count >= 4);
- QApplication::processEvents();
QStandardItem *item000 = new QStandardItem("OnlyOne Last");
delegate.count = 0;
item00->setText("OnlyOne HasChildren");
- item00->appendRow(QList<QStandardItem*>() << item000);
- QApplication::processEvents();
+ item00->appendRow(item000);
QTRY_VERIFY(delegate.count >= 5);
- QApplication::processEvents();
delegate.count = 0;
item0->removeRow(0);
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 3);
- QApplication::processEvents();
item00 = new QStandardItem("OnlyOne");
- item0->insertRow(0, QList<QStandardItem*>() << item00);
- QApplication::processEvents();
+ item0->insertRow(0, item00);
+
delegate.count = 0;
view.expandAll();
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 4);
- QApplication::processEvents();
delegate.count = 0;
item0->removeRow(1);
item00->setText("OnlyOne Last");
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 3);
- QApplication::processEvents();
delegate.count = 0;
item0->removeRow(0);
item0->setText("OnlyOne");
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 2);
- QApplication::processEvents();
//with hidden items
item0->setText("OnlyOne HasChildren");
item00 = new QStandardItem("OnlyOne");
- item0->appendRow(QList<QStandardItem*>() << item00);
+ item0->appendRow(item00);
item01 = new QStandardItem("Assert");
- item0->appendRow(QList<QStandardItem*>() << item01);
+ item0->appendRow(item01);
view.setRowHidden(1, item0->index(), true);
view.expandAll();
QStandardItem *item02 = new QStandardItem("OnlyOne Last");
- item0->appendRow(QList<QStandardItem*>() << item02);
+ item0->appendRow(item02);
delegate.count = 0;
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 4);
- QApplication::processEvents();
item0->removeRow(2);
item00->setText("OnlyOne Last");
delegate.count = 0;
- QApplication::processEvents();
QTRY_VERIFY(delegate.count >= 3);
- QApplication::processEvents();
item00->setText("OnlyOne");
item0->insertRow(2, new QStandardItem("OnlyOne Last"));
@@ -3457,13 +3455,11 @@ void tst_QTreeView::styleOptionViewItem()
item0->removeRow(0);
delegate.count = 0;
QTRY_VERIFY(delegate.count >= 2);
- QApplication::processEvents();
item0->removeRow(1);
item0->setText("OnlyOne");
delegate.count = 0;
QTRY_VERIFY(delegate.count >= 2);
- QApplication::processEvents();
}
}
@@ -3471,10 +3467,10 @@ class task174627_TreeView : public QTreeView
{
Q_OBJECT
protected slots:
- void currentChanged(const QModelIndex &current, const QModelIndex &)
- { emit currentChanged(current); }
+ void currentChanged(const QModelIndex &current, const QModelIndex &) override
+ { emit signalCurrentChanged(current); }
signals:
- void currentChanged(const QModelIndex &);
+ void signalCurrentChanged(const QModelIndex &);
};
void tst_QTreeView::task174627_moveLeftToRoot()
@@ -3490,7 +3486,7 @@ void tst_QTreeView::task174627_moveLeftToRoot()
view.setRootIndex(item1->index());
view.setCurrentIndex(item2->index());
- QSignalSpy spy(&view, SIGNAL(currentChanged(QModelIndex)));
+ QSignalSpy spy(&view, &task174627_TreeView::signalCurrentChanged);
QTest::keyClick(&view, Qt::Key_Left);
QCOMPARE(spy.count(), 0);
}
@@ -3503,9 +3499,9 @@ void tst_QTreeView::task171902_expandWith1stColHidden()
subitem("subitem"), subitem2("subitem"),
subsubitem("subsubitem"), subsubitem2("subsubitem");
- model.appendRow( QList<QStandardItem *>() << &root << &root2);
- root.appendRow( QList<QStandardItem *>() << &subitem << &subitem2);
- subitem.appendRow( QList<QStandardItem *>() << &subsubitem << &subsubitem2);
+ model.appendRow({ &root, &root2 });
+ root.appendRow({ &subitem, &subitem2 });
+ subitem.appendRow({ &subsubitem, &subsubitem2 });
QTreeView view;
view.setModel(&model);
@@ -3523,18 +3519,18 @@ void tst_QTreeView::task171902_expandWith1stColHidden()
void tst_QTreeView::task203696_hidingColumnsAndRowsn()
{
QTreeView view;
- QStandardItemModel *model = new QStandardItemModel(0, 3, &view);
+ QStandardItemModel model(0, 3);
for (int i = 0; i < 3; ++i) {
const QString prefix = QLatin1String("row ") + QString::number(i) + QLatin1String(" col ");
- model->insertRow(model->rowCount());
- for (int j = 0; j < model->columnCount(); ++j)
- model->setData(model->index(i, j), prefix + QString::number(j));
+ model.insertRow(model.rowCount());
+ for (int j = 0; j < model.columnCount(); ++j)
+ model.setData(model.index(i, j), prefix + QString::number(j));
}
- view.setModel(model);
+ view.setModel(&model);
view.show();
view.setColumnHidden(0, true);
view.setRowHidden(0, QModelIndex(), true);
- QCOMPARE(view.indexAt(QPoint(0, 0)), model->index(1, 1));
+ QCOMPARE(view.indexAt(QPoint(0, 0)), model.index(1, 1));
}
@@ -3547,27 +3543,23 @@ void tst_QTreeView::addRowsWhileSectionsAreHidden()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- int i;
- for (i = 0; i < 3; ++i)
+ for (int i = 0; i < 3; ++i)
{
model->insertRow(model->rowCount());
const QString prefix = QLatin1String("row ") + QString::number(i) + QLatin1String(" col ");
- for (int j = 0; j < model->columnCount(); ++j) {
+ for (int j = 0; j < model->columnCount(); ++j)
model->setData(model->index(i, j), prefix + QString::number(j));
- }
}
- int col;
- for (col = 0; col < pass; ++col)
+ for (int col = 0; col < pass; ++col)
view.setColumnHidden(col, true);
- for (i = 3; i < 6; ++i)
+ for (int i = 3; i < 6; ++i)
{
model->insertRow(model->rowCount());
const QString prefix = QLatin1String("row ") + QString::number(i) + QLatin1String(" col ");
- for (int j = 0; j < model->columnCount(); ++j) {
+ for (int j = 0; j < model->columnCount(); ++j)
model->setData(model->index(i, j), prefix + QString::number(j));
- }
}
- for (col = 0; col < pass; ++col)
+ for (int col = 0; col < pass; ++col)
view.setColumnHidden(col, false);
auto allVisualRectsValid = [](QTreeView *view, QStandardItemModel *model) {
@@ -3585,24 +3577,25 @@ void tst_QTreeView::addRowsWhileSectionsAreHidden()
void tst_QTreeView::task216717_updateChildren()
{
- class Tree : public QTreeWidget {
+ class Tree : public QTreeWidget
+ {
protected:
- void paintEvent(QPaintEvent *e)
+ void paintEvent(QPaintEvent *e) override
{
QTreeWidget::paintEvent(e);
- refreshed=true;
+ refreshed = true;
}
public:
- bool refreshed;
+ bool refreshed = false;
} tree;
tree.show();
QVERIFY(QTest::qWaitForWindowExposed(&tree));
tree.refreshed = false;
- QTreeWidgetItem *parent = new QTreeWidgetItem(QStringList() << "parent");
+ QTreeWidgetItem *parent = new QTreeWidgetItem({ "parent" });
tree.addTopLevelItem(parent);
QTRY_VERIFY(tree.refreshed);
tree.refreshed = false;
- parent->addChild(new QTreeWidgetItem(QStringList() << "child"));
+ parent->addChild(new QTreeWidgetItem({ "child" }));
QTRY_VERIFY(tree.refreshed);
}
@@ -3611,13 +3604,14 @@ void tst_QTreeView::task220298_selectColumns()
{
//this is a very simple 3x3 model where the internalId of the index are different for each cell
class Model : public QAbstractTableModel
- { public:
- virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const
+ {
+ public:
+ int columnCount(const QModelIndex & parent = QModelIndex()) const override
{ return parent.isValid() ? 0 : 3; }
- virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const
+ int rowCount(const QModelIndex & parent = QModelIndex()) const override
{ return parent.isValid() ? 0 : 3; }
- virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const
+ QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override
{
if (role == Qt::DisplayRole) {
return QVariant(QString::number(index.column()) + QLatin1Char('-')
@@ -3626,18 +3620,21 @@ void tst_QTreeView::task220298_selectColumns()
return QVariant();
}
- virtual QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const
+ QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override
{
- return hasIndex(row, column, parent) ? createIndex(row, column, column*10+row) : QModelIndex();
+ return hasIndex(row, column, parent) ? createIndex(row, column, quintptr(column * 10 + row)) : QModelIndex();
}
};
- class TreeView : public QTreeView { public: QModelIndexList selectedIndexes () const { return QTreeView::selectedIndexes(); } } view;
+ class TreeView : public QTreeView {
+ public:
+ using QTreeView::selectedIndexes;
+ } view;
Model model;
view.setModel(&model);
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0,
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
view.visualRect(view.model()->index(1, 1)).center());
QTRY_VERIFY(view.selectedIndexes().contains(view.model()->index(1, 2)));
QVERIFY(view.selectedIndexes().contains(view.model()->index(1, 1)));
@@ -3653,8 +3650,8 @@ void tst_QTreeView::task224091_appendColumns()
QTreeView *treeView = new QTreeView(topLevel);
treeView->setModel(model);
topLevel->show();
- treeView->resize(50,50);
- qApp->setActiveWindow(topLevel);
+ treeView->resize(50, 50);
+ QApplication::setActiveWindow(topLevel);
QVERIFY(QTest::qWaitForWindowActive(topLevel));
QVERIFY(!treeView->verticalScrollBar()->isVisible());
@@ -3705,9 +3702,8 @@ void tst_QTreeView::task211293_removeRootIndex()
view.setCurrentIndex(model.indexFromItem(E11314));
view.setExpanded(model.indexFromItem(E11314), true);
view.show();
- qApp->processEvents();
- model.removeRows(0, 1);
- qApp->processEvents();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QVERIFY(model.removeRows(0, 1));
}
void tst_QTreeView::task225539_deleteModel()
@@ -3716,8 +3712,8 @@ void tst_QTreeView::task225539_deleteModel()
treeView.show();
QStandardItemModel *model = new QStandardItemModel(&treeView);
- QStandardItem* parentItem = model->invisibleRootItem();
- QStandardItem* item = new QStandardItem(QString("item"));
+ QStandardItem *parentItem = model->invisibleRootItem();
+ QStandardItem *item = new QStandardItem(QString("item"));
parentItem->appendRow(item);
treeView.setModel(model);
@@ -3767,7 +3763,7 @@ void tst_QTreeView::task230123_setItemsExpandable()
QTest::keyClick(&tree, Qt::Key_Right);
QVERIFY(root.isExpanded());
- const bool navToChild = tree.style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, &tree);
+ const bool navToChild = tree.style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, nullptr, &tree);
QTest::keyClick(&tree, Qt::Key_Right);
QCOMPARE(tree.currentItem(), navToChild ? &child : &root);
@@ -3784,13 +3780,13 @@ void tst_QTreeView::task230123_setItemsExpandable()
void tst_QTreeView::task202039_closePersistentEditor()
{
- QStandardItemModel model(1,1);
+ QStandardItemModel model(1, 1);
QTreeView view;
view.setModel(&model);
QModelIndex current = model.index(0,0);
- QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center());
- QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center());
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.visualRect(current).center());
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(current).center());
QCOMPARE(view.currentIndex(), current);
QVERIFY(view.indexWidget(current));
@@ -3799,8 +3795,8 @@ void tst_QTreeView::task202039_closePersistentEditor()
//here was the bug: closing the persistent editor would not reset the state
//and it was impossible to go into editinon again
- QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center());
- QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center());
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.visualRect(current).center());
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(current).center());
QCOMPARE(view.currentIndex(), current);
QVERIFY(view.indexWidget(current));
}
@@ -3824,13 +3820,12 @@ void tst_QTreeView::task238873_avoidAutoReopening()
view.expandAll();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(child.index()).center());
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(child.index()).center());
QTRY_COMPARE(view.currentIndex(), child.index());
view.setExpanded(item1.index(), false);
- QTest::qWait(500); //enough to trigger the delayedAutoScroll timer
- QVERIFY(!view.isExpanded(item1.index()));
+ QTRY_VERIFY(!view.isExpanded(item1.index()));
}
void tst_QTreeView::task244304_clickOnDecoration()
@@ -3841,39 +3836,38 @@ void tst_QTreeView::task244304_clickOnDecoration()
QStandardItem item00("row 0");
item0.appendRow(&item00);
QStandardItem item1("row 1");
- model.appendColumn(QList<QStandardItem*>() << &item0 << &item1);
+ model.appendColumn({ &item0, &item1 });
view.setModel(&model);
QVERIFY(!view.currentIndex().isValid());
QRect rect = view.visualRect(item0.index());
//we click on the decoration
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, rect.topLeft()+QPoint(-rect.left()/2,rect.height()/2));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
+ rect.topLeft() + QPoint(-rect.left() / 2, rect.height() / 2));
QVERIFY(!view.currentIndex().isValid());
QVERIFY(view.isExpanded(item0.index()));
rect = view.visualRect(item1.index());
//the item has no decoration, it should get selected
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, rect.topLeft()+QPoint(-rect.left()/2,rect.height()/2));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
+ rect.topLeft() + QPoint(-rect.left() / 2, rect.height() / 2));
QCOMPARE(view.currentIndex(), item1.index());
}
void tst_QTreeView::task246536_scrollbarsNotWorking()
{
- struct MyObject : public QObject
+ class MyObject : public QObject
{
- MyObject() : count(0)
- {
- }
-
- bool eventFilter(QObject*, QEvent *e)
+ public:
+ using QObject::QObject;
+ bool eventFilter(QObject*, QEvent *e) override
{
if (e->type() == QEvent::Paint)
count++;
return false;
}
-
- int count;
+ int count = 0;
};
QTreeView tree;
MyObject o;
@@ -3883,11 +3877,11 @@ void tst_QTreeView::task246536_scrollbarsNotWorking()
tree.show();
QVERIFY(QTest::qWaitForWindowExposed(&tree));
QList<QStandardItem *> items;
- for(int i=0; i<100; ++i){
+ for (int i = 0; i < 100; ++i)
items << new QStandardItem(QLatin1String("item ") + QString::number(i));
- }
+ o.count = 0;
model.invisibleRootItem()->appendColumn(items);
- QTest::qWait(100);
+ QTRY_VERIFY(o.count > 0);
o.count = 0;
tree.verticalScrollBar()->setValue(50);
QTRY_VERIFY(o.count > 0);
@@ -3915,12 +3909,12 @@ void tst_QTreeView::task239271_addRowsWithFirstColumnHidden()
class MyDelegate : public QStyledItemDelegate
{
public:
- void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override
{
paintedIndexes << index;
QStyledItemDelegate::paint(painter, option, index);
}
-
mutable QSet<QModelIndex> paintedIndexes;
};
@@ -3953,15 +3947,15 @@ void tst_QTreeView::task254234_proxySort()
//based on tst_QTreeView::sortByColumn
// it used not to work when setting the source of a proxy after enabling sorting
QTreeView view;
- QStandardItemModel model(4,2);
- model.setItem(0,0,new QStandardItem("b"));
- model.setItem(1,0,new QStandardItem("d"));
- model.setItem(2,0,new QStandardItem("c"));
- model.setItem(3,0,new QStandardItem("a"));
- model.setItem(0,1,new QStandardItem("e"));
- model.setItem(1,1,new QStandardItem("g"));
- model.setItem(2,1,new QStandardItem("h"));
- model.setItem(3,1,new QStandardItem("f"));
+ QStandardItemModel model(4, 2);
+ model.setItem(0, 0, new QStandardItem("b"));
+ model.setItem(1, 0, new QStandardItem("d"));
+ model.setItem(2, 0, new QStandardItem("c"));
+ model.setItem(3, 0, new QStandardItem("a"));
+ model.setItem(0, 1, new QStandardItem("e"));
+ model.setItem(1, 1, new QStandardItem("g"));
+ model.setItem(2, 1, new QStandardItem("h"));
+ model.setItem(3, 1, new QStandardItem("f"));
view.sortByColumn(1, Qt::DescendingOrder);
view.setSortingEnabled(true);
@@ -3971,8 +3965,8 @@ void tst_QTreeView::task254234_proxySort()
view.setModel(&proxy);
proxy.setSourceModel(&model);
QCOMPARE(view.header()->sortIndicatorSection(), 1);
- QCOMPARE(view.model()->data(view.model()->index(0,1)).toString(), QString::fromLatin1("h"));
- QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g"));
+ QCOMPARE(view.model()->data(view.model()->index(0, 1)).toString(), QString::fromLatin1("h"));
+ QCOMPARE(view.model()->data(view.model()->index(1, 1)).toString(), QString::fromLatin1("g"));
}
class TreeView : public QTreeView
@@ -3984,7 +3978,8 @@ public slots:
//let's select the last item
QModelIndex idx = model()->index(0, 0);
selectionModel()->select(QItemSelection(idx, idx), QItemSelectionModel::Select);
- disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(handleSelectionChanged()));
+ disconnect(selectionModel(), &QItemSelectionModel::selectionChanged,
+ this, &TreeView::handleSelectionChanged);
}
};
@@ -3993,12 +3988,14 @@ void tst_QTreeView::task248022_changeSelection()
//we check that changing the selection between the mouse press and the mouse release
//works correctly
TreeView view;
- QStringList list = QStringList() << "1" << "2";
+ const QStringList list({"1", "2"});
QStringListModel model(list);
view.setSelectionMode(QAbstractItemView::ExtendedSelection);
view.setModel(&model);
- view.connect(view.selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(handleSelectionChanged()));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(1)).center());
+ connect(view.selectionModel(), &QItemSelectionModel::selectionChanged,
+ &view, &TreeView::handleSelectionChanged);
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
+ view.visualRect(model.index(1)).center());
QCOMPARE(view.selectionModel()->selectedIndexes().count(), list.count());
}
@@ -4012,8 +4009,9 @@ void tst_QTreeView::task245654_changeModelAndExpandAll()
model->appendRow(top);
view.setModel(model.data());
view.expandAll();
- QApplication::processEvents();
- QVERIFY(view.isExpanded(top->index()));
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QTRY_VERIFY(view.isExpanded(top->index()));
//now let's try to delete the model
//then repopulate and expand again
@@ -4024,9 +4022,7 @@ void tst_QTreeView::task245654_changeModelAndExpandAll()
model->appendRow(top);
view.setModel(model.data());
view.expandAll();
- QApplication::processEvents();
- QVERIFY(view.isExpanded(top->index()));
-
+ QTRY_VERIFY(view.isExpanded(top->index()));
}
void tst_QTreeView::doubleClickedWithSpans()
@@ -4042,10 +4038,10 @@ void tst_QTreeView::doubleClickedWithSpans()
QPoint p(10, 10);
QCOMPARE(view.indexAt(p), model.index(0, 0));
- QSignalSpy spy(&view, SIGNAL(doubleClicked(QModelIndex)));
- QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p);
- QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p);
- QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p);
+ QSignalSpy spy(&view, &QAbstractItemView::doubleClicked);
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, p);
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, p);
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, p);
QCOMPARE(spy.count(), 1);
//let's click on the 2nd column
@@ -4053,10 +4049,10 @@ void tst_QTreeView::doubleClickedWithSpans()
QCOMPARE(view.indexAt(p), model.index(0, 0));
//end the previous edition
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p);
- QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p);
- QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p);
- QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p);
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, p);
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, p);
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, p);
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, p);
QTRY_COMPARE(spy.count(), 2);
}
@@ -4069,7 +4065,8 @@ void tst_QTreeView::taskQTBUG_6450_selectAllWith1stColumnHidden()
const int nrRows = 10;
for (int i = 0; i < nrRows; ++i) {
const QString text = QLatin1String("item: ") + QString::number(i);
- items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(text)));
+ items.append(new QTreeWidgetItem(static_cast<QTreeWidget *>(nullptr),
+ QStringList(text)));
items.last()->setText(1, QString("is an item"));
}
tree.insertTopLevelItems(0, items);
@@ -4086,15 +4083,15 @@ class TreeViewQTBUG_9216 : public QTreeView
{
Q_OBJECT
public:
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *event) override
{
if (doCompare)
QCOMPARE(event->rect(), viewport()->rect());
QTreeView::paintEvent(event);
painted++;
}
- int painted;
- bool doCompare;
+ int painted = 0;
+ bool doCompare = false;
};
void tst_QTreeView::taskQTBUG_9216_setSizeAndUniformRowHeightsWrongRepaint()
@@ -4128,7 +4125,7 @@ void tst_QTreeView::keyboardNavigationWithDisabled()
QStandardItemModel model(90, 0);
for (int i = 0; i < 90; i ++) {
model.setItem(i, new QStandardItem(QString::number(i)));
- model.item(i)->setEnabled(i%6 == 0);
+ model.item(i)->setEnabled(i % 6 == 0);
}
view.setModel(&model);
@@ -4179,6 +4176,7 @@ void tst_QTreeView::keyboardNavigationWithDisabled()
class RemoveColumnOne : public QSortFilterProxyModel
{
+ Q_OBJECT
public:
bool filterAcceptsColumn(int source_column, const QModelIndex &) const override
{
@@ -4200,9 +4198,9 @@ void tst_QTreeView::saveRestoreState()
{
QStandardItemModel model;
for (int i = 0; i < 100; i++) {
- QList<QStandardItem *> items;
- items << new QStandardItem(QLatin1String("item ") + QString::number(i)) << new QStandardItem(QStringLiteral("hidden by proxy")) << new QStandardItem(QStringLiteral("hidden by user"));
- model.appendRow(items);
+ model.appendRow({new QStandardItem(QStringLiteral("item ") + QString::number(i)),
+ new QStandardItem(QStringLiteral("hidden by proxy")),
+ new QStandardItem(QStringLiteral("hidden by user")) });
}
QCOMPARE(model.columnCount(), 3);
@@ -4233,32 +4231,29 @@ class Model_11466 : public QAbstractItemModel
{
Q_OBJECT
public:
- Model_11466(QObject * /* parent */) :
- m_block(false)
+ Model_11466(QObject *parent = nullptr) : QAbstractItemModel(parent)
+ , m_selectionModel(new QItemSelectionModel(this, this))
{
- // set up the model to have two top level items and a few others
- m_selectionModel = new QItemSelectionModel(this, this); // owned by this
-
- connect(m_selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)),
- this, SLOT(slotCurrentChanged(QModelIndex,QModelIndex)));
- };
+ connect(m_selectionModel, &QItemSelectionModel::currentChanged,
+ this, &Model_11466::slotCurrentChanged);
+ }
- int rowCount(const QModelIndex &parent) const
+ int rowCount(const QModelIndex &parent) const override
{
if (parent.isValid())
return (parent.internalId() == 0) ? 4 : 0;
return 2; // two top level items
}
- int columnCount(const QModelIndex & /* parent */) const
+ int columnCount(const QModelIndex & /* parent */) const override
{
return 2;
}
- QVariant data(const QModelIndex &index, int role) const
+ QVariant data(const QModelIndex &index, int role) const override
{
if (role == Qt::DisplayRole && index.isValid()) {
- qint64 parentRowPlusOne = index.internalId();
+ qint64 parentRowPlusOne = qint64(index.internalId());
QString str;
QTextStream stream(&str);
if (parentRowPlusOne > 0)
@@ -4270,10 +4265,10 @@ public:
return QVariant();
}
- QModelIndex parent(const QModelIndex &index) const
+ QModelIndex parent(const QModelIndex &index) const override
{
if (index.isValid()) {
- qint64 parentRowPlusOne = index.internalId();
+ qint64 parentRowPlusOne = qint64(index.internalId());
if (parentRowPlusOne > 0) {
int row = static_cast<int>(parentRowPlusOne - 1);
return createIndex(row, 0);
@@ -4294,9 +4289,9 @@ public:
delete oldModel;
}
- QModelIndex index(int row, int column, const QModelIndex &parent) const
+ QModelIndex index(int row, int column, const QModelIndex &parent) const override
{
- return createIndex(row, column, parent.isValid() ? (quintptr)(parent.row() + 1) : (quintptr)0);
+ return createIndex(row, column, parent.isValid() ? quintptr(parent.row() + 1) : quintptr(0));
}
public slots:
@@ -4333,7 +4328,7 @@ public slots:
}
private:
- bool m_block;
+ bool m_block = false;
QItemSelectionModel *m_selectionModel;
};
@@ -4388,9 +4383,9 @@ void tst_QTreeView::taskQTBUG_25333_adjustViewOptionsForIndex()
QStandardItem *data3 = new QStandardItem("Data3");
// Create a treeview
- model.appendRow(QList<QStandardItem*>() << item1 << data1 );
- model.appendRow(QList<QStandardItem*>() << item2 << data2 );
- model.appendRow(QList<QStandardItem*>() << item3 << data3 );
+ model.appendRow({ item1, data1 });
+ model.appendRow({ item2, data2 });
+ model.appendRow({ item3, data3 });
view.setModel(&model);
@@ -4414,6 +4409,9 @@ void tst_QTreeView::taskQTBUG_25333_adjustViewOptionsForIndex()
void tst_QTreeView::taskQTBUG_18539_emitLayoutChanged()
{
+ qRegisterMetaType<QList<QPersistentModelIndex>>();
+ qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>();
+
QTreeView view;
QStandardItem* item = new QStandardItem("Orig");
@@ -4430,14 +4428,14 @@ void tst_QTreeView::taskQTBUG_18539_emitLayoutChanged()
replacementItem->setChild(0, 0, replacementChild);
- QSignalSpy beforeSpy(&model, SIGNAL(layoutAboutToBeChanged()));
- QSignalSpy afterSpy(&model, SIGNAL(layoutChanged()));
+ QSignalSpy beforeSpy(&model, &QAbstractItemModel::layoutAboutToBeChanged);
+ QSignalSpy afterSpy(&model, &QAbstractItemModel::layoutChanged);
- QSignalSpy beforeRISpy(&model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)));
- QSignalSpy afterRISpy(&model, SIGNAL(rowsInserted(QModelIndex,int,int)));
+ QSignalSpy beforeRISpy(&model, &QAbstractItemModel::rowsAboutToBeInserted);
+ QSignalSpy afterRISpy(&model, &QAbstractItemModel::rowsInserted);
- QSignalSpy beforeRRSpy(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)));
- QSignalSpy afterRRSpy(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)));
+ QSignalSpy beforeRRSpy(&model, &QAbstractItemModel::rowsAboutToBeRemoved);
+ QSignalSpy afterRRSpy(&model, &QAbstractItemModel::rowsRemoved);
model.setItem(0, 0, replacementItem);
@@ -4460,7 +4458,7 @@ void tst_QTreeView::taskQTBUG_8176_emitOnExpandAll()
new QTreeWidgetItem(item2, QStringList(QString("item 4")));
QTreeWidgetItem *item5 = new QTreeWidgetItem(&tw, QStringList(QString("item 5")));
new QTreeWidgetItem(item5, QStringList(QString("item 6")));
- QSignalSpy spy(&tw, SIGNAL(expanded(const QModelIndex&)));
+ QSignalSpy spy(&tw, &QTreeView::expanded);
// expand all
tw.expandAll();
@@ -4473,7 +4471,7 @@ void tst_QTreeView::taskQTBUG_8176_emitOnExpandAll()
QCOMPARE(spy.size(), 5);
// collapse all
- QSignalSpy spy2(&tw, SIGNAL(collapsed(const QModelIndex&)));
+ QSignalSpy spy2(&tw, &QTreeView::collapsed);
tw.collapseAll();
QCOMPARE(spy2.size(), 6);
tw.expandAll();
@@ -4496,14 +4494,13 @@ void tst_QTreeView::testInitialFocus()
{
QTreeWidget treeWidget;
treeWidget.setColumnCount(5);
- new QTreeWidgetItem(&treeWidget, QStringList(QString("1;2;3;4;5").split(QLatin1Char(';'))));
+ new QTreeWidgetItem(&treeWidget, QString("1;2;3;4;5").split(QLatin1Char(';')));
treeWidget.setTreePosition(2);
treeWidget.header()->hideSection(0); // make sure we skip hidden section(s)
treeWidget.header()->swapSections(1, 2); // make sure that we look for first visual index (and not first logical)
treeWidget.show();
QVERIFY(QTest::qWaitForWindowExposed(&treeWidget));
- QApplication::processEvents();
- QCOMPARE(treeWidget.currentIndex().column(), 2);
+ QTRY_COMPARE(treeWidget.currentIndex().column(), 2);
}
#if QT_CONFIG(animation)
@@ -4534,9 +4531,8 @@ void tst_QTreeView::quickExpandCollapse()
tree.collapse(rootIndex);
QCOMPARE(tree.state(), QTreeView::AnimatingState);
- QTest::qWait(500); //the animation lasts for 250ms max so 500 should be enough
-
- QCOMPARE(tree.state(), initialState);
+ //the animation lasts for 250ms max so 5000 (default) should be enough
+ QTRY_COMPARE(tree.state(), initialState);
}
#endif // animation
@@ -4576,7 +4572,7 @@ class Qtbug45697TestWidget : public QWidget
public:
static const int columnCount = 3;
- explicit Qtbug45697TestWidget();
+ explicit Qtbug45697TestWidget(QWidget *parent = nullptr);
int timerTick() const { return m_timerTick; }
public slots:
@@ -4586,14 +4582,13 @@ private:
QTreeView *m_treeView;
QStandardItemModel *m_model;
QSortFilterProxyModel *m_sortFilterProxyModel;
- int m_timerTick;
+ int m_timerTick = 0;
};
-Qtbug45697TestWidget::Qtbug45697TestWidget()
- : m_treeView(new QTreeView(this))
+Qtbug45697TestWidget::Qtbug45697TestWidget(QWidget *parent)
+ : QWidget(parent), m_treeView(new QTreeView(this))
, m_model(new QStandardItemModel(0, Qtbug45697TestWidget::columnCount, this))
, m_sortFilterProxyModel(new QSortFilterProxyModel(this))
- , m_timerTick(0)
{
QVBoxLayout *vBoxLayout = new QVBoxLayout(this);
vBoxLayout->addWidget(m_treeView);
@@ -4611,7 +4606,7 @@ Qtbug45697TestWidget::Qtbug45697TestWidget()
m_treeView->setModel(m_sortFilterProxyModel);
QHeaderView *headerView = m_treeView->header();
- for (int s = 1, lastSection = headerView->count() - 1; s < lastSection; ++s )
+ for (int s = 1, lastSection = headerView->count() - 1; s < lastSection; ++s)
headerView->setSectionResizeMode(s, QHeaderView::ResizeToContents);
QTimer *timer = new QTimer(this);
@@ -4697,9 +4692,8 @@ void tst_QTreeView::statusTip()
{
QFETCH(bool, intermediateParent);
QMainWindow mw;
- QtTestModel model;
+ QtTestModel model(5, 5);
model.statusTipsEnabled = true;
- model.rows = model.cols = 5;
QTreeView *view = new QTreeView;
view->setModel(&model);
view->viewport()->setMouseTracking(true);
@@ -4717,7 +4711,7 @@ void tst_QTreeView::statusTip()
mw.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),
QSize(500, 500)));
mw.show();
- qApp->setActiveWindow(&mw);
+ QApplication::setActiveWindow(&mw);
QVERIFY(QTest::qWaitForWindowActive(&mw));
// Ensure it is moved away first and then moved to the relevant section
QTest::mouseMove(mw.windowHandle(), view->mapTo(&mw, view->rect().bottomLeft() + QPoint(20, 20)));
@@ -4736,8 +4730,9 @@ void tst_QTreeView::statusTip()
class FetchMoreModel : public QStandardItemModel
{
+ Q_OBJECT
public:
- FetchMoreModel() : QStandardItemModel(), canFetchReady(false)
+ FetchMoreModel(QObject *parent = nullptr) : QStandardItemModel(parent)
{
for (int i = 0; i < 20; ++i) {
QStandardItem *item = new QStandardItem("Row");
@@ -4757,9 +4752,9 @@ public:
{
QStandardItem *item = itemFromIndex(parent);
for (int i = 0; i < 19; ++i)
- item->appendRow(new QStandardItem(QString("New Child %1").arg(i)));
+ item->appendRow(new QStandardItem(QStringLiteral("New Child ") + QString::number(i)));
}
- bool canFetchReady;
+ bool canFetchReady = false;
};
void tst_QTreeView::fetchMoreOnScroll()
@@ -4865,12 +4860,12 @@ void tst_QTreeView::taskQTBUG_61476()
const QRect rect = priv->itemDecorationRect(mi);
const QPoint pos = rect.center();
- QTest::mousePress(tv.viewport(), Qt::LeftButton, 0, pos);
- if (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, &tv) ==
+ QTest::mousePress(tv.viewport(), Qt::LeftButton, {}, pos);
+ if (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, &tv) ==
QEvent::MouseButtonPress)
QTRY_VERIFY(!tv.isExpanded(mi));
- QTest::mouseRelease(tv.viewport(), Qt::LeftButton, 0, pos);
+ QTest::mouseRelease(tv.viewport(), Qt::LeftButton, nullptr, pos);
QTRY_VERIFY(!tv.isExpanded(mi));
QCOMPARE(lastTopLevel->checkState(), Qt::Checked);
}
diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
index 0d97974b90..6b8beccbdc 100644
--- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
@@ -27,36 +27,22 @@
****************************************************************************/
-#include <QtTest/QtTest>
-#include <qtreewidget.h>
-#include <qtreewidgetitemiterator.h>
-#include <qapplication.h>
-#include <qeventloop.h>
-#include <qdebug.h>
-#include <qheaderview.h>
-#include <qlineedit.h>
+#include <QApplication>
+#include <QHeaderView>
+#include <QLineEdit>
#include <QScrollBar>
+#include <QSignalSpy>
#include <QStyledItemDelegate>
-
-class CustomTreeWidget : public QTreeWidget
-{
- Q_OBJECT
-public:
- QModelIndex indexFromItem(QTreeWidgetItem *item, int column = 0) const
- { return QTreeWidget::indexFromItem(item, column); }
-
- QMimeData * mimeData(const QList<QTreeWidgetItem*> items) const
- { return QTreeWidget::mimeData(items); }
-};
+#include <QTreeWidget>
+#include <QTreeWidgetItemIterator>
+#include <QTest>
class tst_QTreeWidget : public QObject
{
Q_OBJECT
public:
- tst_QTreeWidget();
- ~tst_QTreeWidget();
-
+ tst_QTreeWidget() = default;
public slots:
void initTestCase();
@@ -173,8 +159,25 @@ public slots:
void itemSelectionChanged();
void emitDataChanged();
+public:
+ class PublicTreeWidget : public QTreeWidget
+ {
+ public:
+ using QTreeWidget::indexFromItem;
+ using QTreeWidget::mimeData;
+ using QTreeWidget::sizeHintForColumn;
+ void deleteCurrent() { delete currentItem(); }
+ };
+
+ class PublicTreeItem : public QTreeWidgetItem
+ {
+ public:
+ using QTreeWidgetItem::QTreeWidgetItem;
+ using QTreeWidgetItem::emitDataChanged;
+ };
+
private:
- CustomTreeWidget *testWidget;
+ PublicTreeWidget *testWidget = nullptr;
};
// Testing get/set functions
@@ -186,7 +189,7 @@ void tst_QTreeWidget::getSetCheck()
obj1.setColumnCount(0);
QCOMPARE(obj1.columnCount(), 0);
- obj1.setColumnCount(INT_MIN);
+ obj1.setColumnCount(std::numeric_limits<int>::min());
QCOMPARE(obj1.columnCount(), 0);
//obj1.setColumnCount(INT_MAX);
@@ -202,7 +205,7 @@ void tst_QTreeWidget::getSetCheck()
obj1.setHeaderItem(var2);
QCOMPARE(obj1.headerItem(), var2);
- obj1.setHeaderItem((QTreeWidgetItem *)0);
+ obj1.setHeaderItem(nullptr);
// QCOMPARE(obj1.headerItem(), nullptr);
// QTreeWidgetItem * QTreeWidget::currentItem()
@@ -211,36 +214,28 @@ void tst_QTreeWidget::getSetCheck()
obj1.setCurrentItem(var3);
QCOMPARE(obj1.currentItem(), var3);
- obj1.setCurrentItem((QTreeWidgetItem *)0);
+ obj1.setCurrentItem(nullptr);
QCOMPARE(obj1.currentItem(), nullptr);
}
-typedef QList<int> IntList;
-typedef QList<IntList> ListIntList;
+using IntList = QVector<int>;
+using ListIntList = QVector<IntList>;
+using PersistentModelIndexVec = QVector<QPersistentModelIndex>;
+using TreeItem = QTreeWidgetItem;
+using TreeItemList = QVector<TreeItem*>;
Q_DECLARE_METATYPE(Qt::Orientation)
-
-typedef QTreeWidgetItem TreeItem;
-typedef QList<TreeItem*> TreeItemList;
-
Q_DECLARE_METATYPE(QTreeWidgetItem*)
Q_DECLARE_METATYPE(TreeItemList)
-tst_QTreeWidget::tst_QTreeWidget(): testWidget(0)
-{
-}
-
-tst_QTreeWidget::~tst_QTreeWidget()
-{
-}
-
void tst_QTreeWidget::initTestCase()
{
- qMetaTypeId<QModelIndex>();
qMetaTypeId<Qt::Orientation>();
qRegisterMetaType<QTreeWidgetItem*>("QTreeWidgetItem*");
+ qRegisterMetaType<QList<QPersistentModelIndex>>("QList<QPersistentModelIndex>");
+ qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>("QAbstractItemModel::LayoutChangeHint");
- testWidget = new CustomTreeWidget();
+ testWidget = new PublicTreeWidget();
testWidget->show();
QVERIFY(QTest::qWaitForWindowExposed(testWidget));
}
@@ -261,18 +256,19 @@ void tst_QTreeWidget::cleanup()
{
}
-TreeItem *operator<<(TreeItem *parent, const TreeItemList &children) {
- for (int i = 0; i < children.count(); ++i)
- parent->addChild(children.at(i));
+TreeItem *operator<<(TreeItem *parent, const TreeItemList &children)
+{
+ for (TreeItem *child : children)
+ parent->addChild(child);
return parent;
}
static void populate(QTreeWidget *widget, const TreeItemList &topLevelItems,
- TreeItem *headerItem = 0)
+ TreeItem *headerItem = nullptr)
{
widget->clear();
widget->setHeaderItem(headerItem);
- foreach (TreeItem *item, topLevelItems)
+ for (TreeItem *item : topLevelItems)
widget->addTopLevelItem(item);
}
@@ -282,12 +278,12 @@ void tst_QTreeWidget::addTopLevelItem()
QCOMPARE(tree.topLevelItemCount(), 0);
// try to add 0
- tree.addTopLevelItem(0);
+ tree.addTopLevelItem(nullptr);
QCOMPARE(tree.topLevelItemCount(), 0);
- QCOMPARE(tree.indexOfTopLevelItem(0), -1);
+ QCOMPARE(tree.indexOfTopLevelItem(nullptr), -1);
// add one at a time
- QList<TreeItem*> tops;
+ QList<TreeItem *> tops;
for (int i = 0; i < 10; ++i) {
TreeItem *ti = new TreeItem();
QCOMPARE(tree.indexOfTopLevelItem(ti), -1);
@@ -362,19 +358,19 @@ void tst_QTreeWidget::currentItem_data()
QTest::newRow("only top-level items, 2 columns")
<< (TreeItemList()
- << new TreeItem(QStringList() << "a" << "b")
- << new TreeItem(QStringList() << "c" << "d"));
+ << new TreeItem({"a", "b"})
+ << new TreeItem({"c", "d"}));
TreeItemList lst;
- lst << (new TreeItem(QStringList() << "a" << "b")
+ lst << (new TreeItem({"a", "b"})
<< (TreeItemList()
- << new TreeItem(QStringList() << "c" << "d")
- << new TreeItem(QStringList() << "c" << "d")
+ << new TreeItem({"c", "d"})
+ << new TreeItem({"c", "d"})
)
)
- << (new TreeItem(QStringList() << "e" << "f")
+ << (new TreeItem({"e", "f"})
<< (TreeItemList()
- << new TreeItem(QStringList() << "g" << "h")
- << new TreeItem(QStringList() << "g" << "h")
+ << new TreeItem({"g", "h"})
+ << new TreeItem({"g", "h"})
)
);
QTest::newRow("hierarchy, 2 columns") << lst;
@@ -386,15 +382,15 @@ void tst_QTreeWidget::currentItem()
QTreeWidget tree;
tree.show();
- populate(&tree, topLevelItems, new TreeItem(QStringList() << "1" << "2"));
- QTreeWidgetItem *previous = 0;
+ populate(&tree, topLevelItems, new TreeItem({"1", "2"}));
+ QTreeWidgetItem *previous = nullptr;
for (int x = 0; x < 2; ++x) {
tree.setSelectionBehavior(x ? QAbstractItemView::SelectItems
: QAbstractItemView::SelectRows);
QSignalSpy currentItemChangedSpy(
- &tree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
+ &tree, &QTreeWidget::currentItemChanged);
QSignalSpy itemSelectionChangedSpy(
- &tree, SIGNAL(itemSelectionChanged()));
+ &tree, &QTreeWidget::itemSelectionChanged);
QTreeWidgetItemIterator it(&tree);
// do all items
@@ -468,8 +464,7 @@ void tst_QTreeWidget::editItem()
tree.show();
QVERIFY(QTest::qWaitForWindowActive(&tree));
- QSignalSpy itemChangedSpy(
- &tree, SIGNAL(itemChanged(QTreeWidgetItem*,int)));
+ QSignalSpy itemChangedSpy(&tree, &QTreeWidget::itemChanged);
QTreeWidgetItemIterator it(&tree);
while (QTreeWidgetItem *item = (*it++)) {
@@ -477,18 +472,18 @@ void tst_QTreeWidget::editItem()
if (!(item->flags() & Qt::ItemIsEditable))
QTest::ignoreMessage(QtWarningMsg, "edit: editing failed");
tree.editItem(item, col);
- QApplication::instance()->processEvents();
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
QLineEdit *editor = tree.findChild<QLineEdit*>();
if (editor) {
QVERIFY(item->flags() & Qt::ItemIsEditable);
QCOMPARE(editor->selectedText(), editor->text());
QTest::keyClick(editor, Qt::Key_A);
QTest::keyClick(editor, Qt::Key_Enter);
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(itemChangedSpy.count(), 1);
QVariantList args = itemChangedSpy.takeFirst();
- QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
+ QCOMPARE(qvariant_cast<QTreeWidgetItem *>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), col);
} else {
QVERIFY(!(item->flags() & Qt::ItemIsEditable));
@@ -522,10 +517,10 @@ void tst_QTreeWidget::takeItem()
QFETCH(bool, topLevel);
QFETCH(bool, outOfBounds);
- for (int i=0; i<3; ++i) {
+ for (int i = 0; i < 3; ++i) {
QTreeWidgetItem *top = new QTreeWidgetItem(testWidget);
top->setText(0, QStringLiteral("top") + QString::number(i));
- for (int j=0; j<3; ++j) {
+ for (int j = 0; j < 3; ++j) {
QTreeWidgetItem *child = new QTreeWidgetItem(top);
child->setText(0, QStringLiteral("child") + QString::number(j));
}
@@ -635,27 +630,23 @@ void tst_QTreeWidget::setItemHidden()
parent->setHidden(true);
parent->setHidden(false);
QVERIFY(!parent->isHidden());
-
-
}
void tst_QTreeWidget::setItemHidden2()
{
// From Task 78587
- QStringList hl;
- hl << "ID" << "Desc";
+ const QStringList hl({"ID", "Desc"});
testWidget->setColumnCount(hl.count());
testWidget->setHeaderLabels(hl);
testWidget->setSortingEnabled(true);
QTreeWidgetItem *top = new QTreeWidgetItem(testWidget);
- QTreeWidgetItem *leaf = 0;
top->setText(0, "ItemList");
for (int i = 1; i <= 4; i++) {
- leaf = new QTreeWidgetItem(top);
- leaf->setText(0, QString::asprintf("%d", i));
- leaf->setText(1, QString::asprintf("Item %d", i));
+ auto leaf = new QTreeWidgetItem(top);
+ leaf->setText(0, QString::number(i));
+ leaf->setText(1, QStringLiteral("Item %1").arg(i));
}
if (testWidget->topLevelItemCount() > 0) {
@@ -666,11 +657,10 @@ void tst_QTreeWidget::setItemHidden2()
if (testWidget->topLevelItemCount() > 0) {
top = testWidget->topLevelItem(0);
for (int i = 0; i < top->childCount(); i++) {
- leaf = top->child(i);
+ auto leaf = top->child(i);
if (leaf->text(0).toInt() % 2 == 0) {
- if (!leaf->isHidden()) {
+ if (!leaf->isHidden())
leaf->setHidden(true);
- }
}
}
}
@@ -799,25 +789,25 @@ void tst_QTreeWidget::selectedItems()
QFETCH(int, topLevel);
QFETCH(int, children);
QFETCH(bool, closeTopLevel);
- QFETCH(ListIntList, selectedItems);
- QFETCH(ListIntList, hiddenItems);
- QFETCH(ListIntList, expectedItems);
+ QFETCH(const ListIntList, selectedItems);
+ QFETCH(const ListIntList, hiddenItems);
+ QFETCH(const ListIntList, expectedItems);
// create items
- for (int t=0; t<topLevel; ++t) {
+ for (int t = 0; t < topLevel; ++t) {
QTreeWidgetItem *top = new QTreeWidgetItem(testWidget);
const QString topS = QLatin1String("top") + QString::number(t);
top->setText(0, topS);
- for (int c=0; c<children; ++c) {
+ for (int c = 0; c < children; ++c) {
QTreeWidgetItem *child = new QTreeWidgetItem(top);
child->setText(0, topS + QLatin1String("child") + QString::number(c));
}
}
// set selected
- foreach (IntList itemPath, selectedItems) {
- QTreeWidgetItem *item = 0;
- foreach(int index, itemPath) {
+ for (const auto &itemPath : selectedItems) {
+ QTreeWidgetItem *item = nullptr;
+ for (int index : itemPath) {
if (!item)
item = testWidget->topLevelItem(index);
else
@@ -827,9 +817,9 @@ void tst_QTreeWidget::selectedItems()
}
// hide rows
- foreach (IntList itemPath, hiddenItems) {
- QTreeWidgetItem *item = 0;
- foreach(int index, itemPath) {
+ for (const auto &itemPath : hiddenItems) {
+ QTreeWidgetItem *item = nullptr;
+ for (int index : itemPath) {
if (!item)
item = testWidget->topLevelItem(index);
else
@@ -839,7 +829,7 @@ void tst_QTreeWidget::selectedItems()
}
// open/close toplevel
- for (int i=0; i<testWidget->topLevelItemCount(); ++i) {
+ for (int i = 0; i < testWidget->topLevelItemCount(); ++i) {
if (closeTopLevel)
testWidget->collapseItem(testWidget->topLevelItem(i));
else
@@ -847,26 +837,26 @@ void tst_QTreeWidget::selectedItems()
}
// check selectedItems
- QList<QTreeWidgetItem*> sel = testWidget->selectedItems();
+ const auto sel = testWidget->selectedItems();
QCOMPARE(sel.count(), expectedItems.count());
- foreach (IntList itemPath, expectedItems) {
- QTreeWidgetItem *item = 0;
- foreach(int index, itemPath) {
+ for (const auto &itemPath : expectedItems) {
+ QTreeWidgetItem *item = nullptr;
+ for (int index : itemPath) {
if (!item)
item = testWidget->topLevelItem(index);
else
item = item->child(index);
}
if (item)
- QVERIFY(sel.contains(item));
+ QVERIFY(sel.contains(item));
}
// compare isSelected
- for (int t=0; t<testWidget->topLevelItemCount(); ++t) {
+ for (int t = 0; t < testWidget->topLevelItemCount(); ++t) {
QTreeWidgetItem *top = testWidget->topLevelItem(t);
if (top->isSelected() && !top->isHidden())
QVERIFY(sel.contains(top));
- for (int c=0; c<top->childCount(); ++c) {
+ for (int c = 0; c < top->childCount(); ++c) {
QTreeWidgetItem *child = top->child(c);
if (child->isSelected() && !child->isHidden())
QVERIFY(sel.contains(child));
@@ -883,9 +873,9 @@ QT_WARNING_POP
#endif
// unselect
- foreach (IntList itemPath, selectedItems) {
- QTreeWidgetItem *item = 0;
- foreach(int index, itemPath) {
+ for (const auto &itemPath : selectedItems) {
+ QTreeWidgetItem *item = nullptr;
+ for (int index : itemPath) {
if (!item)
item = testWidget->topLevelItem(index);
else
@@ -903,7 +893,7 @@ void tst_QTreeWidget::itemAssignment()
QTreeWidgetItem *parent = new QTreeWidgetItem(&grandParent);
parent->setText(0, "foo");
parent->setText(1, "bar");
- for (int i=0; i<5; ++i) {
+ for (int i = 0; i < 5; ++i) {
QTreeWidgetItem *child = new QTreeWidgetItem(parent);
child->setText(0, "bingo");
child->setText(1, "bango");
@@ -919,7 +909,7 @@ void tst_QTreeWidget::itemAssignment()
QTreeWidgetItem item(testWidget);
item.setText(0, "baz");
QVERIFY(!item.parent());
- QCOMPARE(item.treeWidget(), static_cast<QTreeWidget *>(testWidget));
+ QCOMPARE(item.treeWidget(), testWidget);
QCOMPARE(item.columnCount(), 1);
QCOMPARE(item.text(0), QString("baz"));
QCOMPARE(item.childCount(), 0);
@@ -959,16 +949,16 @@ void tst_QTreeWidget::clone()
QFETCH(int, column);
QFETCH(int, topLevelIndex);
QFETCH(int, childIndex);
- QFETCH(QStringList, topLevelText);
- QFETCH(QStringList, childText);
+ QFETCH(const QStringList, topLevelText);
+ QFETCH(const QStringList, childText);
QFETCH(bool, cloneChild);
- for (int i = 0; i < topLevelText.count(); ++i) {
+ for (const QString &tl : topLevelText) {
QTreeWidgetItem *item = new QTreeWidgetItem(testWidget);
- item->setText(column, topLevelText.at(i));
- for (int j = 0; j < childText.count(); ++j) {
+ item->setText(column, tl);
+ for (const QString &cl : childText) {
QTreeWidgetItem *child = new QTreeWidgetItem(item);
- child->setText(column, childText.at(j));
+ child->setText(column, cl);
}
}
@@ -984,7 +974,7 @@ void tst_QTreeWidget::clone()
QVERIFY(copiedChild != originalChild);
QCOMPARE(copiedChild->text(column), originalChild->text(column));
QCOMPARE(copiedChild->childCount(), originalChild->childCount());
- QCOMPARE(copiedChild->parent(), cloneChild ? 0 : copy);
+ QCOMPARE(copiedChild->parent(), cloneChild ? nullptr : copy);
QVERIFY(!copiedChild->treeWidget());
if (cloneChild)
delete copiedChild;
@@ -1109,18 +1099,18 @@ void tst_QTreeWidget::findItems_data()
void tst_QTreeWidget::findItems()
{
QFETCH(int, column);
- QFETCH(QStringList, topLevelText);
- QFETCH(QStringList, childText);
+ QFETCH(const QStringList, topLevelText);
+ QFETCH(const QStringList, childText);
QFETCH(QString, pattern);
QFETCH(int, resultCount);
- QFETCH(QStringList, resultText);
+ QFETCH(const QStringList, resultText);
- for (int i = 0; i < topLevelText.count(); ++i) {
+ for (const QString &tl : topLevelText) {
QTreeWidgetItem *item = new QTreeWidgetItem(testWidget);
- item->setText(column, topLevelText.at(i));
- for (int j = 0; j < childText.count(); ++j) {
+ item->setText(column, tl);
+ for (const QString &cl : childText) {
QTreeWidgetItem *child = new QTreeWidgetItem(item);
- child->setText(column, childText.at(j));
+ child->setText(column, cl);
}
}
@@ -1152,7 +1142,7 @@ void tst_QTreeWidget::findItemsInColumn()
void tst_QTreeWidget::sortItems_data()
{
QTest::addColumn<int>("column");
- QTest::addColumn<int>("order");
+ QTest::addColumn<Qt::SortOrder>("order");
QTest::addColumn<QStringList>("topLevelText");
QTest::addColumn<QStringList>("childText");
QTest::addColumn<QStringList>("topLevelResult");
@@ -1162,7 +1152,7 @@ void tst_QTreeWidget::sortItems_data()
QTest::newRow("ascending order")
<< 0
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "c" << "d" << "a" << "b")
<< (QStringList() << "e" << "h" << "g" << "f")
<< (QStringList() << "a" << "b" << "c" << "d")
@@ -1172,7 +1162,7 @@ void tst_QTreeWidget::sortItems_data()
QTest::newRow("descending order")
<< 0
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QStringList() << "c" << "d" << "a" << "b")
<< (QStringList() << "e" << "h" << "g" << "f")
<< (QStringList() << "d" << "c" << "b" << "a")
@@ -1184,7 +1174,7 @@ void tst_QTreeWidget::sortItems_data()
void tst_QTreeWidget::sortItems()
{
QFETCH(int, column);
- QFETCH(int, order);
+ QFETCH(Qt::SortOrder, order);
QFETCH(QStringList, topLevelText);
QFETCH(QStringList, childText);
QFETCH(QStringList, topLevelResult);
@@ -1193,28 +1183,24 @@ void tst_QTreeWidget::sortItems()
QFETCH(IntList, expectedChildRows);
testWidget->setSortingEnabled(false);
- for (int i = 0; i < topLevelText.count(); ++i) {
+ for (const QString &tl : topLevelText) {
QTreeWidgetItem *item = new QTreeWidgetItem(testWidget);
- item->setText(column, topLevelText.at(i));
- for (int j = 0; j < childText.count(); ++j) {
+ item->setText(column, tl);
+ for (const QString &cl : childText) {
QTreeWidgetItem *child = new QTreeWidgetItem(item);
- child->setText(column, childText.at(j));
+ child->setText(column, cl);
}
}
QAbstractItemModel *model = testWidget->model();
- QList<QPersistentModelIndex> tops;
- for (int r = 0; r < model->rowCount(QModelIndex()); ++r) {
- QPersistentModelIndex p = model->index(r, 0, QModelIndex());
- tops << p;
- }
- QList<QPersistentModelIndex> children;
- for (int s = 0; s < model->rowCount(tops.first()); ++s) {
- QPersistentModelIndex c = model->index(s, 0, tops.first());
- children << c;
- }
-
- testWidget->sortItems(column, static_cast<Qt::SortOrder>(order));
+ PersistentModelIndexVec tops;
+ for (int r = 0; r < model->rowCount(QModelIndex()); ++r)
+ tops.push_back(model->index(r, 0, QModelIndex()));
+ PersistentModelIndexVec children;
+ for (int s = 0; s < model->rowCount(tops.constFirst()); ++s)
+ children.push_back(model->index(s, 0, tops.constFirst()));
+
+ testWidget->sortItems(column, order);
QCOMPARE(testWidget->sortColumn(), column);
for (int k = 0; k < topLevelResult.count(); ++k) {
@@ -1382,8 +1368,8 @@ void tst_QTreeWidget::insertTopLevelItems_data()
QTest::addColumn<int>("insertChildIndex");
QTest::addColumn<int>("expectedChildIndex");
- QStringList initial = (QStringList() << "foo" << "bar");
- QStringList insert = (QStringList() << "baz");
+ const QStringList initial{ "foo", "bar" };
+ const QStringList insert{ "baz" };
QTest::newRow("Insert at count") << initial << insert
<< initial.count() << initial.count()
@@ -1434,7 +1420,7 @@ void tst_QTreeWidget::insertTopLevelItems()
delete topsy;
} else {
QTreeWidgetItem *item = testWidget->topLevelItem(expectedTopLevelIndex);
- QVERIFY(item != 0);
+ QVERIFY(item != nullptr);
QCOMPARE(item->text(0), insertText.at(0));
QCOMPARE(testWidget->indexOfTopLevelItem(item), expectedTopLevelIndex);
}
@@ -1442,7 +1428,7 @@ void tst_QTreeWidget::insertTopLevelItems()
{ // test adding more children
QTreeWidgetItem *topLevel = testWidget->topLevelItem(0);
- QVERIFY(topLevel != 0);
+ QVERIFY(topLevel != nullptr);
QTreeWidgetItem *child = new QTreeWidgetItem(QStringList(insertText.at(0)));
topLevel->insertChild(insertChildIndex, child);
if (expectedChildIndex == -1) {
@@ -1450,7 +1436,7 @@ void tst_QTreeWidget::insertTopLevelItems()
delete child;
} else {
QTreeWidgetItem *item = topLevel->child(expectedChildIndex);
- QVERIFY(item != 0);
+ QVERIFY(item != nullptr);
QCOMPARE(item->text(0), insertText.at(0));
}
}
@@ -1486,37 +1472,33 @@ void tst_QTreeWidget::keyboardNavigation()
fillTreeWidget(testWidget, rows);
- QVector<Qt::Key> keymoves;
- keymoves << Qt::Key_Down << Qt::Key_Right << Qt::Key_Left
- << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down
- << Qt::Key_Right
- << Qt::Key_Up << Qt::Key_Left << Qt::Key_Left
- << Qt::Key_Up << Qt::Key_Down << Qt::Key_Up << Qt::Key_Up
- << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up
- << Qt::Key_Down << Qt::Key_Right << Qt::Key_Down << Qt::Key_Down
- << Qt::Key_Down << Qt::Key_Right << Qt::Key_Down << Qt::Key_Down
- << Qt::Key_Left << Qt::Key_Left << Qt::Key_Up << Qt::Key_Down
- << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Left
- << Qt::Key_Down << Qt::Key_Right << Qt::Key_Right << Qt::Key_Right
- << Qt::Key_Left << Qt::Key_Left << Qt::Key_Right << Qt::Key_Left;
-
- int row = 0;
+ const QVector<Qt::Key> keymoves {
+ Qt::Key_Down, Qt::Key_Right, Qt::Key_Left,
+ Qt::Key_Down, Qt::Key_Down, Qt::Key_Down, Qt::Key_Down,
+ Qt::Key_Right,
+ Qt::Key_Up, Qt::Key_Left, Qt::Key_Left,
+ Qt::Key_Up, Qt::Key_Down, Qt::Key_Up, Qt::Key_Up,
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Up,
+ Qt::Key_Down, Qt::Key_Right, Qt::Key_Down, Qt::Key_Down,
+ Qt::Key_Down, Qt::Key_Right, Qt::Key_Down, Qt::Key_Down,
+ Qt::Key_Left, Qt::Key_Left, Qt::Key_Up, Qt::Key_Down,
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Left,
+ Qt::Key_Down, Qt::Key_Right, Qt::Key_Right, Qt::Key_Right,
+ Qt::Key_Left, Qt::Key_Left, Qt::Key_Right, Qt::Key_Left
+ };
+
+ int row = 0;
QTreeWidgetItem *item = testWidget->topLevelItem(0);
testWidget->setCurrentItem(item);
QCOMPARE(testWidget->currentItem(), item);
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
QScrollBar *scrollBar = testWidget->horizontalScrollBar();
- bool checkScroll = false;
- for (int i = 0; i < keymoves.size(); ++i) {
- Qt::Key key = keymoves.at(i);
+ for (const Qt::Key key : keymoves) {
int valueBeforeClick = scrollBar->value();
- if (valueBeforeClick >= scrollBar->singleStep())
- checkScroll = true;
- else
- checkScroll = false;
+ const bool checkScroll = (valueBeforeClick >= scrollBar->singleStep());
QTest::keyClick(testWidget, key);
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
switch (key) {
case Qt::Key_Up:
@@ -1611,15 +1593,15 @@ void tst_QTreeWidget::scrollToItem()
// Check if all parent nodes of the item found are expanded.
// Reported in task #78761
QTreeWidgetItem *search = nullptr;
- for (int i=0; i<2; ++i) {
+ for (int i = 0; i < 2; ++i) {
QTreeWidgetItem *bar = new QTreeWidgetItem(testWidget);
bar->setText(0, QString::number(i));
- for (int j=0; j<2; ++j) {
+ for (int j = 0; j < 2; ++j) {
QTreeWidgetItem *foo = new QTreeWidgetItem(bar);
foo->setText(0, bar->text(0) + QString::number(j));
- for (int k=0; k<2; ++k) {
+ for (int k = 0; k < 2; ++k) {
search = new QTreeWidgetItem(foo);
search->setText(0, foo->text(0) + QString::number(k));
}
@@ -1639,8 +1621,7 @@ void tst_QTreeWidget::scrollToItem()
// From task #85413
void tst_QTreeWidget::setSortingEnabled()
{
- QStringList hl;
- hl << "ID";
+ const QStringList hl{ "ID" };
testWidget->setColumnCount(hl.count());
testWidget->setHeaderLabels(hl);
@@ -1682,14 +1663,14 @@ void tst_QTreeWidget::addChild()
{
QTreeWidget tree;
for (int x = 0; x < 2; ++x) {
- QTreeWidget *view = x ? &tree : static_cast<QTreeWidget*>(0);
- QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)view);
+ QTreeWidget *view = x ? &tree : static_cast<QTreeWidget*>(nullptr);
+ QTreeWidgetItem *item = new QTreeWidgetItem(view);
QCOMPARE(item->childCount(), 0);
// try to add 0
- item->addChild(0);
+ item->addChild(nullptr);
QCOMPARE(item->childCount(), 0);
- QCOMPARE(item->indexOfChild(0), -1);
+ QCOMPARE(item->indexOfChild(nullptr), -1);
// add one at a time
QList<QTreeWidgetItem*> children;
@@ -1762,11 +1743,11 @@ void tst_QTreeWidget::setData()
testWidget->setHeaderItem(headerItem);
QSignalSpy headerDataChangedSpy(
- testWidget->model(), SIGNAL(headerDataChanged(Qt::Orientation,int,int)));
+ testWidget->model(), &QAbstractItemModel::headerDataChanged);
QSignalSpy dataChangedSpy(
- testWidget->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)));
+ testWidget->model(), &QAbstractItemModel::dataChanged);
QSignalSpy itemChangedSpy(
- testWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)));
+ testWidget, &QTreeWidget::itemChanged);
headerItem->setText(0, "test");
QCOMPARE(dataChangedSpy.count(), 0);
QCOMPARE(headerDataChangedSpy.count(), 1);
@@ -1777,7 +1758,7 @@ void tst_QTreeWidget::setData()
{
QSignalSpy itemChangedSpy(
- testWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)));
+ testWidget, &QTreeWidget::itemChanged);
QTreeWidgetItem *item = new QTreeWidgetItem();
testWidget->addTopLevelItem(item);
for (int x = 0; x < 2; ++x) {
@@ -2069,7 +2050,7 @@ void tst_QTreeWidget::setHeaderLabels()
void tst_QTreeWidget::setHeaderItem()
{
- testWidget->setHeaderItem(0);
+ testWidget->setHeaderItem(nullptr);
QTreeWidgetItem *headerItem = new QTreeWidgetItem();
testWidget->setColumnCount(0);
@@ -2118,7 +2099,7 @@ void tst_QTreeWidget::itemWidget()
QFETCH(TreeItemList, topLevelItems);
QTreeWidget tree;
- populate(&tree, topLevelItems, new TreeItem(QStringList() << "1" << "2"));
+ populate(&tree, topLevelItems, new TreeItem({"1", "2"}));
tree.show();
for (int x = 0; x < 2; ++x) {
@@ -2126,18 +2107,18 @@ void tst_QTreeWidget::itemWidget()
while (QTreeWidgetItem *item = (*it++)) {
for (int col = 0; col < item->columnCount(); ++col) {
if (x == 0) {
- QCOMPARE(tree.itemWidget(item, col), static_cast<QWidget*>(0));
+ QCOMPARE(tree.itemWidget(item, col), nullptr);
QWidget *editor = new QLineEdit();
tree.setItemWidget(item, col, editor);
QCOMPARE(tree.itemWidget(item, col), editor);
tree.removeItemWidget(item, col);
- QCOMPARE(tree.itemWidget(item, col), static_cast<QWidget*>(0));
+ QCOMPARE(tree.itemWidget(item, col), nullptr);
} else {
// ### should you really be able to open a persistent
// editor for an item that isn't editable??
tree.openPersistentEditor(item, col);
QWidget *editor = tree.findChild<QLineEdit*>();
- QVERIFY(editor != 0);
+ QVERIFY(editor != nullptr);
tree.closePersistentEditor(item, col);
}
}
@@ -2147,50 +2128,50 @@ void tst_QTreeWidget::itemWidget()
void tst_QTreeWidget::insertItemsWithSorting_data()
{
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<QStringList>("initialItems");
QTest::addColumn<QStringList>("insertItems");
QTest::addColumn<QStringList>("expectedItems");
QTest::addColumn<IntList>("expectedRows");
QTest::newRow("() + (a) = (a)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< QStringList()
<< (QStringList() << "a")
<< (QStringList() << "a")
<< IntList();
QTest::newRow("() + (c, b, a) = (a, b, c)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< QStringList()
<< (QStringList() << "c" << "b" << "a")
<< (QStringList() << "a" << "b" << "c")
<< IntList();
QTest::newRow("() + (a, b, c) = (c, b, a)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< QStringList()
<< (QStringList() << "a" << "b" << "c")
<< (QStringList() << "c" << "b" << "a")
<< IntList();
QTest::newRow("(a) + (b) = (a, b)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< QStringList("a")
<< (QStringList() << "b")
<< (QStringList() << "a" << "b")
<< (IntList() << 0);
QTest::newRow("(a) + (b) = (b, a)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< QStringList("a")
<< (QStringList() << "b")
<< (QStringList() << "b" << "a")
<< (IntList() << 1);
QTest::newRow("(a, c, b) + (d) = (a, b, c, d)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "b")
<< (QStringList() << "d")
<< (QStringList() << "a" << "b" << "c" << "d")
<< (IntList() << 0 << 1 << 2);
QTest::newRow("(b, c, a) + (d) = (d, c, b, a)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QStringList() << "b" << "c" << "a")
<< (QStringList() << "d")
<< (QStringList() << "d" << "c" << "b" << "a")
@@ -2200,38 +2181,38 @@ void tst_QTreeWidget::insertItemsWithSorting_data()
IntList reverseRows;
QStringList ascendingItems;
QStringList reverseItems;
- for (int i = 'a'; i <= 'z'; ++i) {
+ for (char i = 'a'; i <= 'z'; ++i) {
ascendingItems << QString(1, QLatin1Char(i));
reverseItems << QString(1, QLatin1Char('z' - i + 'a'));
ascendingRows << i - 'a';
reverseRows << 'z' - i + 'a';
}
QTest::newRow("() + (sorted items) = (sorted items)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< QStringList()
<< ascendingItems
<< ascendingItems
<< IntList();
QTest::newRow("(sorted items) + () = (sorted items)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< ascendingItems
<< QStringList()
<< ascendingItems
<< ascendingRows;
QTest::newRow("() + (ascending items) = (reverse items)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< QStringList()
<< ascendingItems
<< reverseItems
<< IntList();
QTest::newRow("(reverse items) + () = (ascending items)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< reverseItems
<< QStringList()
<< ascendingItems
<< ascendingRows;
QTest::newRow("(reverse items) + () = (reverse items)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< reverseItems
<< QStringList()
<< reverseItems
@@ -2241,57 +2222,57 @@ void tst_QTreeWidget::insertItemsWithSorting_data()
void tst_QTreeWidget::insertItemsWithSorting()
{
- QFETCH(int, sortOrder);
- QFETCH(QStringList, initialItems);
- QFETCH(QStringList, insertItems);
- QFETCH(QStringList, expectedItems);
+ QFETCH(Qt::SortOrder, sortOrder);
+ QFETCH(const QStringList, initialItems);
+ QFETCH(const QStringList, insertItems);
+ QFETCH(const QStringList, expectedItems);
QFETCH(IntList, expectedRows);
for (int method = 0; method < 5; ++method) {
QTreeWidget w;
w.setSortingEnabled(true);
- w.sortItems(0, static_cast<Qt::SortOrder>(sortOrder));
- for (int i = 0; i < initialItems.count(); ++i)
- w.addTopLevelItem(new QTreeWidgetItem(QStringList() << initialItems.at(i)));
+ w.sortItems(0, sortOrder);
+ for (const QString &initialItem : initialItems)
+ w.addTopLevelItem(new QTreeWidgetItem({initialItem}));
QAbstractItemModel *model = w.model();
- QList<QPersistentModelIndex> persistent;
+ PersistentModelIndexVec persistent;
for (int j = 0; j < model->rowCount(QModelIndex()); ++j)
persistent << model->index(j, 0, QModelIndex());
switch (method) {
case 0:
// insert using item constructor
- for (int i = 0; i < insertItems.size(); ++i)
- new QTreeWidgetItem(&w, QStringList() << insertItems.at(i));
+ for (const QString &txt : insertItems)
+ new QTreeWidgetItem(&w, { txt });
break;
case 1:
{
// insert using insertTopLevelItems()
QList<QTreeWidgetItem*> lst;
- for (int i = 0; i < insertItems.size(); ++i)
- lst << new QTreeWidgetItem(QStringList() << insertItems.at(i));
+ for (const QString &txt : insertItems)
+ lst << new QTreeWidgetItem({ txt });
w.insertTopLevelItems(0, lst);
break;
}
case 2:
// insert using insertTopLevelItem()
- for (int i = 0; i < insertItems.size(); ++i)
- w.insertTopLevelItem(0, new QTreeWidgetItem(QStringList() << insertItems.at(i)));
+ for (const QString &txt : insertItems)
+ w.insertTopLevelItem(0, new QTreeWidgetItem({ txt }));
break;
case 3:
{
// insert using addTopLevelItems()
QList<QTreeWidgetItem*> lst;
- for (int i = 0; i < insertItems.size(); ++i)
- lst << new QTreeWidgetItem(QStringList() << insertItems.at(i));
+ for (const QString &txt : insertItems)
+ lst << new QTreeWidgetItem({ txt });
w.addTopLevelItems(lst);
break;
}
case 4:
// insert using addTopLevelItem()
- for (int i = 0; i < insertItems.size(); ++i)
- w.addTopLevelItem(new QTreeWidgetItem(QStringList() << insertItems.at(i)));
+ for (const QString &txt : insertItems)
+ w.addTopLevelItem(new QTreeWidgetItem({ txt }));
break;
}
QCOMPARE(w.topLevelItemCount(), expectedItems.count());
@@ -2305,8 +2286,8 @@ void tst_QTreeWidget::insertItemsWithSorting()
void tst_QTreeWidget::insertExpandedItemsWithSorting_data()
{
- QTest::addColumn<QStringList>("parentText");
- QTest::addColumn<QStringList>("childText");
+ QTest::addColumn<QStringList>("parentTexts");
+ QTest::addColumn<QStringList>("childTexts");
QTest::addColumn<QStringList>("parentResult");
QTest::addColumn<QStringList>("childResult");
QTest::newRow("test 1")
@@ -2319,36 +2300,36 @@ void tst_QTreeWidget::insertExpandedItemsWithSorting_data()
// From Task 134978
void tst_QTreeWidget::insertExpandedItemsWithSorting()
{
- QFETCH(QStringList, parentText);
- QFETCH(QStringList, childText);
- QFETCH(QStringList, parentResult);
- QFETCH(QStringList, childResult);
+ QFETCH(const QStringList, parentTexts);
+ QFETCH(const QStringList, childTexts);
+ QFETCH(const QStringList, parentResult);
+ QFETCH(const QStringList, childResult);
// create a tree with autosorting enabled
- CustomTreeWidget tree;
+ PublicTreeWidget tree;
tree.setSortingEnabled(true);
// insert expanded items in unsorted order
- QList<QTreeWidgetItem *> items;
- for (int i = 0; i < parentText.count(); ++i) {
- QTreeWidgetItem *parent = new QTreeWidgetItem(&tree, QStringList(parentText.at(i)));
+ QVector<QTreeWidgetItem *> items;
+ for (const QString &text : parentTexts) {
+ QTreeWidgetItem *parent = new QTreeWidgetItem(&tree, {text});
parent->setExpanded(true);
QVERIFY(parent->isExpanded());
items << parent;
- for (int j = 0; j < childText.count(); ++j) {
- QTreeWidgetItem *child = new QTreeWidgetItem(parent, QStringList(childText.at(j)));
+ for (const QString &text : childTexts) {
+ QTreeWidgetItem *child = new QTreeWidgetItem(parent, {text});
items << child;
}
- QCOMPARE(parent->childCount(), childText.count());
+ QCOMPARE(parent->childCount(), childTexts.count());
QVERIFY(parent->isExpanded());
}
- QCOMPARE(tree.model()->rowCount(), parentText.count());
+ QCOMPARE(tree.model()->rowCount(), parentTexts.count());
// verify that the items are still expanded
- foreach (QTreeWidgetItem *item, items) {
+ for (const QTreeWidgetItem *item : qAsConst(items)) {
if (item->childCount() > 0)
QVERIFY(item->isExpanded());
- QModelIndex idx = tree.indexFromItem(const_cast<QTreeWidgetItem *>(item));
+ QModelIndex idx = tree.indexFromItem(item);
QVERIFY(idx.isValid());
//QRect rect = tree.visualRect(idx);
//QVERIFY(rect.isValid());
@@ -2357,16 +2338,12 @@ void tst_QTreeWidget::insertExpandedItemsWithSorting()
// verify that the tree is sorted
QAbstractItemModel *model = tree.model();
- QList<QPersistentModelIndex> parents;
- for (int i = 0; i < model->rowCount(QModelIndex()); ++i) {
- QPersistentModelIndex parent = model->index(i, 0, QModelIndex());
- parents << parent;
- }
- QList<QPersistentModelIndex> children;
- for (int i = 0; i < model->rowCount(parents.first()); ++i) {
- QPersistentModelIndex child = model->index(i, 0, parents.first());
- children << child;
- }
+ PersistentModelIndexVec parents;
+ for (int i = 0; i < model->rowCount(QModelIndex()); ++i)
+ parents.push_back(model->index(i, 0, QModelIndex()));
+ PersistentModelIndexVec children;
+ for (int i = 0; i < model->rowCount(parents.constFirst()); ++i)
+ children.push_back(model->index(i, 0, parents.constFirst()));
for (int i = 0; i < parentResult.count(); ++i) {
QTreeWidgetItem *item = tree.topLevelItem(i);
QCOMPARE(item->text(0), parentResult.at(i));
@@ -2377,7 +2354,7 @@ void tst_QTreeWidget::insertExpandedItemsWithSorting()
void tst_QTreeWidget::changeDataWithSorting_data()
{
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<QStringList>("initialItems");
QTest::addColumn<int>("itemIndex");
QTest::addColumn<QString>("newValue");
@@ -2386,49 +2363,49 @@ void tst_QTreeWidget::changeDataWithSorting_data()
QTest::addColumn<bool>("reorderingExpected");
QTest::newRow("change a to b in (a)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a")
<< 0 << "b"
<< (QStringList() << "b")
<< (IntList() << 0)
<< false;
QTest::newRow("change a to b in (a, c)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c")
<< 0 << "b"
<< (QStringList() << "b" << "c")
<< (IntList() << 0 << 1)
<< false;
QTest::newRow("change a to c in (a, b)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "b")
<< 0 << "c"
<< (QStringList() << "b" << "c")
<< (IntList() << 1 << 0)
<< true;
QTest::newRow("change c to a in (c, b)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QStringList() << "c" << "b")
<< 0 << "a"
<< (QStringList() << "b" << "a")
<< (IntList() << 1 << 0)
<< true;
QTest::newRow("change e to i in (a, c, e, g)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "e" << "g")
<< 2 << "i"
<< (QStringList() << "a" << "c" << "g" << "i")
<< (IntList() << 0 << 1 << 3 << 2)
<< true;
QTest::newRow("change e to a in (c, e, g, i)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "c" << "e" << "g" << "i")
<< 1 << "a"
<< (QStringList() << "a" << "c" << "g" << "i")
<< (IntList() << 1 << 0 << 2 << 3)
<< true;
QTest::newRow("change e to f in (c, e, g, i)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "c" << "e" << "g" << "i")
<< 1 << "f"
<< (QStringList() << "c" << "f" << "g" << "i")
@@ -2438,35 +2415,35 @@ void tst_QTreeWidget::changeDataWithSorting_data()
void tst_QTreeWidget::changeDataWithSorting()
{
- QFETCH(int, sortOrder);
- QFETCH(QStringList, initialItems);
+ QFETCH(Qt::SortOrder, sortOrder);
+ QFETCH(const QStringList, initialItems);
QFETCH(int, itemIndex);
- QFETCH(QString, newValue);
- QFETCH(QStringList, expectedItems);
- QFETCH(IntList, expectedRows);
+ QFETCH(const QString, newValue);
+ QFETCH(const QStringList, expectedItems);
+ QFETCH(const IntList, expectedRows);
QFETCH(bool, reorderingExpected);
QTreeWidget w;
w.setSortingEnabled(true);
- w.sortItems(0, static_cast<Qt::SortOrder>(sortOrder));
- for (int i = 0; i < initialItems.count(); ++i)
- w.addTopLevelItem(new QTreeWidgetItem(QStringList() << initialItems.at(i)));
+ w.sortItems(0, sortOrder);
+ for (const QString &str : initialItems)
+ w.addTopLevelItem(new QTreeWidgetItem({ str }));
QAbstractItemModel *model = w.model();
- QList<QPersistentModelIndex> persistent;
+ PersistentModelIndexVec persistent;
for (int j = 0; j < model->rowCount(QModelIndex()); ++j)
persistent << model->index(j, 0, QModelIndex());
- QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
- QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged()));
+ QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged);
+ QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged);
QTreeWidgetItem *item = w.topLevelItem(itemIndex);
item->setText(0, newValue);
for (int i = 0; i < expectedItems.count(); ++i) {
QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i));
- for (int j = 0; j < persistent.count(); ++j) {
- if (persistent.at(j).row() == i) // the same toplevel row
- QCOMPARE(persistent.at(j).internalPointer(), (void *)w.topLevelItem(i));
+ for (const QPersistentModelIndex &p : qAsConst(persistent)) {
+ if (p.row() == i) // the same toplevel row
+ QCOMPARE(p.internalPointer(), static_cast<void *>(w.topLevelItem(i)));
}
}
@@ -2479,7 +2456,7 @@ void tst_QTreeWidget::changeDataWithSorting()
void tst_QTreeWidget::changeDataWithStableSorting_data()
{
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<QStringList>("initialItems");
QTest::addColumn<int>("itemIndex");
QTest::addColumn<QString>("newValue");
@@ -2489,7 +2466,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
QTest::addColumn<bool>("forceChange");
QTest::newRow("change a to c in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 0 << "c"
<< (QStringList() << "c" << "c" << "c" << "c" << "e")
@@ -2497,7 +2474,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< false
<< false;
QTest::newRow("change e to c in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 4 << "c"
<< (QStringList() << "a" << "c" << "c" << "c" << "c")
@@ -2505,7 +2482,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< false
<< false;
QTest::newRow("change 1st c to c in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 1 << "c"
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
@@ -2513,7 +2490,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< false
<< true;
QTest::newRow("change 2nd c to c in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 2 << "c"
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
@@ -2521,7 +2498,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< false
<< true;
QTest::newRow("change 3rd c to c in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 3 << "c"
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
@@ -2529,7 +2506,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< false
<< true;
QTest::newRow("change 1st c to c in (e, c, c, c, a)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QStringList() << "e" << "c" << "c" << "c" << "a")
<< 1 << "c"
<< (QStringList() << "e" << "c" << "c" << "c" << "a")
@@ -2537,7 +2514,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< false
<< true;
QTest::newRow("change 2nd c to c in (e, c, c, c, a)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QStringList() << "e" << "c" << "c" << "c" << "a")
<< 2 << "c"
<< (QStringList() << "e" << "c" << "c" << "c" << "a")
@@ -2545,7 +2522,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< false
<< true;
QTest::newRow("change 3rd c to c in (e, c, c, c, a)")
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< (QStringList() << "e" << "c" << "c" << "c" << "a")
<< 3 << "c"
<< (QStringList() << "e" << "c" << "c" << "c" << "a")
@@ -2553,7 +2530,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< false
<< true;
QTest::newRow("change 1st c to b in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 1 << "b"
<< (QStringList() << "a" << "b" << "c" << "c" << "e")
@@ -2561,7 +2538,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< false
<< false;
QTest::newRow("change 2nd c to b in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 2 << "b"
<< (QStringList() << "a" << "b" << "c" << "c" << "e")
@@ -2569,7 +2546,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< true
<< false;
QTest::newRow("change 3rd c to b in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 3 << "b"
<< (QStringList() << "a" << "b" << "c" << "c" << "e")
@@ -2577,7 +2554,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< true
<< false;
QTest::newRow("change 1st c to d in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 1 << "d"
<< (QStringList() << "a" << "c" << "c" << "d" << "e")
@@ -2585,7 +2562,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< true
<< false;
QTest::newRow("change 2nd c to d in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 2 << "d"
<< (QStringList() << "a" << "c" << "c" << "d" << "e")
@@ -2593,7 +2570,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
<< true
<< false;
QTest::newRow("change 3rd c to d in (a, c, c, c, e)")
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< (QStringList() << "a" << "c" << "c" << "c" << "e")
<< 3 << "d"
<< (QStringList() << "a" << "c" << "c" << "d" << "e")
@@ -2604,47 +2581,38 @@ void tst_QTreeWidget::changeDataWithStableSorting_data()
void tst_QTreeWidget::changeDataWithStableSorting()
{
- QFETCH(int, sortOrder);
- QFETCH(QStringList, initialItems);
+ QFETCH(Qt::SortOrder, sortOrder);
+ QFETCH(const QStringList, initialItems);
QFETCH(int, itemIndex);
- QFETCH(QString, newValue);
- QFETCH(QStringList, expectedItems);
- QFETCH(IntList, expectedRows);
+ QFETCH(const QString, newValue);
+ QFETCH(const QStringList, expectedItems);
+ QFETCH(const IntList, expectedRows);
QFETCH(bool, reorderingExpected);
QFETCH(bool, forceChange);
- class StableItem : public QTreeWidgetItem
- {
- public:
- StableItem(const QStringList &strings) : QTreeWidgetItem(strings, QTreeWidgetItem::UserType) {}
- void forceChangeData() {
- emitDataChanged();
- }
- };
-
QTreeWidget w;
w.setSortingEnabled(true);
- w.sortItems(0, static_cast<Qt::SortOrder>(sortOrder));
- for (int i = 0; i < initialItems.count(); ++i)
- w.addTopLevelItem(new StableItem(QStringList() << initialItems.at(i)));
+ w.sortItems(0, sortOrder);
+ for (const QString &str : initialItems)
+ w.addTopLevelItem(new PublicTreeItem({ str }));
QAbstractItemModel *model = w.model();
- QList<QPersistentModelIndex> persistent;
+ PersistentModelIndexVec persistent;
for (int j = 0; j < model->rowCount(QModelIndex()); ++j)
persistent << model->index(j, 0, QModelIndex());
- QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
- QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged()));
+ QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged);
+ QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged);
- StableItem *item = static_cast<StableItem *>(w.topLevelItem(itemIndex));
+ auto *item = static_cast<PublicTreeItem *>(w.topLevelItem(itemIndex));
item->setText(0, newValue);
if (forceChange)
- item->forceChangeData();
+ item->emitDataChanged();
for (int i = 0; i < expectedItems.count(); ++i) {
QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i));
- for (int j = 0; j < persistent.count(); ++j) {
- if (persistent.at(j).row() == i) // the same toplevel row
- QCOMPARE(persistent.at(j).internalPointer(), (void *)w.topLevelItem(i));
+ for (const QPersistentModelIndex &p : qAsConst(persistent)) {
+ if (p.row() == i) // the same toplevel row
+ QCOMPARE(p.internalPointer(), static_cast<void *>(w.topLevelItem(i)));
}
}
@@ -2657,24 +2625,24 @@ void tst_QTreeWidget::changeDataWithStableSorting()
void tst_QTreeWidget::sizeHint_data()
{
- QTest::addColumn<int>("scrollBarPolicy");
+ QTest::addColumn<Qt::ScrollBarPolicy>("scrollBarPolicy");
QTest::addColumn<QSize>("viewSize");
- QTest::newRow("ScrollBarAlwaysOn") << static_cast<int>(Qt::ScrollBarAlwaysOn) << QSize();
- QTest::newRow("ScrollBarAlwaysOff") << static_cast<int>(Qt::ScrollBarAlwaysOff) << QSize();
+ QTest::newRow("ScrollBarAlwaysOn") << Qt::ScrollBarAlwaysOn << QSize();
+ QTest::newRow("ScrollBarAlwaysOff") << Qt::ScrollBarAlwaysOff << QSize();
// make sure the scrollbars are shown by resizing the view to 40x40
- QTest::newRow("ScrollBarAsNeeded (40x40)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(40, 40);
- QTest::newRow("ScrollBarAsNeeded (1000x1000)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(1000, 1000);
+ QTest::newRow("ScrollBarAsNeeded (40x40)") << Qt::ScrollBarAsNeeded << QSize(40, 40);
+ QTest::newRow("ScrollBarAsNeeded (1000x1000)") << Qt::ScrollBarAsNeeded << QSize(1000, 1000);
}
void tst_QTreeWidget::sizeHint()
{
- QFETCH(int, scrollBarPolicy);
+ QFETCH(Qt::ScrollBarPolicy, scrollBarPolicy);
QFETCH(QSize, viewSize);
QTreeWidget view;
view.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
- view.setVerticalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
- view.setHorizontalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
+ view.setVerticalScrollBarPolicy(scrollBarPolicy);
+ view.setHorizontalScrollBarPolicy(scrollBarPolicy);
view.setColumnCount(2);
for (int i = 0 ; i < view.columnCount(); ++i)
view.addTopLevelItem(new QTreeWidgetItem(QStringList{"foo","bar"}));
@@ -2726,36 +2694,36 @@ void tst_QTreeWidget::itemOperatorLessThan()
void tst_QTreeWidget::sortedIndexOfChild_data()
{
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<QStringList>("itemTexts");
- QTest::addColumn<QList<int> >("expectedIndexes");
+ QTest::addColumn<IntList>("expectedIndexes");
QTest::newRow("three ascending")
- << int(Qt::AscendingOrder)
- << (QStringList() << "A" << "B" << "C")
- << (QList<int>() << 0 << 1 << 2);
+ << Qt::AscendingOrder
+ << (QStringList{"A", "B", "C"})
+ << (IntList{0, 1, 2});
QTest::newRow("three descending")
- << int(Qt::DescendingOrder)
- << (QStringList() << "A" << "B" << "C")
- << (QList<int>() << 2 << 1 << 0);
+ << Qt::DescendingOrder
+ << (QStringList{"A", "B", "C"})
+ << (IntList{2, 1, 0});
}
void tst_QTreeWidget::sortedIndexOfChild()
{
- QFETCH(int, sortOrder);
- QFETCH(QStringList, itemTexts);
- QFETCH(QList<int>, expectedIndexes);
+ QFETCH(Qt::SortOrder, sortOrder);
+ QFETCH(const QStringList, itemTexts);
+ QFETCH(const IntList, expectedIndexes);
QTreeWidget tw;
- QList<QTreeWidgetItem*> itms;
- QTreeWidgetItem *top = new QTreeWidgetItem(&tw, QStringList() << "top");
+ QVector<QTreeWidgetItem *> itms;
+ auto *top = new QTreeWidgetItem(&tw, {"top"});
- for (int i = 0; i < itemTexts.count(); ++i)
- itms << new QTreeWidgetItem(top, QStringList() << itemTexts.at(i));
+ for (const QString &str : itemTexts)
+ itms << new QTreeWidgetItem(top, {str});
- tw.sortItems(0, (Qt::SortOrder)sortOrder);
+ tw.sortItems(0, sortOrder);
tw.expandAll();
QCOMPARE(itms.count(), expectedIndexes.count());
@@ -2773,8 +2741,8 @@ void tst_QTreeWidget::expandAndCallapse()
for (int j = 0; j < 10; ++j)
new QTreeWidgetItem(p, QStringList(QString::number(j)));
}
- QSignalSpy spy0(&tw, SIGNAL(itemExpanded(QTreeWidgetItem*)));
- QSignalSpy spy1(&tw, SIGNAL(itemCollapsed(QTreeWidgetItem*)));
+ QSignalSpy spy0(&tw, &QTreeWidget::itemExpanded);
+ QSignalSpy spy1(&tw, &QTreeWidget::itemCollapsed);
tw.expandItem(p);
@@ -2909,20 +2877,12 @@ void tst_QTreeWidget::removeSelectedItem()
QCOMPARE(selModel->isSelected(w->model()->index(0,0)), false);
}
-class AnotherTreeWidget : public QTreeWidget
-{
- Q_OBJECT
-public:
- AnotherTreeWidget(QWidget *parent = 0) : QTreeWidget(parent) {}
- void deleteCurrent() { if (currentItem()) delete currentItem(); }
-};
-
void tst_QTreeWidget::removeCurrentItem()
{
- AnotherTreeWidget widget;
- QObject::connect(widget.selectionModel(),
- SIGNAL(currentChanged(QModelIndex,QModelIndex)),
- &widget, SLOT(clear()));
+ PublicTreeWidget widget;
+ connect(widget.selectionModel(),
+ &QItemSelectionModel::currentChanged,
+ &widget, &PublicTreeWidget::clear);
QTreeWidgetItem *item = new QTreeWidgetItem(&widget);
widget.setCurrentItem(item);
widget.deleteCurrent();
@@ -2930,9 +2890,9 @@ void tst_QTreeWidget::removeCurrentItem()
void tst_QTreeWidget::removeCurrentItem_task186451()
{
- AnotherTreeWidget widget;
- QTreeWidgetItem *item = new QTreeWidgetItem(&widget, QStringList() << "1");
- QTreeWidgetItem *item2 = new QTreeWidgetItem(&widget, QStringList() << "2");
+ PublicTreeWidget widget;
+ QTreeWidgetItem *item = new QTreeWidgetItem(&widget, {"1"});
+ QTreeWidgetItem *item2 = new QTreeWidgetItem(&widget, {"2"});
widget.setCurrentItem(item);
widget.deleteCurrent();
@@ -2940,19 +2900,6 @@ void tst_QTreeWidget::removeCurrentItem_task186451()
QCOMPARE(item2, widget.currentItem());
}
-
-class TreeWidget : QTreeWidget {
-
-public:
- QModelIndex indexFromItem(QTreeWidgetItem *item, int column = 0) const {
- return QTreeWidget::indexFromItem(item, column);
- }
- QTreeWidgetItem *itemFromIndex(const QModelIndex &index) const {
- return QTreeWidget::itemFromIndex(index);
- }
-};
-
-
void tst_QTreeWidget::randomExpand()
{
QTreeWidget tree;
@@ -2970,9 +2917,8 @@ void tst_QTreeWidget::randomExpand()
\- item4
*/
- QTreeWidgetItem *newItem1 = 0;
for (int i = 0; i < 100; i++) {
- newItem1 = new QTreeWidgetItem(&tree, item1);
+ auto newItem1 = new QTreeWidgetItem(&tree, item1);
newItem1->setExpanded(true);
QCOMPARE(newItem1->isExpanded(), true);
@@ -2982,35 +2928,34 @@ void tst_QTreeWidget::randomExpand()
QCOMPARE(newItem1->isExpanded(), true);
}
-
}
void tst_QTreeWidget::crashTest()
{
- QTreeWidget *tree = new QTreeWidget();
- tree->setColumnCount(1);
- tree->show();
+ QTreeWidget tree;
+ tree.setColumnCount(1);
+ tree.show();
- QTreeWidgetItem *item1 = new QTreeWidgetItem(tree);
+ QTreeWidgetItem *item1 = new QTreeWidgetItem(&tree);
item1->setText(0, "item1");
item1->setExpanded(true);
QTreeWidgetItem *item2 = new QTreeWidgetItem(item1);
item2->setText(0, "item2");
- QTreeWidgetItem *item3 = new QTreeWidgetItem(tree, item1);
+ QTreeWidgetItem *item3 = new QTreeWidgetItem(&tree, item1);
item3->setText(0, "item3");
item3->setExpanded(true);
QTreeWidgetItem *item4 = new QTreeWidgetItem(item3);
item4->setText(0, "item4");
- QTreeWidgetItem *item5 = new QTreeWidgetItem(tree, item3);
+ QTreeWidgetItem *item5 = new QTreeWidgetItem(&tree, item3);
item5->setText(0, "item5");
item5->setExpanded(true);
QTreeWidgetItem *item6 = new QTreeWidgetItem(item5);
item6->setText(0, "item6");
for (int i = 0; i < 1000; i++) {
- QTreeWidgetItem *newItem1 = new QTreeWidgetItem(tree, item1);
+ QTreeWidgetItem *newItem1 = new QTreeWidgetItem(&tree, item1);
newItem1->setText(0, "newItem");
QTreeWidgetItem *newItem2 = new QTreeWidgetItem(newItem1);
newItem2->setText(0, "subItem1");
@@ -3019,23 +2964,23 @@ void tst_QTreeWidget::crashTest()
delete item3;
item3 = newItem1;
}
- QApplication::instance()->processEvents();
-
- delete tree;
+ QCoreApplication::processEvents();
}
class CrashWidget : public QTreeWidget
{
public:
- CrashWidget(QWidget *parent = 0) : QTreeWidget(parent), i(0) {
+ CrashWidget(QWidget *parent = nullptr) : QTreeWidget(parent)
+ {
setSortingEnabled(true);
timerId = startTimer(10);
}
- int i;
+ int i = 0;
protected:
- void timerEvent(QTimerEvent * event) {
+ void timerEvent(QTimerEvent * event) override
+ {
if (event->timerId() == timerId) {
- QTreeWidgetItem *newItem = new QTreeWidgetItem((QStringList() << QString::number(i++)));
+ auto newItem = new QTreeWidgetItem({QString::number(i++)});
m_list.append(newItem);
insertTopLevelItem(0, newItem);
while (m_list.count() > 10)
@@ -3045,7 +2990,7 @@ protected:
}
private:
int timerId;
- QList<QTreeWidgetItem*> m_list;
+ QVector<QTreeWidgetItem*> m_list;
};
void tst_QTreeWidget::sortAndSelect()
@@ -3068,12 +3013,13 @@ void tst_QTreeWidget::defaultRowSizes()
const QScopedPointer<QTreeWidget> tw(new QTreeWidget);
tw->setIconSize(QSize(50, 50));
tw->setColumnCount(6);
- for (int i=0; i<10; ++i) {
+ for (int i = 0; i < 10; ++i) {
auto it = new QTreeWidgetItem(tw.data());
- for (int j=0; j<tw->columnCount() - 1; ++j) {
+ for (int j = 0; j < tw->columnCount() - 1; ++j)
it->setText(j, "This is a test");
- }
- QPixmap icon = tw->style()->standardPixmap((QStyle::StandardPixmap)(i + QStyle::SP_TitleBarMenuButton));
+ auto sp = static_cast<QStyle::StandardPixmap>(i + QStyle::SP_TitleBarMenuButton);
+ QPixmap icon = tw->style()->standardPixmap(sp);
+
if (icon.isNull())
QSKIP("No pixmap found on current style, skipping this test.");
it->setIcon(tw->columnCount() - 1,
@@ -3089,8 +3035,8 @@ void tst_QTreeWidget::defaultRowSizes()
void tst_QTreeWidget::task191552_rtl()
{
- Qt::LayoutDirection oldDir = qApp->layoutDirection();
- qApp->setLayoutDirection(Qt::RightToLeft);
+ Qt::LayoutDirection oldDir = QGuiApplication::layoutDirection();
+ QGuiApplication::setLayoutDirection(Qt::RightToLeft);
QTreeWidget tw;
tw.setColumnCount(1);
@@ -3111,7 +3057,7 @@ void tst_QTreeWidget::task191552_rtl()
QTest::mouseClick(tw.viewport(), Qt::LeftButton, Qt::NoModifier, checkRect.center());
QCOMPARE(item->checkState(0), Qt::Unchecked);
- qApp->setLayoutDirection(oldDir);
+ QGuiApplication::setLayoutDirection(oldDir);
}
void tst_QTreeWidget::task203673_selection()
@@ -3210,7 +3156,7 @@ void tst_QTreeWidget::task253109_itemHeight()
QTreeWidgetItem item(&treeWidget);
class MyWidget : public QWidget
{
- virtual QSize sizeHint() const { return QSize(200,100); }
+ QSize sizeHint() const override { return QSize(200, 100); }
} w;
treeWidget.setItemWidget(&item, 0, &w);
@@ -3230,24 +3176,23 @@ void tst_QTreeWidget::task206367_duplication()
treeWidget.setHeaderHidden(true);
treeWidget.setSortingEnabled(true);
- QTreeWidgetItem* rootItem = new QTreeWidgetItem( &treeWidget, QStringList("root") );
+ QTreeWidgetItem* rootItem = new QTreeWidgetItem(&treeWidget, QStringList("root"));
for (int nFile = 0; nFile < 2; nFile++ ) {
- QTreeWidgetItem* itemFile = new QTreeWidgetItem(rootItem, QStringList(QString::number(nFile)));
+ QTreeWidgetItem* itemFile = new QTreeWidgetItem(rootItem, {QString::number(nFile)});
for (int nRecord = 0; nRecord < 2; nRecord++)
- new QTreeWidgetItem(itemFile , QStringList(QString::number(nRecord)));
+ new QTreeWidgetItem(itemFile, {QString::number(nRecord)});
itemFile->setExpanded(true);
}
rootItem->setExpanded(true);
//there should be enough room for 2x2 items. If there is a scrollbar, it means the items are duplicated
QTRY_VERIFY(!treeWidget.verticalScrollBar()->isVisible());
-
}
void tst_QTreeWidget::itemSelectionChanged()
{
QVERIFY(testWidget);
- if(testWidget->topLevelItem(0))
+ if (testWidget->topLevelItem(0))
QVERIFY(testWidget->topLevelItem(0)->isSelected());
}
@@ -3255,14 +3200,18 @@ void tst_QTreeWidget::selectionOrder()
{
testWidget->setColumnCount(1);
QList<QTreeWidgetItem *> items;
- for (int i = 0; i < 10; ++i)
- items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QLatin1String("item: ") + QString::number(i))));
+ for (int i = 0; i < 10; ++i) {
+ items.append(new QTreeWidgetItem(static_cast<QTreeWidget *>(nullptr),
+ {QStringLiteral("item: %1").arg(i)}));
+ }
testWidget->insertTopLevelItems(0, items);
- QModelIndex idx = testWidget->indexFromItem(items[0]);
- connect(testWidget, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged()));
+ QModelIndex idx = testWidget->indexFromItem(items.at(0));
+ connect(testWidget, &QTreeWidget::itemSelectionChanged,
+ this, &tst_QTreeWidget::itemSelectionChanged);
testWidget->selectionModel()->select(idx, QItemSelectionModel::SelectCurrent);
- disconnect(testWidget, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged()));
+ disconnect(testWidget, &QTreeWidget::itemSelectionChanged,
+ this, &tst_QTreeWidget::itemSelectionChanged);
}
void tst_QTreeWidget::setSelectionModel()
@@ -3271,7 +3220,7 @@ void tst_QTreeWidget::setSelectionModel()
for(int i = 0; i < 3; ++i)
new QTreeWidgetItem(&tree, QStringList(QString::number(i)));
QItemSelectionModel selection(tree.model());
- selection.select(tree.model()->index(1,0), QItemSelectionModel::Select);
+ selection.select(tree.model()->index(1, 0), QItemSelectionModel::Select);
tree.setSelectionModel(&selection);
QCOMPARE(tree.topLevelItem(1)->isSelected(), true);
}
@@ -3301,9 +3250,9 @@ void tst_QTreeWidget::task217309()
void tst_QTreeWidget::nonEditableTristate()
{
// A tree with checkable items, the parent is tristate
- QTreeWidget *tree = new QTreeWidget;
- QTreeWidgetItem *item = new QTreeWidgetItem();
- tree->insertTopLevelItem(0, item);
+ QTreeWidget tree;
+ QTreeWidgetItem *item = new QTreeWidgetItem;
+ tree.insertTopLevelItem(0, item);
item->setFlags(item->flags() | Qt::ItemIsAutoTristate);
item->setCheckState(0, Qt::Unchecked);
QTreeWidgetItem *subitem1 = new QTreeWidgetItem(item);
@@ -3311,53 +3260,46 @@ void tst_QTreeWidget::nonEditableTristate()
QTreeWidgetItem *subitem2 = new QTreeWidgetItem(item);
subitem2->setCheckState(0, Qt::Unchecked);
QCOMPARE(int(item->checkState(0)), int(Qt::Unchecked));
- tree->show();
+ tree.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&tree));
// Test clicking on the parent item, it should become Checked (not PartiallyChecked)
QStyleOptionViewItem option;
- option.rect = tree->visualRect(tree->model()->index(0, 0));
+ option.rect = tree.visualRect(tree.model()->index(0, 0));
option.state |= QStyle::State_Enabled;
option.features |= QStyleOptionViewItem::HasCheckIndicator | QStyleOptionViewItem::HasDisplay;
option.checkState = item->checkState(0);
- const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
- QPoint pos = qApp->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0);
- QTest::mouseClick(tree->viewport(), Qt::LeftButton, Qt::NoModifier, pos);
- QCOMPARE(int(item->checkState(0)), int(Qt::Checked));
+ auto appStyle = QApplication::style();
+ const int checkMargin = appStyle->pixelMetric(
+ QStyle::PM_FocusFrameHMargin, nullptr, nullptr) + 1;
+ QPoint pos = appStyle->subElementRect(
+ QStyle::SE_ItemViewItemCheckIndicator, &option, nullptr).center();
+ pos.rx() += checkMargin;
+ QTest::mouseClick(tree.viewport(), Qt::LeftButton, Qt::NoModifier, pos);
+ QCOMPARE(item->checkState(0), Qt::Checked);
// Click again, it should become Unchecked.
- QTest::mouseClick(tree->viewport(), Qt::LeftButton, Qt::NoModifier, pos);
- QCOMPARE(int(item->checkState(0)), int(Qt::Unchecked));
-
- delete tree;
+ QTest::mouseClick(tree.viewport(), Qt::LeftButton, Qt::NoModifier, pos);
+ QCOMPARE(item->checkState(0), Qt::Unchecked);
}
-class TreeWidgetItem : public QTreeWidgetItem
-{
-
-public:
- void _emitDataChanged() { emitDataChanged(); }
-
-};
-
void tst_QTreeWidget::emitDataChanged()
{
-
- QTreeWidget *tree = new QTreeWidget;
- QSignalSpy spy(tree, SIGNAL(itemChanged(QTreeWidgetItem*,int)));
- TreeWidgetItem *item = new TreeWidgetItem();
- tree->insertTopLevelItem(0, item);
- item->_emitDataChanged();
+ QTreeWidget tree;
+ QSignalSpy spy(&tree, &QTreeWidget::itemChanged);
+ auto item = new PublicTreeItem;
+ tree.insertTopLevelItem(0, item);
+ item->emitDataChanged();
QCOMPARE(spy.count(), 1);
-
}
void tst_QTreeWidget::setCurrentItemExpandsParent()
{
QTreeWidget w;
w.setColumnCount(1);
- QTreeWidgetItem *i1 = new QTreeWidgetItem(&w, QStringList() << "parent");
- QTreeWidgetItem *i2 = new QTreeWidgetItem(i1, QStringList() << "child");
+ QTreeWidgetItem *i1 = new QTreeWidgetItem(&w, {"parent"});
+ QTreeWidgetItem *i2 = new QTreeWidgetItem(i1, {"child"});
QVERIFY(!i2->isExpanded());
QVERIFY(!w.currentItem());
w.setCurrentItem(i2);
@@ -3373,13 +3315,13 @@ void tst_QTreeWidget::task239150_editorWidth()
QStyleOptionFrame opt;
opt.init(&tree);
const int minWidth = tree.style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(0, 0).
- expandedTo(QApplication::globalStrut()), 0).width();
+ expandedTo(QApplication::globalStrut()), nullptr).width();
{
QTreeWidgetItem item;
item.setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
tree.addTopLevelItem(&item);
- QVERIFY(tree.itemWidget(&item, 0) == 0);
+ QVERIFY(tree.itemWidget(&item, 0) == nullptr);
tree.editItem(&item);
QVERIFY(tree.itemWidget(&item, 0));
QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth);
@@ -3391,7 +3333,7 @@ void tst_QTreeWidget::task239150_editorWidth()
item.setText(0, "foooooooooooooooooooooooo");
item.setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
tree.addTopLevelItem(&item);
- QVERIFY(tree.itemWidget(&item, 0) == 0);
+ QVERIFY(tree.itemWidget(&item, 0) == nullptr);
tree.editItem(&item);
QVERIFY(tree.itemWidget(&item, 0));
QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth + tree.fontMetrics().horizontalAdvance(item.text(0)));
@@ -3408,23 +3350,21 @@ void tst_QTreeWidget::setTextUpdate()
class MyItemDelegate : public QStyledItemDelegate
{
public:
- MyItemDelegate() : numPaints(0) { }
- void paint(QPainter *painter,
- const QStyleOptionViewItem &option, const QModelIndex &index) const
+ using QStyledItemDelegate::QStyledItemDelegate;
+ void paint(QPainter *painter, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override
{
numPaints++;
QStyledItemDelegate::paint(painter, option, index);
}
- mutable int numPaints;
+ mutable int numPaints = 0;
} delegate;
treeWidget.setItemDelegate(&delegate);
treeWidget.show();
QVERIFY(QTest::qWaitForWindowExposed(&treeWidget));
- QStringList strList;
- strList << "variable1" << "0";
- QTreeWidgetItem *item = new QTreeWidgetItem(strList);
+ QTreeWidgetItem *item = new QTreeWidgetItem({ "variable1", "0" });
treeWidget.insertTopLevelItem(0, item);
QTRY_VERIFY(delegate.numPaints > 0);
delegate.numPaints = 0;
@@ -3435,7 +3375,7 @@ void tst_QTreeWidget::setTextUpdate()
void tst_QTreeWidget::taskQTBUG2844_visualItemRect()
{
- CustomTreeWidget tree;
+ PublicTreeWidget tree;
tree.resize(150, 100);
tree.setColumnCount(3);
QTreeWidgetItem item(&tree);
@@ -3457,15 +3397,17 @@ void tst_QTreeWidget::setChildIndicatorPolicy()
class MyItemDelegate : public QStyledItemDelegate
{
public:
- MyItemDelegate() : numPaints(0), expectChildren(false) { }
- void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+ using QStyledItemDelegate::QStyledItemDelegate;
+ void paint(QPainter *painter,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override
{
numPaints++;
QCOMPARE(!(option.state & QStyle::State_Children), !expectChildren);
QStyledItemDelegate::paint(painter, option, index);
}
- mutable int numPaints;
- bool expectChildren;
+ mutable int numPaints = 0;
+ bool expectChildren = false;
} delegate;
treeWidget.setItemDelegate(&delegate);
@@ -3503,19 +3445,15 @@ void tst_QTreeWidget::setChildIndicatorPolicy()
// The test passes simply if it doesn't crash.
void tst_QTreeWidget::taskQTBUG_34717_collapseAtBottom()
{
- struct PublicTreeWidget: public QTreeWidget
- {
- inline int sizeHintForColumn(int column) const { return QTreeWidget::sizeHintForColumn(column); }
- };
PublicTreeWidget treeWidget;
treeWidget.header()->setSectionResizeMode(QHeaderView::ResizeToContents);
treeWidget.setColumnCount(2);
- QTreeWidgetItem *mainItem = new QTreeWidgetItem(&treeWidget, QStringList() << "Root");
+ QTreeWidgetItem *mainItem = new QTreeWidgetItem(&treeWidget, { "Root" });
for (int i = 0; i < 200; ++i) {
- QTreeWidgetItem *item = new QTreeWidgetItem(mainItem, QStringList(QString("Item")));
- new QTreeWidgetItem(item, QStringList() << "Child" << "1");
- new QTreeWidgetItem(item, QStringList() << "Child" << "2");
- new QTreeWidgetItem(item, QStringList() << "Child" << "3");
+ QTreeWidgetItem *item = new QTreeWidgetItem(mainItem, { "Item" });
+ new QTreeWidgetItem(item, { "Child", "1" });
+ new QTreeWidgetItem(item, { "Child", "2" });
+ new QTreeWidgetItem(item, { "Child", "3" });
}
treeWidget.show();
treeWidget.expandAll();
@@ -3545,11 +3483,8 @@ void tst_QTreeWidget::task20345_sortChildren()
tw.setSortingEnabled(true);
tw.show();
- QTreeWidgetItem *rootItem = 0;
- QTreeWidgetItem *childItem = 0;
-
- rootItem = new QTreeWidgetItem(&tw, QStringList("a"));
- childItem = new QTreeWidgetItem(rootItem);
+ auto rootItem = new QTreeWidgetItem(&tw, QStringList("a"));
+ auto childItem = new QTreeWidgetItem(rootItem);
childItem->setText(1, "3");
childItem = new QTreeWidgetItem(rootItem);
childItem->setText(1, "1");
@@ -3558,10 +3493,10 @@ void tst_QTreeWidget::task20345_sortChildren()
tw.setCurrentItem(tw.topLevelItem(0));
- QTreeWidgetItem * curItem = tw.currentItem();
+ QTreeWidgetItem *curItem = tw.currentItem();
int childCount = curItem->childCount() + 1;
- QTreeWidgetItem * newItem = new QTreeWidgetItem(curItem);
+ QTreeWidgetItem *newItem = new QTreeWidgetItem(curItem);
newItem->setText(1, QString::number(childCount));
rootItem->sortChildren(1, Qt::AscendingOrder);
QVERIFY(1);
@@ -3569,7 +3504,7 @@ void tst_QTreeWidget::task20345_sortChildren()
void tst_QTreeWidget::getMimeDataWithInvalidItem()
{
- CustomTreeWidget w;
+ PublicTreeWidget w;
QTest::ignoreMessage(QtWarningMsg, "QTreeWidget::mimeData: Null-item passed");
QMimeData *md = w.mimeData(QList<QTreeWidgetItem*>() << nullptr);
QVERIFY(!md);
diff --git a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp
index 76ca148d3f..68d149fc6e 100644
--- a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp
@@ -27,20 +27,19 @@
****************************************************************************/
-#include <QtTest/QtTest>
+#include <QTreeWidget>
+#include <QTreeWidgetItemIterator>
+#include <QTest>
-#include <qtreewidget.h>
-#include <qtreewidgetitemiterator.h>
-#include <qapplication.h>
-#include <qeventloop.h>
-#include <qdebug.h>
+Q_DECLARE_METATYPE(QTreeWidgetItemIterator::IteratorFlag)
+Q_DECLARE_METATYPE(QTreeWidgetItemIterator::IteratorFlags)
class tst_QTreeWidgetItemIterator : public QObject
{
Q_OBJECT
public:
- tst_QTreeWidgetItemIterator();
+ using QObject::QObject;
private slots:
void initTestCase();
@@ -65,13 +64,9 @@ private slots:
void initializeIterator();
void sortingEnabled();
private:
- QTreeWidget *testWidget;
+ QTreeWidget *testWidget = nullptr;
};
-tst_QTreeWidgetItemIterator::tst_QTreeWidgetItemIterator(): testWidget(0)
-{
-}
-
void tst_QTreeWidgetItemIterator::initTestCase()
{
testWidget = new QTreeWidget();
@@ -90,7 +85,7 @@ void tst_QTreeWidgetItemIterator::initTestCase()
* |Qt::ItemIsDropEnabled
*
*/
- for (int i=0; i <= 16; ++i) {
+ for (int i = 0; i <= 16; ++i) {
QTreeWidgetItem *top = new QTreeWidgetItem(testWidget);
const QString topS = QLatin1String("top") + QString::number(i);
top->setText(0, topS);
@@ -111,9 +106,7 @@ void tst_QTreeWidgetItemIterator::initTestCase()
case 9: top->setFlags(Qt::ItemIsEnabled);break;
case 10: top->setFlags(Qt::ItemIsEnabled);break;
- case 11:
- top->setFlags(0);
- break;
+ case 11: top->setFlags({});break;
case 12: top->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);break;
case 13: top->setFlags(Qt::ItemIsEnabled);break;
@@ -142,7 +135,7 @@ void tst_QTreeWidgetItemIterator::initTestCase()
case 9: child->setFlags(Qt::ItemIsEnabled);break;
case 10: child->setFlags(Qt::ItemIsEnabled);break;
- case 11: child->setFlags(0);break;
+ case 11: child->setFlags({});break;
case 12: child->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);break;
case 13: child->setFlags(Qt::ItemIsEnabled);break;
@@ -188,10 +181,10 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
NotEditable = 0x00020000
*/
QTest::addColumn<int>("start");
- QTest::addColumn<int>("iteratorflags");
+ QTest::addColumn<QTreeWidgetItemIterator::IteratorFlags>("iteratorflags");
QTest::addColumn<QStringList>("matches");
- QTest::newRow("Match all") << 0 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Match all") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::All)
<< (QStringList()
<< "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
<< "top0,child4" << "top0,child5" << "top0,child6" << "top0,child7"
@@ -279,7 +272,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top16,child12" << "top16,child13" << "top16,child14" << "top16,child15"
<< "top16,child16");
- QTest::newRow("Match hidden") << 0 << (int)QTreeWidgetItemIterator::Hidden
+ QTest::newRow("Match hidden") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Hidden)
<< (QStringList()
<< "top0" << "top0,child0" // fails due to hidden row
<< "top1,child0"
@@ -299,7 +292,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top15,child0"
<< "top16,child0");
- QTest::newRow("Match not hidden") << 0 << (int)QTreeWidgetItemIterator::NotHidden
+ QTest::newRow("Match not hidden") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::NotHidden)
<< (QStringList()
<< "top0,child1" << "top0,child2" << "top0,child3"
<< "top0,child4" << "top0,child5" << "top0,child6" << "top0,child7"
@@ -387,7 +380,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top16,child12" << "top16,child13" << "top16,child14" << "top16,child15"
<< "top16,child16");
- QTest::newRow("Match selected") << 0 << (int)QTreeWidgetItemIterator::Selected
+ QTest::newRow("Match selected") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Selected)
<< (QStringList()
<< "top0,child2"
<< "top1,child2"
@@ -407,7 +400,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top15,child2"
<< "top16,child2");
- QTest::newRow("Match selectable") << 0 << (int)QTreeWidgetItemIterator::Selectable
+ QTest::newRow("Match selectable") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Selectable)
<< (QStringList()
<< "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
<< "top0,child4"
@@ -479,7 +472,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top16,child16");
- QTest::newRow("Match DragEnabled") << 0 << (int)QTreeWidgetItemIterator::DragEnabled
+ QTest::newRow("Match DragEnabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::DragEnabled)
<< (QStringList()
<< "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
<< "top0,child6"
@@ -550,7 +543,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top16,child14" << "top16,child15"
<< "top16,child16");
- QTest::newRow("Match DragDisabled") << 0 << (int)QTreeWidgetItemIterator::DragDisabled
+ QTest::newRow("Match DragDisabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::DragDisabled)
<< (QStringList()
/* top0 */
@@ -623,7 +616,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top16,child13" );
- QTest::newRow("Match DropEnabled") << 0 << (int)QTreeWidgetItemIterator::DropEnabled
+ QTest::newRow("Match DropEnabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::DropEnabled)
<< (QStringList()
<< "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
<< "top0,child8"
@@ -694,12 +687,12 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top16,child14" << "top16,child15"
<< "top16,child16");
- QTest::newRow("Match HasChildren") << 0 << (int)QTreeWidgetItemIterator::HasChildren
+ QTest::newRow("Match HasChildren") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::HasChildren)
<< (QStringList() << "top0" << "top1" << "top2" << "top3" << "top4" << "top5"
<< "top6" << "top7" << "top8" << "top9" << "top10" << "top11" << "top12"
<< "top13" << "top14" << "top15" << "top16");
- QTest::newRow("Match Checked") << 0 << (int)QTreeWidgetItemIterator::Checked
+ QTest::newRow("Match Checked") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Checked)
<< (QStringList()
<< "top0,child14" << "top0,child16"
<< "top1,child14" << "top1,child16"
@@ -721,7 +714,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top16"
<< "top16,child14" << "top16,child16");
- QTest::newRow("Match NotChecked") << 0 << (int)QTreeWidgetItemIterator::NotChecked
+ QTest::newRow("Match NotChecked") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::NotChecked)
<< (QStringList()
<< "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
<< "top0,child4" << "top0,child5" << "top0,child6" << "top0,child7"
@@ -810,7 +803,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
- QTest::newRow("Match Disabled") << 0 << (int)QTreeWidgetItemIterator::Disabled
+ QTest::newRow("Match Disabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Disabled)
<< (QStringList()
<< "top0,child11"
<< "top1,child11"
@@ -848,7 +841,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top15,child11"
<< "top16,child11");
- QTest::newRow("Match Editable") << 0 << (int)QTreeWidgetItemIterator::Editable
+ QTest::newRow("Match Editable") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Editable)
<< (QStringList()
<< "top0,child12"
<< "top1,child12"
@@ -869,34 +862,34 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data()
<< "top15,child12"
<< "top16,child12");
- QTest::newRow("Match mutually exclusive Hidden|NotHidden") << 0 << (int)(QTreeWidgetItemIterator::Hidden|QTreeWidgetItemIterator::NotHidden)
+ QTest::newRow("Match mutually exclusive Hidden|NotHidden") << 0 << (QTreeWidgetItemIterator::Hidden|QTreeWidgetItemIterator::NotHidden)
<< QStringList();
- QTest::newRow("Match mutually exclusive Selected|Unselected") << 0 << (int)(QTreeWidgetItemIterator::Selected|QTreeWidgetItemIterator::Unselected)
+ QTest::newRow("Match mutually exclusive Selected|Unselected") << 0 << (QTreeWidgetItemIterator::Selected|QTreeWidgetItemIterator::Unselected)
<< QStringList();
- QTest::newRow("Match mutually exclusive Selectable|NotSelectable") << 0 << (int)(QTreeWidgetItemIterator::Selectable|QTreeWidgetItemIterator::NotSelectable)
+ QTest::newRow("Match mutually exclusive Selectable|NotSelectable") << 0 << (QTreeWidgetItemIterator::Selectable|QTreeWidgetItemIterator::NotSelectable)
<< QStringList();
- QTest::newRow("Match mutually exclusive DragEnabled|DragDisabled") << 0 << (int)(QTreeWidgetItemIterator::DragEnabled|QTreeWidgetItemIterator::DragDisabled)
+ QTest::newRow("Match mutually exclusive DragEnabled|DragDisabled") << 0 << (QTreeWidgetItemIterator::DragEnabled|QTreeWidgetItemIterator::DragDisabled)
<< QStringList();
- QTest::newRow("Match mutually exclusive DropEnabled|DropDisabled") << 0 << (int)(QTreeWidgetItemIterator::DropEnabled|QTreeWidgetItemIterator::DropDisabled)
+ QTest::newRow("Match mutually exclusive DropEnabled|DropDisabled") << 0 << (QTreeWidgetItemIterator::DropEnabled|QTreeWidgetItemIterator::DropDisabled)
<< QStringList();
- QTest::newRow("Match mutually exclusive HasChildren|NoChildren") << 0 << (int)(QTreeWidgetItemIterator::HasChildren|QTreeWidgetItemIterator::NoChildren)
+ QTest::newRow("Match mutually exclusive HasChildren|NoChildren") << 0 << (QTreeWidgetItemIterator::HasChildren|QTreeWidgetItemIterator::NoChildren)
<< QStringList();
- QTest::newRow("Match mutually exclusive Checked|NotChecked") << 0 << (int)(QTreeWidgetItemIterator::Checked|QTreeWidgetItemIterator::NotChecked)
+ QTest::newRow("Match mutually exclusive Checked|NotChecked") << 0 << (QTreeWidgetItemIterator::Checked|QTreeWidgetItemIterator::NotChecked)
<< QStringList();
- QTest::newRow("Match mutually exclusive Disabled|Enabled") << 0 << (int)(QTreeWidgetItemIterator::Disabled|QTreeWidgetItemIterator::Enabled)
+ QTest::newRow("Match mutually exclusive Disabled|Enabled") << 0 << (QTreeWidgetItemIterator::Disabled|QTreeWidgetItemIterator::Enabled)
<< QStringList();
- QTest::newRow("Match mutually exclusive Editable|NotEditable") << 0 << (int)(QTreeWidgetItemIterator::Editable|QTreeWidgetItemIterator::NotEditable)
+ QTest::newRow("Match mutually exclusive Editable|NotEditable") << 0 << (QTreeWidgetItemIterator::Editable|QTreeWidgetItemIterator::NotEditable)
<< QStringList();
}
void tst_QTreeWidgetItemIterator::iteratorflags()
{
QFETCH(int, start);
- QFETCH(int, iteratorflags);
+ QFETCH(QTreeWidgetItemIterator::IteratorFlags, iteratorflags);
QFETCH(QStringList, matches);
- QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::IteratorFlags(iteratorflags));
- it+=start;
+ QTreeWidgetItemIterator it(testWidget, iteratorflags);
+ it += start;
int iMatch = 0;
while (*it && iMatch < matches.count()) {
QTreeWidgetItem *item = *it;
@@ -953,26 +946,26 @@ void tst_QTreeWidgetItemIterator::plus_eq_data()
{
QTest::addColumn<int>("start");
QTest::addColumn<int>("addition");
- QTest::addColumn<int>("iteratorflags");
+ QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>("iteratorflags");
QTest::addColumn<QString>("expecteditem");
- QTest::newRow("+=0") << 0 << 0 << (int)QTreeWidgetItemIterator::All << QString("top0");
- QTest::newRow("+=1") << 0 << 1 << (int)QTreeWidgetItemIterator::All << QString("top0,child0");
- QTest::newRow("+=2") << 0 << 2 << (int)QTreeWidgetItemIterator::All << QString("top0,child1");
- QTest::newRow("+=(-1)") << 1 << -1 << (int)QTreeWidgetItemIterator::All << QString("top0");
- QTest::newRow("+=(-2)") << 3 << -2 << (int)QTreeWidgetItemIterator::All << QString("top0,child0");
+ QTest::newRow("+=0") << 0 << 0 << QTreeWidgetItemIterator::All << QString("top0");
+ QTest::newRow("+=1") << 0 << 1 << QTreeWidgetItemIterator::All << QString("top0,child0");
+ QTest::newRow("+=2") << 0 << 2 << QTreeWidgetItemIterator::All << QString("top0,child1");
+ QTest::newRow("+=(-1)") << 1 << -1 << QTreeWidgetItemIterator::All << QString("top0");
+ QTest::newRow("+=(-2)") << 3 << -2 << QTreeWidgetItemIterator::All << QString("top0,child0");
}
void tst_QTreeWidgetItemIterator::plus_eq()
{
QFETCH(int, start);
QFETCH(int, addition);
- QFETCH(int, iteratorflags);
+ QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags);
QFETCH(QString, expecteditem);
- QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::IteratorFlags(iteratorflags));
- it+=start;
- it+=addition;
+ QTreeWidgetItemIterator it(testWidget, iteratorflags);
+ it += start;
+ it += addition;
QTreeWidgetItem *item = *it;
QVERIFY(item);
@@ -984,28 +977,28 @@ void tst_QTreeWidgetItemIterator::minus_eq_data()
{
QTest::addColumn<int>("start");
QTest::addColumn<int>("subtraction");
- QTest::addColumn<int>("iteratorflags");
+ QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>("iteratorflags");
QTest::addColumn<QString>("expecteditem");
- QTest::newRow("0-=0") << 0 << 0 << (int)QTreeWidgetItemIterator::All << QString("top0");
- QTest::newRow("2-=1") << 2 << 1 << (int)QTreeWidgetItemIterator::All << QString("top0,child0");
- QTest::newRow("4-=2") << 4 << 2 << (int)QTreeWidgetItemIterator::All << QString("top0,child1");
- QTest::newRow("0-=(-1)") << 0 << -1 << (int)QTreeWidgetItemIterator::All << QString("top0,child0");
- QTest::newRow("0-=(-2)") << 0 << -2 << (int)QTreeWidgetItemIterator::All << QString("top0,child1");
- QTest::newRow("18-=1") << 18 << 1 << (int)QTreeWidgetItemIterator::All << QString("top0,child16");
- QTest::newRow("1-=1") << 1 << 1 << (int)QTreeWidgetItemIterator::All << QString("top0");
+ QTest::newRow("0-=0") << 0 << 0 << QTreeWidgetItemIterator::All << QString("top0");
+ QTest::newRow("2-=1") << 2 << 1 << QTreeWidgetItemIterator::All << QString("top0,child0");
+ QTest::newRow("4-=2") << 4 << 2 << QTreeWidgetItemIterator::All << QString("top0,child1");
+ QTest::newRow("0-=(-1)") << 0 << -1 << QTreeWidgetItemIterator::All << QString("top0,child0");
+ QTest::newRow("0-=(-2)") << 0 << -2 << QTreeWidgetItemIterator::All << QString("top0,child1");
+ QTest::newRow("18-=1") << 18 << 1 << QTreeWidgetItemIterator::All << QString("top0,child16");
+ QTest::newRow("1-=1") << 1 << 1 << QTreeWidgetItemIterator::All << QString("top0");
}
void tst_QTreeWidgetItemIterator::minus_eq()
{
QFETCH(int, start);
QFETCH(int, subtraction);
- QFETCH(int, iteratorflags);
+ QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags);
QFETCH(QString, expecteditem);
- QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::IteratorFlags(iteratorflags));
- it+=start;
- it-=subtraction;
+ QTreeWidgetItemIterator it(testWidget, iteratorflags);
+ it += start;
+ it -= subtraction;
QTreeWidgetItem *item = *it;
// should be the first one
QVERIFY(item);
@@ -1017,41 +1010,41 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget_data()
QTest::addColumn<int>("topLevelItems");
QTest::addColumn<int>("childItems");
QTest::addColumn<int>("grandChildItems");
- QTest::addColumn<int>("iteratorflags");
+ QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>("iteratorflags");
QTest::addColumn<int>("removeindex");
QTest::addColumn<int>("expecteditemindex");
QTest::addColumn<QString>("expecteditemvalue");
QTest::addColumn<QString>("expectedUpdatedCurrent");
QTest::addColumn<int>("expecteditemIsNull");
- QTest::newRow("Remove 3, check 1") << 3 << 3 << 0 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove 3, check 1") << 3 << 3 << 0 << QTreeWidgetItemIterator::All
<< 3 << 1 << QString("top0,child0") << QString("top1") << 0;
- QTest::newRow("Remove 1, check 0") << 3 << 3 << 0 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove 1, check 0") << 3 << 3 << 0 << QTreeWidgetItemIterator::All
<< 1 << 0 << QString("top0") << QString("top0,child1") << 0;
- QTest::newRow("Remove 2, check 2") << 3 << 3 << 0 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove 2, check 2") << 3 << 3 << 0 << QTreeWidgetItemIterator::All
<< 2 << 2 << QString("top0,child2") << QString("top0,child2") << 0;
- QTest::newRow("Remove 0, check 0") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove 0, check 0") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
<< 0 << 0 << QString("top1") << QString("top1") << 0;
- QTest::newRow("Remove top1, check top1") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove top1, check top1") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
<< 13 << 13 << QString("top2") << QString("top2") << 0;
- QTest::newRow("Remove top0, check top1") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove top0, check top1") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
<< 0 << 13 << QString("top1") << QString("top1") << 0;
- QTest::newRow("Remove (top0,child1), check (top0,child1)") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove (top0,child1), check (top0,child1)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
<< 5 << 5 << QString("top0,child2") << QString("top0,child2") << 0;
- QTest::newRow("Remove (t0,c0) check (t0,c0)") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove (t0,c0) check (t0,c0)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
<< 1 << 1 << QString("top0,child1") << QString("top0,child1") << 0;
- QTest::newRow("Remove (t0,c1) check (t0,c1)") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove (t0,c1) check (t0,c1)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
<< 5 << 5 << QString("top0,child2") << QString("top0,child2") << 0;
- QTest::newRow("Remove (t0) check (t0,c1)") << 3 << 3 << 0 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove (t0) check (t0,c1)") << 3 << 3 << 0 << QTreeWidgetItemIterator::All
<< 0 << 4 << QString("top1") << QString("top1") << 0;
- QTest::newRow("Remove (t0) check (t0,c0,g1)") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove (t0) check (t0,c0,g1)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
<< 0 << 3 << QString("top1") << QString("top1") << 0;
- QTest::newRow("Remove (top2), check if top2 is null") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All
+ QTest::newRow("Remove (top2), check if top2 is null") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
<< 2*13 << 2*13 << QString() << QString() << 1;
QTest::newRow("Remove last item, check if iterator::current returns 0")
- << 3 << 0 << 0 << (int)QTreeWidgetItemIterator::All << 2 << 2 << QString() << QString() << 1;
+ << 3 << 0 << 0 << QTreeWidgetItemIterator::All << 2 << 2 << QString() << QString() << 1;
QTest::newRow("remove 1, iterator points to 3, should move to 1")
- << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All << 1 << 3 << QString("top0,child1") << QString("top0,child1") << 0;
+ << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 1 << 3 << QString("top0,child1") << QString("top0,child1") << 0;
}
static void populate3Levels(QTreeWidget &tw, int topLevelItems, int childItems, int grandChildItems)
@@ -1077,7 +1070,7 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget()
QFETCH(int, topLevelItems);
QFETCH(int, childItems);
QFETCH(int, grandChildItems);
- QFETCH(int, iteratorflags);
+ QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags);
QFETCH(int, removeindex);
QFETCH(int, expecteditemindex);
QFETCH(QString, expecteditemvalue);
@@ -1089,12 +1082,11 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget()
tw.setColumnCount(2);
populate3Levels(tw, topLevelItems, childItems, grandChildItems);
- QTreeWidgetItemIterator it(&tw, QTreeWidgetItemIterator::IteratorFlags(iteratorflags));
+ QTreeWidgetItemIterator it(&tw, iteratorflags);
it+=expecteditemindex;
- QTreeWidgetItem *item = 0;
QTreeWidgetItemIterator itRemove(&tw, QTreeWidgetItemIterator::IteratorFlags(iteratorflags));
itRemove+=removeindex;
- item = *itRemove;
+ QTreeWidgetItem *item = *itRemove;
QVERIFY(item);
delete item;
item = *it;
@@ -1104,11 +1096,10 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget()
QVERIFY(item);
QCOMPARE(item->text(0), expecteditemvalue);
item = *itRemove;
- if (expectedUpdatedCurrent.isNull()) {
+ if (expectedUpdatedCurrent.isNull())
QVERIFY(!item);
- } else {
+ else
QCOMPARE(item->text(0), expectedUpdatedCurrent);
- }
}
}
@@ -1152,38 +1143,36 @@ void tst_QTreeWidgetItemIterator::updateIteratorAfterDeletedItem_and_ContinueIte
QTreeWidgetItemIterator it(&tw, QTreeWidgetItemIterator::All);
it += iterator_initial_index;
- QTreeWidgetItem *item = 0;
QTreeWidgetItemIterator itRemove(&tw, QTreeWidgetItemIterator::All);
itRemove+=removeindex;
- item = *itRemove;
+ QTreeWidgetItem *item = *itRemove;
QVERIFY(item);
delete item;
it+=iterator_advance_after_removal;
- if (iterator_new_value.isNull()) {
+ if (iterator_new_value.isNull())
QCOMPARE((*it), nullptr);
- } else {
+ else
QCOMPARE((*it)->text(0), iterator_new_value);
- }
}
void tst_QTreeWidgetItemIterator::constructIteratorWithItem_data()
{
QTest::addColumn<int>("indextoitem");
- QTest::addColumn<int>("iteratorflags");
+ QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>("iteratorflags");
QTest::addColumn<QString>("expecteditem");
- QTest::newRow("index 0") << 0 << 0 << QString("top0");
- QTest::newRow("index 1") << 1 << 0 << QString("top0,child0");
- QTest::newRow("index 2") << 2 << 0 << QString("top0,child1");
- QTest::newRow("index 30") << 30 << 0 << QString("top1,child11");
- QTest::newRow("305 (last item)") << 305 << 0 << QString("top16,child16");
- QTest::newRow("index 0, advance to next matching node") << 0 << (int)QTreeWidgetItemIterator::NotHidden << QString("top0,child1");
+ QTest::newRow("index 0") << 0 << QTreeWidgetItemIterator::All << QString("top0");
+ QTest::newRow("index 1") << 1 << QTreeWidgetItemIterator::All << QString("top0,child0");
+ QTest::newRow("index 2") << 2 << QTreeWidgetItemIterator::All << QString("top0,child1");
+ QTest::newRow("index 30") << 30 << QTreeWidgetItemIterator::All << QString("top1,child11");
+ QTest::newRow("305 (last item)") << 305 << QTreeWidgetItemIterator::All << QString("top16,child16");
+ QTest::newRow("index 0, advance to next matching node") << 0 << QTreeWidgetItemIterator::NotHidden << QString("top0,child1");
}
void tst_QTreeWidgetItemIterator::constructIteratorWithItem()
{
QFETCH(int, indextoitem);
- QFETCH(int, iteratorflags);
+ QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags);
QFETCH(QString, expecteditem);
QTreeWidgetItemIterator it(testWidget);
diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
index 8c262ff3a5..84120c70e9 100644
--- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
@@ -115,6 +115,7 @@ private slots:
void context();
void duplicatedShortcutOverride();
void shortcutToFocusProxy();
+ void deleteLater();
protected:
static Qt::KeyboardModifiers toButtons( int key );
@@ -1263,5 +1264,14 @@ void tst_QShortcut::shortcutToFocusProxy()
QCOMPARE(le.text(), QString());
}
+void tst_QShortcut::deleteLater()
+{
+ QWidget w;
+ QPointer<QShortcut> sc(new QShortcut(QKeySequence(Qt::Key_1), &w));
+ sc->deleteLater();
+ QTRY_VERIFY(!sc);
+}
+
+
QTEST_MAIN(tst_QShortcut)
#include "tst_qshortcut.moc"
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 51049ecd81..3e372b76f5 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -7704,9 +7704,7 @@ void tst_QWidget::moveWindowInShowEvent()
void tst_QWidget::repaintWhenChildDeleted()
{
#ifdef Q_OS_WIN
- if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista) {
- QTest::qWait(1000);
- }
+ QTest::qWait(1000);
#endif
ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red);
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
@@ -8903,13 +8901,13 @@ void tst_QWidget::translucentWidget()
#ifdef Q_OS_WIN
QWidget *desktopWidget = QApplication::desktop()->screen(0);
- if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista)
- widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height());
- else
+ widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height());
+#else
+ widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size()));
#endif
- widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size()));
const QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32);
- const QImage expected = pm.toImage().scaled(label.devicePixelRatioF() * pm.size());
+ QImage expected = pm.toImage().scaled(label.devicePixelRatioF() * pm.size());
+ expected.setDevicePixelRatio(label.devicePixelRatioF());
if (m_platform == QStringLiteral("winrt"))
QEXPECT_FAIL("", "WinRT: This fails. QTBUG-68297.", Abort);
QCOMPARE(actual.size(),expected.size());
diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
index ae084310b1..4cec54856f 100644
--- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
+++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -67,15 +67,9 @@ using namespace QTestPrivate;
class tst_QStyle : public QObject
{
Q_OBJECT
-public:
- tst_QStyle();
-private:
- bool testAllFunctions(QStyle *);
- bool testScrollBarSubControls();
private slots:
void drawItemPixmap();
- void init();
void cleanup();
#ifndef QT_NO_STYLE_FUSION
void testFusionStyle();
@@ -100,38 +94,29 @@ private slots:
void testProxyCalled();
void testStyleOptionInit();
private:
+ bool testAllFunctions(QStyle *);
+ bool testScrollBarSubControls(const QStyle *style);
+ void testPainting(QStyle *style, const QString &platform);
void lineUpLayoutTest(QStyle *);
- QWidget *testWidget;
};
-
-tst_QStyle::tst_QStyle()
-{
- testWidget = 0;
-}
-
class MyWidget : public QWidget
{
public:
- MyWidget( QWidget* QWidget=0, const char* name=0 );
+ using QWidget::QWidget;
+
protected:
- void paintEvent( QPaintEvent* );
+ void paintEvent(QPaintEvent *) override;
};
-void tst_QStyle::init()
-{
- testWidget = new MyWidget( 0, "testObject");
-}
-
void tst_QStyle::cleanup()
{
- delete testWidget;
- testWidget = 0;
+ QVERIFY(QApplication::topLevelWidgets().isEmpty());
}
void tst_QStyle::testStyleFactory()
{
- QStringList keys = QStyleFactory::keys();
+ const QStringList keys = QStyleFactory::keys();
#ifndef QT_NO_STYLE_FUSION
QVERIFY(keys.contains("Fusion"));
#endif
@@ -139,17 +124,17 @@ void tst_QStyle::testStyleFactory()
QVERIFY(keys.contains("Windows"));
#endif
- foreach (QString styleName , keys) {
- QStyle *style = QStyleFactory::create(styleName);
- QVERIFY2(style != 0, qPrintable(QString::fromLatin1("Fail to load style '%1'").arg(styleName)));
- delete style;
+ for (const QString &styleName : keys) {
+ QScopedPointer<QStyle> style(QStyleFactory::create(styleName));
+ QVERIFY2(!style.isNull(),
+ qPrintable(QString::fromLatin1("Fail to load style '%1'").arg(styleName)));
}
}
class CustomProxy : public QProxyStyle
{
- virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = 0,
- const QWidget *widget = 0) const
+ int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
+ const QWidget *widget = nullptr) const override
{
if (metric == QStyle::PM_ButtonIconSize)
return 13;
@@ -170,9 +155,9 @@ void tst_QStyle::testProxyStyle()
QCOMPARE(proxyStyle->baseStyle(), style);
QVERIFY(testAllFunctions(proxyStyle));
- proxyStyle->setBaseStyle(0);
+ proxyStyle->setBaseStyle(nullptr);
QVERIFY(proxyStyle->baseStyle());
- qApp->setStyle(proxyStyle);
+ QApplication::setStyle(proxyStyle);
QProxyStyle* baseStyle = new QProxyStyle("Windows");
QCOMPARE(baseStyle->baseStyle()->objectName(), style->objectName());
@@ -189,10 +174,12 @@ void tst_QStyle::testProxyStyle()
void tst_QStyle::drawItemPixmap()
{
- testWidget->resize(300, 300);
- testWidget->showNormal();
+ MyWidget testWidget;
+ testWidget.setObjectName("testObject");
+ testWidget.resize(300, 300);
+ testWidget.showNormal();
- QImage image = testWidget->grab().toImage();
+ QImage image = testWidget.grab().toImage();
const QRgb green = QColor(Qt::green).rgb();
QVERIFY(image.reinterpretAsFormat(QImage::Format_RGB32));
const QRgb *bits = reinterpret_cast<const QRgb *>(image.constBits());
@@ -201,33 +188,33 @@ void tst_QStyle::drawItemPixmap()
QEXPECT_FAIL("", "QWidget::resize does not work on WinRT", Continue);
#endif
QVERIFY(std::all_of(bits, end, [green] (QRgb r) { return r == green; }));
- testWidget->hide();
}
bool tst_QStyle::testAllFunctions(QStyle *style)
{
QStyleOption opt;
- opt.init(testWidget);
+ QWidget testWidget;
+ opt.init(&testWidget);
- testWidget->setStyle(style);
+ testWidget.setStyle(style);
//Tests styleHint with default arguments for potential crashes
for ( int hint = 0 ; hint < int(QStyle::SH_Menu_Mask); ++hint) {
style->styleHint(QStyle::StyleHint(hint));
- style->styleHint(QStyle::StyleHint(hint), &opt, testWidget);
+ style->styleHint(QStyle::StyleHint(hint), &opt, &testWidget);
}
//Tests pixelMetric with default arguments for potential crashes
for ( int pm = 0 ; pm < int(QStyle::PM_LayoutVerticalSpacing); ++pm) {
style->pixelMetric(QStyle::PixelMetric(pm));
- style->pixelMetric(QStyle::PixelMetric(pm), &opt, testWidget);
+ style->pixelMetric(QStyle::PixelMetric(pm), &opt, &testWidget);
}
//Tests drawControl with default arguments for potential crashes
for ( int control = 0 ; control < int(QStyle::CE_ColumnViewGrip); ++control) {
QPixmap surface(QSize(200, 200));
QPainter painter(&surface);
- style->drawControl(QStyle::ControlElement(control), &opt, &painter, 0);
+ style->drawControl(QStyle::ControlElement(control), &opt, &painter, nullptr);
}
//Tests drawComplexControl with default arguments for potential crashes
@@ -235,35 +222,35 @@ bool tst_QStyle::testAllFunctions(QStyle *style)
QPixmap surface(QSize(200, 200));
QPainter painter(&surface);
QStyleOptionComboBox copt1;
- copt1.init(testWidget);
+ copt1.init(&testWidget);
QStyleOptionGroupBox copt2;
- copt2.init(testWidget);
+ copt2.init(&testWidget);
QStyleOptionSizeGrip copt3;
- copt3.init(testWidget);
+ copt3.init(&testWidget);
QStyleOptionSlider copt4;
- copt4.init(testWidget);
+ copt4.init(&testWidget);
copt4.minimum = 0;
copt4.maximum = 100;
copt4.tickInterval = 25;
copt4.sliderValue = 50;
QStyleOptionSpinBox copt5;
- copt5.init(testWidget);
+ copt5.init(&testWidget);
QStyleOptionTitleBar copt6;
- copt6.init(testWidget);
+ copt6.init(&testWidget);
QStyleOptionToolButton copt7;
- copt7.init(testWidget);
+ copt7.init(&testWidget);
QStyleOptionComplex copt9;
- copt9.initFrom(testWidget);
-
- style->drawComplexControl(QStyle::CC_SpinBox, &copt5, &painter, 0);
- style->drawComplexControl(QStyle::CC_ComboBox, &copt1, &painter, 0);
- style->drawComplexControl(QStyle::CC_ScrollBar, &copt4, &painter, 0);
- style->drawComplexControl(QStyle::CC_Slider, &copt4, &painter, 0);
- style->drawComplexControl(QStyle::CC_ToolButton, &copt7, &painter, 0);
- style->drawComplexControl(QStyle::CC_TitleBar, &copt6, &painter, 0);
- style->drawComplexControl(QStyle::CC_GroupBox, &copt2, &painter, 0);
- style->drawComplexControl(QStyle::CC_Dial, &copt4, &painter, 0);
+ copt9.initFrom(&testWidget);
+
+ style->drawComplexControl(QStyle::CC_SpinBox, &copt5, &painter, nullptr);
+ style->drawComplexControl(QStyle::CC_ComboBox, &copt1, &painter, nullptr);
+ style->drawComplexControl(QStyle::CC_ScrollBar, &copt4, &painter, nullptr);
+ style->drawComplexControl(QStyle::CC_Slider, &copt4, &painter, nullptr);
+ style->drawComplexControl(QStyle::CC_ToolButton, &copt7, &painter, nullptr);
+ style->drawComplexControl(QStyle::CC_TitleBar, &copt6, &painter, nullptr);
+ style->drawComplexControl(QStyle::CC_GroupBox, &copt2, &painter, nullptr);
+ style->drawComplexControl(QStyle::CC_Dial, &copt4, &painter, nullptr);
}
//Check standard pixmaps/icons
@@ -279,20 +266,21 @@ bool tst_QStyle::testAllFunctions(QStyle *style)
}
style->itemPixmapRect(QRect(0, 0, 100, 100), Qt::AlignHCenter, QPixmap(200, 200));
- style->itemTextRect(QFontMetrics(qApp->font()), QRect(0, 0, 100, 100), Qt::AlignHCenter, true, QString("Test"));
+ style->itemTextRect(QFontMetrics(QApplication::font()), QRect(0, 0, 100, 100),
+ Qt::AlignHCenter, true, QLatin1String("Test"));
- return testScrollBarSubControls();
+ return testScrollBarSubControls(style);
}
-bool tst_QStyle::testScrollBarSubControls()
+bool tst_QStyle::testScrollBarSubControls(const QStyle *style)
{
- const auto *style = testWidget->style();
- const bool isMacStyle = style->objectName().toLower() == "macintosh";
+ const bool isMacStyle = style->objectName().compare(QLatin1String("macintosh"),
+ Qt::CaseInsensitive) == 0;
QScrollBar scrollBar;
setFrameless(&scrollBar);
scrollBar.show();
const QStyleOptionSlider opt = qt_qscrollbarStyleOption(&scrollBar);
- foreach (int sc, QList<int>() << 1 << 2 << 4 << 8) {
+ for (int sc : {1, 2, 4, 8}) {
const auto subControl = static_cast<QStyle::SubControl>(sc);
const QRect sr = style->subControlRect(QStyle::CC_ScrollBar, &opt, subControl, &scrollBar);
if (sr.isNull()) {
@@ -310,34 +298,34 @@ bool tst_QStyle::testScrollBarSubControls()
#ifndef QT_NO_STYLE_FUSION
void tst_QStyle::testFusionStyle()
{
- QStyle *fstyle = QStyleFactory::create("Fusion");
- QVERIFY(testAllFunctions(fstyle));
- lineUpLayoutTest(fstyle);
- delete fstyle;
+ QScopedPointer<QStyle> fstyle(QStyleFactory::create("Fusion"));
+ QVERIFY(!fstyle.isNull());
+ QVERIFY(testAllFunctions(fstyle.data()));
+ lineUpLayoutTest(fstyle.data());
}
#endif
void tst_QStyle::testWindowsStyle()
{
- QStyle *wstyle = QStyleFactory::create("Windows");
- QVERIFY(testAllFunctions(wstyle));
- lineUpLayoutTest(wstyle);
+ QScopedPointer<QStyle> wstyle(QStyleFactory::create("Windows"));
+ QVERIFY(!wstyle.isNull());
+ QVERIFY(testAllFunctions(wstyle.data()));
+ lineUpLayoutTest(wstyle.data());
// Tests drawing indeterminate progress with 0 size: QTBUG-15973
QStyleOptionProgressBar pb;
pb.rect = QRect(0,0,-9,0);
QPixmap surface(QSize(200, 200));
QPainter painter(&surface);
- wstyle->drawControl(QStyle::CE_ProgressBar, &pb, &painter, 0);
- delete wstyle;
+ wstyle->drawControl(QStyle::CE_ProgressBar, &pb, &painter, nullptr);
}
#if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA) && !defined(Q_OS_WINRT)
void tst_QStyle::testWindowsVistaStyle()
{
- QStyle *vistastyle = QStyleFactory::create("WindowsVista");
- QVERIFY(testAllFunctions(vistastyle));
- delete vistastyle;
+ QScopedPointer<QStyle> vistastyle(QStyleFactory::create("WindowsVista"));
+ QVERIFY(!vistastyle.isNull());
+ QVERIFY(testAllFunctions(vistastyle.data()));
}
#endif
@@ -351,14 +339,7 @@ void tst_QStyle::testMacStyle()
#endif
// Helper class...
-
-MyWidget::MyWidget( QWidget* parent, const char* name )
- : QWidget( parent )
-{
- setObjectName(name);
-}
-
-void MyWidget::paintEvent( QPaintEvent* )
+void MyWidget::paintEvent(QPaintEvent *)
{
QPainter p(this);
QPixmap big(400,400);
@@ -371,20 +352,12 @@ class Qt42Style : public QCommonStyle
{
Q_OBJECT
public:
- Qt42Style() : QCommonStyle()
- {
- margin_toplevel = 10;
- margin = 5;
- spacing = 0;
- }
-
- virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0,
- const QWidget * widget = 0 ) const;
-
- int margin_toplevel;
- int margin;
- int spacing;
+ int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
+ const QWidget *widget = nullptr) const override;
+ int margin_toplevel = 10;
+ int margin = 5;
+ int spacing = 0;
};
int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * /* option = 0*/,
@@ -393,13 +366,10 @@ int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * /* option =
switch (metric) {
case QStyle::PM_DefaultTopLevelMargin:
return margin_toplevel;
- break;
case QStyle::PM_DefaultChildMargin:
return margin;
- break;
case QStyle::PM_DefaultLayoutSpacing:
return spacing;
- break;
default:
break;
}
@@ -409,7 +379,7 @@ int Qt42Style::pixelMetric(PixelMetric metric, const QStyleOption * /* option =
void tst_QStyle::pixelMetric()
{
- Qt42Style *style = new Qt42Style();
+ QScopedPointer<Qt42Style> style(new Qt42Style);
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), 10);
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), 5);
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), 0);
@@ -427,8 +397,6 @@ void tst_QStyle::pixelMetric()
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultTopLevelMargin), -1);
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultChildMargin), -1);
QCOMPARE(style->pixelMetric(QStyle::PM_DefaultLayoutSpacing), -1);
-
- delete style;
}
#if !defined(QT_NO_STYLE_WINDOWS) && !defined(QT_NO_STYLE_FUSION)
@@ -474,10 +442,11 @@ void tst_QStyle::lineUpLayoutTest(QStyle *style)
layout.addWidget(&lineedit);
layout.addWidget(&combo);
widget.setLayout(&layout);
- widget.setStyle(style);
- // propagate the style.
- foreach (QWidget *w, widget.findChildren<QWidget *>())
- w->setStyle(style);
+ widget.setStyle(style);
+ // propagate the style.
+ const auto children = widget.findChildren<QWidget *>();
+ for (QWidget *w : children)
+ w->setStyle(style);
widget.show();
QVERIFY(QTest::qWaitForWindowExposed(&widget));
@@ -498,31 +467,32 @@ void tst_QStyle::lineUpLayoutTest(QStyle *style)
void tst_QStyle::defaultFont()
{
- QFont defaultFont = qApp->font();
+ QFont defaultFont = QApplication::font();
QFont pointFont = defaultFont;
pointFont.setPixelSize(9);
- qApp->setFont(pointFont);
+ QApplication::setFont(pointFont);
QPushButton button;
setFrameless(&button);
button.show();
- qApp->processEvents();
- qApp->setFont(defaultFont);
+ QCoreApplication::processEvents();
+ QApplication::setFont(defaultFont);
}
class DrawTextStyle : public QProxyStyle
{
Q_OBJECT
public:
- DrawTextStyle(QStyle *base = 0) : QProxyStyle(), alignment(0) { setBaseStyle(base); }
+ using QProxyStyle::QProxyStyle;
+
void drawItemText(QPainter *painter, const QRect &rect,
- int flags, const QPalette &pal, bool enabled,
- const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const
+ int flags, const QPalette &pal, bool enabled,
+ const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const override
{
- DrawTextStyle *that = (DrawTextStyle *)this;
- that->alignment = flags;
+ alignment = flags;
QProxyStyle::drawItemText(painter, rect, flags, pal, enabled, text, textRole);
}
- int alignment;
+
+ mutable int alignment = 0;
};
@@ -533,46 +503,48 @@ void tst_QStyle::testDrawingShortcuts()
setFrameless(&w);
QToolButton *tb = new QToolButton(&w);
tb->setText("&abc");
- DrawTextStyle *dts = new DrawTextStyle;
+ QScopedPointer<DrawTextStyle> dts(new DrawTextStyle);
w.show();
- tb->setStyle(dts);
+ tb->setStyle(dts.data());
tb->grab();
QStyleOptionToolButton sotb;
sotb.initFrom(tb);
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
- delete dts;
}
{
QToolBar w;
setFrameless(&w);
QToolButton *tb = new QToolButton(&w);
tb->setText("&abc");
- DrawTextStyle *dts = new DrawTextStyle;
+ QScopedPointer<DrawTextStyle> dts(new DrawTextStyle);
w.addWidget(tb);
w.show();
- tb->setStyle(dts);
+ tb->setStyle(dts.data());
tb->grab();
QStyleOptionToolButton sotb;
sotb.initFrom(tb);
bool showMnemonic = dts->styleHint(QStyle::SH_UnderlineShortcut, &sotb, tb);
QVERIFY(dts->alignment & (showMnemonic ? Qt::TextShowMnemonic : Qt::TextHideMnemonic));
- delete dts;
}
}
-#define SCROLLBAR_SPACING 33
+static const int SCROLLBAR_SPACING = 33;
class FrameTestStyle : public QProxyStyle {
public:
FrameTestStyle() : QProxyStyle("Windows") { }
- int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const {
+
+ int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
+ QStyleHintReturn *returnData) const override
+ {
if (hint == QStyle::SH_ScrollView_FrameOnlyAroundContents)
return 1;
return QProxyStyle ::styleHint(hint, opt, widget, returnData);
}
- int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget) const {
+ int pixelMetric(PixelMetric pm, const QStyleOption *option, const QWidget *widget) const override
+ {
if (pm == QStyle::PM_ScrollView_ScrollBarSpacing)
return SCROLLBAR_SPACING;
return QProxyStyle ::pixelMetric(pm, option ,widget);
@@ -583,12 +555,12 @@ void tst_QStyle::testFrameOnlyAroundContents()
{
QScrollArea area;
area.setGeometry(0, 0, 200, 200);
- QStyle *winStyle = QStyleFactory::create("Windows");
+ QScopedPointer<QStyle> winStyle(QStyleFactory::create("Windows"));
FrameTestStyle frameStyle;
QWidget *widget = new QWidget(&area);
widget->setGeometry(0, 0, 400, 400);
- area.setStyle(winStyle);
- area.verticalScrollBar()->setStyle(winStyle);
+ area.setStyle(winStyle.data());
+ area.verticalScrollBar()->setStyle(winStyle.data());
area.setWidget(widget);
area.setVisible(true);
int viewPortWidth = area.viewport()->width();
@@ -598,8 +570,7 @@ void tst_QStyle::testFrameOnlyAroundContents()
#ifdef Q_OS_WINRT
QEXPECT_FAIL("", "QWidget::setGeometry does not work on WinRT", Continue);
#endif
- QVERIFY(viewPortWidth == area.viewport()->width() + SCROLLBAR_SPACING);
- delete winStyle;
+ QCOMPARE(viewPortWidth, area.viewport()->width() + SCROLLBAR_SPACING);
}
@@ -607,16 +578,16 @@ class ProxyTest: public QProxyStyle
{
Q_OBJECT
public:
- ProxyTest(QStyle *style = 0)
- :QProxyStyle(style)
- , called(false)
- {}
+ using QProxyStyle::QProxyStyle;
- void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const override {
+ void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
+ const QWidget *w) const override
+ {
called = true;
return QProxyStyle::drawPrimitive(pe, opt, p, w);
}
- mutable bool called;
+
+ mutable bool called = false;
};
@@ -630,17 +601,16 @@ void tst_QStyle::testProxyCalled()
QPixmap surface(QSize(200, 200));
QPainter painter(&surface);
- QStringList keys = QStyleFactory::keys();
+ const QStringList keys = QStyleFactory::keys();
QVector<QStyle*> styles;
styles.reserve(keys.size() + 1);
styles << new QCommonStyle();
- Q_FOREACH (const QString &key, keys) {
+ for (const QString &key : keys)
styles << QStyleFactory::create(key);
- }
- Q_FOREACH (QStyle *style, styles) {
+ for (QStyle *style : styles) {
ProxyTest testStyle;
testStyle.setBaseStyle(style);
style->drawControl(QStyle::CE_ToolButtonLabel, &opt, &painter, &b);
@@ -654,11 +624,9 @@ class TestStyleOptionInitProxy: public QProxyStyle
{
Q_OBJECT
public:
- mutable bool invalidOptionsDetected;
- explicit TestStyleOptionInitProxy(QStyle *style = nullptr)
- : QProxyStyle(style),
- invalidOptionsDetected(false)
- {}
+ mutable bool invalidOptionsDetected = false;
+
+ using QProxyStyle::QProxyStyle;
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const override {
checkStyleEnum<QStyle::PrimitiveElement>(pe, opt);
@@ -743,7 +711,7 @@ void tst_QStyle::testStyleOptionInit()
QStringList keys = QStyleFactory::keys();
keys.prepend(QString()); // QCommonStyle marker
- Q_FOREACH (const QString &key, keys) {
+ for (const QString &key : qAsConst(keys)) {
QStyle* style = key.isEmpty() ? new QCommonStyle : QStyleFactory::create(key);
TestStyleOptionInitProxy testStyle;
testStyle.setBaseStyle(style);
diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
index a671a6c4d8..400e46cb97 100644
--- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
+++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -25,12 +25,40 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include <QtCore>
-#include <QtGui>
-#include <QtWidgets>
+
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QCheckBox>
+#include <QtWidgets/QComboBox>
+#include <QtWidgets/QDateEdit>
+#include <QtWidgets/QDialog>
+#include <QtWidgets/QDialogButtonBox>
+#include <QtWidgets/QGridLayout>
+#include <QtWidgets/QGroupBox>
+#include <QtWidgets/QLabel>
+#include <QtWidgets/QHeaderView>
+#include <QtWidgets/QLineEdit>
+#include <QtWidgets/QMainWindow>
+#include <QtWidgets/QMenu>
+#include <QtWidgets/QPushButton>
+#include <QtWidgets/QProgressBar>
+#include <QtWidgets/QSpinBox>
+#include <QtWidgets/QSplitter>
+#include <QtWidgets/QStyle>
+#include <QtWidgets/QStyleFactory>
+#include <QtWidgets/QTableWidget>
+#include <QtWidgets/QToolButton>
+#include <QtWidgets/QToolTip>
+#include <QtWidgets/QTreeView>
+#include <QtWidgets/QVBoxLayout>
+
+#include <QtGui/QPainter>
+#include <QtGui/QScreen>
+
#include <QtTest/QtTest>
-#include <QtDebug>
-#include <QMetaObject>
+
+#include <QtCore/QDebug>
+#include <QtCore/QMetaObject>
+#include <QtCore/QScopedPointer>
#include <private/qstylesheetstyle_p.h>
#include <private/qhighdpiscaling_p.h>
@@ -43,10 +71,12 @@ class tst_QStyleSheetStyle : public QObject
Q_OBJECT
public:
tst_QStyleSheetStyle();
- ~tst_QStyleSheetStyle();
+
+ static void initMain();
private slots:
void init();
+ void cleanup();
void repolish();
void repolish_without_crashing();
void numinstances();
@@ -77,7 +107,7 @@ private slots:
void hoverColors();
#endif
void background();
- void tabAlignement();
+ void tabAlignment();
void attributesList();
void minmaxSizes();
void task206238_twice();
@@ -107,37 +137,53 @@ private slots:
void highdpiImages();
private:
- QColor COLOR(const QWidget& w) {
+ static QColor COLOR(const QWidget &w)
+ {
w.ensurePolished();
return w.palette().color(w.foregroundRole());
}
- QColor APPCOLOR(const QWidget& w) {
+
+ static QColor APPCOLOR(const QWidget &w)
+ {
w.ensurePolished();
- return qApp->palette(&w).color(w.foregroundRole());
+ return QApplication::palette(&w).color(w.foregroundRole());
}
- QColor BACKGROUND(const QWidget& w) {
+
+ static QColor BACKGROUND(const QWidget &w)
+ {
w.ensurePolished();
return w.palette().color(w.backgroundRole());
}
- QColor APPBACKGROUND(const QWidget& w) {
+
+ static QColor APPBACKGROUND(const QWidget &w)
+ {
w.ensurePolished();
- return qApp->palette(&w).color(w.backgroundRole());
+ return QApplication::palette(&w).color(w.backgroundRole());
}
- int FONTSIZE(const QWidget &w) {
+
+ static int FONTSIZE(const QWidget &w)
+ {
w.ensurePolished();
return w.font().pointSize();
}
- int APPFONTSIZE(const QWidget &w) {
- return qApp->font(&w).pointSize();
- }
+
+ static int APPFONTSIZE(const QWidget &w) { return QApplication::font(&w).pointSize(); }
+
+ const QRect m_availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
+ QSize m_testSize;
};
-tst_QStyleSheetStyle::tst_QStyleSheetStyle()
+// highdpiImages() tests HighDPI scaling; disable initially.
+void tst_QStyleSheetStyle::initMain()
{
+ QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
}
-tst_QStyleSheetStyle::~tst_QStyleSheetStyle()
+tst_QStyleSheetStyle::tst_QStyleSheetStyle()
{
+ const int testSize = qMax(200, m_availableGeometry.width() / 10);
+ m_testSize.setWidth(testSize);
+ m_testSize.setHeight(testSize);
}
void tst_QStyleSheetStyle::init()
@@ -146,10 +192,16 @@ void tst_QStyleSheetStyle::init()
QCoreApplication::setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles, false);
}
+void tst_QStyleSheetStyle::cleanup()
+{
+ QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty());
+}
+
void tst_QStyleSheetStyle::numinstances()
{
QWidget w;
- w.resize(200, 200);
+ w.setWindowTitle(QTest::currentTestFunction());
+ w.resize(m_testSize);
centerOnScreen(&w);
QCommonStyle *style = new QCommonStyle;
style->setParent(&w);
@@ -175,7 +227,7 @@ void tst_QStyleSheetStyle::numinstances()
QCOMPARE(QStyleSheetStyle::numinstances, 0);
// set and unset widget stylesheet
- w.setStyle(0);
+ w.setStyle(nullptr);
w.setStyleSheet("color: red");
QCOMPARE(QStyleSheetStyle::numinstances, 1);
c.setStyle(style);
@@ -325,7 +377,7 @@ void tst_QStyleSheetStyle::reparentWithNoChildStyleSheet()
QCOMPARE(COLOR(c1), red);
qApp->setStyleSheet("* { color: blue }");
- c1.setParent(0);
+ c1.setParent(nullptr);
QCOMPARE(COLOR(c1), blue);
delete pb;
}
@@ -372,6 +424,8 @@ void tst_QStyleSheetStyle::repolish_without_crashing()
{
// This used to crash, QTBUG-69204
QMainWindow w;
+ w.resize(m_testSize);
+ w.setWindowTitle(QTest::currentTestFunction());
QScopedPointer<QSplitter> splitter1(new QSplitter(w.centralWidget()));
QScopedPointer<QSplitter> splitter2(new QSplitter);
QScopedPointer<QSplitter> splitter3(new QSplitter);
@@ -408,7 +462,7 @@ void tst_QStyleSheetStyle::widgetStyle()
QPointer<QStyle> style1 = QStyleFactory::create("Windows");
QPointer<QStyle> style2 = QStyleFactory::create("Windows");
- QStyle *appStyle = qApp->style();
+ QStyle *appStyle = QApplication::style();
// Sanity: By default, a window inherits the application style
QCOMPARE(appStyle, window1->style());
@@ -423,7 +477,7 @@ void tst_QStyleSheetStyle::widgetStyle()
QVERIFY(!style1.isNull()); // case we have not already crashed
// Setting null style must make it follow the qApp style
- window1->setStyle(0);
+ window1->setStyle(nullptr);
QCOMPARE(window1->style(), appStyle);
QVERIFY(!style2.isNull()); // case we have not already crashed
QVERIFY(!style2.isNull()); // case we have not already crashed
@@ -431,16 +485,15 @@ void tst_QStyleSheetStyle::widgetStyle()
// Sanity: Set the stylesheet
window1->setStyleSheet(":x { }");
- QPointer<QStyleSheetStyle> proxy = (QStyleSheetStyle *)window1->style();
+ QPointer<QStyleSheetStyle> proxy = qobject_cast<QStyleSheetStyle *>(window1->style());
QVERIFY(!proxy.isNull());
- QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); // must be our proxy
- QVERIFY(proxy->base == 0); // and follows the application
+ QCOMPARE(proxy->base, nullptr); // and follows the application
// Set the stylesheet
window1->setStyle(style1);
QVERIFY(proxy.isNull()); // we create a new one each time
- proxy = (QStyleSheetStyle *)window1->style();
- QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle"); // it is a proxy
+ proxy = qobject_cast<QStyleSheetStyle *>(window1->style());
+ QVERIFY(!proxy.isNull()); // it is a proxy
QCOMPARE(proxy->baseStyle(), style1.data()); // must have been replaced with the new one
// Update the stylesheet and check nothing changes
@@ -449,15 +502,15 @@ void tst_QStyleSheetStyle::widgetStyle()
QCOMPARE(proxy->baseStyle(), style1.data()); // the same guy
// Remove the stylesheet
- proxy = (QStyleSheetStyle *)window1->style();
+ proxy = qobject_cast<QStyleSheetStyle *>(window1->style());
window1->setStyleSheet(QString());
QVERIFY(proxy.isNull()); // should have disappeared
QCOMPARE(window1->style(), style1.data()); // its restored
// Style Sheet existing children propagation
window1->setStyleSheet(":z { }");
- proxy = (QStyleSheetStyle *)window1->style();
- QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle");
+ proxy = qobject_cast<QStyleSheetStyle *>(window1->style());
+ QVERIFY(!proxy.isNull()); // it is a proxy
QCOMPARE(window1->style(), widget1->style()); // proxy must have propagated
QCOMPARE(widget2->style(), appStyle); // widget2 is following the app style
@@ -473,55 +526,57 @@ void tst_QStyleSheetStyle::widgetStyle()
// Style Sheet propagation on a child widget with a custom style
widget2->setStyle(style1);
window2->setStyleSheet(":x { }");
- proxy = (QStyleSheetStyle *)widget2->style();
- QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle");
+ proxy = qobject_cast<QStyleSheetStyle *>(widget2->style());
+ QVERIFY(!proxy.isNull()); // it is a proxy
QCOMPARE(proxy->baseStyle(), style1.data());
// Style Sheet propagation on a child widget with a custom style already set
window2->setStyleSheet(QString());
QCOMPARE(window2->style(), style2.data());
QCOMPARE(widget2->style(), style1.data());
- widget2->setStyle(0);
+ widget2->setStyle(nullptr);
window2->setStyleSheet(":x { }");
widget2->setStyle(style1);
- proxy = (QStyleSheetStyle *)widget2->style();
- QCOMPARE(proxy->metaObject()->className(), "QStyleSheetStyle");
+ proxy = qobject_cast<QStyleSheetStyle *>(widget2->style());
+ QVERIFY(!proxy.isNull()); // it is a proxy
// QApplication, QWidget both having a style sheet
// clean everything out
- window1->setStyle(0);
+ window1->setStyle(nullptr);
window1->setStyleSheet(QString());
- window2->setStyle(0);
+ window2->setStyle(nullptr);
window2->setStyleSheet(QString());
- qApp->setStyle(0);
+ QApplication::setStyle(nullptr);
qApp->setStyleSheet("may_insanity_prevail { }"); // app has stylesheet
- QCOMPARE(window1->style(), qApp->style());
+ QCOMPARE(window1->style(), QApplication::style());
QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle");
QCOMPARE(widget1->style()->metaObject()->className(), "QStyleSheetStyle"); // check the child
window1->setStyleSheet("may_more_insanity_prevail { }"); // window has stylesheet
QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); // a new one
QCOMPARE(widget1->style(), window1->style()); // child follows...
- proxy = (QStyleSheetStyle *) window1->style();
+ proxy = qobject_cast<QStyleSheetStyle *>(window1->style());
+ QVERIFY(!proxy.isNull());
QStyle *newStyle = QStyleFactory::create("Windows");
- qApp->setStyle(newStyle); // set a custom style on app
- proxy = (QStyleSheetStyle *) window1->style();
+ QApplication::setStyle(newStyle); // set a custom style on app
+ proxy = qobject_cast<QStyleSheetStyle *>(window1->style());
+ QVERIFY(!proxy.isNull()); // it is a proxy
QCOMPARE(proxy->baseStyle(), newStyle); // magic ;) the widget still follows the application
QCOMPARE(static_cast<QStyle *>(proxy), widget1->style()); // child still follows...
window1->setStyleSheet(QString()); // remove stylesheet
- QCOMPARE(window1->style(), qApp->style()); // is this cool or what
- QCOMPARE(widget1->style(), qApp->style()); // annoying child follows...
+ QCOMPARE(window1->style(), QApplication::style()); // is this cool or what
+ QCOMPARE(widget1->style(), QApplication::style()); // annoying child follows...
QScopedPointer<QStyle> wndStyle(QStyleFactory::create("Windows"));
window1->setStyle(wndStyle.data());
QCOMPARE(window1->style()->metaObject()->className(), "QStyleSheetStyle"); // auto wraps it
QCOMPARE(widget1->style(), window1->style()); // and auto propagates to child
qApp->setStyleSheet(QString()); // remove the app stylesheet
QCOMPARE(window1->style(), wndStyle.data()); // auto dewrap
- QCOMPARE(widget1->style(), qApp->style()); // and child state is restored
- window1->setStyle(0); // let sanity prevail
- qApp->setStyle(0);
+ QCOMPARE(widget1->style(), QApplication::style()); // and child state is restored
+ window1->setStyle(nullptr); // let sanity prevail
+ QApplication::setStyle(nullptr);
delete window1;
delete widget2;
@@ -534,32 +589,32 @@ void tst_QStyleSheetStyle::appStyle()
{
qApp->setStyleSheet(QString());
// qApp style can never be 0
- QVERIFY(QApplication::style() != 0);
+ QVERIFY(QApplication::style() != nullptr);
QPointer<QStyle> style1 = QStyleFactory::create("Windows");
QPointer<QStyle> style2 = QStyleFactory::create("Windows");
- qApp->setStyle(style1);
+ QApplication::setStyle(style1);
// Basic sanity
QCOMPARE(QApplication::style(), style1.data());
- qApp->setStyle(style2);
+ QApplication::setStyle(style2);
QVERIFY(style1.isNull()); // qApp must have taken ownership and deleted it
// Setting null should not crash
- qApp->setStyle(0);
+ QApplication::setStyle(nullptr);
QCOMPARE(QApplication::style(), style2.data());
// Set the stylesheet
qApp->setStyleSheet("whatever");
- QPointer<QStyleSheetStyle> sss = (QStyleSheetStyle *)qApp->style();
+ QPointer<QStyleSheetStyle> sss = static_cast<QStyleSheetStyle *>(QApplication::style());
QVERIFY(!sss.isNull());
QCOMPARE(sss->metaObject()->className(), "QStyleSheetStyle"); // must be our proxy now
QVERIFY(!style2.isNull()); // this should exist as it is the base of the proxy
QCOMPARE(sss->baseStyle(), style2.data());
style1 = QStyleFactory::create("Windows");
- qApp->setStyle(style1);
+ QApplication::setStyle(style1);
QVERIFY(style2.isNull()); // should disappear automatically
QVERIFY(sss.isNull()); // should disappear automatically
// Update the stylesheet and check nothing changes
- sss = (QStyleSheetStyle *)qApp->style();
+ sss = static_cast<QStyleSheetStyle *>(QApplication::style());
qApp->setStyleSheet("whatever2");
QCOMPARE(QApplication::style(), sss.data());
QCOMPARE(sss->baseStyle(), style1.data());
@@ -577,14 +632,15 @@ void tst_QStyleSheetStyle::dynamicProperty()
{
qApp->setStyleSheet(QString());
- QString appStyle = qApp->style()->metaObject()->className();
+ QString appStyle = QApplication::style()->metaObject()->className();
QPushButton pb1(QStringLiteral("dynamicProperty_pb1"));
- pb1.setMinimumWidth(160);
- pb1.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 100));
+ pb1.setMinimumWidth(m_testSize.width());
+ pb1.move(m_availableGeometry.topLeft() + QPoint(20, 100));
QPushButton pb2(QStringLiteral("dynamicProperty_pb2"));
- pb2.setMinimumWidth(160);
- pb2.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 200));
+ pb2.setWindowTitle(QTest::currentTestFunction());
+ pb2.setMinimumWidth(m_testSize.width());
+ pb2.move(m_availableGeometry.topLeft() + QPoint(20, m_testSize.width() + 40));
pb1.setProperty("type", "critical");
qApp->setStyleSheet("*[class~=\"QPushButton\"] { color: red; } *[type=\"critical\"] { background: white; }");
@@ -625,7 +681,7 @@ namespace ns {
class PushButton1 : public QPushButton {
Q_OBJECT
public:
- PushButton1() { }
+ using QPushButton::QPushButton;
};
class PushButton2 : public PushButton1 {
Q_OBJECT
@@ -781,7 +837,7 @@ void tst_QStyleSheetStyle::onWidgetDestroyed()
qApp->setStyleSheet(QString());
QLabel *l = new QLabel;
l->setStyleSheet("QLabel { color: red }");
- QPointer<QStyleSheetStyle> ss = (QStyleSheetStyle *) l->style();
+ QPointer<QStyleSheetStyle> ss = static_cast<QStyleSheetStyle *>(l->style());
delete l;
QVERIFY(ss.isNull());
}
@@ -789,7 +845,8 @@ void tst_QStyleSheetStyle::onWidgetDestroyed()
void tst_QStyleSheetStyle::fontPrecedence()
{
QLineEdit edit;
- edit.setMinimumWidth(200);
+ edit.setWindowTitle(QTest::currentTestFunction());
+ edit.setMinimumWidth(m_testSize.width());
centerOnScreen(&edit);
edit.show();
QFont font;
@@ -817,23 +874,23 @@ void tst_QStyleSheetStyle::fontPrecedence()
}
// Ensure primary will only return true if the color covers more than 50% of pixels
-static bool testForColors(const QImage& image, const QColor& color, bool ensurePrimary=false)
+static bool testForColors(const QImage& image, const QColor &color, bool ensurePrimary = false)
{
int count = 0;
QRgb rgb = color.rgba();
- int totalCount = image.height()*image.width();
+ int totalCount = image.height() * image.width();
for (int y = 0; y < image.height(); ++y) {
for (int x = 0; x < image.width(); ++x) {
// Because of antialiasing we allow a certain range of errors here.
QRgb pixel = image.pixel(x, y);
- if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) +
- qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) +
- qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) {
+ if (qAbs(int(pixel & 0xff) - int(rgb & 0xff)) +
+ qAbs(int((pixel & 0xff00) >> 8) - int((rgb & 0xff00) >> 8)) +
+ qAbs(int((pixel & 0xff0000) >> 16) - int((rgb & 0xff0000) >> 16)) <= 50) {
count++;
if (!ensurePrimary && count >=10 )
return true;
- else if (count > totalCount/2)
+ if (count > totalCount / 2)
return true;
}
}
@@ -842,7 +899,8 @@ static bool testForColors(const QImage& image, const QColor& color, bool ensureP
return false;
}
-class TestDialog : public QDialog {
+class TestDialog : public QDialog
+{
public:
explicit TestDialog(const QString &styleSheet);
@@ -878,8 +936,8 @@ TestDialog::TestDialog(const QString &styleSheet) :
addWidget(spinbox);
QComboBox *combobox = new QComboBox;
combobox->setEditable(true);
- combobox->addItems(QStringList() << "TESTING TESTING");
- addWidget(spinbox);
+ combobox->addItems(QStringList{"TESTING TESTING"});
+ addWidget(combobox);
addWidget(new QLabel("<b>TESTING TESTING</b>"));
}
@@ -921,12 +979,12 @@ void tst_QStyleSheetStyle::focusColors()
QVERIFY2(testForColors(image, QColor(0xe8, 0xff, 0x66)),
(QString::fromLatin1(widget->metaObject()->className())
+ " did not contain background color #e8ff66, using style "
- + QString::fromLatin1(qApp->style()->metaObject()->className()))
+ + QString::fromLatin1(QApplication::style()->metaObject()->className()))
.toLocal8Bit().constData());
QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)),
(QString::fromLatin1(widget->metaObject()->className())
+ " did not contain text color #ff0084, using style "
- + QString::fromLatin1(qApp->style()->metaObject()->className()))
+ + QString::fromLatin1(QApplication::style()->metaObject()->className()))
.toLocal8Bit().constData());
}
}
@@ -1007,20 +1065,14 @@ class SingleInheritanceDialog : public QDialog
{
Q_OBJECT
public:
- SingleInheritanceDialog(QWidget *w = 0) :
- QDialog(w)
- {
- }
+ using QDialog::QDialog;
};
class DoubleInheritanceDialog : public SingleInheritanceDialog
{
Q_OBJECT
public:
- DoubleInheritanceDialog(QWidget *w = 0) :
- SingleInheritanceDialog(w)
- {
- }
+ using SingleInheritanceDialog::SingleInheritanceDialog;
};
void tst_QStyleSheetStyle::background()
@@ -1029,24 +1081,25 @@ void tst_QStyleSheetStyle::background()
const QString styleSheet = QStringLiteral("* { background-color: #e8ff66; }");
QVector<WidgetPtr> widgets;
- const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft();
+ const QPoint topLeft = m_availableGeometry.topLeft();
// Testing inheritance styling of QDialog.
WidgetPtr toplevel(new SingleInheritanceDialog);
- toplevel->resize(200, 200);
+ toplevel->resize(m_testSize);
toplevel->move(topLeft + QPoint(20, 20));
toplevel->setStyleSheet(styleSheet);
widgets.append(toplevel);
toplevel = WidgetPtr(new DoubleInheritanceDialog);
- toplevel->resize(200, 200);
- toplevel->move(topLeft + QPoint(20, 320));
+ toplevel->resize(m_testSize);
+ toplevel->move(topLeft + QPoint(20, m_testSize.height() + 120));
toplevel->setStyleSheet(styleSheet);
widgets.append(toplevel);
// Testing gradients in QComboBox.
// First color
toplevel = WidgetPtr(new QDialog);
- toplevel->move(topLeft + QPoint(320, 20));
+ toplevel->resize(m_testSize);
+ toplevel->move(topLeft + QPoint(m_testSize.width() + 120, 20));
QGridLayout *layout = new QGridLayout(toplevel.data());
QComboBox* cb = new QComboBox;
cb->setMinimumWidth(160);
@@ -1055,7 +1108,8 @@ void tst_QStyleSheetStyle::background()
widgets.append(toplevel);
// Second color
toplevel = WidgetPtr(new QDialog);
- toplevel->move(topLeft + QPoint(320, 320));
+ toplevel->resize(m_testSize);
+ toplevel->move(topLeft + QPoint(m_testSize.width() + 120, m_testSize.height() + 120));
layout = new QGridLayout(toplevel.data());
cb = new QComboBox;
cb->setMinimumWidth(160);
@@ -1086,9 +1140,10 @@ void tst_QStyleSheetStyle::background()
}
}
-void tst_QStyleSheetStyle::tabAlignement()
+void tst_QStyleSheetStyle::tabAlignment()
{
QWidget topLevel;
+ topLevel.setWindowTitle(QTest::currentTestFunction());
QTabWidget tabWidget(&topLevel);
tabWidget.addTab(new QLabel("tab1"),"tab1");
tabWidget.resize(QSize(400,400));
@@ -1148,6 +1203,8 @@ void tst_QStyleSheetStyle::attributesList()
void tst_QStyleSheetStyle::minmaxSizes()
{
QTabWidget tabWidget;
+ tabWidget.resize(m_testSize);
+ tabWidget.setWindowTitle(QTest::currentTestFunction());
tabWidget.setObjectName("tabWidget");
int index1 = tabWidget.addTab(new QLabel("Tab1"),"a");
@@ -1187,6 +1244,8 @@ void tst_QStyleSheetStyle::task206238_twice()
{
const QColor red(Qt::red);
QMainWindow w;
+ w.resize(m_testSize);
+ w.setWindowTitle(QTest::currentTestFunction());
QTabWidget* tw = new QTabWidget;
tw->addTab(new QLabel("foo"), "test");
w.setCentralWidget(tw);
@@ -1220,6 +1279,8 @@ void tst_QStyleSheetStyle::transparent()
class ProxyStyle : public QStyle
{
+ Q_OBJECT
+
public:
ProxyStyle(QStyle *s)
{
@@ -1227,19 +1288,19 @@ class ProxyStyle : public QStyle
}
void drawControl(ControlElement ce, const QStyleOption *opt,
- QPainter *painter, const QWidget *widget = 0) const;
+ QPainter *painter, const QWidget *widget = nullptr) const override;
void drawPrimitive(QStyle::PrimitiveElement pe,
const QStyleOption* opt,
- QPainter* p ,
- const QWidget* w) const
+ QPainter *p,
+ const QWidget *w) const override
{
style->drawPrimitive(pe, opt, p, w);
}
QRect subElementRect(QStyle::SubElement se,
- const QStyleOption* opt,
- const QWidget* w) const
+ const QStyleOption *opt,
+ const QWidget *w) const override
{
Q_UNUSED(se);
Q_UNUSED(opt);
@@ -1248,64 +1309,64 @@ class ProxyStyle : public QStyle
}
void drawComplexControl(QStyle::ComplexControl cc,
- const QStyleOptionComplex* opt,
- QPainter* p,
- const QWidget* w) const
+ const QStyleOptionComplex *opt,
+ QPainter *p,
+ const QWidget *w) const override
{
style->drawComplexControl(cc, opt, p, w);
}
SubControl hitTestComplexControl(QStyle::ComplexControl cc,
- const QStyleOptionComplex* opt,
- const QPoint& pt,
- const QWidget* w) const
+ const QStyleOptionComplex *opt,
+ const QPoint &pt,
+ const QWidget *w) const override
{
return style->hitTestComplexControl(cc, opt, pt, w);
}
QRect subControlRect(QStyle::ComplexControl cc,
- const QStyleOptionComplex* opt,
+ const QStyleOptionComplex *opt,
QStyle::SubControl sc,
- const QWidget* w) const
+ const QWidget *w) const override
{
return style->subControlRect(cc, opt, sc, w);
}
int pixelMetric(QStyle::PixelMetric pm,
- const QStyleOption* opt,
- const QWidget* w) const
+ const QStyleOption *opt,
+ const QWidget *w) const override
{
return style->pixelMetric(pm, opt, w);
}
QSize sizeFromContents(QStyle::ContentsType ct,
- const QStyleOption* opt,
- const QSize& size,
- const QWidget* w) const
+ const QStyleOption *opt,
+ const QSize &size,
+ const QWidget *w) const override
{
return style->sizeFromContents(ct, opt, size, w);
}
int styleHint(QStyle::StyleHint sh,
- const QStyleOption* opt,
- const QWidget* w,
- QStyleHintReturn* shr) const
+ const QStyleOption *opt,
+ const QWidget *w,
+ QStyleHintReturn *shr) const override
{
return style->styleHint(sh, opt, w, shr);
}
QPixmap standardPixmap(QStyle::StandardPixmap spix,
- const QStyleOption* opt,
- const QWidget* w) const
+ const QStyleOption *opt,
+ const QWidget *w) const override
{
return style->standardPixmap(spix, opt, w);
}
QPixmap generatedIconPixmap(QIcon::Mode mode,
- const QPixmap& pix,
- const QStyleOption* opt) const
+ const QPixmap &pix,
+ const QStyleOption *opt) const override
{
return style->generatedIconPixmap(mode, pix, opt);
}
@@ -1314,14 +1375,14 @@ class ProxyStyle : public QStyle
QSizePolicy::ControlType c2,
Qt::Orientation ori,
const QStyleOption *opt,
- const QWidget *w) const
+ const QWidget *w) const override
{
return style->layoutSpacing(c1, c2, ori, opt, w);
}
QIcon standardIcon(StandardPixmap si,
const QStyleOption *opt,
- const QWidget *w) const
+ const QWidget *w) const override
{
return style->standardIcon(si, opt, w);
}
@@ -1357,15 +1418,15 @@ void tst_QStyleSheetStyle::proxyStyle()
{
//Should not crash; task 158984
- ProxyStyle *proxy = new ProxyStyle(qApp->style());
+ ProxyStyle *proxy = new ProxyStyle(QApplication::style());
QString styleSheet("QPushButton {background-color: red; }");
QWidget *w = new QWidget;
- w->setMinimumWidth(160);
+ w->setMinimumWidth(m_testSize.width());
centerOnScreen(w);
QVBoxLayout *layout = new QVBoxLayout(w);
- QPushButton *pb1 = new QPushButton(qApp->style()->objectName(), w);
+ QPushButton *pb1 = new QPushButton(QApplication::style()->objectName(), w);
layout->addWidget(pb1);
QPushButton *pb2 = new QPushButton("ProxyStyle", w);
@@ -1383,7 +1444,7 @@ void tst_QStyleSheetStyle::proxyStyle()
// In this case it would be the QStyleSheetStyle that is deleted
// later on. We need to get access to the "real" QStyle to be able to
// draw correctly.
- ProxyStyle* newProxy = new ProxyStyle(qApp->style());
+ ProxyStyle *newProxy = new ProxyStyle(QApplication::style());
pb4->setStyle(newProxy);
layout->addWidget(pb4);
@@ -1421,6 +1482,7 @@ void tst_QStyleSheetStyle::emptyStyleSheet()
//empty stylesheet should not change anything
qApp->setStyleSheet(QString());
QWidget w;
+ w.setWindowTitle(QTest::currentTestFunction());
QHBoxLayout layout(&w);
w.setLayout(&layout);
layout.addWidget(new QPushButton("push", &w));
@@ -1479,6 +1541,8 @@ void tst_QStyleSheetStyle::toolTip()
{
qApp->setStyleSheet(QString());
QWidget w;
+ w.resize(m_testSize);
+ w.setWindowTitle(QTest::currentTestFunction());
// Use "Fusion" to prevent the Vista style from clobbering the tooltip palette in polish().
QStyle *fusionStyle = QStyleFactory::create(QLatin1String("Fusion"));
QVERIFY(fusionStyle);
@@ -1512,28 +1576,27 @@ void tst_QStyleSheetStyle::toolTip()
centerOnScreen(&w);
w.show();
- qApp->setActiveWindow(&w);
+ QApplication::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
const QColor normalToolTip = QToolTip::palette().color(QPalette::Inactive, QPalette::ToolTipBase);
- QList<QWidget *> widgets;
- QList<QColor> colors;
-
-
- //tooltip on the widget without stylesheet, then to othes widget, including one without stylesheet
- //(the tooltip will be reused but his colour must change)
- widgets << wid4 << wid1 << wid2 << wid3 << wid4;
- colors << normalToolTip << "#ae2" << "#f81" << "#0b8" << normalToolTip;
-
- for (int i = 0; i < widgets.count() ; i++)
- {
+ // Tooltip on the widget without stylesheet, then to other widget,
+ // including one without stylesheet (the tooltip will be reused,
+ // but its color must change)
+ const QWidgetList widgets{wid4, wid1, wid2, wid3, wid4};
+ const QVector<QColor> colors{normalToolTip, QColor("#ae2"), QColor("#f81"),
+ QColor("#0b8"), normalToolTip};
+
+ QWidgetList topLevels;
+ for (int i = 0; i < widgets.count() ; ++i) {
QWidget *wid = widgets.at(i);
QColor col = colors.at(i);
QToolTip::showText( QPoint(0,0) , "This is " + wid->objectName(), wid);
- QWidget *tooltip = 0;
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ topLevels = QApplication::topLevelWidgets();
+ QWidget *tooltip = nullptr;
+ for (QWidget *widget : qAsConst(topLevels)) {
if (widget->inherits("QTipLabel")) {
tooltip = widget;
break;
@@ -1548,17 +1611,18 @@ void tst_QStyleSheetStyle::toolTip()
QTest::qWait(100);
delete wid3; //should not crash;
QTest::qWait(10);
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ topLevels = QApplication::topLevelWidgets();
+ for (QWidget *widget : qAsConst(topLevels))
widget->update(); //should not crash either
- }
}
void tst_QStyleSheetStyle::embeddedFonts()
{
//task 235622 and 210551
QSpinBox spin;
- spin.setMinimumWidth(160);
- spin.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 20));
+ spin.setWindowTitle(QTest::currentTestFunction());
+ spin.setMinimumWidth(m_testSize.width());
+ spin.move(m_availableGeometry.topLeft() + QPoint(20, 20));
spin.show();
spin.setStyleSheet("QSpinBox { font-size: 32px; }");
QTest::qWait(20);
@@ -1579,7 +1643,7 @@ void tst_QStyleSheetStyle::embeddedFonts()
//task 242556
QComboBox box;
box.setMinimumWidth(160);
- box.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 120));
+ box.move(m_availableGeometry.topLeft() + QPoint(20, 120));
box.setEditable(true);
box.addItems(QStringList() << "First" << "Second" << "Third");
box.setStyleSheet("QComboBox { font-size: 32px; }");
@@ -1636,19 +1700,17 @@ void tst_QStyleSheetStyle::complexWidgetFocus()
// For this reason, we use unusual and extremely ugly colors! :-)
QDialog frame;
+ frame.setWindowTitle(QTest::currentTestFunction());
frame.setStyleSheet("*:focus { background: black; color: black } "
"QSpinBox::up-arrow:focus, QSpinBox::down-arrow:focus { width: 7px; height: 7px; background: #ff0084 } "
"QComboBox::down-arrow:focus { width: 7px; height: 7px; background: #ff0084 }"
"QSlider::handle:horizontal:focus { width: 7px; height: 7px; background: #ff0084 } ");
- QList<QWidget *> widgets;
- widgets << new QSpinBox;
- widgets << new QComboBox;
- widgets << new QSlider(Qt::Horizontal);
+ const QWidgetList widgets{new QSpinBox, new QComboBox, new QSlider(Qt::Horizontal)};
QLayout* layout = new QGridLayout;
layout->addWidget(new QLineEdit); // Avoids initial focus.
- foreach (QWidget *widget, widgets)
+ for (QWidget *widget : widgets)
layout->addWidget(widget);
frame.setLayout(layout);
@@ -1656,7 +1718,7 @@ void tst_QStyleSheetStyle::complexWidgetFocus()
frame.show();
QApplication::setActiveWindow(&frame);
QVERIFY(QTest::qWaitForWindowActive(&frame));
- foreach (QWidget *widget, widgets) {
+ for (QWidget *widget : widgets) {
widget->setFocus();
QApplication::processEvents();
@@ -1668,7 +1730,7 @@ void tst_QStyleSheetStyle::complexWidgetFocus()
QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)),
(QString::fromLatin1(widget->metaObject()->className())
+ " did not contain text color #ff0084, using style "
- + QString::fromLatin1(qApp->style()->metaObject()->className()))
+ + QString::fromLatin1(QApplication::style()->metaObject()->className()))
.toLocal8Bit().constData());
}
}
@@ -1676,8 +1738,9 @@ void tst_QStyleSheetStyle::complexWidgetFocus()
void tst_QStyleSheetStyle::task188195_baseBackground()
{
QTreeView tree;
+ tree.setWindowTitle(QTest::currentTestFunction());
tree.setStyleSheet( "QTreeView:disabled { background-color:#ab1251; }" );
- tree.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 100));
+ tree.setGeometry(QRect(m_availableGeometry.topLeft() + QPoint(20, 100), m_testSize));
tree.show();
QVERIFY(QTest::qWaitForWindowActive(&tree));
QImage image(tree.width(), tree.height(), QImage::Format_ARGB32);
@@ -1698,7 +1761,8 @@ void tst_QStyleSheetStyle::task188195_baseBackground()
QTableWidget table(12, 12);
table.setItem(0, 0, new QTableWidgetItem());
table.setStyleSheet( "QTableView {background-color: #ff0000}" );
- table.move(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(300, 100));
+ // This needs to be large so that >50% (excluding header rows/columns) are red.
+ table.setGeometry(QRect(m_availableGeometry.topLeft() + QPoint(300, 100), m_testSize * 2));
table.show();
QVERIFY(QTest::qWaitForWindowActive(&table));
image = QImage(table.width(), table.height(), QImage::Format_ARGB32);
@@ -1720,6 +1784,7 @@ void tst_QStyleSheetStyle::task232085_spinBoxLineEditBg()
spinbox->setValue(8888);
QDialog frame;
+ frame.setWindowTitle(QTest::currentTestFunction());
QLayout* layout = new QGridLayout;
QLineEdit* dummy = new QLineEdit; // Avoids initial focus.
@@ -1746,18 +1811,19 @@ void tst_QStyleSheetStyle::task232085_spinBoxLineEditBg()
QVERIFY2(testForColors(image, QColor(0xe8, 0xff, 0x66)),
(QString::fromLatin1(spinbox->metaObject()->className())
+ " did not contain background color #e8ff66, using style "
- + QString::fromLatin1(qApp->style()->metaObject()->className()))
+ + QString::fromLatin1(QApplication::style()->metaObject()->className()))
.toLocal8Bit().constData());
QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)),
(QString::fromLatin1(spinbox->metaObject()->className())
+ " did not contain text color #ff0084, using style "
- + QString::fromLatin1(qApp->style()->metaObject()->className()))
+ + QString::fromLatin1(QApplication::style()->metaObject()->className()))
.toLocal8Bit().constData());
}
class ChangeEventWidget : public QWidget
-{ public:
- void changeEvent(QEvent * event)
+{
+protected:
+ void changeEvent(QEvent *event) override
{
if(event->type() == QEvent::StyleChange) {
static bool recurse = false;
@@ -1789,10 +1855,10 @@ void tst_QStyleSheetStyle::QTBUG11658_cachecrash()
class Widget : public QWidget
{
public:
- Widget(QWidget *parent = 0)
+ Widget(int minimumWidth, QWidget *parent = nullptr)
: QWidget(parent)
{
- setMinimumWidth(160);
+ setMinimumWidth(minimumWidth);
QVBoxLayout* pLayout = new QVBoxLayout(this);
QCheckBox* pCheckBox = new QCheckBox(this);
pLayout->addWidget(pCheckBox);
@@ -1800,13 +1866,14 @@ void tst_QStyleSheetStyle::QTBUG11658_cachecrash()
QString szStyleSheet = QLatin1String("* { color: red; }");
qApp->setStyleSheet(szStyleSheet);
- qApp->setStyle(QStyleFactory::create(QLatin1String("Windows")));
+ QApplication::setStyle(QStyleFactory::create(QLatin1String("Windows")));
}
};
- Widget *w = new Widget();
+ Widget *w = new Widget(m_testSize.width());
delete w;
- w = new Widget();
+ w = new Widget(m_testSize.width());
+ w->setWindowTitle(QTest::currentTestFunction());
centerOnScreen(w);
w->show();
@@ -1818,15 +1885,17 @@ void tst_QStyleSheetStyle::QTBUG11658_cachecrash()
void tst_QStyleSheetStyle::QTBUG15910_crashNullWidget()
{
struct Widget : QWidget {
- virtual void paintEvent(QPaintEvent* ) {
+ void paintEvent(QPaintEvent *) override
+ {
QStyleOption opt;
opt.init(this);
QPainter p(this);
- style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, 0);
- style()->drawPrimitive(QStyle::PE_Frame, &opt, &p, 0);
- style()->drawControl(QStyle::CE_PushButton, &opt, &p, 0);
+ style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, nullptr);
+ style()->drawPrimitive(QStyle::PE_Frame, &opt, &p, nullptr);
+ style()->drawControl(QStyle::CE_PushButton, &opt, &p, nullptr);
}
} w;
+ w.setWindowTitle(QTest::currentTestFunction());
w.setStyleSheet("* { background-color: white; color:black; border 3px solid yellow }");
w.setMinimumWidth(160);
centerOnScreen(&w);
@@ -1840,10 +1909,13 @@ void tst_QStyleSheetStyle::QTBUG36933_brokenPseudoClassLookup()
const int columnCount = 10;
QTableWidget widget(rowCount, columnCount);
+ widget.resize(m_testSize);
+ widget.setWindowTitle(QTest::currentTestFunction());
for (int row = 0; row < rowCount; ++row) {
+ const QString rowNumber = QLatin1String("row ") + QString::number(row + 1);
for (int column = 0; column < columnCount; ++column) {
- const QString t = QLatin1String("row ") + QString::number(row + 1)
+ const QString t = rowNumber
+ QLatin1String(" column ") + QString::number(column + 1);
widget.setItem(row, column, new QTableWidgetItem(t));
}
@@ -1874,14 +1946,15 @@ void tst_QStyleSheetStyle::QTBUG36933_brokenPseudoClassLookup()
void tst_QStyleSheetStyle::styleSheetChangeBeforePolish()
{
QWidget widget;
+ widget.setWindowTitle(QTest::currentTestFunction());
QVBoxLayout *vbox = new QVBoxLayout(&widget);
QFrame *frame = new QFrame(&widget);
- frame->setFixedSize(200, 200);
+ frame->setFixedSize(m_testSize);
frame->setStyleSheet("background-color: #FF0000;");
frame->setStyleSheet("background-color: #00FF00;");
vbox->addWidget(frame);
QFrame *frame2 = new QFrame(&widget);
- frame2->setFixedSize(200, 200);
+ frame2->setFixedSize(m_testSize);
frame2->setStyleSheet("background-color: #FF0000;");
frame2->setStyleSheet("background-color: #00FF00;");
vbox->addWidget(frame);
@@ -2106,6 +2179,8 @@ void tst_QStyleSheetStyle::highdpiImages()
QFETCH(QColor, color);
QWidget w;
+ w.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("::")
+ + QLatin1String(QTest::currentDataTag()));
QScreen *screen = QGuiApplication::primaryScreen();
w.move(screen->availableGeometry().topLeft());
QHighDpiScaling::setScreenFactor(screen, screenFactor);
diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
index 5a51f15008..4ccbe42353 100644
--- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
@@ -107,8 +107,10 @@ private slots:
void csMatchingOnCiSortedModel_data();
void csMatchingOnCiSortedModel();
+#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
void directoryModel_data();
void directoryModel();
+#endif
void fileSystemModel_data();
void fileSystemModel();
@@ -224,9 +226,14 @@ void tst_QCompleter::setSourceModel(ModelType type)
parent->setText(completionColumn, QLatin1String("p2,c4p2"));
break;
case DIRECTORY_MODEL:
+#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
completer->setCsvCompletion(false);
completer->setModel(new QDirModel(completer));
completer->setCompletionColumn(0);
+QT_WARNING_POP
+#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
break;
case FILESYSTEM_MODEL:
completer->setCsvCompletion(false);
@@ -590,6 +597,7 @@ void tst_QCompleter::csMatchingOnCiSortedModel()
filter();
}
+#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
void tst_QCompleter::directoryModel_data()
{
delete completer;
@@ -639,6 +647,7 @@ void tst_QCompleter::directoryModel()
#endif
filter();
}
+#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
void tst_QCompleter::fileSystemModel_data()
{
@@ -1057,15 +1066,15 @@ void tst_QCompleter::setters()
delete completer;
completer = new CsvCompleter;
QVERIFY(completer->popup() != nullptr);
- QPointer<QDirModel> dirModel = new QDirModel(completer);
+ QPointer<QStandardItemModel> itemModel(new QStandardItemModel(1, 0, completer));
QAbstractItemModel *oldModel = completer->model();
- completer->setModel(dirModel);
+ completer->setModel(itemModel.data());
QVERIFY(completer->popup()->model() != oldModel);
QCOMPARE(completer->popup()->model(), completer->completionModel());
completer->setPopup(new QListView);
QCOMPARE(completer->popup()->model(), completer->completionModel());
completer->setModel(new QStringListModel(completer));
- QVERIFY(dirModel == nullptr); // must have been deleted
+ QVERIFY(itemModel.isNull()); // must have been deleted
completer->setModel(nullptr);
completer->setWidget(nullptr);
diff --git a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp
index 420ef56106..1b477fbbd0 100644
--- a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp
+++ b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp
@@ -295,6 +295,12 @@ void tst_QGroupBox::enabledChildPropagation()
QVERIFY(!childWidget->isEnabled());
dialog = new QDialog(&testWidget);
QVERIFY(dialog->isEnabled());
+
+ // children that are enabled after adding should still be disabled before
+ // they are shown
+ childWidget->setEnabled(true);
+ testWidget.show();
+ QVERIFY(!childWidget->isEnabled());
}
void tst_QGroupBox::sizeHint()
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 1c68a5f752..0cfbc651ad 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -4860,6 +4860,7 @@ void tst_QLineEdit::inputRejected()
QCOMPARE(spyInputRejected.count(), 0);
QTest::keyClicks(testWidget, "fgh");
QCOMPARE(spyInputRejected.count(), 3);
+#if QT_CONFIG(clipboard)
testWidget->clear();
spyInputRejected.clear();
QApplication::clipboard()->setText("ijklmno");
@@ -4867,6 +4868,7 @@ void tst_QLineEdit::inputRejected()
// The first 5 characters are accepted, but
// the last 2 are not.
QCOMPARE(spyInputRejected.count(), 1);
+#endif
testWidget->setMaxLength(INT_MAX);
testWidget->clear();
@@ -4877,11 +4879,13 @@ void tst_QLineEdit::inputRejected()
QCOMPARE(spyInputRejected.count(), 0);
QTest::keyClicks(testWidget, "a#");
QCOMPARE(spyInputRejected.count(), 2);
+#if QT_CONFIG(clipboard)
testWidget->clear();
spyInputRejected.clear();
QApplication::clipboard()->setText("a#");
testWidget->paste();
QCOMPARE(spyInputRejected.count(), 1);
+#endif
testWidget->clear();
testWidget->setValidator(0);
diff --git a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp
index 3408fc0946..f2f9cfc009 100644
--- a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp
+++ b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp
@@ -171,11 +171,8 @@ void tst_QProgressBar::format()
bar.setFormat("%v of %m (%p%)");
qApp->processEvents();
-#ifndef Q_OS_MAC
+#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN)
// Animated scroll bars get paint events all the time
-#ifdef Q_OS_WIN
- if (QOperatingSystemVersion::current() < QOperatingSystemVersion::WindowsVista)
-#endif
QVERIFY(!bar.repainted);
#endif
diff --git a/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp b/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp
index 91a9c49b00..64e4582366 100644
--- a/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp
+++ b/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp
@@ -36,6 +36,7 @@ class tst_QSplashScreen : public QObject
private slots:
void checkCloseTime();
+ void checkScreenConstructor();
};
class CloseEventSplash : public QSplashScreen
@@ -69,5 +70,16 @@ void tst_QSplashScreen::checkCloseTime()
QVERIFY(w.windowHandle()->isExposed());
}
+void tst_QSplashScreen::checkScreenConstructor()
+{
+ for (const auto screen : QGuiApplication::screens()) {
+ QSplashScreen splash(screen);
+ splash.show();
+ QCOMPARE(splash.screen(), screen);
+ QVERIFY(splash.windowHandle());
+ QCOMPARE(splash.windowHandle()->screen(), screen);
+ }
+}
+
QTEST_MAIN(tst_QSplashScreen)
#include "tst_qsplashscreen.moc"
diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
index c2cf31bfa4..b31e230893 100644
--- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
+++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
@@ -1978,8 +1978,23 @@ void tst_QTextEdit::fullWidthSelection_data()
#endif
#ifdef QT_BUILD_INTERNAL
+
+// With the fix for QTBUG-78318 scaling of documentMargin is added. The testing framework
+// forces qt_defaultDpi() to always return 96 DPI. For systems where the actual DPI differs
+// (typically 72 DPI) this would now cause scaling of the documentMargin when
+// drawing QTextEdit into QImage. In order to avoid the need of multiple reference PNGs
+// for comparison we disable the Qt::AA_Use96Dpi attribute for these tests.
+
+struct ForceSystemDpiHelper {
+ ForceSystemDpiHelper() { QCoreApplication::setAttribute(Qt::AA_Use96Dpi, false); }
+ ~ForceSystemDpiHelper() { QCoreApplication::setAttribute(Qt::AA_Use96Dpi, old); }
+ bool old = QCoreApplication::testAttribute(Qt::AA_Use96Dpi);
+};
+
void tst_QTextEdit::fullWidthSelection()
{
+ ForceSystemDpiHelper useSystemDpi;
+
QFETCH(int, cursorFrom);
QFETCH(int, cursorTo);
QFETCH(QString, imageFileName);
@@ -2048,6 +2063,8 @@ void tst_QTextEdit::fullWidthSelection()
#ifdef QT_BUILD_INTERNAL
void tst_QTextEdit::fullWidthSelection2()
{
+ ForceSystemDpiHelper useSystemDpi;
+
QPalette myPalette;
myPalette.setColor(QPalette::All, QPalette::HighlightedText, QColor(0,0,0,0));
myPalette.setColor(QPalette::All, QPalette::Highlight, QColor(239,221,85));