~ubuntu-branches/ubuntu/trusty/bibletime/trusty

« back to all changes in this revision

Viewing changes to src/backend/bookshelfmodel/btmodulenamefilterproxymodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden
  • Date: 2009-10-08 22:55:24 UTC
  • mfrom: (1.2.4 upstream) (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091008225524-sbgsvm8jpndjeul4
* New upstream version 2.3
* Bump Standards-Version to 3.8.3 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* In the name of the Father, and of the Son, and of the Holy Spirit.
 
4
*
 
5
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
6
*
 
7
* Copyright 1999-2009 by the BibleTime developers.
 
8
* The BibleTime source code is licensed under the GNU General Public License
 
9
* version 2.0.
 
10
*
 
11
**********/
 
12
 
 
13
#include "backend/bookshelfmodel/btmodulenamefilterproxymodel.h"
 
14
 
 
15
BtModuleNameFilterProxyModel::BtModuleNameFilterProxyModel(QObject *parent)
 
16
    : QSortFilterProxyModel(parent), m_enabled(true)
 
17
{
 
18
    setFilterCaseSensitivity(Qt::CaseInsensitive);
 
19
}
 
20
 
 
21
BtModuleNameFilterProxyModel::~BtModuleNameFilterProxyModel() {
 
22
    // Intentionally empty
 
23
}
 
24
 
 
25
bool BtModuleNameFilterProxyModel::filterAcceptsRow(int row,
 
26
                                                    const QModelIndex &p) const
 
27
{
 
28
    if (!m_enabled) return true;
 
29
 
 
30
    const QAbstractItemModel *m(sourceModel());
 
31
    Q_ASSERT(m != 0);
 
32
 
 
33
    QModelIndex itemIndex(m->index(row, 0, p));
 
34
    int numChildren(m->rowCount(itemIndex));
 
35
    if (numChildren == 0) {
 
36
        return QSortFilterProxyModel::filterAcceptsRow(row, p);
 
37
    } else {
 
38
        for (int i(0); i < numChildren; i++) {
 
39
            if (filterAcceptsRow(i, itemIndex)) return true;
 
40
        }
 
41
        return false;
 
42
    }
 
43
}