on xenial help sign in
First implementation of the value slider filter
commitc6497661ca45f3ca7ac3df000bdf55c61eed003b authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 25 Nov 2015, 11:46 (11 years ago) parent773d857
11 files changed+407−3
qml/Dash/Filters/FilterValueSlider.qml+72 qml/Dash/Filters/FilterWidgetFactory.qml+1 tests/mocks/Unity/CMakeLists.txt+4 tests/mocks/Unity/fake_filters.cpp+18−2 tests/mocks/Unity/fake_unity_plugin.cpp+3−1 tests/mocks/Unity/fake_valuesliderfilter.cpp+84 tests/mocks/Unity/fake_valuesliderfilter.h+55 tests/mocks/Unity/fake_valueslidervalues.cpp+51 tests/mocks/Unity/fake_valueslidervalues.h+36 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/Filters/tst_FilterValueSlider.qml+82
qml/Dash/Filters/FilterValueSlider.qmlnew file+72
@@ -0,0 +1,72 @@
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+import QtQuick 2.4
18+import QtQuick.Layouts 1.1
19+import Ubuntu.Components 1.3
20+
21+/*! Range Input Filter Widget. */
22+
23+FilterWidget {
24+ id: root
25+
26+ implicitHeight: childrenRect.height + units.gu(2)
27+
28+ Slider {
29+ id: slider
30+ objectName: "slider"
31+
32+ anchors {
33+ top: parent.top
34+ topMargin: units.gu(1)
35+ left: parent.left
36+ right: parent.right
37+ }
38+
39+ minimumValue: widgetData.minValue
40+ maximumValue: widgetData.maxValue
41+ value: widgetData.value
42+ onValueChanged: {
43+ widgetData.value = value;
44+ }
45+
46+ // TODO SDK
47+ readonly property Item bar: __styleInstance ? __styleInstance.bar : null
48+ readonly property Item thumb: __styleInstance ? __styleInstance.thumb : null
49+ readonly property real thumbSpacing: __styleInstance ? __styleInstance.thumbSpacing : 0
50+ readonly property real barMinusThumb: bar && thumb ? bar.width - (thumb.width + 2.0*thumbSpacing) : 0.0
51+ }
52+
53+ Repeater {
54+ model: widgetData.values
55+ delegate: Label {
56+ anchors {
57+ top: slider.bottom
58+ // The slider is too tall, so move a bit up
59+ topMargin: -units.gu(1)
60+ }
61+ text: label
62+ visible: value <= widgetData.maxValue && value >= widgetData.minValue
63+ x: {
64+ var halfThumbDifference = (width - slider.thumb.width) / 2;
65+ var result = (value - widgetData.minValue) * slider.barMinusThumb / (widgetData.maxValue - widgetData.minValue) - halfThumbDifference;
66+ result = Math.max(result, 0);
67+ result = Math.min(result, parent.width - width);
68+ return result;
69+ }
70+ }
71+ }
72+}
qml/Dash/Filters/FilterWidgetFactory.qml+1
@@ -66,6 +66,7 @@ Item {
6666 switch (widgetType) {
6767 case Filters.OptionSelectorFilter: return "FilterOptionSelector.qml";
6868 case Filters.RangeInputFilter: return "FilterRangeInput.qml";
69+ case Filters.ValueSliderFilter: return "FilterValueSlider.qml";
6970 default: return "";
7071 }
7172 }
tests/mocks/Unity/CMakeLists.txt+4
@@ -33,6 +33,8 @@ set(UnityQML_SOURCES
3333 fake_optionselectorfilter.cpp
3434 fake_optionselectoroptions.cpp
3535 fake_rangeinputfilter.cpp
36+ fake_valuesliderfilter.cpp
37+ fake_valueslidervalues.cpp
3638 fake_unity_plugin.cpp
3739 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/CategoriesInterface.h
3840 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/FilterBaseInterface.h
@@ -48,6 +50,8 @@ set(UnityQML_SOURCES
4850 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopeInterface.h
4951 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ScopesInterface.h
5052 ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/SettingsModelInterface.h
53+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ValueSliderFilterInterface.h
54+ ${SCOPES_API_INCLUDEDIR}/unity/shell/scopes/ValueSliderValuesInterface.h
5155)
5256
5357# Workaround for gcc failure LP: #1417664
tests/mocks/Unity/fake_filters.cpp+18−2
@@ -18,6 +18,7 @@
1818
1919#include "fake_optionselectorfilter.h"
2020#include "fake_rangeinputfilter.h"
21+#include "fake_valuesliderfilter.h"
2122#include "fake_scope.h"
2223
2324Filters::Filters(Scope* parent)
@@ -32,23 +33,34 @@ Filters::Filters(Scope* parent)
3233 rif->setStartPostfixLabel("m");
3334 rif->setEndPostfixLabel("m");
3435 addFilter(rif);
36+
37+ QMap<int, QString> labels;
38+ labels[15] = "Default";
39+ labels[50] = "50";
40+ labels[100] = "100";
41+ FakeValueSliderFilter *vsf = new FakeValueSliderFilter("VS1", "Tag4", 15, 10, 150, labels, this);
42+ addFilter(vsf);
3543}
3644
3745void Filters::addFilter(unity::shell::scopes::FilterBaseInterface *f)
3846{
3947 switch (f->filterType()) {
40− case FiltersInterface::OptionSelectorFilter: {
48+ case FiltersInterface::OptionSelectorFilter: {
4149 FakeOptionSelectorFilter *osf = static_cast<FakeOptionSelectorFilter *>(f);
4250 connect(osf, &FakeOptionSelectorFilter::isActiveChanged, this, &Filters::activeFiltersCountChanged);
4351 }
4452 break;
4553
46− case FiltersInterface::RangeInputFilter: {
54+ case FiltersInterface::RangeInputFilter: {
4755 FakeRangeInputFilter *rif = static_cast<FakeRangeInputFilter *>(f);
4856 connect(rif, &FakeRangeInputFilter::isActiveChanged, this, &Filters::activeFiltersCountChanged);
4957 }
5058 break;
5159
60+ case FiltersInterface::ValueSliderFilter: {
61+ // Not counting value slider as active in the mock
62+ }
63+
5264 case Invalid:
5365 break;
5466 }
@@ -100,6 +112,10 @@ int Filters::activeFiltersCount() const
100112 }
101113 break;
102114
115+ case FiltersInterface::ValueSliderFilter: {
116+ // Not counting value slider as active in the mock
117+ }
118+
103119 case Invalid:
104120 break;
105121 }
tests/mocks/Unity/fake_unity_plugin.cpp+3−1
@@ -29,6 +29,7 @@
2929#include "fake_previewwidgetmodel.h"
3030#include "fake_resultsmodel.h"
3131#include "fake_settingsmodel.h"
32+#include "fake_valueslidervalues.h"
3233
3334// External
3435#include <glib-object.h>
@@ -57,5 +58,6 @@ void FakeUnityPlugin::registerTypes(const char *uri)
5758 qmlRegisterUncreatableType<PreviewStack>(uri, 0, 2, "PreviewStack", "Can't create new PreviewStack in QML. Get them from Scope instance.");
5859 qmlRegisterUncreatableType<unity::shell::scopes::FiltersInterface>(uri, 0, 2, "Filters", "Can't create Filters object in QML. Get them from Scope instance.");
5960 qmlRegisterUncreatableType<unity::shell::scopes::FilterBaseInterface>(uri, 0, 2, "Filter", "Can't create Filter object in QML. Get them from Scope instance.");
60− qmlRegisterUncreatableType<unity::shell::scopes::OptionSelectorOptionsInterface>(uri, 0, 2, "OptionSelectorOptions", "Can't create Filters object in QML. Get them from OptionSelector instance.");
61+ qmlRegisterUncreatableType<unity::shell::scopes::OptionSelectorOptionsInterface>(uri, 0, 2, "OptionSelectorOptions", "Can't create OptionSelectorOptions object in QML");
62+ qmlRegisterUncreatableType<unity::shell::scopes::ValueSliderValuesInterface>(uri, 0, 2, "ValueSliderValues", "Can't create ValueSliderValuesInterface object in QML");
6163}
tests/mocks/Unity/fake_valuesliderfilter.cppnew file+84
@@ -0,0 +1,84 @@
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_valuesliderfilter.h"
18+#include "fake_valueslidervalues.h"
19+
20+FakeValueSliderFilter::FakeValueSliderFilter(const QString &id, const QString &tag, int value, int minValue, int maxValue, const QMap<int, QString> &labels, QObject* parent)
21+ : unity::shell::scopes::ValueSliderFilterInterface(parent),
22+ m_filterId(id),
23+ m_filterTag(tag),
24+ m_value(value),
25+ m_minValue(minValue),
26+ m_maxValue(maxValue),
27+ m_values(new FakeValueSliderValues(labels, this))
28+{
29+}
30+
31+QString FakeValueSliderFilter::filterId() const
32+{
33+ return m_filterId;
34+}
35+
36+QString FakeValueSliderFilter::filterTag() const
37+{
38+ return m_filterTag;
39+}
40+
41+QString FakeValueSliderFilter::title() const
42+{
43+ return m_title;
44+}
45+
46+int FakeValueSliderFilter::value() const
47+{
48+ return m_value;
49+}
50+
51+void FakeValueSliderFilter::setValue(int value)
52+{
53+ if (value != m_value) {
54+ m_value = value;
55+ Q_EMIT valueChanged();
56+ }
57+}
58+
59+int FakeValueSliderFilter::minValue() const
60+{
61+ return m_minValue;
62+}
63+
64+int FakeValueSliderFilter::maxValue() const
65+{
66+ return m_maxValue;
67+}
68+
69+unity::shell::scopes::ValueSliderValuesInterface* FakeValueSliderFilter::values() const
70+{
71+ return m_values;
72+}
73+
74+bool FakeValueSliderFilter::isActive() const
75+{
76+ // Doesn't really matter
77+ return false;
78+}
79+
80+void FakeValueSliderFilter::setTitle(const QString &title)
81+{
82+ m_title = title;
83+ Q_EMIT titleChanged();
84+}
tests/mocks/Unity/fake_valuesliderfilter.hnew 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+#ifndef FAKE_VALUESLIDERFILTER_H
18+#define FAKE_VALUESLIDERFILTER_H
19+
20+#include <unity/shell/scopes/ValueSliderFilterInterface.h>
21+
22+class FakeValueSliderFilter : public unity::shell::scopes::ValueSliderFilterInterface
23+{
24+ Q_OBJECT
25+
26+public:
27+ FakeValueSliderFilter(const QString &id, const QString &tag, int value, int minValue, int maxValue, const QMap<int, QString> &labels, QObject* parent);
28+
29+ QString filterId() const override;
30+ QString filterTag() const override;
31+ QString title() const override;
32+
33+ int value() const override;
34+ void setValue(int value) override;
35+ int minValue() const override;
36+ int maxValue() const override;
37+ unity::shell::scopes::ValueSliderValuesInterface* values() const override;
38+
39+ // Not part of the iface, for mock/testing purposes
40+ bool isActive() const;
41+
42+ void setTitle(const QString &title);
43+
44+private:
45+ QString m_filterId;
46+ QString m_filterTag;
47+ QString m_title;
48+
49+ int m_value;
50+ int m_minValue;
51+ int m_maxValue;
52+ unity::shell::scopes::ValueSliderValuesInterface *m_values;
53+};
54+
55+#endif
tests/mocks/Unity/fake_valueslidervalues.cppnew file+51
@@ -0,0 +1,51 @@
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_valueslidervalues.h"
18+
19+FakeValueSliderValues::FakeValueSliderValues(const QMap<int, QString> &labels, QObject* parent)
20+ : unity::shell::scopes::ValueSliderValuesInterface(parent)
21+ , m_labels(labels)
22+{
23+}
24+
25+int FakeValueSliderValues::rowCount(const QModelIndex &parent) const
26+{
27+ if (parent.isValid())
28+ return 0;
29+
30+ return m_labels.count();
31+}
32+
33+QVariant FakeValueSliderValues::data(const QModelIndex &index, int role) const
34+{
35+ if (!index.isValid())
36+ return QVariant();
37+
38+ const int row = index.row();
39+ auto it = m_labels.begin();
40+ it += row;
41+
42+ switch (role) {
43+ case RoleValue:
44+ return it.key();
45+
46+ case RoleLabel:
47+ return it.value();
48+ }
49+
50+ return QVariant();
51+}
tests/mocks/Unity/fake_valueslidervalues.hnew file+36
@@ -0,0 +1,36 @@
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_VALUESLIDERVALUES_H
18+#define FAKE_VALUESLIDERVALUES_H
19+
20+#include <unity/shell/scopes/ValueSliderValuesInterface.h>
21+
22+class FakeValueSliderValues : public unity::shell::scopes::ValueSliderValuesInterface
23+{
24+ Q_OBJECT
25+
26+public:
27+ FakeValueSliderValues(const QMap<int, QString> &labels, QObject* parent);
28+
29+ int rowCount(const QModelIndex &parent) const override;
30+ QVariant data(const QModelIndex &index, int role) const override;
31+
32+private:
33+ const QMap<int, QString> m_labels;
34+};
35+
36+#endif
tests/qmltests/CMakeLists.txt+1
@@ -51,6 +51,7 @@ add_unity8_qmltest(Dash/Previews PreviewWidgetFactory)
5151add_unity8_qmltest(Dash/Previews PreviewZoomableImage)
5252add_unity8_qmltest(Dash/Filters FilterOptionSelector)
5353add_unity8_qmltest(Dash/Filters FilterRangeInput)
54+add_unity8_qmltest(Dash/Filters FilterValueSlider)
5455add_unity8_qmltest(Dash/Filters FilterWidgetFactory)
5556add_unity8_qmltest(Dash/ScopeSettings ScopeSettingBoolean)
5657add_unity8_qmltest(Dash/ScopeSettings ScopeSettingList)
tests/qmltests/Dash/Filters/tst_FilterValueSlider.qmlnew file+82
@@ -0,0 +1,82 @@
1+/*
2+ * Copyright 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+import QtQuick 2.4
18+import QtTest 1.0
19+import Ubuntu.Components 1.3
20+import "../../../../qml/Dash/Filters"
21+import Unity.Test 0.1 as UT
22+import Unity 0.2
23+
24+Rectangle {
25+ id: root
26+ width: units.gu(60)
27+ height: units.gu(80)
28+ color: theme.palette.selected.background
29+
30+ QtObject {
31+ id: widgetData1
32+
33+ property string title
34+ property int value: 30
35+ property int minValue: 10
36+ property int maxValue: 150
37+
38+ property ListModel values: ListModel {
39+ ListElement {
40+ value: 10
41+ label: "10"
42+ }
43+ ListElement {
44+ value: 30
45+ label: "30"
46+ }
47+ ListElement {
48+ value: 100
49+ label: "100"
50+ }
51+ ListElement {
52+ value: 150
53+ label: "150"
54+ }
55+ }
56+ }
57+
58+ FilterWidgetFactory {
59+ id: factory
60+ widgetId: "testRangeValueSlider"
61+ widgetType: Filters.ValueSliderFilter
62+ widgetData: widgetData1;
63+ y: 100
64+ anchors {
65+ left: parent.left
66+ right: parent.right
67+ }
68+ }
69+
70+ UT.UnityTestCase {
71+ name: "FilterValueSlider"
72+ when: windowShown
73+
74+ function test_valueChanges() {
75+ var slider = findChild(factory, "slider");
76+ compare(slider.value, 30);
77+
78+ slider.value = 50
79+ compare(widgetData1.value, 50);
80+ }
81+ }
82+}