11#include " controllers/scripting/legacy/controllerscriptenginelegacy.h"
22
3+ #include < memory>
4+
35#ifdef MIXXX_USE_QML
46#include < QDirIterator>
57#include < QQmlEngine>
@@ -114,13 +116,8 @@ bool ControllerScriptEngineLegacy::callShutdownFunction() {
114116 return callFunctionOnObjects (m_scriptFunctionPrefixes, " shutdown" );
115117#ifdef MIXXX_USE_QML
116118 } else {
117- QHashIterator<QString, mixxx::qml::QmlMixxxControllerScreen*> i (m_rootItems);
118119 bool success = true ;
119- while (i.hasNext ()) {
120- i.next ();
121- const auto & screen = i.value ();
122- const QString& screenIdentifier = i.key ();
123-
120+ for (const auto & [screenIdentifier, screen] : m_rootItems) {
124121 if (!screen->getShutdown ().isCallable ()) {
125122 qCDebug (m_logger) << " QML Scene for screen" << screenIdentifier
126123 << " has no valid shutdown method." ;
@@ -159,12 +156,7 @@ bool ControllerScriptEngineLegacy::callInitFunction() {
159156 return callFunctionOnObjects (m_scriptFunctionPrefixes, " init" , args, true );
160157#ifdef MIXXX_USE_QML
161158 } else {
162- QHashIterator<QString, mixxx::qml::QmlMixxxControllerScreen*> i (m_rootItems);
163- while (i.hasNext ()) {
164- i.next ();
165- const auto & screen = i.value ();
166- const QString& screenIdentifier = i.key ();
167-
159+ for (const auto & [screenIdentifier, screen] : m_rootItems) {
168160 if (!screen->getInit ().isCallable ()) {
169161 qCDebug (m_logger) << " QML Scene for screen" << screenIdentifier
170162 << " has no valid init method." ;
@@ -480,7 +472,7 @@ bool ControllerScriptEngineLegacy::bindSceneToScreen(
480472 // evaluating it.
481473 watchFilePath (qmlFile.file .absoluteFilePath ());
482474
483- auto * pScene = loadQMLFile (qmlFile, pScreen);
475+ auto pScene = loadQMLFile (qmlFile, pScreen);
484476 if (!pScene) {
485477 VERIFY_OR_DEBUG_ASSERT (!pScreen->isValid () ||
486478 !pScreen->isRunning () || pScreen->stop ()) {
@@ -494,7 +486,7 @@ bool ControllerScriptEngineLegacy::bindSceneToScreen(
494486 this ,
495487 &ControllerScriptEngineLegacy::handleScreenFrame);
496488 m_renderingScreens.insert (screenIdentifier, pScreen);
497- m_rootItems.insert (screenIdentifier, pScene);
489+ m_rootItems.emplace (screenIdentifier, std::move ( pScene) );
498490 // In case a rendering issue occurs, we need to shutdown the controller
499491 // since its only purpose is to render screens. This might not be the case
500492 // in the future controller modules
@@ -519,7 +511,7 @@ void ControllerScriptEngineLegacy::handleScreenFrame(
519511 return ;
520512 };
521513
522- auto * pScreen = m_rootItems.value (screenInfo.identifier );
514+ auto & pScreen = m_rootItems.at (screenInfo.identifier );
523515
524516 if (CmdlineArgs::Instance ().getControllerPreviewScreens ()) {
525517 QImage screenDebug (frame);
@@ -742,7 +734,7 @@ bool ControllerScriptEngineLegacy::evaluateScriptFile(const QFileInfo& scriptFil
742734}
743735
744736#ifdef MIXXX_USE_QML
745- mixxx::qml::QmlMixxxControllerScreen* ControllerScriptEngineLegacy::loadQMLFile (
737+ std::unique_ptr< mixxx::qml::QmlMixxxControllerScreen> ControllerScriptEngineLegacy::loadQMLFile (
746738 const LegacyControllerMapping::ScriptFileInfo& qmlScript,
747739 std::shared_ptr<ControllerRenderingEngine> pScreen) {
748740 VERIFY_OR_DEBUG_ASSERT (m_pJSEngine ||
@@ -806,7 +798,7 @@ mixxx::qml::QmlMixxxControllerScreen* ControllerScriptEngineLegacy::loadQMLFile(
806798 mixxx::qml::QmlMixxxControllerScreen* rootItem =
807799 qobject_cast<mixxx::qml::QmlMixxxControllerScreen*>(pRootObject);
808800 if (!rootItem) {
809- qWarning (" run: Not a QQuickItem " );
801+ qWarning (" run: Not a MixxxControllerScreen " );
810802 delete pRootObject;
811803 return nullptr ;
812804 }
@@ -820,7 +812,7 @@ mixxx::qml::QmlMixxxControllerScreen* ControllerScriptEngineLegacy::loadQMLFile(
820812 rootItem->setHeight (pScreen->quickWindow ()->height ());
821813 }
822814
823- return rootItem;
815+ return std::unique_ptr<mixxx::qml::QmlMixxxControllerScreen>( rootItem) ;
824816}
825817#endif
826818
0 commit comments