QmlProject: Add simple way to change between Qt6/Qt5 kits

The feature is only available in QDS mode.
This adds a combobox to the run configuration which allows
the easy selection of a Qt 5 or Qt 6 kit.


Task-number: QDS-4733
Change-Id: I53fae9fe4bc415e5b1e8d385ef85ed81b8010b3a
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
Thomas Hartmann
2021-08-03 18:33:38 +02:00
parent 9b17a2b283
commit 4a4e124b07

View File

@@ -34,12 +34,14 @@
#include <coreplugin/icore.h>
#include <coreplugin/idocument.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
#include <projectexplorer/environmentaspect.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtsupportconstants.h>
@@ -64,6 +66,14 @@ namespace Internal {
// QmlProjectRunConfiguration
static bool isQtDesignStudio()
{
QSettings *settings = Core::ICore::settings();
const QString qdsStandaloneEntry = "QML/Designer/StandAloneMode"; //entry from qml settings
return settings->value(qdsStandaloneEntry, false).toBool();
}
class QmlProjectRunConfiguration final : public RunConfiguration
{
Q_DECLARE_TR_FUNCTIONS(QmlProjectManager::QmlProjectRunConfiguration)
@@ -78,10 +88,12 @@ private:
QString mainScript() const;
FilePath qmlRuntimeFilePath() const;
QString commandLineArguments() const;
void createQtVersionAspect();
StringAspect *m_qmlViewerAspect = nullptr;
QmlMainFileAspect *m_qmlMainFileAspect = nullptr;
QmlMultiLanguageAspect *m_multiLanguageAspect = nullptr;
SelectionAspect *m_qtversionAspect = nullptr;
};
QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
@@ -103,6 +115,8 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
m_qmlMainFileAspect = addAspect<QmlMainFileAspect>(target);
connect(m_qmlMainFileAspect, &QmlMainFileAspect::changed, this, &RunConfiguration::update);
createQtVersionAspect();
connect(target, &Target::kitChanged, this, &RunConfiguration::update);
m_multiLanguageAspect = addAspect<QmlMultiLanguageAspect>(target);
@@ -223,6 +237,70 @@ QString QmlProjectRunConfiguration::commandLineArguments() const
return args;
}
void QmlProjectRunConfiguration::createQtVersionAspect()
{
if (!isQtDesignStudio())
return;
m_qtversionAspect = addAspect<SelectionAspect>();
m_qtversionAspect->setDisplayStyle(SelectionAspect::DisplayStyle::ComboBox);
m_qtversionAspect->setLabelText(tr("Qt Version:"));
m_qtversionAspect->setSettingsKey("QmlProjectManager.kit");
Kit *kit = target()->kit();
BaseQtVersion *version = QtKitAspect::qtVersion(kit);
if (version) {
const QmlBuildSystem *buildSystem = qobject_cast<QmlBuildSystem *>(target()->buildSystem());
const bool isQt6Project = buildSystem && buildSystem->qt6Project();
if (isQt6Project) {
m_qtversionAspect->addOption(tr("Qt 6"));
m_qtversionAspect->setReadOnly(true);
} else { /* Only if this is not a Qt 6 project changing kits makes sense */
m_qtversionAspect->addOption(tr("Qt 5"));
m_qtversionAspect->addOption(tr("Qt 6"));
const int valueForVersion = version->qtVersion().majorVersion == 6 ? 1 : 0;
m_qtversionAspect->setValue(valueForVersion);
connect(m_qtversionAspect, &SelectionAspect::changed, this, [&]() {
QTC_ASSERT(target(), return );
auto project = target()->project();
QTC_ASSERT(project, return );
int oldValue = !m_qtversionAspect->value();
const int preferedQtVersion = m_qtversionAspect->value() > 0 ? 6 : 5;
Kit *currentKit = target()->kit();
const QList<Kit *> kits = Utils::filtered(KitManager::kits(), [&](const Kit *k) {
QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(k);
return (version && version->qtVersion().majorVersion == preferedQtVersion)
&& DeviceTypeKitAspect::deviceTypeId(k)
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
});
if (kits.contains(currentKit))
return;
if (!kits.isEmpty()) {
auto newTarget = target()->project()->target(kits.first());
if (!newTarget)
newTarget = project->addTargetForKit(kits.first());
SessionManager::setActiveTarget(project, newTarget, SetActive::Cascade);
/* Reset the aspect. We changed the target and this aspect should not change. */
m_qtversionAspect->blockSignals(true);
m_qtversionAspect->setValue(oldValue);
m_qtversionAspect->blockSignals(false);
}
});
}
}
}
bool QmlProjectRunConfiguration::isEnabled() const
{
return m_qmlMainFileAspect->isQmlFilePresent() && !commandLine().executable().isEmpty()