summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2023-03-03 14:49:05 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2023-10-09 16:25:57 +0200
commit0fa4af060e420f5c6213d45cdde8fb313f214672 (patch)
treee557fac27f6374bca0b0ea6542a9af75711b99d3 /src
parent7d663d2e08fb71801f0f1f084a124e706722bf0f (diff)
QTemporaryFile: Add support for std::filesystem::path
Since it hides QFile's overloads this was not supported for QTemporaryFile. [ChangeLog][QtCore][QTemporaryFile] Added support for passing std::filesystem::path to rename and createNativeFile. Change-Id: I909ff1d5b9c586824c9901d7dad278dfad09ffc3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp24
-rw-r--r--src/corelib/io/qtemporaryfile.h35
2 files changed, 57 insertions, 2 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 80ea57fb92..a98256c1f4 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -631,6 +631,12 @@ QTemporaryFile::QTemporaryFile()
}
/*!
+ \fn QTemporaryFile::QTemporaryFile(const std::filesystem::path &templateName, QObject *parent)
+ \overload
+ \since 6.7
+*/
+
+/*!
Constructs a QTemporaryFile with a template filename of \a
templateName. Upon opening the temporary file this will be used to create
a unique filename.
@@ -792,6 +798,12 @@ QString QTemporaryFile::fileTemplate() const
}
/*!
+ \fn void QTemporaryFile::setFileTemplate(const std::filesystem::path &name)
+ \overload
+ \since 6.7
+*/
+
+/*!
Sets the static portion of the file name to \a name. If the file
template contains XXXXXX that will automatically be replaced with
the unique part of the filename, otherwise a filename will be
@@ -813,6 +825,12 @@ void QTemporaryFile::setFileTemplate(const QString &name)
}
/*!
+ \fn bool QTemporaryFile::rename(const std::filesystem::path &newName)
+ \overload
+ \since 6.7
+*/
+
+/*!
Renames the current temporary file to \a newName and returns true if it
succeeded.
@@ -860,7 +878,11 @@ bool QTemporaryFile::rename(const QString &newName)
Works on the given \a fileName rather than an existing QFile
object.
*/
-
+/*!
+ \fn QTemporaryFile *QTemporaryFile::createNativeFile(const std::filesystem::path &fileName)
+ \overload
+ \since 6.7
+*/
/*!
If \a file is not already a native file, then a QTemporaryFile is created
diff --git a/src/corelib/io/qtemporaryfile.h b/src/corelib/io/qtemporaryfile.h
index e1058e566c..721ebc5b22 100644
--- a/src/corelib/io/qtemporaryfile.h
+++ b/src/corelib/io/qtemporaryfile.h
@@ -32,7 +32,16 @@ public:
#ifndef QT_NO_QOBJECT
explicit QTemporaryFile(QObject *parent);
QTemporaryFile(const QString &templateName, QObject *parent);
-#endif
+
+# if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
+ Q_WEAK_OVERLOAD
+ explicit QTemporaryFile(const std::filesystem::path &templateName, QObject *parent = nullptr)
+ : QTemporaryFile(QtPrivate::fromFilesystemPath(templateName), parent)
+ {
+ }
+# endif // QT_CONFIG(cxx17_filesystem)
+#endif // !QT_NO_QOBJECT
+
~QTemporaryFile();
bool autoRemove() const;
@@ -44,14 +53,38 @@ public:
QString fileName() const override;
QString fileTemplate() const;
void setFileTemplate(const QString &name);
+#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
+ Q_WEAK_OVERLOAD
+ void setFileTemplate(const std::filesystem::path &name)
+ {
+ return setFileTemplate(QtPrivate::fromFilesystemPath(name));
+ }
+#endif // QT_CONFIG(cxx17_filesystem)
// Hides QFile::rename
bool rename(const QString &newName);
+#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
+ Q_WEAK_OVERLOAD
+ bool rename(const std::filesystem::path &newName)
+ {
+ return rename(QtPrivate::fromFilesystemPath(newName));
+ }
+#endif // QT_CONFIG(cxx17_filesystem)
+
inline static QTemporaryFile *createNativeFile(const QString &fileName)
{ QFile file(fileName); return createNativeFile(file); }
static QTemporaryFile *createNativeFile(QFile &file);
+#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
+ Q_WEAK_OVERLOAD
+ static QTemporaryFile *createNativeFile(const std::filesystem::path &fileName)
+ {
+ QFile file(fileName);
+ return createNativeFile(file);
+ }
+#endif // QT_CONFIG(cxx17_filesystem)
+
protected:
bool open(OpenMode flags) override;