From 363b0e20cd5a9b492f415341a25c5c9f9b0543c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Fri, 20 Oct 2023 20:53:45 +0200 Subject: [PATCH] Introduce wrapper for non const iterators for erase and insert --- src/preferences/dialog/dlgprefmixer.cpp | 6 +++--- src/util/make_const_iterator.h | 27 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/preferences/dialog/dlgprefmixer.cpp b/src/preferences/dialog/dlgprefmixer.cpp index d00b0611946e..a0266a413617 100644 --- a/src/preferences/dialog/dlgprefmixer.cpp +++ b/src/preferences/dialog/dlgprefmixer.cpp @@ -56,7 +56,7 @@ constexpr int kFrequencyLowerLimit = 16; constexpr int kXfaderGridHLines = 3; constexpr int kXfaderGridVLines = 5; -bool isMixingEQ(EffectManifest* pManifest) { +bool isMixingEQ(const EffectManifest* pManifest) { return pManifest->isMixingEQ(); } @@ -1175,11 +1175,11 @@ const QList DlgPrefMixer::getDeckEqManifests() const { allManifests.end(), [](const auto& pManifest) { return isMixingEQ(pManifest.data()); }); if (m_eqEffectsOnly) { - constErase(&allManifests, nonEqsStartIt, allManifests.end()); + erase(&allManifests, nonEqsStartIt, allManifests.end()); } else { // Add a null item between EQs and non-EQs. The combobox fill function // will use this to insert a separator. - constInsert(&allManifests, nonEqsStartIt, EffectManifestPointer()); + insert(&allManifests, nonEqsStartIt, EffectManifestPointer()); } return allManifests; } diff --git a/src/util/make_const_iterator.h b/src/util/make_const_iterator.h index 9b53387eaab5..2ab4c6107244 100644 --- a/src/util/make_const_iterator.h +++ b/src/util/make_const_iterator.h @@ -34,6 +34,15 @@ typename C::const_iterator constErase(C* pContainer, I begin, I end) { #endif } +template +typename C::iterator erase(C* pContainer, I begin, I end) { +#if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return pContainer->erase(C::const_iterator > (begin), C::const_iterator > (end)); +#else + return pContainer->erase(begin, end); +#endif +} + template typename C::const_iterator constErase(C* pContainer, I it) { #if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -43,6 +52,15 @@ typename C::const_iterator constErase(C* pContainer, I it) { #endif } +template +typename C::iterator erase(C* pContainer, I it) { +#if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return pContainer->erase(C::const_iterator > (it)); +#else + return pContainer->erase(it); +#endif +} + template typename C::const_iterator constInsert(C* pContainer, I before, T t) { #if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -52,3 +70,12 @@ typename C::const_iterator constInsert(C* pContainer, I before, T t) { pContainer->insert(make_iterator(pContainer, before), t)); #endif } + +template +typename C::iterator insert(C* pContainer, I before, T t) { +#if defined(QT_VERSION) && QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return pContainer->insert(C::const_iterator > (before), std::move(t)); +#else + return pContainer->insert(before, t); +#endif +}