on xenial help sign in
Some initial work for flattening multi-range filter.
commit1c851d680a2450255a305dad20650dcb80579729 authorPawel Stolowski <pawel.stolowski@canonical.com> dateWed 19 Jun 2013, 17:53 (13 years ago) parentffba04d
10 files changed+315−40
plugins/Unity/CMakeLists.txt+3 plugins/Unity/combinedfilteroption.cpp+98 plugins/Unity/combinedfilteroption.h+56 plugins/Unity/combinedfilteroptions.cpp+74 plugins/Unity/combinedfilteroptions.h+56 plugins/Unity/filteroption.cpp+1−1 plugins/Unity/filteroption.h+16−19 plugins/Unity/listmodelwrapper.h+1−15 plugins/Unity/multirangefilter.cpp+6−2 plugins/Unity/multirangefilter.h+4−3
plugins/Unity/CMakeLists.txt+3
@@ -12,6 +12,9 @@ include_directories(
1212)
1313
1414set(QMLPLUGIN_SRC
15+ abstractfilteroption.cpp
16+ combinedfilteroption.cpp
17+ combinedfilteroptions.cpp
1518 ../Utils/qsortfilterproxymodelqml.cpp # FIXME evaluate a more generic approach for using other plugins
1619 scope.cpp
1720 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 @@
2424#include <UnityCore/Filter.h>
2525
2626FilterOption::FilterOption(unity::dash::FilterOption::Ptr unityFilterOption, QObject *parent) :
27− QObject(parent), m_unityFilterOption(NULL)
27+ AbstractFilterOption(parent), m_unityFilterOption(NULL)
2828{
2929 setUnityFilterOption(unityFilterOption);
3030}
plugins/Unity/filteroption.h+16−19
@@ -21,41 +21,38 @@
2121#define FILTEROPTION_H
2222
2323// Local
24+#include "abstractfilteroption.h"
2425#include "listmodelwrapper.h"
2526
26−// Qt
27−#include <QObject>
28−#include <QMetaType>
29−
3027// libunity-core
3128#include <UnityCore/Filter.h>
3229
33−class FilterOption : public QObject
30+class FilterOption : public AbstractFilterOption
3431{
3532 Q_OBJECT
3633
37− Q_PROPERTY(QString id READ id NOTIFY idChanged)
38− Q_PROPERTY(QString name READ name NOTIFY nameChanged)
39− Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
40− Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
34+// Q_PROPERTY(QString id READ id NOTIFY idChanged)
35+// Q_PROPERTY(QString name READ name NOTIFY nameChanged)
36+// Q_PROPERTY(QString iconHint READ iconHint NOTIFY iconHintChanged)
37+// Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
4138
4239public:
4340 explicit FilterOption(unity::dash::FilterOption::Ptr unityFilterOption, QObject *parent = 0);
4441
4542 /* getters */
46− QString id() const;
47− QString name() const;
48− QString iconHint() const;
49− bool active() const;
43+ QString id() const override;
44+ QString name() const override;
45+ QString iconHint() const override;
46+ bool active() const override;
5047
5148 /* setters */
52− void setActive(bool active);
49+ void setActive(bool active) override;
5350
54−Q_SIGNALS:
55− void idChanged(std::string);
56− void nameChanged(std::string);
57− void iconHintChanged(std::string);
58− void activeChanged(bool);
51+//Q_SIGNALS:
52+// void idChanged(std::string);
53+// void nameChanged(std::string);
54+// void iconHintChanged(std::string);
55+// void activeChanged(bool);
5956
6057private:
6158 void setUnityFilterOption(unity::dash::FilterOption::Ptr unityFilterOption);
plugins/Unity/listmodelwrapper.h+1−15
@@ -30,8 +30,6 @@
3030template <class WrapperItem, class ItemClass>
3131class ListModelWrapper : public QAbstractListModel
3232{
33−// Q_ENUMS(Roles)
34−
3533public:
3634 explicit ListModelWrapper(const std::vector<ItemClass>& list,
3735 sigc::signal<void, ItemClass> itemAddedSignal,
@@ -39,10 +37,6 @@ public:
3937 QObject *parent = 0);
4038 ~ListModelWrapper();
4139
42−// enum Roles {
43− // RoleItem
44−// };/
45−
4640 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
4741 int rowCount(const QModelIndex& parent = QModelIndex()) const;
4842
@@ -68,10 +62,6 @@ ListModelWrapper<WrapperItem, ItemClass>::ListModelWrapper(const std::vector<Ite
6862 QObject *parent) :
6963 QAbstractListModel(parent)
7064{
71−// QHash<int, QByteArray> roles;
72−// roles[ListModelWrapper::RoleItem] = "item";
73−// setRoleNames(roles);
74−
7565 for (unsigned int i=0; i<list.size(); i++) {
7666 addItem(list[i], i);
7767 }
@@ -111,11 +101,7 @@ QVariant ListModelWrapper<WrapperItem, ItemClass>::data(const QModelIndex& index
111101
112102 WrapperItem* item = m_list.at(index.row());
113103
114−// if (role == ListModelWrapper::RoleItem) {
115− return QVariant::fromValue(item);
116−// } else {
117−// return QVariant();
118−// }
104+ return QVariant::fromValue(item);
119105}
120106
121107template <class WrapperItem, class ItemClass>
plugins/Unity/multirangefilter.cpp+6−2
@@ -25,7 +25,7 @@ MultiRangeFilter::MultiRangeFilter(QObject *parent) :
2525{
2626}
2727
28−FilterOptions* MultiRangeFilter::options() const
28+CombinedFilterOptions* MultiRangeFilter::options() const
2929{
3030 return m_options;
3131}
@@ -45,7 +45,11 @@ void MultiRangeFilter::onOptionsChanged(unity::dash::MultiRangeFilter::Options o
4545 delete m_options;
4646 m_options = NULL;
4747 }
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,
4953 m_unityMultiRangeFilter->option_added,
5054 m_unityMultiRangeFilter->option_removed);
5155 /* Property change signals */
plugins/Unity/multirangefilter.h+4−3
@@ -30,18 +30,19 @@
3030// Local
3131#include "filter.h"
3232#include "filteroption.h"
33+#include "combinedfilteroptions.h"
3334
3435class MultiRangeFilter : public Filter
3536{
3637 Q_OBJECT
3738
38− Q_PROPERTY(FilterOptions* options READ options NOTIFY optionsChanged)
39+ Q_PROPERTY(CombinedFilterOptions* options READ options NOTIFY optionsChanged)
3940
4041public:
4142 explicit MultiRangeFilter(QObject *parent = 0);
4243
4344 /* getters */
44− FilterOptions* options() const;
45+ CombinedFilterOptions* options() const;
4546
4647Q_SIGNALS:
4748 void optionsChanged();
@@ -51,7 +52,7 @@ protected:
5152
5253private:
5354 unity::dash::MultiRangeFilter::Ptr m_unityMultiRangeFilter;
54− FilterOptions* m_options;
55+ CombinedFilterOptions* m_options;
5556
5657 void onOptionsChanged(unity::dash::MultiRangeFilter::Options);
5758};