Update Settings page values correctly

This commit is contained in:
Matti Viljanen 2020-03-21 05:04:52 +02:00
parent 02b3f40524
commit 193dc5dccf
No known key found for this signature in database
GPG key ID: CF32A1495158F888
2 changed files with 18 additions and 10 deletions

View file

@ -24,7 +24,22 @@ Page {
onStatusChanged: { onStatusChanged: {
if(status === PageStatus.Activating) { if(status === PageStatus.Activating) {
autoStopCharging.checked = settings.notificationsEnabled settingsTimer.start()
}
}
Timer {
id: settingsTimer
interval: 10
repeat: false
onTriggered: {
autoStopCharging.checked = settings.limitEnabled
highLimitSlider.value = settings.highLimit
lowLimitSlider.value = settings.lowLimit
notificationsSwitch.checked = settings.notificationsEnabled
highAlertSlider.value = settings.highAlert
lowAlertSlider.value = settings.lowAlert
intervalSlider.value = settings.interval
} }
} }
@ -32,8 +47,6 @@ Page {
anchors.fill: parent anchors.fill: parent
contentHeight: header.height + settingsColumn.height + Theme.horizontalPageMargin contentHeight: header.height + settingsColumn.height + Theme.horizontalPageMargin
VerticalScrollDecorator { flickable: mainFlickable }
PullDownMenu { PullDownMenu {
MenuItem { MenuItem {
text: qsTr("About", "About this application") text: qsTr("About", "About this application")
@ -76,7 +89,6 @@ Page {
minimumValue: 21 minimumValue: 21
maximumValue: 95 maximumValue: 95
stepSize: 1 stepSize: 1
Component.onCompleted: value = settings.highLimit
valueText: value + "%" valueText: value + "%"
highlightDirection: Qt.RightToLeft highlightDirection: Qt.RightToLeft
onValueChanged: { onValueChanged: {
@ -93,7 +105,6 @@ Page {
minimumValue: 20 minimumValue: 20
maximumValue: 94 maximumValue: 94
stepSize: 1 stepSize: 1
Component.onCompleted: value = settings.lowLimit
valueText: value + "%" valueText: value + "%"
onValueChanged: { onValueChanged: {
settings.lowLimit = value settings.lowLimit = value
@ -110,7 +121,6 @@ Page {
id: notificationsSwitch id: notificationsSwitch
text: qsTr("Use notifications") text: qsTr("Use notifications")
description: qsTr("When the application is minimized, display visual and audible notifications about reached battery charge levels.") description: qsTr("When the application is minimized, display visual and audible notifications about reached battery charge levels.")
Component.onCompleted: checked = settings.notificationsEnabled
onCheckedChanged: settings.notificationsEnabled = checked onCheckedChanged: settings.notificationsEnabled = checked
} }
MySlider { MySlider {
@ -120,7 +130,6 @@ Page {
minimumValue: 11 minimumValue: 11
maximumValue: 100 maximumValue: 100
stepSize: 1 stepSize: 1
Component.onCompleted: value = settings.highAlert
valueText: value + "%" valueText: value + "%"
highlightDirection: Qt.RightToLeft highlightDirection: Qt.RightToLeft
onValueChanged: { onValueChanged: {
@ -136,7 +145,6 @@ Page {
minimumValue: 10 minimumValue: 10
maximumValue: 99 maximumValue: 99
stepSize: 1 stepSize: 1
Component.onCompleted: value = settings.lowAlert
valueText: value + "%" valueText: value + "%"
onValueChanged: { onValueChanged: {
settings.lowAlert = value settings.lowAlert = value
@ -145,12 +153,12 @@ Page {
} }
} }
MySlider { MySlider {
id: intervalSlider
width: parent.width width: parent.width
label: qsTr("Notification interval") label: qsTr("Notification interval")
minimumValue: 60 minimumValue: 60
maximumValue: 600 maximumValue: 600
stepSize: 10 stepSize: 10
Component.onCompleted: value = settings.interval
valueText: Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60) valueText: Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
onValueChanged: settings.interval = value onValueChanged: settings.interval = value
} }

View file

@ -53,7 +53,7 @@ Settings::~Settings()
saveInteger(sLowLimit, &lowLimit); saveInteger(sLowLimit, &lowLimit);
saveInteger(sHighLimit, &highLimit); saveInteger(sHighLimit, &highLimit);
mySettings.sync(); mySettings.sync();
qInfo() << "Settings saved:" << mySettings.status() == QSettings::NoError; qInfo() << "Settings saved:" << (mySettings.status() == QSettings::NoError);
} }
int Settings::getLowAlert() { int Settings::getLowAlert() {