This repository has been archived on 2022-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
fanny-app/sources/appsettings.cpp
dorian f7d5a111d0 added header to the event view, showing:
- creation date
- target date
- cleaning class

added one event block underneath the header indicating what the different fields contain
2018-12-26 23:44:24 +01:00

121 lines
3 KiB
C++

#include "headers/appsettings.h"
AppSettings * pGlobalAppSettings = nullptr;
AppSettings::AppSettings(QObject* parent)
:QObject(parent)
{
qDebug("+----- AppSettings konstruktor -----");
pGlobalAppSettings = this;
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
qDebug() << "+----- Settings Path:" << path;
this->settingsManager = new QSettings(path+"/fannyapp/settings.ini", QSettings::IniFormat);
if(loadSetting("init") == "false"){
this->writeSetting("init", 0);
}
if(loadSetting("grade") == "false"){
this->writeSetting("grade", 5);
}
this->filtersFile = new QFile(path + "/fannyapp/filters.json");
//QList<QStringList> filters = {{"5", "d"}, {"6", "c"}, {"11", ""}};
//writeFilters(filters);
//qDebug() << readFilters();
}
QString AppSettings::loadSetting(const QString &key)
{
this->settingsManager->beginGroup("AppSettings");
QString value = this->settingsManager->value(key , false).toString();
this->settingsManager->endGroup();
return(value);
}
void AppSettings::writeSetting(const QString &key, const QVariant &variant)
{
this->settingsManager->beginGroup("AppSettings");
this->settingsManager->setValue(key , variant);
this->settingsManager->endGroup();
}
QList<QStringList> AppSettings::readFilters() {
// list to be returned
QList<QStringList> filtersList;
this->filtersFile->open(QFile::ReadOnly | QFile::Text);
QString jsonString = this->filtersFile->readAll();
this->filtersFile->close();
//qDebug() << jsonString;
QJsonDocument jsonFilters = QJsonDocument::fromJson(jsonString.toUtf8());
// array with all filters in it
QJsonArray filtersArray = jsonFilters.array();
foreach(const QJsonValue & value, filtersArray){
// array of a single filter
QJsonArray filterArray = value.toArray();
// extract values from array
QString gradeString = filterArray[0].toString();
QString letterString = filterArray[1].toString();
filtersList.append({gradeString, letterString});
}
return(filtersList);
}
void AppSettings::writeFilters(QList<QStringList> list) {
// string to write to file
QString jsonString;
QJsonArray filtersArray;
foreach(QStringList filter, list){
QJsonArray filterArray;
filterArray.append(filter[0]);
filterArray.append(filter[1]);
filtersArray.append(filterArray);
}
QJsonDocument filtersDoc(filtersArray);
//qDebug() << filtersDoc.toJson();
this->filtersFile->open(QIODevice::ReadWrite);
this->filtersFile->resize(0);
this->filtersFile->write(filtersDoc.toJson());
this->filtersFile->close();
}
QStringList AppSettings::readFiltersQml() {
QStringList filtersList;
foreach(QStringList filterList, this->readFilters()){
filtersList.append(filterList[0]+"|"+filterList[1]);
}
return(filtersList);
}
void AppSettings::writeFiltersQml(QStringList) {
}
AppSettings::~AppSettings()
{
delete settingsManager;
}