@@ -3,11 +3,69 @@ import QtQuick.Controls 2.3
33import de.skycoder42.QtMvvm.Core 1.0
44import de.skycoder42.QtMvvm.Quick 1.0
55
6+ /*! @brief A presentation helper that can present generic mvvm dialogs
7+ *
8+ * @extends QtQml.QtObject
9+ *
10+ * @details You can use this class as presenter for dialogs in case you create your own root
11+ * presenter instead of using the QtMvvmApp. This partial presenter can handle simple dialogs
12+ * (the ones shown via QtMvvm::CoreApp::showDialog). Use it as follows:
13+ *
14+ * @code{.qml}
15+ * MyPresenter {
16+ * id: _root
17+ *
18+ * DialogPresenter {
19+ * id: _rootDialogs
20+ * rootItem: _root.contentItem
21+ * }
22+ *
23+ * function showDialog(config, result) {
24+ * return _rootDialogs.showDialog(config, result);
25+ * }
26+ *
27+ * function closeAction() {
28+ * var closed = false;
29+ * // ...
30+ * if(!closed)
31+ * closed = _rootDialogs.closeAction();
32+ * // ...
33+ * return closed;
34+ * }
35+ * }
36+ * @endcode
37+ *
38+ * @sa QtMvvmApp
39+ */
640QtObject {
741 id: _dialogPresenter
842
43+ /* ! @brief The root item to present dialogs to
44+ *
45+ * @default{`null`}
46+ *
47+ * This propety **must** be set in order for the presenter to work. It will create new
48+ * dialogs with that item as parent, which decides in which relative are they are
49+ * displayed. Unless you want to explicitly reposition dialogs, this should always be the
50+ * root item of the root component of your application.
51+ *
52+ * @accessors{
53+ * @memberAc{rootItem}
54+ * @notifyAc{rootItemChanged()}
55+ * }
56+ */
957 property Item rootItem: null
1058
59+ /* ! @brief The primary presenting method to present a dialog
60+ *
61+ * @param type:MessageConfig config The message configuration to create a dialog of
62+ * @param type:MessageResult result The result to report the dialog result to
63+ * @return type:bool `true` if successfully presented, `false` if not
64+ *
65+ * Use this method in your main presenter to present dialogs via this sub presenter.
66+ *
67+ * @sa QtMvvm::MessageConfig, QtMvvm::MessageResult, QtMvvmApp::showDialog
68+ */
1169 function showDialog (config , result ) {
1270 if (config .type == " msgbox" )
1371 return createMsgBox (config, result)
@@ -19,6 +77,15 @@ QtObject {
1977 return false ;
2078 }
2179
80+ /* ! @brief Can be called to try to close open dialogs
81+ *
82+ * @return type:bool `true` if a dialog was closed, `false` if not
83+ *
84+ * Use this method in your main presenter react on a close event. It will close the
85+ * latest top level dialog, if one is present.
86+ *
87+ * @sa QtMvvmApp::closeAction
88+ */
2289 function closeAction () {
2390 if (_popups .length > 0 ) {
2491 _popups[_popups .length - 1 ].reject ();
@@ -27,7 +94,9 @@ QtObject {
2794 return false ;
2895 }
2996
97+ // ! Internal property
3098 property var _popups: []
99+ // ! Internal property
31100 property Component _msgBoxComponent: MsgBox {
32101 id: __msgBox
33102
@@ -45,6 +114,7 @@ QtObject {
45114 }
46115 }
47116
117+ // ! Internal property
48118 property Component _inputComponent: InputDialog {
49119 id: __input
50120
@@ -62,6 +132,7 @@ QtObject {
62132 }
63133 }
64134
135+ // ! Internal property
65136 property Component _fileComponent: FileDialog {
66137 id: __file
67138
@@ -79,6 +150,7 @@ QtObject {
79150 }
80151 }
81152
153+ // ! Internal property
82154 property Component _folderComponent: FolderDialog {
83155 id: __folder
84156
@@ -96,6 +168,18 @@ QtObject {
96168 }
97169 }
98170
171+ /* ! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeMessageBox
172+ *
173+ * @param type:MessageConfig config The message configuration to create a dialog of
174+ * @param type:MessageResult result The result to report the dialog result to
175+ * @return type:bool `true` if successfully presented, `false` if not
176+ *
177+ * Used by the showDialog() method to show a dialog of the message box type. You can use
178+ * it yourself if you want to extend the presenter and still keep the default dialogs it
179+ * supports.
180+ *
181+ * @sa DialogPresenter::showDialog
182+ */
99183 function createMsgBox (config , result ) {
100184 var props = config .viewProperties ;
101185 props[" msgConfig" ] = config;
@@ -104,6 +188,18 @@ QtObject {
104188 return incubator .status !== Component .Error ;
105189 }
106190
191+ /* ! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeInputDialog
192+ *
193+ * @param type:MessageConfig config The message configuration to create a dialog of
194+ * @param type:MessageResult result The result to report the dialog result to
195+ * @return type:bool `true` if successfully presented, `false` if not
196+ *
197+ * Used by the showDialog() method to show a dialog of the input dialog type. You can use
198+ * it yourself if you want to extend the presenter and still keep the default dialogs it
199+ * supports.
200+ *
201+ * @sa DialogPresenter::showDialog
202+ */
107203 function createInput (config , result ) {
108204 var props = config .viewProperties ;
109205 props[" msgConfig" ] = config;
@@ -112,6 +208,18 @@ QtObject {
112208 return incubator .status !== Component .Error ;
113209 }
114210
211+ /* ! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeFileDialog
212+ *
213+ * @param type:MessageConfig config The message configuration to create a dialog of
214+ * @param type:MessageResult result The result to report the dialog result to
215+ * @return type:bool `true` if successfully presented, `false` if not
216+ *
217+ * Used by the showDialog() method to show a dialog of the file dialog type. You can use
218+ * it yourself if you want to extend the presenter and still keep the default dialogs it
219+ * supports.
220+ *
221+ * @sa DialogPresenter::showDialog
222+ */
115223 function createFile (config , result ) {
116224 var props = config .viewProperties ;
117225 props[" msgConfig" ] = config;
0 commit comments