~ubuntu-branches/ubuntu/wily/zanshin/wily-proposed

« back to all changes in this revision

Viewing changes to src/contextsmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2009-08-13 23:19:32 UTC
  • Revision ID: james.westby@ubuntu.com-20090813231932-lewqphiry1qs7w80
Tags: upstream-0.1+svn1006410
ImportĀ upstreamĀ versionĀ 0.1+svn1006410

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Zanshin Todo.
 
2
 
 
3
   Copyright 2008 Kevin Ottens <ervin@kde.org>
 
4
 
 
5
   This program is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU General Public License as
 
7
   published by the Free Software Foundation; either version 2 of
 
8
   the License or (at your option) version 3 or any later version
 
9
   accepted by the membership of KDE e.V. (or its successor approved
 
10
   by the membership of KDE e.V.), which shall act as a proxy
 
11
   defined in Section 14 of version 3 of the license.
 
12
 
 
13
   This program is distributed in the hope that it will be useful,
 
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
16
   GNU General Public License for more details.
 
17
 
 
18
   You should have received a copy of the GNU General Public License
 
19
   along with this program; if not, write to the Free Software
 
20
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 
21
   USA.
 
22
*/
 
23
 
 
24
#include "contextsmodel.h"
 
25
 
 
26
#include "todocategoriesmodel.h"
 
27
#include "todoflatmodel.h"
 
28
 
 
29
ContextsModel::ContextsModel(QObject *parent)
 
30
    : QSortFilterProxyModel(parent)
 
31
{
 
32
    setDynamicSortFilter(true);
 
33
}
 
34
 
 
35
ContextsModel::~ContextsModel()
 
36
{
 
37
}
 
38
 
 
39
void ContextsModel::setSourceModel(QAbstractItemModel *sourceModel)
 
40
{
 
41
    Q_ASSERT(sourceModel==0 || qobject_cast<TodoCategoriesModel*>(sourceModel)!=0);
 
42
    QSortFilterProxyModel::setSourceModel(sourceModel);
 
43
 
 
44
    connect(categoriesModel(), SIGNAL(rowsInserted(const QModelIndex&, int, int)),
 
45
            this, SLOT(invalidate()));
 
46
    connect(categoriesModel(), SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
 
47
            this, SLOT(invalidate()));
 
48
    connect(categoriesModel(), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
 
49
            this, SLOT(invalidate()));
 
50
}
 
51
 
 
52
TodoCategoriesModel *ContextsModel::categoriesModel() const
 
53
{
 
54
    return qobject_cast<TodoCategoriesModel*>(sourceModel());
 
55
}
 
56
 
 
57
bool ContextsModel::filterAcceptsColumn(int sourceColumn, const QModelIndex &/*sourceParent*/) const
 
58
{
 
59
    return sourceColumn==TodoFlatModel::Summary;
 
60
}
 
61
 
 
62
bool ContextsModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
 
63
{
 
64
    QModelIndex index = categoriesModel()->index(sourceRow,
 
65
                                                 TodoFlatModel::RemoteId,
 
66
                                                 sourceParent);
 
67
 
 
68
    return categoriesModel()->data(index).toString().isEmpty();
 
69
}
 
70