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);
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user