on xenial help sign in
Merge lp:~cimi/unity8/scope-settings
commit4b6ce0495dcfc8e9effaf081c09bf33056d3c6af authorMichał Sawicz <michal.sawicz@canonical.com> dateTue 26 Aug 2014, 20:42 (12 years ago) parentf7cdbb25a0ce70
17 files changed+71−53
qml/Dash/GenericScopeView.qml+14−12 qml/Dash/PageHeader.qml+3−10 qml/Dash/ScopeSettings/ScopeSetting.qml+3−2 qml/Dash/ScopeSettings/ScopeSettingBoolean.qml+6−5 qml/Dash/ScopeSettings/ScopeSettingList.qml+12−1 qml/Dash/ScopeSettings/ScopeSettingString.qml+4−3 qml/Dash/ScopeSettings/ScopeSettingsWidgetFactory.qml+4−3 qml/Dash/ScopeSettingsPage.qml+1−1 tests/mocks/Unity/fake_settingsmodel.cpp+1−2 tests/mocks/Unity/fake_unity_plugin.cpp+1−1 tests/qmltests/Dash/Previews/tst_PreviewWidgetFactory.qml+1−1 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingBoolean.qml+1−1 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingList.qml+11−3 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingNumber.qml+3−3 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingString.qml+2−2 tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingsWidgetFactory.qml+2−2 tests/qmltests/Dash/tst_GenericScopeView.qml+2−1
qml/Dash/GenericScopeView.qml+14−12
@@ -482,24 +482,26 @@ FocusScope {
482482 open = false;
483483 }
484484
485− source: subPage && (subPage == "preview" ? "PreviewListView.qml" : "ScopeSettingsPage.qml") || ""
485+ source: switch(subPage) {
486+ case "preview": return "PreviewListView.qml";
487+ case "settings": return "ScopeSettingsPage.qml";
488+ default: return "";
489+ }
486490
487491 onLoaded: {
488− if (status === Loader.Ready) {
489− item.scope = Qt.binding(function() { return subPageLoader.scope } )
490− item.scopeStyle = Qt.binding(function() { return subPageLoader.scopeStyle } )
491− if (subPage == "preview") {
492− item.open = Qt.binding(function() { return subPageLoader.open } )
493− item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex } )
494− item.model = Qt.binding(function() { return subPageLoader.model } )
495− }
496− open = true;
492+ item.scope = Qt.binding(function() { return subPageLoader.scope; } )
493+ item.scopeStyle = Qt.binding(function() { return subPageLoader.scopeStyle; } )
494+ if (subPage == "preview") {
495+ item.open = Qt.binding(function() { return subPageLoader.open; } )
496+ item.initialIndex = Qt.binding(function() { return subPageLoader.initialIndex; } )
497+ item.model = Qt.binding(function() { return subPageLoader.model; } )
497498 }
499+ open = true;
498500 }
499501
500− onOpenChanged: pageHeaderLoader.item.unfocus();
502+ onOpenChanged: pageHeaderLoader.item.unfocus()
501503
502− onVisibleChanged: if (!visible) subPage = "";
504+ onVisibleChanged: if (!visible) subPage = ""
503505
504506 Connections {
505507 target: subPageLoader.item
qml/Dash/PageHeader.qml+3−10
@@ -249,9 +249,7 @@ Item {
249249 backAction: Action {
250250 iconName: "back"
251251 visible: root.showBackButton
252− onTriggered: {
253− root.backClicked();
254− }
252+ onTriggered: root.backClicked()
255253 }
256254
257255 actions: [
@@ -270,20 +268,15 @@ Item {
270268 text: i18n.tr("Settings")
271269 iconName: "settings"
272270 visible: root.settingsEnabled
273− onTriggered: {
274− root.settingsClicked()
275− }
271+ onTriggered: root.settingsClicked()
276272 },
277273 Action {
278274 objectName: "favorite"
279275 text: root.favorite ? i18n.tr("Remove from Favorites") : i18n.tr("Add to Favorites")
280276 iconName: root.favorite ? "starred" : "non-starred"
281277 visible: root.favoriteEnabled
282− onTriggered: {
283− root.favoriteClicked()
284− }
278+ onTriggered: root.favoriteClicked()
285279 }
286−
287280 ]
288281 }
289282
qml/Dash/ScopeSettings/ScopeSetting.qml+3−2
@@ -26,11 +26,12 @@ Item {
2626 //! Variable used to contain widget's data
2727 property var widgetData: null
2828
29− readonly property real __margins: units.gu(2)
30−
3129 /*! \brief This signal should be emitted when a setting action was updated.
3230 *
3331 * \param value the new setting value.
3432 */
3533 signal updated(var value)
34+
35+ //! \internal
36+ readonly property real settingMargins: units.gu(2)
3637}
qml/Dash/ScopeSettings/ScopeSettingBoolean.qml+6−5
@@ -26,21 +26,22 @@ ScopeSetting {
2626 id: listItem
2727
2828 onClicked: {
29− control.checked = !control.checked
30− updated(control.checked)
29+ control.checked = !control.checked;
30+ updated(control.checked);
3131 }
3232
3333 Label {
3434 anchors {
3535 left: parent.left
36− leftMargin: __margins
36+ leftMargin: settingMargins
3737 right: control.left
3838 rightMargin: units.gu(1)
3939 verticalCenter: parent.verticalCenter
4040 }
4141 text: widgetData.displayName
4242 elide: Text.ElideMiddle
43− maximumLineCount: 1
43+ maximumLineCount: 2
44+ wrapMode: Text.Wrap
4445 color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
4546 }
4647
@@ -49,7 +50,7 @@ ScopeSetting {
4950 objectName: "control"
5051 anchors {
5152 right: parent.right
52− rightMargin: __margins
53+ rightMargin: settingMargins
5354 verticalCenter: parent.verticalCenter
5455 }
5556 checked: widgetData.value
qml/Dash/ScopeSettings/ScopeSettingList.qml+12−1
@@ -24,6 +24,8 @@ ScopeSetting {
2424 // FIXME workaround for: https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1355830
2525 height: listItem.currentlyExpanded ? listItem.itemHeight * widgetData.properties["values"].length + units.gu(6) : listItem.height
2626
27+ property int initialValue: -1
28+
2729 ListItem.ItemSelector {
2830 id: listItem
2931 objectName: "control"
@@ -34,6 +36,15 @@ ScopeSetting {
3436 text: widgetData.displayName
3537 model: widgetData.properties["values"]
3638
37− onSelectedIndexChanged: root.updated(selectedIndex)
39+ onSelectedIndexChanged: {
40+ if (root.initialValue >= 0) {
41+ var tmpValue = root.initialValue;
42+ root.initialValue = -1;
43+ selectedIndex = tmpValue;
44+ return;
45+ }
46+
47+ root.updated(selectedIndex);
48+ }
3849 }
3950}
qml/Dash/ScopeSettings/ScopeSettingString.qml+4−3
@@ -35,14 +35,15 @@ ScopeSetting {
3535 id: label
3636 anchors {
3737 left: parent.left
38− leftMargin: __margins
38+ leftMargin: settingMargins
3939 right: control.left
4040 rightMargin: units.gu(1)
4141 verticalCenter: parent.verticalCenter
4242 }
4343 text: widgetData.displayName
4444 elide: Text.ElideMiddle
45− maximumLineCount: 1
45+ maximumLineCount: 2
46+ wrapMode: Text.Wrap
4647 color: scopeStyle ? scopeStyle.foreground : Theme.palette.normal.baseText
4748 }
4849
@@ -51,7 +52,7 @@ ScopeSetting {
5152 objectName: "control"
5253 anchors {
5354 right: parent.right
54− rightMargin: __margins
55+ rightMargin: settingMargins
5556 verticalCenter: parent.verticalCenter
5657 }
5758 width: root.mode == "number" ? units.gu(8) : units.gu(12)
qml/Dash/ScopeSettings/ScopeSettingsWidgetFactory.qml+4−3
@@ -45,12 +45,13 @@ Loader {
4545 //! \endcond
4646
4747 onLoaded: {
48− item.widgetData = Qt.binding(function() { return root.widgetData } )
49− item.scopeStyle = Qt.binding(function() { return root.scopeStyle } )
48+ if (item.hasOwnProperty("initialValue")) item.initialValue = root.widgetData.value;
49+ item.widgetData = Qt.binding(function() { return root.widgetData; } )
50+ item.scopeStyle = Qt.binding(function() { return root.scopeStyle; } )
5051 }
5152
5253 Connections {
5354 target: root.item
54− onUpdated: root.updated(value)
55+ onUpdated: if (value !== widgetData.value) root.updated(value)
5556 }
5657}
qml/Dash/ScopeSettingsPage.qml+1−1
@@ -34,7 +34,7 @@ Item {
3434 width: parent.width
3535 title: scope ? scope.name : ""
3636 showBackButton: true
37− scopeStyle: root.scopeStyle || undefined
37+ scopeStyle: root.scopeStyle
3838
3939 onBackClicked: root.backClicked()
4040 }
tests/mocks/Unity/fake_settingsmodel.cpp+1−2
@@ -69,8 +69,7 @@ QVariant SettingsModel::data(const QModelIndex& index, int role) const {
6969 return result;
7070}
7171
72−bool SettingsModel::setData(const QModelIndex &index, const QVariant &value,
73− int role) {
72+bool SettingsModel::setData(const QModelIndex &index, const QVariant &value, int role) {
7473 int row = index.row();
7574 if (row < m_data.size()) {
7675 switch (role) {
tests/mocks/Unity/fake_unity_plugin.cpp+1−1
@@ -44,7 +44,7 @@ void FakeUnityPlugin::registerTypes(const char *uri)
4444 qmlRegisterType<Scopes>(uri, 0, 2, "Scopes");
4545 qmlRegisterType<Scope>(uri, 0, 2, "MockScope");
4646 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.");
4848 qmlRegisterUncreatableType<unity::shell::scopes::NavigationInterface>(uri, 0, 2, "Navigation", "Can't create Navigation object in QML.");
4949 qmlRegisterUncreatableType<unity::shell::scopes::CategoriesInterface>(uri, 0, 2, "Categories", "Can't create Categories object in QML.");
5050 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 {
9393 factory.widgetData = { type: data.type };
9494 factory.widgetType = data.type;
9595
96− verify(("" + factory.source).indexOf(data.source) != -1);
96+ verify((String(factory.source)).indexOf(data.source) != -1);
9797 }
9898 }
9999}
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingBoolean.qml+1−1
@@ -44,7 +44,7 @@ Rectangle {
4444
4545 UT.UnityTestCase {
4646 id: testCase
47− name: "ScopeSettingBooleanTest"
47+ name: "ScopeSettingBoolean"
4848 when: windowShown
4949
5050 function test_updated() {
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingList.qml+11−3
@@ -32,8 +32,8 @@ Rectangle {
3232
3333 ScopeSettingList {
3434 id: scopeSetting
35− widgetData: settingData
3635 width: parent.width
36+ widgetData: settingData
3737 }
3838
3939 SignalSpy {
@@ -44,16 +44,24 @@ Rectangle {
4444
4545 UT.UnityTestCase {
4646 id: testCase
47− name: "ScopeSettingListTest"
47+ name: "ScopeSettingList"
4848 when: windowShown
4949
5050 property var control: findChild(scopeSetting, "control")
5151
52− function init() {
52+ function cleanup() {
5353 control.selectedIndex = 0;
5454 spy.clear();
5555 }
5656
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+
5765 function test_updated_data() {
5866 return [
5967 { tag: "current", index: 0, updated: false },
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingNumber.qml+3−3
@@ -44,13 +44,13 @@ Rectangle {
4444
4545 UT.UnityTestCase {
4646 id: testCase
47− name: "ScopeSettingNumberTest"
47+ name: "ScopeSettingNumber"
4848 when: windowShown
4949
5050 property var control: findChild(scopeSetting, "control")
5151 property real newNumber: 11.7
5252
53− function init() {
53+ function cleanup() {
5454 control.focus = false;
5555 control.text = settingData.value;
5656 spy.clear();
@@ -85,7 +85,7 @@ Rectangle {
8585 verify(control.displayText == newNumber);
8686 }
8787
88− function test_unacceptableInput() {
88+ function test_unacceptable_input() {
8989 mouseClick(control, control.width / 2, control.height / 2);
9090 control.selectAll();
9191 control.cut();
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingString.qml+2−2
@@ -44,13 +44,13 @@ Rectangle {
4444
4545 UT.UnityTestCase {
4646 id: testCase
47− name: "ScopeSettingStringTest"
47+ name: "ScopeSettingString"
4848 when: windowShown
4949
5050 property var control: findChild(scopeSetting, "control")
5151 property string newText: "new text to compare"
5252
53− function init() {
53+ function cleanup() {
5454 control.focus = false;
5555 control.text = settingData.value;
5656 spy.clear();
tests/qmltests/Dash/ScopeSettings/tst_ScopeSettingsWidgetFactory.qml+2−2
@@ -42,7 +42,7 @@ Rectangle {
4242
4343 UT.UnityTestCase {
4444 id: testCase
45− name: "ScopeSettingWidgetFactoryTest"
45+ name: "ScopeSettingWidgetFactory"
4646 when: windowShown
4747
4848 function test_mapping_data() {
@@ -59,7 +59,7 @@ Rectangle {
5959 newSettingData.type = data.type;
6060 scopeSettingsWidgetFactory.widgetData = newSettingData;
6161
62− verify(("" + scopeSettingsWidgetFactory.source).indexOf(data.source) != -1);
62+ verify((String(scopeSettingsWidgetFactory.source)).indexOf(data.source) != -1);
6363 }
6464 }
6565}
tests/qmltests/Dash/tst_GenericScopeView.qml+2−1
@@ -377,7 +377,7 @@ Item {
377377 var settings = findChild(innerHeader, "settings_header_button");
378378 mouseClick(settings, settings.width / 2, settings.height / 2);
379379 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);
381381 tryCompare(genericScopeView, "subPageShown", true);
382382 compare(testCase.subPageLoader.subPage, "settings");
383383 tryCompare(testCase.subPageLoader, "x", 0);
@@ -390,6 +390,7 @@ Item {
390390 var categoryListView = findChild(genericScopeView, "categoryListView");
391391 tryCompare(categoryListView, "x", 0);
392392 tryCompare(testCase.subPageLoader, "visible", false);
393+ tryCompare(testCase.subPageLoader, "source", "");
393394 }
394395
395396 function test_header_style_data() {