This repository has been archived by the owner on Mar 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appsettings.cpp
77 lines (70 loc) · 2.29 KB
/
appsettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// SmartServer
// Copyright (C) 2021 АО "Нефтеавтоматика"
//
// Разработчик
// Ананьев А.А. <Ananev-AA@nefteavtomatika.ru>
//
#include <QSize>
#include <QPoint>
#include <QColor>
#include <QCoreApplication>
#include "appsettings.h"
const Setting AppSettings::SmartCardReader = { "SmartCardReader", QString() };
const Setting AppSettings::SerialPortSettings = { "SerialPortSettings", QVariant() };
const Setting AppSettings::ModbusAddressType = { "ModbusAddressType", QString() };
const Setting AppSettings::ModbusStartAddress = { "ModbusStartAddress", 1 };
const Setting AppSettings::ModbusBufferSize = { "ModbusBufferSize", 5 };
const Setting AppSettings::ModbusServerAddress = { "ModbusServerAddress", 1 };
const Setting AppSettings::ModbusServerRestartTimeout = { "ModbusServerRestartTimeout", 30 };
//
/// \brief AppSettings::instance
/// \return
///
AppSettings* AppSettings::instance()
{
static AppSettings* __ptr(nullptr);
if (!qApp->property("appsettings").isValid() && !__ptr)
{
__ptr = &getInstance(); // Q_GLOBAL_STATIC pointer
qApp->setProperty("appsettings", QVariant::fromValue(__ptr));
}
else if (!__ptr)
{
__ptr = qvariant_cast<AppSettings*>(qApp->property("appsettings"));
}
else if (!qApp->property("appsettings").isValid())
{
qApp->setProperty("appsettings", QVariant::fromValue(__ptr));
}
return __ptr;
}
///
/// \brief AppSettings::GetSetting
/// \param setting
/// \return
///
QVariant AppSettings::GetSetting(const Setting& setting)
{
std::lock_guard<std::mutex> lock(mutex);
{
if(variantSettings.find(setting.Name) == variantSettings.end())
{
variantSettings[setting.Name] = settings.value(setting.Name, setting.DefaultValue);
}
return variantSettings.at(setting.Name);
}
}
///
/// \brief AppSettings::SetSetting
/// \param setting
/// \param value
///
void AppSettings::SetSetting(const Setting& setting, const QVariant& value)
{
std::lock_guard<std::mutex> lock(mutex);
{
variantSettings[setting.Name] = value;
settings.setValue(setting.Name, value);
}
}