Files
scheincommander/DeviceTypesSettingsPage.qml
T

121 lines
4.0 KiB
QML
Raw Normal View History

2023-02-15 01:12:19 +01:00
import QtQuick
import QtQuick.Controls
2023-02-15 01:12:19 +01:00
import QtQuick.Controls.Material
import QtQuick.Layouts
2023-02-21 20:28:53 +01:00
import scheincommander
2023-02-15 01:12:19 +01:00
ColumnLayout {
Label {
text: qsTr("Device Types Settings")
}
RowLayout {
//Layout.fillWidth: true
Layout.fillHeight: true
EditableListView {
id: listView
2023-02-15 01:12:19 +01:00
Layout.preferredWidth: 300
Layout.maximumWidth: 300
Layout.fillHeight: true
model: DeviceTypesModel {
id: deviceTypesModel
controller: __controller
}
2023-02-15 01:12:19 +01:00
onAddClicked: (index) => { const newIndex = index < 0 ? 0 : index + 1; if (deviceTypesModel.insertRow(newIndex)) currentIndex = newIndex; else console.warn('failed'); }
onRemoveClicked: (index) => {
const dialog = dialogComponent.createObject(Overlay.overlay);
dialog.index = index;
dialog.open();
}
Component {
id: dialogComponent
Dialog {
property int index
anchors.centerIn: parent
standardButtons: DialogButtonBox.Yes | DialogButtonBox.Cancel
modal: true
title: qsTr('Confirmation')
onAccepted: deviceTypesModel.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)
}
}
}
2023-02-15 01:12:19 +01:00
}
ColumnLayout {
enabled: listView.currentIndex !== -1
2023-02-15 01:12:19 +01:00
GridLayout {
2023-02-15 22:27:57 +01:00
Layout.preferredWidth: 600
Layout.maximumWidth: 600
2023-02-15 01:12:19 +01:00
columns: 2
Label { text: qsTr("Id:") }
SpinBox {
2023-02-15 22:27:57 +01:00
enabled: false
2023-02-15 01:12:19 +01:00
Layout.fillWidth: true
2023-02-18 21:31:59 +01:00
value: listView.currentData ? listView.currentData.id : -1
2023-02-18 23:48:28 +01:00
onValueModified: if (listView.currentData) listView.currentData.id = value; else console.warn('discarded');
2023-02-15 01:12:19 +01:00
}
Label { text: qsTr("Name:") }
TextField {
Layout.fillWidth: true
2023-02-18 21:31:59 +01:00
text: listView.currentData ? listView.currentData.name : ''
2023-02-18 23:48:28 +01:00
onTextEdited: if (listView.currentData) listView.currentData.name = text; else console.warn('discarded');
2023-02-15 01:12:19 +01:00
}
2023-02-18 18:45:32 +01:00
Label { text: qsTr("Icon:") }
2023-02-18 23:48:28 +01:00
IconComboBox {
id: iconComboBox
2023-02-18 18:45:32 +01:00
Layout.fillWidth: true
2023-02-18 22:46:16 +01:00
Layout.preferredHeight: 64
2023-02-18 23:48:28 +01:00
textRole: "fileBaseName"
valueRole: "fileBaseName"
iconSourceRole: "fileUrl"
2023-02-18 22:46:16 +01:00
2023-02-19 04:19:56 +01:00
model: IconsModel {
id: iconsModel
}
2023-02-18 23:48:28 +01:00
currentIndex: listView.currentData ? iconComboBox.indexOfValue(listView.currentData.iconName) : -1
2023-02-19 02:59:19 +01:00
Component.onCompleted: {
iconsModel.onRowCountChanged.connect(function(){
currentIndex = Qt.binding(function() { return listView.currentData ? iconComboBox.indexOfValue(listView.currentData.iconName) : -1});
});
}
2023-02-19 04:19:56 +01:00
onActivated: if (listView.currentData) listView.currentData.iconName = currentValue; else console.warn('discarded');
2023-02-18 18:45:32 +01:00
}
2023-02-15 01:12:19 +01:00
Label { text: qsTr("Registers:") }
RegistersSettingsItem {
2023-02-15 01:12:19 +01:00
Layout.fillWidth: true
Layout.fillHeight: true
2023-02-18 21:31:59 +01:00
deviceTypeId: listView.currentData ? listView.currentData.id : -1
2023-02-15 01:12:19 +01:00
}
}
Item {
Layout.fillHeight: true
}
}
}
}