diff options
author | Marc Mutz <[email protected]> | 2019-07-10 21:21:17 +0200 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2019-07-15 14:21:25 +0200 |
commit | 874f8ef3b9fb9d80a2b05c264ca48464e31257e2 (patch) | |
tree | 2a1213104b290a196e71f57e928befc38a20c992 | |
parent | 0a8d24180e11a093656a8efe31370a591115a96f (diff) |
Eradicate Java-style iterators and Q_FOREACH and mark the module free of them
... and QLinkedList.
Java-style iterators are scheduled to be deprecated, or at the very
least banned from use in Qt's own implementation. Ditto Q_FOREACH.
Ditto QLinkedList.
Change-Id: I92eb5c22762b63cba45f8eaf717c1b7d458fcda4
Reviewed-by: Volker Hilsheimer <[email protected]>
Reviewed-by: Andy Shaw <[email protected]>
Reviewed-by: Mitch Curtis <[email protected]>
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | examples/quickcontrols/controls/tableview/src/sortfilterproxymodel.cpp | 18 | ||||
-rw-r--r-- | examples/quickcontrols/controls/texteditor/src/documenthandler.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp | 16 | ||||
-rw-r--r-- | tests/auto/shared/testmodel.h | 3 | ||||
-rw-r--r-- | tests/benchmarks/objectcount/tst_objectcount.cpp | 4 |
6 files changed, 18 insertions, 28 deletions
diff --git a/.qmake.conf b/.qmake.conf index 92f4428e3..eb6b6a3bc 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -2,4 +2,6 @@ load(qt_build_config) CONFIG += warning_clean android|ios|qnx|isEmpty(QT.widgets.name): CONFIG += no_desktop +DEFINES += QT_NO_FOREACH QT_NO_JAVA_STYLE_ITERATORS QT_NO_LINKED_LIST + MODULE_VERSION = 5.14.0 diff --git a/examples/quickcontrols/controls/tableview/src/sortfilterproxymodel.cpp b/examples/quickcontrols/controls/tableview/src/sortfilterproxymodel.cpp index b93641a90..1e47f23e5 100644 --- a/examples/quickcontrols/controls/tableview/src/sortfilterproxymodel.cpp +++ b/examples/quickcontrols/controls/tableview/src/sortfilterproxymodel.cpp @@ -132,11 +132,8 @@ QJSValue SortFilterProxyModel::get(int idx) const QJSValue value = engine->newObject(); if (idx >= 0 && idx < count()) { QHash<int, QByteArray> roles = roleNames(); - QHashIterator<int, QByteArray> it(roles); - while (it.hasNext()) { - it.next(); + for (auto it = roles.cbegin(), end = roles.cend(); it != end; ++it) value.setProperty(QString::fromUtf8(it.value()), data(index(idx, 0), it.key()).toString()); - } } return value; } @@ -156,14 +153,7 @@ void SortFilterProxyModel::componentComplete() int SortFilterProxyModel::roleKey(const QByteArray &role) const { - QHash<int, QByteArray> roles = roleNames(); - QHashIterator<int, QByteArray> it(roles); - while (it.hasNext()) { - it.next(); - if (it.value() == role) - return it.key(); - } - return -1; + return roleNames().key(role, -1); } QHash<int, QByteArray> SortFilterProxyModel::roleNames() const @@ -181,9 +171,7 @@ bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &so QAbstractItemModel *model = sourceModel(); if (filterRole().isEmpty()) { QHash<int, QByteArray> roles = roleNames(); - QHashIterator<int, QByteArray> it(roles); - while (it.hasNext()) { - it.next(); + for (auto it = roles.cbegin(), end = roles.cend(); it != end; ++it) { QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent); QString key = model->data(sourceIndex, it.key()).toString(); if (key.contains(rx)) diff --git a/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp b/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp index 69da88f0b..ac9f5bd47 100644 --- a/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp +++ b/examples/quickcontrols/controls/texteditor/src/documenthandler.cpp @@ -345,7 +345,8 @@ QStringList DocumentHandler::defaultFontSizes() const // uhm... this is quite ugly QStringList sizes; QFontDatabase db; - foreach (int size, db.standardSizes()) + const auto standardSizes = db.standardSizes(); + for (int size : standardSizes) sizes.append(QString::number(size)); return sizes; } diff --git a/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp b/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp index 0fec548d8..c035c6760 100644 --- a/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp +++ b/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp @@ -1181,8 +1181,8 @@ void tst_QQuickTreeModelAdaptor::reparentOnSameRow() // at least DepthRole and ModeIndexRole changes should have happened for the affected row bool depthChanged = false; bool modelIndexChanged = false; - QList<QList<QVariant> > &changes = dataChangedSpy; - foreach (QList<QVariant> change, changes) { + const QList<QList<QVariant> > &changes = dataChangedSpy; + for (const QList<QVariant> &change : changes) { if (change.at(0) == movedIndex) { if (change.at(2).value<QVector<int> >().contains(QQuickTreeModelAdaptor1::DepthRole)) depthChanged = true; @@ -1258,7 +1258,7 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() QCOMPARE(sel.count(), 2); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. - foreach (const QItemSelectionRange &range, sel) { + for (const QItemSelectionRange &range : sel) { if (range.topLeft() == model.index(0, 0)) QCOMPARE(QModelIndex(range.bottomRight()), model.index(0, 0)); else if (range.topLeft() == model.index(0, 0, parent)) @@ -1275,7 +1275,7 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() QCOMPARE(sel.count(), 2); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. - foreach (const QItemSelectionRange &range, sel) { + for (const QItemSelectionRange &range : sel) { if (range.topLeft() == model.index(0, 0)) QCOMPARE(QModelIndex(range.bottomRight()), model.index(4, 0)); else if (range.topLeft() == model.index(0, 0, parent)) @@ -1296,7 +1296,7 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() QCOMPARE(sel.count(), 3); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. - foreach (const QItemSelectionRange &range, sel) { + for (const QItemSelectionRange &range : sel) { if (range.topLeft() == model.index(0, 0)) QCOMPARE(QModelIndex(range.bottomRight()), model.index(4, 0)); else if (range.topLeft() == model.index(0, 0, parent)) @@ -1319,7 +1319,7 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() QCOMPARE(sel.count(), 3); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. - foreach (const QItemSelectionRange &range, sel) { + for (const QItemSelectionRange &range : sel) { if (range.topLeft() == model.index(0, 0)) QCOMPARE(QModelIndex(range.bottomRight()), model.index(0, 0)); else if (range.topLeft() == model.index(0, 0, parent)) @@ -1338,7 +1338,7 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() QCOMPARE(sel.count(), 4); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. - foreach (const QItemSelectionRange &range, sel) { + for (const QItemSelectionRange &range : sel) { if (range.topLeft() == model.index(0, 0)) QCOMPARE(QModelIndex(range.bottomRight()), model.index(ModelRowCount - 1, 0)); else if (range.topLeft() == model.index(0, 0, parent)) @@ -1359,7 +1359,7 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() QCOMPARE(sel.count(), 4); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. - foreach (const QItemSelectionRange &range, sel) { + for (const QItemSelectionRange &range : sel) { if (range.topLeft() == model.index(1, 0)) QCOMPARE(QModelIndex(range.bottomRight()), model.index(1, 0)); else if (range.topLeft() == model.index(1, 0, parent)) diff --git a/tests/auto/shared/testmodel.h b/tests/auto/shared/testmodel.h index 6eaab74aa..b1d9308e4 100644 --- a/tests/auto/shared/testmodel.h +++ b/tests/auto/shared/testmodel.h @@ -289,8 +289,7 @@ public: ~Node() { - foreach (Node *n, children) - delete n; + qDeleteAll(children); } void addRows(int row, int count) diff --git a/tests/benchmarks/objectcount/tst_objectcount.cpp b/tests/benchmarks/objectcount/tst_objectcount.cpp index c57971603..996b4b66c 100644 --- a/tests/benchmarks/objectcount/tst_objectcount.cpp +++ b/tests/benchmarks/objectcount/tst_objectcount.cpp @@ -83,7 +83,7 @@ static void printItems(const QList<QQuickItem *> &items) std::cout << " QQuickItems: " << items.count() << " (total of QObjects: " << qt_qobjects->count() << ")" << std::endl; if (qt_verbose) { - foreach (QObject *object, *qt_qobjects) + for (QObject *object : qAsConst(*qt_qobjects)) qInfo() << "\t" << object; } } @@ -101,7 +101,7 @@ void tst_ObjectCount::controls() QVERIFY2(object.data(), qPrintable(component.errorString())); QList<QQuickItem *> items; - foreach (QObject *object, *qt_qobjects()) { + for (QObject *object : qAsConst(*qt_qobjects)) { QQuickItem *item = qobject_cast<QQuickItem *>(object); if (item) items += item; |