~ps-jenkins/unity-scopes-shell/ubuntu-rtm-14.09-proposed

« back to all changes in this revision

Viewing changes to src/unityoptionsmodel.cpp

  • Committer: Michal Hruby
  • Date: 2013-11-07 17:48:16 UTC
  • Revision ID: michal.mhr@gmail.com-20131107174816-w1vqq6juarrawx23
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Pawel Stolowski <pawel.stolowski@canonical.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; version 3.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
// self
 
21
#include "unityoptionsmodel.h"
 
22
 
 
23
// local
 
24
#include "filteroption.h"
 
25
 
 
26
UnityOptionsModel::UnityOptionsModel(QObject *parent,
 
27
                                     const std::vector<unity::dash::FilterOption::Ptr> options,
 
28
                                     sigc::signal<void, unity::dash::FilterOption::Ptr> optionAdded,
 
29
                                     sigc::signal<void, unity::dash::FilterOption::Ptr> optionRemoved,
 
30
                                     bool showAllOption) :
 
31
    GenericOptionsModel(showAllOption, parent)
 
32
{
 
33
    setOptions(options, optionAdded, optionRemoved);
 
34
}
 
35
 
 
36
void UnityOptionsModel::setOptions(const std::vector<unity::dash::FilterOption::Ptr> options,
 
37
                                            sigc::signal<void, unity::dash::FilterOption::Ptr> optionAdded,
 
38
                                            sigc::signal<void, unity::dash::FilterOption::Ptr> optionRemoved)
 
39
{
 
40
    for (unsigned int i=0; i<options.size(); i++)
 
41
    {
 
42
        addOption(new FilterOption(options[i], this));
 
43
    }
 
44
    optionAdded.connect(sigc::mem_fun(this, &UnityOptionsModel::onOptionAdded));
 
45
    optionRemoved.connect(sigc::mem_fun(this, &UnityOptionsModel::onOptionRemoved));
 
46
}
 
47
 
 
48
void UnityOptionsModel::onOptionAdded(unity::dash::FilterOption::Ptr option)
 
49
{
 
50
    int index = m_options.count();
 
51
    if (index >= 0)
 
52
    {
 
53
        beginInsertRows(QModelIndex(), index, index);
 
54
        addOption(new FilterOption(option, this));
 
55
        endInsertRows();
 
56
    }
 
57
}
 
58
 
 
59
void UnityOptionsModel::onOptionRemoved(unity::dash::FilterOption::Ptr option)
 
60
{
 
61
    auto index = indexOf(QString::fromStdString(option->id));
 
62
    if (index >= 0)
 
63
    {
 
64
        beginRemoveRows(QModelIndex(), index, index);
 
65
        removeOption(index);
 
66
        endRemoveRows();
 
67
    }
 
68
}