UpdatePTUDevCtrl/utils.cpp
Gerhard Hoffmann b508c0517d Reset.
Add helper functions read1stLineOfFile() and zoneNr().
2023-08-02 15:45:20 +02:00

36 lines
730 B
C++

#include "utils.h"
#include <QFile>
#include <QTextStream>
int Utils::read1stLineOfFile(QString fileName) {
QFile f(fileName);
if (f.exists()) {
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&f);
in.setCodec("UTF-8");
while(!in.atEnd()) {
return in.readLine().toInt();
}
}
}
return -1;
}
QString Utils::zoneName(quint8 i) {
static constexpr char const *zName[] = {
"",
"purple",
"blue",
"yellow",
"green",
"yellow (mars)",
"green (mars)"
};
if (i < (sizeof(zName)/sizeof(char const *))) {
return zName[i];
}
return "N/A";
}