diff --git a/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp b/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp index 1dc194f8425..d02d099e3e1 100644 --- a/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp +++ b/src/plugins/qmldesigner/qmldesignerexternaldependencies.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -135,54 +136,6 @@ bool ExternalDependencies::hasStartupTarget() const namespace { -Utils::FilePath qmlPuppetExecutablePath(const Utils::FilePath &workingDirectory) -{ - return workingDirectory.pathAppended(QString{"qml2puppet-"} + Core::Constants::IDE_VERSION_LONG) - .withExecutableSuffix(); -} - -Utils::FilePath qmlPuppetFallbackDirectory(const DesignerSettings &settings) -{ - auto puppetFallbackDirectory = Utils::FilePath::fromString( - settings.value(DesignerSettingsKey::PUPPET_DEFAULT_DIRECTORY).toString()); - if (puppetFallbackDirectory.isEmpty() || !puppetFallbackDirectory.exists()) - return Core::ICore::libexecPath(); - return puppetFallbackDirectory; -} - -std::pair qmlPuppetFallbackPaths(const DesignerSettings &settings) -{ - auto workingDirectory = qmlPuppetFallbackDirectory(settings); - - return {workingDirectory, qmlPuppetExecutablePath(workingDirectory)}; -} - -std::pair pathsForKitPuppet(ProjectExplorer::Target *target) -{ - if (!target || !target->kit()) - return {}; - - QtSupport::QtVersion *currentQtVersion = QtSupport::QtKitAspect::qtVersion(target->kit()); - - if (currentQtVersion) { - auto path = currentQtVersion->binPath(); - return {path, qmlPuppetExecutablePath(path)}; - } - - return {}; -} - -std::pair qmlPuppetPaths(ProjectExplorer::Target *target, - const DesignerSettings &settings) -{ - auto [workingDirectoryPath, puppetPath] = pathsForKitPuppet(target); - - if (workingDirectoryPath.isEmpty() || !puppetPath.exists()) - return qmlPuppetFallbackPaths(settings); - - return {workingDirectoryPath, puppetPath}; -} - bool isForcingFreeType(ProjectExplorer::Target *target) { if (Utils::HostOsInfo::isWindowsHost() && target) { @@ -209,7 +162,7 @@ PuppetStartData ExternalDependencies::puppetStartData(const Model &model) const { PuppetStartData data; auto target = ProjectExplorer::SessionManager::startupTarget(); - auto [workingDirectory, puppetPath] = qmlPuppetPaths(target, m_designerSettings); + auto [workingDirectory, puppetPath] = QmlPuppetPaths::qmlPuppetPaths(target, m_designerSettings); data.puppetPath = puppetPath.toString(); data.workingDirectoryPath = workingDirectory.toString(); @@ -229,7 +182,7 @@ bool ExternalDependencies::instantQmlTextUpdate() const Utils::FilePath ExternalDependencies::qmlPuppetPath() const { auto target = ProjectExplorer::SessionManager::startupTarget(); - auto [workingDirectory, puppetPath] = qmlPuppetPaths(target, m_designerSettings); + auto [workingDirectory, puppetPath] = QmlPuppetPaths::qmlPuppetPaths(target, m_designerSettings); return puppetPath; } diff --git a/src/plugins/qmldesignerbase/CMakeLists.txt b/src/plugins/qmldesignerbase/CMakeLists.txt index 73d35db10f0..63698d96443 100644 --- a/src/plugins/qmldesignerbase/CMakeLists.txt +++ b/src/plugins/qmldesignerbase/CMakeLists.txt @@ -1,6 +1,6 @@ add_qtc_plugin(QmlDesignerBase DEPENDS Qt::Core - PLUGIN_DEPENDS Core ProjectExplorer + PLUGIN_DEPENDS Core ProjectExplorer QtSupport SOURCES qmldesignerbase_global.h qmldesignerbaseplugin.cpp qmldesignerbaseplugin.h @@ -11,4 +11,5 @@ extend_qtc_plugin(QmlDesignerBase SOURCES_PREFIX ${CMAKE_CURRENT_LIST_DIR}/utils SOURCES designersettings.cpp designersettings.h + qmlpuppetpaths.cpp qmlpuppetpaths.h ) diff --git a/src/plugins/qmldesignerbase/utils/qmlpuppetpaths.cpp b/src/plugins/qmldesignerbase/utils/qmlpuppetpaths.cpp new file mode 100644 index 00000000000..d73ea62ea97 --- /dev/null +++ b/src/plugins/qmldesignerbase/utils/qmlpuppetpaths.cpp @@ -0,0 +1,70 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 + +#include "qmlpuppetpaths.h" + +#include "designersettings.h" + +#include +#include +#include +#include +#include +#include + +namespace QmlDesigner { +namespace QmlPuppetPaths { + +namespace { + +Utils::FilePath qmlPuppetExecutablePath(const Utils::FilePath &workingDirectory) +{ + return workingDirectory.pathAppended(QString{"qml2puppet-"} + Core::Constants::IDE_VERSION_LONG) + .withExecutableSuffix(); +} + +Utils::FilePath qmlPuppetFallbackDirectory(const DesignerSettings &settings) +{ + auto puppetFallbackDirectory = Utils::FilePath::fromString( + settings.value(DesignerSettingsKey::PUPPET_DEFAULT_DIRECTORY).toString()); + if (puppetFallbackDirectory.isEmpty() || !puppetFallbackDirectory.exists()) + return Core::ICore::libexecPath(); + return puppetFallbackDirectory; +} + +std::pair qmlPuppetFallbackPaths(const DesignerSettings &settings) +{ + auto workingDirectory = qmlPuppetFallbackDirectory(settings); + + return {workingDirectory, qmlPuppetExecutablePath(workingDirectory)}; +} + +std::pair pathsForKitPuppet(ProjectExplorer::Target *target) +{ + if (!target || !target->kit()) + return {}; + + QtSupport::QtVersion *currentQtVersion = QtSupport::QtKitAspect::qtVersion(target->kit()); + + if (currentQtVersion) { + auto path = currentQtVersion->binPath(); + return {path, qmlPuppetExecutablePath(path)}; + } + + return {}; +} +} // namespace + +std::pair qmlPuppetPaths(ProjectExplorer::Target *target, + const DesignerSettings &settings) +{ + auto [workingDirectoryPath, puppetPath] = pathsForKitPuppet(target); + + if (workingDirectoryPath.isEmpty() || !puppetPath.exists()) + return qmlPuppetFallbackPaths(settings); + + return {workingDirectoryPath, puppetPath}; +} + +} // namespace QmlPuppetPaths +} // namespace QmlDesigner diff --git a/src/plugins/qmldesignerbase/utils/qmlpuppetpaths.h b/src/plugins/qmldesignerbase/utils/qmlpuppetpaths.h new file mode 100644 index 00000000000..711ab100a20 --- /dev/null +++ b/src/plugins/qmldesignerbase/utils/qmlpuppetpaths.h @@ -0,0 +1,18 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 + +#include "../qmldesignerbase_global.h" + +#include + +namespace ProjectExplorer { +class Target; +} +namespace QmlDesigner { +class DesignerSettings; + +namespace QmlPuppetPaths { +QMLDESIGNERBASE_EXPORT std::pair qmlPuppetPaths( + ProjectExplorer::Target *target, const DesignerSettings &settings); +} +} // namespace QmlDesigner diff --git a/src/plugins/qmlprojectmanager/CMakeLists.txt b/src/plugins/qmlprojectmanager/CMakeLists.txt index 64dec0f86b9..5ecc763ef73 100644 --- a/src/plugins/qmlprojectmanager/CMakeLists.txt +++ b/src/plugins/qmlprojectmanager/CMakeLists.txt @@ -2,7 +2,7 @@ add_qtc_plugin(QmlProjectManager CONDITION TARGET Qt5::QuickWidgets PLUGIN_CLASS QmlProjectPlugin DEPENDS QmlJS Qt5::QuickWidgets - PLUGIN_DEPENDS Core ProjectExplorer QtSupport + PLUGIN_DEPENDS Core ProjectExplorer QtSupport QmlDesignerBase SOURCES fileformat/filefilteritems.cpp fileformat/filefilteritems.h fileformat/qmlprojectfileformat.cpp fileformat/qmlprojectfileformat.h diff --git a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp index f88d6d24d9f..d996ac93fdd 100644 --- a/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp +++ b/src/plugins/qmlprojectmanager/qmlprojectrunconfiguration.cpp @@ -2,10 +2,12 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 #include "qmlprojectrunconfiguration.h" -#include "qmlproject.h" -#include "qmlprojectmanagerconstants.h" #include "qmlmainfileaspect.h" #include "qmlmultilanguageaspect.h" +#include "qmlproject.h" +#include "qmlprojectmanagerconstants.h" + +#include // getting the qmlpuppet path from setings #include @@ -26,6 +28,8 @@ #include #include +#include + #include #include @@ -43,51 +47,6 @@ using namespace ProjectExplorer; using namespace QtSupport; using namespace Utils; -namespace { -Utils::FilePath qmlPuppetPath(const Utils::FilePath puppetDirectoryPath) -{ - return puppetDirectoryPath.pathAppended(QString{"qml2puppet-"} + - Core::Constants::IDE_VERSION_LONG).withExecutableSuffix(); -} - -Utils::FilePath qmlPuppetPathFromSettings() -{ - const char PUPPET_DEFAULT_DIRECTORY[] = "PuppetDefaultDirectory"; - const char QML_SETTINGS_GROUP[] = "QML"; - const char QML_DESIGNER_SETTINGS_GROUP[] = "Designer"; - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup(QLatin1String(QML_SETTINGS_GROUP)); - settings->beginGroup(QLatin1String(QML_DESIGNER_SETTINGS_GROUP)); - - auto puppetFallbackDirectory = Utils::FilePath::fromString( - settings->value(PUPPET_DEFAULT_DIRECTORY).toString()); - - settings->endGroup(); - settings->endGroup(); - - if (!puppetFallbackDirectory.isEmpty() && puppetFallbackDirectory.exists()) - return qmlPuppetPath(puppetFallbackDirectory); - - return {}; -} - -Utils::FilePath puppetAsQmlRuntime(QtVersion *version) -{ - if (version->qtVersion() >= QVersionNumber(6, 4, 0)) { - Utils::FilePath qmlPuppetFilePath = qmlPuppetPathFromSettings(); - if (qmlPuppetFilePath.isExecutableFile()) - return qmlPuppetFilePath; - else { - qmlPuppetFilePath = qmlPuppetPath(version->binPath()); - if (qmlPuppetFilePath.isExecutableFile()) - return qmlPuppetFilePath; - } - } - return {}; -} - -} // namespace - namespace QmlProjectManager { class QmlMultiLanguageAspect; namespace Internal { @@ -231,10 +190,11 @@ FilePath QmlProjectRunConfiguration::qmlRuntimeFilePath() const // If not given explicitly by Qt Version, try to pick it from $PATH. const bool isDesktop = version->type() == QtSupport::Constants::DESKTOPQT; - Utils::FilePath puppetAsQmlRuntimePath = puppetAsQmlRuntime(version); - if (!puppetAsQmlRuntimePath.isEmpty()) { + auto [workingDirectoryPath, puppetPath] = QmlDesigner::QmlPuppetPaths::qmlPuppetPaths( + target(), QmlDesigner::QmlDesignerBasePlugin::settings()); + if (!puppetPath.isEmpty()) { usePuppetAsQmlRuntime = true; - return puppetAsQmlRuntimePath; + return puppetPath; } return isDesktop ? version->qmlRuntimeFilePath() : "qmlscene";