48 bool operator==(
const QFileSystemModelNodePathKey &other)
const {
return !compare(other, Qt::CaseInsensitive); }
63 Q_DECLARE_PUBLIC(QFileSystemModel)
77 Q_DISABLE_COPY_MOVE(QFileSystemNode)
79 explicit QFileSystemNode(
const QString &filename = QString(), QFileSystemNode *p =
nullptr)
80 : fileName(filename), parent(p) {}
91 inline qint64 size()
const {
if (info && !info->isDir())
return info->size();
return 0; }
92 inline QString type()
const {
if (info)
return info->displayType;
return QLatin1StringView(
""); }
93 inline QDateTime lastModified(
const QTimeZone &tz)
const {
return info ? info->lastModified(tz) : QDateTime(); }
94 inline QFile::Permissions permissions()
const {
if (info)
return info->permissions();
return { }; }
95 inline bool isReadable()
const {
return ((permissions() & QFile::ReadUser) != 0); }
96 inline bool isWritable()
const {
return ((permissions() & QFile::WriteUser) != 0); }
97 inline bool isExecutable()
const {
return ((permissions() & QFile::ExeUser) != 0); }
98 inline bool isDir()
const {
100 return info->isDir();
101 if (children.size() > 0)
105 inline QFileInfo fileInfo()
const {
if (info)
return info->fileInfo();
return QFileInfo(); }
106 inline bool isFile()
const {
if (info)
return info->isFile();
return true; }
107 inline bool isSystem()
const {
if (info)
return info->isSystem();
return true; }
108 inline bool isHidden()
const {
if (info)
return info->isHidden();
return false; }
109 inline bool isSymLink(
bool ignoreNtfsSymLinks =
false)
const {
return info && info->isSymLink(ignoreNtfsSymLinks); }
110 inline bool caseSensitive()
const {
if (info)
return info->isCaseSensitive();
return false; }
111 inline QIcon icon()
const {
if (info)
return info->icon;
return QIcon(); }
113 inline bool operator <(
const QFileSystemNode &node)
const {
114 if (caseSensitive() || node.caseSensitive())
115 return fileName < node.fileName;
116 return QString::compare(fileName, node.fileName, Qt::CaseInsensitive) < 0;
118 inline bool operator >(
const QString &name)
const {
120 return fileName > name;
121 return QString::compare(fileName, name, Qt::CaseInsensitive) > 0;
123 inline bool operator <(
const QString &name)
const {
125 return fileName < name;
126 return QString::compare(fileName, name, Qt::CaseInsensitive) < 0;
128 inline bool operator !=(
const QExtendedInformation &fileInfo)
const {
129 return !operator==(fileInfo);
131 bool operator ==(
const QString &name)
const {
133 return fileName == name;
134 return QString::compare(fileName, name, Qt::CaseInsensitive) == 0;
136 bool operator ==(
const QExtendedInformation &fileInfo)
const {
137 return info && (*info == fileInfo);
140 inline bool hasInformation()
const {
return info !=
nullptr; }
142 void populate(
const QExtendedInformation &fileInfo) {
144 info =
new QExtendedInformation(fileInfo.fileInfo());
149 inline int visibleLocation(
const QString &childName) {
150 return visibleChildren.indexOf(childName);
152 void updateIcon(QAbstractFileIconProvider *iconProvider,
const QString &path) {
157 info->icon = iconProvider->icon(QFileInfo(path));
159 for (QFileSystemNode *child : std::as_const(children)) {
161 if (!path.isEmpty()) {
162 if (path.endsWith(u'/'))
163 child->updateIcon(iconProvider, path + child->fileName);
165 child->updateIcon(iconProvider, path + u'/' + child->fileName);
167 child->updateIcon(iconProvider, child->fileName);
171 void retranslateStrings(QAbstractFileIconProvider *iconProvider,
const QString &path) {
176 info->displayType = iconProvider->type(QFileInfo(path));
177 for (QFileSystemNode *child : std::as_const(children)) {
179 if (!path.isEmpty()) {
180 if (path.endsWith(u'/'))
181 child->retranslateStrings(iconProvider, path + child->fileName);
183 child->retranslateStrings(iconProvider, path + u'/' + child->fileName);
185 child->retranslateStrings(iconProvider, child->fileName);
189 QHash<QFileSystemModelNodePathKey, QFileSystemNode *> children;
190 QList<QString> visibleChildren;
191 QExtendedInformation *info =
nullptr;
192 QFileSystemNode *parent;
193 int dirtyChildrenIndex = -1;
194 bool populatedChildren =
false;
195 bool isVisible =
false;
198 QFileSystemModelPrivate();
199 ~QFileSystemModelPrivate();
202
203
204
205
206 inline bool isHiddenByFilter(QFileSystemNode *indexNode,
const QModelIndex &index)
const
208 return (indexNode != &root && !index.isValid());
210 QFileSystemNode *node(
const QModelIndex &index)
const;
211 QFileSystemNode *node(
const QString &path,
bool fetch =
true)
const;
212 inline QModelIndex index(
const QString &path,
int column = 0) {
return index(node(path), column); }
213 QModelIndex index(
const QFileSystemNode *node,
int column = 0)
const;
214 bool filtersAcceptsNode(
const QFileSystemNode *node)
const;
215 bool passNameFilters(
const QFileSystemNode *node)
const;
216 void removeNode(QFileSystemNode *parentNode,
const QString &name);
217 QFileSystemNode* addNode(QFileSystemNode *parentNode,
const QString &fileName,
const QFileInfo &info);
218 void addVisibleFiles(QFileSystemNode *parentNode,
const QStringList &newFiles);
219 void removeVisibleFile(QFileSystemNode *parentNode,
int visibleLocation);
220 void sortChildren(
int column,
const QModelIndex &parent);
222 inline int translateVisibleLocation(QFileSystemNode *parent,
int row)
const {
223 if (sortOrder != Qt::AscendingOrder) {
224 if (parent->dirtyChildrenIndex == -1)
225 return parent->visibleChildren.size() - row - 1;
227 if (row < parent->dirtyChildrenIndex)
228 return parent->dirtyChildrenIndex - row - 1;
234 inline static QString myComputer() {
240 return QFileSystemModel::tr(
"My Computer");
242 return QFileSystemModel::tr(
"Computer");
246 inline void delayedSort() {
247 if (!delayedSortTimer.isActive())
248 delayedSortTimer.start(0);
251 QIcon icon(
const QModelIndex &index)
const;
252 QString name(
const QModelIndex &index)
const;
253 QString displayName(
const QModelIndex &index)
const;
254 QString filePath(
const QModelIndex &index)
const;
255 QString size(
const QModelIndex &index)
const;
256 static QString size(qint64 bytes);
257 QString type(
const QModelIndex &index)
const;
258 QString time(
const QModelIndex &index)
const;
260 void directoryChanged(
const QString &directory,
const QStringList &list);
261 void performDelayedSort();
262 void fileSystemChanged(
const QString &path,
const QList<std::pair<QString, QFileInfo>> &);
263 void resolvedName(
const QString &fileName,
const QString &resolvedName);
266#if QT_CONFIG(filesystemwatcher)
268 QStringList unwatchPathsAt(
const QModelIndex &);
269 void watchPaths(
const QStringList &paths) { fileInfoGatherer->watchPaths(paths); }
271 std::unique_ptr<QFileInfoGatherer> fileInfoGatherer;
273 QTimer delayedSortTimer;
274 QHash<
const QFileSystemNode*,
bool> bypassFilters;
275#if QT_CONFIG(regularexpression)
276 QStringList nameFilters;
277 std::vector<QRegularExpression> nameFiltersRegexps;
278 void rebuildNameFilterRegexps();
280 QHash<QString, QString> resolvedSymLinks;
282 QFileSystemNode root;
287 const QFileSystemNode *node;
289 QList<Fetching> toFetch;
291 QBasicTimer fetchingTimer;
293 QDir::Filters filters = QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs;
295 Qt::SortOrder sortOrder = Qt::AscendingOrder;
296 bool forceSort =
true;
297 bool readOnly =
true;
298 bool setRootPath =
false;
299 bool nameFilterDisables =
true;
302 bool disableRecursiveSort =
false;