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 <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2023-06-28 17:14:43 +02:00
parent e38cd151cf
commit f2aaf68b0c
10 changed files with 30 additions and 47 deletions

View File

@@ -329,6 +329,8 @@ void BaseAspect::setReadOnly(bool readOnly)
lineEdit->setReadOnly(readOnly);
else if (auto textEdit = qobject_cast<QTextEdit *>(w))
textEdit->setReadOnly(readOnly);
else if (auto pathChooser = qobject_cast<PathChooser *>(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<QString> 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<QString> tmp = d->m_valueAcceptor(m_internal, val);
if (tmp)
m_internal = *tmp;
} else {
m_internal = val;
}
}
void StringAspect::internalToGui()

View File

@@ -456,7 +456,6 @@ public:
void setValueAcceptor(ValueAcceptor &&acceptor);
QString value() const;
void setValue(const QString &val);
void setShowToolTipOnLabel(bool show);

View File

@@ -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)

View File

@@ -26,7 +26,6 @@ public:
: RunConfiguration(target, id)
{
const auto exeAspect = addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice);
exeAspect->setDisplayStyle(StringAspect::LabelDisplay);
exeAspect->setPlaceHolderText(Tr::tr("Unknown"));
addAspect<ArgumentsAspect>(macroExpander());
@@ -50,7 +49,7 @@ public:
const auto exeAspect = addAspect<ExecutableAspect>(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);

View File

@@ -59,7 +59,6 @@ IosRunConfiguration::IosRunConfiguration(Target *target, Id id)
: RunConfiguration(target, id)
{
auto executableAspect = addAspect<ExecutableAspect>(target, ExecutableAspect::RunDevice);
executableAspect->setDisplayStyle(StringAspect::LabelDisplay);
addAspect<ArgumentsAspect>(macroExpander());

View File

@@ -28,7 +28,7 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe
auto exeAspect = addAspect<ExecutableAspect>(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());

View File

@@ -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);

View File

@@ -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;
};

View File

@@ -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);

View File

@@ -37,7 +37,7 @@ RemoteLinuxCustomRunConfiguration::RemoteLinuxCustomRunConfiguration(Target *tar
auto exeAspect = addAspect<ExecutableAspect>(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);