on bbab3ce help sign in
unity8/plugins/Unity/unityoptionsmodel.cpp
67 lines 2.4 kB history raw
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 */
20// self
21#include "unityoptionsmodel.h"
23// local
24#include "filteroption.h"
26UnityOptionsModel::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 GenericOptionsModel(parent)
32 setOptions(options, optionAdded, optionRemoved);
35void UnityOptionsModel::setOptions(const std::vector<unity::dash::FilterOption::Ptr> options,
36 sigc::signal<void, unity::dash::FilterOption::Ptr> optionAdded,
37 sigc::signal<void, unity::dash::FilterOption::Ptr> optionRemoved)
39 for (unsigned int i=0; i<options.size(); i++)
40 {
41 addOption(new FilterOption(options[i], this), i);
42 }
43 optionAdded.connect(sigc::mem_fun(this, &UnityOptionsModel::onOptionAdded));
44 optionRemoved.connect(sigc::mem_fun(this, &UnityOptionsModel::onOptionRemoved));
47void UnityOptionsModel::onOptionAdded(unity::dash::FilterOption::Ptr option)
49 int index = m_options.count();
50 if (index >= 0)
51 {
52 beginInsertRows(QModelIndex(), index, index);
53 addOption(new FilterOption(option, this), index);
54 endInsertRows();
55 }
58void UnityOptionsModel::onOptionRemoved(unity::dash::FilterOption::Ptr option)
60 auto index = indexOf(QString::fromStdString(option->id));
61 if (index >= 0)
62 {
63 beginRemoveRows(QModelIndex(), index, index);
64 removeOption(index);
65 endRemoveRows();
66 }