From 7e7a98bae3a2508883d4ef7f649c1d14947ada1a Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 22 Nov 2024 14:24:10 +0100 Subject: [PATCH 1/2] qAsConst is deprecated, use std::as_const --- .../test/tst_KDStlContainerAdaptor.cpp | 11 ++++++++--- qt/model_view/updateableModel/UpdateableModel.h | 4 ++++ qt/tabWindow/src/tabwindow.cpp | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/qt/KDStlContainerAdaptor/test/tst_KDStlContainerAdaptor.cpp b/qt/KDStlContainerAdaptor/test/tst_KDStlContainerAdaptor.cpp index bea08f7..575a693 100644 --- a/qt/KDStlContainerAdaptor/test/tst_KDStlContainerAdaptor.cpp +++ b/qt/KDStlContainerAdaptor/test/tst_KDStlContainerAdaptor.cpp @@ -70,6 +70,11 @@ void tst_KDStlContainerAdaptor::vectorAdaptorIterators() QCOMPARE(result, 15); } +// For Qt5 (without C++17) and Qt6/C++17 compatibility +template struct AddConst { typedef const T type; }; +template constexpr typename AddConst::type &asConst(T &t) noexcept { return t; } +template void asConst(const T &&) = delete; // prevent rvalue arguments + void tst_KDStlContainerAdaptor::vectorAdaptorDataAccess() { IntVec v{1, 2, 3, 4, 5}; @@ -80,7 +85,7 @@ void tst_KDStlContainerAdaptor::vectorAdaptorDataAccess() QCOMPARE(v.constData()[i], expected); QCOMPARE(v.at(i), expected); QCOMPARE(v[i], expected); - QCOMPARE(qAsConst(v)[i], expected); + QCOMPARE(asConst(v)[i], expected); QCOMPARE(v.value(i), expected); } @@ -93,14 +98,14 @@ void tst_KDStlContainerAdaptor::vectorAdaptorDataAccess() QCOMPARE(v.first(), -1); v.first() = 123; QCOMPARE(v.first(), 123); - QCOMPARE(qAsConst(v).first(), 123); + QCOMPARE(asConst(v).first(), 123); QCOMPARE(v.constFirst(), 123); v[4] = -1; QCOMPARE(v.last(), -1); v.last() = 456; QCOMPARE(v.last(), 456); - QCOMPARE(qAsConst(v).last(), 456); + QCOMPARE(asConst(v).last(), 456); QCOMPARE(v.constLast(), 456); } diff --git a/qt/model_view/updateableModel/UpdateableModel.h b/qt/model_view/updateableModel/UpdateableModel.h index b10e158..1df1c64 100644 --- a/qt/model_view/updateableModel/UpdateableModel.h +++ b/qt/model_view/updateableModel/UpdateableModel.h @@ -352,7 +352,11 @@ class UpdateableModel : public BaseModel // reconstruct vector of changed roles QVector roles; roles.reserve(m_changedRoles.count()); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + for (int role : std::as_const(m_changedRoles)) +#else for (int role : qAsConst(m_changedRoles)) +#endif { roles.append(role); } diff --git a/qt/tabWindow/src/tabwindow.cpp b/qt/tabWindow/src/tabwindow.cpp index b8df920..7041ed4 100644 --- a/qt/tabWindow/src/tabwindow.cpp +++ b/qt/tabWindow/src/tabwindow.cpp @@ -82,7 +82,11 @@ void TabWindowManager::removeWindow(TabWindow *window) TabWindow *TabWindowManager::possibleWindow(TabWindow *currentWindow, QPoint globalPos) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + for (auto tabWindow : std::as_const(m_windows)) +#else for (auto tabWindow : qAsConst(m_windows)) +#endif { if (tabWindow == currentWindow) continue; From 97c2f49b27ad0d3cb492904f8cfe08c8860e1acc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:24:52 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../test/tst_KDStlContainerAdaptor.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/qt/KDStlContainerAdaptor/test/tst_KDStlContainerAdaptor.cpp b/qt/KDStlContainerAdaptor/test/tst_KDStlContainerAdaptor.cpp index 575a693..fe00ac2 100644 --- a/qt/KDStlContainerAdaptor/test/tst_KDStlContainerAdaptor.cpp +++ b/qt/KDStlContainerAdaptor/test/tst_KDStlContainerAdaptor.cpp @@ -71,9 +71,18 @@ void tst_KDStlContainerAdaptor::vectorAdaptorIterators() } // For Qt5 (without C++17) and Qt6/C++17 compatibility -template struct AddConst { typedef const T type; }; -template constexpr typename AddConst::type &asConst(T &t) noexcept { return t; } -template void asConst(const T &&) = delete; // prevent rvalue arguments +template +struct AddConst +{ + typedef const T type; +}; +template +constexpr typename AddConst::type &asConst(T &t) noexcept +{ + return t; +} +template +void asConst(const T &&) = delete; // prevent rvalue arguments void tst_KDStlContainerAdaptor::vectorAdaptorDataAccess() {