on xenial help sign in
Implement Scope::activeFiltersCount in the mock plugin
commit036c0ff0bf5c2697fe7862261a537a22527afb04 authorAlbert Astals Cid <albert.astals@canonical.com> dateTue 13 Oct 2015, 16:35 (11 years ago) parent73dbe45
8 files changed+57−9
tests/mocks/Unity/fake_filters.cpp+17−3 tests/mocks/Unity/fake_filters.h+9−2 tests/mocks/Unity/fake_optionselectorfilter.cpp+5 tests/mocks/Unity/fake_optionselectorfilter.h+8−1 tests/mocks/Unity/fake_optionselectoroptions.cpp+9 tests/mocks/Unity/fake_optionselectoroptions.h+5 tests/mocks/Unity/fake_scope.cpp+2−2 tests/mocks/Unity/fake_scope.h+2−1
tests/mocks/Unity/fake_filters.cpp+17−3
@@ -22,9 +22,14 @@
2222Filters::Filters(Scope* parent)
2323 : unity::shell::scopes::FiltersInterface(parent)
2424{
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;
25+ addFilter(new FakeOptionSelectorFilter("OSF1", "Tag1", "Which Cake you like More", false, QStringList() << "cheese" << "carrot" << "chocolate", 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);
32+ m_filters << f;
2833}
2934
3035int Filters::rowCount(const QModelIndex &parent) const
@@ -54,3 +59,12 @@ QVariant Filters::data(const QModelIndex &index, int role) const
5459 return QVariant();
5560 }
5661}
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 @@
1818#define FAKE_FILTERS_H
1919
2020#include <unity/shell/scopes/FiltersInterface.h>
21−#include <unity/shell/scopes/FilterBaseInterface.h>
2221
2322class Scope;
23+class FakeOptionSelectorFilter;
2424
2525class Filters : public unity::shell::scopes::FiltersInterface
2626{
@@ -32,8 +32,15 @@ public:
3232 int rowCount(const QModelIndex &parent) const override;
3333 QVariant data(const QModelIndex &index, int role) const override;
3434
35+ int activeFiltersCount() const;
36+
37+Q_SIGNALS:
38+ void activeFiltersCountChanged();
39+
3540private:
36− QVector<unity::shell::scopes::FilterBaseInterface*> m_filters;
41+ void addFilter(FakeOptionSelectorFilter* f);
42+
43+ QVector<FakeOptionSelectorFilter*> m_filters;
3744};
3845
3946#endif
tests/mocks/Unity/fake_optionselectorfilter.cpp+5
@@ -26,6 +26,7 @@ FakeOptionSelectorFilter::FakeOptionSelectorFilter(const QString &id, const QStr
2626 m_multiSelect(multiselect)
2727{
2828 m_options = new FakeOptionSelectorOptions(optionLabels, this);
29+ connect(m_options, &FakeOptionSelectorOptions::anyCheckedChanged, this, &FakeOptionSelectorFilter::isActiveChanged);
2930}
3031
3132QString FakeOptionSelectorFilter::filterId() const
@@ -53,3 +54,7 @@ unity::shell::scopes::OptionSelectorOptionsInterface* FakeOptionSelectorFilter::
5354 return m_options;
5455}
5556
57+bool FakeOptionSelectorFilter::isActive() const
58+{
59+ return m_options->anyChecked();
60+}
tests/mocks/Unity/fake_optionselectorfilter.h+8−1
@@ -19,6 +19,8 @@
1919
2020#include <unity/shell/scopes/OptionSelectorFilterInterface.h>
2121
22+class FakeOptionSelectorOptions;
23+
2224class FakeOptionSelectorFilter : public unity::shell::scopes::OptionSelectorFilterInterface
2325{
2426 Q_OBJECT
@@ -32,12 +34,17 @@ public:
3234 bool multiSelect() const override;
3335 unity::shell::scopes::OptionSelectorOptionsInterface* options() const override;
3436
37+ bool isActive() const;
38+
39+Q_SIGNALS:
40+ void isActiveChanged();
41+
3542private:
3643 QString m_filterId;
3744 QString m_filterTag;
3845 QString m_label;
3946 bool m_multiSelect;
40− unity::shell::scopes::OptionSelectorOptionsInterface* m_options;
47+ FakeOptionSelectorOptions* m_options;
4148};
4249
4350#endif
tests/mocks/Unity/fake_optionselectoroptions.cpp+9
@@ -53,6 +53,7 @@ QVariant FakeOptionSelectorOptions::data(const QModelIndex &index, int role) con
5353
5454void FakeOptionSelectorOptions::setChecked(int row, bool checked)
5555{
56+ const bool wasChecked = anyChecked();
5657 if (checked) {
5758 if (!static_cast<FakeOptionSelectorFilter*>(parent())->multiSelect()) {
5859 if (!m_checkedIndexes.isEmpty()) {
@@ -66,4 +67,12 @@ void FakeOptionSelectorOptions::setChecked(int row, bool checked)
6667 }
6768 const QModelIndex idx = index(row, 0);
6869 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();
6978}
tests/mocks/Unity/fake_optionselectoroptions.h+5
@@ -34,6 +34,11 @@ public:
3434 QVariant data(const QModelIndex &index, int role) const override;
3535 Q_INVOKABLE void setChecked(int index, bool checked) override;
3636
37+ bool anyChecked() const;
38+
39+Q_SIGNALS:
40+ void anyCheckedChanged();
41+
3742private:
3843 QStringList m_optionLabels;
3944 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
5050 , m_returnNullPreview(returnNullPreview)
5151{
5252 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);
5354}
5455
5556QString Scope::id() const
@@ -316,8 +317,7 @@ QString Scope::primaryNavigationTag() const
316317
317318int Scope::activeFiltersCount() const
318319{
319− // TODO
320− return 0;
320+ return m_filters->activeFiltersCount();
321321}
322322
323323void Scope::resetPrimaryNavigationTag()
tests/mocks/Unity/fake_scope.h+2−1
@@ -24,6 +24,7 @@
2424
2525#include <QTimer>
2626
27+class Filters;
2728class Scopes;
2829class FakeOptionSelectorFilter;
2930
@@ -112,7 +113,7 @@ protected:
112113 unity::shell::scopes::CategoriesInterface* m_categories;
113114 unity::shell::scopes::ScopeInterface* m_openScope;
114115 unity::shell::scopes::SettingsModelInterface* m_settings;
115− unity::shell::scopes::FiltersInterface* m_filters;
116+ Filters* m_filters;
116117 FakeOptionSelectorFilter* m_primaryNavigationFilter;
117118
118119 bool m_returnNullPreview;