2025-04-22 10:10:55 +08:00
|
|
|
|
#include "powerTerminal.h"
|
|
|
|
|
|
|
|
|
|
|
|
PowerTerminal::PowerTerminal(const QString& parentEntityId,
|
|
|
|
|
|
TerminalType type,
|
|
|
|
|
|
const QString& name,
|
|
|
|
|
|
const QPointF& relativePos,
|
2025-04-30 16:29:17 +08:00
|
|
|
|
const QString& uuid,
|
2025-10-11 18:51:33 +08:00
|
|
|
|
const double dPerX,
|
|
|
|
|
|
const double dPerY,
|
2025-04-22 10:10:55 +08:00
|
|
|
|
QObject* parent)
|
|
|
|
|
|
: QObject(parent),
|
2025-04-30 16:29:17 +08:00
|
|
|
|
m_id(uuid),
|
2025-04-22 10:10:55 +08:00
|
|
|
|
m_parentEntityId(parentEntityId),
|
|
|
|
|
|
m_type(type),
|
|
|
|
|
|
m_name(name),
|
2025-10-11 18:51:33 +08:00
|
|
|
|
m_relativePosition(relativePos),
|
|
|
|
|
|
m_dPerX(dPerX),
|
|
|
|
|
|
m_dPerY(dPerY)
|
2025-04-30 16:29:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
if(m_id.isEmpty())
|
|
|
|
|
|
m_id = QUuid::createUuid().toString();
|
|
|
|
|
|
}
|
2025-04-22 10:10:55 +08:00
|
|
|
|
|
|
|
|
|
|
void PowerTerminal::setRelativePosition(const QPointF& newPos) {
|
|
|
|
|
|
if (m_relativePosition != newPos) {
|
|
|
|
|
|
m_relativePosition = newPos;
|
|
|
|
|
|
emit positionChanged(newPos);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject PowerTerminal::toJson() const {
|
|
|
|
|
|
QJsonObject obj;
|
|
|
|
|
|
obj["id"] = m_id;
|
|
|
|
|
|
obj["parentEntity"] = m_parentEntityId;
|
|
|
|
|
|
obj["type"] = static_cast<int>(m_type);
|
|
|
|
|
|
obj["name"] = m_name;
|
|
|
|
|
|
obj["relX"] = m_relativePosition.x();
|
|
|
|
|
|
obj["relY"] = m_relativePosition.y();
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PowerTerminal* PowerTerminal::fromJson(const QJsonObject& json, QObject* parent) {
|
|
|
|
|
|
QString id = json["id"].toString();
|
|
|
|
|
|
QString parentId = json["parentEntity"].toString();
|
|
|
|
|
|
TerminalType type = static_cast<TerminalType>(json["type"].toInt());
|
|
|
|
|
|
QString name = json["name"].toString();
|
|
|
|
|
|
qreal x = json["relX"].toDouble();
|
|
|
|
|
|
qreal y = json["relY"].toDouble();
|
|
|
|
|
|
|
2025-10-11 18:51:33 +08:00
|
|
|
|
PowerTerminal* term = new PowerTerminal(parentId, type, name, QPointF(x, y),id,0,0, parent); //***不再使用***
|
2025-04-22 10:10:55 +08:00
|
|
|
|
term->m_id = id; // 注意:需要修改m_id为可写,或使用其他机制保持ID一致
|
|
|
|
|
|
return term;
|
|
|
|
|
|
}
|