1 | /* |
2 | Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> |
3 | Copyright (C) 2006 by Dominic Battre <dominic@battre.de> |
4 | Copyright (C) 2006 by Martin Pool <mbp@canonical.com> |
5 | |
6 | Separated from Dolphin by Nick Shaforostoff <shafff@ukr.net> |
7 | |
8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public |
10 | License version 2 as published by the Free Software Foundation. |
11 | |
12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. |
21 | */ |
22 | |
23 | #ifndef KDIRSORTFILTERPROXYMODEL_H |
24 | #define KDIRSORTFILTERPROXYMODEL_H |
25 | |
26 | #include <QtCore/QFileInfo> |
27 | |
28 | #include <kcategorizedsortfilterproxymodel.h> |
29 | |
30 | #include <kfile_export.h> |
31 | |
32 | /** |
33 | * @brief Acts as proxy model for KDirModel to sort and filter |
34 | * KFileItems. |
35 | * |
36 | * A natural sorting is done. This means that items like: |
37 | * - item_10.png |
38 | * - item_1.png |
39 | * - item_2.png |
40 | * |
41 | * are sorted like |
42 | * - item_1.png |
43 | * - item_2.png |
44 | * - item_10.png |
45 | * |
46 | * Don't use it with non-KDirModel derivatives. |
47 | * |
48 | * @author Dominic Battre, Martin Pool and Peter Penz |
49 | */ |
50 | class KFILE_EXPORT KDirSortFilterProxyModel |
51 | : public KCategorizedSortFilterProxyModel |
52 | { |
53 | Q_OBJECT |
54 | |
55 | public: |
56 | KDirSortFilterProxyModel(QObject* parent = 0); |
57 | virtual ~KDirSortFilterProxyModel(); |
58 | |
59 | /** Reimplemented from QAbstractItemModel. Returns true for directories. */ |
60 | virtual bool hasChildren(const QModelIndex& parent = QModelIndex()) const; |
61 | |
62 | /** |
63 | * Reimplemented from QAbstractItemModel. |
64 | * Returns true for 'empty' directories so they can be populated later. |
65 | */ |
66 | virtual bool canFetchMore(const QModelIndex& parent) const; |
67 | |
68 | /** |
69 | * Returns the permissions in "points". This is useful for sorting by |
70 | * permissions. |
71 | */ |
72 | static int pointsForPermissions(const QFileInfo &info); |
73 | |
74 | /** |
75 | * Choose if files and folders are sorted separately (with folders first) or not. |
76 | * @since 4.3 |
77 | */ |
78 | void setSortFoldersFirst(bool foldersFirst); |
79 | |
80 | /** |
81 | * Returns if files and folders are sorted separately (with folders first) or not. |
82 | * @since 4.3 |
83 | */ |
84 | bool sortFoldersFirst() const; |
85 | |
86 | protected: |
87 | /** |
88 | * Reimplemented from KCategorizedSortFilterProxyModel. |
89 | */ |
90 | virtual bool subSortLessThan(const QModelIndex& left, |
91 | const QModelIndex& right) const; |
92 | private: |
93 | Q_PRIVATE_SLOT(d, void slotNaturalSortingChanged()) |
94 | |
95 | private: |
96 | class KDirSortFilterProxyModelPrivate; |
97 | KDirSortFilterProxyModelPrivate* const d; |
98 | }; |
99 | |
100 | |
101 | #endif |
102 | |