Added SettingsHandler class.
This commit is contained in:
@ -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
43
data/settingshandler.cpp
Normal 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
15
data/settingshandler.h
Normal 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
|
||||
@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user