From c87e2c37de439996895fc2e2e4c79376b6ec1f09 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 8 Sep 2019 20:21:41 +0200 Subject: tst_QDataWidgetMapper/QFileIconProvider/ItemEditorFactory: cleanup Cleanup QDataWidgetMapper/QFileIconProvider/ItemEditorFactory autotests: - use range-based for loops - use nullptr - use member initialization - use new signal/slot syntax - use static invocations - use override Change-Id: I1a36ea2da7de1cfa5d5d4e305ef508fda3a6c460 Reviewed-by: Friedemann Kleint --- .../qdatawidgetmapper/tst_qdatawidgetmapper.cpp | 26 ++++++++++--------- .../qfileiconprovider/tst_qfileiconprovider.cpp | 29 +++++++--------------- .../qitemeditorfactory/tst_qitemeditorfactory.cpp | 8 +++--- 3 files changed, 28 insertions(+), 35 deletions(-) (limited to 'tests/auto/widgets/itemviews') diff --git a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp index 5717afab51..856672b957 100644 --- a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp +++ b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp @@ -25,15 +25,16 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + +#include #include -#include #include -#include +#include +#include +#include +#include #include #include -#include -#include -#include class tst_QDataWidgetMapper: public QObject { @@ -56,7 +57,7 @@ private slots: Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint) -static QStandardItemModel *testModel(QObject *parent = 0) +static QStandardItemModel *testModel(QObject *parent) { QStandardItemModel *model = new QStandardItemModel(10, 10, parent); @@ -84,7 +85,7 @@ void tst_QDataWidgetMapper::setModel() { // let the model go out of scope firstma QStandardItemModel model; mapper.setModel(&model); - QCOMPARE(mapper.model(), static_cast(&model)); + QCOMPARE(mapper.model(), &model); } QCOMPARE(mapper.model(), nullptr); @@ -273,7 +274,7 @@ void tst_QDataWidgetMapper::currentIndexChanged() QAbstractItemModel *model = testModel(&mapper); mapper.setModel(model); - QSignalSpy spy(&mapper, SIGNAL(currentIndexChanged(int))); + QSignalSpy spy(&mapper, &QDataWidgetMapper::currentIndexChanged); mapper.toFirst(); QCOMPARE(spy.count(), 1); @@ -405,13 +406,13 @@ void tst_QDataWidgetMapper::mappedWidgetAt() mapper.addMapping(&lineEdit1, 1); mapper.addMapping(&lineEdit2, 2); - QCOMPARE(mapper.mappedWidgetAt(1), static_cast(&lineEdit1)); - QCOMPARE(mapper.mappedWidgetAt(2), static_cast(&lineEdit2)); + QCOMPARE(mapper.mappedWidgetAt(1), &lineEdit1); + QCOMPARE(mapper.mappedWidgetAt(2), &lineEdit2); mapper.addMapping(&lineEdit2, 4242); QCOMPARE(mapper.mappedWidgetAt(2), nullptr); - QCOMPARE(mapper.mappedWidgetAt(4242), static_cast(&lineEdit2)); + QCOMPARE(mapper.mappedWidgetAt(4242), &lineEdit2); } void tst_QDataWidgetMapper::textEditDoesntChangeFocusOnTab_qtbug3305() @@ -423,7 +424,8 @@ void tst_QDataWidgetMapper::textEditDoesntChangeFocusOnTab_qtbug3305() QAbstractItemModel *model = testModel(&mapper); mapper.setModel(model); - QSignalSpy closeEditorSpy(mapper.itemDelegate(), SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); + QSignalSpy closeEditorSpy(mapper.itemDelegate(), + &QAbstractItemDelegate::closeEditor); QVERIFY(closeEditorSpy.isValid()); QWidget container; diff --git a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp index 6db1f78312..4824973576 100644 --- a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp +++ b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp @@ -27,16 +27,15 @@ ****************************************************************************/ -#include -#include -#include +#include +#include +#include class tst_QFileIconProvider : public QObject { Q_OBJECT private slots: - void qfileiconprovider_data(); void qfileiconprovider(); void iconType_data(); @@ -51,21 +50,10 @@ private slots: void taskQTBUG_46755_QFileIconEngine_crash(); }; -// Subclass that exposes the protected functions. -class SubQFileIconProvider : public QFileIconProvider -{ -public: - -}; - -void tst_QFileIconProvider::qfileiconprovider_data() -{ -} - void tst_QFileIconProvider::qfileiconprovider() { // don't crash - SubQFileIconProvider provider; + QFileIconProvider provider; } Q_DECLARE_METATYPE(QFileIconProvider::IconType) @@ -86,7 +74,7 @@ void tst_QFileIconProvider::iconType_data() void tst_QFileIconProvider::iconType() { QFETCH(QFileIconProvider::IconType, type); - SubQFileIconProvider provider; + QFileIconProvider provider; QVERIFY(!provider.icon(type).isNull()); } @@ -109,7 +97,7 @@ void tst_QFileIconProvider::iconInfo() if (setPath) QVERIFY(info.exists()); - SubQFileIconProvider provider; + QFileIconProvider provider; // we should always get an icon QVERIFY(!provider.icon(info).isNull()); } @@ -131,7 +119,7 @@ void tst_QFileIconProvider::type_data() void tst_QFileIconProvider::type() { QFETCH(QFileInfo, info); - SubQFileIconProvider provider; + QFileIconProvider provider; QVERIFY(!provider.type(info).isEmpty()); } @@ -144,7 +132,8 @@ static QIcon getIcon() void tst_QFileIconProvider::taskQTBUG_46755_QFileIconEngine_crash() { const QIcon &icon = getIcon(); - foreach (const QSize &size, icon.availableSizes()) + const auto sizes = icon.availableSizes(); + for (const QSize &size : sizes) icon.pixmap(size); // No crash, all good. diff --git a/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp b/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp index ae587279b2..ed4c543d0a 100644 --- a/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp +++ b/tests/auto/widgets/itemviews/qitemeditorfactory/tst_qitemeditorfactory.cpp @@ -25,9 +25,11 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include -#include -#include + + +#include +#include +#include class tst_QItemEditorFactory: public QObject { -- cgit v1.2.1