Fix QSettings not getting saved, get rid of load() and save()
This commit is contained in:
parent
ad28b2e402
commit
960750f2a7
2 changed files with 14 additions and 13 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue