diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-12-17 01:05:14 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-05-22 05:15:39 +0000 |
commit | 923e08132cfd0c9140e705a7f0f27b3432f94695 (patch) | |
tree | 8e0ef7f6c0e304e986e4adc458bb0bb373211b16 /tests | |
parent | 208f22300aa611292d9bdaaddf04708a53c577c8 (diff) |
tst_QActionGroup: avoid Java-style iterators
They are going to be deprecated soon.
Use a lambda to mimic the adjacent addActions() calls.
Also, I didn't want to add a scope or extend the lifetime
of the return value of actions() until the end of the
function, and
for (QAction *action : actGroup.action())
would detach. I'd've made it a helper function, but it's
used only once, so... a lambda.
Change-Id: I2b3aae463036fd61a9cca7b4ef991b8752869bf3
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp index 52ca10d31f..0ba3cedf16 100644 --- a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp +++ b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp @@ -166,24 +166,22 @@ void tst_QActionGroup::separators() separator->setSeparator(true); actGroup.addAction(separator); - QListIterator<QAction*> it(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 2); - it = QListIterator<QAction*>(actGroup.actions()); - while (it.hasNext()) - menu.removeAction(it.next()); + const auto removeActions = [&menu](const QList<QAction *> &actions) { + for (QAction *action : actions) + menu.removeAction(action); + }; + removeActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 0); action = new QAction(&actGroup); action->setText("test two"); - it = QListIterator<QAction*>(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); QCOMPARE((int)menu.actions().size(), 3); } |