增加UI配置项

This commit is contained in:
2025-10-16 17:40:00 +08:00
parent eeb5af98eb
commit f88b815723
181 changed files with 718 additions and 465 deletions

View File

@@ -1,5 +1,5 @@
#include "Basic.h"
#include <QColor>
/**
* @brief map 映射函数,把x的值,映射到out_min到out_max的范围内
@@ -173,4 +173,99 @@ uint16_t extractUInt32_16BitPart(uint32_t data, int index) {
return 00;
}
}
/**
* @brief getNodeValue 获取节点内的值
* @param nodeId 欲获取的节点文本
* @return 类型:QVariant 节点的值
*/
QVariant getNodeValue(const QString &nodeId){
QString mNodeID = nodeId;
if(!mNodeID.contains("ns=6;s=::AsGlobalPV:"))
mNodeID = "ns=6;s=::AsGlobalPV:"+mNodeID;
return gOPC_NodeValue[mNodeID];
}
/**
* @brief getColorStr 获取颜色文本
* @param Str 欲获取的文本内容
* @return 返回颜色文本
*/
QString getColorStr(QString str)
{
/*
颜色文本的表现形式:
color: rgb(255, 0, 0);
color: #ff0000;
颜色文本格式:
color: rgb(255, 0, 0);
color: rgb(255, 0, 0)
rgb(255, 0, 0)
rgb(255, 0, 0);
255, 0, 0
255, 0, 0;
color: #ff0000
color: #ff0000;
#ff0000
#ff0000;
ff0000
ff0000;
*/
str = str.trimmed();
/* 1. 先尝试匹配 rgb(r, g, b) 形式 */
static QRegularExpression reRgb(
R"(^\s*(?:color\s*:\s*)?rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\);?\s*$)",
QRegularExpression::CaseInsensitiveOption);
auto match = reRgb.match(str);
if (match.hasMatch()) {
int r = match.captured(1).toInt();
int g = match.captured(2).toInt();
int b = match.captured(3).toInt();
return QString("color: rgb(%1, %2, %3);").arg(r).arg(g).arg(b);
}
/* 2. 再尝试匹配 #hex 或裸 hex 形式 */
static QRegularExpression reHex(
R"(^\s*(?:color\s*:\s*)?(?:#)?([0-9a-f]{6});?\s*$)",
QRegularExpression::CaseInsensitiveOption);
match = reHex.match(str);
if (match.hasMatch()) {
QString hex = match.captured(1).toLower();
return QString("color: #%1;").arg(hex);
}
/* 3. 都不符合,原样返回(或按需返回空串) */
return str;
}
/**
* @brief getColor
* @param str 任意颜色字符串
* @return QColor无效 QColor 表示解析失败)
*/
QColor getColor(const QString &str)
{
QString s = str.trimmed();
/* 1. rgb(r, g, b) */
static QRegularExpression reRgb(
R"(^\s*(?:color\s*:\s*)?rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\);?\s*$)",
QRegularExpression::CaseInsensitiveOption);
auto m = reRgb.match(s);
if (m.hasMatch()) {
int r = m.captured(1).toInt();
int g = m.captured(2).toInt();
int b = m.captured(3).toInt();
return QColor(r, g, b);
}
/* 2. #RRGGBB 或 RRGGBB */
static QRegularExpression reHex(
R"(^\s*(?:color\s*:\s*)?(?:#)?([0-9a-fA-F]{6});?\s*$)");
m = reHex.match(s);
if (m.hasMatch())
return QColor('#' + m.captured(1)); // QColor 接受 "#ff0000"
/* 3. 解析失败 */
return QColor(); // 无效颜色
}

View File

@@ -1,9 +1,10 @@
#ifndef BASIC_H
#define BASIC_H
#include <GlobalDefinitions/DataType.h>
#include <GlobalDefinitions/Variable.h>
#include <QCoreApplication>
#include <QTime>
#include <QRegularExpression>
/**
* @brief map 映射函数,把x的值,映射到out_min到out_max的范围内
@@ -81,4 +82,25 @@ uint8_t extractUInt32_8BitPart(uint32_t data, uint8_t index);
* @throws std::out_of_range 当索引超出0-1范围时
*/
uint16_t extractUInt32_16BitPart(uint32_t data, int index);
/**
* @brief getNodeValue 获取节点内的值
* @param nodeId 欲获取的节点文本
* @return 类型:QVariant 节点的值
*/
QVariant getNodeValue(const QString &nodeId);
/**
* @brief getColorStr 获取颜色文本
* @param Str 欲获取的文本内容
* @return 返回颜色文本
*/
QString getColorStr(QString Str);
/**
* @brief getColor
* @param str 任意颜色字符串
* @return QColor无效 QColor 表示解析失败)
*/
QColor getColor(const QString &str);
#endif // BASIC_H