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

« back to all changes in this revision

Viewing changes to src/ratingsfilter.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) 2011, 2013 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *  Florian Boucault <florian.boucault@canonical.com>
 
6
 *  Pawel Stolowski <pawel.stolowski@canonical.com>
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; version 3.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
// Self
 
22
#include "ratingsfilter.h"
 
23
 
 
24
// local
 
25
#include "ratingfilteroption.h"
 
26
#include "ratingoptionsmodel.h"
 
27
 
 
28
RatingsFilter::RatingsFilter(QObject *parent) :
 
29
    Filter(parent),
 
30
    m_unityRatingsFilter(nullptr),
 
31
    m_options(nullptr)
 
32
{
 
33
}
 
34
 
 
35
GenericOptionsModel* RatingsFilter::options() const
 
36
{
 
37
    return m_options;
 
38
}
 
39
 
 
40
float RatingsFilter::rating() const
 
41
{
 
42
    if (m_unityRatingsFilter)
 
43
    {
 
44
        return m_unityRatingsFilter->rating;
 
45
    }
 
46
    return 0.0f;
 
47
}
 
48
 
 
49
void RatingsFilter::setUnityFilter(unity::dash::Filter::Ptr filter)
 
50
{
 
51
    Filter::setUnityFilter(filter);
 
52
    m_unityRatingsFilter = std::dynamic_pointer_cast<unity::dash::RatingsFilter>(m_unityFilter);
 
53
 
 
54
    delete m_options;
 
55
 
 
56
    m_options = new RatingOptionsModel(m_unityRatingsFilter->show_all_button, this);
 
57
    connect(m_options, SIGNAL(activeChanged(AbstractFilterOption *)), m_options, SLOT(ensureTheOnlyActive(AbstractFilterOption *)));
 
58
    connect(m_options, SIGNAL(activeChanged(AbstractFilterOption *)), this, SLOT(onActiveChanged(AbstractFilterOption *)));
 
59
    connect(m_options, SIGNAL(showAllActivated()), this, SLOT(clear()));
 
60
 
 
61
    Q_EMIT optionsChanged();
 
62
}
 
63
 
 
64
void RatingsFilter::onActiveChanged(AbstractFilterOption *option)
 
65
{
 
66
    RatingFilterOption *ratingOption = dynamic_cast<RatingFilterOption*>(option);
 
67
    if (ratingOption != nullptr)
 
68
    {
 
69
        const float val = ratingOption->active() ? ratingOption->value() : 0.0f;
 
70
        m_unityRatingsFilter->rating = val;
 
71
        Q_EMIT ratingChanged(val);
 
72
    }
 
73
}