// ChannelConfig.h #pragma once #include #include #include #include #include #include "export.hpp" // 简化配置结构 struct DIAGRAM_DESIGNER_PUBLIC ChannelConfig { // 通用配置 QString id; // 通道ID: "http_channel" 或 "websocket_channel" QString name; // 通道名称 QString endpoint; // 连接地址 int timeout = 30000; // 超时时间(ms) bool enabled = true; // 是否启用 bool autoConnect = false; // 是否自动连接 QVariantMap headers; //头 // 认证 QString username; QString password; // 状态 bool connected = false; QDateTime lastConnectTime; int errorCount = 0; // WebSocket特有 int heartbeatInterval = 30000; // 心跳间隔 // 转换为Map QVariantMap toMap() const { return { {"id", id}, {"name", name}, {"endpoint", endpoint}, {"timeout", timeout}, {"enabled", enabled}, {"autoConnect", autoConnect}, {"username", username}, {"password", password}, {"connected", connected}, {"lastConnectTime", lastConnectTime.toString(Qt::ISODate)}, {"errorCount", errorCount}, {"headers", headers}, {"heartbeatInterval", heartbeatInterval} }; } // 从Map创建 static ChannelConfig fromMap(const QVariantMap& map) { ChannelConfig config; config.id = map.value("id").toString(); config.name = map.value("name").toString(); config.endpoint = map.value("endpoint").toString(); config.timeout = map.value("timeout", 30000).toInt(); config.enabled = map.value("enabled", true).toBool(); config.autoConnect = map.value("autoConnect", false).toBool(); config.username = map.value("username").toString(); config.password = map.value("password").toString(); config.connected = map.value("connected", false).toBool(); config.lastConnectTime = QDateTime::fromString( map.value("lastConnectTime").toString(), Qt::ISODate); config.errorCount = map.value("errorCount", 0).toInt(); config.headers = map.value("headers").toMap(); config.heartbeatInterval = map.value("heartbeatInterval", 30000).toInt(); return config; } };