2 * Copyright (C) 2013 Canonical, Ltd.
5 * Pawel Stolowski <pawel.stolowski@canonical.com>
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.
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.
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/>.
20#include "combinedfilteroptions.h"
22CombinedFilterOptions::CombinedFilterOptions(const std::vector<unity::dash::FilterOption::Ptr>& list,
23 sigc::signal<void, unity::dash::FilterOption::Ptr> itemAddedSignal,
24 sigc::signal<void, unity::dash::FilterOption::Ptr> itemRemovedSignal,
26 : QAbstractListModel(parent)
28 initList(list, itemAddedSignal, itemRemovedSignal);
32QVariant CombinedFilterOptions::data(const QModelIndex& index, int /* role */) const
34 if (!index.isValid()) {
38 CombinedFilterOption* item = m_list.at(index.row());
39 return QVariant::fromValue(item);
42int CombinedFilterOptions::rowCount(const QModelIndex& /* parent */) const
44 return m_list.count();
47void CombinedFilterOptions::initList(const std::vector<unity::dash::FilterOption::Ptr>& list,
48 sigc::signal<void, unity::dash::FilterOption::Ptr> itemAddedSignal,
49 sigc::signal<void, unity::dash::FilterOption::Ptr> itemRemovedSignal)
51 // combine options, e.g. A, B, C becomes A-B, B-C, C
53 while (i < list.size() - 1) {
54 unity::dash::FilterOption::Ptr option1 = list[i];
55 unity::dash::FilterOption::Ptr option2 = NULL;
56 //if (i < list.size()-1) {
59 auto co = new CombinedFilterOption(option1, option2);
60 connect(co, SIGNAL(activeChanged(bool)), this, SLOT(onActiveChanged(bool)));
64 if (list.size() > 0) {
65 auto co = new CombinedFilterOption(list[i], NULL);
69 itemAddedSignal.connect(sigc::mem_fun(this, &CombinedFilterOptions::onItemAdded));
70 itemRemovedSignal.connect(sigc::mem_fun(this, &CombinedFilterOptions::onItemRemoved));
73void CombinedFilterOptions::addOption(CombinedFilterOption *option)
75 int index = m_list.count();
76 beginInsertRows(QModelIndex(), index, index);
77 m_list.insert(index, option);
81void CombinedFilterOptions::onActiveChanged(bool state)
83 // if option became active, need to disable all other options
85 CombinedFilterOption *option = dynamic_cast<CombinedFilterOption*>(QObject::sender());
87 Q_FOREACH (auto fo, m_list) {
89 // note that changing state will result in onActiveChanged signal for that option, but
90 // since it will be 'false', we won't end up in an infinite loop
91 fo->setInactive(*option);
98void CombinedFilterOptions::onItemAdded(unity::dash::FilterOption::Ptr item)
102void CombinedFilterOptions::onItemRemoved(unity::dash::FilterOption::Ptr item)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list