From 01ebeb29be41b133ebce515704cd3b7e2e14a971 Mon Sep 17 00:00:00 2001 From: Mohsen Date: Mon, 14 Oct 2024 17:33:25 +0330 Subject: [PATCH] Add QfDialog. Cleaner dialog codes + we can have our custom dialog later. remove lots of duplication. --- src/qml/BluetoothDeviceChooser.qml | 11 +----- src/qml/BookmarkProperties.qml | 11 +----- src/qml/DigitizingToolbar.qml | 12 +----- src/qml/FeatureForm.qml | 13 +------ src/qml/FeatureListForm.qml | 38 ++----------------- src/qml/MessageLog.qml | 6 +-- src/qml/PluginManagerSettings.qml | 14 ++----- src/qml/QFieldCloudPackageLayersFeedback.qml | 11 +----- src/qml/QFieldCloudPopup.qml | 22 +---------- src/qml/QFieldLocalDataPickerScreen.qml | 6 +-- .../ordered_relation_editor.qml | 11 +----- .../relationeditors/relation_editor.qml | 11 +----- src/qml/geometryeditors/FillRing.qml | 10 +---- src/qml/imports/Theme/QfDialog.qml | 12 ++++++ src/qml/imports/Theme/qmldir | 1 + src/qml/qgismobileapp.qml | 10 +---- src/qml/qml.qrc | 1 + 17 files changed, 35 insertions(+), 165 deletions(-) create mode 100644 src/qml/imports/Theme/QfDialog.qml diff --git a/src/qml/BluetoothDeviceChooser.qml b/src/qml/BluetoothDeviceChooser.qml index 615b0424a6..3c2f9e6420 100644 --- a/src/qml/BluetoothDeviceChooser.qml +++ b/src/qml/BluetoothDeviceChooser.qml @@ -154,17 +154,9 @@ Item { } } - Dialog { + QfDialog { id: fullDiscoveryDialog parent: mainWindow.contentItem - - visible: false - modal: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Make a full service discovery") Label { width: parent.width @@ -172,7 +164,6 @@ Item { text: qsTr('A full device scan can take longer. You really want to do it?\nCancel to make a minimal device scan instead.') } - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { bluetoothDeviceModel.startServiceDiscovery(true); visible = false; diff --git a/src/qml/BookmarkProperties.qml b/src/qml/BookmarkProperties.qml index f0803c4d66..aeaa1cb0c6 100644 --- a/src/qml/BookmarkProperties.qml +++ b/src/qml/BookmarkProperties.qml @@ -177,18 +177,10 @@ Popup { } } - Dialog { + QfDialog { id: removeBookmarkDialog parent: mainWindow.contentItem - - visible: false - modal: true - font: Theme.defaultFont - z: 10000 // 1000s are embedded feature forms, user a higher value to insure the dialog will always show above embedded feature forms - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Remove bookmark") Label { width: parent.width @@ -196,7 +188,6 @@ Popup { text: qsTr("You are about to remove a bookmark, proceed?") } - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { bookmarkModel.removeBookmark(bookmarkProperties.bookmarkId); bookmarkProperties.close(); diff --git a/src/qml/DigitizingToolbar.qml b/src/qml/DigitizingToolbar.qml index 8ea136c63d..0a6322e5e6 100644 --- a/src/qml/DigitizingToolbar.qml +++ b/src/qml/DigitizingToolbar.qml @@ -247,25 +247,15 @@ QfVisibilityFadingRow { } } - Dialog { + QfDialog { id: cancelDialog parent: mainWindow.contentItem - - visible: false - modal: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Cancel digitizing") Label { width: parent.width wrapMode: Text.WordWrap text: qsTr("Should the digitized geometry be discarded?") } - - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { digitizingLogger.clearCoordinates(); rubberbandModel.reset(); diff --git a/src/qml/FeatureForm.qml b/src/qml/FeatureForm.qml index c45357c00b..98ab0edf54 100644 --- a/src/qml/FeatureForm.qml +++ b/src/qml/FeatureForm.qml @@ -850,27 +850,16 @@ Page { } } } - - Dialog { + QfDialog { id: cancelDialog parent: mainWindow.contentItem - - visible: false - modal: true - font: Theme.defaultFont - z: 10000 // 1000s are embedded feature forms, user a higher value to insure the dialog will always show above embedded feature forms - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Cancel editing") Label { width: parent.width wrapMode: Text.WordWrap text: form.state === 'Add' ? qsTr("You are about to dismiss the new feature, proceed?") : qsTr("You are about to leave editing state, any changes will be lost. Proceed?") } - - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { form.cancel(); } diff --git a/src/qml/FeatureListForm.qml b/src/qml/FeatureListForm.qml index 061961ced9..6ec16f0c90 100644 --- a/src/qml/FeatureListForm.qml +++ b/src/qml/FeatureListForm.qml @@ -796,7 +796,7 @@ Rectangle { } } - Dialog { + QfDialog { id: mergeDialog parent: mainWindow.contentItem @@ -804,13 +804,6 @@ Rectangle { property string featureDisplayName: '' property bool isMerged: false - visible: false - modal: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Merge feature(s)") Label { width: parent.width @@ -818,7 +811,6 @@ Rectangle { text: qsTr("Should the %n feature(s) selected really be merge?\n\nThe features geometries will be combined into feature '%1', which will keep its attributes.", "0", mergeDialog.selectedCount).arg(mergeDialog.featureDisplayName) } - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { if (isMerged) { return; @@ -845,17 +837,9 @@ Rectangle { } } - Dialog { + QfDialog { id: transferDialog parent: mainWindow.contentItem - - visible: false - modal: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Transfer Feature Attributes") Column { @@ -891,7 +875,6 @@ Rectangle { } } - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { let feature = transferFeatureListModel.getFeatureById(transferComboBox.currentValue); if (featureForm.model.featureModel.updateAttributesFromFeature(feature)) { @@ -914,28 +897,15 @@ Rectangle { } } - Dialog { + QfDialog { id: deleteDialog parent: mainWindow.contentItem property int selectedCount: 0 property bool isDeleted: false - visible: false - modal: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Delete feature(s)") - Label { - width: parent.width - wrapMode: Text.WordWrap - text: qsTr("Should the %n feature(s) selected really be deleted?", "0", deleteDialog.selectedCount) - } - - standardButtons: Dialog.Ok | Dialog.Cancel + text: qsTr("Should the %n feature(s) selected really be deleted?", "0", deleteDialog.selectedCount) onAccepted: { if (isDeleted) { return; diff --git a/src/qml/MessageLog.qml b/src/qml/MessageLog.qml index 6958549ba2..aba158304a 100644 --- a/src/qml/MessageLog.qml +++ b/src/qml/MessageLog.qml @@ -146,13 +146,10 @@ Page { } } - Dialog { + QfDialog { id: applicationLogDialog title: qsTr("Send application log") focus: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 y: (mainWindow.height - height - 80) / 2 onAboutToShow: { @@ -201,7 +198,6 @@ Page { } } - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { var applicationLogMessage = appliationLogInput.text.trim(); iface.sendLog(applicationLogMessage != '' ? applicationLogMessage : 'Manual log submission', includeCloudInformationCheckBox.checked ? cloudConnection.username : ''); diff --git a/src/qml/PluginManagerSettings.qml b/src/qml/PluginManagerSettings.qml index 751716807f..1d6091cfb6 100644 --- a/src/qml/PluginManagerSettings.qml +++ b/src/qml/PluginManagerSettings.qml @@ -216,11 +216,10 @@ Popup { } } - Dialog { + QfDialog { id: authorDetails title: authorName parent: mainWindow.contentItem - x: (mainWindow.width - width) / 2 y: (mainWindow.height - height - 80) / 2 property string authorName: "" @@ -264,14 +263,11 @@ Popup { standardButtons: Dialog.Close } - Dialog { + QfDialog { id: installFromUrlDialog title: "Install Plugin from URL" parent: mainWindow.contentItem focus: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 y: (mainWindow.height - height - 80) / 2 onAboutToShow: { @@ -304,17 +300,16 @@ Popup { } } - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { pluginManager.installFromUrl(installFromUrlInput.text); } } - Dialog { + QfDialog { id: uninstallConfirmation title: "Uninstall Plugin" parent: mainWindow.contentItem - x: (mainWindow.width - width) / 2 + modal: false y: (mainWindow.height - height - 80) / 2 property string pluginName: "" @@ -341,7 +336,6 @@ Popup { } } - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { pluginManager.uninstall(pluginUuid); } diff --git a/src/qml/QFieldCloudPackageLayersFeedback.qml b/src/qml/QFieldCloudPackageLayersFeedback.qml index 0c17bc671f..7aedcc09a2 100644 --- a/src/qml/QFieldCloudPackageLayersFeedback.qml +++ b/src/qml/QFieldCloudPackageLayersFeedback.qml @@ -7,31 +7,22 @@ import Theme /** * \ingroup qml */ -Dialog { +QfDialog { parent: mainWindow.contentItem property int selectedCount: 0 property bool isDeleted: false property alias packagedLayersListViewModel: packagedLayersListView.model - visible: false - modal: true width: mainWindow.width - 20 - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("QFieldCloud had troubles packaging your project") ColumnLayout { id: layout - anchors.fill: parent Label { Layout.fillWidth: true - text: qsTr("Some layers have not been packaged correctly on QFieldCloud. These layers might be misconfigured or their data source is not accessible from the QFieldCloud server. Please check the logs of the latest packaging job on the qfield.cloud website.") wrapMode: Text.WordWrap } diff --git a/src/qml/QFieldCloudPopup.qml b/src/qml/QFieldCloudPopup.qml index 7e54949f2a..947a454409 100644 --- a/src/qml/QFieldCloudPopup.qml +++ b/src/qml/QFieldCloudPopup.qml @@ -612,20 +612,13 @@ Popup { } } - Dialog { + QfDialog { id: revertDialog parent: mainWindow.contentItem property int selectedCount: 0 property bool isDeleted: false - visible: false - modal: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Revert local changes") Label { width: parent.width @@ -633,8 +626,6 @@ Popup { text: qsTr("Should local changes be reverted?") } - standardButtons: Dialog.Ok | Dialog.Cancel - onAccepted: { revertLocalChangesFromCurrentProject(); } @@ -644,20 +635,13 @@ Popup { } } - Dialog { + QfDialog { id: resetDialog parent: mainWindow.contentItem property int selectedCount: 0 property bool isDeleted: false - visible: false - modal: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Reset cloud project") Label { width: parent.width @@ -665,8 +649,6 @@ Popup { text: qsTr("Last warning, resetting the cloud project will erase any local changes, are you sure you want to go ahead?") } - standardButtons: Dialog.Ok | Dialog.Cancel - onAccepted: { resetCurrentProject(); } diff --git a/src/qml/QFieldLocalDataPickerScreen.qml b/src/qml/QFieldLocalDataPickerScreen.qml index 9f0bef5e92..f9f8992684 100644 --- a/src/qml/QFieldLocalDataPickerScreen.qml +++ b/src/qml/QFieldLocalDataPickerScreen.qml @@ -644,13 +644,10 @@ Page { } } - Dialog { + QfDialog { id: importUrlDialog title: "Import URL" focus: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 y: (mainWindow.height - height - 80) / 2 onAboutToShow: { @@ -683,7 +680,6 @@ Page { } } - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { iface.importUrl(importUrlInput.text); } diff --git a/src/qml/editorwidgets/relationeditors/ordered_relation_editor.qml b/src/qml/editorwidgets/relationeditors/ordered_relation_editor.qml index b33b1a7506..1329ec4070 100644 --- a/src/qml/editorwidgets/relationeditors/ordered_relation_editor.qml +++ b/src/qml/editorwidgets/relationeditors/ordered_relation_editor.qml @@ -383,7 +383,7 @@ EditorWidgetBase { running: orderedRelationModel.isLoading } - Dialog { + QfDialog { id: deleteDialog parent: mainWindow.contentItem @@ -395,22 +395,13 @@ EditorWidgetBase { property string nmReferencedLayerName: orderedRelationModel.nmRelation.referencedLayer ? orderedRelationModel.nmRelation.referencedLayer.name : '' property string nmReferencingLayerName - visible: false - modal: true z: 10000 // 1000s are embedded feature forms, use a higher value to insure feature form popups always show above embedded feature forms - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - - font: Theme.defaultFont - title: nmRelationId ? qsTr('Unlink feature %1 (%2) of %3').arg(nmReferencedFeatureDisplayMessage).arg(nmReferencedFeatureId).arg(nmReferencedLayerName) : qsTr('Delete feature %1 (%2) on %3').arg(referencingFeatureDisplayMessage).arg(referencingFeatureId).arg(referencingLayerName) Label { width: parent.width wrapMode: Text.WordWrap text: nmRelationId ? qsTr('Should the feature %1 (%2) of layer %3 be unlinked?
(The connection will be deleted on layer %4)').arg(deleteDialog.nmReferencedFeatureDisplayMessage).arg(deleteDialog.nmReferencedFeatureId).arg(deleteDialog.nmReferencedLayerName).arg(deleteDialog.referencingLayerName) : qsTr('Should the feature %1 (%2) on layer %3 be deleted?').arg(deleteDialog.referencingFeatureDisplayMessage).arg(deleteDialog.referencingFeatureId).arg(deleteDialog.referencingLayerName) } - - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { if (!orderedRelationModel.deleteFeature(referencingFeatureId)) { displayToast(qsTr("Failed to delete referencing feature"), 'error'); diff --git a/src/qml/editorwidgets/relationeditors/relation_editor.qml b/src/qml/editorwidgets/relationeditors/relation_editor.qml index 72498cbdd4..e82054edcc 100644 --- a/src/qml/editorwidgets/relationeditors/relation_editor.qml +++ b/src/qml/editorwidgets/relationeditors/relation_editor.qml @@ -289,7 +289,7 @@ EditorWidgetBase { } } - Dialog { + QfDialog { id: deleteDialog parent: mainWindow.contentItem @@ -301,22 +301,13 @@ EditorWidgetBase { property string nmReferencedLayerName: relationEditorModel.nmRelation.referencedLayer ? relationEditorModel.nmRelation.referencedLayer.name : '' property string nmReferencingLayerName - visible: false - modal: true z: 10000 // 1000s are embedded feature forms, use a higher value to insure feature form popups always show above embedded feature forms - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - - font: Theme.defaultFont - title: nmRelationId ? qsTr('Unlink feature %1 (%2) of %3').arg(nmReferencedFeatureDisplayMessage).arg(nmReferencedFeatureId).arg(nmReferencedLayerName) : qsTr('Delete feature %1 (%2) on %3').arg(referencingFeatureDisplayMessage).arg(referencingFeatureId).arg(referencingLayerName) Label { width: parent.width wrapMode: Text.WordWrap text: nmRelationId ? qsTr('Should the feature %1 (%2) of layer %3 be unlinked?
(The connection will be deleted on layer %4)').arg(deleteDialog.nmReferencedFeatureDisplayMessage).arg(deleteDialog.nmReferencedFeatureId).arg(deleteDialog.nmReferencedLayerName).arg(deleteDialog.referencingLayerName) : qsTr('Should the feature %1 (%2) on layer %3 be deleted?').arg(deleteDialog.referencingFeatureDisplayMessage).arg(deleteDialog.referencingFeatureId).arg(deleteDialog.referencingLayerName) } - - standardButtons: Dialog.Ok | Dialog.Cancel onAccepted: { if (!referencingFeatureListView.model.deleteFeature(referencingFeatureId)) { displayToast(qsTr("Failed to delete referencing feature"), 'error'); diff --git a/src/qml/geometryeditors/FillRing.qml b/src/qml/geometryeditors/FillRing.qml index 8d30094e2c..7f857957ff 100644 --- a/src/qml/geometryeditors/FillRing.qml +++ b/src/qml/geometryeditors/FillRing.qml @@ -75,17 +75,9 @@ QfVisibilityFadingRow { } } - Dialog { + QfDialog { id: addPolygonDialog parent: mainWindow.contentItem - - visible: false - modal: true - font: Theme.defaultFont - - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 - title: qsTr("Fill ring") Label { width: parent.width diff --git a/src/qml/imports/Theme/QfDialog.qml b/src/qml/imports/Theme/QfDialog.qml new file mode 100644 index 0000000000..748a05432d --- /dev/null +++ b/src/qml/imports/Theme/QfDialog.qml @@ -0,0 +1,12 @@ +import QtQuick +import QtQuick.Controls + +Dialog { + visible: false + modal: true + font: Theme.defaultFont + standardButtons: Dialog.Ok | Dialog.Cancel + + x: (mainWindow.width - width) / 2 + y: (mainWindow.height - height) / 2 +} diff --git a/src/qml/imports/Theme/qmldir b/src/qml/imports/Theme/qmldir index 73ecae353b..367b68d6ac 100644 --- a/src/qml/imports/Theme/qmldir +++ b/src/qml/imports/Theme/qmldir @@ -20,3 +20,4 @@ QfProgrerssRing 1.0 QfProgrerssRing.qml QfScrollBar 1.0 QfScrollBar.qml QfSearchBar 1.0 QfSearchBar.qml QfVisibilityFadingRow 1.0 QfVisibilityFadingRow.qml +QfDialog 1.0 QfDialog.qml diff --git a/src/qml/qgismobileapp.qml b/src/qml/qgismobileapp.qml index 56823a2605..e046e3ec3a 100644 --- a/src/qml/qgismobileapp.qml +++ b/src/qml/qgismobileapp.qml @@ -4003,17 +4003,10 @@ ApplicationWindow { enabled: false } - Dialog { + QfDialog { id: pluginPermissionDialog parent: mainWindow.contentItem - - visible: false - modal: true - font: Theme.defaultFont - z: 10000 // 1000s are embedded feature forms, user a higher value to insure the dialog will always show above embedded feature forms - x: (mainWindow.width - width) / 2 - y: (mainWindow.height - height) / 2 property alias permanent: permanentCheckBox.checked @@ -4042,7 +4035,6 @@ ApplicationWindow { pluginManager.denyRequestedPluginPermission(permanent); permanent = false; } - standardButtons: Dialog.Yes | Dialog.No } diff --git a/src/qml/qml.qrc b/src/qml/qml.qrc index a8508e61af..d753b191f4 100644 --- a/src/qml/qml.qrc +++ b/src/qml/qml.qrc @@ -123,5 +123,6 @@ imports/Theme/QfProgrerssRing.qml imports/Theme/QfScrollBar.qml imports/Theme/QfSearchBar.qml + imports/Theme/QfDialog.qml