2
* Copyright (C) 2007-2008 Omat Holding B.V. <info@omat.nl>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library 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 GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#include "ksortfilterproxymodel.h"
23
* Private class that helps to provide binary compatibility between releases.
27
class KSortFilterProxyModelPrivate {
29
KSortFilterProxyModelPrivate() {
30
showAllChildren = false;
32
~KSortFilterProxyModelPrivate() {}
37
KSortFilterProxyModel::KSortFilterProxyModel(QObject * parent)
38
: QSortFilterProxyModel(parent), d_ptr( new KSortFilterProxyModelPrivate )
42
KSortFilterProxyModel::~KSortFilterProxyModel()
47
bool KSortFilterProxyModel::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const
49
if( filterRegExp().isEmpty() ) return true; //Shortcut for common case
51
if( QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent) )
54
//one of our children might be accepted, so accept this row if one of our children are accepted.
55
QModelIndex source_index = sourceModel()->index(source_row, 0, source_parent);
56
for(int i = 0 ; i < sourceModel()->rowCount(source_index); i++) {
57
if(filterAcceptsRow(i, source_index)) return true;
60
//one of our parents might be accepted, so accept this row if one of our parents is accepted.
61
if(d_ptr->showAllChildren) {
62
QModelIndex parent_index = source_parent;
63
while(parent_index.isValid()) {
64
int row = parent_index.row();
65
parent_index = parent_index.parent();
66
if(QSortFilterProxyModel::filterAcceptsRow(row, parent_index)) return true;
73
bool KSortFilterProxyModel::showAllChildren() const
75
return d_ptr->showAllChildren;
77
void KSortFilterProxyModel::setShowAllChildren(bool showAllChildren)
79
if(showAllChildren == d_ptr->showAllChildren)
81
d_ptr->showAllChildren = showAllChildren;