on xenial help sign in
Flatten and export RatingsFilter options.
commit1448d73c18ddec357fd5987076ce8e201a8026d1 authorPawel Stolowski <pawel.stolowski@canonical.com> dateWed 10 Jul 2013, 16:58 (13 years ago) parentef246e1
7 files changed+241−1
plugins/Unity/CMakeLists.txt+2 plugins/Unity/genericlistmodel.cpp+48 plugins/Unity/genericlistmodel.h+50 plugins/Unity/ratingfilteroption.cpp+51 plugins/Unity/ratingfilteroption.h+51 plugins/Unity/ratingsfilter.cpp+28−1 plugins/Unity/ratingsfilter.h+11
plugins/Unity/CMakeLists.txt+2
@@ -26,11 +26,13 @@ set(QMLPLUGIN_SRC
2626 filter.cpp
2727 filteroption.cpp
2828 filter.cpp
29+ genericlistmodel.cpp
2930 categoryresults.cpp
3031 plugin.cpp
3132 multirangefilter.cpp
3233 radiooptionfilter.cpp
3334 ratingsfilter.cpp
35+ ratingfilteroption.cpp
3436 bottombarvisibilitycommunicatorshell.cpp
3537 launchermodel.cpp
3638 applicationpreview.cpp
plugins/Unity/genericlistmodel.cppnew file+48
@@ -0,0 +1,48 @@
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+ */
19+
20+#include "genericlistmodel.h"
21+
22+GenericListModel::GenericListModel(QObject *parent)
23+ : QAbstractListModel(parent)
24+{
25+}
26+
27+QVariant GenericListModel::data(const QModelIndex& index, int /* role */) const
28+{
29+ if (!index.isValid()) {
30+ return QVariant();
31+ }
32+
33+ QObject* item = m_list.at(index.row());
34+ return QVariant::fromValue(item);
35+}
36+
37+int GenericListModel::rowCount(const QModelIndex& /* parent */) const
38+{
39+ return m_list.count();
40+}
41+
42+void GenericListModel::addOption(QObject *option)
43+{
44+ int index = m_list.count();
45+ beginInsertRows(QModelIndex(), index, index);
46+ m_list.insert(index, option);
47+ endInsertRows();
48+}
plugins/Unity/genericlistmodel.hnew file+50
@@ -0,0 +1,50 @@
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+ */
19+
20+#ifndef GENERICLISTMODEL_H
21+#define GENERICLISTMODEL_H
22+
23+// Qt
24+#include <QObject>
25+#include <QAbstractListModel>
26+
27+// libunity-core
28+#include <UnityCore/Filter.h>
29+
30+// local
31+#include "combinedfilteroption.h"
32+
33+class GenericListModel : public QAbstractListModel
34+{
35+ Q_OBJECT
36+
37+public:
38+ GenericListModel(QObject *parent = 0);
39+
40+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
41+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
42+
43+ void addOption(QObject* option);
44+
45+ QList<QObject *> m_list;
46+};
47+
48+Q_DECLARE_METATYPE(GenericListModel*)
49+
50+#endif
plugins/Unity/ratingfilteroption.cppnew file+51
@@ -0,0 +1,51 @@
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+ */
19+
20+#include "ratingfilteroption.h"
21+
22+RatingFilterOption::RatingFilterOption(const QString &id, float value, QObject *parent) :
23+ QObject(parent),
24+ m_active(false),
25+ m_id(id),
26+ m_value(value)
27+{
28+}
29+
30+QString RatingFilterOption::id() const
31+{
32+ return m_id;
33+}
34+
35+float RatingFilterOption::value() const
36+{
37+ return m_value;
38+}
39+
40+bool RatingFilterOption::active() const
41+{
42+ return m_active;
43+}
44+
45+void RatingFilterOption::setActive(bool active)
46+{
47+ if (active != m_active) {
48+ m_active = active;
49+ Q_EMIT activeChanged(m_active);
50+ }
51+}
plugins/Unity/ratingfilteroption.hnew file+51
@@ -0,0 +1,51 @@
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+ */
19+
20+#ifndef RATINGFILTEROPTION_H
21+#define RATINGFILTEROPTION_H
22+
23+#include <QObject>
24+
25+class Q_DECL_EXPORT RatingFilterOption : public QObject
26+{
27+ Q_OBJECT
28+
29+public:
30+ explicit RatingFilterOption(const QString &id, float ratingValue, QObject *parent = 0);
31+
32+ /* getters */
33+ QString id() const;
34+ bool active() const;
35+ float value() const;
36+
37+ /* setters */
38+ Q_INVOKABLE void setActive(bool active);
39+
40+Q_SIGNALS:
41+ void activeChanged(bool);
42+
43+private:
44+ bool m_active;
45+ float m_value;
46+ QString m_id;
47+};
48+
49+Q_DECLARE_METATYPE(RatingFilterOption*)
50+
51+#endif /* COMBINEDFILTEROPTION_H */
plugins/Unity/ratingsfilter.cpp+28−1
@@ -20,8 +20,11 @@
2020// Self
2121#include "ratingsfilter.h"
2222
23+// local
24+#include "genericlistmodel.h"
25+
2326RatingsFilter::RatingsFilter(QObject *parent) :
24− Filter(parent), m_unityRatingsFilter(NULL)
27+ Filter(parent), m_unityRatingsFilter(NULL), m_options(nullptr)
2528{
2629}
2730
@@ -30,6 +33,11 @@ float RatingsFilter::rating() const
3033 return m_unityRatingsFilter->rating();
3134}
3235
36+GenericListModel* RatingsFilter::options() const
37+{
38+ return m_options;
39+}
40+
3341void RatingsFilter::setRating(float rating)
3442{
3543 m_unityRatingsFilter->rating = rating;
@@ -44,8 +52,27 @@ void RatingsFilter::setUnityFilter(unity::dash::Filter::Ptr filter)
4452 Filter::setUnityFilter(filter);
4553 m_unityRatingsFilter = std::dynamic_pointer_cast<unity::dash::RatingsFilter>(m_unityFilter);
4654
55+ if (m_options) {
56+ delete m_options;
57+ }
58+
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+ }
65+
4766 /* Property change signals */
4867 m_signals << m_unityRatingsFilter->rating.changed.connect(sigc::mem_fun(this, &RatingsFilter::ratingChanged));
4968}
5069
70+void RatingsFilter::onActiveChanged()
71+{
72+ RatingFilterOption *option = dynamic_cast<RatingFilterOption*>(QObject::sender());
73+ if (option != nullptr) {
74+ setRating(option->value());
75+ }
76+}
77+
5178#include "ratingsfilter.moc"
plugins/Unity/ratingsfilter.h+11
@@ -30,6 +30,10 @@
3030// Local
3131#include "filter.h"
3232#include "signalslist.h"
33+#include "ratingfilteroption.h"
34+#include "ratingfilteroption.h"
35+
36+class GenericListModel;
3337
3438class Q_DECL_EXPORT RatingsFilter : public Filter
3539{
@@ -43,6 +47,9 @@ public:
4347 /* getters */
4448 float rating() const;
4549
50+ /* getters */
51+ GenericListModel* options() const;
52+
4653 /* setters */
4754 void setRating(float rating);
4855
@@ -52,8 +59,12 @@ Q_SIGNALS:
5259protected:
5360 virtual void setUnityFilter(unity::dash::Filter::Ptr filter);
5461
62+protected Q_SLOTS:
63+ void onActiveChanged();
64+
5565private:
5666 unity::dash::RatingsFilter::Ptr m_unityRatingsFilter;
67+ GenericListModel *m_options;
5768 SignalsList m_signals;
5869};
5970