Added SettingsHandler class.

This commit is contained in:
2025-10-31 15:24:06 +01:00
parent d943f2d89a
commit 7ba0304232
4 changed files with 60 additions and 0 deletions

View File

@ -21,6 +21,7 @@ add_library(${TARGET_APP} STATIC
genericcore.h
${TS_FILES}
constants.h
data/settingshandler.h data/settingshandler.cpp
)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

43
data/settingshandler.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "settingshandler.h"
#include <QSettings>
QVariantMap SettingsHandler::getSettings(QString group) {
QSettings settings;
QVariantMap result;
if (!group.isEmpty()) {
settings.beginGroup(group);
}
foreach (QString key, settings.allKeys()) {
result.insert(key, settings.value(key));
}
if (!group.isEmpty()) {
settings.endGroup();
}
return result;
}
void SettingsHandler::saveSettings(QVariantMap settingMap, QString group) {
qInfo() << "saving settings...";
QSettings settings;
if (!group.isEmpty()) {
settings.beginGroup(group);
}
foreach (QString key, settingMap.keys()) {
// qDebug() << "saving:" << key << "-" << settingMap.value(key);
settings.setValue(key, settingMap.value(key));
}
if (!group.isEmpty()) {
settings.endGroup();
}
settings.sync();
}
SettingsHandler::SettingsHandler() {}

15
data/settingshandler.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef SETTINGSHANDLER_H
#define SETTINGSHANDLER_H
#include <QVariantMap>
class SettingsHandler {
public:
static QVariantMap getSettings(QString group = "");
static void saveSettings(QVariantMap settingMap, QString group = "");
private:
SettingsHandler();
};
#endif // SETTINGSHANDLER_H

View File

@ -69,6 +69,7 @@ QString GenericCore::getMaintenanceToolFilePath() const {
/// setting the applicationDirPath hard coded to test update feature from IDE
#ifdef QT_DEBUG
// REFACTOR retrieve application name automatically instead of using hard coded name
applicationDirPath = "/opt/GenericQtClient";
#endif