Commit dc501ae2 authored by Leander Schulten's avatar Leander Schulten
Browse files

Added possibility to load settings from local settings.ini file in the same...

Added possibility to load settings from local settings.ini file in the same dir as the executable. If a setting is not found in the local ini-file, it is loaded from the global settings
parent 841a6a91
......@@ -114,17 +114,23 @@ int main(int argc, char *argv[])
qRegisterMetaType<Modules::ValueType>("ValueType");
qRegisterMetaType<Modules::ProgramBlock::Status>("Status");
qRegisterMetaType<Modules::PropertiesVector*>("PropertiesVector*");
Settings settings;
settings.setJsonSettingsFilePath("QTJSONFile.json");
QFile file(settings.getJsonSettingsFilePath());
file.copy(settings.getJsonSettingsFilePath()+"_"+QDateTime::currentDateTime().toString("dd.MM.YYYY HH.mm.ss"));
// Load Settings and ApplicationData
Settings settings(QFileInfo("settings.ini"));
QFile file("QTJSONFile.json");
if(!file.exists()){
file.setFileName(settings.getJsonSettingsFilePath());
}
if(file.exists()){
file.copy(file.fileName()+"_"+QDateTime::currentDateTime().toString("dd.MM.yyyy HH.mm.ss"));
}
auto after = ApplicationData::loadData(file);
//#warning Dont use IDBase<xxxxx>::getAllIDBases() in this file. It will crash the aplication when its closing
std::thread t(Test::testLoopProgramm);
t.join();
auto after = ApplicationData::loadData(file);
QStringList dataList;
......
......@@ -8,3 +8,29 @@ Settings::Settings(QObject *parent) : QObject(parent), settings("Turmstraße 1 e
Modules::Compiler::compilerLibraryFlags = settings.value("compilerLibraryFlags",Modules::Compiler::compilerLibraryFlags).toString();
Modules::Compiler::includePath = settings.value("includePath",Modules::Compiler::includePath).toString();
}
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)))
{
localSettings.value<QSettings*>()->setIniCodec("UTF-8");
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();
}
void Settings::setValue(const QString &key, const QVariant &value){
if(localSettings.isValid()){
if(localSettings.value<QSettings*>()->contains(key)){
localSettings.value<QSettings*>()->setValue(key,value);
}
}
settings.setValue(key,value);
}
QVariant Settings::value(const QString &key, const QVariant &defaultValue) const{
if(localSettings.isValid()){
if(localSettings.value<QSettings*>()->contains(key)){
return localSettings.value<QSettings*>()->value(key,defaultValue);
}
}
return settings.value(key,defaultValue);
}
......@@ -11,6 +11,7 @@ class Settings : public QObject
{
Q_OBJECT
QSettings settings;
QVariant localSettings; //TODO replace with std::optionl when using c++17
Q_PROPERTY(QString jsonSettingsFilePath READ getJsonSettingsFilePath WRITE setJsonSettingsFilePath NOTIFY jsonSettingsFilePathChanged)
Q_PROPERTY(QString driverFilePath READ getDriverFilePath WRITE setDriverFilePath NOTIFY driverFilePathChanged)
Q_PROPERTY(QString moduleDirPath READ getModuleDirPath WRITE setModuleDirPath NOTIFY moduleDirPathChanged)
......@@ -20,55 +21,59 @@ 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)
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);
void setJsonSettingsFilePath(QString file){
if(file == getJsonSettingsFilePath())return;
if(QFile::exists(file)){
settings.setValue("jsonSettingsFilePath",file);
setValue("jsonSettingsFilePath",file);
emit jsonSettingsFilePathChanged();
}
}
QString getJsonSettingsFilePath()const{return settings.value("jsonSettingsFilePath").toString();}
QString getJsonSettingsFilePath()const{return value("jsonSettingsFilePath").toString();}
void setDriverFilePath(QString file){
if(file == getDriverFilePath())return;
if(QFile::exists(file)){
settings.setValue("driverFilePath",file);
setValue("driverFilePath",file);
emit driverFilePathChanged();
}
}
QString getDriverFilePath()const{return settings.value("driverFilePath").toString();}
QString getDriverFilePath()const{return value("driverFilePath").toString();}
void setAudioCaptureFilePath(QString file){
if(file == getAudioCaptureFilePath()){
return;
}
if(QFile::exists(file)){
settings.setValue("audioCaptureFilePath",file);
setValue("audioCaptureFilePath",file);
emit audioCaptureFilePathChanged();
}
}
QString getAudioCaptureFilePath()const{return settings.value("audioCaptureFilePath").toString();}
QString getAudioCaptureFilePath()const{return value("audioCaptureFilePath").toString();}
void setUpdatePauseInMs(unsigned int pause){settings.setValue("updatePauseInMs",pause);emit updatePauseInMsChanged();}
unsigned int getUpdatePauseInMs()const{return settings.value("updatePauseInMs").toUInt();}
void setUpdatePauseInMs(unsigned int pause){setValue("updatePauseInMs",pause);emit updatePauseInMsChanged();}
unsigned int getUpdatePauseInMs()const{return value("updatePauseInMs").toUInt();}
void setModuleDirPath( const QString &_moduleDirPath){
if(_moduleDirPath == getModuleDirPath())
return;
if(!QDir(_moduleDirPath).exists())
return;
settings.setValue("moduleDirPath",_moduleDirPath);
setValue("moduleDirPath",_moduleDirPath);
emit moduleDirPathChanged();
}
QString getModuleDirPath() const {
return settings.value("moduleDirPath").toString();
return value("moduleDirPath").toString();
}
void setCompilerPath( const QString _compilerPath){
void setCompilerPath( const QString &_compilerPath){
if(_compilerPath != Modules::Compiler::compilerCmd){
settings.setValue("compilerCmd",_compilerPath);
setValue("compilerCmd",_compilerPath);
Modules::Compiler::compilerCmd = _compilerPath;
emit compilerPathChanged();
}
......@@ -76,10 +81,10 @@ public:
QString getCompilerPath() const {
return Modules::Compiler::compilerCmd;
}
void setIncludePath( const QString _includePath){
void setIncludePath( const QString &_includePath){
if(_includePath != Modules::Compiler::includePath){
Modules::Compiler::includePath = _includePath;
settings.setValue("includePath",_includePath);
setValue("includePath",_includePath);
emit includePathChanged();
}
}
......@@ -87,9 +92,9 @@ public:
return Modules::Compiler::includePath;
}
void setCompilerFlags( const QString _compilerFlags){
void setCompilerFlags( const QString &_compilerFlags){
if(_compilerFlags != Modules::Compiler::compilerFlags){
settings.setValue("compilerFlags",_compilerFlags);
setValue("compilerFlags",_compilerFlags);
Modules::Compiler::compilerFlags = _compilerFlags;
emit compilerFlagsChanged();
}
......@@ -98,9 +103,9 @@ public:
return Modules::Compiler::compilerFlags;
}
void setCompilerLibraryFlags( const QString _compilerLibraryFlags){
void setCompilerLibraryFlags( const QString &_compilerLibraryFlags){
if(_compilerLibraryFlags != Modules::Compiler::compilerLibraryFlags){
settings.setValue("compilerLibraryFlags",_compilerLibraryFlags);
setValue("compilerLibraryFlags",_compilerLibraryFlags);
Modules::Compiler::compilerLibraryFlags = _compilerLibraryFlags; emit compilerLibraryFlagsChanged();
}
}
......
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