on xenial help sign in
MenuItemFactory: use Menus.RadioMenu and Menus.ButtonMenu
commit28d1c5ce9a2814ee16e1c77dd3f74bacf896e66c authorBileto Bot <ci-train-bot@canonical.com> dateWed 16 Nov 2016, 10:44 (10 years ago) parent0917e08b696b80
3 files changed+64−15
debian/changelog+2 qml/Panel/Indicators/MenuItemFactory.qml+36−10 tests/qmltests/Panel/Indicators/tst_MenuItemFactory.qml+26−5
debian/changelog+2
@@ -5,6 +5,8 @@ unity8 (8.15) UNRELEASED; urgency=medium
55 Adds support for showing the calendar at the requested date, marking days
66 with events properly and toggling the visibility of the week number.
77
8+ * MenuItemFactory: use Menus.RadioMenu and Menus.ButtonMenu
9+
810 * Bump version as USC breaks with unity8 << 8.14
911
1012 -- Marco Trevisan (Treviño) <marco@ubuntu.com> Thu, 27 Oct 2016 14:03:03 +0200
qml/Panel/Indicators/MenuItemFactory.qml+36−10
@@ -362,6 +362,35 @@ Item {
362362 }
363363 }
364364
365+ Component {
366+ id: radioMenu;
367+
368+ Menus.RadioMenu {
369+ id: radioItem
370+ objectName: "radioMenu"
371+ property QtObject menuData: null
372+ property int menuIndex: -1
373+ property bool serverChecked: menuData && menuData.isToggled || false
374+
375+ text: menuData && menuData.label || ""
376+ enabled: menuData && menuData.sensitive || false
377+ checked: serverChecked
378+ highlightWhenPressed: false
379+
380+ ServerPropertySynchroniser {
381+ objectName: "sync"
382+ syncTimeout: Utils.Constants.indicatorValueTimeout
383+
384+ serverTarget: radioItem
385+ serverProperty: "serverChecked"
386+ userTarget: radioItem
387+ userProperty: "checked"
388+
389+ onSyncTriggered: menuModel.activate(radioItem.menuIndex)
390+ }
391+ }
392+ }
393+
365394 Component {
366395 id: switchMenu;
367396
@@ -1003,7 +1032,7 @@ Item {
10031032 Component {
10041033 id: buttonSectionMenu;
10051034
1006− Menus.StandardMenu {
1035+ Menus.ButtonMenu {
10071036 objectName: "buttonSectionMenu"
10081037 property QtObject menuData: null
10091038 property var menuModel: menuFactory.menuModel
@@ -1015,6 +1044,7 @@ Item {
10151044 highlightWhenPressed: false
10161045 text: menuData && menuData.label || ""
10171046 foregroundColor: theme.palette.normal.backgroundText
1047+ buttonText: getExtendedProperty(extendedData, "xCanonicalExtraLabel", "")
10181048
10191049 onMenuModelChanged: {
10201050 loadAttributes();
@@ -1027,14 +1057,7 @@ Item {
10271057 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-extra-label': 'string'});
10281058 }
10291059
1030− slots: Button {
1031− objectName: "buttonSectionMenuControl"
1032− text: getExtendedProperty(extendedData, "xCanonicalExtraLabel", "")
1033−
1034− onClicked: {
1035− menuModel.activate(menuIndex);
1036− }
1037− }
1060+ onButtonClicked: menuModel.activate(menuIndex);
10381061 }
10391062 }
10401063
@@ -1053,9 +1076,12 @@ Item {
10531076 return component;
10541077 }
10551078
1056− if (modelData.isCheck || modelData.isRadio) {
1079+ if (modelData.isCheck) {
10571080 return checkableMenu;
10581081 }
1082+ if (modelData.isRadio) {
1083+ return radioMenu;
1084+ }
10591085 if (modelData.isSeparator) {
10601086 return separatorMenu;
10611087 }
tests/qmltests/Panel/Indicators/tst_MenuItemFactory.qml+26−5
@@ -144,13 +144,12 @@ Item {
144144 }
145145
146146 function test_create_radio() {
147− skip("No radio component");
148147 menuData.isRadio = true;
149148
150149 loader.data = menuData;
151150 loader.sourceComponent = factory.load(menuData);
152151 tryCompareFunction(function() { return loader.item != undefined; }, true);
153− compare(loader.item.objectName, "checkableMenu", "Should have created a checkable menu");
152+ compare(loader.item.objectName, "radioMenu", "Should have created a radio menu");
154153 }
155154
156155 function test_create_separator() {
@@ -344,6 +343,30 @@ Item {
344343 compare(loader.item.enabled, data.enabled, "Enabled does not match data");
345344 }
346345
346+ function test_create_radioMenu_data() {
347+ return [
348+ {label: "testLabel1", enabled: true, checked: false },
349+ {label: "testLabel2", enabled: false, checked: true },
350+ ];
351+ }
352+
353+ function test_create_radioMenu(data) {
354+ menuData.type = "";
355+ menuData.label = data.label;
356+ menuData.sensitive = data.enabled;
357+ menuData.isRadio = true;
358+ menuData.isToggled = data.checked;
359+
360+ loader.data = menuData;
361+ loader.sourceComponent = factory.load(menuData);
362+ tryCompareFunction(function() { return loader.item != undefined; }, true);
363+ compare(loader.item.objectName, "radioMenu", "Should have created a radio menu");
364+
365+ compare(loader.item.text, data.label, "Label does not match data");
366+ compare(loader.item.checked, data.checked, "Checked does not match data");
367+ compare(loader.item.enabled, data.enabled, "Enabled does not match data");
368+ }
369+
347370 function test_create_switchMenu_data() {
348371 return [
349372 {label: "testLabel1", enabled: true, checked: false, icon: "file:///testIcon1" },
@@ -537,9 +560,7 @@ Item {
537560 compare(loader.item.iconSource, data.icon, "Icon does not match data");
538561 compare(loader.item.enabled, data.enabled, "Enabled does not match data");
539562
540− var button = findChild(loader.item, "buttonSectionMenuControl");
541− verify(button !== null);
542− compare(button.text, data.buttonText, "Button text does not match data");
563+ compare(loader.item.buttonText, data.buttonText, "Button text does not match data");
543564 }
544565
545566 function test_create_wifiSection_data() {