From b4a88aa7589d9d09fd54a5a7df29036a74293116 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 14 Dec 2017 00:29:30 +0100 Subject: examples: port away from Java-style iterators There's no reason to use them here, the Mutable is misleading in a few instances, ranged-for is much simpler, and more future-proof. Change-Id: Ifd5eaae95bbaa0b4cf0f435e6cfee6d778817b44 Reviewed-by: David Faure --- examples/opengl/legacy/overpainting/glwidget.cpp | 6 +----- examples/opengl/qopenglwidget/glwidget.cpp | 7 ++----- examples/qtconcurrent/wordcount/main.cpp | 5 +---- examples/widgets/tools/i18n/languagechooser.cpp | 7 ++----- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/examples/opengl/legacy/overpainting/glwidget.cpp b/examples/opengl/legacy/overpainting/glwidget.cpp index f98d043c5c..0094f8ead7 100644 --- a/examples/opengl/legacy/overpainting/glwidget.cpp +++ b/examples/opengl/legacy/overpainting/glwidget.cpp @@ -247,12 +247,8 @@ void GLWidget::createBubbles(int number) //! [13] void GLWidget::animate() { - QMutableListIterator iter(bubbles); - - while (iter.hasNext()) { - Bubble *bubble = iter.next(); + for (Bubble *bubble : qAsConst(bubbles)) bubble->move(rect()); - } update(); } //! [13] diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp index 946b2bec67..5057291f12 100644 --- a/examples/opengl/qopenglwidget/glwidget.cpp +++ b/examples/opengl/qopenglwidget/glwidget.cpp @@ -399,12 +399,9 @@ void GLWidget::paintGL() painter.end(); - QMutableListIterator iter(m_bubbles); - - while (iter.hasNext()) { - Bubble *bubble = iter.next(); + for (Bubble *bubble : qAsConst(m_bubbles)) bubble->move(rect()); - } + if (!(m_frames % 100)) { m_time.start(); m_frames = 0; diff --git a/examples/qtconcurrent/wordcount/main.cpp b/examples/qtconcurrent/wordcount/main.cpp index ff7ea24ee7..32cb4d0e08 100644 --- a/examples/qtconcurrent/wordcount/main.cpp +++ b/examples/qtconcurrent/wordcount/main.cpp @@ -126,11 +126,8 @@ WordCount countWords(const QString &file) // at a time. void reduce(WordCount &result, const WordCount &w) { - QMapIterator i(w); - while (i.hasNext()) { - i.next(); + for (auto i = w.begin(), end = w.end(); i != end; ++i) result[i.key()] += i.value(); - } } int main(int argc, char** argv) diff --git a/examples/widgets/tools/i18n/languagechooser.cpp b/examples/widgets/tools/i18n/languagechooser.cpp index f07d0ddee3..963165ff81 100644 --- a/examples/widgets/tools/i18n/languagechooser.cpp +++ b/examples/widgets/tools/i18n/languagechooser.cpp @@ -163,11 +163,8 @@ QStringList LanguageChooser::findQmFiles() QDir dir(":/translations"); QStringList fileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name); - QMutableStringListIterator i(fileNames); - while (i.hasNext()) { - i.next(); - i.setValue(dir.filePath(i.value())); - } + for (QString &fileName : fileNames) + fileName = dir.filePath(fileName); return fileNames; } -- cgit v1.2.3