From f114197ba3f88b50f5f315934944e58d97473a29 Mon Sep 17 00:00:00 2001 From: Antoine C Date: Sat, 19 Oct 2024 21:11:08 +0100 Subject: [PATCH] fixup! Fix "Use QLatin1String("") or QString() instead of an empty QStringLiteral [-Wclazy-empty-qstringliteral]" error --- .../legacy/controllerscriptenginelegacy.cpp | 28 +++++++------------ .../legacy/controllerscriptenginelegacy.h | 9 +++--- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp b/src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp index 88c030d005b6..ce3846387dbb 100644 --- a/src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp +++ b/src/controllers/scripting/legacy/controllerscriptenginelegacy.cpp @@ -1,5 +1,7 @@ #include "controllers/scripting/legacy/controllerscriptenginelegacy.h" +#include + #ifdef MIXXX_USE_QML #include #include @@ -114,13 +116,8 @@ bool ControllerScriptEngineLegacy::callShutdownFunction() { return callFunctionOnObjects(m_scriptFunctionPrefixes, "shutdown"); #ifdef MIXXX_USE_QML } else { - QHashIterator i(m_rootItems); bool success = true; - while (i.hasNext()) { - i.next(); - const auto& screen = i.value(); - const QString& screenIdentifier = i.key(); - + for (const auto& [screenIdentifier, screen] : m_rootItems) { if (!screen->getShutdown().isCallable()) { qCDebug(m_logger) << "QML Scene for screen" << screenIdentifier << "has no valid shutdown method."; @@ -159,12 +156,7 @@ bool ControllerScriptEngineLegacy::callInitFunction() { return callFunctionOnObjects(m_scriptFunctionPrefixes, "init", args, true); #ifdef MIXXX_USE_QML } else { - QHashIterator i(m_rootItems); - while (i.hasNext()) { - i.next(); - const auto& screen = i.value(); - const QString& screenIdentifier = i.key(); - + for (const auto& [screenIdentifier, screen] : m_rootItems) { if (!screen->getInit().isCallable()) { qCDebug(m_logger) << "QML Scene for screen" << screenIdentifier << "has no valid init method."; @@ -480,7 +472,7 @@ bool ControllerScriptEngineLegacy::bindSceneToScreen( // evaluating it. watchFilePath(qmlFile.file.absoluteFilePath()); - auto* pScene = loadQMLFile(qmlFile, pScreen); + auto pScene = loadQMLFile(qmlFile, pScreen); if (!pScene) { VERIFY_OR_DEBUG_ASSERT(!pScreen->isValid() || !pScreen->isRunning() || pScreen->stop()) { @@ -494,7 +486,7 @@ bool ControllerScriptEngineLegacy::bindSceneToScreen( this, &ControllerScriptEngineLegacy::handleScreenFrame); m_renderingScreens.insert(screenIdentifier, pScreen); - m_rootItems.insert(screenIdentifier, pScene); + m_rootItems.emplace(screenIdentifier, std::move(pScene)); // In case a rendering issue occurs, we need to shutdown the controller // since its only purpose is to render screens. This might not be the case // in the future controller modules @@ -519,7 +511,7 @@ void ControllerScriptEngineLegacy::handleScreenFrame( return; }; - auto* pScreen = m_rootItems.value(screenInfo.identifier); + auto& pScreen = m_rootItems.at(screenInfo.identifier); if (CmdlineArgs::Instance().getControllerPreviewScreens()) { QImage screenDebug(frame); @@ -742,7 +734,7 @@ bool ControllerScriptEngineLegacy::evaluateScriptFile(const QFileInfo& scriptFil } #ifdef MIXXX_USE_QML -mixxx::qml::QmlMixxxControllerScreen* ControllerScriptEngineLegacy::loadQMLFile( +std::unique_ptr ControllerScriptEngineLegacy::loadQMLFile( const LegacyControllerMapping::ScriptFileInfo& qmlScript, std::shared_ptr pScreen) { VERIFY_OR_DEBUG_ASSERT(m_pJSEngine || @@ -806,7 +798,7 @@ mixxx::qml::QmlMixxxControllerScreen* ControllerScriptEngineLegacy::loadQMLFile( mixxx::qml::QmlMixxxControllerScreen* rootItem = qobject_cast(pRootObject); if (!rootItem) { - qWarning("run: Not a QQuickItem"); + qWarning("run: Not a MixxxControllerScreen"); delete pRootObject; return nullptr; } @@ -820,7 +812,7 @@ mixxx::qml::QmlMixxxControllerScreen* ControllerScriptEngineLegacy::loadQMLFile( rootItem->setHeight(pScreen->quickWindow()->height()); } - return rootItem; + return std::unique_ptr(rootItem); } #endif diff --git a/src/controllers/scripting/legacy/controllerscriptenginelegacy.h b/src/controllers/scripting/legacy/controllerscriptenginelegacy.h index 19d93c7826ce..df4d29d9607b 100644 --- a/src/controllers/scripting/legacy/controllerscriptenginelegacy.h +++ b/src/controllers/scripting/legacy/controllerscriptenginelegacy.h @@ -4,6 +4,7 @@ #include #include #include +#include #ifdef MIXXX_USE_QML #include #endif @@ -89,8 +90,7 @@ class ControllerScriptEngineLegacy : public ControllerScriptEngineBase { std::shared_ptr pScreen); void extractTransformFunction(const QMetaObject* metaObject, const QString& screenIdentifier); - // The returned QmlMixxxController will be owned and managed by the pScreen - mixxx::qml::QmlMixxxControllerScreen* loadQMLFile( + std::unique_ptr loadQMLFile( const LegacyControllerMapping::ScriptFileInfo& qmlScript, std::shared_ptr pScreen); @@ -120,9 +120,8 @@ class ControllerScriptEngineLegacy : public ControllerScriptEngineBase { QHash> m_renderingScreens; // Contains all the scenes loaded for this mapping. Key is the scene // identifier (LegacyControllerMapping::ScreenInfo::identifier), value in - // the QML root item. Note that the pointer is owned by the QML scene which - // will free them on shutdown (ControllerScriptEngineLegacy::shutdown) - QHash m_rootItems; + // the QML root item. + std::unordered_map> m_rootItems; QList m_modules; QList m_infoScreens; QString m_resourcePath{QStringLiteral(".")};