Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit bd75e15

Browse files
committed
refactor qml version files
1 parent 93a620b commit bd75e15

8 files changed

+126
-76
lines changed

src/imports/mvvmquick/DialogPresenter.qml

+87-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import QtQuick 2.10
22
import QtQuick.Controls 2.3
3-
import de.skycoder42.QtMvvm.Core 1.0
4-
import de.skycoder42.QtMvvm.Quick 1.0
3+
import de.skycoder42.QtMvvm.Core 1.1
4+
import de.skycoder42.QtMvvm.Quick 1.1
55

66
/*! @brief A presentation helper that can present generic mvvm dialogs
77
*
@@ -56,6 +56,22 @@ QtObject {
5656
*/
5757
property Item rootItem: null
5858

59+
/*! @brief Checks if the presenter has no open dialogs
60+
*
61+
* @default{`false`}
62+
*
63+
* As soon as there is at least a single open dialog, this property gets false. Only when
64+
* no dialogs are show is it true. This property is always updated from within the
65+
* closeAction() method, so you can be shure that it is true after the last dialog was
66+
* closed that way.
67+
*
68+
* @accessors{
69+
* @memberAc{empty}
70+
* @notifyAc{emptyChanged()}
71+
* }
72+
*/
73+
readonly property bool empty: _popups.length == 0
74+
5975
/*! @brief The primary presenting method to present a dialog
6076
*
6177
* @param type:MessageConfig config The message configuration to create a dialog of
@@ -67,12 +83,16 @@ QtObject {
6783
* @sa QtMvvm::MessageConfig, QtMvvm::MessageResult, QtMvvmApp::showDialog
6884
*/
6985
function showDialog(config, result) {
70-
if(config.type == "msgbox")
86+
if(config.type === "msgbox")
7187
return createMsgBox(config, result)
72-
else if(config.type == "input")
88+
else if(config.type === "input")
7389
return createInput(config, result)
74-
else if(config.type == "file")
90+
else if(config.type === "file")
7591
return createFile(config, result)
92+
else if(config.type === "color")
93+
return createColor(config, result)
94+
else if(config.type === "progress")
95+
return createProgress(config, result)
7696
else
7797
return false;
7898
}
@@ -88,6 +108,10 @@ QtObject {
88108
*/
89109
function closeAction() {
90110
if(_popups.length > 0) {
111+
if(typeof _popups[_popups.length - 1].closeAction == "function") {
112+
if(_popups[_popups.length - 1].closeAction())
113+
return true;
114+
}
91115
_popups[_popups.length - 1].reject();
92116
return true;
93117
} else
@@ -168,6 +192,24 @@ QtObject {
168192
}
169193
}
170194

195+
//! Internal property
196+
property Component _progressComponent: ProgressDialog {
197+
id: __progress
198+
199+
onClosed: {
200+
var index = _popups.indexOf(__progress);
201+
if(index > -1) {
202+
__progress.destroy();
203+
_dialogPresenter._popups.splice(index, 1);
204+
}
205+
}
206+
207+
Component.onCompleted: {
208+
_popups.push(__progress)
209+
__progress.open()
210+
}
211+
}
212+
171213
/*! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeMessageBox
172214
*
173215
* @param type:MessageConfig config The message configuration to create a dialog of
@@ -225,10 +267,49 @@ QtObject {
225267
props["msgConfig"] = config;
226268
props["msgResult"] = result;
227269
var incubator = null;
228-
if(config.subType == "folder")
270+
if(config.subType === "folder")
229271
incubator = _folderComponent.incubateObject(rootItem, props, Qt.Synchronous);
230272
else
231273
incubator = _fileComponent.incubateObject(rootItem, props, Qt.Synchronous);
232274
return incubator.status !== Component.Error;
233275
}
276+
277+
/*! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeColorDialog
278+
*
279+
* @param type:MessageConfig config The message configuration to create a dialog of
280+
* @param type:MessageResult result The result to report the dialog result to
281+
* @return type:bool `true` if successfully presented, `false` if not
282+
*
283+
* Used by the showDialog() method to show a dialog of the color dialog type. You can use
284+
* it yourself if you want to extend the presenter and still keep the default dialogs it
285+
* supports.
286+
*
287+
* @sa DialogPresenter::showDialog
288+
*/
289+
function createColor(config, result) {
290+
config.viewProperties["alpha"] = (config.subType === "argb");
291+
config.type = "input";
292+
config.subType = "QColor";
293+
return createInput(config, result);
294+
}
295+
296+
/*! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeProgressDialog
297+
*
298+
* @param type:MessageConfig config The message configuration to create a dialog of
299+
* @param type:MessageResult result The result to report the dialog result to
300+
* @return type:bool `true` if successfully presented, `false` if not
301+
*
302+
* Used by the showDialog() method to show a dialog of the progress dialog type. You can
303+
* use it yourself if you want to extend the presenter and still keep the default dialogs
304+
* it supports.
305+
*
306+
* @sa DialogPresenter::showDialog
307+
*/
308+
function createProgress(config, result) {
309+
var props = config.viewProperties;
310+
props["msgConfig"] = config;
311+
props["msgResult"] = result;
312+
var incubator = _progressComponent.incubateObject(rootItem, props, Qt.Synchronous);
313+
return incubator.status !== Component.Error;
314+
}
234315
}

src/imports/mvvmquick/DialogPresenter11.qml renamed to src/imports/mvvmquick/DialogPresenter10.qml

+2-46
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import QtQuick 2.10
22
import QtQuick.Controls 2.3
3-
import de.skycoder42.QtMvvm.Core 1.1
4-
import de.skycoder42.QtMvvm.Quick 1.1
3+
import de.skycoder42.QtMvvm.Core 1.0
4+
import de.skycoder42.QtMvvm.Quick 1.0
55

66
/*! @brief A presentation helper that can present generic mvvm dialogs
77
*
@@ -56,9 +56,6 @@ QtObject {
5656
*/
5757
property Item rootItem: null
5858

59-
//TODO document
60-
readonly property bool empty: _popups.length == 0
61-
6259
/*! @brief The primary presenting method to present a dialog
6360
*
6461
* @param type:MessageConfig config The message configuration to create a dialog of
@@ -76,10 +73,6 @@ QtObject {
7673
return createInput(config, result)
7774
else if(config.type == "file")
7875
return createFile(config, result)
79-
else if(config.type == "color")
80-
return createColor(config, result)
81-
else if(config.type == "progress")
82-
return createProgress(config, result)
8376
else
8477
return false;
8578
}
@@ -95,10 +88,6 @@ QtObject {
9588
*/
9689
function closeAction() {
9790
if(_popups.length > 0) {
98-
if(typeof _popups[_popups.length - 1].closeAction == "function") {
99-
if(_popups[_popups.length - 1].closeAction())
100-
return true;
101-
}
10291
_popups[_popups.length - 1].reject();
10392
return true;
10493
} else
@@ -179,24 +168,6 @@ QtObject {
179168
}
180169
}
181170

182-
//! Internal property
183-
property Component _progressComponent: ProgressDialog {
184-
id: __progress
185-
186-
onClosed: {
187-
var index = _popups.indexOf(__progress);
188-
if(index > -1) {
189-
__progress.destroy();
190-
_dialogPresenter._popups.splice(index, 1);
191-
}
192-
}
193-
194-
Component.onCompleted: {
195-
_popups.push(__progress)
196-
__progress.open()
197-
}
198-
}
199-
200171
/*! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeMessageBox
201172
*
202173
* @param type:MessageConfig config The message configuration to create a dialog of
@@ -260,19 +231,4 @@ QtObject {
260231
incubator = _fileComponent.incubateObject(rootItem, props, Qt.Synchronous);
261232
return incubator.status !== Component.Error;
262233
}
263-
264-
function createColor(config, result) {
265-
config.viewProperties["alpha"] = (config.subType == "argb");
266-
config.type = "input";
267-
config.subType = "QColor";
268-
return createInput(config, result);
269-
}
270-
271-
function createProgress(config, result) {
272-
var props = config.viewProperties;
273-
props["msgConfig"] = config;
274-
props["msgResult"] = result;
275-
var incubator = _progressComponent.incubateObject(rootItem, props, Qt.Synchronous);
276-
return incubator.status !== Component.Error;
277-
}
278234
}

src/imports/mvvmquick/PopupPresenter.qml

+21-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,23 @@ QtObject {
5454
* }
5555
*/
5656
property Item rootItem: null
57-
57+
58+
/*! @brief Checks if the presenter has no open popups
59+
*
60+
* @default{`false`}
61+
*
62+
* As soon as there is at least a single open popup, this property gets false. Only when
63+
* no popups are show is it true. This property is always updated from within the
64+
* closeAction() method, so you can be shure that it is true after the last popup was
65+
* closed that way.
66+
*
67+
* @accessors{
68+
* @memberAc{empty}
69+
* @notifyAc{emptyChanged()}
70+
* }
71+
*/
72+
readonly property bool empty: _popups.length == 0
73+
5874
//! Internal property
5975
property var _popups: []
6076

@@ -92,6 +108,10 @@ QtObject {
92108
*/
93109
function closeAction() {
94110
if(_popups.length > 0) {
111+
if(typeof _popups[_popups.length - 1].closeAction == "function") {
112+
if(_popups[_popups.length - 1].closeAction())
113+
return true;
114+
}
95115
_popups[_popups.length - 1].close();
96116
return true;
97117
} else

src/imports/mvvmquick/PopupPresenter11.qml renamed to src/imports/mvvmquick/PopupPresenter10.qml

+1-8
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ QtObject {
5454
* }
5555
*/
5656
property Item rootItem: null
57-
58-
//TODO document
59-
readonly property bool empty: _popups.length == 0
60-
57+
6158
//! Internal property
6259
property var _popups: []
6360

@@ -95,10 +92,6 @@ QtObject {
9592
*/
9693
function closeAction() {
9794
if(_popups.length > 0) {
98-
if(typeof _popups[_popups.length - 1].closeAction == "function") {
99-
if(_popups[_popups.length - 1].closeAction())
100-
return true;
101-
}
10295
_popups[_popups.length - 1].close();
10396
return true;
10497
} else

src/imports/mvvmquick/PresentingStackView.qml

+3-7
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,10 @@ StackView {
113113
return true;
114114
}
115115

116-
if(_presenterStack.depth <= 1)
116+
if(_presenterStack.safePop())
117+
return true;
118+
else
117119
return false;
118-
else {
119-
if(_presenterStack.safePop())
120-
return true;
121-
else
122-
return false;
123-
}
124120
}
125121

126122
/*! @brief Pop and delete a view

src/imports/mvvmquick/PresentingStackView11.qml renamed to src/imports/mvvmquick/PresentingStackView10.qml

+7-3
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,14 @@ StackView {
113113
return true;
114114
}
115115

116-
if(_presenterStack.safePop())
117-
return true;
118-
else
116+
if(_presenterStack.depth <= 1)
119117
return false;
118+
else {
119+
if(_presenterStack.safePop())
120+
return true;
121+
else
122+
return false;
123+
}
120124
}
121125

122126
/*! @brief Pop and delete a view

src/imports/mvvmquick/QtMvvmApp.qml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import QtQuick 2.10
22
import QtQuick.Controls 2.3
3-
import de.skycoder42.QtMvvm.Quick 1.0
3+
import de.skycoder42.QtMvvm.Quick 1.1
44

55
/*! @brief An application root window that is a full fledged QML presenter
66
*
@@ -172,6 +172,9 @@ ApplicationWindow {
172172
closed = _drawerLoader.item.closeAction();
173173
if(!closed)
174174
closed = _rootStack.closeAction();
175+
//if everything was closed -> still accept it
176+
if(closed && _rootDialogs.emtpy && _rootPopup.empty && _rootStack.empty)
177+
closed = false;
175178
return closed;
176179
}
177180

src/imports/mvvmquick/QtMvvmApp11.qml renamed to src/imports/mvvmquick/QtMvvmApp10.qml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import QtQuick 2.10
22
import QtQuick.Controls 2.3
3-
import de.skycoder42.QtMvvm.Quick 1.1
3+
import de.skycoder42.QtMvvm.Quick 1.0
44

55
/*! @brief An application root window that is a full fledged QML presenter
66
*
@@ -172,9 +172,6 @@ ApplicationWindow {
172172
closed = _drawerLoader.item.closeAction();
173173
if(!closed)
174174
closed = _rootStack.closeAction();
175-
//if everything was closed -> still accept it
176-
if(closed && _rootDialogs.emtpy && _rootPopup.empty && _rootStack.empty)
177-
closed = false;
178175
return closed;
179176
}
180177

0 commit comments

Comments
 (0)