]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinsortfilterproxymodel.h
b9e6b74e887868afb6dcf9299d3d9f624f9ba60a
[dolphin.git] / src / dolphinsortfilterproxymodel.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef DOLPHINSORTFILTERPROXYMODEL_H
21 #define DOLPHINSORTFILTERPROXYMODEL_H
22
23 #include <dolphinview.h>
24 #include <kdirsortfilterproxymodel.h>
25 #include <libdolphin_export.h>
26
27 /**
28 * @brief Acts as proxy model for DolphinModel to sort and filter
29 * KFileItems.
30 *
31 * A natural sorting is done. This means that items like:
32 * - item_10.png
33 * - item_1.png
34 * - item_2.png
35 * are sorted like
36 * - item_1.png
37 * - item_2.png
38 * - item_10.png
39 *
40 * @note It is NOT assured that directories are always sorted before files.
41 * For example, on a Nepomuk based sorting, it is possible to have a file
42 * rated with 10 stars, and a directory rated with 5 stars. The file will
43 * be shown before the directory.
44 */
45 class LIBDOLPHINPRIVATE_EXPORT DolphinSortFilterProxyModel : public KDirSortFilterProxyModel
46 {
47 Q_OBJECT
48
49 public:
50 DolphinSortFilterProxyModel(QObject* parent = 0);
51 virtual ~DolphinSortFilterProxyModel();
52
53 void setSorting(DolphinView::Sorting sorting);
54 DolphinView::Sorting sorting() const;
55
56 void setSortOrder(Qt::SortOrder sortOrder);
57 Qt::SortOrder sortOrder() const;
58
59 /**
60 * @reimplemented, @internal
61 *
62 * If the view 'forces' sorting order to change we will
63 * notice now.
64 */
65 virtual void sort(int column,
66 Qt::SortOrder order = Qt::AscendingOrder);
67
68 /**
69 * Helper method to get the DolphinView::Sorting type for a given
70 * column \a column. If the column is smaller 0 or greater than the
71 * available columns, DolphinView::SortByName is returned.
72 */
73 static DolphinView::Sorting sortingForColumn(int column);
74
75 signals:
76 void sortingRoleChanged();
77
78 protected:
79 virtual bool subSortLessThan(const QModelIndex& left,
80 const QModelIndex& right) const;
81
82 private:
83 /**
84 * Returns true, if the left or right file item is a directory
85 * or a hidden file. In this case \a result provides the information
86 * whether \a left is less than \a right. If false is returned,
87 * the value of \a result is undefined.
88 */
89 bool isDirectoryOrHidden(const KFileItem& left,
90 const KFileItem& right,
91 bool& result) const;
92
93 private:
94 DolphinView::Sorting m_sorting:16;
95 Qt::SortOrder m_sortOrder:16;
96 };
97
98 inline DolphinView::Sorting DolphinSortFilterProxyModel::sorting() const
99 {
100 return m_sorting;
101 }
102
103 inline Qt::SortOrder DolphinSortFilterProxyModel::sortOrder() const
104 {
105 return m_sortOrder;
106 }
107
108 #endif