1
2/*
3 * infokcmproxymodel.cpp
4 *
5 * Copyright (C) 2010 David Hubner <hubnerd@ntlworld.com>
6 *
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.
11 *
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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23//Local
24#include "infokcmproxymodel.h"
25
26//KDE
27#include <KDebug>
28
29InfoKcmProxyModel::InfoKcmProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
30{
31 setSortRole(Qt::UserRole);
32}
33
34bool InfoKcmProxyModel::lessThan(const QModelIndex &leftIndex, const QModelIndex &rightIndex) const
35{
36 if(!leftIndex.isValid() && !rightIndex.isValid()) return true;
37
38 KcmTreeItem *leftItem = static_cast<KcmTreeItem*>(leftIndex.internalPointer());
39 KcmTreeItem *rightItem = static_cast<KcmTreeItem*>(rightIndex.internalPointer());
40
41 return (leftItem->weight() < rightItem->weight());
42}
43
44bool InfoKcmProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
45{
46 QModelIndex index=sourceModel()->index(sourceRow, 0, sourceParent);
47 KcmTreeItem *indexItem = static_cast<KcmTreeItem*>(index.internalPointer());
48
49 if(indexItem->type() == KcmTreeItem::CATEGORY)
50 {
51 if(indexItem->childrenRegExp(filterRegExp()) == true) return true;
52 }
53 return ((indexItem->keywords().filter(filterRegExp()).count() > 0));
54}
55