on xenial help sign in
MenuItemFactory: prevent infinite loops on model activation causing calendar day changes

Propagate the selected date changes only if the calendar is visible, and avoid to update the model info when selected date changes because we've just received a new calendar-day from the backend, or we'll have an endless ping-pong between UI and backend. This is because calendarDay changes happens when both selection changes and when the calendar is opened.

commit22568dd0a90c51b94539c5d5abcdd9ac19e59f1d authorMarco Trevisan (Treviño) <mail@3v1n0.net> dateFri 11 Nov 2016, 03:47 (10 years ago) parent9ccea1d
1 file changed+19−6
qml/Panel/Indicators/MenuItemFactory.qml+19−6
qml/Panel/Indicators/MenuItemFactory.qml+19−6
@@ -505,25 +505,38 @@ Item {
505505 id: calendarMenu
506506
507507 Menus.CalendarMenu {
508+ id: calendarItem
508509 objectName: "calendarMenu"
509510 focus: true
510511
511512 property QtObject menuData: null
512513 property var menuModel: menuFactory.menuModel
513514 property var actionState: menuData && menuData.actionState || null
514− property int calendarDay: getExtendedProperty(actionState, "calendar-day", 0) * 1000
515+ property real calendarDay: getExtendedProperty(actionState, "calendar-day", 0)
515516 property int menuIndex: -1
516517
517518 showWeekNumbers: getExtendedProperty(actionState, "show-week-numbers", false)
518519 eventDays: getExtendedProperty(actionState, "appointment-days", [])
519520
520− Binding on currentDate {
521− when: calendarDay > 0
522− value: new Date(calendarDay)
521+ onCalendarDayChanged: {
522+ if (calendarDay > 0) {
523+ // This would trigger a selectionDateChanged signal, thus
524+ // we've to avoid that the subsequent model activation
525+ // would cause an infinite loop
526+ modelUpdateConnections.enabled = false
527+ currentDate = new Date(calendarDay * 1000)
528+ modelUpdateConnections.enabled = true
529+ }
523530 }
524531
525− onSelectedDateChanged: {
526− menuModel.activate(menuIndex, selectedDate.getTime() / 1000 | 0)
532+ Connections {
533+ id: modelUpdateConnections
534+ property bool enabled: true
535+ target: (enabled && calendarItem.visible) ? calendarItem : null
536+
537+ onSelectedDateChanged: {
538+ menuModel.activate(menuIndex, selectedDate.getTime() / 1000 | 0)
539+ }
527540 }
528541 }
529542 }