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 kdirsortfilterproxymodel.h <KDirSortFilterProxyModel>
24 *
25 * @brief Acts as proxy model for KDirModel to sort and filter
26 * KFileItems.
27 *
28 * A natural sorting is done. This means that items like:
29 * - item_10.png
30 * - item_1.png
31 * - item_2.png
32 *
33 * are sorted like
34 * - item_1.png
35 * - item_2.png
36 * - item_10.png
37 *
38 * Don't use it with non-KDirModel derivatives.
39 *
40 * @author Dominic Battre, Martin Pool and Peter Penz
41 */
42class KIOFILEWIDGETS_EXPORT KDirSortFilterProxyModel : public KCategorizedSortFilterProxyModel
43{
44 Q_OBJECT
45
46public:
47 explicit KDirSortFilterProxyModel(QObject *parent = nullptr);
48 ~KDirSortFilterProxyModel() override;
49
50 /** Reimplemented from QAbstractItemModel. Returns true for directories. */
51 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
52
53 /**
54 * Reimplemented from QAbstractItemModel.
55 * Returns true for 'empty' directories so they can be populated later.
56 */
57 bool canFetchMore(const QModelIndex &parent) const override;
58
59 /**
60 * Returns the permissions in "points". This is useful for sorting by
61 * permissions.
62 */
63 static int pointsForPermissions(const QFileInfo &info);
64
65 /**
66 * Choose if files and folders are sorted separately (with folders first) or not.
67 */
68 void setSortFoldersFirst(bool foldersFirst);
69
70 /**
71 * Returns if files and folders are sorted separately (with folders first) or not.
72 */
73 bool sortFoldersFirst() const;
74
75 /**
76 * Sets a separate sorting with hidden files and folders last (true) or not (false).
77 * @since 5.95
78 */
79 void setSortHiddenFilesLast(bool hiddenFilesLast);
80 bool sortHiddenFilesLast() const;
81
82 Qt::DropActions supportedDragOptions() const;
83
84protected:
85 /**
86 * Reimplemented from KCategorizedSortFilterProxyModel.
87 */
88 virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override;
89
90private:
91 class KDirSortFilterProxyModelPrivate;
92 std::unique_ptr<KDirSortFilterProxyModelPrivate> const d;
93};
94
95#endif
96

source code of kio/src/filewidgets/kdirsortfilterproxymodel.h