QtWidgets tests: port remaining users away from Q_FOREACH
These are all trivial: all are over (already or newly-made) const local variables. As a drive-by, replace a QList legacy left-shift-based- with initializer_list-construction. Pick-to: 6.6 6.5 Task-number: QTBUG-115803 Change-Id: I453e24272c4c4b7dce5b91a0bd04481d833c50bb Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
6f5f10bea8
commit
40afcb9d01
@ -565,9 +565,9 @@ void tst_QWizard::addPage()
|
|||||||
|
|
||||||
#define CHECK_VISITED(wizard, list) \
|
#define CHECK_VISITED(wizard, list) \
|
||||||
do { \
|
do { \
|
||||||
QList<int> myList = list; \
|
const QList<int> myList = list; \
|
||||||
QCOMPARE((wizard).visitedIds(), myList); \
|
QCOMPARE((wizard).visitedIds(), myList); \
|
||||||
Q_FOREACH(int id, myList) \
|
for (int id : myList) \
|
||||||
QVERIFY((wizard).hasVisitedPage(id)); \
|
QVERIFY((wizard).hasVisitedPage(id)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -1837,7 +1837,8 @@ public:
|
|||||||
#define OPT(option, on) OptionInfo::instance().operation(option, on)
|
#define OPT(option, on) OptionInfo::instance().operation(option, on)
|
||||||
#define CLROPT(option) OPT(option, false)
|
#define CLROPT(option) OPT(option, false)
|
||||||
#define SETOPT(option) OPT(option, true)
|
#define SETOPT(option) OPT(option, true)
|
||||||
foreach (QWizard::WizardOption option, OptionInfo::instance().options()) {
|
const auto options = OptionInfo::instance().options();
|
||||||
|
for (QWizard::WizardOption option : options) {
|
||||||
setAllOptions[false] << CLROPT(option);
|
setAllOptions[false] << CLROPT(option);
|
||||||
setAllOptions[true] << SETOPT(option);
|
setAllOptions[true] << SETOPT(option);
|
||||||
}
|
}
|
||||||
@ -1924,7 +1925,8 @@ public:
|
|||||||
testGroup.add() << pageOp << optionOps;
|
testGroup.add() << pageOp << optionOps;
|
||||||
testGroup.createTestRows();
|
testGroup.createTestRows();
|
||||||
|
|
||||||
foreach (QWizard::WizardOption option, OptionInfo::instance().options()) {
|
const auto options = OptionInfo::instance().options();
|
||||||
|
for (QWizard::WizardOption option : options) {
|
||||||
QSharedPointer<Operation> optionOp = OPT(option, i == 1);
|
QSharedPointer<Operation> optionOp = OPT(option, i == 1);
|
||||||
testGroup.reset("testAll 4.3");
|
testGroup.reset("testAll 4.3");
|
||||||
testGroup.add() << optionOp << pageOp;
|
testGroup.add() << optionOp << pageOp;
|
||||||
@ -1947,7 +1949,8 @@ public:
|
|||||||
testGroup.add() << styleOp << optionOps;
|
testGroup.add() << styleOp << optionOps;
|
||||||
testGroup.createTestRows();
|
testGroup.createTestRows();
|
||||||
|
|
||||||
foreach (QWizard::WizardOption option, OptionInfo::instance().options()) {
|
const auto options = OptionInfo::instance().options();
|
||||||
|
for (QWizard::WizardOption option : options) {
|
||||||
QSharedPointer<Operation> optionOp = OPT(option, i == 1);
|
QSharedPointer<Operation> optionOp = OPT(option, i == 1);
|
||||||
testGroup.reset("testAll 5.3");
|
testGroup.reset("testAll 5.3");
|
||||||
testGroup.add() << optionOp << styleOp;
|
testGroup.add() << optionOp << styleOp;
|
||||||
@ -1986,7 +1989,8 @@ public:
|
|||||||
testGroup.add() << styleOp << pageOp << optionOps;
|
testGroup.add() << styleOp << pageOp << optionOps;
|
||||||
testGroup.createTestRows();
|
testGroup.createTestRows();
|
||||||
|
|
||||||
foreach (QWizard::WizardOption option, OptionInfo::instance().options()) {
|
const auto options = OptionInfo::instance().options();
|
||||||
|
for (QWizard::WizardOption option : options) {
|
||||||
QSharedPointer<Operation> optionOp = OPT(option, i == 1);
|
QSharedPointer<Operation> optionOp = OPT(option, i == 1);
|
||||||
testGroup.reset("testAll 6.5");
|
testGroup.reset("testAll 6.5");
|
||||||
testGroup.add() << optionOp << pageOp << styleOp;
|
testGroup.add() << optionOp << pageOp << styleOp;
|
||||||
@ -2570,7 +2574,8 @@ void tst_QWizard::task161658_alignments()
|
|||||||
wizard.show();
|
wizard.show();
|
||||||
QVERIFY(QTest::qWaitForWindowExposed(&wizard));
|
QVERIFY(QTest::qWaitForWindowExposed(&wizard));
|
||||||
|
|
||||||
foreach (QLabel *subtitleLabel, wizard.findChildren<QLabel *>()) {
|
const auto subtitleLabels = wizard.findChildren<QLabel *>();
|
||||||
|
for (QLabel *subtitleLabel : subtitleLabels) {
|
||||||
if (subtitleLabel->text().startsWith("SUBTITLE#")) {
|
if (subtitleLabel->text().startsWith("SUBTITLE#")) {
|
||||||
QCOMPARE(lineEdit1.mapToGlobal(lineEdit1.contentsRect().bottomRight()).x(),
|
QCOMPARE(lineEdit1.mapToGlobal(lineEdit1.contentsRect().bottomRight()).x(),
|
||||||
subtitleLabel->mapToGlobal(subtitleLabel->contentsRect().bottomRight()).x());
|
subtitleLabel->mapToGlobal(subtitleLabel->contentsRect().bottomRight()).x());
|
||||||
|
@ -2476,7 +2476,8 @@ void tst_QGraphicsProxyWidget::tooltip_basic()
|
|||||||
|
|
||||||
bool foundView = false;
|
bool foundView = false;
|
||||||
bool foundTipLabel = false;
|
bool foundTipLabel = false;
|
||||||
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
|
const auto widgets = QApplication::topLevelWidgets();
|
||||||
|
for (QWidget *widget : widgets) {
|
||||||
if (widget == &view)
|
if (widget == &view)
|
||||||
foundView = true;
|
foundView = true;
|
||||||
if (widget->inherits("QTipLabel"))
|
if (widget->inherits("QTipLabel"))
|
||||||
|
@ -1049,9 +1049,9 @@ void tst_QGraphicsView::rotated_rubberBand()
|
|||||||
sendMouseMove(view.viewport(), QPoint(midWidth + 2, view.viewport()->height()),
|
sendMouseMove(view.viewport(), QPoint(midWidth + 2, view.viewport()->height()),
|
||||||
Qt::LeftButton, Qt::LeftButton);
|
Qt::LeftButton, Qt::LeftButton);
|
||||||
QCOMPARE(scene.selectedItems().size(), dim);
|
QCOMPARE(scene.selectedItems().size(), dim);
|
||||||
foreach (const QGraphicsItem *item, scene.items()) {
|
const auto items = scene.items();
|
||||||
|
for (const QGraphicsItem *item : items)
|
||||||
QCOMPARE(item->isSelected(), item->data(0).toBool());
|
QCOMPARE(item->isSelected(), item->data(0).toBool());
|
||||||
}
|
|
||||||
sendMouseRelease(view.viewport(), QPoint(), Qt::LeftButton);
|
sendMouseRelease(view.viewport(), QPoint(), Qt::LeftButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2739,7 +2739,8 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState2()
|
|||||||
rectB->setTransform(QTransform::fromTranslate(200, 200));
|
rectB->setTransform(QTransform::fromTranslate(200, 200));
|
||||||
rectB->setPen(QPen(Qt::black, 0));
|
rectB->setPen(QPen(Qt::black, 0));
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, scene.items())
|
const auto items = scene.items();
|
||||||
|
for (QGraphicsItem *item : items)
|
||||||
item->setOpacity(0.6);
|
item->setOpacity(0.6);
|
||||||
|
|
||||||
CustomView view(&scene);
|
CustomView view(&scene);
|
||||||
@ -3258,7 +3259,8 @@ protected:
|
|||||||
{
|
{
|
||||||
++mouseMoves;
|
++mouseMoves;
|
||||||
QGraphicsView::mouseMoveEvent(event);
|
QGraphicsView::mouseMoveEvent(event);
|
||||||
foreach (QGraphicsItem *item, scene()->items()) {
|
const auto items = scene()->items();
|
||||||
|
for (QGraphicsItem *item : items) {
|
||||||
scene()->removeItem(item);
|
scene()->removeItem(item);
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ private slots:
|
|||||||
static inline int visibleTopLevelWidgetCount()
|
static inline int visibleTopLevelWidgetCount()
|
||||||
{
|
{
|
||||||
int result= 0;
|
int result= 0;
|
||||||
foreach (const QWidget *topLevel, QApplication::topLevelWidgets()) {
|
const auto topLevels = QApplication::topLevelWidgets();
|
||||||
|
for (const QWidget *topLevel : topLevels) {
|
||||||
if (topLevel->isVisible())
|
if (topLevel->isVisible())
|
||||||
++result;
|
++result;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,8 @@ void tst_QToolTip::keyEvent()
|
|||||||
|
|
||||||
static QWidget *findWhatsThat()
|
static QWidget *findWhatsThat()
|
||||||
{
|
{
|
||||||
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
|
const auto widgets = QApplication::topLevelWidgets();
|
||||||
|
for (QWidget *widget : widgets) {
|
||||||
if (widget->inherits("QWhatsThat"))
|
if (widget->inherits("QWhatsThat"))
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
@ -4717,7 +4717,8 @@ void tst_QLineEdit::sideWidgets()
|
|||||||
testWidget.move(300, 300);
|
testWidget.move(300, 300);
|
||||||
testWidget.show();
|
testWidget.show();
|
||||||
QVERIFY(QTest::qWaitForWindowExposed(&testWidget));
|
QVERIFY(QTest::qWaitForWindowExposed(&testWidget));
|
||||||
foreach (QToolButton *button, lineEdit->findChildren<QToolButton *>())
|
const auto buttons = lineEdit->findChildren<QToolButton *>();
|
||||||
|
for (QToolButton *button : buttons)
|
||||||
QCOMPARE(button->cursor().shape(), Qt::ArrowCursor);
|
QCOMPARE(button->cursor().shape(), Qt::ArrowCursor);
|
||||||
// Arbitrarily add/remove actions, trying to detect crashes. Add QTRY_VERIFY(false) to view the result.
|
// Arbitrarily add/remove actions, trying to detect crashes. Add QTRY_VERIFY(false) to view the result.
|
||||||
delete label3Action;
|
delete label3Action;
|
||||||
@ -4732,7 +4733,8 @@ void tst_QLineEdit::sideWidgets()
|
|||||||
|
|
||||||
template <class T> T *findAssociatedWidget(const QAction *a)
|
template <class T> T *findAssociatedWidget(const QAction *a)
|
||||||
{
|
{
|
||||||
foreach (QObject *w, a->associatedObjects()) {
|
const auto associatedObjects = a->associatedObjects();
|
||||||
|
for (QObject *w : associatedObjects) {
|
||||||
if (T *result = qobject_cast<T *>(w))
|
if (T *result = qobject_cast<T *>(w))
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1361,8 +1361,8 @@ void tst_QMenuBar::menubarSizeHint()
|
|||||||
|
|
||||||
mb.setStyle(&style);
|
mb.setStyle(&style);
|
||||||
//this is a list of arbitrary strings so that we check the geometry
|
//this is a list of arbitrary strings so that we check the geometry
|
||||||
QStringList list = QStringList() << "trer" << "ezrfgtgvqd" << "sdgzgzerzerzer" << "eerzertz" << "er";
|
const auto list = QStringList{"trer", "ezrfgtgvqd", "sdgzgzerzerzer", "eerzertz", "er"};
|
||||||
foreach(QString str, list)
|
for (const QString &str : list)
|
||||||
mb.addAction(str);
|
mb.addAction(str);
|
||||||
|
|
||||||
const int panelWidth = style.pixelMetric(QStyle::PM_MenuBarPanelWidth);
|
const int panelWidth = style.pixelMetric(QStyle::PM_MenuBarPanelWidth);
|
||||||
@ -1373,7 +1373,8 @@ void tst_QMenuBar::menubarSizeHint()
|
|||||||
centerOnScreen(&mb);
|
centerOnScreen(&mb);
|
||||||
mb.show();
|
mb.show();
|
||||||
QRect result;
|
QRect result;
|
||||||
foreach(QAction *action, mb.actions()) {
|
const auto actions = mb.actions();
|
||||||
|
for (QAction *action : actions) {
|
||||||
const QRect actionRect = mb.actionGeometry(action);
|
const QRect actionRect = mb.actionGeometry(action);
|
||||||
if (!result.isNull()) //this is the first item
|
if (!result.isNull()) //this is the first item
|
||||||
QCOMPARE(actionRect.left() - result.right() - 1, spacing);
|
QCOMPARE(actionRect.left() - result.right() - 1, spacing);
|
||||||
|
@ -995,7 +995,7 @@ void tst_QPlainTextEdit::copyAvailable_data()
|
|||||||
//Tests the copyAvailable slot for several cases
|
//Tests the copyAvailable slot for several cases
|
||||||
void tst_QPlainTextEdit::copyAvailable()
|
void tst_QPlainTextEdit::copyAvailable()
|
||||||
{
|
{
|
||||||
QFETCH(pairListType,keystrokes);
|
QFETCH(const pairListType, keystrokes);
|
||||||
QFETCH(QList<bool>, copyAvailable);
|
QFETCH(QList<bool>, copyAvailable);
|
||||||
QFETCH(QString, function);
|
QFETCH(QString, function);
|
||||||
|
|
||||||
@ -1008,9 +1008,8 @@ void tst_QPlainTextEdit::copyAvailable()
|
|||||||
QSignalSpy spyCopyAvailabe(ed, SIGNAL(copyAvailable(bool)));
|
QSignalSpy spyCopyAvailabe(ed, SIGNAL(copyAvailable(bool)));
|
||||||
|
|
||||||
//Execute Keystrokes
|
//Execute Keystrokes
|
||||||
foreach(keyPairType keyPair, keystrokes) {
|
for (keyPairType keyPair : keystrokes)
|
||||||
QTest::keyClick(ed, keyPair.first, keyPair.second );
|
QTest::keyClick(ed, keyPair.first, keyPair.second );
|
||||||
}
|
|
||||||
|
|
||||||
//Execute ed->"function"
|
//Execute ed->"function"
|
||||||
if (function == "cut")
|
if (function == "cut")
|
||||||
|
@ -1352,7 +1352,7 @@ void tst_QTextEdit::copyAvailable_data()
|
|||||||
//Tests the copyAvailable slot for several cases
|
//Tests the copyAvailable slot for several cases
|
||||||
void tst_QTextEdit::copyAvailable()
|
void tst_QTextEdit::copyAvailable()
|
||||||
{
|
{
|
||||||
QFETCH(pairListType,keystrokes);
|
QFETCH(const pairListType, keystrokes);
|
||||||
QFETCH(QList<bool>, copyAvailable);
|
QFETCH(QList<bool>, copyAvailable);
|
||||||
QFETCH(QString, function);
|
QFETCH(QString, function);
|
||||||
|
|
||||||
@ -1365,9 +1365,8 @@ void tst_QTextEdit::copyAvailable()
|
|||||||
QSignalSpy spyCopyAvailabe(ed, SIGNAL(copyAvailable(bool)));
|
QSignalSpy spyCopyAvailabe(ed, SIGNAL(copyAvailable(bool)));
|
||||||
|
|
||||||
//Execute Keystrokes
|
//Execute Keystrokes
|
||||||
foreach(keyPairType keyPair, keystrokes) {
|
for (keyPairType keyPair : keystrokes)
|
||||||
QTest::keyClick(ed, keyPair.first, keyPair.second );
|
QTest::keyClick(ed, keyPair.first, keyPair.second );
|
||||||
}
|
|
||||||
|
|
||||||
//Execute ed->"function"
|
//Execute ed->"function"
|
||||||
if (function == "cut")
|
if (function == "cut")
|
||||||
|
Loading…
Reference in New Issue
Block a user