Added SettingsHandler class.
This commit is contained in:
@ -21,6 +21,7 @@ add_library(${TARGET_APP} STATIC
|
|||||||
genericcore.h
|
genericcore.h
|
||||||
${TS_FILES}
|
${TS_FILES}
|
||||||
constants.h
|
constants.h
|
||||||
|
data/settingshandler.h data/settingshandler.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
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
|
/// setting the applicationDirPath hard coded to test update feature from IDE
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
|
// REFACTOR retrieve application name automatically instead of using hard coded name
|
||||||
applicationDirPath = "/opt/GenericQtClient";
|
applicationDirPath = "/opt/GenericQtClient";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user