on xenial help sign in
Merge lp:~cimi/unity8/scope-settings
4b6ce04Michał Sawicz
qml/Dash/GenericScopeView.qml+14−12
@@ -482,24 +482,26 @@ FocusScope {
482 open = false;
482 open = false;
483 }
483 }
484
484
485+ source: switch(subPage) {
485− source: subPage && (subPage == "preview" ? "PreviewListView.qml" : "ScopeSettingsPage.qml") || ""
486+ case "preview": return "PreviewListView.qml";
487+ case "settings": return "ScopeSettingsPage.qml";
488+ default: return "";
489+ }
486
490
487 onLoaded: {
491 onLoaded: {
488− if (status === Loader.Ready) {
489− item.scope = Qt.binding(function() { return subPageLoader.scope } )
492+ item.scope = Qt.binding(function() { return subPageLoader.scope; } )
490− item.scopeStyle = Qt.binding(function() { return subPageLoader.scopeStyle } )
493+ item.scopeStyle = Qt.binding(function() { return subPageLoader.scopeStyle; } )
491− if (subPage == "preview") {
494+ if (subPage == "preview") {
492− item.open = Qt.binding(function() { return subPageLoader.open } )
495+ item.open = Qt.binding(function() { return subPageLoader.open; } )
493− item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex } )
496+ item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex; } )
494− item.model = Qt.binding(function() { return subPageLoader.model } )
497+ item.model = Qt.binding(function() { return subPageLoader.model; } )
495− }
496− open = true;
497 }
498 }
499+ open = true;
498 }
500 }
499
501
500− onOpenChanged: pageHeaderLoader.item.unfocus();
502+ onOpenChanged: pageHeaderLoader.item.unfocus()
501
503
502− onVisibleChanged: if (!visible) subPage = "";
504+ onVisibleChanged: if (!visible) subPage = ""
503
505
504 Connections {
506 Connections {
505 target: subPageLoader.item
507 target: subPageLoader.item
qml/Dash/PageHeader.qml+3−10
@@ -249,9 +249,7 @@ Item {
249 backAction: Action {
249 backAction: Action {
250 iconName: "back"
250 iconName: "back"
251 visible: root.showBackButton
251 visible: root.showBackButton
252− onTriggered: {
253− root.backClicked();
252+ onTriggered: root.backClicked()
254− }
255 }
253 }
256
254
257 actions: [
255 actions: [
@@ -270,20 +268,15 @@ Item {
270 text: i18n.tr("Settings")
268 text: i18n.tr("Settings")
271 iconName: "settings"
269 iconName: "settings"
272 visible: root.settingsEnabled
270 visible: root.settingsEnabled
273− onTriggered: {
274− root.settingsClicked()
271+ onTriggered: root.settingsClicked()
275− }
276 },
272 },
277 Action {
273 Action {
278 objectName: "favorite"
274 objectName: "favorite"
279 text: root.favorite ? i18n.tr("Remove from Favorites") : i18n.tr("Add to Favorites")
275 text: root.favorite ? i18n.tr("Remove from Favorites") : i18n.tr("Add to Favorites")
280 iconName: root.favorite ? "starred" : "non-starred"
276 iconName: root.favorite ? "starred" : "non-starred"
281 visible: root.favoriteEnabled
277 visible: root.favoriteEnabled
282− onTriggered: {
283− root.favoriteClicked()
278+ onTriggered: root.favoriteClicked()
284− }
285 }
279 }
286−
287 ]
280 ]
288 }
281 }
289
282
qml/Dash/ScopeSettings/ScopeSetting.qml+3−2
@@ -26,11 +26,12 @@ Item {
26 //! Variable used to contain widget's data
26 //! Variable used to contain widget's data
27 property var widgetData: null
27 property var widgetData: null
28
28
29− readonly property real __margins: units.gu(2)
30−
31 /*! \brief This signal should be emitted when a setting action was updated.
29 /*! \brief This signal should be emitted when a setting action was updated.
32 *
30 *
33 * \param value the new setting value.
31 * \param value the new setting value.
34 */
32 */
35 signal updated(var value)
33 signal updated(var value)
34+
35+ //! \internal
36+ readonly property real settingMargins: units.gu(2)
36}
37}
qml/Dash/ScopeSettings/ScopeSettingBoolean.qml+6−5
@@ -26,21 +26,22 @@ ScopeSetting {
26 id: listItem
26 id: listItem
27
27
28 onClicked: {
28 onClicked: {
29− control.checked = !control.checked
29+ control.checked = !control.checked;
30− updated(control.checked)
30+ updated(control.checked);
31 }
31 }
32
32
33 Label {
33 Label {
34 anchors {
34 anchors {
35 left: parent.left
35 left: parent.left
36− leftMargin: __margins
36+ leftMargin: settingMargins
37 right: control.left
37 right: control.left
38 rightMargin: units.gu(1)
38 rightMargin: units.gu(1)
39 verticalCenter: parent.verticalCenter
39 verticalCenter: parent.verticalCenter
40 }
40 }
41 text: widgetData.displayName
41 text: widgetData.displayName
42 elide: Text.ElideMiddle
42 elide: Text.ElideMiddle
43− maximumLineCount: 1
43+ maximumLineCount: 2
44+ wrapMode: Text.Wrap
44 color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
45 color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
45 }
46 }
46
47
@@ -49,7 +50,7 @@ ScopeSetting {
49 objectName: "control"
50 objectName: "control"
50 anchors {
51 anchors {
51 right: parent.right
52 right: parent.right
52− rightMargin: __margins
53+ rightMargin: settingMargins
53 verticalCenter: parent.verticalCenter
54 verticalCenter: parent.verticalCenter
54 }
55 }
55 checked: widgetData.value
56 checked: widgetData.value
qml/Dash/ScopeSettings/ScopeSettingList.qml+12−1
@@ -24,6 +24,8 @@ ScopeSetting {
24 // FIXME workaround for: https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1355830
24 // FIXME workaround for: https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1355830
25 height: listItem.currentlyExpanded ? listItem.itemHeight * widgetData.properties["values"].length + units.gu(6) : listItem.height
25 height: listItem.currentlyExpanded ? listItem.itemHeight * widgetData.properties["values"].length + units.gu(6) : listItem.height
26
26
27+ property int initialValue: -1
28+
27 ListItem.ItemSelector {
29 ListItem.ItemSelector {
28 id: listItem
30 id: listItem
29 objectName: "control"
31 objectName: "control"
@@ -34,6 +36,15 @@ ScopeSetting {
34 text: widgetData.displayName
36 text: widgetData.displayName
35 model: widgetData.properties["values"]
37 model: widgetData.properties["values"]
36
38
39+ onSelectedIndexChanged: {
40+ if (root.initialValue >= 0) {
41+ var tmpValue = root.initialValue;
42+ root.initialValue = -1;
43+ selectedIndex = tmpValue;
44+ return;
45+ }
46+
37− onSelectedIndexChanged: root.updated(selectedIndex)
47+ root.updated(selectedIndex);
48+ }
38 }
49 }
39}
50}
qml/Dash/ScopeSettings/ScopeSettingString.qml+4−3
@@ -35,14 +35,15 @@ ScopeSetting {
35 id: label
35 id: label
36 anchors {
36 anchors {
37 left: parent.left
37 left: parent.left
38− leftMargin: __margins
38+ leftMargin: settingMargins
39 right: control.left
39 right: control.left
40 rightMargin: units.gu(1)
40 rightMargin: units.gu(1)
41 verticalCenter: parent.verticalCenter
41 verticalCenter: parent.verticalCenter
42 }
42 }
43 text: widgetData.displayName
43 text: widgetData.displayName
44 elide: Text.ElideMiddle
44 elide: Text.ElideMiddle
45− maximumLineCount: 1
45+ maximumLineCount: 2
46+ wrapMode: Text.Wrap
46 color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
47 color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
47 }
48 }
48
49
@@ -51,7 +52,7 @@ ScopeSetting {
51 objectName: "control"
52 objectName: "control"
52 anchors {
53 anchors {
53 right: parent.right
54 right: parent.right
54− rightMargin: __margins
55+ rightMargin: settingMargins
55 verticalCenter: parent.verticalCenter
56 verticalCenter: parent.verticalCenter
56 }
57 }
57 width: root.mode == "number" ? units.gu(8) : units.gu(12)
58 width: root.mode == "number" ? units.gu(8) : units.gu(12)
qml/Dash/ScopeSettings/ScopeSettingsWidgetFactory.qml+4−3
@@ -45,12 +45,13 @@ Loader {
45 //! \endcond
45 //! \endcond
46
46
47 onLoaded: {
47 onLoaded: {
48+ if (item.hasOwnProperty("initialValue")) item.initialValue = root.widgetData.value;
48− item.widgetData = Qt.binding(function() { return root.widgetData } )
49+ item.widgetData = Qt.binding(function() { return root.widgetData; } )
49− item.scopeStyle = Qt.binding(function() { return root.scopeStyle } )
50+ item.scopeStyle = Qt.binding(function() { return root.scopeStyle; } )
50 }
51 }
51
52
52 Connections {
53 Connections {
53 target: root.item
54 target: root.item
54− onUpdated: root.updated(value)
55+ onUpdated: if (value !== widgetData.value) root.updated(value)
55 }
56 }
56}
57}
qml/Dash/ScopeSettingsPage.qml+1−1
@@ -34,7 +34,7 @@ Item {
34 width: parent.width
34 width: parent.width
35 title: scope ? scope.name : ""
35 title: scope ? scope.name : ""
36 showBackButton: true
36 showBackButton: true
37− scopeStyle: root.scopeStyle || undefined
37+ scopeStyle: root.scopeStyle
38
38
39 onBackClicked: root.backClicked()
39 onBackClicked: root.backClicked()
40 }
40 }
tests/mocks/Unity/fake_settingsmodel.cpp+1−2
@@ -69,8 +69,7 @@ QVariant SettingsModel::data(const QModelIndex& index, int role) const {
69 return result;
69 return result;
70}
70}
71
71
72−bool SettingsModel::setData(const QModelIndex &index, const QVariant &value,
72+bool SettingsModel::setData(const QModelIndex &index, const QVariant &value, int role) {
73− int role) {
74 int row = index.row();
73 int row = index.row();
75 if (row < m_data.size()) {
74 if (row < m_data.size()) {
76 switch (role) {
75 switch (role) {
tests/mocks/Unity/fake_unity_plugin.cpp+1−1
@@ -44,7 +44,7 @@ void FakeUnityPlugin::registerTypes(const char *uri)
44 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
44 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
45 qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
45 qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
46 qmlRegisterUncreatableType<unity::shell::scopes::ScopeInterface>(uri, 0, 2, "Scope", "Can't create Scope object in QML.");
46 qmlRegisterUncreatableType<unity::shell::scopes::ScopeInterface>(uri, 0, 2, "Scope", "Can't create Scope object in QML.");
47− qmlRegisterUncreatableType<unity::shell::scopes::SettingsModelInterface>(uri, 0, 2, "Scope", "Can't create SettingsModel object in QML.");
47+ qmlRegisterUncreatableType<unity::shell::scopes::SettingsModelInterface>(uri, 0, 2, "SettingsModel", "Can't create SettingsModel object in QML.");
48 qmlRegisterUncreatableType<unity::shell::scopes::NavigationInterface>(uri, 0, 2, "Navigation", "Can't create Navigation object in QML.");
48 qmlRegisterUncreatableType<unity::shell::scopes::NavigationInterface>(uri, 0, 2, "Navigation", "Can't create Navigation object in QML.");
49 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
49 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
50 qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");
50 qmlRegisterUncreatableType<unity::shell::scopes::PreviewModelInterface>(uri, 0, 2, "PreviewModel", "Can't create new PreviewModel in QML. Get them from PreviewStack instance.");
tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1−1
@@ -93,7 +93,7 @@ Rectangle {
93 factory.widgetData = { type: data.type };
93 factory.widgetData = { type: data.type };
94 factory.widgetType = data.type;
94 factory.widgetType = data.type;
95
95
96− verify(("" + factory.source).indexOf(data.source) != -1);
96+ verify((String(factory.source)).indexOf(data.source) != -1);
97 }
97 }
98 }
98 }
99}
99}
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingBoolean.qml+1−1
@@ -44,7 +44,7 @@ Rectangle {
44
44
45 UT.UnityTestCase {
45 UT.UnityTestCase {
46 id: testCase
46 id: testCase
47− name: "ScopeSettingBooleanTest"
47+ name: "ScopeSettingBoolean"
48 when: windowShown
48 when: windowShown
49
49
50 function test_updated() {
50 function test_updated() {
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingList.qml+11−3
@@ -32,8 +32,8 @@ Rectangle {
32
32
33 ScopeSettingList {
33 ScopeSettingList {
34 id: scopeSetting
34 id: scopeSetting
35− widgetData: settingData
36 width: parent.width
35 width: parent.width
36+ widgetData: settingData
37 }
37 }
38
38
39 SignalSpy {
39 SignalSpy {
@@ -44,16 +44,24 @@ Rectangle {
44
44
45 UT.UnityTestCase {
45 UT.UnityTestCase {
46 id: testCase
46 id: testCase
47− name: "ScopeSettingListTest"
47+ name: "ScopeSettingList"
48 when: windowShown
48 when: windowShown
49
49
50 property var control: findChild(scopeSetting, "control")
50 property var control: findChild(scopeSetting, "control")
51
51
52− function init() {
52+ function cleanup() {
53 control.selectedIndex = 0;
53 control.selectedIndex = 0;
54 spy.clear();
54 spy.clear();
55 }
55 }
56
56
57+ function test_initialValue() {
58+ var newObject = Qt.createQmlObject('import "../../../../qml/Dash/ScopeSettings" \n\
59+ ScopeSettingList { initialValue: 2; }', root, "dynamicScopeSettingList");
60+ newObject.widgetData = settingData;
61+ var controlDynamic = findChild(newObject, "control");
62+ tryCompare(controlDynamic, "selectedIndex", 2);
63+ }
64+
57 function test_updated_data() {
65 function test_updated_data() {
58 return [
66 return [
59 { tag: "current", index: 0, updated: false },
67 { tag: "current", index: 0, updated: false },
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingNumber.qml+3−3
@@ -44,13 +44,13 @@ Rectangle {
44
44
45 UT.UnityTestCase {
45 UT.UnityTestCase {
46 id: testCase
46 id: testCase
47− name: "ScopeSettingNumberTest"
47+ name: "ScopeSettingNumber"
48 when: windowShown
48 when: windowShown
49
49
50 property var control: findChild(scopeSetting, "control")
50 property var control: findChild(scopeSetting, "control")
51 property real newNumber: 11.7
51 property real newNumber: 11.7
52
52
53− function init() {
53+ function cleanup() {
54 control.focus = false;
54 control.focus = false;
55 control.text = settingData.value;
55 control.text = settingData.value;
56 spy.clear();
56 spy.clear();
@@ -85,7 +85,7 @@ Rectangle {
85 verify(control.displayText == newNumber);
85 verify(control.displayText == newNumber);
86 }
86 }
87
87
88− function test_unacceptableInput() {
88+ function test_unacceptable_input() {
89 mouseClick(control, control.width / 2, control.height / 2);
89 mouseClick(control, control.width / 2, control.height / 2);
90 control.selectAll();
90 control.selectAll();
91 control.cut();
91 control.cut();
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingString.qml+2−2
@@ -44,13 +44,13 @@ Rectangle {
44
44
45 UT.UnityTestCase {
45 UT.UnityTestCase {
46 id: testCase
46 id: testCase
47− name: "ScopeSettingStringTest"
47+ name: "ScopeSettingString"
48 when: windowShown
48 when: windowShown
49
49
50 property var control: findChild(scopeSetting, "control")
50 property var control: findChild(scopeSetting, "control")
51 property string newText: "new text to compare"
51 property string newText: "new text to compare"
52
52
53− function init() {
53+ function cleanup() {
54 control.focus = false;
54 control.focus = false;
55 control.text = settingData.value;
55 control.text = settingData.value;
56 spy.clear();
56 spy.clear();
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingsWidgetFactory.qml+2−2
@@ -42,7 +42,7 @@ Rectangle {
42
42
43 UT.UnityTestCase {
43 UT.UnityTestCase {
44 id: testCase
44 id: testCase
45− name: "ScopeSettingWidgetFactoryTest"
45+ name: "ScopeSettingWidgetFactory"
46 when: windowShown
46 when: windowShown
47
47
48 function test_mapping_data() {
48 function test_mapping_data() {
@@ -59,7 +59,7 @@ Rectangle {
59 newSettingData.type = data.type;
59 newSettingData.type = data.type;
60 scopeSettingsWidgetFactory.widgetData = newSettingData;
60 scopeSettingsWidgetFactory.widgetData = newSettingData;
61
61
62− verify(("" + scopeSettingsWidgetFactory.source).indexOf(data.source) != -1);
62+ verify((String(scopeSettingsWidgetFactory.source)).indexOf(data.source) != -1);
63 }
63 }
64 }
64 }
65}
65}
tests/qmltests/Dash/tst_GenericScopeView.qml+2−1
@@ -377,7 +377,7 @@ Item {
377 var settings = findChild(innerHeader, "settings_header_button");
377 var settings = findChild(innerHeader, "settings_header_button");
378 mouseClick(settings, settings.width / 2, settings.height / 2);
378 mouseClick(settings, settings.width / 2, settings.height / 2);
379 tryCompare(testCase.subPageLoader, "open", true);
379 tryCompare(testCase.subPageLoader, "open", true);
380− tryCompareFunction(function() { return ("" + subPageLoader.source).indexOf("ScopeSettingsPage.qml") != -1; }, true);
380+ tryCompareFunction(function() { return (String(subPageLoader.source)).indexOf("ScopeSettingsPage.qml") != -1; }, true);
381 tryCompare(genericScopeView, "subPageShown", true);
381 tryCompare(genericScopeView, "subPageShown", true);
382 compare(testCase.subPageLoader.subPage, "settings");
382 compare(testCase.subPageLoader.subPage, "settings");
383 tryCompare(testCase.subPageLoader, "x", 0);
383 tryCompare(testCase.subPageLoader, "x", 0);
@@ -390,6 +390,7 @@ Item {
390 var categoryListView = findChild(genericScopeView, "categoryListView");
390 var categoryListView = findChild(genericScopeView, "categoryListView");
391 tryCompare(categoryListView, "x", 0);
391 tryCompare(categoryListView, "x", 0);
392 tryCompare(testCase.subPageLoader, "visible", false);
392 tryCompare(testCase.subPageLoader, "visible", false);
393+ tryCompare(testCase.subPageLoader, "source", "");
393 }
394 }
394
395
395 function test_header_style_data() {
396 function test_header_style_data() {