Commit 9fde4116 authored by Leander Schulten's avatar Leander Schulten

update Settings API so that the local settings file is loaded for every Settings object

parent 015f0362
......@@ -116,7 +116,8 @@ int main(int argc, char *argv[])
qRegisterMetaType<Modules::PropertiesVector*>("PropertiesVector*");
// Load Settings and ApplicationData
Settings settings(QFileInfo("settings.ini"));
Settings::setLocalSettingFile(QFileInfo("settings.ini"));
Settings settings;
QFile file("QTJSONFile.json");
if(!file.exists()){
file.setFileName(settings.getJsonSettingsFilePath());
......
#include "settings.h"
Settings::Settings(QObject *parent) : QObject(parent), settings("Turmstraße 1 e.V.","Lichtsteuerung")
{
Modules::Compiler::compilerCmd = settings.value("compilerCmd",Modules::Compiler::compilerCmd).toString();
Modules::Compiler::compilerFlags = settings.value("compilerFlags",Modules::Compiler::compilerFlags).toString();
Modules::Compiler::compilerLibraryFlags = settings.value("compilerLibraryFlags",Modules::Compiler::compilerLibraryFlags).toString();
Modules::Compiler::includePath = settings.value("includePath",Modules::Compiler::includePath).toString();
}
QFileInfo Settings::localSettingsFile;
Settings::Settings(const QFileInfo &settingsFile, QObject *parent) : QObject(parent), settings("Turmstraße 1 e.V.","Lichtsteuerung"), localSettings(QVariant::fromValue(new QSettings(settingsFile.filePath(),QSettings::IniFormat)))
Settings::Settings(QObject *parent) : QObject(parent), settings("Turmstraße 1 e.V.","Lichtsteuerung")
{
localSettings.value<QSettings*>()->setIniCodec("UTF-8");
if(localSettingsFile.exists()){
localSettings = QVariant::fromValue(new QSettings(localSettingsFile.filePath(),QSettings::IniFormat));
localSettings.value<QSettings*>()->setIniCodec("UTF-8");
}
Modules::Compiler::compilerCmd = value("compilerCmd",Modules::Compiler::compilerCmd).toString();
Modules::Compiler::compilerFlags = value("compilerFlags",Modules::Compiler::compilerFlags).toString();
Modules::Compiler::compilerLibraryFlags = value("compilerLibraryFlags",Modules::Compiler::compilerLibraryFlags).toString();
Modules::Compiler::includePath = value("includePath",Modules::Compiler::includePath).toString();
}
Settings::~Settings(){
if(localSettings.isValid()){
delete localSettings.value<QSettings*>();
}
}
void Settings::setValue(const QString &key, const QVariant &value){
if(localSettings.isValid()){
if(localSettings.value<QSettings*>()->contains(key)){
......
......@@ -21,12 +21,21 @@ class Settings : public QObject
Q_PROPERTY(QString includePath READ getIncludePath WRITE setIncludePath NOTIFY includePathChanged)
Q_PROPERTY(QString audioCaptureFilePath READ getAudioCaptureFilePath WRITE setAudioCaptureFilePath NOTIFY audioCaptureFilePathChanged)
Q_PROPERTY(unsigned int updatePauseInMs READ getUpdatePauseInMs WRITE setUpdatePauseInMs NOTIFY updatePauseInMsChanged)
static QFileInfo localSettingsFile;
public:
/**
* @brief setLocalSettingFile sets a localSetting file that is loaded and preferred everytime a Settings object is created
* @param settingFile the filePath to the local setting file in utf8 ini format
*/
static void setLocalSettingFile(const QFileInfo & settingFile){
localSettingsFile = settingFile;
}
protected:
void setValue(const QString &key, const QVariant &value);
QVariant value(const QString &key, const QVariant &defaultValue = QVariant())const;
public:
explicit Settings(QObject *parent = nullptr);
Settings(const QFileInfo & settingsFile, QObject *parent = nullptr);
~Settings();
void setJsonSettingsFilePath(QString file){
if(file == getJsonSettingsFilePath())return;
if(QFile::exists(file)){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment