summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-07-29 20:16:48 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-08-12 23:06:36 +0200
commite635568985ef8a09302edc02ff4f74eca4a65843 (patch)
tree9569cfed173be6c3c20df7507dfa0ab7cd6748d5 /src/widgets
parent99aefbb4c00ce2ad01bea186a297a3407b1da973 (diff)
QFileSystemModel: use the QFileInfo from the model as much as possible
If the file system already stores a QFileInfo, then it will have the information cached, which avoids costly roundtrips to the file system. Task-number: QTBUG-41373 Change-Id: I830a39fe0e20ebf07abde4438a87f7572f608d66 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dialogs/qfilesystemmodel.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp
index 96d3f0e011..f088712987 100644
--- a/src/widgets/dialogs/qfilesystemmodel.cpp
+++ b/src/widgets/dialogs/qfilesystemmodel.cpp
@@ -1393,8 +1393,14 @@ QString QFileSystemModel::filePath(const QModelIndex &index) const
#endif
&& d->resolvedSymLinks.contains(fullPath)
&& dirNode->isDir()) {
- QFileInfo resolvedInfo(fullPath);
- resolvedInfo = resolvedInfo.canonicalFilePath();
+ QFileInfo fullPathInfo(dirNode->fileInfo());
+ if (!dirNode->hasInformation())
+ fullPathInfo = QFileInfo(fullPath);
+ QString canonicalPath = fullPathInfo.canonicalFilePath();
+ auto *canonicalNode = d->node(fullPathInfo.canonicalFilePath(), false);
+ QFileInfo resolvedInfo = canonicalNode->fileInfo();
+ if (!canonicalNode->hasInformation())
+ resolvedInfo = QFileInfo(canonicalPath);
if (resolvedInfo.exists())
return resolvedInfo.filePath();
}
@@ -1485,12 +1491,9 @@ QModelIndex QFileSystemModel::setRootPath(const QString &newPath)
#else
QString longNewPath = newPath;
#endif
- QDir newPathDir(longNewPath);
//we remove .. and . from the given path if exist
- if (!newPath.isEmpty()) {
+ if (!newPath.isEmpty())
longNewPath = QDir::cleanPath(longNewPath);
- newPathDir.setPath(longNewPath);
- }
d->setRootPath = true;
@@ -1501,8 +1504,15 @@ QModelIndex QFileSystemModel::setRootPath(const QString &newPath)
if (d->rootDir.path() == longNewPath)
return d->index(rootPath());
+ auto node = d->node(longNewPath);
+ QFileInfo newPathInfo;
+ if (node && node->hasInformation())
+ newPathInfo = node->fileInfo();
+ else
+ newPathInfo = QFileInfo(longNewPath);
+
bool showDrives = (longNewPath.isEmpty() || longNewPath == QFileSystemModelPrivate::myComputer());
- if (!showDrives && !newPathDir.exists())
+ if (!showDrives && !newPathInfo.exists())
return d->index(rootPath());
//We remove the watcher on the previous path
@@ -1518,13 +1528,13 @@ QModelIndex QFileSystemModel::setRootPath(const QString &newPath)
}
// We have a new valid root path
- d->rootDir = newPathDir;
+ d->rootDir = QDir(longNewPath);
QModelIndex newRootIndex;
if (showDrives) {
// otherwise dir will become '.'
d->rootDir.setPath(QLatin1String(""));
} else {
- newRootIndex = d->index(newPathDir.path());
+ newRootIndex = d->index(d->rootDir.path());
}
fetchMore(newRootIndex);
emit rootPathChanged(longNewPath);