From 737fe89691a3d8dfa779862c9daaa002e00f3dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 7 Feb 2020 14:03:43 +0100 Subject: 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 --- src/corelib/io/qfileinfo.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) (limited to 'src/corelib/io/qfileinfo.cpp') diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 64b1557231..479532fc36 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -363,7 +363,7 @@ QFileInfo::QFileInfo(const QFile &file) : d_ptr(new QFileInfoPrivate(file.fileNa /*! Constructs a new QFileInfo that gives information about the given - \a file in the directory \a dir. + \a file relative to the directory \a dir. If \a dir has a relative path, the QFileInfo will also have a relative path. @@ -1576,4 +1576,83 @@ QDebug operator<<(QDebug dbg, const QFileInfo &fi) } #endif +/*! + \fn QFileInfo::QFileInfo(const std::filesystem::path &file) + \since 6.0 + + Constructs a new QFileInfo that gives information about the given + \a file. + + \sa setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath() +*/ +/*! + \fn QFileInfo::QFileInfo(const QDir &dir, const std::filesystem::path &file) + \since 6.0 + + Constructs a new QFileInfo that gives information about the given + \a file relative to the directory \a dir. + + If \a dir has a relative path, the QFileInfo will also have a + relative path. + + If \a file is an absolute path, then the directory specified + by \a dir will be disregarded. +*/ +/*! + \fn void QFileInfo::setFile(const std::filesystem::path &file) + \since 6.0 + + Sets the file that the QFileInfo provides information about to \a + file. +*/ +/*! + \fn std::filesystem::path QFileInfo::filesystemFilePath() const + \since 6.0 + + Returns filePath() as a \c{std::filesystem::path}. + \sa filePath() +*/ +/*! + \fn std::filesystem::path QFileInfo::filesystemAbsoluteFilePath() const + \since 6.0 + + Returns absoluteFilePath() as a \c{std::filesystem::path}. + \sa absoluteFilePath() +*/ +/*! + \fn std::filesystem::path QFileInfo::filesystemCanonicalFilePath() const + \since 6.0 + + Returns canonicalFilePath() as a \c{std::filesystem::path}. + \sa canonicalFilePath() +*/ +/*! + \fn std::filesystem::path QFileInfo::filesystemPath() const + \since 6.0 + + Returns path() as a \c{std::filesystem::path}. + \sa path() +*/ +/*! + \fn std::filesystem::path QFileInfo::filesystemAbsolutePath() const + \since 6.0 + + Returns absolutePath() as a \c{std::filesystem::path}. + \sa absolutePath() +*/ +/*! + \fn std::filesystem::path QFileInfo::filesystemCanonicalPath() const + \since 6.0 + + Returns canonicalPath() as a \c{std::filesystem::path}. + \sa canonicalPath() +*/ +/*! + \fn std::filesystem::path QFileInfo::filesystemSymLinkTarget() const + \since 6.0 + + Returns symLinkTarget() as a \c{std::filesystem::path}. + \sa symLinkTarget() +*/ + QT_END_NAMESPACE -- cgit v1.2.3