Utils: Introduce FilePathAspect::setDefaultPathValue(FilePath)

... as a convenience function for .setDefaultValue(filePath.toUserOutput());

The case that someone already has FilePaths should not look (much)
uglier on the user side than the QString "raw" case.

Direct overloading setDefaultValue(FilePath) causes resolution
conflicts, which are solvable, but I'd rather keep it explicit now.

Change-Id: I03d71e4f99005a1d1f76ebf23080bebe46a9351d
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2024-01-24 12:31:10 +01:00
parent 359ab928b1
commit ead7afde3d
5 changed files with 11 additions and 5 deletions

View File

@@ -1442,6 +1442,11 @@ void FilePathAspect::setDefaultValue(const QString &filePath)
TypedAspect::setDefaultValue(filePath); TypedAspect::setDefaultValue(filePath);
} }
void FilePathAspect::setDefaultPathValue(const FilePath &filePath)
{
TypedAspect::setDefaultValue(filePath.toUserOutput());
}
/*! /*!
Adds a check box with a \a checkerLabel according to \a checkBoxPlacement Adds a check box with a \a checkerLabel according to \a checkBoxPlacement
to the line edit. to the line edit.

View File

@@ -666,6 +666,7 @@ public:
void setValue(const FilePath &filePath, Announcement howToAnnounce = DoEmit); void setValue(const FilePath &filePath, Announcement howToAnnounce = DoEmit);
void setValue(const QString &filePath, Announcement howToAnnounce = DoEmit); void setValue(const QString &filePath, Announcement howToAnnounce = DoEmit);
void setDefaultValue(const QString &filePath); void setDefaultValue(const QString &filePath);
void setDefaultPathValue(const FilePath &filePath);
void setPromptDialogFilter(const QString &filter); void setPromptDialogFilter(const QString &filter);
void setPromptDialogTitle(const QString &title); void setPromptDialogTitle(const QString &title);

View File

@@ -68,7 +68,7 @@ CopilotSettings::CopilotSettings()
const FilePath distFromVim = findOrDefault(searchDirs, &FilePath::exists); const FilePath distFromVim = findOrDefault(searchDirs, &FilePath::exists);
nodeJsPath.setExpectedKind(PathChooser::ExistingCommand); nodeJsPath.setExpectedKind(PathChooser::ExistingCommand);
nodeJsPath.setDefaultValue(nodeFromPath.toUserOutput()); nodeJsPath.setDefaultPathValue(nodeFromPath);
nodeJsPath.setSettingsKey("Copilot.NodeJsPath"); nodeJsPath.setSettingsKey("Copilot.NodeJsPath");
nodeJsPath.setLabelText(Tr::tr("Node.js path:")); nodeJsPath.setLabelText(Tr::tr("Node.js path:"));
nodeJsPath.setHistoryCompleter("Copilot.NodePath.History"); nodeJsPath.setHistoryCompleter("Copilot.NodePath.History");
@@ -79,7 +79,7 @@ CopilotSettings::CopilotSettings()
.arg("https://nodejs.org/en/download/")); .arg("https://nodejs.org/en/download/"));
distPath.setExpectedKind(PathChooser::File); distPath.setExpectedKind(PathChooser::File);
distPath.setDefaultValue(distFromVim.toUserOutput()); distPath.setDefaultPathValue(distFromVim);
distPath.setSettingsKey("Copilot.DistPath"); distPath.setSettingsKey("Copilot.DistPath");
distPath.setLabelText(Tr::tr("Path to agent.js:")); distPath.setLabelText(Tr::tr("Path to agent.js:"));
distPath.setHistoryCompleter("Copilot.DistPath.History"); distPath.setHistoryCompleter("Copilot.DistPath.History");

View File

@@ -57,7 +57,7 @@ ScreenRecorderSettings::ScreenRecorderSettings()
const FilePath ffmpegDefault const FilePath ffmpegDefault
= Environment::systemEnvironment().searchInPath(Constants::FFMPEG_COMMAND, = Environment::systemEnvironment().searchInPath(Constants::FFMPEG_COMMAND,
FileUtils::usefulExtraSearchPaths()); FileUtils::usefulExtraSearchPaths());
ffmpegTool.setDefaultValue(ffmpegDefault.toUserOutput()); ffmpegTool.setDefaultPathValue(ffmpegDefault);
ffmpegTool.setLabelText(Tr::tr("ffmpeg tool:")); ffmpegTool.setLabelText(Tr::tr("ffmpeg tool:"));
ffprobeTool.setSettingsKey("FFprobeTool"); ffprobeTool.setSettingsKey("FFprobeTool");
@@ -66,7 +66,7 @@ ScreenRecorderSettings::ScreenRecorderSettings()
const FilePath ffprobeDefault const FilePath ffprobeDefault
= Environment::systemEnvironment().searchInPath(Constants::FFPROBE_COMMAND, = Environment::systemEnvironment().searchInPath(Constants::FFPROBE_COMMAND,
FileUtils::usefulExtraSearchPaths()); FileUtils::usefulExtraSearchPaths());
ffprobeTool.setDefaultValue(ffprobeDefault.toUserOutput()); ffprobeTool.setDefaultPathValue(ffprobeDefault);
ffprobeTool.setLabelText(Tr::tr("ffprobe tool:")); ffprobeTool.setLabelText(Tr::tr("ffprobe tool:"));
captureCursor.setSettingsKey("CaptureCursor"); captureCursor.setSettingsKey("CaptureCursor");

View File

@@ -40,7 +40,7 @@ VcpkgSettings::VcpkgSettings()
if (!defaultPath.isDir()) if (!defaultPath.isDir())
defaultPath = FilePath::fromUserInput(qtcEnvironmentVariable(Constants::ENVVAR_VCPKG_ROOT)); defaultPath = FilePath::fromUserInput(qtcEnvironmentVariable(Constants::ENVVAR_VCPKG_ROOT));
if (defaultPath.isDir()) if (defaultPath.isDir())
vcpkgRoot.setDefaultValue(defaultPath.toUserOutput()); vcpkgRoot.setDefaultPathValue(defaultPath);
connect(this, &AspectContainer::applied, this, &VcpkgSettings::setVcpkgRootEnvironmentVariable); connect(this, &AspectContainer::applied, this, &VcpkgSettings::setVcpkgRootEnvironmentVariable);