-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.cpp
61 lines (46 loc) · 1.16 KB
/
configuration.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
#include "configuration.h"
Configuration::Configuration(QObject* parent, QString t_configPath) : QObject(parent)
{
init(t_configPath);
}
Configuration* Configuration::instance(QObject* parent, QString t_configPath)
{
if (m_instance == nullptr)
{
m_instance = new Configuration(parent, t_configPath);
}
return m_instance;
}
Configuration* Configuration::instance(QObject* parent)
{
if (m_instance == nullptr)
{
m_instance = new Configuration(parent);
}
return m_instance;
}
void Configuration::init(QString t_fileName)
{
QString valueFromFile;
QFile file;
file.setFileName(t_fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qCritical() << file.errorString();
return;
}
valueFromFile = file.readAll();
file.close();
QJsonDocument documentJson = QJsonDocument::fromJson(valueFromFile.toUtf8());
m_config = documentJson.object();
}
QVariant Configuration::readData(QString data)
{
QJsonValue value = m_config.value(QString(data));
return value.toVariant();
}
Configuration::~Configuration()
{
}
// Initialize static member of class DatabaseManager
Configuration* Configuration::m_instance = nullptr;