2020-08-20 04:45:29 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import "../imports"
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: root
|
|
|
|
property var isValid: true
|
2020-09-09 11:04:01 +00:00
|
|
|
property var isPending: false
|
2020-08-20 04:45:29 +00:00
|
|
|
property var validate: function() {
|
|
|
|
let isValid = true
|
|
|
|
for (let i=0; i<children.length; i++) {
|
|
|
|
const component = children[i]
|
|
|
|
if (component.hasOwnProperty("validate") && typeof component.validate === "function") {
|
|
|
|
isValid = component.validate()
|
|
|
|
}
|
2020-09-09 11:04:01 +00:00
|
|
|
if (component.hasOwnProperty("isPending")) {
|
|
|
|
isPending = component.isPending
|
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
|
|
|
root.isValid = isValid
|
2020-09-09 11:04:01 +00:00
|
|
|
root.isPending = isPending
|
|
|
|
return { isValid, isPending }
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
|
|
|
color: Style.current.background
|
|
|
|
function reset() {
|
|
|
|
for (let i=0; i<children.length; i++) {
|
|
|
|
const component = children[i]
|
|
|
|
try {
|
|
|
|
if (component.hasOwnProperty("resetInternal") && typeof component.resetInternal === "function") {
|
|
|
|
component.resetInternal()
|
|
|
|
}
|
|
|
|
if (component.hasOwnProperty("reset") && typeof component.reset === "function") {
|
|
|
|
component.reset()
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("Error resetting component", i, ":", e.message)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StackView.onActivated: {
|
|
|
|
// parent refers to the StackView
|
|
|
|
parent.groupActivated(this)
|
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
|
|
for (let i=0; i<children.length; i++) {
|
|
|
|
const component = children[i]
|
|
|
|
if (component.hasOwnProperty("isValid")) {
|
2020-09-09 11:04:01 +00:00
|
|
|
component.isValidChanged.connect(updateGroupValidityAndPendingStatus)
|
2020-08-20 04:45:29 +00:00
|
|
|
root.isValid = root.isValid && component.isValid // set the initial state
|
|
|
|
}
|
2020-09-09 11:04:01 +00:00
|
|
|
if (component.hasOwnProperty("isPending")) {
|
|
|
|
component.isPendingChanged.connect(updateGroupValidityAndPendingStatus)
|
|
|
|
root.isPending = component.isPending
|
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-09 11:04:01 +00:00
|
|
|
function updateGroupValidityAndPendingStatus() {
|
2020-08-20 04:45:29 +00:00
|
|
|
let isValid = true
|
2020-09-09 11:04:01 +00:00
|
|
|
let isPending = false
|
2020-08-20 04:45:29 +00:00
|
|
|
for (let i=0; i<children.length; i++) {
|
|
|
|
const component = children[i]
|
|
|
|
if (component.hasOwnProperty("isValid")) {
|
|
|
|
isValid = isValid && component.isValid
|
|
|
|
}
|
2020-09-09 11:04:01 +00:00
|
|
|
if (component.hasOwnProperty("isPending")) {
|
|
|
|
isPending = component.isPending
|
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
|
|
|
root.isValid = isValid
|
2020-09-09 11:04:01 +00:00
|
|
|
root.isPending = isPending
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
2020-09-09 11:04:01 +00:00
|
|
|
}
|