| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at> |
| 3 | SPDX-FileCopyrightText: 2006 Dominic Battre <dominic@battre.de> |
| 4 | SPDX-FileCopyrightText: 2006 Martin Pool <mbp@canonical.com> |
| 5 | |
| 6 | Separated from Dolphin by Nick Shaforostoff <shafff@ukr.net> |
| 7 | |
| 8 | SPDX-License-Identifier: LGPL-2.0-only |
| 9 | */ |
| 10 | |
| 11 | #ifndef KDIRSORTFILTERPROXYMODEL_H |
| 12 | #define KDIRSORTFILTERPROXYMODEL_H |
| 13 | |
| 14 | #include <QFileInfo> |
| 15 | |
| 16 | #include <KCategorizedSortFilterProxyModel> |
| 17 | |
| 18 | #include "kiofilewidgets_export.h" |
| 19 | |
| 20 | #include <memory> |
| 21 | |
| 22 | /*! |
| 23 | * \class KDirSortFilterProxyModel |
| 24 | * \inmodule KIOFileWidgets |
| 25 | * |
| 26 | * \brief Acts as proxy model for KDirModel to sort and filter |
| 27 | * KFileItems. |
| 28 | * |
| 29 | * A natural sorting is done. This means that items like: |
| 30 | * \list |
| 31 | * \li item_10.png |
| 32 | * \li item_1.png |
| 33 | * \li item_2.png |
| 34 | * \endlist |
| 35 | * |
| 36 | * are sorted like |
| 37 | * \list |
| 38 | * \li item_1.png |
| 39 | * \li item_2.png |
| 40 | * \li item_10.png |
| 41 | * \endlist |
| 42 | * |
| 43 | * Don't use it with non-KDirModel derivatives. |
| 44 | */ |
| 45 | class KIOFILEWIDGETS_EXPORT KDirSortFilterProxyModel : public KCategorizedSortFilterProxyModel |
| 46 | { |
| 47 | Q_OBJECT |
| 48 | |
| 49 | public: |
| 50 | explicit KDirSortFilterProxyModel(QObject *parent = nullptr); |
| 51 | ~KDirSortFilterProxyModel() override; |
| 52 | |
| 53 | /*! |
| 54 | * \reimp |
| 55 | * Returns true for directories. |
| 56 | */ |
| 57 | bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; |
| 58 | |
| 59 | /*! |
| 60 | * \reimp |
| 61 | * Returns true for 'empty' directories so they can be populated later. |
| 62 | */ |
| 63 | bool canFetchMore(const QModelIndex &parent) const override; |
| 64 | |
| 65 | /*! |
| 66 | * Returns the permissions in "points". This is useful for sorting by |
| 67 | * permissions. |
| 68 | */ |
| 69 | static int pointsForPermissions(const QFileInfo &info); |
| 70 | |
| 71 | /*! |
| 72 | * Choose if files and folders are sorted separately (with folders first) or not. |
| 73 | */ |
| 74 | void setSortFoldersFirst(bool foldersFirst); |
| 75 | |
| 76 | /*! |
| 77 | * Returns if files and folders are sorted separately (with folders first) or not. |
| 78 | */ |
| 79 | bool sortFoldersFirst() const; |
| 80 | |
| 81 | /*! |
| 82 | * Sets a separate sorting with hidden files and folders last (true) or not (false). |
| 83 | * \since 5.95 |
| 84 | */ |
| 85 | void setSortHiddenFilesLast(bool hiddenFilesLast); |
| 86 | |
| 87 | /*! |
| 88 | * |
| 89 | */ |
| 90 | bool sortHiddenFilesLast() const; |
| 91 | |
| 92 | /*! |
| 93 | * |
| 94 | */ |
| 95 | Qt::DropActions supportedDragOptions() const; |
| 96 | |
| 97 | protected: |
| 98 | bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override; |
| 99 | |
| 100 | private: |
| 101 | class KDirSortFilterProxyModelPrivate; |
| 102 | std::unique_ptr<KDirSortFilterProxyModelPrivate> const d; |
| 103 | }; |
| 104 | |
| 105 | #endif |
| 106 | |