Utils: Make OsType addition less visible

Change-Id: I092930ef6b0ed6876e32ed6b0c78d6bd58becddc
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-08-04 16:35:31 +02:00
parent 3e8f6bbf82
commit 56a8c59845
4 changed files with 26 additions and 11 deletions

View File

@@ -740,14 +740,22 @@ QString FilePath::displayName(const QString &args) const
\sa toString, fromUserInput \sa toString, fromUserInput
*/ */
FilePath FilePath::fromString(const QString &filepath, OsType osType) FilePath FilePath::fromString(const QString &filepath)
{ {
FilePath fn; FilePath fn;
fn.setFromString(filepath, osType); fn.setFromString(filepath);
return fn; return fn;
} }
bool isWindowsDriveLetter(QChar ch) { FilePath FilePath::fromStringAndOs(const QString &filepath, OsType osType)
{
FilePath fn;
fn.setFromStringAndOs(filepath, osType);
return fn;
}
bool isWindowsDriveLetter(QChar ch)
{
return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
} }
@@ -817,7 +825,12 @@ void FilePath::setRootAndPath(QStringView path, OsType osType)
} }
} }
void FilePath::setFromString(const QString &filename, OsType osType) void FilePath::setFromString(const QString &fileName)
{
setFromStringAndOs(fileName, HostOsInfo::hostOs());
}
void FilePath::setFromStringAndOs(const QString &filename, OsType osType)
{ {
static const QLatin1String qtcDevSlash("__qtc_devices__/"); static const QLatin1String qtcDevSlash("__qtc_devices__/");
static const QLatin1String colonSlashSlash("://"); static const QLatin1String colonSlashSlash("://");

View File

@@ -6,7 +6,6 @@
#include "utils_global.h" #include "utils_global.h"
#include "osspecificaspects.h" #include "osspecificaspects.h"
#include "hostosinfo.h"
#include <QDir> #include <QDir>
#include <QDirIterator> #include <QDirIterator>
@@ -48,9 +47,10 @@ class QTCREATOR_UTILS_EXPORT FilePath
public: public:
FilePath(); FilePath();
template <size_t N> FilePath(const char (&literal)[N], OsType osType = HostOsInfo::hostOs()) { setFromString(literal, osType); } template <size_t N> FilePath(const char (&literal)[N]) { setFromString(literal); }
[[nodiscard]] static FilePath fromString(const QString &filepath, OsType osType = HostOsInfo::hostOs()); [[nodiscard]] static FilePath fromString(const QString &filepath);
[[nodiscard]] static FilePath fromStringAndOs(const QString &filepath, OsType osType);
[[nodiscard]] static FilePath fromStringWithExtension(const QString &filepath, const QString &defaultExtension); [[nodiscard]] static FilePath fromStringWithExtension(const QString &filepath, const QString &defaultExtension);
[[nodiscard]] static FilePath fromUserInput(const QString &filepath); [[nodiscard]] static FilePath fromUserInput(const QString &filepath);
[[nodiscard]] static FilePath fromUtf8(const char *filepath, int filepathSize = -1); [[nodiscard]] static FilePath fromUtf8(const char *filepath, int filepathSize = -1);
@@ -205,7 +205,8 @@ private:
friend class ::tst_fileutils; friend class ::tst_fileutils;
static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath); static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath);
void setRootAndPath(QStringView path, OsType osType); void setRootAndPath(QStringView path, OsType osType);
void setFromString(const QString &filepath, OsType osType); void setFromString(const QString &filepath);
void setFromStringAndOs(const QString &filepath, OsType osType);
[[nodiscard]] QString mapToDevicePath() const; [[nodiscard]] QString mapToDevicePath() const;
QString m_scheme; QString m_scheme;

View File

@@ -4,6 +4,7 @@
#include "reloadpromptutils.h" #include "reloadpromptutils.h"
#include "fileutils.h" #include "fileutils.h"
#include "hostosinfo.h"
#include <QDir> #include <QDir>
#include <QGuiApplication> #include <QGuiApplication>

View File

@@ -374,7 +374,7 @@ void tst_fileutils::fromString()
QFETCH(QString, path); QFETCH(QString, path);
QFETCH(OsType, osType); QFETCH(OsType, osType);
FilePath filePath = FilePath::fromString(input, osType); FilePath filePath = FilePath::fromStringAndOs(input, osType);
QCOMPARE(filePath.scheme(), scheme); QCOMPARE(filePath.scheme(), scheme);
QCOMPARE(filePath.host(), host); QCOMPARE(filePath.host(), host);
QCOMPARE(filePath.path(), path); QCOMPARE(filePath.path(), path);
@@ -715,8 +715,8 @@ void tst_fileutils::startsWithDriveLetter_data()
QTest::addColumn<bool>("expected"); QTest::addColumn<bool>("expected");
QTest::newRow("empty") << FilePath() << false; QTest::newRow("empty") << FilePath() << false;
QTest::newRow("simple-win") << FilePath("c:/a", OsType::OsTypeWindows) << true; QTest::newRow("simple-win") << FilePath::fromStringAndOs("c:/a", OsType::OsTypeWindows) << true;
QTest::newRow("simple-linux") << FilePath("/c:/a", OsType::OsTypeLinux) << false; QTest::newRow("simple-linux") << FilePath::fromStringAndOs("/c:/a", OsType::OsTypeLinux) << false;
QTest::newRow("relative") << FilePath("a/b") << false; QTest::newRow("relative") << FilePath("a/b") << false;
} }