on xenial help sign in
Implement fake filters
1164199Albert Astals Cid
tests/mocks/Unity/CMakeLists.txt+7
@@ -29,9 +29,16 @@ set(UnityQML_SOURCES
29 fake_previewmodel.cpp
29 fake_previewmodel.cpp
30 fake_previewstack.cpp
30 fake_previewstack.cpp
31 fake_previewwidgetmodel.cpp
31 fake_previewwidgetmodel.cpp
32+ fake_filters.cpp
33+ fake_optionselectorfilter.cpp
34+ fake_optionselectoroptions.cpp
32 fake_unity_plugin.cpp
35 fake_unity_plugin.cpp
33 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
36 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
37+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/FilterBaseInterface.h
38+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/FiltersInterface.h
34 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/NavigationInterface.h
39 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/NavigationInterface.h
40+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/OptionSelectorFilterInterface.h
41+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/OptionSelectorOptionsInterface.h
35 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h
42 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h
36 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h
43 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h
37 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewWidgetModelInterface.h
44 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewWidgetModelInterface.h
tests/mocks/Unity/fake_filters.cppnew file+48
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "fake_filters.h"
18+
19+#include "fake_optionselectorfilter.h"
20+#include "fake_scope.h"
21+
22+Filters::Filters(Scope* parent)
23+ : unity::shell::scopes::FiltersInterface(parent)
24+{
25+ auto optionFilter1 = new FakeOptionSelectorFilter("OSF1", "Tag1", "Which Cake you like More", false, QStringList() << "cheese" << "carrot" << "chocolate", this);
26+ auto optionFilter2 = new FakeOptionSelectorFilter("OSF2", "Tag2", "Which Countries have you been to?", true, QStringList() << "Germany" << "UK" << "New Zealand", this);
27+ m_filters << optionFilter1 << optionFilter2;
28+}
29+
30+int Filters::rowCount(const QModelIndex &parent) const
31+{
32+ if (parent.isValid())
33+ return 0;
34+
35+ return m_filters.count();
36+}
37+
38+QVariant Filters::data(const QModelIndex &index, int role) const
39+{
40+ const int row = index.row();
41+ if (row < 0 || row >= m_filters.count())
42+ return QVariant();
43+
44+ switch (role) {
45+ default:
46+ return QVariant();
47+ }
48+}
tests/mocks/Unity/fake_filters.hnew file+39
@@ -0,0 +1,39 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef FAKE_FILTERS_H
18+#define FAKE_FILTERS_H
19+
20+#include <unity/shell/scopes/FiltersInterface.h>
21+#include <unity/shell/scopes/FilterBaseInterface.h>
22+
23+class Scope;
24+
25+class Filters : public unity::shell::scopes::FiltersInterface
26+{
27+ Q_OBJECT
28+
29+public:
30+ Filters(Scope* parent);
31+
32+ int rowCount(const QModelIndex &parent) const override;
33+ QVariant data(const QModelIndex &index, int role) const override;
34+
35+private:
36+ QVector<unity::shell::scopes::FilterBaseInterface*> m_filters;
37+};
38+
39+#endif
tests/mocks/Unity/fake_optionselectorfilter.cppnew file+55
@@ -0,0 +1,55 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "fake_optionselectorfilter.h"
18+
19+#include "fake_optionselectoroptions.h"
20+
21+FakeOptionSelectorFilter::FakeOptionSelectorFilter(const QString &id, const QString &tag, const QString &label, bool multiselect, const QStringList &optionLabels, QObject* parent)
22+ : unity::shell::scopes::OptionSelectorFilterInterface(parent),
23+ m_filterId(id),
24+ m_filterTag(tag),
25+ m_label(label),
26+ m_multiSelect(multiselect)
27+{
28+ m_options = new FakeOptionSelectorOptions(optionLabels, this);
29+}
30+
31+QString FakeOptionSelectorFilter::filterId() const
32+{
33+ return m_filterId;
34+}
35+
36+QString FakeOptionSelectorFilter::filterTag() const
37+{
38+ return m_filterTag;
39+}
40+
41+QString FakeOptionSelectorFilter::label() const
42+{
43+ return m_label;
44+}
45+
46+bool FakeOptionSelectorFilter::multiSelect() const
47+{
48+ return m_multiSelect;
49+}
50+
51+unity::shell::scopes::OptionSelectorOptionsInterface* FakeOptionSelectorFilter::options() const
52+{
53+ return m_options;
54+}
55+
tests/mocks/Unity/fake_optionselectorfilter.hnew file+43
@@ -0,0 +1,43 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef FAKE_OPTIONSELECTORFILTER_H
18+#define FAKE_OPTIONSELECTORFILTER_H
19+
20+#include <unity/shell/scopes/OptionSelectorFilterInterface.h>
21+
22+class FakeOptionSelectorFilter : public unity::shell::scopes::OptionSelectorFilterInterface
23+{
24+ Q_OBJECT
25+
26+public:
27+ FakeOptionSelectorFilter(const QString &id, const QString &tag, const QString &label, bool multiselect, const QStringList &optionLabels, QObject* parent);
28+
29+ QString filterId() const override;
30+ QString filterTag() const override;
31+ QString label() const override;
32+ bool multiSelect() const override;
33+ unity::shell::scopes::OptionSelectorOptionsInterface* options() const override;
34+
35+private:
36+ QString m_filterId;
37+ QString m_filterTag;
38+ QString m_label;
39+ bool m_multiSelect;
40+ unity::shell::scopes::OptionSelectorOptionsInterface* m_options;
41+};
42+
43+#endif
tests/mocks/Unity/fake_optionselectoroptions.cppnew file+63
@@ -0,0 +1,63 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "fake_optionselectoroptions.h"
18+
19+#include "fake_optionselectorfilter.h"
20+
21+FakeOptionSelectorOptions::FakeOptionSelectorOptions(const QStringList &optionLabels, FakeOptionSelectorFilter* parent)
22+ : unity::shell::scopes::OptionSelectorOptionsInterface(parent),
23+ m_optionLabels(optionLabels)
24+{
25+}
26+
27+int FakeOptionSelectorOptions::rowCount(const QModelIndex &parent) const
28+{
29+ if (parent.isValid())
30+ return 0;
31+
32+ return m_optionLabels.count();
33+}
34+
35+QVariant FakeOptionSelectorOptions::data(const QModelIndex &index, int role) const
36+{
37+ const int row = index.row();
38+ if (row < 0 || row >= m_optionLabels.count())
39+ return QVariant();
40+
41+ switch (role) {
42+ case RoleOptionId:
43+ return static_cast<FakeOptionSelectorFilter*>(parent())->filterId() + QString::number(row);
44+ case RoleOptionLabel:
45+ return m_optionLabels[row];
46+ case RoleOptionChecked:
47+ return m_checkedIndexes.contains(row);
48+ default:
49+ return QVariant();
50+ }
51+
52+}
53+
54+void FakeOptionSelectorOptions::setChecked(int row, bool checked)
55+{
56+ if (checked) {
57+ m_checkedIndexes << row;
58+ } else {
59+ m_checkedIndexes.remove(row);
60+ }
61+ const QModelIndex idx = index(row, 0);
62+ Q_EMIT dataChanged(idx, idx, QVector<int>() << RoleOptionChecked);
63+}
tests/mocks/Unity/fake_optionselectoroptions.hnew file+42
@@ -0,0 +1,42 @@
1+/*
2+ * Copyright (C) 2015 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef FAKE_OPTIONSELECTOROPTIONS_H
18+#define FAKE_OPTIONSELECTOROPTIONS_H
19+
20+#include <unity/shell/scopes/OptionSelectorFilterInterface.h>
21+
22+#include <QSet>
23+
24+class FakeOptionSelectorFilter;
25+
26+class FakeOptionSelectorOptions : public unity::shell::scopes::OptionSelectorOptionsInterface
27+{
28+ Q_OBJECT
29+
30+public:
31+ FakeOptionSelectorOptions(const QStringList &optionLabels, FakeOptionSelectorFilter* parent);
32+
33+ int rowCount(const QModelIndex &parent) const override;
34+ QVariant data(const QModelIndex &index, int role) const override;
35+ Q_INVOKABLE void setChecked(int index, bool checked) override;
36+
37+private:
38+ QStringList m_optionLabels;
39+ QSet<int> m_checkedIndexes;
40+};
41+
42+#endif
tests/mocks/Unity/fake_scope.cpp+6−2
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013, 2014 Canonical, Ltd.
2+ * Copyright (C) 2013, 2014, 2015 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
19
19
20#include "fake_scope.h"
20#include "fake_scope.h"
21
21
22+#include "fake_filters.h"
22#include "fake_navigation.h"
23#include "fake_navigation.h"
23#include "fake_resultsmodel.h"
24#include "fake_resultsmodel.h"
24#include "fake_scopes.h"
25#include "fake_scopes.h"
@@ -42,6 +43,7 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
42 , m_categories(new Categories(categories, this))
43 , m_categories(new Categories(categories, this))
43 , m_openScope(nullptr)
44 , m_openScope(nullptr)
44 , m_settings(new SettingsModel(this))
45 , m_settings(new SettingsModel(this))
46+ , m_filters(new Filters(this))
45 , m_returnNullPreview(returnNullPreview)
47 , m_returnNullPreview(returnNullPreview)
46{
48{
47}
49}
@@ -292,16 +294,18 @@ unity::shell::scopes::FilterBaseInterface* Scope::primaryNavigationFilter() cons
292
294
293unity::shell::scopes::FiltersInterface* Scope::filters() const
295unity::shell::scopes::FiltersInterface* Scope::filters() const
294{
296{
295− return nullptr;
297+ return m_filters;
296}
298}
297
299
298QString Scope::primaryNavigationTag() const
300QString Scope::primaryNavigationTag() const
299{
301{
302+ // TODO
300 return QString();
303 return QString();
301}
304}
302
305
303int Scope::activeFiltersCount() const
306int Scope::activeFiltersCount() const
304{
307{
308+ // TODO
305 return 0;
309 return 0;
306}
310}
307
311
tests/mocks/Unity/fake_scope.h+2−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013, 2014 Canonical, Ltd.
2+ * Copyright (C) 2013, 2014, 2015 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -107,6 +107,7 @@ protected:
107 unity::shell::scopes::CategoriesInterface* m_categories;
107 unity::shell::scopes::CategoriesInterface* m_categories;
108 unity::shell::scopes::ScopeInterface* m_openScope;
108 unity::shell::scopes::ScopeInterface* m_openScope;
109 unity::shell::scopes::SettingsModelInterface* m_settings;
109 unity::shell::scopes::SettingsModelInterface* m_settings;
110+ unity::shell::scopes::FiltersInterface* m_filters;
110
111
111 bool m_returnNullPreview;
112 bool m_returnNullPreview;
112};
113};