Save settings after releasing the sliders

This commit is contained in:
Matti Viljanen 2020-04-26 18:23:35 +03:00
parent c0e8004cc2
commit a5d8ae0fa3
No known key found for this signature in database
GPG key ID: CF32A1495158F888
2 changed files with 21 additions and 7 deletions

View file

@ -103,10 +103,13 @@ Page {
valueText: value + "%" valueText: value + "%"
highlightDirection: Qt.RightToLeft highlightDirection: Qt.RightToLeft
onValueChanged: { onValueChanged: {
settings.highLimit = value
if(lowLimitSlider.value >= value) if(lowLimitSlider.value >= value)
lowLimitSlider.value = value - 1 lowLimitSlider.value = value - 1
} }
onReleased: {
settings.lowLimit = lowLimitSlider.value
settings.highLimit = value
}
} }
MySlider { MySlider {
id: lowLimitSlider id: lowLimitSlider
@ -118,10 +121,13 @@ Page {
stepSize: 1 stepSize: 1
valueText: value + "%" valueText: value + "%"
onValueChanged: { onValueChanged: {
settings.lowLimit = value
if(highLimitSlider.value <= value) if(highLimitSlider.value <= value)
highLimitSlider.value = value + 1 highLimitSlider.value = value + 1
} }
onReleased: {
settings.lowLimit = value
settings.highLimit = highLimitSlider.value
}
} }
} }
Column { Column {
@ -149,10 +155,13 @@ Page {
valueText: value + "%" valueText: value + "%"
highlightDirection: Qt.RightToLeft highlightDirection: Qt.RightToLeft
onValueChanged: { onValueChanged: {
settings.highAlert = value
if(lowAlertSlider.value >= value) if(lowAlertSlider.value >= value)
lowAlertSlider.value = value - 1 lowAlertSlider.value = value - 1
} }
onReleased: {
settings.lowAlert = lowAlertSlider.value
settings.highAlert = value
}
} }
MySlider { MySlider {
id: lowAlertSlider id: lowAlertSlider
@ -163,10 +172,13 @@ Page {
stepSize: 1 stepSize: 1
valueText: value + "%" valueText: value + "%"
onValueChanged: { onValueChanged: {
settings.lowAlert = value
if(highAlertSlider.value <= value) if(highAlertSlider.value <= value)
highAlertSlider.value = value + 1 highAlertSlider.value = value + 1
} }
onReleased: {
settings.lowAlert = value
settings.highAlert = highAlertSlider.value
}
} }
MySlider { MySlider {
id: intervalSlider id: intervalSlider
@ -176,7 +188,7 @@ Page {
maximumValue: 600 maximumValue: 600
stepSize: 10 stepSize: 10
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 onReleased: settings.interval = value
} }
} }
} }

View file

@ -82,7 +82,8 @@ QString Settings::getNotificationHighText() { return notificationHighText; }
void Settings::setLowAlert(int newLimit) { void Settings::setLowAlert(int newLimit) {
lowAlert = newLimit; lowAlert = newLimit;
saveInteger(sLowAlert, &lowAlert); saveInteger(sLowAlert, &lowAlert);
mySettings->sync(); // Lows and highs are always saved in pairs!
//mySettings->sync();
emit lowAlertChanged(lowAlert); emit lowAlertChanged(lowAlert);
qDebug() << "Change" << sLowAlert << newLimit; qDebug() << "Change" << sLowAlert << newLimit;
} }
@ -106,7 +107,8 @@ void Settings::setInterval(int newInterval) {
void Settings::setLowLimit(int newLimit) { void Settings::setLowLimit(int newLimit) {
lowLimit = newLimit; lowLimit = newLimit;
saveInteger(sLowLimit, &lowLimit); saveInteger(sLowLimit, &lowLimit);
mySettings->sync(); // Lows and highs are always saved in pairs!
//mySettings->sync();
emit lowLimitChanged(lowLimit); emit lowLimitChanged(lowLimit);
qDebug() << "Change" << sLowLimit << newLimit; qDebug() << "Change" << sLowLimit << newLimit;
} }