-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappconfig.cpp
More file actions
43 lines (36 loc) · 1.04 KB
/
appconfig.cpp
File metadata and controls
43 lines (36 loc) · 1.04 KB
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
#include "appconfig.h"
#include <QFile>
#include <QJsonDocument>
#include <QDebug>
AppConfig& AppConfig::instance()
{
static AppConfig instance;
return instance;
}
AppConfig::AppConfig() {}
bool AppConfig::loadAllConfigs()
{
bool success = true;
success &= loadJson(":/lteBandData.json", lteBandData);
success &= loadJson(":/lteSsubConf.json", lteSsubConf);
success &= loadJson(":/nrBandData.json", nrBandData);
success &= loadJson(":/nrRbData.json", nrRbData);
return success;
}
bool AppConfig::loadJson(const QString &path, QJsonObject &target)
{
QFile file(path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Couldn't open config file:" << path;
return false;
}
QByteArray data = file.readAll();
file.close();
QJsonDocument doc = QJsonDocument::fromJson(data);
if (doc.isNull() || !doc.isObject()) {
qWarning() << "Failed to parse JSON file or it's not an object:" << path;
return false;
}
target = doc.object();
return true;
}