on xenial help sign in
Implement the optional title for filters
24cb111Albert Astals Cid
qml/Dash/Filters/FilterWidgetFactory.qml+41−13
@@ -15,13 +15,13 @@
15 */
15 */
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18+import Ubuntu.Components 1.3
18import Unity 0.2
19import Unity 0.2
19
20
20//! \brief This component loads the widgets based on widgetType.
21//! \brief This component loads the widgets based on widgetType.
21
22
22−Loader {
23+Item {
23 id: root
24 id: root
24−
25 //! Identifier of the widget.
25 //! Identifier of the widget.
26 property string widgetId: ""
26 property string widgetId: ""
27
27
@@ -31,20 +31,48 @@ Loader {
31 //! Widget data, forwarded to the widget as is.
31 //! Widget data, forwarded to the widget as is.
32 property var widgetData: null
32 property var widgetData: null
33
33
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
35
45
36− //! \cond private
46+ topMargin: height > 0 ? units.gu(1) : 0
37− readonly property url widgetSource: {
47+ leftMargin: units.gu(2)
38− switch (widgetType) {
48+ rightMargin: anchors.leftMargin
39− case Filters.OptionSelectorFilter: return "FilterOptionSelector.qml";
40− case Filters.RangeInputFilter: return "FilterRangeInput.qml";
41− default: return "";
42 }
49 }
43 }
50 }
44− //! \endcond
45
51
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+
46− onLoaded: {
73+ onLoaded: {
47− item.widgetId = Qt.binding(function() { return root.widgetId } )
74+ item.widgetId = Qt.binding(function() { return root.widgetId } )
48− item.widgetData = Qt.binding(function() { return root.widgetData } )
75+ item.widgetData = Qt.binding(function() { return root.widgetData } )
76+ }
49 }
77 }
50}
78}
tests/mocks/Unity/fake_filters.cpp+1
@@ -27,6 +27,7 @@ Filters::Filters(Scope* parent)
27 addFilter(new FakeOptionSelectorFilter("OSF2", "Tag2", "Which Countries have you been to?", true, QStringList() << "Germany" << "UK" << "New Zealand", this));
27 addFilter(new FakeOptionSelectorFilter("OSF2", "Tag2", "Which Countries have you been to?", true, QStringList() << "Germany" << "UK" << "New Zealand", this));
28
28
29 FakeRangeInputFilter *rif = new FakeRangeInputFilter("RIF1", "Tag3", this);
29 FakeRangeInputFilter *rif = new FakeRangeInputFilter("RIF1", "Tag3", this);
30+ rif->setTitle("How much do you want to walk?");
30 rif->setCentralLabel("to");
31 rif->setCentralLabel("to");
31 rif->setStartPostfixLabel("m");
32 rif->setStartPostfixLabel("m");
32 rif->setEndPostfixLabel("m");
33 rif->setEndPostfixLabel("m");
tests/mocks/Unity/fake_rangeinputfilter.cpp+6
@@ -130,6 +130,12 @@ bool FakeRangeInputFilter::isActive() const
130 return hasStartValue() && hasEndValue();
130 return hasStartValue() && hasEndValue();
131}
131}
132
132
133+void FakeRangeInputFilter::setTitle(const QString &title)
134+{
135+ m_title = title;
136+ Q_EMIT titleChanged();
137+}
138+
133void FakeRangeInputFilter::setStartPrefixLabel(const QString &startPrefixLabel)
139void FakeRangeInputFilter::setStartPrefixLabel(const QString &startPrefixLabel)
134{
140{
135 m_startPrefixLabel = startPrefixLabel;
141 m_startPrefixLabel = startPrefixLabel;
tests/mocks/Unity/fake_rangeinputfilter.h+1
@@ -48,6 +48,7 @@ public:
48 // Not part of the iface, for mock/testing purposes
48 // Not part of the iface, for mock/testing purposes
49 bool isActive() const;
49 bool isActive() const;
50
50
51+ void setTitle(const QString &title);
51 void setStartPrefixLabel(const QString &startPrefixLabel);
52 void setStartPrefixLabel(const QString &startPrefixLabel);
52 void setStartPostfixLabel(const QString &startPostfixLabel);
53 void setStartPostfixLabel(const QString &startPostfixLabel);
53 void setCentralLabel(const QString &centralLabel);
54 void setCentralLabel(const QString &centralLabel);
tests/qmltests/Dash/Filters/tst_FilterRangeInput.qml+15
@@ -30,6 +30,7 @@ Rectangle {
30 QtObject {
30 QtObject {
31 id: widgetData1
31 id: widgetData1
32
32
33+ property string title
33 property real startValue
34 property real startValue
34 property real endValue
35 property real endValue
35 property bool hasStartValue
36 property bool hasStartValue
@@ -62,6 +63,7 @@ Rectangle {
62 }
63 }
63
64
64 function generateData() {
65 function generateData() {
66+ widgetData1.title = title.text
65 widgetData1.startValue = startValue.text;
67 widgetData1.startValue = startValue.text;
66 widgetData1.endValue = endValue.text;
68 widgetData1.endValue = endValue.text;
67 widgetData1.hasStartValue = startValueHasValue.checked;
69 widgetData1.hasStartValue = startValueHasValue.checked;
@@ -95,6 +97,19 @@ Rectangle {
95 text: "Values"
97 text: "Values"
96 }
98 }
97
99
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+
98 Row {
113 Row {
99 spacing: units.gu(1)
114 spacing: units.gu(1)
100 Text {
115 Text {