From f076cdb88fdc74557b1e2202f8fde403bffc562a Mon Sep 17 00:00:00 2001 From: Richard Genoud Date: Sun, 22 Dec 2019 10:02:58 +0100 Subject: [PATCH] thermostat: settings: don't use another QSettings instance --- soft/thermostat/inc/settings.h | 2 +- soft/thermostat/src/settings.cpp | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/soft/thermostat/inc/settings.h b/soft/thermostat/inc/settings.h index 79c8949..f0fdbef 100644 --- a/soft/thermostat/inc/settings.h +++ b/soft/thermostat/inc/settings.h @@ -41,7 +41,7 @@ public: struct Brocker m_broker; private: - Settings(void); + explicit Settings(QObject *parent = Q_NULLPTR); ~Settings(void); static Settings *_singleton; diff --git a/soft/thermostat/src/settings.cpp b/soft/thermostat/src/settings.cpp index ab5b851..939f8ef 100644 --- a/soft/thermostat/src/settings.cpp +++ b/soft/thermostat/src/settings.cpp @@ -7,42 +7,42 @@ */ #include +#include #include #include "settings.h" Settings *Settings::_singleton = NULL; -Settings::Settings(void) +Settings::Settings(QObject *parent) : QSettings(parent) { - QSettings s; struct Room room; struct Heater heater; int nb_rooms; - nb_rooms = s.beginReadArray("rooms"); + nb_rooms = this->beginReadArray("rooms"); if (nb_rooms > MAX_NB_ZONES) { // TODO; nb_rooms = MAX_NB_ZONES; } for (int i = 0; i < nb_rooms; ++i) { - s.setArrayIndex(i); - room.name = s.value("name", "").toString(); - room.sensor_topic = s.value("sensor_topic", "").toString(); - room.availability_topic = s.value("availability_topic", "").toString(); - int size = s.beginReadArray("heaters"); + this->setArrayIndex(i); + room.name = this->value("name", "").toString(); + room.sensor_topic = this->value("sensor_topic", "").toString(); + room.availability_topic = this->value("availability_topic", "").toString(); + int size = this->beginReadArray("heaters"); for (int j = 0; j < size; ++j) { - s.setArrayIndex(j); - heater.ctrl_topic = s.value("control_topic", "").toString(); + this->setArrayIndex(j); + heater.ctrl_topic = this->value("control_topic", "").toString(); room.heaters << heater; } - s.endArray(); + this->endArray(); m_rooms << room; } - s.endArray(); - m_broker.address = s.value("broker/address", "localhost").toString(); - m_broker.port = s.value("broker/port", 1883).toInt(); + this->endArray(); + m_broker.address = this->value("broker/address", "localhost").toString(); + m_broker.port = this->value("broker/port", 1883).toInt(); } int Settings::nbZones(void) @@ -57,7 +57,7 @@ Settings::~Settings(void) Settings *Settings::getInstance(void) { if (!_singleton) { - _singleton = new Settings; + _singleton = new Settings(); } return _singleton;