Fix QSettings not getting saved, get rid of load() and save()

This commit is contained in:
Matti Viljanen 2019-01-08 20:19:54 +02:00
parent ad28b2e402
commit 960750f2a7
No known key found for this signature in database
GPG key ID: CF32A1495158F888
2 changed files with 14 additions and 13 deletions

View file

@ -17,29 +17,30 @@
*/
#include "settings.h"
Settings::Settings(QObject *parent) : QObject(parent) { load(); }
Settings::~Settings() { save(); }
void Settings::load()
Settings::Settings(QObject *parent) : QObject(parent)
{
QSettings mySettings;
qDebug() << "Loading settings from" << mySettings.fileName();
int tempValue;
if(mySettings.contains("lowerLimit")) {
tempValue = mySettings.value("lowerLimit").toInt();
if(tempValue <= 10 && tempValue >= 99)
if(tempValue >= 10 && tempValue <= 50) {
lowerLimit = tempValue;
qDebug() << "Lower limit:" << lowerLimit;
emit lowerLimitChanged();
}
}
if(mySettings.contains("upperLimit")) {
tempValue = mySettings.value("upperLimit").toInt();
if(tempValue <= 60 && tempValue >= 99)
if(tempValue >= 60 && tempValue <= 100) {
upperLimit = tempValue;
qDebug() << "Upper limit:" << upperLimit;
emit upperLimitChanged();
}
}
}
void Settings::save()
Settings::~Settings()
{
QSettings mySettings;
mySettings.setValue("lowerLimit", QByteArray::number(lowerLimit));
mySettings.setValue("upperLimit", QByteArray::number(upperLimit));
}

View file

@ -20,6 +20,7 @@
#include <QObject>
#include <QSettings>
#include <QDebug>
class Settings : public QObject
{
@ -42,15 +43,14 @@ public:
void setUpperLimit(int newLimit);
private:
QSettings mySettings;
// Default values
int lowerLimit = 25;
int upperLimit = 75;
QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav";
QString highAlertFile = "/usr/share/sounds/jolla-ambient/stereo/positive_confirmation.wav";
void load();
void save();
signals:
int lowerLimitChanged();
int upperLimitChanged();