Utils: Use some of the FilePath convenience functions in FileCrumbLabel

Change-Id: I79f6b52847106bab22454f032407eb6866012362
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-11-24 17:38:18 +01:00
parent 4c1b3c863c
commit 9e7743494c

View File

@@ -17,7 +17,7 @@ FileCrumbLabel::FileCrumbLabel(QWidget *parent)
setTextFormat(Qt::RichText); setTextFormat(Qt::RichText);
setWordWrap(true); setWordWrap(true);
connect(this, &QLabel::linkActivated, this, [this](const QString &url) { connect(this, &QLabel::linkActivated, this, [this](const QString &url) {
emit pathClicked(FilePath::fromString(QUrl(url).toLocalFile())); emit pathClicked(FilePath::fromUrl(QUrl(url)));
}); });
setPath(FilePath()); setPath(FilePath());
} }
@@ -25,7 +25,7 @@ FileCrumbLabel::FileCrumbLabel(QWidget *parent)
static QString linkForPath(const FilePath &path, const QString &display) static QString linkForPath(const FilePath &path, const QString &display)
{ {
return "<a href=\"" return "<a href=\""
+ QUrl::fromLocalFile(path.toString()).toString(QUrl::FullyEncoded) + "\">" + path.toUrl().toString(QUrl::FullyEncoded) + "\">"
+ display + "</a>"; + display + "</a>";
} }
@@ -37,7 +37,7 @@ void FileCrumbLabel::setPath(const FilePath &path)
const QString fileName = current.fileName(); const QString fileName = current.fileName();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
links.prepend(linkForPath(current, fileName)); links.prepend(linkForPath(current, fileName));
} else if (HostOsInfo::isWindowsHost() && QDir(current.toString()).isRoot()) { } else if (HostOsInfo::isWindowsHost() && current.isRootPath()) {
// Only on Windows add the drive letter, without the '/' at the end // Only on Windows add the drive letter, without the '/' at the end
QString display = current.toString(); QString display = current.toString();
if (display.endsWith('/')) if (display.endsWith('/'))