on xenial help sign in
Flatten and export RatingsFilter options.
1448d73Pawel Stolowski
plugins/Unity/CMakeLists.txt+2
@@ -26,11 +26,13 @@ set(QMLPLUGIN_SRC
26 filter.cpp
26 filter.cpp
27 filteroption.cpp
27 filteroption.cpp
28 filter.cpp
28 filter.cpp
29+ genericlistmodel.cpp
29 categoryresults.cpp
30 categoryresults.cpp
30 plugin.cpp
31 plugin.cpp
31 multirangefilter.cpp
32 multirangefilter.cpp
32 radiooptionfilter.cpp
33 radiooptionfilter.cpp
33 ratingsfilter.cpp
34 ratingsfilter.cpp
35+ ratingfilteroption.cpp
34 bottombarvisibilitycommunicatorshell.cpp
36 bottombarvisibilitycommunicatorshell.cpp
35 launchermodel.cpp
37 launchermodel.cpp
36 applicationpreview.cpp
38 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 @@
20// Self
20// Self
21#include "ratingsfilter.h"
21#include "ratingsfilter.h"
22
22
23+// local
24+#include "genericlistmodel.h"
25+
23RatingsFilter::RatingsFilter(QObject *parent) :
26RatingsFilter::RatingsFilter(QObject *parent) :
24− Filter(parent), m_unityRatingsFilter(NULL)
27+ Filter(parent), m_unityRatingsFilter(NULL), m_options(nullptr)
25{
28{
26}
29}
27
30
@@ -30,6 +33,11 @@ float RatingsFilter::rating() const
30 return m_unityRatingsFilter->rating();
33 return m_unityRatingsFilter->rating();
31}
34}
32
35
36+GenericListModel* RatingsFilter::options() const
37+{
38+ return m_options;
39+}
40+
33void RatingsFilter::setRating(float rating)
41void RatingsFilter::setRating(float rating)
34{
42{
35 m_unityRatingsFilter->rating = rating;
43 m_unityRatingsFilter->rating = rating;
@@ -44,8 +52,27 @@ void RatingsFilter::setUnityFilter(unity::dash::Filter::Ptr filter)
44 Filter::setUnityFilter(filter);
52 Filter::setUnityFilter(filter);
45 m_unityRatingsFilter = std::dynamic_pointer_cast<unity::dash::RatingsFilter>(m_unityFilter);
53 m_unityRatingsFilter = std::dynamic_pointer_cast<unity::dash::RatingsFilter>(m_unityFilter);
46
54
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+
47 /* Property change signals */
66 /* Property change signals */
48 m_signals << m_unityRatingsFilter->rating.changed.connect(sigc::mem_fun(this, &RatingsFilter::ratingChanged));
67 m_signals << m_unityRatingsFilter->rating.changed.connect(sigc::mem_fun(this, &RatingsFilter::ratingChanged));
49}
68}
50
69
70+void RatingsFilter::onActiveChanged()
71+{
72+ RatingFilterOption *option = dynamic_cast<RatingFilterOption*>(QObject::sender());
73+ if (option != nullptr) {
74+ setRating(option->value());
75+ }
76+}
77+
51#include "ratingsfilter.moc"
78#include "ratingsfilter.moc"
plugins/Unity/ratingsfilter.h+11
@@ -30,6 +30,10 @@
30// Local
30// Local
31#include "filter.h"
31#include "filter.h"
32#include "signalslist.h"
32#include "signalslist.h"
33+#include "ratingfilteroption.h"
34+#include "ratingfilteroption.h"
35+
36+class GenericListModel;
33
37
34class Q_DECL_EXPORT RatingsFilter : public Filter
38class Q_DECL_EXPORT RatingsFilter : public Filter
35{
39{
@@ -43,6 +47,9 @@ public:
43 /* getters */
47 /* getters */
44 float rating() const;
48 float rating() const;
45
49
50+ /* getters */
51+ GenericListModel* options() const;
52+
46 /* setters */
53 /* setters */
47 void setRating(float rating);
54 void setRating(float rating);
48
55
@@ -52,8 +59,12 @@ Q_SIGNALS:
52protected:
59protected:
53 virtual void setUnityFilter(unity::dash::Filter::Ptr filter);
60 virtual void setUnityFilter(unity::dash::Filter::Ptr filter);
54
61
62+protected Q_SLOTS:
63+ void onActiveChanged();
64+
55private:
65private:
56 unity::dash::RatingsFilter::Ptr m_unityRatingsFilter;
66 unity::dash::RatingsFilter::Ptr m_unityRatingsFilter;
67+ GenericListModel *m_options;
57 SignalsList m_signals;
68 SignalsList m_signals;
58};
69};
59
70