on xenial help sign in
Make sure we destroy the popups when the item goes away
ab45135Albert Astals Cid
qml/ApplicationMenus/MenuBar.qml+7
@@ -230,6 +230,13 @@ Item {
230 }
230 }
231 }
231 }
232 }
232 }
233+
234+ Component.onDestruction: {
235+ if (__popup) {
236+ __popup.destroy();
237+ __popup = null;
238+ }
239+ }
233 } // Item ( delegate )
240 } // Item ( delegate )
234 } // Repeater
241 } // Repeater
235 } // Row
242 } // Row
qml/ApplicationMenus/MenuPopup.qml+10−1
@@ -297,6 +297,8 @@ UbuntuShape {
297
297
298 width: MathUtils.clamp(implicitWidth, d.__minimumWidth, d.__maximumWidth)
298 width: MathUtils.clamp(implicitWidth, d.__minimumWidth, d.__maximumWidth)
299
299
300+ property Item popup: null
301+
300 action.onTriggered: {
302 action.onTriggered: {
301 submenuHoverTimer.stop();
303 submenuHoverTimer.stop();
302
304
@@ -351,6 +353,13 @@ UbuntuShape {
351 }
353 }
352 }
354 }
353 }
355 }
356+
357+ Component.onDestruction: {
358+ if (popup) {
359+ popup.destroy();
360+ popup = null;
361+ }
362+ }
354 }
363 }
355 }
364 }
356
365
@@ -373,7 +382,7 @@ UbuntuShape {
373 id: loader
382 id: loader
374 objectName: root.objectName + "-item" + __ownIndex
383 objectName: root.objectName + "-item" + __ownIndex
375
384
376− property Item popup: null
385+ readonly property var popup: item ? item.popup : null
377 property var __menuData: model
386 property var __menuData: model
378 property int __ownIndex: index
387 property int __ownIndex: index
379 property bool __isSeparator: model.isSeparator
388 property bool __isSeparator: model.isSeparator
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+25
@@ -339,6 +339,31 @@ Item {
339 }, true);
339 }, true);
340 }
340 }
341
341
342+ function test_stray_submenus() {
343+ menuBackend.modelData = appMenuData.generateTestData(3,4,1,0,"menu");
344+ var priv = findInvisibleChild(menuBar, "d");
345+
346+ var menuItem = findChild(menuBar, "menuBar-item0");
347+ menuItem.show();
348+ compare(priv.currentItem, menuItem, "CurrentItem should be set to item 0");
349+ compare(priv.currentItem.popupVisible, true, "Popup should be visible");
350+
351+ var actionItem = findChild(menuBar, "menuBar-item0-menu-item0-actionItem");
352+ mouseClick(actionItem);
353+
354+ actionItem = findChild(menuBar, "menuBar-item0-menu-item0-menu-item0-actionItem");
355+ mouseClick(actionItem);
356+
357+ actionItem = findChild(menuBar, "menuBar-item0-menu-item0-menu-item0-menu-item0-actionItem");
358+
359+ // There's one popup
360+ tryCompareFunction(function() { return findChildsByType(root, "MenuPopup").length; }, 3);
361+
362+ menuBackend.modelData = null;
363+
364+ tryCompareFunction(function() { return findChildsByType(root, "MenuPopup").length; }, 0);
365+ }
366+
342 function test_firstDisabled() {
367 function test_firstDisabled() {
343 var data = appMenuData.generateTestData(10,5,2,3);
368 var data = appMenuData.generateTestData(10,5,2,3);
344 data[0].submenu[1].submenu[0].rowData.sensitive = false;
369 data[0].submenu[1].submenu[0].rowData.sensitive = false;