on xenial help sign in
Implement fake filters
commit1164199e0eb313d1c496353d54de2536afcd6b49 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 4 Sep 2015, 12:33 (11 years ago) parent90c5f00
9 files changed+305−3
tests/mocks/Unity/CMakeLists.txt+7 tests/mocks/Unity/fake_filters.cpp+48 tests/mocks/Unity/fake_filters.h+39 tests/mocks/Unity/fake_optionselectorfilter.cpp+55 tests/mocks/Unity/fake_optionselectorfilter.h+43 tests/mocks/Unity/fake_optionselectoroptions.cpp+63 tests/mocks/Unity/fake_optionselectoroptions.h+42 tests/mocks/Unity/fake_scope.cpp+6−2 tests/mocks/Unity/fake_scope.h+2−1
tests/mocks/Unity/CMakeLists.txt+7
@@ -29,9 +29,16 @@ set(UnityQML_SOURCES
2929 fake_previewmodel.cpp
3030 fake_previewstack.cpp
3131 fake_previewwidgetmodel.cpp
32+ fake_filters.cpp
33+ fake_optionselectorfilter.cpp
34+ fake_optionselectoroptions.cpp
3235 fake_unity_plugin.cpp
3336 ${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
3439 ${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
3542 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewModelInterface.h
3643 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/PreviewStackInterface.h
3744 ${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 @@
11/*
2− * Copyright (C) 2013, 2014 Canonical, Ltd.
2+ * Copyright (C) 2013, 2014, 2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
1919
2020#include "fake_scope.h"
2121
22+#include "fake_filters.h"
2223#include "fake_navigation.h"
2324#include "fake_resultsmodel.h"
2425#include "fake_scopes.h"
@@ -42,6 +43,7 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
4243 , m_categories(new Categories(categories, this))
4344 , m_openScope(nullptr)
4445 , m_settings(new SettingsModel(this))
46+ , m_filters(new Filters(this))
4547 , m_returnNullPreview(returnNullPreview)
4648{
4749}
@@ -292,16 +294,18 @@ unity::shell::scopes::FilterBaseInterface* Scope::primaryNavigationFilter() cons
292294
293295unity::shell::scopes::FiltersInterface* Scope::filters() const
294296{
295− return nullptr;
297+ return m_filters;
296298}
297299
298300QString Scope::primaryNavigationTag() const
299301{
302+ // TODO
300303 return QString();
301304}
302305
303306int Scope::activeFiltersCount() const
304307{
308+ // TODO
305309 return 0;
306310}
307311
tests/mocks/Unity/fake_scope.h+2−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013, 2014 Canonical, Ltd.
2+ * Copyright (C) 2013, 2014, 2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -107,6 +107,7 @@ protected:
107107 unity::shell::scopes::CategoriesInterface* m_categories;
108108 unity::shell::scopes::ScopeInterface* m_openScope;
109109 unity::shell::scopes::SettingsModelInterface* m_settings;
110+ unity::shell::scopes::FiltersInterface* m_filters;
110111
111112 bool m_returnNullPreview;
112113};