Rename createLocalFile to createNativeFile & deprecate createLocalFile
As it was confusing to use the term local file when referring to a file that was accessible using native APIs and not just a file that was on a hard disk somewhere already the function name has been changed. By renaming it to createNativeFile we keep it consistant with QFileInfo which has an isNativeFile() function too. Test also added. Task-number: QTBUG-3169 Change-Id: I410e7ed28133d68fd312c6c0faf3f7191460d7ce Reviewed-by: João Abecasis <joao@abecasis.name> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
f20266f9f4
commit
ef3a544436
@ -700,6 +700,21 @@ void QTemporaryFile::setFileTemplate(const QString &name)
|
|||||||
/*!
|
/*!
|
||||||
\fn QTemporaryFile *QTemporaryFile::createLocalFile(const QString &fileName)
|
\fn QTemporaryFile *QTemporaryFile::createLocalFile(const QString &fileName)
|
||||||
\overload
|
\overload
|
||||||
|
\obsolete
|
||||||
|
|
||||||
|
Use QTemporaryFile::createNativeFile(const QString &fileName) instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
|
||||||
|
\obsolete
|
||||||
|
|
||||||
|
Use QTemporaryFile::createNativeFile(QFile &file) instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QTemporaryFile *QTemporaryFile::createNativeFile(const QString &fileName)
|
||||||
|
\overload
|
||||||
|
|
||||||
Works on the given \a fileName rather than an existing QFile
|
Works on the given \a fileName rather than an existing QFile
|
||||||
object.
|
object.
|
||||||
@ -707,16 +722,27 @@ void QTemporaryFile::setFileTemplate(const QString &name)
|
|||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
If \a file is not on a local disk, a temporary file is created
|
If \a file is not already a native file then a QTemporaryFile is created
|
||||||
on a local disk, \a file is copied into the temporary local file,
|
in the tempPath() and \a file is copied into the temporary file, then a
|
||||||
and a pointer to the temporary local file is returned. If \a file
|
pointer to the temporary file is returned. If \a file is already a native
|
||||||
is already on a local disk, a copy is not created and 0 is returned.
|
file, a QTemporaryFile is not created, no copy is made and 0 is returned.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
QFile f(":/resources/file.txt");
|
||||||
|
QTemporaryFile::createNativeFile(f); // Returns a pointer to a temporary file
|
||||||
|
|
||||||
|
QFile f("/users/qt/file.txt");
|
||||||
|
QTemporaryFile::createNativeFile(f); // Returns 0
|
||||||
|
|
||||||
|
\sa QFileInfo::isNativePath()
|
||||||
*/
|
*/
|
||||||
QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
|
|
||||||
|
QTemporaryFile *QTemporaryFile::createNativeFile(QFile &file)
|
||||||
{
|
{
|
||||||
if (QAbstractFileEngine *engine = file.d_func()->engine()) {
|
if (QAbstractFileEngine *engine = file.d_func()->engine()) {
|
||||||
if(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)
|
if(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)
|
||||||
return 0; //local already
|
return 0; //native already
|
||||||
//cache
|
//cache
|
||||||
bool wasOpen = file.isOpen();
|
bool wasOpen = file.isOpen();
|
||||||
qint64 old_off = 0;
|
qint64 old_off = 0;
|
||||||
|
@ -83,10 +83,15 @@ public:
|
|||||||
QString fileName() const;
|
QString fileName() const;
|
||||||
QString fileTemplate() const;
|
QString fileTemplate() const;
|
||||||
void setFileTemplate(const QString &name);
|
void setFileTemplate(const QString &name);
|
||||||
|
#if QT_DEPRECATED_SINCE(5,1)
|
||||||
inline static QTemporaryFile *createLocalFile(const QString &fileName)
|
QT_DEPRECATED inline static QTemporaryFile *createLocalFile(const QString &fileName)
|
||||||
{ QFile file(fileName); return createLocalFile(file); }
|
{ return createNativeFile(fileName); }
|
||||||
static QTemporaryFile *createLocalFile(QFile &file);
|
QT_DEPRECATED inline static QTemporaryFile *createLocalFile(QFile &file)
|
||||||
|
{ return createNativeFile(file); }
|
||||||
|
#endif
|
||||||
|
inline static QTemporaryFile *createNativeFile(const QString &fileName)
|
||||||
|
{ QFile file(fileName); return createNativeFile(file); }
|
||||||
|
static QTemporaryFile *createNativeFile(QFile &file);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool open(OpenMode flags);
|
bool open(OpenMode flags);
|
||||||
|
@ -5,3 +5,4 @@ QT = core testlib
|
|||||||
SOURCES = tst_qtemporaryfile.cpp
|
SOURCES = tst_qtemporaryfile.cpp
|
||||||
TESTDATA += tst_qtemporaryfile.cpp
|
TESTDATA += tst_qtemporaryfile.cpp
|
||||||
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
|
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
|
||||||
|
RESOURCES += qtemporaryfile.qrc
|
5
tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc
Normal file
5
tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<!DOCTYPE RCC><RCC version="1.0">
|
||||||
|
<qresource>
|
||||||
|
<file>resources/test.txt</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
1
tests/auto/corelib/io/qtemporaryfile/resources/test.txt
Normal file
1
tests/auto/corelib/io/qtemporaryfile/resources/test.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
This is a test
|
@ -88,7 +88,8 @@ private slots:
|
|||||||
void resetTemplateAfterError();
|
void resetTemplateAfterError();
|
||||||
void setTemplateAfterOpen();
|
void setTemplateAfterOpen();
|
||||||
void autoRemoveAfterFailedRename();
|
void autoRemoveAfterFailedRename();
|
||||||
|
void createNativeFile_data();
|
||||||
|
void createNativeFile();
|
||||||
void QTBUG_4796_data();
|
void QTBUG_4796_data();
|
||||||
void QTBUG_4796();
|
void QTBUG_4796();
|
||||||
};
|
};
|
||||||
@ -633,6 +634,41 @@ void tst_QTemporaryFile::autoRemoveAfterFailedRename()
|
|||||||
cleaner.reset();
|
cleaner.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QTemporaryFile::createNativeFile_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("filePath");
|
||||||
|
QTest::addColumn<qint64>("currentPos");
|
||||||
|
QTest::addColumn<bool>("valid");
|
||||||
|
QTest::addColumn<QByteArray>("content");
|
||||||
|
|
||||||
|
QTest::newRow("nativeFile") << QFINDTESTDATA("resources/test.txt") << (qint64)-1 << false << QByteArray();
|
||||||
|
QTest::newRow("nativeFileWithPos") << QFINDTESTDATA("resources/test.txt") << (qint64)5 << false << QByteArray();
|
||||||
|
QTest::newRow("resourceFile") << ":/resources/test.txt" << (qint64)-1 << true << QByteArray("This is a test");
|
||||||
|
QTest::newRow("resourceFileWithPos") << ":/resources/test.txt" << (qint64)5 << true << QByteArray("This is a test");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QTemporaryFile::createNativeFile()
|
||||||
|
{
|
||||||
|
QFETCH(QString, filePath);
|
||||||
|
QFETCH(qint64, currentPos);
|
||||||
|
QFETCH(bool, valid);
|
||||||
|
QFETCH(QByteArray, content);
|
||||||
|
|
||||||
|
QFile f(filePath);
|
||||||
|
if (currentPos != -1) {
|
||||||
|
f.open(QIODevice::ReadOnly);
|
||||||
|
f.seek(currentPos);
|
||||||
|
}
|
||||||
|
QTemporaryFile *tempFile = QTemporaryFile::createNativeFile(f);
|
||||||
|
QVERIFY(valid == (bool)tempFile);
|
||||||
|
if (currentPos != -1)
|
||||||
|
QCOMPARE(currentPos, f.pos());
|
||||||
|
if (valid) {
|
||||||
|
QCOMPARE(content, tempFile->readAll());
|
||||||
|
delete tempFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QTemporaryFile::QTBUG_4796_data()
|
void tst_QTemporaryFile::QTBUG_4796_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QString>("prefix");
|
QTest::addColumn<QString>("prefix");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user