on 174fe91 help sign in
unity8/plugins/Unity/combinedfilteroptions.cpp
65 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#include "combinedfilteroptions.h"
21#include "combinedfilteroption.h"
23CombinedFilterOptions::CombinedFilterOptions(const std::vector<unity::dash::FilterOption::Ptr>& list, QObject *parent)
24 : GenericListModel(parent)
26 initList(list);
29void CombinedFilterOptions::initList(const std::vector<unity::dash::FilterOption::Ptr>& list)
31 // combine options, e.g. A, B, C becomes A-B, B-C, C
32 unsigned int i = 0;
33 while (i < list.size() - 1) {
34 unity::dash::FilterOption::Ptr option1 = list[i];
35 unity::dash::FilterOption::Ptr option2 = list[i+1];
36 auto co = new CombinedFilterOption(option1, option2, this);
37 connect(co, SIGNAL(activeChanged(bool)), this, SLOT(onActiveChanged(bool)));
38 addObject(co);
39 ++i;
40 }
41 if (list.size() > 0) {
42 auto co = new CombinedFilterOption(list[i], nullptr, this);
43 addObject(co);
44 }
47void CombinedFilterOptions::onActiveChanged(bool state)
49 // if option became active, need to disable all other options
50 if (state) {
51 CombinedFilterOption *option = dynamic_cast<CombinedFilterOption*>(QObject::sender());
52 if (option) {
53 Q_FOREACH (auto fo, m_list) {
54 if (option != fo) {
55 CombinedFilterOption *other = dynamic_cast<CombinedFilterOption*>(fo);
56 if (fo) {
57 // note that changing state will result in onActiveChanged signal for that option, but
58 // since it will be 'false', we won't end up in an infinite loop
59 other->setInactive(*option);
60 }
61 }
62 }
63 }
64 }