Implemented EditValueItem for friendly name and price limit

This commit is contained in:
2024-07-17 23:07:24 +02:00
parent f6a2fef64b
commit 690c477f9e
12 changed files with 166 additions and 75 deletions

View File

@@ -63,7 +63,6 @@ qt_add_qml_module(evcharger-app
CablePage.qml CablePage.qml
CarPage.qml CarPage.qml
CenteredDialog.qml CenteredDialog.qml
ChangeNumberItem.qml
ChargerTabPage.qml ChargerTabPage.qml
ChargingConfigurationPage.qml ChargingConfigurationPage.qml
ChargingSpeedPage.qml ChargingSpeedPage.qml
@@ -79,7 +78,9 @@ qt_add_qml_module(evcharger-app
DeviceListScreen.qml DeviceListScreen.qml
DeviceScreen.qml DeviceScreen.qml
DisplaySettingsPage.qml DisplaySettingsPage.qml
DoubleSpinBox.qml
EcoTabPage.qml EcoTabPage.qml
EditValueItem.qml
EthernetPage.qml EthernetPage.qml
EVChargerApp.qml EVChargerApp.qml
FirmwarePage.qml FirmwarePage.qml
@@ -114,6 +115,7 @@ qt_add_qml_module(evcharger-app
SensorsConfigurationPage.qml SensorsConfigurationPage.qml
SetPriceLimitPage.qml SetPriceLimitPage.qml
SettingsTabPage.qml SettingsTabPage.qml
SetValueHelper.qml
SimpleNavigationItem.qml SimpleNavigationItem.qml
SwitchLanguagePage.qml SwitchLanguagePage.qml
TimeComponentLabel.qml TimeComponentLabel.qml

View File

@@ -1,45 +0,0 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
WhiteItemDelegate {
property alias descriptionText: descriptionText.text
property alias valueText: valueText.text
Layout.fillWidth: true
contentItem: RowLayout {
Text {
id: descriptionText
wrapMode: Text.Wrap
Layout.fillWidth: true
font.bold: true
}
Text {
id: valueText
}
Text {
text: ">"
}
}
onClicked: dialog.open()
CenteredDialog {
id: dialog
title: qsTr("Password required")
standardButtons: Dialog.Ok | Dialog.Cancel
focus: true
modal: true
contentItem: SpinBox {
}
// onAccepted: theDeviceConnection.sendAuth(passwordInput.text)
// onRejected: loader.close()
}
}

View File

@@ -168,10 +168,16 @@ AnimatedStackView {
} }
NavigationItem { NavigationItem {
ApiKeyValueHelper {
id: priceLimitHelper
deviceConnection: theDeviceConnection
apiKey: "awp"
}
visible: logicMode.value == 4 visible: logicMode.value == 4
iconSource: "material-icons/grid_guides.svg" iconSource: "material-icons/grid_guides.svg"
title: qsTr("Price limit") title: qsTr("Price limit")
description: qsTr("%0 ct/kWh").arg(0) description: qsTr("%0 ct/kWh").arg(priceLimitHelper.value)
component: "SetPriceLimitPage.qml" component: "SetPriceLimitPage.qml"
} }

33
DoubleSpinBox.qml Normal file
View File

@@ -0,0 +1,33 @@
import QtQuick
import QtQuick.Controls
Item {
id: doubleSpinBox
property int decimals: 2
property real value: 0.0
property real from: 0.0
property real to: 100.0
property real stepSize: 1.0
SpinBox {
property real factor: Math.pow(10, decimals)
id: spinbox
stepSize: doubleSpinBox.stepSize * factor
value: doubleSpinBox.value * factor
onValueChanged: doubleSpinBox.value = spinbox.value / factor
to : doubleSpinBox.to * factor
from : doubleSpinBox.from * factor
validator: DoubleValidator {
bottom: Math.min(spinbox.from, spinbox.to) * spinbox.factor
top: Math.max(spinbox.from, spinbox.to) * spinbox.factor
}
textFromValue: function(value, locale) {
return parseFloat(value * 1.0 / factor).toFixed(decimals)
}
}
}

71
EditValueItem.qml Normal file
View File

@@ -0,0 +1,71 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import EVChargerApp
WhiteItemDelegate {
id: itemDelegate
required property string apiKey
property string valueText: apiKeyValueHelper.value
property alias editableItem: dialog.contentItem
property alias value: apiKeyValueHelper.value
property bool fullWidth: false
Layout.fillWidth: true
ApiKeyValueHelper {
id: apiKeyValueHelper
deviceConnection: theDeviceConnection
apiKey: itemDelegate.apiKey
}
SetValueHelper {
id: setValueHelper
deviceConnection: theDeviceConnection
apiKey: itemDelegate.apiKey
}
contentItem: RowLayout {
Text {
wrapMode: Text.Wrap
Layout.fillWidth: true
font.bold: true
text: itemDelegate.text
}
Text {
text: itemDelegate.valueText
}
Text {
text: ">"
}
}
onClicked: {
editableItem.value = value
dialog.open()
}
CenteredDialog {
id: dialog
title: itemDelegate.text
standardButtons: Dialog.Ok | Dialog.Cancel
focus: true
modal: true
Binding {
target: dialog
property: "width"
value: dialog.parent.width
when: fullWidth
}
onAccepted: {
console.log(editableItem.value)
setValueHelper.setValue(editableItem.value)
}
}
}

View File

@@ -21,9 +21,10 @@ WhiteCheckDelegate {
apiKey: checkDelegate.apiKey apiKey: checkDelegate.apiKey
} }
SendMessageHelper { SetValueHelper {
id: valueChanger id: valueChanger
deviceConnection: theDeviceConnection deviceConnection: theDeviceConnection
apiKey: checkDelegate.apiKey
onResponseChanged: checkDelegate.checked = Qt.binding(function(){ return valueHelper.value; }) onResponseChanged: checkDelegate.checked = Qt.binding(function(){ return valueHelper.value; })
} }
@@ -31,11 +32,7 @@ WhiteCheckDelegate {
text: valueHelper.value ? qsTr("On") : qsTr("Off") text: valueHelper.value ? qsTr("On") : qsTr("Off")
onClicked: { onClicked: {
valueChanger.sendMessage({ valueChanger.setValue(checked)
type: "setValue",
key: checkDelegate.apiKey,
value: checked
})
} }
BusyIndicator { BusyIndicator {

View File

@@ -5,9 +5,20 @@ import QtQuick.Layouts
NavigationPage { NavigationPage {
title: qsTr("Name") title: qsTr("Name")
Text { NavigationItem {
text: "TODO" iconSource: "material-icons/grid_guides.svg"
title: qsTr("Name")
component: "NamePage.qml"
}
Layout.fillHeight: true EditValueItem {
id: test
text: qsTr("Name")
apiKey: "fna"
fullWidth: true
editableItem: TextField {
id: textField
property alias value: textField.text
}
} }
} }

View File

@@ -9,9 +9,10 @@ WhiteBox {
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
SendMessageHelper { SetValueHelper {
id: valueChanger id: valueChanger
deviceConnection: theDeviceConnection deviceConnection: theDeviceConnection
apiKey: "lmo"
onResponseChanged: { onResponseChanged: {
ecoButton.checked = Qt.binding(() => ecoButton.selectedMode) ecoButton.checked = Qt.binding(() => ecoButton.selectedMode)
basicButton.checked = Qt.binding(() => basicButton.selectedMode) basicButton.checked = Qt.binding(() => basicButton.selectedMode)
@@ -35,7 +36,7 @@ WhiteBox {
if (selectedMode) if (selectedMode)
tabBar.setCurrentIndex(1) tabBar.setCurrentIndex(1)
else else
valueChanger.sendMessage({type: "setValue", key: "lmo", value: 4}) valueChanger.setValue(4)
} }
} }
@@ -47,7 +48,7 @@ WhiteBox {
text: qsTr("Basic") text: qsTr("Basic")
icon.source: "icons/EcoModeFilled.svg" icon.source: "icons/EcoModeFilled.svg"
description: qsTr("Basic charging") description: qsTr("Basic charging")
onClicked: valueChanger.sendMessage({type: "setValue", key: "lmo", value: 3}) onClicked: valueChanger.setValue(3)
} }
LogicModeButton { LogicModeButton {
@@ -62,7 +63,7 @@ WhiteBox {
if (selectedMode) if (selectedMode)
stackView.push(dailyTripPageComponent) stackView.push(dailyTripPageComponent)
else else
valueChanger.sendMessage({type: "setValue", key: "lmo", value: 5}) valueChanger.setValue(5)
} }
Component { Component {

View File

@@ -11,9 +11,16 @@ NavigationPage {
wrapMode: Text.Wrap wrapMode: Text.Wrap
} }
ChangeNumberItem { EditValueItem {
descriptionText: qsTr("Price limit") id: test
valueText: qsTr("%0 ct/kWh").arg(0) text: qsTr("Price limit")
valueText: qsTr("%0 ct/kWh").arg(test.value)
apiKey: "awp"
editableItem: DoubleSpinBox {
from: -1000.
to: 1000.
stepSize: .1
}
} }
Item { Item {

13
SetValueHelper.qml Normal file
View File

@@ -0,0 +1,13 @@
import EVChargerApp
SendMessageHelper {
required property string apiKey
function setValue(value) {
sendMessage({
type: "setValue",
key: apiKey,
value: value
})
}
}

View File

@@ -18,9 +18,10 @@ WhiteCheckDelegate {
apiKey: "wen" apiKey: "wen"
} }
SendMessageHelper { SetValueHelper {
id: staEnabledChanger id: staEnabledChanger
deviceConnection: theDeviceConnection deviceConnection: theDeviceConnection
apiKey: "wen"
} }
checked: staEnabled.value checked: staEnabled.value
@@ -28,11 +29,7 @@ WhiteCheckDelegate {
onClicked: { onClicked: {
if (checked) if (checked)
staEnabledChanger.sendMessage({ staEnabledChanger.setValue(checked)
type: "setValue",
key: "wen",
value: checked
})
else { else {
checked = true checked = true
disableStaDialog.open() disableStaDialog.open()
@@ -57,11 +54,7 @@ WhiteCheckDelegate {
onAccepted: { onAccepted: {
checkDelegate.checked = false checkDelegate.checked = false
staEnabledChanger.sendMessage({ staEnabledChanger.setValue(false)
type: "setValue",
key: "wen",
value: false
})
} }
onRejected: checkDelegate.checked = Qt.binding(function() { return staEnabled.value }) onRejected: checkDelegate.checked = Qt.binding(function() { return staEnabled.value })

4
qmldir
View File

@@ -13,7 +13,6 @@ EVChargerApp 1.0 BaseNavigationPage.qml
EVChargerApp 1.0 CablePage.qml EVChargerApp 1.0 CablePage.qml
EVChargerApp 1.0 CarPage.qml EVChargerApp 1.0 CarPage.qml
EVChargerApp 1.0 CenteredDialog.qml EVChargerApp 1.0 CenteredDialog.qml
EVChargerApp 1.0 ChangeNumberItem.qml
EVChargerApp 1.0 ChargerTabPage.qml EVChargerApp 1.0 ChargerTabPage.qml
EVChargerApp 1.0 ChargingConfigurationPage.qml EVChargerApp 1.0 ChargingConfigurationPage.qml
EVChargerApp 1.0 ChargingSpeedPage.qml EVChargerApp 1.0 ChargingSpeedPage.qml
@@ -29,7 +28,9 @@ EVChargerApp 1.0 DateAndTimePage.qml
EVChargerApp 1.0 DeviceListScreen.qml EVChargerApp 1.0 DeviceListScreen.qml
EVChargerApp 1.0 DeviceScreen.qml EVChargerApp 1.0 DeviceScreen.qml
EVChargerApp 1.0 DisplaySettingsPage.qml EVChargerApp 1.0 DisplaySettingsPage.qml
EVChargerApp 1.0 DoubleSpinBox.qml
EVChargerApp 1.0 EcoTabPage.qml EVChargerApp 1.0 EcoTabPage.qml
EVChargerApp 1.0 EditValueItem.qml
EVChargerApp 1.0 EthernetPage.qml EVChargerApp 1.0 EthernetPage.qml
EVChargerApp 1.0 EVChargerApp.qml EVChargerApp 1.0 EVChargerApp.qml
EVChargerApp 1.0 FirmwarePage.qml EVChargerApp 1.0 FirmwarePage.qml
@@ -64,6 +65,7 @@ EVChargerApp 1.0 SelectLogicModeItem.qml
EVChargerApp 1.0 SensorsConfigurationPage.qml EVChargerApp 1.0 SensorsConfigurationPage.qml
EVChargerApp 1.0 SetPriceLimitPage.qml EVChargerApp 1.0 SetPriceLimitPage.qml
EVChargerApp 1.0 SettingsTabPage.qml EVChargerApp 1.0 SettingsTabPage.qml
EVChargerApp 1.0 SetValueHelper.qml
EVChargerApp 1.0 SimpleNavigationItem.qml EVChargerApp 1.0 SimpleNavigationItem.qml
EVChargerApp 1.0 SwitchLanguagePage.qml EVChargerApp 1.0 SwitchLanguagePage.qml
EVChargerApp 1.0 TimeComponentLabel.qml EVChargerApp 1.0 TimeComponentLabel.qml