on xenial help sign in
Implement Scope::activeFiltersCount in the mock plugin
036c0ffAlbert Astals Cid
tests/mocks/Unity/fake_filters.cpp+17−3
@@ -22,9 +22,14 @@
22Filters::Filters(Scope* parent)
22Filters::Filters(Scope* parent)
23 : unity::shell::scopes::FiltersInterface(parent)
23 : unity::shell::scopes::FiltersInterface(parent)
24{
24{
25− auto optionFilter1 = new FakeOptionSelectorFilter("OSF1", "Tag1", "Which Cake you like More", false, QStringList() << "cheese" << "carrot" << "chocolate", this);
25+ addFilter(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);
26+ addFilter(new FakeOptionSelectorFilter("OSF2", "Tag2", "Which Countries have you been to?", true, QStringList() << "Germany" << "UK" << "New Zealand", this));
27+}
28+
29+void Filters::addFilter(FakeOptionSelectorFilter *f)
30+{
31+ connect(f, &FakeOptionSelectorFilter::isActiveChanged, this, &Filters::activeFiltersCountChanged);
27− m_filters << optionFilter1 << optionFilter2;
32+ m_filters << f;
28}
33}
29
34
30int Filters::rowCount(const QModelIndex &parent) const
35int Filters::rowCount(const QModelIndex &parent) const
@@ -54,3 +59,12 @@ QVariant Filters::data(const QModelIndex &index, int role) const
54 return QVariant();
59 return QVariant();
55 }
60 }
56}
61}
62+
63+int Filters::activeFiltersCount() const
64+{
65+ int active = 0;
66+ Q_FOREACH(FakeOptionSelectorFilter *f, m_filters) {
67+ if (f->isActive()) ++active;
68+ }
69+ return active;
70+}
tests/mocks/Unity/fake_filters.h+9−2
@@ -18,9 +18,9 @@
18#define FAKE_FILTERS_H
18#define FAKE_FILTERS_H
19
19
20#include <unity/shell/scopes/FiltersInterface.h>
20#include <unity/shell/scopes/FiltersInterface.h>
21−#include <unity/shell/scopes/FilterBaseInterface.h>
22
21
23class Scope;
22class Scope;
23+class FakeOptionSelectorFilter;
24
24
25class Filters : public unity::shell::scopes::FiltersInterface
25class Filters : public unity::shell::scopes::FiltersInterface
26{
26{
@@ -32,8 +32,15 @@ public:
32 int rowCount(const QModelIndex &parent) const override;
32 int rowCount(const QModelIndex &parent) const override;
33 QVariant data(const QModelIndex &index, int role) const override;
33 QVariant data(const QModelIndex &index, int role) const override;
34
34
35+ int activeFiltersCount() const;
36+
37+Q_SIGNALS:
38+ void activeFiltersCountChanged();
39+
35private:
40private:
36− QVector<unity::shell::scopes::FilterBaseInterface*> m_filters;
41+ void addFilter(FakeOptionSelectorFilter* f);
42+
43+ QVector<FakeOptionSelectorFilter*> m_filters;
37};
44};
38
45
39#endif
46#endif
tests/mocks/Unity/fake_optionselectorfilter.cpp+5
@@ -26,6 +26,7 @@ FakeOptionSelectorFilter::FakeOptionSelectorFilter(const QString &id, const QStr
26 m_multiSelect(multiselect)
26 m_multiSelect(multiselect)
27{
27{
28 m_options = new FakeOptionSelectorOptions(optionLabels, this);
28 m_options = new FakeOptionSelectorOptions(optionLabels, this);
29+ connect(m_options, &FakeOptionSelectorOptions::anyCheckedChanged, this, &FakeOptionSelectorFilter::isActiveChanged);
29}
30}
30
31
31QString FakeOptionSelectorFilter::filterId() const
32QString FakeOptionSelectorFilter::filterId() const
@@ -53,3 +54,7 @@ unity::shell::scopes::OptionSelectorOptionsInterface* FakeOptionSelectorFilter::
53 return m_options;
54 return m_options;
54}
55}
55
56
57+bool FakeOptionSelectorFilter::isActive() const
58+{
59+ return m_options->anyChecked();
60+}
tests/mocks/Unity/fake_optionselectorfilter.h+8−1
@@ -19,6 +19,8 @@
19
19
20#include <unity/shell/scopes/OptionSelectorFilterInterface.h>
20#include <unity/shell/scopes/OptionSelectorFilterInterface.h>
21
21
22+class FakeOptionSelectorOptions;
23+
22class FakeOptionSelectorFilter : public unity::shell::scopes::OptionSelectorFilterInterface
24class FakeOptionSelectorFilter : public unity::shell::scopes::OptionSelectorFilterInterface
23{
25{
24 Q_OBJECT
26 Q_OBJECT
@@ -32,12 +34,17 @@ public:
32 bool multiSelect() const override;
34 bool multiSelect() const override;
33 unity::shell::scopes::OptionSelectorOptionsInterface* options() const override;
35 unity::shell::scopes::OptionSelectorOptionsInterface* options() const override;
34
36
37+ bool isActive() const;
38+
39+Q_SIGNALS:
40+ void isActiveChanged();
41+
35private:
42private:
36 QString m_filterId;
43 QString m_filterId;
37 QString m_filterTag;
44 QString m_filterTag;
38 QString m_label;
45 QString m_label;
39 bool m_multiSelect;
46 bool m_multiSelect;
40− unity::shell::scopes::OptionSelectorOptionsInterface* m_options;
47+ FakeOptionSelectorOptions* m_options;
41};
48};
42
49
43#endif
50#endif
tests/mocks/Unity/fake_optionselectoroptions.cpp+9
@@ -53,6 +53,7 @@ QVariant FakeOptionSelectorOptions::data(const QModelIndex &index, int role) con
53
53
54void FakeOptionSelectorOptions::setChecked(int row, bool checked)
54void FakeOptionSelectorOptions::setChecked(int row, bool checked)
55{
55{
56+ const bool wasChecked = anyChecked();
56 if (checked) {
57 if (checked) {
57 if (!static_cast<FakeOptionSelectorFilter*>(parent())->multiSelect()) {
58 if (!static_cast<FakeOptionSelectorFilter*>(parent())->multiSelect()) {
58 if (!m_checkedIndexes.isEmpty()) {
59 if (!m_checkedIndexes.isEmpty()) {
@@ -66,4 +67,12 @@ void FakeOptionSelectorOptions::setChecked(int row, bool checked)
66 }
67 }
67 const QModelIndex idx = index(row, 0);
68 const QModelIndex idx = index(row, 0);
68 Q_EMIT dataChanged(idx, idx, QVector<int>() << RoleOptionChecked);
69 Q_EMIT dataChanged(idx, idx, QVector<int>() << RoleOptionChecked);
70+ if (wasChecked != anyChecked()) {
71+ Q_EMIT anyCheckedChanged();
72+ }
73+}
74+
75+bool FakeOptionSelectorOptions::anyChecked() const
76+{
77+ return !m_checkedIndexes.isEmpty();
69}
78}
tests/mocks/Unity/fake_optionselectoroptions.h+5
@@ -34,6 +34,11 @@ public:
34 QVariant data(const QModelIndex &index, int role) const override;
34 QVariant data(const QModelIndex &index, int role) const override;
35 Q_INVOKABLE void setChecked(int index, bool checked) override;
35 Q_INVOKABLE void setChecked(int index, bool checked) override;
36
36
37+ bool anyChecked() const;
38+
39+Q_SIGNALS:
40+ void anyCheckedChanged();
41+
37private:
42private:
38 QStringList m_optionLabels;
43 QStringList m_optionLabels;
39 QSet<int> m_checkedIndexes;
44 QSet<int> m_checkedIndexes;
tests/mocks/Unity/fake_scope.cpp+2−2
@@ -50,6 +50,7 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
50 , m_returnNullPreview(returnNullPreview)
50 , m_returnNullPreview(returnNullPreview)
51{
51{
52 m_primaryNavigationFilter = new FakeOptionSelectorFilter("OSF3", "PFTag", "Which food you like More", false, QStringList() << "meat" << "vegetables", this);
52 m_primaryNavigationFilter = new FakeOptionSelectorFilter("OSF3", "PFTag", "Which food you like More", false, QStringList() << "meat" << "vegetables", this);
53+ connect(m_filters, &Filters::activeFiltersCountChanged, this, &Scope::activeFiltersCountChanged);
53}
54}
54
55
55QString Scope::id() const
56QString Scope::id() const
@@ -316,8 +317,7 @@ QString Scope::primaryNavigationTag() const
316
317
317int Scope::activeFiltersCount() const
318int Scope::activeFiltersCount() const
318{
319{
319− // TODO
320+ return m_filters->activeFiltersCount();
320− return 0;
321}
321}
322
322
323void Scope::resetPrimaryNavigationTag()
323void Scope::resetPrimaryNavigationTag()
tests/mocks/Unity/fake_scope.h+2−1
@@ -24,6 +24,7 @@
24
24
25#include <QTimer>
25#include <QTimer>
26
26
27+class Filters;
27class Scopes;
28class Scopes;
28class FakeOptionSelectorFilter;
29class FakeOptionSelectorFilter;
29
30
@@ -112,7 +113,7 @@ protected:
112 unity::shell::scopes::CategoriesInterface* m_categories;
113 unity::shell::scopes::CategoriesInterface* m_categories;
113 unity::shell::scopes::ScopeInterface* m_openScope;
114 unity::shell::scopes::ScopeInterface* m_openScope;
114 unity::shell::scopes::SettingsModelInterface* m_settings;
115 unity::shell::scopes::SettingsModelInterface* m_settings;
115− unity::shell::scopes::FiltersInterface* m_filters;
116+ Filters* m_filters;
116 FakeOptionSelectorFilter* m_primaryNavigationFilter;
117 FakeOptionSelectorFilter* m_primaryNavigationFilter;
117
118
118 bool m_returnNullPreview;
119 bool m_returnNullPreview;