]>
cloud.milkyroute.net Git - dolphin.git/blob - src/views/dolphinsortfilterproxymodel.cpp
70256f15612ccab55f66012dcebcea336173195e
1 /***************************************************************************
2 * Copyright (C) 2006-2010 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 * Copyright (C) 2007 by Rafael Fernández López <ereslibre@kde.org> *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program 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 *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
23 #include "dolphinsortfilterproxymodel.h"
25 DolphinSortFilterProxyModel::DolphinSortFilterProxyModel(QObject
* parent
) :
26 KDirSortFilterProxyModel(parent
),
27 m_sorting(DolphinView::SortByName
),
28 m_sortOrder(Qt::AscendingOrder
)
32 DolphinSortFilterProxyModel::~DolphinSortFilterProxyModel()
36 void DolphinSortFilterProxyModel::setSorting(DolphinView::Sorting sorting
)
39 KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting
), m_sortOrder
);
42 void DolphinSortFilterProxyModel::setSortOrder(Qt::SortOrder sortOrder
)
44 m_sortOrder
= sortOrder
;
45 KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting
), m_sortOrder
);
48 void DolphinSortFilterProxyModel::setSortFoldersFirst(bool foldersFirst
)
50 if (foldersFirst
!= sortFoldersFirst()) {
51 KDirSortFilterProxyModel::setSortFoldersFirst(foldersFirst
);
53 // We need to make sure that the files and folders are really resorted.
54 // Without the following two lines, QSortFilterProxyModel::sort(int column, Qt::SortOrder order)
55 // would do nothing because neither the column nor the sort order have changed.
56 // TODO: remove this hack if we find a better way to force the ProxyModel to re-sort the data.
57 const Qt::SortOrder tmpSortOrder
= (m_sortOrder
== Qt::AscendingOrder
? Qt::DescendingOrder
: Qt::AscendingOrder
);
58 KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting
), tmpSortOrder
);
60 // Now comes the real sorting with the old column and sort order
61 KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting
), m_sortOrder
);
65 void DolphinSortFilterProxyModel::sort(int column
, Qt::SortOrder sortOrder
)
67 m_sorting
= sortingForColumn(column
);
68 m_sortOrder
= sortOrder
;
70 emit
sortingRoleChanged();
71 KDirSortFilterProxyModel::sort(static_cast<int>(m_sorting
), sortOrder
);
74 DolphinView::Sorting
DolphinSortFilterProxyModel::sortingForColumn(int column
)
76 Q_ASSERT(column
>= 0);
77 Q_ASSERT(column
<= DolphinView::MaxSortingEnum
);
78 return static_cast<DolphinView::Sorting
>(column
);
81 #include "dolphinsortfilterproxymodel.moc"