on xenial help sign in
MenuItemFactory: Add subtitle support to SwitchItem widget

Approved by: Marco Trevisan (Treviño), Michał Sawicz, Unity8 CI Bot

commit2143b4e858e463bea55d3c5cff17dbdb1a72f575 authorPete Woods <pete.woods@canonical.com> dateWed 7 Dec 2016, 13:47 (10 years ago) parent800ba87683d23b
2 files changed+28−2
qml/Panel/Indicators/MenuItemFactory.qml+22−1 tests/qmltests/Panel/Indicators/tst_MenuItemFactory.qml+6−1
qml/Panel/Indicators/MenuItemFactory.qml+22−1
@@ -106,7 +106,7 @@ Item {
106106 }
107107
108108 if (component === undefined) {
109− console.debug("Don't know how to make " + modelData.type + " for " + indicator);
109+ console.debug("Don't know how to make " + type + " for " + indicator);
110110 }
111111
112112 return component
@@ -398,7 +398,9 @@ Item {
398398 id: switchItem
399399 objectName: "switchMenu"
400400 property QtObject menuData: null
401+ property var menuModel: menuFactory.menuModel
401402 property int menuIndex: -1
403+ property var extendedData: menuData && menuData.ext || undefined
402404 property bool serverChecked: menuData && menuData.isToggled || false
403405
404406 text: menuData && menuData.label || ""
@@ -407,6 +409,25 @@ Item {
407409 checked: serverChecked
408410 highlightWhenPressed: false
409411
412+ property var subtitleAction: UnityMenuAction {
413+ model: menuModel
414+ index: menuIndex
415+ name: getExtendedProperty(extendedData, "xCanonicalSubtitleAction", "")
416+ }
417+ subtitle.text: subtitleAction.valid ? subtitleAction.state : ""
418+
419+ onMenuModelChanged: {
420+ loadAttributes();
421+ }
422+ onMenuIndexChanged: {
423+ loadAttributes();
424+ }
425+
426+ function loadAttributes() {
427+ if (!menuModel || menuIndex == -1) return;
428+ menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-subtitle-action': 'string'});
429+ }
430+
410431 ServerPropertySynchroniser {
411432 objectName: "sync"
412433 syncTimeout: Utils.Constants.indicatorValueTimeout
tests/qmltests/Panel/Indicators/tst_MenuItemFactory.qml+6−1
@@ -370,7 +370,8 @@ Item {
370370 function test_create_switchMenu_data() {
371371 return [
372372 {label: "testLabel1", enabled: true, checked: false, icon: "file:///testIcon1" },
373− {label: "testLabel2", enabled: false, checked: true, icon: "file:///testIcon2" },
373+ {label: "testLabel2", enabled: false, checked: true, icon: "file:///testIcon2", subtitleAction: "action::subtitle1" },
374+ {label: "testLabel2", enabled: false, checked: true, icon: "file:///testIcon3", subtitleAction: "action::subtitle2" },
374375 ];
375376 }
376377
@@ -380,6 +381,9 @@ Item {
380381 menuData.sensitive = data.enabled;
381382 menuData.icon = data.icon;
382383 menuData.isToggled = data.checked;
384+ menuData.ext = {
385+ 'xCanonicalSubtitleAction': data.subtitleAction,
386+ };
383387
384388 loader.data = menuData;
385389 loader.sourceComponent = factory.load(menuData);
@@ -390,6 +394,7 @@ Item {
390394 compare(loader.item.iconSource, data.icon, "Icon does not match data");
391395 compare(loader.item.checked, data.checked, "Checked does not match data");
392396 compare(loader.item.enabled, data.enabled, "Enabled does not match data");
397+ compare(loader.item.subtitleAction.name, data.subtitleAction === undefined ? "" : data.subtitleAction, "Subtitle action does not match data");
393398 }
394399
395400 function test_create_alarmMenu_data() {