Skip to content

Commit

Permalink
Allow validation error stacking
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Dec 29, 2024
1 parent c20029c commit 5a90551
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/QmlControls/QGCPopupDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Popup {
property real _contentMargin: ScreenTools.defaultFontPixelHeight / 2
property bool _acceptAllowed: acceptButton.visible
property bool _rejectAllowed: rejectButton.visible
property int _previousValidationErrorCount: 0

background: QGCMouseArea {
width: mainWindow.width
Expand All @@ -84,16 +85,21 @@ Popup {
contentChildren[contentChildren.length - 1].parent = dialogContentParent
}

onAboutToShow: setupDialogButtons(buttons)
onAboutToShow: {
_previousValidationErrorCount = globals.validationErrorCount
setupDialogButtons(buttons)
}

onClosed: {
globals.validationErrorCount = _previousValidationErrorCount
Qt.inputMethod.hide()
if (destroyOnClose) {
root.destroy()
}
}

function _accept() {
if (_acceptAllowed && mainWindow.allowViewSwitch()) {
if (_acceptAllowed && mainWindow.allowViewSwitch(_previousValidationErrorCount)) {
accepted()
if (preventClose) {
preventClose = false
Expand All @@ -105,7 +111,7 @@ Popup {

function _reject() {
// Dialogs with cancel button are allowed to close with validation errors
if (_rejectAllowed && ((buttons & Dialog.Cancel) || mainWindow.allowViewSwitch())) {
if (_rejectAllowed && ((buttons & Dialog.Cancel) || mainWindow.allowViewSwitch(_previousValidationErrorCount))) {
rejected()
if (preventClose) {
preventClose = false
Expand Down
4 changes: 2 additions & 2 deletions src/UI/MainRootWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ ApplicationWindow {
//-- Global Scope Functions

// This function is used to prevent view switching if there are validation errors
function allowViewSwitch() {
function allowViewSwitch(previousValidationErrorCount = 0) {
// Run validation on active focus control to ensure it is valid before switching views
if (mainWindow.activeFocusControl instanceof QGCTextField) {
mainWindow.activeFocusControl.onEditingFinished()
}
return globals.validationErrorCount === 0
return globals.validationErrorCount <= previousValidationErrorCount
}

function showPlanView() {
Expand Down

0 comments on commit 5a90551

Please sign in to comment.