on xenial help sign in
ExpandableFilterWidget
commit46d3556dfb4c67511f27256b6568940be3c803ed authorAlbert Astals Cid <albert.astals@canonical.com> dateMon 14 Mar 2016, 17:46 (11 years ago) parentb1ee23e
10 files changed+228−14
qml/Dash/Filters/FilterExpandableWidget.qml+93 qml/Dash/Filters/FilterWidget.qml+3 qml/Dash/Filters/FilterWidgetFactory.qml+2−1 tests/mocks/Unity/CMakeLists.txt+2 tests/mocks/Unity/fake_expandablefilterwidget.cpp+53 tests/mocks/Unity/fake_expandablefilterwidget.h+48 tests/mocks/Unity/fake_filters.cpp+19−8 tests/mocks/Unity/fake_filters.h+4−4 tests/mocks/Unity/fake_scope.cpp+2 tests/qmltests/Dash/Filters/tst_FilterWidgetFactory.qml+2−1
qml/Dash/Filters/FilterExpandableWidget.qmlnew file+93
@@ -0,0 +1,93 @@
1+/*
2+ * Copyright (C) 2016 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+import QtQuick 2.4
18+import Ubuntu.Components 1.3
19+import Ubuntu.Components.ListItems 1.3 as ListItems
20+
21+/*! Option Selector Filter Widget. */
22+
23+FilterWidget {
24+ id: root
25+
26+ showsTitleOnItsOwn: true
27+
28+ implicitHeight: expandingItem.height
29+
30+ ListItems.Expandable {
31+ id: expandingItem
32+ objectName: "expandingItem"
33+
34+ expandedHeight: collapsedHeight + column.height
35+ width: parent.width
36+ showDivider: false
37+
38+ onClicked: {
39+ expanded = !expanded;
40+ forceActiveFocus();
41+ }
42+ __contentsMargins: 0
43+
44+ Item {
45+ id: titleHolder
46+ anchors.top: parent.top
47+ height: expandingItem.collapsedHeight
48+ width: parent.width
49+
50+ Label {
51+ anchors.left: parent.left
52+ anchors.leftMargin: units.gu(2)
53+ anchors.right: dropDown.left
54+ anchors.verticalCenter: parent.verticalCenter
55+ text: widgetData.title || ""
56+ }
57+
58+ Image {
59+ id: dropDown
60+ height: units.gu(3)
61+ fillMode: Image.PreserveAspectFit
62+ anchors.right: parent.right
63+ anchors.rightMargin: units.gu(2)
64+ anchors.verticalCenter: parent.verticalCenter
65+ source: expandingItem.expanded ? "image://theme/up" : "image://theme/down"
66+ }
67+ }
68+
69+ Column {
70+ id: column
71+ width: parent.width
72+ anchors.top: titleHolder.bottom
73+
74+ Repeater {
75+ id: repeater
76+ model: widgetData.filters
77+
78+ delegate: FilterWidgetFactory {
79+ width: parent.width
80+
81+ widgetId: id
82+ widgetType: type
83+ widgetData: filter
84+
85+ ListItems.ThinDivider {
86+ anchors.bottom: parent.bottom
87+ visible: index != repeater.count - 1
88+ }
89+ }
90+ }
91+ }
92+ }
93+}
qml/Dash/Filters/FilterWidget.qml+3
@@ -25,5 +25,8 @@ Item {
2525 //! Variable used to contain widget's data
2626 property var widgetData: null
2727
28+ //! Does the widget show the title inside?
29+ property bool showsTitleOnItsOwn: false
30+
2831 objectName: widgetId
2932}
qml/Dash/Filters/FilterWidgetFactory.qml+2−1
@@ -35,7 +35,7 @@ Item {
3535
3636 Label {
3737 id: title
38− text: widgetData ? widgetData.title : ""
38+ text: widgetData && !(loader.item && loader.item.showsTitleOnItsOwn) ? widgetData.title : ""
3939 height: text != "" ? implicitHeight : 0
4040
4141 anchors {
@@ -67,6 +67,7 @@ Item {
6767 case Filters.OptionSelectorFilter: return "FilterOptionSelector.qml";
6868 case Filters.RangeInputFilter: return "FilterRangeInput.qml";
6969 case Filters.ValueSliderFilter: return "FilterValueSlider.qml";
70+ case Filters.ExpandableFilterWidget: return "FilterExpandableWidget.qml";
7071 default: return "";
7172 }
7273 }
tests/mocks/Unity/CMakeLists.txt+2
@@ -34,6 +34,7 @@ set(UnityQML_SOURCES
3434 fake_optionselectoroptions.cpp
3535 fake_rangeinputfilter.cpp
3636 fake_valuesliderfilter.cpp
37+ fake_expandablefilterwidget.cpp
3738 fake_valueslidervalues.cpp
3839 fake_unity_plugin.cpp
3940 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
@@ -51,6 +52,7 @@ set(UnityQML_SOURCES
5152 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/SettingsModelInterface.h
5253 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ValueSliderFilterInterface.h
5354 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ValueSliderValuesInterface.h
55+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ExpandableFilterWidgetInterface.h
5456)
5557
5658# Workaround for gcc failure LP: #1417664
tests/mocks/Unity/fake_expandablefilterwidget.cppnew file+53
@@ -0,0 +1,53 @@
1+/*
2+ * Copyright (C) 2016 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_expandablefilterwidget.h"
18+
19+#include "fake_filters.h"
20+
21+FakeExpandbleFilterWidget::FakeExpandbleFilterWidget(const QString &id, const QString &tag, const QString &title, QObject* parent)
22+ : unity::shell::scopes::ExpandableFilterWidgetInterface(parent)
23+ , m_filterId(id)
24+ , m_filterTag(tag)
25+ , m_title(title)
26+{
27+ m_filters = new Filters(this);
28+}
29+
30+QString FakeExpandbleFilterWidget::filterId() const
31+{
32+ return m_filterId;
33+}
34+
35+QString FakeExpandbleFilterWidget::filterTag() const
36+{
37+ return m_filterTag;
38+}
39+
40+QString FakeExpandbleFilterWidget::title() const
41+{
42+ return m_title;
43+}
44+
45+unity::shell::scopes::FiltersInterface* FakeExpandbleFilterWidget::filters() const
46+{
47+ return m_filters;
48+}
49+
50+void FakeExpandbleFilterWidget::addFilter(unity::shell::scopes::FilterBaseInterface* f)
51+{
52+ m_filters->addFilter(f);
53+}
tests/mocks/Unity/fake_expandablefilterwidget.hnew file+48
@@ -0,0 +1,48 @@
1+/*
2+ * Copyright (C) 2016 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_EXPANDABLEFILTERWIDGET_H
18+#define FAKE_EXPANDABLEFILTERWIDGET_H
19+
20+#include <unity/shell/scopes/ExpandableFilterWidgetInterface.h>
21+
22+class Filters;
23+
24+class FakeExpandbleFilterWidget : public unity::shell::scopes::ExpandableFilterWidgetInterface
25+{
26+ Q_OBJECT
27+
28+public:
29+ FakeExpandbleFilterWidget(const QString &id, const QString &tag, const QString &title, QObject* parent);
30+
31+ QString filterId() const override;
32+ QString filterTag() const override;
33+ QString title() const override;
34+
35+ unity::shell::scopes::FiltersInterface* filters() const override;
36+
37+ // mock API
38+ void addFilter(unity::shell::scopes::FilterBaseInterface* f);
39+
40+private:
41+ QString m_filterId;
42+ QString m_filterTag;
43+ QString m_title;
44+
45+ Filters *m_filters;
46+};
47+
48+#endif
tests/mocks/Unity/fake_filters.cpp+19−8
@@ -19,10 +19,14 @@
1919#include "fake_optionselectorfilter.h"
2020#include "fake_rangeinputfilter.h"
2121#include "fake_valuesliderfilter.h"
22−#include "fake_scope.h"
22+#include "fake_expandablefilterwidget.h"
2323
24−Filters::Filters(Scope* parent)
24+Filters::Filters(QObject* parent)
2525 : unity::shell::scopes::FiltersInterface(parent)
26+{
27+}
28+
29+void Filters::addFakeFilters()
2630{
2731 addFilter(new FakeOptionSelectorFilter("OSF1", "Tag1", "Which Cake you like More", false, QStringList() << "cheese" << "carrot" << "chocolate", this));
2832
@@ -41,6 +45,11 @@ Filters::Filters(Scope* parent)
4145 addFilter(vsf);
4246
4347 addFilter(new FakeOptionSelectorFilter("OSF2", "Tag2", "Which Countries have you been to?", true, QStringList() << "Germany" << "UK" << "New Zealand", this));
48+
49+ auto expandableFilter = new FakeExpandbleFilterWidget("EFW", "Tag5", "Advanced Settings", this);
50+ expandableFilter->addFilter(new FakeValueSliderFilter("VS2", "Tag6", 15, 10, 150, labels, this));
51+
52+ addFilter(expandableFilter);
4453}
4554
4655void Filters::addFilter(unity::shell::scopes::FilterBaseInterface *f)
@@ -58,9 +67,10 @@ void Filters::addFilter(unity::shell::scopes::FilterBaseInterface *f)
5867 }
5968 break;
6069
61− case FiltersInterface::ValueSliderFilter: {
62− // Not counting value slider as active in the mock
63− }
70+ case FiltersInterface::ExpandableFilterWidget:
71+ // Can't be active
72+ case FiltersInterface::ValueSliderFilter:
73+ // Not counting value as active in the mock
6474
6575 case Invalid:
6676 break;
@@ -113,9 +123,10 @@ int Filters::activeFiltersCount() const
113123 }
114124 break;
115125
116− case FiltersInterface::ValueSliderFilter: {
117− // Not counting value slider as active in the mock
118− }
126+ case FiltersInterface::ExpandableFilterWidget:
127+ // Can't be active
128+ case FiltersInterface::ValueSliderFilter:
129+ // Not counting value as active in the mock
119130
120131 case Invalid:
121132 break;
tests/mocks/Unity/fake_filters.h+4−4
@@ -20,25 +20,25 @@
2020#include <unity/shell/scopes/FiltersInterface.h>
2121#include <unity/shell/scopes/FilterBaseInterface.h>
2222
23−class Scope;
24−
2523class Filters : public unity::shell::scopes::FiltersInterface
2624{
2725 Q_OBJECT
2826
2927public:
30− Filters(Scope* parent);
28+ Filters(QObject* parent);
3129
3230 int rowCount(const QModelIndex &parent) const override;
3331 QVariant data(const QModelIndex &index, int role) const override;
3432
33+ // Mock API
3534 int activeFiltersCount() const;
35+ void addFakeFilters();
36+ void addFilter(unity::shell::scopes::FilterBaseInterface* f);
3637
3738Q_SIGNALS:
3839 void activeFiltersCountChanged();
3940
4041private:
41− void addFilter(unity::shell::scopes::FilterBaseInterface* f);
4242
4343 QVector<unity::shell::scopes::FilterBaseInterface*> m_filters;
4444};
tests/mocks/Unity/fake_scope.cpp+2
@@ -49,6 +49,8 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
4949 , m_filters(new Filters(this))
5050 , m_returnNullPreview(returnNullPreview)
5151{
52+ m_filters->addFakeFilters();
53+
5254 m_primaryNavigationFilter = new FakeOptionSelectorFilter("OSF3", "PFTag", "Which food you like More", false, QStringList() << "meat" << "vegetables", this);
5355 connect(m_filters, &Filters::activeFiltersCountChanged, this, &Scope::activeFiltersCountChanged);
5456}
tests/qmltests/Dash/Filters/tst_FilterWidgetFactory.qml+2−1
@@ -43,7 +43,8 @@ Rectangle {
4343 return [
4444 { tag: "OptionSelector", type: Filters.OptionSelectorFilter, source: "FilterOptionSelector.qml" },
4545 { tag: "RangeInputFilter", type: Filters.RangeInputFilter, source: "FilterRangeInput.qml" },
46− { tag: "ValueSliderFilter", type: Filters.ValueSliderFilter, source: "FilterValueSlider.qml" }
46+ { tag: "ValueSliderFilter", type: Filters.ValueSliderFilter, source: "FilterValueSlider.qml" },
47+ { tag: "ExpandableFilter", type: Filters.ExpandableFilterWidget, source: "FilterExpandableWidget.qml" }
4748 ];
4849 }
4950