-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_item_interface.cpp
202 lines (169 loc) · 5.76 KB
/
test_item_interface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* @Author: 陈俊健
* @Date: 2024-05-20 23:00:24
* @LastEditors: 陈俊健
* @LastEditTime: 2024-07-02 04:39:05
* @FilePath: \LabViewIniEditor2024\test_item_interface.cpp
* @Description:
*
* Copyright (c) 2024 by Chenjunjian, All Rights Reserved.
*/
#if _MSC_VER >= 1600 // MSVC2015>1899,对于MSVC2010以上版本都可以使用
#pragma execution_character_set("utf-8")
#endif
#include "test_item_interface.h"
#include "message.h"
#include "ui_test_item_interface.h"
#include <QDebug>
#define CB_TX_END_NC 0
#define CB_TX_END_R_N 1
#define CB_TX_END_HEX 2
const QStringList STR_TX_END = {"NC", "<\\r\\n>", "<HEX>"};
QStringList TestItemInterface::STR_TEST_TYPE = {
"68", "AT", "AT1", "AT2", "AT3", "串口查询真", "串口查询假", "单按钮弹框", "双按钮弹框",
};
QStringList TestItemInterface::UI_COM_LIST = {
"底板串口",
"产品串口",
"主机串口",
"下载串口",
};
TestItemInterface::TestItemInterface(QWidget *parent)
: QWidget(parent)
, ui(new Ui::TestItemInterface)
{
ui->setupUi(this);
ui->cbTxEnd->setCurrentText(STR_TX_END.at(CB_TX_END_NC)); // NC
ui->cbEncode->setVisible(false);
ui->cbComName->clear();
ui->cbComName->addItems(UI_COM_LIST);
}
TestItemInterface::~TestItemInterface() { delete ui; }
void TestItemInterface::on_leTx_textChanged(const QString &arg1)
{
// uiSetTx(arg1);
}
void TestItemInterface::on_leTx_editingFinished()
{
// 去除最后的空格、回车、换行
QString tx = ui->leTx->text();
tx = tx.trimmed();
//
uiSetTx(tx);
}
void TestItemInterface::on_leRx_editingFinished()
{
// 去除最后的空格、回车、换行
QString rx = ui->leRx->text();
rx = rx.trimmed();
ui->leRx->setText(rx);
}
void TestItemInterface::setIndex(int index) { ui->lbIndex->setText(QString::number(index)); }
void TestItemInterface::setHighlight(bool isSet)
{
ui->lbIndex->setStyleSheet(isSet ? "background-color: yellow" : "");
QFont font = ui->lbIndex->font();
font.setBold(isSet); // 设置粗体
font.setItalic(isSet); // 设置斜体
font.setUnderline(isSet); // 设置下划线
ui->lbIndex->setFont(font);
}
/**
* @brief 配置测试项
* @param index 测试项序号
* @param item 测试项
*/
void TestItemInterface::setUi(int index, const TestCmd &item)
{
// 初始化
ui->cbTxEnd->setCurrentText(STR_TX_END.at(CB_TX_END_NC));
ui->lbIndex->setText(QString::number(index));
// ui->leBrief->setText(item.brief);
if (!UI_COM_LIST.contains(item.comName))
{
UI_COM_LIST.append(item.comName);
ui->cbComName->clear();
ui->cbComName->addItems(UI_COM_LIST);
}
ui->cbComName->setCurrentText(item.comName);
ui->leBrief->setText(item.brief);
uiSetTx(item.tx);
ui->leRx->setText(item.rx);
ui->cbTestType->setCurrentText(item.cmdType);
// ui->spbxDataSize->setValue(item.dataByteLen);
// ui->spbxDecPlace->setValue(item.decimal);
// ui->spbxByteOrder->setCurrentText(item.byteOrder);
// ui->cbEncode->setCurrentText(item.encodeWay);
// ui->cbSign->setCurrentText(item.sign);
ui->spbxDelay->setValue(item.cmdDelay);
ui->spbxTimeout->setValue(item.cmdTimeout);
// if (item.resultShow != "")
// {
// if (item.resultShow.contains("<")) // 截取 < 之前的字符串
// ui->cbDisplayResult->setCurrentIndex(2);
// else
// ui->cbDisplayResult->setCurrentIndex(1);
// }
// if (item.rxAnalysis != "")
// {
// ui->cbAnalysis->setCurrentText(item.rxAnalysis);
// ui->leAnalysis->setText(item.rxAnalysis);
// }
// ui->cbDataLimit->setCurrentText(item.dataLimit);
// ui->cbUnit->setCurrentText(item.dataUnit);
}
void TestItemInterface::uiSetTx(QString strTx)
{
if (strTx.toUpper().endsWith(STR_TX_END.at(CB_TX_END_HEX)))
{
strTx = strTx.mid(0, strTx.length() - STR_TX_END.at(CB_TX_END_HEX).length());
ui->cbTxEnd->setCurrentText(STR_TX_END.at(CB_TX_END_HEX)); // <HEX>
}
else if (strTx.toLower().endsWith(STR_TX_END.at(CB_TX_END_R_N)))
{
strTx = strTx.mid(0, strTx.length() - STR_TX_END.at(CB_TX_END_R_N).length());
ui->cbTxEnd->setCurrentText(STR_TX_END.at(CB_TX_END_R_N)); // <\r\n>
}
if (strTx.toUpper() != "NA" && strTx.toUpper().contains("NA"))
{
Message::warning("第" + ui->lbIndex->text() + "条命令,发送 = 包含 \"NA\" \n部分上位机会识别为 不发送", 6000);
}
ui->leTx->setText(strTx);
}
TestCmd TestItemInterface::getTestCmd() const
{
TestCmd cmd;
cmd.index = ui->lbIndex->text().toInt();
cmd.comName = ui->cbComName->currentText();
cmd.brief = ui->leBrief->text();
cmd.tx = ui->leTx->text();
if (cmd.tx.isEmpty())
cmd.tx = "NA";
else if (ui->cbTxEnd->currentText() != STR_TX_END.at(CB_TX_END_NC))
cmd.tx += ui->cbTxEnd->currentText();
cmd.rx = ui->leRx->text();
if (cmd.rx.isEmpty())
cmd.rx = "NA";
cmd.cmdType = ui->cbTestType->currentText();
// cmd.encodeWay = ui->cbEncode->currentText();
cmd.cmdDelay = ui->spbxDelay->value();
cmd.cmdTimeout = ui->spbxTimeout->value();
return cmd;
}
void TestItemInterface::on_cbTestType_currentTextChanged(const QString &arg1)
{
int index = STR_TEST_TYPE.indexOf(arg1);
int disableIndex = STR_TEST_TYPE.indexOf("串口查询真"); // "串口查询真
if (index >= disableIndex)
ui->cbComName->setEnabled(false);
else
ui->cbComName->setEnabled(true);
}
void TestItemInterface::on_cbTestType_currentIndexChanged(int index)
{
int disableIndex = STR_TEST_TYPE.indexOf("串口查询真"); // "串口查询真
if (index >= disableIndex)
ui->cbComName->setEnabled(false);
else
ui->cbComName->setEnabled(true);
}