summaryrefslogtreecommitdiffstats
path: root/src/gui/itemmodels/qfilesystemmodel.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2024-01-11 22:02:57 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2024-01-26 20:19:23 +0000
commit83e5d74864a8780445db4b34e406afc53b331039 (patch)
tree880b5dfcb035aaac8192ef51468b3b9e478449e6 /src/gui/itemmodels/qfilesystemmodel.cpp
parent5e237f1af21af363a395aef09f93115c5882b443 (diff)
QFileSystemModel: respect dir filters
Given a dir A that has some files and a subdir B, when a model is set to only show files, setting the root path to A, the filters are initially respected. Setting the root path to B then back to A, the filters would be ignored and B would be visible in the model. Traversing the path elements in node() led to dir B getting added to the bypassFilters hash table, which made filtersAcceptNode() bypass the filters. I couldn't find a commit explaining the logic behind using bypassFilters (the trail goes cold at the 'Qt 4.5' mega commit). The only clue I found was the "// always accept drives" comment in the code, which hints at this being useful only on Windows(?). Fixes: QTBUG-74471 Pick-to: 6.7 6.6 6.5 Change-Id: Icb9055524a28990c591e924634a63e29a49835aa Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/itemmodels/qfilesystemmodel.cpp')
-rw-r--r--src/gui/itemmodels/qfilesystemmodel.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/gui/itemmodels/qfilesystemmodel.cpp b/src/gui/itemmodels/qfilesystemmodel.cpp
index 6924165732..f7778a3ced 100644
--- a/src/gui/itemmodels/qfilesystemmodel.cpp
+++ b/src/gui/itemmodels/qfilesystemmodel.cpp
@@ -2126,8 +2126,14 @@ void QFileSystemModelPrivate::init()
*/
bool QFileSystemModelPrivate::filtersAcceptsNode(const QFileSystemNode *node) const
{
+ // When the model is set to only show files, then a node representing a dir
+ // should be hidden regardless of bypassFilters.
+ // QTBUG-74471
+ const bool hideDirs = (filters & (QDir::Dirs | QDir::AllDirs)) == 0;
+ const bool shouldHideDirNode = hideDirs && node->isDir();
+
// always accept drives
- if (node->parent == &root || bypassFilters.contains(node))
+ if (node->parent == &root || (!shouldHideDirNode && bypassFilters.contains(node)))
return true;
// If we don't know anything yet don't accept it
@@ -2136,7 +2142,6 @@ bool QFileSystemModelPrivate::filtersAcceptsNode(const QFileSystemNode *node) co
const bool filterPermissions = ((filters & QDir::PermissionMask)
&& (filters & QDir::PermissionMask) != QDir::PermissionMask);
- const bool hideDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
const bool hideFiles = !(filters & QDir::Files);
const bool hideReadable = !(!filterPermissions || (filters & QDir::Readable));
const bool hideWritable = !(!filterPermissions || (filters & QDir::Writable));