-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsavecommanddialog.cpp
More file actions
68 lines (55 loc) · 1.94 KB
/
savecommanddialog.cpp
File metadata and controls
68 lines (55 loc) · 1.94 KB
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
//
// Created by Administrator on 2025/5/5.
//
#include "savecommanddialog.hpp"
#include "ui_savecommanddialog.h"
#include <QMessageBox>
#include "utils.hpp"
SaveCommandDialog::SaveCommandDialog(QWidget *parent,
const QString &defaultValue,
const QString &defaultRemark)
: QDialog(parent), ui(new Ui::SaveCommandDialog) {
ui->setupUi(this);
// 如果有初始值,则设置为编辑模式
if (!defaultValue.isEmpty()) {
ui->commandValueView->setPlainText(defaultValue);
ui->remarkValueView->setText(defaultRemark);
setWindowTitle(QString("编辑扩展指令"));
}
connect(ui->saveCommandButton, &QPushButton::clicked, this,
&SaveCommandDialog::onSaveCommandButtonClicked);
connect(ui->cancelButton, &QPushButton::clicked, this,
&SaveCommandDialog::onCancelButtonClicked);
}
void SaveCommandDialog::onSaveCommandButtonClicked() {
const QString commandValue = ui->commandValueView->toPlainText();
if (commandValue.isEmpty()) {
QMessageBox::warning(this, "提示", "请输入指令值为空");
return;
}
if (!Utils::isHexString(commandValue)) {
QMessageBox::warning(this, "提示", "请输入合法的十六进制指令值");
return;
}
accept();
}
void SaveCommandDialog::onCancelButtonClicked() { close(); }
Command SaveCommandDialog::getInputValue() const {
Command command;
// 返回输入的值,并转换为大写,并添加空格 格式化
const auto hex = ui->commandValueView->toPlainText().toUpper();
if (hex.contains(" ")) {
command.setValue(hex);
} else {
QStringList parts;
for (int i = 0; i < hex.length(); i += 2) {
parts << hex.mid(i, 2);
}
const QString value = parts.join(" ");
command.setValue(value);
}
const auto remark = ui->remarkValueView->text();
command.setRemark(remark);
return command;
}
SaveCommandDialog::~SaveCommandDialog() { delete ui; }