QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
PopupPresenter.qml
1 import QtQuick 2.10
2 import QtQuick.Controls 2.3
3 
39 QtObject {
40  id: _popPresenter
41 
56  property Item rootItem: null
57 
72  readonly property bool empty: _popups.length == 0
73 
75  property var _popups: []
76 
86  function presentPopup(popup) {
87  popup.parent = rootItem;
88  popup.closed.connect(function() {
89  var index = _popups.indexOf(popup);
90  if(index > -1) {
91  popup.destroy();
92  _popups.splice(index, 1);
93  }
94  });
95  _popups.push(popup);
96  popup.open();
97  return true;
98  }
99 
109  function closeAction() {
110  if(_popups.length > 0) {
111  if(typeof _popups[_popups.length - 1].closeAction == "function") {
112  if(_popups[_popups.length - 1].closeAction())
113  return true;
114  }
115  _popups[_popups.length - 1].close();
116  return true;
117  } else
118  return false;
119  }
120 }