diff --git a/src/imports/mvvmquick/DialogPresenter.qml b/src/imports/mvvmquick/DialogPresenter.qml index 7bf4fbc..126e5c0 100644 --- a/src/imports/mvvmquick/DialogPresenter.qml +++ b/src/imports/mvvmquick/DialogPresenter.qml @@ -1,7 +1,7 @@ import QtQuick 2.10 import QtQuick.Controls 2.3 -import de.skycoder42.QtMvvm.Core 1.0 -import de.skycoder42.QtMvvm.Quick 1.0 +import de.skycoder42.QtMvvm.Core 1.1 +import de.skycoder42.QtMvvm.Quick 1.1 /*! @brief A presentation helper that can present generic mvvm dialogs * @@ -56,6 +56,22 @@ QtObject { */ property Item rootItem: null + /*! @brief Checks if the presenter has no open dialogs + * + * @default{`false`} + * + * As soon as there is at least a single open dialog, this property gets false. Only when + * no dialogs are show is it true. This property is always updated from within the + * closeAction() method, so you can be shure that it is true after the last dialog was + * closed that way. + * + * @accessors{ + * @memberAc{empty} + * @notifyAc{emptyChanged()} + * } + */ + readonly property bool empty: _popups.length == 0 + /*! @brief The primary presenting method to present a dialog * * @param type:MessageConfig config The message configuration to create a dialog of @@ -67,12 +83,16 @@ QtObject { * @sa QtMvvm::MessageConfig, QtMvvm::MessageResult, QtMvvmApp::showDialog */ function showDialog(config, result) { - if(config.type == "msgbox") + if(config.type === "msgbox") return createMsgBox(config, result) - else if(config.type == "input") + else if(config.type === "input") return createInput(config, result) - else if(config.type == "file") + else if(config.type === "file") return createFile(config, result) + else if(config.type === "color") + return createColor(config, result) + else if(config.type === "progress") + return createProgress(config, result) else return false; } @@ -88,6 +108,10 @@ QtObject { */ function closeAction() { if(_popups.length > 0) { + if(typeof _popups[_popups.length - 1].closeAction == "function") { + if(_popups[_popups.length - 1].closeAction()) + return true; + } _popups[_popups.length - 1].reject(); return true; } else @@ -168,6 +192,24 @@ QtObject { } } + //! Internal property + property Component _progressComponent: ProgressDialog { + id: __progress + + onClosed: { + var index = _popups.indexOf(__progress); + if(index > -1) { + __progress.destroy(); + _dialogPresenter._popups.splice(index, 1); + } + } + + Component.onCompleted: { + _popups.push(__progress) + __progress.open() + } + } + /*! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeMessageBox * * @param type:MessageConfig config The message configuration to create a dialog of @@ -225,10 +267,49 @@ QtObject { props["msgConfig"] = config; props["msgResult"] = result; var incubator = null; - if(config.subType == "folder") + if(config.subType === "folder") incubator = _folderComponent.incubateObject(rootItem, props, Qt.Synchronous); else incubator = _fileComponent.incubateObject(rootItem, props, Qt.Synchronous); return incubator.status !== Component.Error; } + + /*! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeColorDialog + * + * @param type:MessageConfig config The message configuration to create a dialog of + * @param type:MessageResult result The result to report the dialog result to + * @return type:bool `true` if successfully presented, `false` if not + * + * Used by the showDialog() method to show a dialog of the color dialog type. You can use + * it yourself if you want to extend the presenter and still keep the default dialogs it + * supports. + * + * @sa DialogPresenter::showDialog + */ + function createColor(config, result) { + config.viewProperties["alpha"] = (config.subType === "argb"); + config.type = "input"; + config.subType = "QColor"; + return createInput(config, result); + } + + /*! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeProgressDialog + * + * @param type:MessageConfig config The message configuration to create a dialog of + * @param type:MessageResult result The result to report the dialog result to + * @return type:bool `true` if successfully presented, `false` if not + * + * Used by the showDialog() method to show a dialog of the progress dialog type. You can + * use it yourself if you want to extend the presenter and still keep the default dialogs + * it supports. + * + * @sa DialogPresenter::showDialog + */ + function createProgress(config, result) { + var props = config.viewProperties; + props["msgConfig"] = config; + props["msgResult"] = result; + var incubator = _progressComponent.incubateObject(rootItem, props, Qt.Synchronous); + return incubator.status !== Component.Error; + } } diff --git a/src/imports/mvvmquick/DialogPresenter11.qml b/src/imports/mvvmquick/DialogPresenter10.qml similarity index 83% rename from src/imports/mvvmquick/DialogPresenter11.qml rename to src/imports/mvvmquick/DialogPresenter10.qml index 05eca03..7bf4fbc 100644 --- a/src/imports/mvvmquick/DialogPresenter11.qml +++ b/src/imports/mvvmquick/DialogPresenter10.qml @@ -1,7 +1,7 @@ import QtQuick 2.10 import QtQuick.Controls 2.3 -import de.skycoder42.QtMvvm.Core 1.1 -import de.skycoder42.QtMvvm.Quick 1.1 +import de.skycoder42.QtMvvm.Core 1.0 +import de.skycoder42.QtMvvm.Quick 1.0 /*! @brief A presentation helper that can present generic mvvm dialogs * @@ -56,9 +56,6 @@ QtObject { */ property Item rootItem: null - //TODO document - readonly property bool empty: _popups.length == 0 - /*! @brief The primary presenting method to present a dialog * * @param type:MessageConfig config The message configuration to create a dialog of @@ -76,10 +73,6 @@ QtObject { return createInput(config, result) else if(config.type == "file") return createFile(config, result) - else if(config.type == "color") - return createColor(config, result) - else if(config.type == "progress") - return createProgress(config, result) else return false; } @@ -95,10 +88,6 @@ QtObject { */ function closeAction() { if(_popups.length > 0) { - if(typeof _popups[_popups.length - 1].closeAction == "function") { - if(_popups[_popups.length - 1].closeAction()) - return true; - } _popups[_popups.length - 1].reject(); return true; } else @@ -179,24 +168,6 @@ QtObject { } } - //! Internal property - property Component _progressComponent: ProgressDialog { - id: __progress - - onClosed: { - var index = _popups.indexOf(__progress); - if(index > -1) { - __progress.destroy(); - _dialogPresenter._popups.splice(index, 1); - } - } - - Component.onCompleted: { - _popups.push(__progress) - __progress.open() - } - } - /*! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeMessageBox * * @param type:MessageConfig config The message configuration to create a dialog of @@ -260,19 +231,4 @@ QtObject { incubator = _fileComponent.incubateObject(rootItem, props, Qt.Synchronous); return incubator.status !== Component.Error; } - - function createColor(config, result) { - config.viewProperties["alpha"] = (config.subType == "argb"); - config.type = "input"; - config.subType = "QColor"; - return createInput(config, result); - } - - function createProgress(config, result) { - var props = config.viewProperties; - props["msgConfig"] = config; - props["msgResult"] = result; - var incubator = _progressComponent.incubateObject(rootItem, props, Qt.Synchronous); - return incubator.status !== Component.Error; - } } diff --git a/src/imports/mvvmquick/PopupPresenter.qml b/src/imports/mvvmquick/PopupPresenter.qml index 6b1446a..6b49f57 100644 --- a/src/imports/mvvmquick/PopupPresenter.qml +++ b/src/imports/mvvmquick/PopupPresenter.qml @@ -54,7 +54,23 @@ QtObject { * } */ property Item rootItem: null - + + /*! @brief Checks if the presenter has no open popups + * + * @default{`false`} + * + * As soon as there is at least a single open popup, this property gets false. Only when + * no popups are show is it true. This property is always updated from within the + * closeAction() method, so you can be shure that it is true after the last popup was + * closed that way. + * + * @accessors{ + * @memberAc{empty} + * @notifyAc{emptyChanged()} + * } + */ + readonly property bool empty: _popups.length == 0 + //! Internal property property var _popups: [] @@ -92,6 +108,10 @@ QtObject { */ function closeAction() { if(_popups.length > 0) { + if(typeof _popups[_popups.length - 1].closeAction == "function") { + if(_popups[_popups.length - 1].closeAction()) + return true; + } _popups[_popups.length - 1].close(); return true; } else diff --git a/src/imports/mvvmquick/PopupPresenter11.qml b/src/imports/mvvmquick/PopupPresenter10.qml similarity index 92% rename from src/imports/mvvmquick/PopupPresenter11.qml rename to src/imports/mvvmquick/PopupPresenter10.qml index 35392f5..6b1446a 100644 --- a/src/imports/mvvmquick/PopupPresenter11.qml +++ b/src/imports/mvvmquick/PopupPresenter10.qml @@ -54,10 +54,7 @@ QtObject { * } */ property Item rootItem: null - - //TODO document - readonly property bool empty: _popups.length == 0 - + //! Internal property property var _popups: [] @@ -95,10 +92,6 @@ QtObject { */ function closeAction() { if(_popups.length > 0) { - if(typeof _popups[_popups.length - 1].closeAction == "function") { - if(_popups[_popups.length - 1].closeAction()) - return true; - } _popups[_popups.length - 1].close(); return true; } else diff --git a/src/imports/mvvmquick/PresentingStackView.qml b/src/imports/mvvmquick/PresentingStackView.qml index d813774..6d8660b 100644 --- a/src/imports/mvvmquick/PresentingStackView.qml +++ b/src/imports/mvvmquick/PresentingStackView.qml @@ -113,14 +113,10 @@ StackView { return true; } - if(_presenterStack.depth <= 1) + if(_presenterStack.safePop()) + return true; + else return false; - else { - if(_presenterStack.safePop()) - return true; - else - return false; - } } /*! @brief Pop and delete a view diff --git a/src/imports/mvvmquick/PresentingStackView11.qml b/src/imports/mvvmquick/PresentingStackView10.qml similarity index 97% rename from src/imports/mvvmquick/PresentingStackView11.qml rename to src/imports/mvvmquick/PresentingStackView10.qml index 6d8660b..d813774 100644 --- a/src/imports/mvvmquick/PresentingStackView11.qml +++ b/src/imports/mvvmquick/PresentingStackView10.qml @@ -113,10 +113,14 @@ StackView { return true; } - if(_presenterStack.safePop()) - return true; - else + if(_presenterStack.depth <= 1) return false; + else { + if(_presenterStack.safePop()) + return true; + else + return false; + } } /*! @brief Pop and delete a view diff --git a/src/imports/mvvmquick/QtMvvmApp.qml b/src/imports/mvvmquick/QtMvvmApp.qml index 9e6e17e..0ae6f49 100644 --- a/src/imports/mvvmquick/QtMvvmApp.qml +++ b/src/imports/mvvmquick/QtMvvmApp.qml @@ -1,6 +1,6 @@ import QtQuick 2.10 import QtQuick.Controls 2.3 -import de.skycoder42.QtMvvm.Quick 1.0 +import de.skycoder42.QtMvvm.Quick 1.1 /*! @brief An application root window that is a full fledged QML presenter * @@ -172,6 +172,9 @@ ApplicationWindow { closed = _drawerLoader.item.closeAction(); if(!closed) closed = _rootStack.closeAction(); + //if everything was closed -> still accept it + if(closed && _rootDialogs.emtpy && _rootPopup.empty && _rootStack.empty) + closed = false; return closed; } diff --git a/src/imports/mvvmquick/QtMvvmApp11.qml b/src/imports/mvvmquick/QtMvvmApp10.qml similarity index 96% rename from src/imports/mvvmquick/QtMvvmApp11.qml rename to src/imports/mvvmquick/QtMvvmApp10.qml index 0ae6f49..9e6e17e 100644 --- a/src/imports/mvvmquick/QtMvvmApp11.qml +++ b/src/imports/mvvmquick/QtMvvmApp10.qml @@ -1,6 +1,6 @@ import QtQuick 2.10 import QtQuick.Controls 2.3 -import de.skycoder42.QtMvvm.Quick 1.1 +import de.skycoder42.QtMvvm.Quick 1.0 /*! @brief An application root window that is a full fledged QML presenter * @@ -172,9 +172,6 @@ ApplicationWindow { closed = _drawerLoader.item.closeAction(); if(!closed) closed = _rootStack.closeAction(); - //if everything was closed -> still accept it - if(closed && _rootDialogs.emtpy && _rootPopup.empty && _rootStack.empty) - closed = false; return closed; }