DiagramDesigner/common/frontend/monitor_item.h

237 lines
6.9 KiB
C

#ifndef MONITOR_ITEM_H
#define MONITOR_ITEM_H
/*********人机界面********/
#include <QString>
#include <QMap>
#include <QJsonObject>
enum class MonitorItemState { //监控item的状态
Normal = 0, //正常
Closing, //合闸
Opening, //分闸
AccidentTrip, //事故跳闸
StatusFault, //状态故障
Energized, //带电
DeEnergized, //失电
Grounding, //接地
Running, //运行
ShutDown, //停运
Alarm, //告警
LineBreak, //断线
MeasureMentOutLimit //量测越限
};
struct MonitorItemAttributeInfo //单个监控item属性
{
QString sGroup; //所属组别
QString sTag; //索引名
QString sName; //显示名
int nConnectType = 0; //关联数据类别 0字段 1量测
QString sConnectPara; //查询参数(参数服务使用)
int nShowType = 0; //显示类别 0字符 1图表
bool bShowDiagram = false; //显示到组态中
int nGraphType = 0; //图表类型 0折线1柱状
QString sTimeRange; //时间范围(分)
QMap<quint64,double> mapValue; //属性值
bool bSelected = false;
// 转换为JSON对象
QJsonObject toJson() const {
QJsonObject obj;
obj["sGroup"] = sGroup;
obj["sTag"] = sTag;
obj["sName"] = sName;
obj["nConnectType"] = nConnectType;
obj["sConnectPara"] = sConnectPara;
obj["nShowType"] = nShowType;
obj["bShowDiagram"] = bShowDiagram;
obj["nGraphType"] = nGraphType;
obj["sTimeRange"] = sTimeRange;
obj["sValue"] = mapToJson(mapValue);
obj["bSelected"] = bSelected;
return obj;
}
// 从JSON对象解析
void fromJson(const QJsonObject& json) {
sGroup = json["sGroup"].toString();
sTag = json["sTag"].toString();
sName = json["sName"].toString();
nConnectType = json["nConnectType"].toInt();
sConnectPara = json["sConnectPara"].toString();
nShowType = json["nShowType"].toInt();
bShowDiagram = json["bShowDiagram"].toBool();
nGraphType = json["nGraphType"].toInt();
sTimeRange = json["sTimeRange"].toString();
mapValue = jsonToMap(json["sValue"].toObject());
bSelected = json["bSelected"].toBool();
}
// 检查有效性
bool isValid() const {
return !sTag.isEmpty() && !sName.isEmpty();
}
// 重载相等运算符
bool operator==(const MonitorItemAttributeInfo& other) const {
return sTag == other.sTag &&
sName == other.sName &&
sGroup == other.sGroup;
}
QJsonObject mapToJson(const QMap<quint64, double>& map) const{
QJsonObject jsonObj;
for (auto it = map.constBegin(); it != map.constEnd(); ++it) {
// 将quint64的key转换为QString
QString key = QString::number(it.key());
jsonObj[key] = it.value();
}
return jsonObj;
}
// 从JSON转换回来
QMap<quint64, double> jsonToMap(const QJsonObject& jsonObj) const{
QMap<quint64, double> map;
for (auto it = jsonObj.constBegin(); it != jsonObj.constEnd(); ++it) {
bool ok;
quint64 key = it.key().toULongLong(&ok);
if (ok) {
double value = it.value().toDouble();
map[key] = value;
}
}
return map;
}
};
struct MonitorItemTypeStruct //监控设备类型
{
QString sTag;
QString sName;
bool isValid() const {
return !sTag.isEmpty() && !sName.isEmpty();
}
bool operator==(const MonitorItemTypeStruct& other) const {
return sTag == other.sTag && sName == other.sName;
}
bool operator<(const MonitorItemTypeStruct& other) const {
return sTag < other.sTag || (sTag == other.sTag && sName < other.sName);
}
// 转换为JSON对象 - 成员函数
QJsonObject toJson() const {
QJsonObject obj;
obj["sTag"] = sTag;
obj["sName"] = sName;
return obj;
}
// 从JSON对象解析 - 成员函数
void fromJson(const QJsonObject& json) {
sTag = json["sTag"].toString();
sName = json["sName"].toString();
}
};
struct MonitorItemStateStruct //监控设备状态
{
QString sState;
MonitorItemState eState;
bool isValid() const {
return !sState.isEmpty();
}
bool operator==(const MonitorItemStateStruct& other) const {
return sState == other.sState && eState == other.eState;
}
bool operator<(const MonitorItemStateStruct& other) const {
return sState < other.sState || (sState == other.sState && eState < other.eState);
}
// 转换为JSON对象 - 成员函数
QJsonObject toJson() const {
QJsonObject obj;
obj["sState"] = sState;
obj["eState"] = static_cast<int>(eState);
return obj;
}
// 从JSON对象解析 - 成员函数
void fromJson(const QJsonObject& json) {
sState = json["sState"].toString();
eState = static_cast<MonitorItemState>(json["eState"].toInt());
}
};
struct ModelTypeInfo{ //类型临时信息
int nType;
QString sType;
QString sName;
QString sMeta; //该类型元模名
QString sModel; //该类型工程模名
};
struct MonitorPageInfo //运行时page
{
int id = -1;
QUuid uid;
QString tag;
QString name;
QString parent;
QJsonObject context;
QString ts;
};
struct MonitorItemDisplayInfo //监控模式显示信息
{
int nItemType; //设备类型
QString sStateName; //状态名
bool bEnable = false;
QString sColor;
QByteArray bytPicture; //存储二进制数据
int nWidth;
int nHeight;
QString sMeta; //元模型名
QString sModel; //工程模名
QJsonObject toJson() const {
QJsonObject obj;
obj["nItemType"] = nItemType;
obj["sStateName"] = sStateName;
obj["bEnable"] = bEnable;
obj["sColor"] = sColor;
obj["bytPicture"] = QString(bytPicture.toBase64());
obj["nWidth"] = nWidth;
obj["nHeight"] = nHeight;
obj["sMeta"] = sMeta;
obj["sModel"] = sModel;
return obj;
}
// 从JSON对象解析 - 成员函数
void fromJson(const QJsonObject& json) {
nItemType = json["nItemType"].toInt();
sStateName = json["sStateName"].toString();
bEnable = json["bEnable"].toBool();
sColor = json["sColor"].toString();
QString pictureBase64 = json["bytPicture"].toString();
bytPicture = QByteArray::fromBase64(pictureBase64.toUtf8());
nWidth = json["nWidth"].toInt();
nHeight = json["nHeight"].toInt();
sMeta = json["sMeta"].toString();
sModel = json["sModel"].toString();
}
};
#endif