on xenial help sign in
Some initial work for flattening multi-range filter.
1c851d6Pawel Stolowski
plugins/Unity/CMakeLists.txt+3
@@ -12,6 +12,9 @@ include_directories(
12)
12)
13
13
14set(QMLPLUGIN_SRC
14set(QMLPLUGIN_SRC
15+ abstractfilteroption.cpp
16+ combinedfilteroption.cpp
17+ combinedfilteroptions.cpp
15 ../Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
18 ../Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
16 scope.cpp
19 scope.cpp
17 scopes.cpp
20 scopes.cpp
plugins/Unity/combinedfilteroption.cppnew file+98
@@ -0,0 +1,98 @@
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 "combinedfilteroption.h"
21+
22+CombinedFilterOption::CombinedFilterOption(unity::dash::FilterOption::Ptr unityFilterOption1, unity::dash::FilterOption::Ptr unityFilterOption2, QObject *parent)
23+ : AbstractFilterOption(parent),
24+ m_active(false),
25+ m_unityFilterOption {NULL, NULL}
26+{
27+ setUnityFilterOption(unityFilterOption1, unityFilterOption2);
28+}
29+
30+std::string CombinedFilterOption::getCombinedId() const
31+{
32+ return m_unityFilterOption[0]->id() + "-" + m_unityFilterOption[1]->id();
33+}
34+
35+std::string CombinedFilterOption::getCombinedName() const
36+{
37+ if (m_unityFilterOption[1] != NULL)
38+ return m_unityFilterOption[0]->name() + " - " + m_unityFilterOption[1]->name(); //TODO i18n?
39+ return m_unityFilterOption[0]->name();
40+}
41+
42+QString CombinedFilterOption::id() const
43+{
44+ return QString::fromStdString(getCombinedId());
45+}
46+
47+QString CombinedFilterOption::name() const
48+{
49+ return QString::fromStdString(getCombinedName());
50+}
51+
52+QString CombinedFilterOption::iconHint() const
53+{
54+ return "";
55+}
56+
57+bool CombinedFilterOption::active() const
58+{
59+ return m_unityFilterOption[0]->active && m_unityFilterOption[1]->active;
60+}
61+
62+void CombinedFilterOption::setActive(bool active)
63+{
64+ m_active = active;
65+ m_unityFilterOption[0]->active;
66+ if (m_unityFilterOption[1] != NULL)
67+ m_unityFilterOption[1]->active = active;
68+}
69+
70+void CombinedFilterOption::onIdChanged(const std::string &/* id */)
71+{
72+ Q_EMIT idChanged(getCombinedId());
73+}
74+
75+void CombinedFilterOption::onActiveChanged(bool /*active*/)
76+{
77+ Q_EMIT activeChanged(CombinedFilterOption::active());
78+}
79+
80+void CombinedFilterOption::setUnityFilterOption(unity::dash::FilterOption::Ptr unityFilterOption1, unity::dash::FilterOption::Ptr unityFilterOption2)
81+{
82+ for (int i=0; i<2; i++) {
83+ if (m_unityFilterOption[0] != NULL) {
84+ // FIXME: should disconnect from m_unityFilterOption's signals
85+ }
86+ }
87+
88+ m_unityFilterOption[0] = unityFilterOption1;
89+ m_unityFilterOption[1] = unityFilterOption2;
90+
91+ /* Property change signals */
92+ for (int i=0; i<2; i++) {
93+ m_unityFilterOption[i]->id.changed.connect(sigc::mem_fun(this, &CombinedFilterOption::onIdChanged));
94+ m_unityFilterOption[i]->name.changed.connect(sigc::mem_fun(this, &CombinedFilterOption::nameChanged));
95+ m_unityFilterOption[i]->icon_hint.changed.connect(sigc::mem_fun(this, &CombinedFilterOption::iconHintChanged));
96+ m_unityFilterOption[i]->active.changed.connect(sigc::mem_fun(this, &CombinedFilterOption::activeChanged));
97+ }
98+}
plugins/Unity/combinedfilteroption.hnew file+56
@@ -0,0 +1,56 @@
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 COMBINEDFILTEROPTION_H
21+#define COMBINEDFILTEROPTION_H
22+
23+// Local
24+#include "abstractfilteroption.h"
25+
26+// libunity-core
27+#include <UnityCore/Filter.h>
28+
29+class CombinedFilterOption : public AbstractFilterOption
30+{
31+public:
32+ explicit CombinedFilterOption(unity::dash::FilterOption::Ptr unityFilterOption1, unity::dash::FilterOption::Ptr unityFilterOption2, QObject *parent = 0);
33+
34+ /* getters */
35+ QString id() const override;
36+ QString name() const override;
37+ QString iconHint() const override;
38+ bool active() const override;
39+
40+ /* setters */
41+ void setActive(bool active) override;
42+
43+private Q_SLOTS:
44+ void onIdChanged(const std::string &id);
45+ void onActiveChanged(bool active);
46+
47+private:
48+ std::string getCombinedId() const;
49+ std::string getCombinedName() const;
50+ void setUnityFilterOption(unity::dash::FilterOption::Ptr unityFilterOption1, unity::dash::FilterOption::Ptr unityFilterOption2 = NULL);
51+
52+ bool m_active;
53+ unity::dash::FilterOption::Ptr m_unityFilterOption[2];
54+};
55+
56+#endif /* COMBINEDFILTEROPTION_H */
plugins/Unity/combinedfilteroptions.cppnew file+74
@@ -0,0 +1,74 @@
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 "combinedfilteroptions.h"
21+
22+CombinedFilterOptions::CombinedFilterOptions(const std::vector<unity::dash::FilterOption::Ptr>& list,
23+ sigc::signal<void, unity::dash::FilterOption::Ptr> itemAddedSignal,
24+ sigc::signal<void, unity::dash::FilterOption::Ptr> itemRemovedSignal,
25+ QObject *parent)
26+ : QAbstractListModel(parent)
27+{
28+}
29+
30+
31+QVariant CombinedFilterOptions::data(const QModelIndex& index, int /* role */) const
32+{
33+ if (!index.isValid()) {
34+ return QVariant();
35+ }
36+
37+ CombinedFilterOption* item = m_list.at(index.row());
38+ return QVariant::fromValue(item);
39+}
40+
41+int CombinedFilterOptions::rowCount(const QModelIndex& /* parent */) const
42+{
43+ return m_list.count();
44+}
45+
46+void CombinedFilterOptions::initList(const std::vector<unity::dash::FilterOption::Ptr>& list,
47+ sigc::signal<void, unity::dash::FilterOption::Ptr> itemAddedSignal,
48+ sigc::signal<void, unity::dash::FilterOption::Ptr> itemRemovedSignal)
49+{
50+ unsigned int i = 0;
51+ while (i < list.size()) {
52+ unity::dash::FilterOption::Ptr option1 = list[i];
53+ unity::dash::FilterOption::Ptr option2 = NULL;
54+ if (i < list.size()-1) {
55+ option2 = list[i+1];
56+ }
57+ auto co = new CombinedFilterOption(option1, option2);
58+ ++i;
59+ }
60+ if (list.size() > 1) {
61+ auto co = new CombinedFilterOption(list[i], NULL);
62+ }
63+
64+ itemAddedSignal.connect(sigc::mem_fun(this, &CombinedFilterOptions::onItemAdded));
65+ itemRemovedSignal.connect(sigc::mem_fun(this, &CombinedFilterOptions::onItemRemoved));
66+}
67+
68+void CombinedFilterOptions::onItemAdded(unity::dash::FilterOption::Ptr item)
69+{
70+}
71+
72+void CombinedFilterOptions::onItemRemoved(unity::dash::FilterOption::Ptr item)
73+{
74+}
plugins/Unity/combinedfilteroptions.hnew file+56
@@ -0,0 +1,56 @@
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 COMBINEDOPTIONSWRAPPER_H
21+#define COMBINEDOPTIONSWRAPPER_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 CombinedFilterOptions : public QAbstractListModel
34+{
35+public:
36+ CombinedFilterOptions(const std::vector<unity::dash::FilterOption::Ptr>& list,
37+ sigc::signal<void, unity::dash::FilterOption::Ptr> itemAddedSignal,
38+ sigc::signal<void, unity::dash::FilterOption::Ptr> itemRemovedSignal,
39+ QObject *parent = 0);
40+
41+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
42+ int rowCount(const QModelIndex& parent = QModelIndex()) const override;
43+
44+private:
45+ void initList(const std::vector<unity::dash::FilterOption::Ptr>& list,
46+ sigc::signal<void, unity::dash::FilterOption::Ptr> itemAddedSignal,
47+ sigc::signal<void, unity::dash::FilterOption::Ptr> itemRemovedSignal);
48+ void onItemAdded(unity::dash::FilterOption::Ptr item);
49+ void onItemRemoved(unity::dash::FilterOption::Ptr item);
50+
51+ QList<CombinedFilterOption*> m_list;
52+};
53+
54+Q_DECLARE_METATYPE(CombinedFilterOptions*)
55+
56+#endif
plugins/Unity/filteroption.cpp+1−1
@@ -24,7 +24,7 @@
24#include <UnityCore/Filter.h>
24#include <UnityCore/Filter.h>
25
25
26FilterOption::FilterOption(unity::dash::FilterOption::Ptr unityFilterOption, QObject *parent) :
26FilterOption::FilterOption(unity::dash::FilterOption::Ptr unityFilterOption, QObject *parent) :
27− QObject(parent), m_unityFilterOption(NULL)
27+ AbstractFilterOption(parent), m_unityFilterOption(NULL)
28{
28{
29 setUnityFilterOption(unityFilterOption);
29 setUnityFilterOption(unityFilterOption);
30}
30}
plugins/Unity/filteroption.h+16−19
@@ -21,41 +21,38 @@
21#define FILTEROPTION_H
21#define FILTEROPTION_H
22
22
23// Local
23// Local
24+#include "abstractfilteroption.h"
24#include "listmodelwrapper.h"
25#include "listmodelwrapper.h"
25
26
26−// Qt
27−#include <QObject>
28−#include <QMetaType>
29−
30// libunity-core
27// libunity-core
31#include <UnityCore/Filter.h>
28#include <UnityCore/Filter.h>
32
29
33−class FilterOption : public QObject
30+class FilterOption : public AbstractFilterOption
34{
31{
35 Q_OBJECT
32 Q_OBJECT
36
33
37− Q_PROPERTY(QString id READ id NOTIFY idChanged)
34+// Q_PROPERTY(QString id READ id NOTIFY idChanged)
38− Q_PROPERTY(QString name READ name NOTIFY nameChanged)
35+// Q_PROPERTY(QString name READ name NOTIFY nameChanged)
39− Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
36+// Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
40− Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
37+// Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
41
38
42public:
39public:
43 explicit FilterOption(unity::dash::FilterOption::Ptr unityFilterOption, QObject *parent = 0);
40 explicit FilterOption(unity::dash::FilterOption::Ptr unityFilterOption, QObject *parent = 0);
44
41
45 /* getters */
42 /* getters */
46− QString id() const;
43+ QString id() const override;
47− QString name() const;
44+ QString name() const override;
48− QString iconHint() const;
45+ QString iconHint() const override;
49− bool active() const;
46+ bool active() const override;
50
47
51 /* setters */
48 /* setters */
52− void setActive(bool active);
49+ void setActive(bool active) override;
53
50
54−Q_SIGNALS:
51+//Q_SIGNALS:
55− void idChanged(std::string);
52+// void idChanged(std::string);
56− void nameChanged(std::string);
53+// void nameChanged(std::string);
57− void iconHintChanged(std::string);
54+// void iconHintChanged(std::string);
58− void activeChanged(bool);
55+// void activeChanged(bool);
59
56
60private:
57private:
61 void setUnityFilterOption(unity::dash::FilterOption::Ptr unityFilterOption);
58 void setUnityFilterOption(unity::dash::FilterOption::Ptr unityFilterOption);
plugins/Unity/listmodelwrapper.h+1−15
@@ -30,8 +30,6 @@
30template <class WrapperItem, class ItemClass>
30template <class WrapperItem, class ItemClass>
31class ListModelWrapper : public QAbstractListModel
31class ListModelWrapper : public QAbstractListModel
32{
32{
33−// Q_ENUMS(Roles)
34−
35public:
33public:
36 explicit ListModelWrapper(const std::vector<ItemClass>& list,
34 explicit ListModelWrapper(const std::vector<ItemClass>& list,
37 sigc::signal<void, ItemClass> itemAddedSignal,
35 sigc::signal<void, ItemClass> itemAddedSignal,
@@ -39,10 +37,6 @@ public:
39 QObject *parent = 0);
37 QObject *parent = 0);
40 ~ListModelWrapper();
38 ~ListModelWrapper();
41
39
42−// enum Roles {
43− // RoleItem
44−// };/
45−
46 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
40 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
47 int rowCount(const QModelIndex& parent = QModelIndex()) const;
41 int rowCount(const QModelIndex& parent = QModelIndex()) const;
48
42
@@ -68,10 +62,6 @@ ListModelWrapper<WrapperItem, ItemClass>::ListModelWrapper(const std::vector<Ite
68 QObject *parent) :
62 QObject *parent) :
69 QAbstractListModel(parent)
63 QAbstractListModel(parent)
70{
64{
71−// QHash<int, QByteArray> roles;
72−// roles[ListModelWrapper::RoleItem] = "item";
73−// setRoleNames(roles);
74−
75 for (unsigned int i=0; i<list.size(); i++) {
65 for (unsigned int i=0; i<list.size(); i++) {
76 addItem(list[i], i);
66 addItem(list[i], i);
77 }
67 }
@@ -111,11 +101,7 @@ QVariant ListModelWrapper<WrapperItem, ItemClass>::data(const QModelIndex& index
111
101
112 WrapperItem* item = m_list.at(index.row());
102 WrapperItem* item = m_list.at(index.row());
113
103
114−// if (role == ListModelWrapper::RoleItem) {
115− return QVariant::fromValue(item);
104+ return QVariant::fromValue(item);
116−// } else {
117−// return QVariant();
118−// }
119}
105}
120
106
121template <class WrapperItem, class ItemClass>
107template <class WrapperItem, class ItemClass>
plugins/Unity/multirangefilter.cpp+6−2
@@ -25,7 +25,7 @@ MultiRangeFilter::MultiRangeFilter(QObject *parent) :
25{
25{
26}
26}
27
27
28−FilterOptions* MultiRangeFilter::options() const
28+CombinedFilterOptions* MultiRangeFilter::options() const
29{
29{
30 return m_options;
30 return m_options;
31}
31}
@@ -45,7 +45,11 @@ void MultiRangeFilter::onOptionsChanged(unity::dash::MultiRangeFilter::Options o
45 delete m_options;
45 delete m_options;
46 m_options = NULL;
46 m_options = NULL;
47 }
47 }
48− m_options = new FilterOptions(m_unityMultiRangeFilter->options,
48+/* m_options = new FilterOptions(m_unityMultiRangeFilter->options,
49+ m_unityMultiRangeFilter->option_added,
50+ m_unityMultiRangeFilter->option_removed);*/
51+
52+ m_options = new CombinedFilterOptions(m_unityMultiRangeFilter->options,
49 m_unityMultiRangeFilter->option_added,
53 m_unityMultiRangeFilter->option_added,
50 m_unityMultiRangeFilter->option_removed);
54 m_unityMultiRangeFilter->option_removed);
51 /* Property change signals */
55 /* Property change signals */
plugins/Unity/multirangefilter.h+4−3
@@ -30,18 +30,19 @@
30// Local
30// Local
31#include "filter.h"
31#include "filter.h"
32#include "filteroption.h"
32#include "filteroption.h"
33+#include "combinedfilteroptions.h"
33
34
34class MultiRangeFilter : public Filter
35class MultiRangeFilter : public Filter
35{
36{
36 Q_OBJECT
37 Q_OBJECT
37
38
38− Q_PROPERTY(FilterOptions* options READ options NOTIFY optionsChanged)
39+ Q_PROPERTY(CombinedFilterOptions* options READ options NOTIFY optionsChanged)
39
40
40public:
41public:
41 explicit MultiRangeFilter(QObject *parent = 0);
42 explicit MultiRangeFilter(QObject *parent = 0);
42
43
43 /* getters */
44 /* getters */
44− FilterOptions* options() const;
45+ CombinedFilterOptions* options() const;
45
46
46Q_SIGNALS:
47Q_SIGNALS:
47 void optionsChanged();
48 void optionsChanged();
@@ -51,7 +52,7 @@ protected:
51
52
52private:
53private:
53 unity::dash::MultiRangeFilter::Ptr m_unityMultiRangeFilter;
54 unity::dash::MultiRangeFilter::Ptr m_unityMultiRangeFilter;
54− FilterOptions* m_options;
55+ CombinedFilterOptions* m_options;
55
56
56 void onOptionsChanged(unity::dash::MultiRangeFilter::Options);
57 void onOptionsChanged(unity::dash::MultiRangeFilter::Options);
57};
58};