发布时间:2023-11-09 17:00
设备面板展示数据,相对于表格展示,可能在一个页面中能够展示的设备数据量少一些,但是有些用户和场景,又需要这种面板的形式,可能更生动形象一些。尤其是经过这么些年的社会的毒打,我的原则是:用户是上帝和大爷,尽量站在用户的角度换位思考,只要是合理或者基本合理的需求,甚至说只要不是太过分,给钱就干。
其实这种面板展示数据的需求,从我刚开始工作的时候,编写的软件,就已经有了,比如一台主机对应一个设备面板,除了显示对应的数值(电压值、电流值等),每个面板上还有按钮提供用户交互操作。对于通用的物联网平台来说,需要进行交互的场景很少,绝大部分都是用来展示采集到的数据,所以本系统的面板就显示对于的数据,如果需要回控操作的话,双击对应面板弹出详细面板信息进行操作。
设备面板几个特色功能:
#include \"frmdevicenode.h\"
#include \"ui_frmdevicenode.h\"
#include \"quihelper.h\"
#include \"iconhelper.h\"
#include \"dbquery.h\"
#include \"deviceserver.h\"
#include \"frmdevicecontrol.h\"
frmDeviceNode::frmDeviceNode(QWidget *parent) : QWidget(parent), ui(new Ui::frmDeviceNode)
{
ui->setupUi(this);
this->initForm();
this->initStyle();
//this->initControl();
}
frmDeviceNode::~frmDeviceNode()
{
delete ui;
}
bool frmDeviceNode::eventFilter(QObject *watched, QEvent *event)
{
//要区分在线离线的情况
//在线双击则弹出具体详情面板
//离线双击则重连当前端口下的所有设备
if (event->type() == QEvent::MouseButtonDblClick) {
if (!online) {
QString deviceName = this->property(\"deviceName\").toString();
QString portName = DbQuery::getPortName(deviceName);
DeviceServer::Instance()->readValue(portName, 255, true);
} else {
QString positionID = this->property(\"positionID\").toString();
frmDeviceControl::Instance()->setPositionID(positionID);
frmDeviceControl::Instance()->show();
}
}
return QWidget::eventFilter(watched, event);
}
void frmDeviceNode::initForm()
{
value = 0;
online = true;
alarm = false;
select = false;
this->installEventFilter(this);
QFont font;
font.setPixelSize(QUIConfig::FontSize + 2);
ui->labNodeInfo->setFont(font);
ui->labNodeInfo->setFixedHeight(30);
//设置图形字体
QFont iconFont = IconHelper::getIconFontAwesome();
ui->labNodeNamex->setFont(iconFont);
ui->labPositionIDx->setFont(iconFont);
ui->labNodeTypex->setFont(iconFont);
ui->labNodeValuex->setFont(iconFont);
ui->labNodeNamex->setText(QChar(0xf132));
ui->labPositionIDx->setText(QChar(0xf015));
ui->labNodeTypex->setText(QChar(0xf124));
ui->labNodeValuex->setText(QChar(0xf0c3));
//通过弱属性控制样式
ui->devicePanel2->setProperty(\"form\", \"panel\");
ui->deviceTitle1->setProperty(\"form\", \"panel\");
ui->devicePanel1->setProperty(\"form\", \"panel\");
ui->deviceTitle1->setProperty(\"flag\", \"paneltitle\");
ui->devicePanel1->setProperty(\"flag\", \"panelcontrol\");
//可以自行根据项目需要调整范围值小数点等
ui->gaugeSpeed->setUnit(\"\");
ui->gaugeSpeed->setPrecision(0);
ui->gaugeSpeed->setDigitCount(3);
ui->gaugeSpeed->setRange(0, 200);
ui->gaugeSpeed->setValue(ui->gaugeSpeed->getMinValue());
}
void frmDeviceNode::initStyle()
{
//根据不同的面板样式隐藏对应的面板
if (AppConfig::PanelStyle == 0) {
ui->widget1->setVisible(true);
ui->widget2->setVisible(false);
} else if (AppConfig::PanelStyle == 1) {
ui->widget1->setVisible(false);
ui->widget2->setVisible(true);
}
QString textColor, bgColor;
if (alarm) {
//判断低报还是高报
QString positionID = this->property(\"positionID\").toString();
int index = DbData::NodeInfo_PositionID.indexOf(positionID);
bool alarmLimit = DbData::NodeInfo_AlarmLimit.at(index);
bool alarmUpper = DbData::NodeInfo_AlarmUpper.at(index);
//bool alarmOther = DbData::NodeInfo_AlarmOther.at(index);
//报警面板颜色
textColor = \"#EEEEEE\";
if (alarmLimit) {
bgColor = AppConfig::ColorLimit;
} else if (alarmUpper) {
bgColor = AppConfig::ColorUpper;
} else {
bgColor = AppConfig::ColorOther;
}
//报警状态下的选中将颜色加个透明度
if (select) {
QColor color(bgColor);
bgColor = QString(\"rgba(%1,%2,%3,150)\").arg(color.red()).arg(color.green()).arg(color.blue());
}
} else {
//选中面板颜色
textColor = online ? QUIConfig::TextColor : QUIConfig::BorderColor;
bgColor = select ? QUIConfig::DarkColorStart : QUIConfig::NormalColorStart;
}
QStringList qss;
//仪表盘中的数码管禁用样式
qss << QString(\"QLCDNumber:disabled{background:%1;}\").arg(QUIConfig::NormalColorStart);
//仪表样式中的节点信息标签
qss << QString(\"#labNodeInfo{color:%1;background:%2;}\").arg(textColor).arg(alarm ? bgColor : QUIConfig::DarkColorEnd);
//仪表样式面板需要调整下颜色
if (AppConfig::PanelStyle == 1 && alarm) {
textColor = QUIConfig::TextColor;
bgColor = select ? QUIConfig::DarkColorStart : QUIConfig::NormalColorStart;
}
//全局文字颜色
qss << QString(\"*{color:%1;}GaugeSpeed{qproperty-textColor:%1;}\").arg(textColor);
//整体面板背景颜色
qss << QString(\"#deviceTitle1,#devicePanel1,#devicePanel2{background:%1;}\").arg(bgColor);
this->setStyleSheet(qss.join(\"\"));
}
void frmDeviceNode::initControl()
{
QString positionID = this->property(\"positionID\").toString();
QString nodeName = this->property(\"nodeName\").toString();
QString nodeType = this->property(\"nodeType\").toString();
QString nodeSign = this->property(\"nodeSign\").toString();
ui->labNodeName->setText(\"名称: \" + nodeName);
ui->labPositionID->setText(\"位号: \" + positionID);
ui->labNodeType->setText(\"型号: \" + nodeType);
ui->labNodeValue->setText(QString(\"数值: %1 %2\").arg(value).arg(nodeSign));
ui->gaugeSpeed->setText(nodeSign);
ui->gaugeSpeed->setValue(value);
ui->labNodeInfo->setText(positionID + \" -- \" + nodeName);
}
void frmDeviceNode::setValue(float value)
{
this->value = value;
QString nodeType = this->property(\"nodeType\").toString();
QString nodeSign = this->property(\"nodeSign\").toString();
//有两个传感器是开关量,数值是1 2显示时用正常和异常代替
if (nodeType == \"SJ-0001\" || nodeType == \"JG-0001\") {
ui->labNodeValue->setText(QString(\"数值: %1\").arg(value == 1 ? \"正常\" : \"异常\"));
ui->gaugeSpeed->setValue(value == 1 ? ui->gaugeSpeed->getMinValue() : ui->gaugeSpeed->getMaxValue());
} else {
ui->labNodeValue->setText(QString(\"数值: %1 %2\").arg(value).arg(nodeSign));
ui->gaugeSpeed->setValue(value);
}
}
void frmDeviceNode::setOnline(bool online)
{
if (this->online != online) {
this->online = online;
if (!online) {
this->value = 0;
this->alarm = false;
this->select = false;
}
this->setEnabled(online);
this->initStyle();
this->initControl();
}
}
void frmDeviceNode::setAlarm(bool alarm)
{
//可能由低报转为高报所以这里不要做过滤判断
this->alarm = alarm;
this->initStyle();
}
void frmDeviceNode::setSelect(bool select)
{
if (this->select != select) {
this->select = select;
this->initStyle();
}
}