Mark the module as free of Q_FOREACH, except where it isn't

The density of Q_FOREACH uses is high here, too high for this author,
unfamiliar with this module, to tackle in a short amount of time. But
they're concentrated in just a few TUs, so pick a different strategy:

Mark the whole module with QT_NO_FOREACH, to prevent new uses from
creeping in, and whitelist the affected TUs by #undef'ing
QT_NO_FOREACH locally, at the top of each file. For TUs that are part
of a larger executable, this requires these files to be compiled
separately, so add them to NO_PCH_SOURCES (which implies
NO_UNITY_BUILD_SOURCES, too). Created QTBUG-115807 to keep track of
this.

Ported one that was trivial and where whitelisting of the file with a
single Q_FOREACH would have been more work than directly fixing it.

Task-number: QTBUG-115807
Change-Id: I2fa6c740e35039baf34115af7d69d6c420e4de10
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
This commit is contained in:
Marc Mutz 2023-08-05 23:48:44 +02:00
parent 0c45ec75d8
commit a84bf68892
23 changed files with 57 additions and 2 deletions

View File

@ -1,3 +1,4 @@
set(QT_REPO_MODULE_VERSION "6.7.0")
set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1")
set(QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_AS_CONST=1")
list(APPEND QT_EXTRA_INTERNAL_TARGET_DEFINES "QT_NO_FOREACH=1")

View File

@ -82,6 +82,20 @@ qt_internal_add_module(DataVisualization
utils/vertexindexer.cpp utils/vertexindexer_p.h
DEFINES
QT_NO_CONTEXTLESS_CONNECT
NO_PCH_SOURCES
# undef QT_NO_FOREACH:
engine/abstract3dcontroller.cpp
engine/abstract3drenderer.cpp
engine/axisrendercache.cpp
engine/bars3dcontroller.cpp
engine/bars3drenderer.cpp
engine/q3dscatter.cpp
engine/q3dsurface.cpp
engine/scatter3dcontroller.cpp
engine/scatter3drenderer.cpp
engine/surface3dcontroller.cpp
engine/surface3drenderer.cpp
# end undef QT_NO_FOREACH
INCLUDE_DIRECTORIES
axis
data

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "abstractdeclarativeinterface_p.h"
#include "abstract3dcontroller_p.h"
#include "qabstract3daxis_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "abstract3drenderer_p.h"
#include "texturehelper_p.h"
#include "q3dcamera_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "axisrendercache_p.h"
#include <QtGui/QFontMetrics>

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "bars3dcontroller_p.h"
#include "bars3drenderer_p.h"
#include "qvalue3daxis_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "bars3drenderer_p.h"
#include "q3dcamera_p.h"
#include "shaderhelper_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "q3dscatter.h"
#include "q3dscatter_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "q3dsurface.h"
#include "q3dsurface_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "scatter3dcontroller_p.h"
#include "scatter3drenderer_p.h"
#include "qvalue3daxis_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "scatter3drenderer_p.h"
#include "q3dcamera_p.h"
#include "shaderhelper_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "surface3dcontroller_p.h"
#include "surface3drenderer_p.h"
#include "qvalue3daxis_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "surface3drenderer_p.h"
#include "q3dcamera_p.h"
#include "shaderhelper_p.h"

View File

@ -44,6 +44,8 @@ qt_internal_add_qml_module(DataVisualizationQml
enumtostringmap.cpp enumtostringmap_p.h
foreigntypes_p.h
glstatestore.cpp glstatestore_p.h
NO_PCH_SOURCES
declarativetheme.cpp # undef QT_NO_FOREACH
DEFINES
QT_NO_CONTEXTLESS_CONNECT
QML_FILES

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "abstractdeclarative_p.h"
#include "declarativetheme_p.h"
#include "declarativerendernode_p.h"

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "declarativetheme_p.h"
QT_BEGIN_NAMESPACE

View File

@ -11,6 +11,8 @@ qt_internal_add_manual_test(barstest
buttonwrapper.cpp buttonwrapper.h
custominputhandler.cpp custominputhandler.h
main.cpp
NO_PCH_SOURCES
chart.cpp # undef QT_NO_FOREACH
)
target_link_libraries(barstest PUBLIC
Qt::Gui

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "chart.h"
#include "custominputhandler.h"
#include <QtDataVisualization/qcategory3daxis.h>

View File

@ -208,8 +208,8 @@ void GraphDataGenerator::changeSelectedButtonClicked()
{
// Change all selected cells to a random value 1-10
QVariant value = QVariant::fromValue(QRandomGenerator::global()->bounded(10.0) + 1);
QList<QTableWidgetItem *> selectedItems = m_tableWidget->selectedItems();
foreach (QTableWidgetItem *item, selectedItems) {
const QList<QTableWidgetItem *> selectedItems = m_tableWidget->selectedItems();
for (QTableWidgetItem *item : selectedItems) {
QString oldData = item->data(Qt::DisplayRole).toString();
item->setData(Qt::DisplayRole,
oldData.left(5)

View File

@ -8,6 +8,8 @@ qt_internal_add_manual_test(scattertest
SOURCES
main.cpp
scatterchart.cpp scatterchart.h
NO_PCH_SOURCES
scatterchart.cpp # undef QT_NO_FOREACH
)
target_link_libraries(scattertest PUBLIC
Qt::Gui

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "scatterchart.h"
#include <QtDataVisualization/qscatterdataproxy.h>
#include <QtDataVisualization/qscatter3dseries.h>

View File

@ -10,6 +10,8 @@ qt_internal_add_manual_test(surfacetest
checkboxwrapper.cpp checkboxwrapper.h
graphmodifier.cpp graphmodifier.h
main.cpp
NO_PCH_SOURCES
graphmodifier.cpp # undef QT_NO_FOREACH
)
target_link_libraries(surfacetest PUBLIC
Qt::Gui

View File

@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include "graphmodifier.h"
#include <QtDataVisualization/QValue3DAxis>
#include <QtDataVisualization/QSurfaceDataProxy>