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>
This commit is contained in:
parent
99aefbb4c0
commit
e635568985
@ -1393,8 +1393,14 @@ QString QFileSystemModel::filePath(const QModelIndex &index) const
|
|||||||
#endif
|
#endif
|
||||||
&& d->resolvedSymLinks.contains(fullPath)
|
&& d->resolvedSymLinks.contains(fullPath)
|
||||||
&& dirNode->isDir()) {
|
&& dirNode->isDir()) {
|
||||||
QFileInfo resolvedInfo(fullPath);
|
QFileInfo fullPathInfo(dirNode->fileInfo());
|
||||||
resolvedInfo = resolvedInfo.canonicalFilePath();
|
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())
|
if (resolvedInfo.exists())
|
||||||
return resolvedInfo.filePath();
|
return resolvedInfo.filePath();
|
||||||
}
|
}
|
||||||
@ -1485,12 +1491,9 @@ QModelIndex QFileSystemModel::setRootPath(const QString &newPath)
|
|||||||
#else
|
#else
|
||||||
QString longNewPath = newPath;
|
QString longNewPath = newPath;
|
||||||
#endif
|
#endif
|
||||||
QDir newPathDir(longNewPath);
|
|
||||||
//we remove .. and . from the given path if exist
|
//we remove .. and . from the given path if exist
|
||||||
if (!newPath.isEmpty()) {
|
if (!newPath.isEmpty())
|
||||||
longNewPath = QDir::cleanPath(longNewPath);
|
longNewPath = QDir::cleanPath(longNewPath);
|
||||||
newPathDir.setPath(longNewPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
d->setRootPath = true;
|
d->setRootPath = true;
|
||||||
|
|
||||||
@ -1501,8 +1504,15 @@ QModelIndex QFileSystemModel::setRootPath(const QString &newPath)
|
|||||||
if (d->rootDir.path() == longNewPath)
|
if (d->rootDir.path() == longNewPath)
|
||||||
return d->index(rootPath());
|
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());
|
bool showDrives = (longNewPath.isEmpty() || longNewPath == QFileSystemModelPrivate::myComputer());
|
||||||
if (!showDrives && !newPathDir.exists())
|
if (!showDrives && !newPathInfo.exists())
|
||||||
return d->index(rootPath());
|
return d->index(rootPath());
|
||||||
|
|
||||||
//We remove the watcher on the previous path
|
//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
|
// We have a new valid root path
|
||||||
d->rootDir = newPathDir;
|
d->rootDir = QDir(longNewPath);
|
||||||
QModelIndex newRootIndex;
|
QModelIndex newRootIndex;
|
||||||
if (showDrives) {
|
if (showDrives) {
|
||||||
// otherwise dir will become '.'
|
// otherwise dir will become '.'
|
||||||
d->rootDir.setPath(QLatin1String(""));
|
d->rootDir.setPath(QLatin1String(""));
|
||||||
} else {
|
} else {
|
||||||
newRootIndex = d->index(newPathDir.path());
|
newRootIndex = d->index(d->rootDir.path());
|
||||||
}
|
}
|
||||||
fetchMore(newRootIndex);
|
fetchMore(newRootIndex);
|
||||||
emit rootPathChanged(longNewPath);
|
emit rootPathChanged(longNewPath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user