File indexing completed on 2024-09-15 03:38:39
0001 /* 0002 SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at> 0003 SPDX-FileCopyrightText: 2006 Dominic Battre <dominic@battre.de> 0004 SPDX-FileCopyrightText: 2006 Martin Pool <mbp@canonical.com> 0005 0006 Separated from Dolphin by Nick Shaforostoff <shafff@ukr.net> 0007 0008 SPDX-License-Identifier: LGPL-2.0-only 0009 */ 0010 0011 #ifndef KDIRSORTFILTERPROXYMODEL_H 0012 #define KDIRSORTFILTERPROXYMODEL_H 0013 0014 #include <QFileInfo> 0015 0016 #include <KCategorizedSortFilterProxyModel> 0017 0018 #include "kiofilewidgets_export.h" 0019 0020 #include <memory> 0021 0022 /** 0023 * @class KDirSortFilterProxyModel kdirsortfilterproxymodel.h <KDirSortFilterProxyModel> 0024 * 0025 * @brief Acts as proxy model for KDirModel to sort and filter 0026 * KFileItems. 0027 * 0028 * A natural sorting is done. This means that items like: 0029 * - item_10.png 0030 * - item_1.png 0031 * - item_2.png 0032 * 0033 * are sorted like 0034 * - item_1.png 0035 * - item_2.png 0036 * - item_10.png 0037 * 0038 * Don't use it with non-KDirModel derivatives. 0039 * 0040 * @author Dominic Battre, Martin Pool and Peter Penz 0041 */ 0042 class KIOFILEWIDGETS_EXPORT KDirSortFilterProxyModel : public KCategorizedSortFilterProxyModel 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 explicit KDirSortFilterProxyModel(QObject *parent = nullptr); 0048 ~KDirSortFilterProxyModel() override; 0049 0050 /** Reimplemented from QAbstractItemModel. Returns true for directories. */ 0051 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; 0052 0053 /** 0054 * Reimplemented from QAbstractItemModel. 0055 * Returns true for 'empty' directories so they can be populated later. 0056 */ 0057 bool canFetchMore(const QModelIndex &parent) const override; 0058 0059 /** 0060 * Returns the permissions in "points". This is useful for sorting by 0061 * permissions. 0062 */ 0063 static int pointsForPermissions(const QFileInfo &info); 0064 0065 /** 0066 * Choose if files and folders are sorted separately (with folders first) or not. 0067 */ 0068 void setSortFoldersFirst(bool foldersFirst); 0069 0070 /** 0071 * Returns if files and folders are sorted separately (with folders first) or not. 0072 */ 0073 bool sortFoldersFirst() const; 0074 0075 /** 0076 * Sets a separate sorting with hidden files and folders last (true) or not (false). 0077 * @since 5.95 0078 */ 0079 void setSortHiddenFilesLast(bool hiddenFilesLast); 0080 bool sortHiddenFilesLast() const; 0081 0082 Qt::DropActions supportedDragOptions() const; 0083 0084 protected: 0085 /** 0086 * Reimplemented from KCategorizedSortFilterProxyModel. 0087 */ 0088 virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override; 0089 0090 private: 0091 class KDirSortFilterProxyModelPrivate; 0092 std::unique_ptr<KDirSortFilterProxyModelPrivate> const d; 0093 }; 0094 0095 #endif