From 2854217108c0736c02ad0d938fad71590515d5bc Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Fri, 20 Mar 2020 23:00:30 +0200 Subject: [PATCH] Massive typofix in settings' key names, optimize constructor --- qml/pages/SettingsPage.qml | 12 ++++---- src/settings.cpp | 60 +++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index 61bf759..a040533 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -75,7 +75,7 @@ Page { valueText: value + "%" highlightDirection: Qt.RightToLeft onValueChanged: { - settings.highLimit = value + settings.highAlert = value if(lowAlertSlider.value >= value) lowAlertSlider.value = value - 1 } @@ -90,7 +90,7 @@ Page { value: settings.lowAlert valueText: value + "%" onValueChanged: { - settings.highLimit = value + settings.lowAlert = value if(highAlertSlider.value <= value) highAlertSlider.value = value + 1 } @@ -111,11 +111,11 @@ Page { minimumValue: 20 maximumValue: 95 stepSize: 1 - value: settings.lowLimit + value: settings.highLimit valueText: value + "%" highlightDirection: Qt.RightToLeft onValueChanged: { - settings.lowLimit = value + settings.highLimit = value if(lowLimitSlider.value >= value) lowLimitSlider.value = value - 1 } @@ -128,10 +128,10 @@ Page { minimumValue: 20 maximumValue: 95 stepSize: 1 - value: settings.highLimit + value: settings.lowLimit valueText: value + "%" onValueChanged: { - settings.highLimit = value + settings.lowLimit = value if(highLimitSlider.value <= value) highLimitSlider.value = value + 1 } diff --git a/src/settings.cpp b/src/settings.cpp index 16dff8d..6dd0c03 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -20,44 +20,36 @@ Settings::Settings(QObject *parent) : QObject(parent) { int tempValue; - if(mySettings.contains(sLowAlert)) { - tempValue = mySettings.value(sLowAlert).toInt(); - if(tempValue >= 10 && tempValue <= 99) { - lowAlert = tempValue; - emit lowAlertChanged(); - } + tempValue = mySettings.value(sLowAlert, lowAlert).toInt(); + if(tempValue >= 10 && tempValue <= 99) { + lowAlert = tempValue; + emit lowAlertChanged(); } - if(mySettings.contains(sHighAlert)) { - tempValue = mySettings.value(sHighAlert).toInt(); - if(tempValue >= 10 && tempValue <= 99) { - highAlert = tempValue; - emit highAlertChanged(); - } + + tempValue = mySettings.value(sHighAlert, highAlert).toInt(); + if(tempValue >= 10 && tempValue <= 99) { + highAlert = tempValue; + emit highAlertChanged(); } - if(mySettings.contains(sInterval)) { - tempValue = mySettings.value(sInterval).toInt(); - if(tempValue >= 60 && tempValue <= 600) { - interval = tempValue; - emit intervalChanged(); - } + + tempValue = mySettings.value(sInterval, interval).toInt(); + if(tempValue >= 60 && tempValue <= 600) { + interval = tempValue; + emit intervalChanged(); } - if(mySettings.contains(sLimitEnabled)) { - limitEnabled = (mySettings.value(sLimitEnabled).toInt() == 1); - emit limitEnabledChanged(); + + limitEnabled = (mySettings.value(sLimitEnabled, sLimitEnabled).toInt() == 1); + emit limitEnabledChanged(); + tempValue = mySettings.value(sLowLimit).toInt(); + if(tempValue >= 20 && tempValue <= 95) { + lowLimit = tempValue; + emit lowLimitChanged(); } - if(mySettings.contains(sLowLimit)) { - tempValue = mySettings.value(sLowLimit).toInt(); - if(tempValue >= 20 && tempValue <= 95) { - lowLimit = tempValue; - emit lowLimitChanged(); - } - } - if(mySettings.contains(sHighLimit)) { - tempValue = mySettings.value(sHighLimit).toInt(); - if(tempValue >= 20 && tempValue <= 95) { - highLimit = tempValue; - emit highLimitChanged(); - } + + tempValue = mySettings.value(sHighLimit, highLimit).toInt(); + if(tempValue >= 20 && tempValue <= 95) { + highLimit = tempValue; + emit highLimitChanged(); } }