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>
This commit is contained in:
parent
208f22300a
commit
923e08132c
@ -166,24 +166,22 @@ void tst_QActionGroup::separators()
|
|||||||
separator->setSeparator(true);
|
separator->setSeparator(true);
|
||||||
actGroup.addAction(separator);
|
actGroup.addAction(separator);
|
||||||
|
|
||||||
QListIterator<QAction*> it(actGroup.actions());
|
menu.addActions(actGroup.actions());
|
||||||
while (it.hasNext())
|
|
||||||
menu.addAction(it.next());
|
|
||||||
|
|
||||||
QCOMPARE((int)menu.actions().size(), 2);
|
QCOMPARE((int)menu.actions().size(), 2);
|
||||||
|
|
||||||
it = QListIterator<QAction*>(actGroup.actions());
|
const auto removeActions = [&menu](const QList<QAction *> &actions) {
|
||||||
while (it.hasNext())
|
for (QAction *action : actions)
|
||||||
menu.removeAction(it.next());
|
menu.removeAction(action);
|
||||||
|
};
|
||||||
|
removeActions(actGroup.actions());
|
||||||
|
|
||||||
QCOMPARE((int)menu.actions().size(), 0);
|
QCOMPARE((int)menu.actions().size(), 0);
|
||||||
|
|
||||||
action = new QAction(&actGroup);
|
action = new QAction(&actGroup);
|
||||||
action->setText("test two");
|
action->setText("test two");
|
||||||
|
|
||||||
it = QListIterator<QAction*>(actGroup.actions());
|
menu.addActions(actGroup.actions());
|
||||||
while (it.hasNext())
|
|
||||||
menu.addAction(it.next());
|
|
||||||
|
|
||||||
QCOMPARE((int)menu.actions().size(), 3);
|
QCOMPARE((int)menu.actions().size(), 3);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user