diff options
Diffstat (limited to 'src/gui/itemmodels/qfilesystemmodel_p.h')
-rw-r--r-- | src/gui/itemmodels/qfilesystemmodel_p.h | 95 |
1 files changed, 38 insertions, 57 deletions
diff --git a/src/gui/itemmodels/qfilesystemmodel_p.h b/src/gui/itemmodels/qfilesystemmodel_p.h index 70468460e8..e01b0d56e6 100644 --- a/src/gui/itemmodels/qfilesystemmodel_p.h +++ b/src/gui/itemmodels/qfilesystemmodel_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QFILESYSTEMMODEL_P_H #define QFILESYSTEMMODEL_P_H @@ -86,7 +50,10 @@ public: Q_DECLARE_TYPEINFO(QFileSystemModelNodePathKey, Q_RELOCATABLE_TYPE); -inline size_t qHash(const QFileSystemModelNodePathKey &key) { return qHash(key.toCaseFolded()); } +inline size_t qHash(const QFileSystemModelNodePathKey &key, size_t seed = 0) +{ + return qHash(key.toCaseFolded(), seed); +} #else // Q_OS_WIN typedef QString QFileSystemModelNodePathKey; #endif @@ -96,7 +63,13 @@ class Q_GUI_EXPORT QFileSystemModelPrivate : public QAbstractItemModelPrivate Q_DECLARE_PUBLIC(QFileSystemModel) public: - enum { NumColumns = 4 }; + enum { + NameColumn, + SizeColumn, + TypeColumn, + TimeColumn, + NumColumns = 4 + }; class QFileSystemNode { @@ -116,8 +89,8 @@ public: #endif inline qint64 size() const { if (info && !info->isDir()) return info->size(); return 0; } - inline QString type() const { if (info) return info->displayType; return QLatin1String(""); } - inline QDateTime lastModified() const { if (info) return info->lastModified(); return QDateTime(); } + inline QString type() const { if (info) return info->displayType; return QLatin1StringView(""); } + inline QDateTime lastModified(const QTimeZone &tz) const { return info ? info->lastModified(tz) : QDateTime(); } inline QFile::Permissions permissions() const { if (info) return info->permissions(); return { }; } inline bool isReadable() const { return ((permissions() & QFile::ReadUser) != 0); } inline bool isWritable() const { return ((permissions() & QFile::WriteUser) != 0); } @@ -125,7 +98,7 @@ public: inline bool isDir() const { if (info) return info->isDir(); - if (children.count() > 0) + if (children.size() > 0) return true; return false; } @@ -177,30 +150,37 @@ public: return visibleChildren.indexOf(childName); } void updateIcon(QAbstractFileIconProvider *iconProvider, const QString &path) { + if (!iconProvider) + return; + if (info) info->icon = iconProvider->icon(QFileInfo(path)); - for (QFileSystemNode *child : qAsConst(children)) { + + for (QFileSystemNode *child : std::as_const(children)) { //On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/) if (!path.isEmpty()) { - if (path.endsWith(QLatin1Char('/'))) + if (path.endsWith(u'/')) child->updateIcon(iconProvider, path + child->fileName); else - child->updateIcon(iconProvider, path + QLatin1Char('/') + child->fileName); + child->updateIcon(iconProvider, path + u'/' + child->fileName); } else child->updateIcon(iconProvider, child->fileName); } } void retranslateStrings(QAbstractFileIconProvider *iconProvider, const QString &path) { + if (!iconProvider) + return; + if (info) info->displayType = iconProvider->type(QFileInfo(path)); - for (QFileSystemNode *child : qAsConst(children)) { + for (QFileSystemNode *child : std::as_const(children)) { //On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/) if (!path.isEmpty()) { - if (path.endsWith(QLatin1Char('/'))) + if (path.endsWith(u'/')) child->retranslateStrings(iconProvider, path + child->fileName); else - child->retranslateStrings(iconProvider, path + QLatin1Char('/') + child->fileName); + child->retranslateStrings(iconProvider, path + u'/' + child->fileName); } else child->retranslateStrings(iconProvider, child->fileName); } @@ -215,7 +195,8 @@ public: bool isVisible = false; }; - QFileSystemModelPrivate() = default; + QFileSystemModelPrivate(); + ~QFileSystemModelPrivate(); void init(); /* \internal @@ -241,7 +222,7 @@ public: inline int translateVisibleLocation(QFileSystemNode *parent, int row) const { if (sortOrder != Qt::AscendingOrder) { if (parent->dirtyChildrenIndex == -1) - return parent->visibleChildren.count() - row - 1; + return parent->visibleChildren.size() - row - 1; if (row < parent->dirtyChildrenIndex) return parent->dirtyChildrenIndex - row - 1; @@ -276,18 +257,18 @@ public: QString type(const QModelIndex &index) const; QString time(const QModelIndex &index) const; - void _q_directoryChanged(const QString &directory, const QStringList &list); - void _q_performDelayedSort(); - void _q_fileSystemChanged(const QString &path, const QList<QPair<QString, QFileInfo>> &); - void _q_resolvedName(const QString &fileName, const QString &resolvedName); + void directoryChanged(const QString &directory, const QStringList &list); + void performDelayedSort(); + void fileSystemChanged(const QString &path, const QList<std::pair<QString, QFileInfo>> &); + void resolvedName(const QString &fileName, const QString &resolvedName); QDir rootDir; #if QT_CONFIG(filesystemwatcher) # ifdef Q_OS_WIN QStringList unwatchPathsAt(const QModelIndex &); - void watchPaths(const QStringList &paths) { fileInfoGatherer.watchPaths(paths); } + void watchPaths(const QStringList &paths) { fileInfoGatherer->watchPaths(paths); } # endif // Q_OS_WIN - QFileInfoGatherer fileInfoGatherer; + std::unique_ptr<QFileInfoGatherer> fileInfoGatherer; #endif // filesystemwatcher QTimer delayedSortTimer; QHash<const QFileSystemNode*, bool> bypassFilters; |