FemaLocalSoftware/logs_r.h
lopata29435_NSK 3af06d02ec finish
2025-01-08 05:13:48 +07:00

76 lines
2.2 KiB
C++

#ifndef LOGS_R_H
#define LOGS_R_H
#include <QJsonArray>
#include <QJsonObject>
#include <QList>
#include <QString>
class LogsR
{
public:
LogsR() = default;
LogsR(const QString &mark,
const QString &message,
const QString &sensorGroup,
const QString &sensorId,
const QString &serial,
int threatLevel,
const QString &time)
: mark(mark)
, message(message)
, sensor_group(sensorGroup)
, sensor_id(sensorId)
, serial(serial)
, threat_level(threatLevel)
, time(time)
{}
void parseResponse(const QJsonObject &json)
{
if (json.contains("mark") && json["mark"].isString()) {
mark = json["mark"].toString();
}
if (json.contains("message") && json["message"].isString()) {
message = json["message"].toString();
}
if (json.contains("sensor_group") && json["sensor_group"].isString()) {
sensor_group = json["sensor_group"].toString();
}
if (json.contains("sensor_id") && json["sensor_id"].isString()) {
sensor_id = json["sensor_id"].toString();
}
if (json.contains("serial") && json["serial"].isString()) {
serial = json["serial"].toString();
}
if (json.contains("threat_level") && json["threat_level"].isDouble()) {
threat_level = json["threat_level"].toInt();
}
if (json.contains("time") && json["time"].isDouble()) {
qint64 unixTime = json["time"].toVariant().toLongLong();
QDateTime dateTime = QDateTime::fromSecsSinceEpoch(unixTime);
time = dateTime.toString("HH:mm dd.MM.yyyy");
}
}
QString getMark() const { return mark; }
QString getMessage() const { return message; }
QString getSensorGroup() const { return sensor_group; }
QString getSensorId() const { return sensor_id; }
QString getSerial() const { return serial; }
int getThreatLevel() const { return threat_level; }
QString getTime() const { return time; }
private:
QString mark;
QString message;
QString sensor_group;
QString sensor_id;
QString serial;
int threat_level;
QString time;
};
#endif // LOGS_R_H