QtMvvm  1.0.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
DialogPresenter.qml
1 import QtQuick 2.10
2 import QtQuick.Controls 2.3
3 import de.skycoder42.QtMvvm.Core 1.0
4 import de.skycoder42.QtMvvm.Quick 1.0
5 
40 QtObject {
41  id: _dialogPresenter
42 
57  property Item rootItem: null
58 
69  function showDialog(config, result) {
70  if(config.type == "msgbox")
71  return createMsgBox(config, result)
72  else if(config.type == "input")
73  return createInput(config, result)
74  else if(config.type == "file")
75  return createFile(config, result)
76  else
77  return false;
78  }
79 
89  function closeAction() {
90  if(_popups.length > 0) {
91  _popups[_popups.length - 1].reject();
92  return true;
93  } else
94  return false;
95  }
96 
98  property var _popups: []
100  property Component _msgBoxComponent: MsgBox {
101  id: __msgBox
102 
103  onClosed: {
104  var index = _popups.indexOf(__msgBox);
105  if(index > -1) {
106  __msgBox.destroy();
107  _dialogPresenter._popups.splice(index, 1);
108  }
109  }
110 
111  Component.onCompleted: {
112  _popups.push(__msgBox)
113  __msgBox.open()
114  }
115  }
116 
118  property Component _inputComponent: InputDialog {
119  id: __input
120 
121  onClosed: {
122  var index = _popups.indexOf(__input);
123  if(index > -1) {
124  __input.destroy();
125  _dialogPresenter._popups.splice(index, 1);
126  }
127  }
128 
129  Component.onCompleted: {
130  _popups.push(__input)
131  __input.open()
132  }
133  }
134 
136  property Component _fileComponent: FileDialog {
137  id: __file
138 
139  onClosed: {
140  var index = _popups.indexOf(__file);
141  if(index > -1) {
142  __file.destroy();
143  _dialogPresenter._popups.splice(index, 1);
144  }
145  }
146 
147  Component.onCompleted: {
148  _popups.push(__file)
149  __file.open()
150  }
151  }
152 
154  property Component _folderComponent: FolderDialog {
155  id: __folder
156 
157  onClosed: {
158  var index = _popups.indexOf(__folder);
159  if(index > -1) {
160  __folder.destroy();
161  _dialogPresenter._popups.splice(index, 1);
162  }
163  }
164 
165  Component.onCompleted: {
166  _popups.push(__folder)
167  __folder.open()
168  }
169  }
170 
183  function createMsgBox(config, result) {
184  var props = config.viewProperties;
185  props["msgConfig"] = config;
186  props["msgResult"] = result;
187  var incubator = _msgBoxComponent.incubateObject(rootItem, props);
188  return incubator.status !== Component.Error;
189  }
190 
203  function createInput(config, result) {
204  var props = config.viewProperties;
205  props["msgConfig"] = config;
206  props["msgResult"] = result;
207  var incubator = _inputComponent.incubateObject(rootItem, props);
208  return incubator.status !== Component.Error;
209  }
210 
223  function createFile(config, result) {
224  var props = config.viewProperties;
225  props["msgConfig"] = config;
226  props["msgResult"] = result;
227  var incubator = null;
228  if(config.subType == "folder")
229  incubator = _folderComponent.incubateObject(rootItem, props);
230  else
231  incubator = _fileComponent.incubateObject(rootItem, props);
232  return incubator.status !== Component.Error;
233  }
234 }
The QML import for the QtMvvmCore QML module.
The QML import for the QtMvvmQuick QML module.
Definition: ActionButton.qml:4
void open()
Opens the file chooser by sending the show intent.
A folder dialog implementation based on the labs folder dialog.
A file dialog implementation based on the labs file dialog.
Definition: FileDialog.qml:18