From acf43c17b647cdbfc3186bb8bf7e183df67a090b Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Tue, 1 Mar 2016 15:44:06 +0300 Subject: QFileSystemModel: create nodes with correct QFileInfos Create parent nodes with the corresponding paths, not with the absolute path of the child node. Otherwise we will get incorrect QFileInfo at least in the following case: QFileSystemModel model; model.setRootPath("/usr/bin"); QModelIndex idx = model.setRootPath("/usr"); qDebug() << model.fileInfo(idx).absoluteFilePath(); Without the fix it prints "/usr/bin". It's a regression triggered by 61cefb2f7a7cb16dfa2732e26d2319017039ef62 (De-inline QFileSystemModel::fileInfo() and implement it efficiently). Change-Id: I3b4e5f5b256711e27ad50824eaa8492dbc096808 Task-number: QTBUG-51586 Reviewed-by: Lars Knoll --- .../qfilesystemmodel/tst_qfilesystemmodel.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/auto/widgets/dialogs/qfilesystemmodel') diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index 19b1d0e7c8..b27943f071 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -126,6 +126,8 @@ private slots: void doNotUnwatchOnFailedRmdir(); void specialFiles(); + void fileInfo(); + protected: bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList()); @@ -1146,6 +1148,25 @@ void tst_QFileSystemModel::specialFiles() QTRY_VERIFY(!fileListUnderIndex(&model, rootIndex).contains(testFileName)); } +void tst_QFileSystemModel::fileInfo() +{ + QFileSystemModel model; + QModelIndex idx; + + QVERIFY(model.fileInfo(idx).filePath().isEmpty()); + + const QString dirPath = flatDirTestPath; + QDir dir(dirPath); + const QString subdir = QStringLiteral("subdir"); + QVERIFY(dir.mkdir(subdir)); + const QString subdirPath = dir.absoluteFilePath(subdir); + + idx = model.setRootPath(subdirPath); + QCOMPARE(model.fileInfo(idx), QFileInfo(subdirPath)); + idx = model.setRootPath(dirPath); + QCOMPARE(model.fileInfo(idx), QFileInfo(dirPath)); +} + QTEST_MAIN(tst_QFileSystemModel) #include "tst_qfilesystemmodel.moc" -- cgit v1.2.3