From e56172f7de7f227024740f6582eacc2261625330 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sat, 18 Feb 2023 21:42:32 +0100 Subject: [PATCH] Add confirmation dialog before deleting devices --- DevicesSettingsPage.qml | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/DevicesSettingsPage.qml b/DevicesSettingsPage.qml index 363f32c..29b22ab 100644 --- a/DevicesSettingsPage.qml +++ b/DevicesSettingsPage.qml @@ -1,4 +1,5 @@ import QtQuick +import QtQuick.Controls import QtQuick.Controls.Material import QtQuick.Layouts @@ -20,10 +21,40 @@ ColumnLayout { model: devicesModel - onAddClicked: (index) => devicesModel.insertRow(index < 0 ? 0 : index + 1); - onRemoveClicked: (index) => devicesModel.removeRow(index) + onAddClicked: (index) => { const newIndex = index < 0 ? 0 : index + 1; if (devicesModel.insertRow(newIndex)) currentIndex = newIndex; else console.warn('failed'); } + onRemoveClicked: (index) => { + const dialog = dialogComponent.createObject(Overlay.overlay); + dialog.index = index; + dialog.open(); + } - onCurrentDataChanged: if (currentData) test.value = currentData.position + onCurrentDataChanged: if (currentData) positionField.value = currentData.position + + Component { + id: dialogComponent + + Dialog { + property int index + + anchors.centerIn: parent + standardButtons: DialogButtonBox.Yes | DialogButtonBox.Cancel + modal: true + title: qsTr('Confirmation') + + onAccepted: devicesModel.removeRow(index) + + Label { + id: textContainer + + anchors.fill: parent + + horizontalAlignment: Qt.AlignLeft + verticalAlignment: Qt.AlignTop + + text: qsTr('Are you sure you want to remove row %0').arg(index) + } + } + } } ColumnLayout {