on xenial help sign in
Implement the optional title for filters
commit24cb1113748334bcf70ba5433854fc3ee44e93eb authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 18 Nov 2015, 12:16 (11 years ago) parent8b7cb8d
5 files changed+64−13
qml/Dash/Filters/FilterWidgetFactory.qml+41−13 tests/mocks/Unity/fake_filters.cpp+1 tests/mocks/Unity/fake_rangeinputfilter.cpp+6 tests/mocks/Unity/fake_rangeinputfilter.h+1 tests/qmltests/Dash/Filters/tst_FilterRangeInput.qml+15
qml/Dash/Filters/FilterWidgetFactory.qml+41−13
@@ -15,13 +15,13 @@
1515 */
1616
1717import QtQuick 2.4
18+import Ubuntu.Components 1.3
1819import Unity 0.2
1920
2021//! \brief This component loads the widgets based on widgetType.
2122
22−Loader {
23+Item {
2324 id: root
24−
2525 //! Identifier of the widget.
2626 property string widgetId: ""
2727
@@ -31,20 +31,48 @@ Loader {
3131 //! Widget data, forwarded to the widget as is.
3232 property var widgetData: null
3333
34− source: widgetSource
34+ implicitHeight: childrenRect.height + title.anchors.topMargin
35+
36+ Label {
37+ id: title
38+ text: widgetData ? widgetData.title : ""
39+ height: text != "" ? implicitHeight : 0
40+
41+ anchors {
42+ top: parent.top
43+ left: parent.left
44+ right: parent.right
3545
36− //! \cond private
37− readonly property url widgetSource: {
38− switch (widgetType) {
39− case Filters.OptionSelectorFilter: return "FilterOptionSelector.qml";
40− case Filters.RangeInputFilter: return "FilterRangeInput.qml";
41− default: return "";
46+ topMargin: height > 0 ? units.gu(1) : 0
47+ leftMargin: units.gu(2)
48+ rightMargin: anchors.leftMargin
4249 }
4350 }
44− //! \endcond
4551
46− onLoaded: {
47− item.widgetId = Qt.binding(function() { return root.widgetId } )
48− item.widgetData = Qt.binding(function() { return root.widgetData } )
52+ property alias active: loader.active
53+
54+ Loader {
55+ id: loader
56+
57+ anchors {
58+ top: title.bottom
59+ left: parent.left
60+ right: parent.right
61+ }
62+
63+ source: widgetSource
64+
65+ readonly property url widgetSource: {
66+ switch (widgetType) {
67+ case Filters.OptionSelectorFilter: return "FilterOptionSelector.qml";
68+ case Filters.RangeInputFilter: return "FilterRangeInput.qml";
69+ default: return "";
70+ }
71+ }
72+
73+ onLoaded: {
74+ item.widgetId = Qt.binding(function() { return root.widgetId } )
75+ item.widgetData = Qt.binding(function() { return root.widgetData } )
76+ }
4977 }
5078}
tests/mocks/Unity/fake_filters.cpp+1
@@ -27,6 +27,7 @@ Filters::Filters(Scope* parent)
2727 addFilter(new FakeOptionSelectorFilter("OSF2", "Tag2", "Which Countries have you been to?", true, QStringList() << "Germany" << "UK" << "New Zealand", this));
2828
2929 FakeRangeInputFilter *rif = new FakeRangeInputFilter("RIF1", "Tag3", this);
30+ rif->setTitle("How much do you want to walk?");
3031 rif->setCentralLabel("to");
3132 rif->setStartPostfixLabel("m");
3233 rif->setEndPostfixLabel("m");
tests/mocks/Unity/fake_rangeinputfilter.cpp+6
@@ -130,6 +130,12 @@ bool FakeRangeInputFilter::isActive() const
130130 return hasStartValue() && hasEndValue();
131131}
132132
133+void FakeRangeInputFilter::setTitle(const QString &title)
134+{
135+ m_title = title;
136+ Q_EMIT titleChanged();
137+}
138+
133139void FakeRangeInputFilter::setStartPrefixLabel(const QString &startPrefixLabel)
134140{
135141 m_startPrefixLabel = startPrefixLabel;
tests/mocks/Unity/fake_rangeinputfilter.h+1
@@ -48,6 +48,7 @@ public:
4848 // Not part of the iface, for mock/testing purposes
4949 bool isActive() const;
5050
51+ void setTitle(const QString &title);
5152 void setStartPrefixLabel(const QString &startPrefixLabel);
5253 void setStartPostfixLabel(const QString &startPostfixLabel);
5354 void setCentralLabel(const QString &centralLabel);
tests/qmltests/Dash/Filters/tst_FilterRangeInput.qml+15
@@ -30,6 +30,7 @@ Rectangle {
3030 QtObject {
3131 id: widgetData1
3232
33+ property string title
3334 property real startValue
3435 property real endValue
3536 property bool hasStartValue
@@ -62,6 +63,7 @@ Rectangle {
6263 }
6364
6465 function generateData() {
66+ widgetData1.title = title.text
6567 widgetData1.startValue = startValue.text;
6668 widgetData1.endValue = endValue.text;
6769 widgetData1.hasStartValue = startValueHasValue.checked;
@@ -95,6 +97,19 @@ Rectangle {
9597 text: "Values"
9698 }
9799
100+ Row {
101+ spacing: units.gu(1)
102+ Text {
103+ text: "Title"
104+ verticalAlignment: Text.AlignVCenter
105+ height: parent.height
106+ }
107+ TextField {
108+ id: title
109+ text: ""
110+ }
111+ }
112+
98113 Row {
99114 spacing: units.gu(1)
100115 Text {