]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kfileitemmodelsortalgorithm.h
Fix Bug 310465 - Can't switch view mode for non-writable paths
[dolphin.git] / src / kitemviews / private / kfileitemmodelsortalgorithm.h
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
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 KFILEITEMMODELSORTALGORITHM_H
21 #define KFILEITEMMODELSORTALGORITHM_H
22
23 #include <libdolphin_export.h>
24
25 #include <kitemviews/kfileitemmodel.h>
26
27 /**
28 * @brief Sort algorithm for sorting items of KFileItemModel.
29 *
30 * Sorts the items by using KFileItemModel::lessThan() as comparison criteria.
31 * The merge sort algorithm is used to assure a worst-case
32 * of O(n * log(n)) and to keep the number of comparisons low.
33 *
34 * The implementation is based on qStableSortHelper() from qalgorithms.h
35 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
36 * The sorting implementations of qAlgorithms could not be used as they
37 * don't support having a member-function as comparison criteria.
38 */
39 class LIBDOLPHINPRIVATE_EXPORT KFileItemModelSortAlgorithm
40 {
41 public:
42 static void sort(KFileItemModel* model,
43 QList<KFileItemModel::ItemData*>::iterator begin,
44 QList<KFileItemModel::ItemData*>::iterator end);
45
46 private:
47 static void merge(KFileItemModel* model,
48 QList<KFileItemModel::ItemData*>::iterator begin,
49 QList<KFileItemModel::ItemData*>::iterator pivot,
50 QList<KFileItemModel::ItemData*>::iterator end);
51
52 static QList<KFileItemModel::ItemData*>::iterator
53 lowerBound(KFileItemModel* model,
54 QList<KFileItemModel::ItemData*>::iterator begin,
55 QList<KFileItemModel::ItemData*>::iterator end,
56 const KFileItemModel::ItemData* value);
57
58 static QList<KFileItemModel::ItemData*>::iterator
59 upperBound(KFileItemModel* model,
60 QList<KFileItemModel::ItemData*>::iterator begin,
61 QList<KFileItemModel::ItemData*>::iterator end,
62 const KFileItemModel::ItemData* value);
63
64 static void reverse(QList<KFileItemModel::ItemData*>::iterator begin,
65 QList<KFileItemModel::ItemData*>::iterator end);
66 };
67
68 #endif
69
70