From f2aaf68b0c8cea30423de68dbb7cc685e49a1c28 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 28 Jun 2023 17:14:43 +0200 Subject: [PATCH] ProjectExplorer: Use FilePathAspect(s) in ExecutableAspect In the read-only case, make it look like the previously used StringAspect with LabelDisplay. Change-Id: Ica76c1ba23bf9b3946c227e303cc1336f3f8d5b4 Reviewed-by: Christian Stenger Reviewed-by: Reviewed-by: Christian Kandeler --- src/libs/utils/aspects.cpp | 44 +++++++------------ src/libs/utils/aspects.h | 1 - src/libs/utils/pathchooser.cpp | 3 +- .../baremetal/baremetalrunconfiguration.cpp | 3 +- src/plugins/ios/iosrunconfiguration.cpp | 1 - .../customexecutablerunconfiguration.cpp | 2 +- .../runconfigurationaspects.cpp | 13 ++---- .../projectexplorer/runconfigurationaspects.h | 6 +-- src/plugins/remotelinux/makeinstallstep.cpp | 2 +- .../remotelinuxcustomrunconfiguration.cpp | 2 +- 10 files changed, 30 insertions(+), 47 deletions(-) diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index 456010c78d8..8571bffe3c3 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -329,6 +329,8 @@ void BaseAspect::setReadOnly(bool readOnly) lineEdit->setReadOnly(readOnly); else if (auto textEdit = qobject_cast(w)) textEdit->setReadOnly(readOnly); + else if (auto pathChooser = qobject_cast(w)) + pathChooser->setReadOnly(readOnly); } } @@ -806,28 +808,6 @@ QString StringAspect::value() const return TypedAspect::value(); } -/*! - Sets the value, \a val, of this StringAspect from an ordinary \c QString. -*/ -void StringAspect::setValue(const QString &val) -{ - const bool isSame = val == value(); - if (isSame) - return; - - QString processedValue = val; - if (d->m_valueAcceptor) { - const std::optional tmp = d->m_valueAcceptor(value(), val); - if (!tmp) { - internalToGui(); // Make sure the original value is retained in the UI - return; - } - processedValue = tmp.value(); - } - - TypedAspect::setValue(processedValue); -} - /*! \reimp */ @@ -1124,6 +1104,7 @@ void StringAspect::addToLayout(LayoutItem &parent) d->m_pathChooserDisplay->setPromptDialogTitle(d->m_prompDialogTitle); d->m_pathChooserDisplay->setCommandVersionArguments(d->m_commandVersionArguments); d->m_pathChooserDisplay->setAllowPathFromDevice(d->m_allowPathFromDevice); + d->m_pathChooserDisplay->setReadOnly(isReadOnly()); d->m_pathChooserDisplay->lineEdit()->setValidatePlaceHolder(d->m_validatePlaceHolder); if (defaultValue() == value()) d->m_pathChooserDisplay->setDefaultValue(defaultValue()); @@ -1141,7 +1122,7 @@ void StringAspect::addToLayout(LayoutItem &parent) if (d->m_blockAutoApply) return; d->m_blockAutoApply = true; - setValueQuietly(d->m_pathChooserDisplay->filePath().toString()); + setValue(d->m_pathChooserDisplay->filePath().toString()); d->m_blockAutoApply = false; }; connect(d->m_pathChooserDisplay, &PathChooser::editingFinished, this, setPathChooserValue); @@ -1149,7 +1130,7 @@ void StringAspect::addToLayout(LayoutItem &parent) } else { connect(d->m_pathChooserDisplay, &PathChooser::textChanged, this, [this](const QString &path) { - setValueQuietly(path); + setValue(path); }); } } @@ -1234,21 +1215,30 @@ void StringAspect::addToLayout(LayoutItem &parent) void StringAspect::guiToInternal() { + QString val; switch (d->m_displayStyle) { case PathChooserDisplay: if (d->m_pathChooserDisplay) - m_internal = d->m_pathChooserDisplay->lineEdit()->text(); + val = d->m_pathChooserDisplay->lineEdit()->text(); break; case LineEditDisplay: if (d->m_lineEditDisplay) - m_internal = d->m_lineEditDisplay->text(); + val = d->m_lineEditDisplay->text(); break; case TextEditDisplay: if (d->m_textEditDisplay) - m_internal = d->m_textEditDisplay->document()->toPlainText(); + val = d->m_textEditDisplay->document()->toPlainText(); case LabelDisplay: break; } + + if (d->m_valueAcceptor) { + const std::optional tmp = d->m_valueAcceptor(m_internal, val); + if (tmp) + m_internal = *tmp; + } else { + m_internal = val; + } } void StringAspect::internalToGui() diff --git a/src/libs/utils/aspects.h b/src/libs/utils/aspects.h index eafceeddb32..8d9307e6685 100644 --- a/src/libs/utils/aspects.h +++ b/src/libs/utils/aspects.h @@ -456,7 +456,6 @@ public: void setValueAcceptor(ValueAcceptor &&acceptor); QString value() const; - void setValue(const QString &val); void setShowToolTipOnLabel(bool show); diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index a13471ef07f..c3054ec3cac 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -377,9 +377,10 @@ bool PathChooser::isReadOnly() const void PathChooser::setReadOnly(bool b) { d->m_lineEdit->setReadOnly(b); + d->m_lineEdit->setFrame(!b); const auto buttons = d->m_buttons; for (QAbstractButton *button : buttons) - button->setEnabled(!b); + button->setVisible(!b); } void PathChooser::slotBrowse(bool remote) diff --git a/src/plugins/baremetal/baremetalrunconfiguration.cpp b/src/plugins/baremetal/baremetalrunconfiguration.cpp index 4fe6b090246..bc880467903 100644 --- a/src/plugins/baremetal/baremetalrunconfiguration.cpp +++ b/src/plugins/baremetal/baremetalrunconfiguration.cpp @@ -26,7 +26,6 @@ public: : RunConfiguration(target, id) { const auto exeAspect = addAspect(target, ExecutableAspect::RunDevice); - exeAspect->setDisplayStyle(StringAspect::LabelDisplay); exeAspect->setPlaceHolderText(Tr::tr("Unknown")); addAspect(macroExpander()); @@ -50,7 +49,7 @@ public: const auto exeAspect = addAspect(target, ExecutableAspect::RunDevice); exeAspect->setSettingsKey("BareMetal.CustomRunConfig.Executable"); exeAspect->setPlaceHolderText(Tr::tr("Unknown")); - exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay); + exeAspect->setReadOnly(false); exeAspect->setHistoryCompleter("BareMetal.CustomRunConfig.History"); exeAspect->setExpectedKind(PathChooser::Any); diff --git a/src/plugins/ios/iosrunconfiguration.cpp b/src/plugins/ios/iosrunconfiguration.cpp index 8a0a3e62dcf..d10ddbe4d80 100644 --- a/src/plugins/ios/iosrunconfiguration.cpp +++ b/src/plugins/ios/iosrunconfiguration.cpp @@ -59,7 +59,6 @@ IosRunConfiguration::IosRunConfiguration(Target *target, Id id) : RunConfiguration(target, id) { auto executableAspect = addAspect(target, ExecutableAspect::RunDevice); - executableAspect->setDisplayStyle(StringAspect::LabelDisplay); addAspect(macroExpander()); diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp index 00f7225d0df..1673c874d53 100644 --- a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp +++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp @@ -28,7 +28,7 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe auto exeAspect = addAspect(target, ExecutableAspect::HostDevice); exeAspect->setSettingsKey("ProjectExplorer.CustomExecutableRunConfiguration.Executable"); - exeAspect->setDisplayStyle(StringAspect::PathChooserDisplay); + exeAspect->setReadOnly(false); exeAspect->setHistoryCompleter("Qt.CustomExecutable.History"); exeAspect->setExpectedKind(PathChooser::ExistingCommand); exeAspect->setEnvironment(envAspect->environment()); diff --git a/src/plugins/projectexplorer/runconfigurationaspects.cpp b/src/plugins/projectexplorer/runconfigurationaspects.cpp index 52b594d0a14..5d44872439e 100644 --- a/src/plugins/projectexplorer/runconfigurationaspects.cpp +++ b/src/plugins/projectexplorer/runconfigurationaspects.cpp @@ -500,11 +500,11 @@ ExecutableAspect::ExecutableAspect(Target *target, ExecutionDeviceSelector selec { setDisplayName(Tr::tr("Executable")); setId("ExecutableAspect"); + setReadOnly(true); addDataExtractor(this, &ExecutableAspect::executable, &Data::executable); m_executable.setPlaceHolderText(Tr::tr("Enter the path to the executable")); m_executable.setLabelText(Tr::tr("Executable:")); - m_executable.setDisplayStyle(StringAspect::LabelDisplay); updateDevice(); @@ -579,14 +579,9 @@ void ExecutableAspect::setEnvironment(const Environment &env) m_alternativeExecutable->setEnvironment(env); } -/*! - Sets the display \a style for aspect. - - \sa Utils::StringAspect::setDisplayStyle() -*/ -void ExecutableAspect::setDisplayStyle(StringAspect::DisplayStyle style) +void ExecutableAspect::setReadOnly(bool readOnly) { - m_executable.setDisplayStyle(style); + m_executable.setReadOnly(readOnly); } /*! @@ -601,7 +596,7 @@ void ExecutableAspect::setDisplayStyle(StringAspect::DisplayStyle style) void ExecutableAspect::makeOverridable(const QString &overridingKey, const QString &useOverridableKey) { QTC_ASSERT(!m_alternativeExecutable, return); - m_alternativeExecutable = new StringAspect; + m_alternativeExecutable = new FilePathAspect; m_alternativeExecutable->setDisplayStyle(StringAspect::LineEditDisplay); m_alternativeExecutable->setLabelText(Tr::tr("Alternate executable on device:")); m_alternativeExecutable->setSettingsKey(overridingKey); diff --git a/src/plugins/projectexplorer/runconfigurationaspects.h b/src/plugins/projectexplorer/runconfigurationaspects.h index 9fc7364772d..f7e3e4c4211 100644 --- a/src/plugins/projectexplorer/runconfigurationaspects.h +++ b/src/plugins/projectexplorer/runconfigurationaspects.h @@ -169,7 +169,7 @@ public: void setHistoryCompleter(const QString &historyCompleterKey); void setExpectedKind(const Utils::PathChooser::Kind expectedKind); void setEnvironment(const Utils::Environment &env); - void setDisplayStyle(Utils::StringAspect::DisplayStyle style); + void setReadOnly(bool readOnly); struct Data : BaseAspect::Data { @@ -184,8 +184,8 @@ private: QString executableText() const; void updateDevice(); - Utils::StringAspect m_executable; - Utils::StringAspect *m_alternativeExecutable = nullptr; + Utils::FilePathAspect m_executable; + Utils::FilePathAspect *m_alternativeExecutable = nullptr; Target *m_target = nullptr; ExecutionDeviceSelector m_selector = RunDevice; }; diff --git a/src/plugins/remotelinux/makeinstallstep.cpp b/src/plugins/remotelinux/makeinstallstep.cpp index a93fccba41b..13465b57254 100644 --- a/src/plugins/remotelinux/makeinstallstep.cpp +++ b/src/plugins/remotelinux/makeinstallstep.cpp @@ -65,7 +65,7 @@ MakeInstallStep::MakeInstallStep(BuildStepList *parent, Id id) : MakeStep(parent ExecutableAspect::BuildDevice); makeAspect->setId(MakeAspectId); makeAspect->setSettingsKey(MakeAspectId); - makeAspect->setDisplayStyle(StringAspect::PathChooserDisplay); + makeAspect->setReadOnly(false); makeAspect->setLabelText(Tr::tr("Command:")); connect(makeAspect, &ExecutableAspect::changed, this, &MakeInstallStep::updateCommandFromAspect); diff --git a/src/plugins/remotelinux/remotelinuxcustomrunconfiguration.cpp b/src/plugins/remotelinux/remotelinuxcustomrunconfiguration.cpp index 9b99d66923b..f431cdf2d3b 100644 --- a/src/plugins/remotelinux/remotelinuxcustomrunconfiguration.cpp +++ b/src/plugins/remotelinux/remotelinuxcustomrunconfiguration.cpp @@ -37,7 +37,7 @@ RemoteLinuxCustomRunConfiguration::RemoteLinuxCustomRunConfiguration(Target *tar auto exeAspect = addAspect(target, ExecutableAspect::RunDevice); exeAspect->setSettingsKey("RemoteLinux.CustomRunConfig.RemoteExecutable"); exeAspect->setLabelText(Tr::tr("Remote executable:")); - exeAspect->setDisplayStyle(StringAspect::LineEditDisplay); + exeAspect->setReadOnly(false); exeAspect->setHistoryCompleter("RemoteLinux.CustomExecutable.History"); exeAspect->setExpectedKind(PathChooser::Any);