on 1448d73 help sign in
unity8/plugins/Unity/ratingsfilter.cpp
78 lines 2.1 kB history raw
1/*
2 * Copyright (C) 2011 Canonical, Ltd.
3 *
4 * Authors:
5 * Florian Boucault <florian.boucault@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 "ratingsfilter.h"
23// local
24#include "genericlistmodel.h"
26RatingsFilter::RatingsFilter(QObject *parent) :
27 Filter(parent), m_unityRatingsFilter(NULL), m_options(nullptr)
31float RatingsFilter::rating() const
33 return m_unityRatingsFilter->rating();
36GenericListModel* RatingsFilter::options() const
38 return m_options;
41void RatingsFilter::setRating(float rating)
43 m_unityRatingsFilter->rating = rating;
46void RatingsFilter::setUnityFilter(unity::dash::Filter::Ptr filter)
48 if (m_unityFilter != NULL) {
49 m_signals.disconnectAll();
50 }
52 Filter::setUnityFilter(filter);
53 m_unityRatingsFilter = std::dynamic_pointer_cast<unity::dash::RatingsFilter>(m_unityFilter);
55 if (m_options) {
56 delete m_options;
57 }
59 m_options = new GenericListModel(this);
60 for (int i=1; i<=5; i++) {
61 auto opt = new RatingFilterOption(QString::number(i), i*0.2f, this);
62 connect(opt, SIGNAL(activeChanged(bool)), this, SLOT(onActiveChanged()));
63 m_options->addOption(opt);
64 }
66 /* Property change signals */
67 m_signals << m_unityRatingsFilter->rating.changed.connect(sigc::mem_fun(this, &RatingsFilter::ratingChanged));
70void RatingsFilter::onActiveChanged()
72 RatingFilterOption *option = dynamic_cast<RatingFilterOption*>(QObject::sender());
73 if (option != nullptr) {
74 setRating(option->value());
75 }
78#include "ratingsfilter.moc"