diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2020-02-07 14:03:43 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2020-03-24 16:20:03 +0100 |
commit | 737fe89691a3d8dfa779862c9daaa002e00f3dca (patch) | |
tree | df7498f54d2a5d57ff5de93bd8630fe2b3ecaa3a /src/corelib/io/qdir.h | |
parent | c4ef0b92d5fb2c621e880347bd48d01b6f31eb24 (diff) |
Q{File,FileInfo,Dir}: add std::filesystem::path overloads
Add some overloads where (I thought) it makes sense for QDir and QFile
to accept std::filesystem::path objects. Currently my thinking is to
not add overloads for static functions where std::filesystem can already
do the same job, e.g. create directory or file.
Template and enable_if is needed due to both QString and
std::filesystem::path being able to be constructed from string literals.
The common shared code is currently in QFile because QDir had an
implicit include of QFile, made explicit in this patch, and QFileInfo
has an include to QFile as well.
The QT_HAS_STD_FILESYSTEM macro is visible in user-code which I
currently take advantage of in the tests, and users could too.
Change-Id: I8d05d3c34c6c17e20972a6a2053862b8891d6c3c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qdir.h')
-rw-r--r-- | src/corelib/io/qdir.h | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index 45a40995f8..f0dda73ebb 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -41,13 +41,13 @@ #define QDIR_H #include <QtCore/qstring.h> +#include <QtCore/qfile.h> #include <QtCore/qfileinfo.h> #include <QtCore/qstringlist.h> #include <QtCore/qshareddata.h> QT_BEGIN_NAMESPACE - class QDirIterator; class QDirPrivate; @@ -102,6 +102,22 @@ public: QDir(const QString &path = QString()); QDir(const QString &path, const QString &nameFilter, SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries); +#ifdef Q_CLANG_QDOC + QDir(const std::filesystem::path &path); + QDir(const std::filesystem::path &path, const QString &nameFilter, + SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries); +#elif QT_CONFIG(cxx17_filesystem) + template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> + QDir(const T &path) : QDir(QtPrivate::fromFilesystemPath(path)) + { + } + template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> + QDir(const T &path, const QString &nameFilter, + SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries) + : QDir(QtPrivate::fromFilesystemPath(path), nameFilter, sort, filter) + { + } +#endif // QT_CONFIG(cxx17_filesystem) ~QDir(); QDir &operator=(const QDir &); @@ -115,9 +131,26 @@ public: { qSwap(d_ptr, other.d_ptr); } void setPath(const QString &path); +#ifdef Q_CLANG_QDOC + void setPath(const std::filesystem::path &path); +#elif QT_CONFIG(cxx17_filesystem) + template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> + void setPath(const T &path) + { + setPath(QtPrivate::fromFilesystemPath(path)); + } +#endif // QT_CONFIG(cxx17_filesystem) QString path() const; QString absolutePath() const; QString canonicalPath() const; +#if QT_CONFIG(cxx17_filesystem) + std::filesystem::path filesystemPath() const + { return QtPrivate::toFilesystemPath(path()); } + std::filesystem::path filesystemAbsolutePath() const + { return QtPrivate::toFilesystemPath(absolutePath()); } + std::filesystem::path filesystemCanonicalPath() const + { return QtPrivate::toFilesystemPath(canonicalPath()); } +#endif // QT_CONFIG(cxx17_filesystem) #if QT_DEPRECATED_SINCE(5, 13) QT_DEPRECATED_X("Use QDir::addSearchPath() instead") @@ -126,6 +159,15 @@ public: static void setSearchPaths(const QString &prefix, const QStringList &searchPaths); static void addSearchPath(const QString &prefix, const QString &path); +#ifdef Q_CLANG_QDOC + static void addSearchPath(const QString &prefix, const std::filesystem::path &path); +#elif QT_CONFIG(cxx17_filesystem) + template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> + static void addSearchPath(const QString &prefix, const T &path) + { + addSearchPath(prefix, QtPrivate::fromFilesystemPath(path)); + } +#endif // QT_CONFIG(cxx17_filesystem) static QStringList searchPaths(const QString &prefix); QString dirName() const; |