diff --git a/src/plugins/qbsprojectmanager/qbssettings.cpp b/src/plugins/qbsprojectmanager/qbssettings.cpp index 58c9b96c698..409ebcd88b0 100644 --- a/src/plugins/qbsprojectmanager/qbssettings.cpp +++ b/src/plugins/qbsprojectmanager/qbssettings.cpp @@ -13,11 +13,13 @@ #include #include #include +#include #include #include #include #include +#include using namespace Utils; @@ -52,12 +54,17 @@ static bool operator!=(const QbsSettingsData &s1, const QbsSettingsData &s2) FilePath QbsSettings::qbsExecutableFilePath() { - const QString fileName = HostOsInfo::withExecutableSuffix("qbs"); FilePath candidate = instance().m_settings.qbsExecutableFilePath; - if (!candidate.exists()) { - candidate = FilePath::fromString(QCoreApplication::applicationDirPath()) - .pathAppended(fileName); - } + if (!candidate.exists()) + candidate = defaultQbsExecutableFilePath(); + return candidate; +} + +FilePath QbsSettings::defaultQbsExecutableFilePath() +{ + const QString fileName = HostOsInfo::withExecutableSuffix("qbs"); + FilePath candidate = FilePath::fromString(QCoreApplication::applicationDirPath()) + .pathAppended(fileName); if (!candidate.exists()) candidate = Environment::systemEnvironment().searchInPath(fileName); return candidate; @@ -136,7 +143,8 @@ void QbsSettings::loadSettings() void QbsSettings::storeSettings() const { QSettings * const s = Core::ICore::settings(); - s->setValue(QBS_EXE_KEY, m_settings.qbsExecutableFilePath.toString()); + QtcSettings::setValueWithDefault(s, QBS_EXE_KEY, m_settings.qbsExecutableFilePath.toString(), + defaultQbsExecutableFilePath().toString()); s->setValue(QBS_DEFAULT_INSTALL_DIR_KEY, m_settings.defaultInstallDirTemplate); s->setValue(USE_CREATOR_SETTINGS_KEY, m_settings.useCreatorSettings); } @@ -148,6 +156,7 @@ public: { m_qbsExePathChooser.setExpectedKind(PathChooser::ExistingCommand); m_qbsExePathChooser.setFilePath(QbsSettings::qbsExecutableFilePath()); + m_resetQbsExeButton.setText(Tr::tr("Reset")); m_defaultInstallDirLineEdit.setText(QbsSettings::defaultInstallDirTemplate()); m_versionLabel.setText(getQbsVersionString()); //: %1 == "Qt Creator" or "Qt Design Studio" @@ -157,13 +166,19 @@ public: const auto layout = new QFormLayout(this); layout->addRow(&m_settingsDirCheckBox); - layout->addRow(Tr::tr("Path to qbs executable:"), &m_qbsExePathChooser); + const auto qbsExeLayout = new QHBoxLayout; + qbsExeLayout->addWidget(&m_qbsExePathChooser); + qbsExeLayout->addWidget(&m_resetQbsExeButton); + layout->addRow(Tr::tr("Path to qbs executable:"), qbsExeLayout); layout->addRow(Tr::tr("Default installation directory:"), &m_defaultInstallDirLineEdit); layout->addRow(Tr::tr("Qbs version:"), &m_versionLabel); connect(&m_qbsExePathChooser, &PathChooser::textChanged, [this] { m_versionLabel.setText(getQbsVersionString()); }); + connect(&m_resetQbsExeButton, &QPushButton::clicked, [this] { + m_qbsExePathChooser.setFilePath(QbsSettings::defaultQbsExecutableFilePath()); + }); } void apply() final @@ -185,6 +200,7 @@ private: } PathChooser m_qbsExePathChooser; + QPushButton m_resetQbsExeButton; QLabel m_versionLabel; QCheckBox m_settingsDirCheckBox; FancyLineEdit m_defaultInstallDirLineEdit; diff --git a/src/plugins/qbsprojectmanager/qbssettings.h b/src/plugins/qbsprojectmanager/qbssettings.h index a91a9059653..434a9af34f3 100644 --- a/src/plugins/qbsprojectmanager/qbssettings.h +++ b/src/plugins/qbsprojectmanager/qbssettings.h @@ -27,6 +27,7 @@ public: static QbsSettings &instance(); static Utils::FilePath qbsExecutableFilePath(); + static Utils::FilePath defaultQbsExecutableFilePath(); static Utils::FilePath qbsConfigFilePath(); static bool hasQbsExecutable(); static QString defaultInstallDirTemplate();