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 <Friedemann.Kleint@qt.io>
This commit is contained in:
Christian Ehrlicher 2019-09-08 20:21:41 +02:00
parent 538d5bdf66
commit c87e2c37de
3 changed files with 29 additions and 36 deletions

View File

@ -25,15 +25,16 @@
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QDataWidgetMapper>
#include <QStandardItemModel>
#include <QLineEdit>
#include <QComboBox>
#include <QDataWidgetMapper>
#include <QLineEdit>
#include <QMetaType>
#include <QStandardItemModel>
#include <QSignalSpy>
#include <QTest>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QTest>
#include <QSignalSpy>
#include <QMetaType>
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<QAbstractItemModel *>(&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<QWidget *>(&lineEdit1));
QCOMPARE(mapper.mappedWidgetAt(2), static_cast<QWidget *>(&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<QWidget *>(&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;

View File

@ -27,16 +27,15 @@
****************************************************************************/
#include <QtTest/QtTest>
#include <qfileiconprovider.h>
#include <qfileinfo.h>
#include <QFileIconProvider>
#include <QFileInfo>
#include <QTest>
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.

View File

@ -25,9 +25,11 @@
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtGui/QtGui>
#include <QtWidgets/QtWidgets>
#include <QtTest/QtTest>
#include <QDoubleSpinBox>
#include <QItemEditorFactory>
#include <QTest>
class tst_QItemEditorFactory: public QObject
{