From 0b3017fb55292b8a27d8ce56e78e3cbcecc37d6c Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Wed, 26 Jun 2024 17:30:23 +0700 Subject: [PATCH] Provider users with visual feedback when initiating a child addition process --- .../ordered_relation_editor.qml | 50 ++++++++++++------- .../relationeditors/relation_editor.qml | 36 +++++++++++-- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/src/qml/editorwidgets/relationeditors/ordered_relation_editor.qml b/src/qml/editorwidgets/relationeditors/ordered_relation_editor.qml index 36b890aa22..20fb7422a6 100644 --- a/src/qml/editorwidgets/relationeditors/ordered_relation_editor.qml +++ b/src/qml/editorwidgets/relationeditors/ordered_relation_editor.qml @@ -92,30 +92,35 @@ EditorWidgetBase { anchors { top: parent.top; right: parent.right; rightMargin: 10 } height: parent.height - ToolButton { + QfToolButton { id: addButton width: parent.height height: parent.height enabled: constraintsHardValid - contentItem: Rectangle { - anchors.fill: parent - color: parent.enabled ? nmRelationId ? 'blue' : 'black' : 'grey' - Image { - anchors.fill: parent - anchors.margins: 8 - fillMode: Image.PreserveAspectFit - horizontalAlignment: Image.AlignHCenter - verticalAlignment: Image.AlignVCenter - source: Theme.getThemeIcon( 'ic_add_white_24dp' ) - } - } + round: false + iconSource: Theme.getThemeIcon( 'ic_add_white_24dp' ) + bgcolor: parent.enabled ? nmRelationId ? 'blue' : 'black' : 'grey' } } - MouseArea { - anchors.fill: parent - onClicked: { + BusyIndicator { + id: addingIndicator + anchors { top: parent.top; right: parent.right; rightMargin: 10 } + width: parent.height + height: parent.height + running: false + } + + Timer { + id: addingTimer + + property string printName: '' + + interval: 50 + repeat: false + + onTriggered: { if (ProjectUtils.transactionMode(qgisProject) !== Qgis.TransactionMode.Disabled) { // When a transaction mode is enabled, we must fallback to saving the parent feature to have provider-side issues if (!save()) { @@ -137,6 +142,13 @@ EditorWidgetBase { } } } + + MouseArea { + anchors.fill: parent + onClicked: { + addingTimer.restart() + } + } } } @@ -455,10 +467,14 @@ EditorWidgetBase { } } - onFeatureSaved: { + onFeatureSaved: (id) => { orderedRelationModel.featureFocus = id orderedRelationModel.reload() } + + onOpened: { + addingIndicator.running = false + } } function requestedGeometryReceived(geometry) { diff --git a/src/qml/editorwidgets/relationeditors/relation_editor.qml b/src/qml/editorwidgets/relationeditors/relation_editor.qml index 120a7146fe..6d5b034066 100644 --- a/src/qml/editorwidgets/relationeditors/relation_editor.qml +++ b/src/qml/editorwidgets/relationeditors/relation_editor.qml @@ -128,12 +128,27 @@ EditorWidgetBase { } } - MouseArea { - anchors.fill: parent - onClicked: { + BusyIndicator { + id: addingIndicator + anchors { top: parent.top; right: parent.right; rightMargin: 10 } + width: parent.height + height: parent.height + running: false + } + + Timer { + id: addingTimer + + property string printName: '' + + interval: 50 + repeat: false + + onTriggered: { if (ProjectUtils.transactionMode(qgisProject) !== Qgis.TransactionMode.Disabled) { // When a transaction mode is enabled, we must fallback to saving the parent feature to have provider-side issues if (!save()) { + addingIndicator.running = false displayToast(qsTr('Cannot add child feature: insure the parent feature meets all constraints and can be saved'), 'warning') return } @@ -151,10 +166,19 @@ EditorWidgetBase { } else { + addingIndicator.running = false displayToast(qsTr('Cannot add child feature: attribute value linking parent and children is not set'), 'warning') } } } + + MouseArea { + anchors.fill: parent + onClicked: { + addingIndicator.running = true + addingTimer.restart() + } + } } } } @@ -345,10 +369,14 @@ EditorWidgetBase { relationEditorModel.reload() } - onFeatureSaved: { + onFeatureSaved: (id) => { relationEditorModel.featureFocus = id relationEditorModel.reload() } + + onOpened: { + addingIndicator.running = false + } } function isButtonEnabled(buttonType) {