Implemented helpers:

QString getLocation(QString fileName);
    QString getTariffVersion(QString fileName);
    QString getTariffInfo(QString fileName);

Read project location, tariff location and tariff-info
from tariff[].json file.
This commit is contained in:
Gerhard Hoffmann 2024-01-17 15:18:03 +01:00
parent e6f6d43bf2
commit bc9ebb7d68

View File

@ -30,6 +30,82 @@ int Utils::read1stLineOfFile(QString fileName) {
return -1; return -1;
} }
QString Utils::getLocation(QString fileName) {
QString location("N/A");
QFile f(fileName);
if (f.exists()) {
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&f);
in.setCodec("UTF-8");
while(!in.atEnd()) {
QString const &line = in.readLine();
if (line.indexOf("Project", Qt::CaseInsensitive) != -1) {
int const c = line.indexOf(":");
if (c != -1) {
location = line.mid(c+1);
if (!location.isEmpty()) {
return location.replace(QChar('"'), QString("")).trimmed();
}
}
}
}
}
}
return location;
}
QString Utils::getTariffVersion(QString fileName) {
QString version("N/A");
QFile f(fileName);
if (f.exists()) {
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&f);
in.setCodec("UTF-8");
while(!in.atEnd()) {
QString const &line = in.readLine();
if (line.indexOf("Version", Qt::CaseInsensitive) != -1) {
int const c = line.indexOf(":");
if (c != -1) {
version = line.mid(c+1);
if (!version.isEmpty()) {
return version.replace(QChar('"'), QString("")).trimmed();
}
}
}
}
}
}
return version;
}
QString Utils::getTariffInfo(QString fileName) {
QString info("N/A");
QFile f(fileName);
if (f.exists()) {
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&f);
in.setCodec("UTF-8");
while(!in.atEnd()) {
QString const &line = in.readLine();
if (line.indexOf("Info", Qt::CaseInsensitive) != -1) {
int const c = line.indexOf(":");
if (c != -1) {
info = line.mid(c+1);
if (!info.isEmpty()) {
return info.replace(QChar('"'), QString("")).trimmed();
}
}
}
}
}
}
return info;
}
QString Utils::zoneName(quint8 i) { QString Utils::zoneName(quint8 i) {
static constexpr char const *zName[] = { static constexpr char const *zName[] = {
"", "",