]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinsortfilterproxymodel.h
e7fc781828f65bd50358b02db4c574f7467afa53
[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 <QSortFilterProxyModel>
24 #include <dolphinview.h>
25 #include <libdolphin_export.h>
26
27 /**
28 * @brief Acts as proxy model for KDirModel 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 * It is assured that directories are always sorted before files.
41 */
42 class LIBDOLPHINPRIVATE_EXPORT DolphinSortFilterProxyModel : public QSortFilterProxyModel
43 {
44 Q_OBJECT
45
46 public:
47 DolphinSortFilterProxyModel(QObject* parent = 0);
48 virtual ~DolphinSortFilterProxyModel();
49
50 void setSorting(DolphinView::Sorting sorting);
51 DolphinView::Sorting sorting() const
52 {
53 return m_sorting;
54 }
55
56 void setSortOrder(Qt::SortOrder sortOrder);
57 Qt::SortOrder sortOrder() const
58 {
59 return m_sortOrder;
60 }
61
62 /**
63 * @reimplemented, @internal
64 *
65 * If the view 'forces' sorting order to change we will
66 * notice now.
67 */
68 virtual void sort(int column,
69 Qt::SortOrder order = Qt::AscendingOrder);
70
71 /** Reimplemented from QAbstractItemModel. Returns true for directories. */
72 virtual bool hasChildren(const QModelIndex& parent = QModelIndex()) const;
73
74 /** Reimplemented from QAbstractItemModel. Returns true for empty directories. */
75 virtual bool canFetchMore(const QModelIndex& parent) const;
76
77 /**
78 * Helper method to get the DolphinView::Sorting type for a given
79 * column \a column. If the column is smaller 0 or greater than the
80 * available columns, DolphinView::SortByName is returned.
81 */
82 static DolphinView::Sorting sortingForColumn(int column);
83
84 protected:
85 virtual bool lessThan(const QModelIndex& left,
86 const QModelIndex& right) const;
87
88 private:
89 static int naturalCompare(const QString& a, const QString& b);
90
91 private:
92 int m_sortColumn;
93 DolphinView::Sorting m_sorting;
94 Qt::SortOrder m_sortOrder;
95 };
96
97 #endif