~mterry/telephony-service/notification-timeout

« back to all changes in this revision

Viewing changes to FilterModel.qml

  • Committer: Gustavo Pichorim Boiko
  • Date: 2013-03-12 18:15:29 UTC
  • mto: This revision was merged to the branch mainline in revision 610.
  • Revision ID: gustavo.boiko@canonical.com-20130312181529-rabifvte8sfls914
Rename the main app files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2012 Canonical Ltd.
3
 
 *
4
 
 * This file is part of telephony-app.
5
 
 *
6
 
 * telephony-app is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; version 3.
9
 
 *
10
 
 * telephony-app is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
import QtQuick 2.0
20
 
 
21
 
QtObject {
22
 
    property ListModel proxyModel: null
23
 
    property ListModel model: ListModel { }
24
 
    property string filter: ""
25
 
    property variant fields: null
26
 
    property int proxyCount: proxyModel ? proxyModel.count : 0
27
 
 
28
 
    function checkFilter(element) {
29
 
        if (filter.length == 0) {
30
 
            return true
31
 
        }
32
 
 
33
 
        var lowerFilter = filter.toLowerCase()
34
 
        for (var i=0; i < fields.length; i++) {
35
 
            var value = element[fields[i]].toLowerCase()
36
 
            if (value.indexOf(lowerFilter) >= 0)
37
 
                return true
38
 
        }
39
 
 
40
 
        return false
41
 
    }
42
 
 
43
 
    function applyFilter() {
44
 
        model.clear();
45
 
        for(var i=0; i < proxyModel.count; i++) {
46
 
            var element = proxyModel.get(i)
47
 
            if (checkFilter(element)) {
48
 
                model.append(element)
49
 
            }
50
 
        }
51
 
    }
52
 
 
53
 
    onProxyModelChanged: { applyFilter() }
54
 
    onFilterChanged: { applyFilter() }
55
 
    onProxyCountChanged: applyFilter()
56
 
}