DiagramDesigner/diagramCavas/source/structDataActionParaDlg.cpp

81 lines
2.5 KiB
C++
Raw Normal View History

2026-01-16 18:40:46 +08:00
#include "structDataActionParaDlg.h"
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
StructDataActionParaDlg::StructDataActionParaDlg(QWidget *parent)
: QDialog(parent) {
setWindowTitle("动作参数");
resize(350, 300);
QVBoxLayout *layout = new QVBoxLayout(this);
// 告警列表
m_listWidget = new QListWidget(this);
layout->addWidget(m_listWidget);
// 添加区
QHBoxLayout *addLayout = new QHBoxLayout;
m_editLine = new QLineEdit(this);
m_editLine->setPlaceholderText("输入动作参数");
m_btnAdd = new QPushButton("添加", this);
addLayout->addWidget(m_editLine, 1);
addLayout->addWidget(m_btnAdd);
layout->addLayout(addLayout);
// 操作区
QHBoxLayout *opLayout = new QHBoxLayout;
m_btnDelete = new QPushButton("删除选中", this);
m_btnClear = new QPushButton("清空", this);
opLayout->addWidget(m_btnDelete);
opLayout->addWidget(m_btnClear);
opLayout->addStretch();
layout->addLayout(opLayout);
// 确定取消
QHBoxLayout *btnLayout = new QHBoxLayout;
m_btnOk = new QPushButton("确定", this);
m_btnCancel = new QPushButton("取消", this);
btnLayout->addStretch();
btnLayout->addWidget(m_btnOk);
btnLayout->addWidget(m_btnCancel);
layout->addLayout(btnLayout);
// 连接信号
connect(m_btnAdd, &QPushButton::clicked, this, &StructDataActionParaDlg::onAddClicked);
connect(m_btnDelete, &QPushButton::clicked, this, &StructDataActionParaDlg::onDeleteClicked);
connect(m_btnClear, &QPushButton::clicked, m_listWidget, &QListWidget::clear);
connect(m_editLine, &QLineEdit::returnPressed, this, &StructDataActionParaDlg::onAddClicked);
connect(m_btnOk, &QPushButton::clicked, this, &QDialog::accept);
connect(m_btnCancel, &QPushButton::clicked, this, &QDialog::reject);
}
void StructDataActionParaDlg::setAlarms(const QStringList &alarms) {
m_listWidget->clear();
m_listWidget->addItems(alarms);
}
QStringList StructDataActionParaDlg::alarms() const {
QStringList result;
for (int i = 0; i < m_listWidget->count(); ++i) {
result << m_listWidget->item(i)->text();
}
return result;
}
void StructDataActionParaDlg::onAddClicked() {
QString text = m_editLine->text().trimmed();
if (!text.isEmpty()) {
m_listWidget->addItem(text);
m_editLine->clear();
}
}
void StructDataActionParaDlg::onDeleteClicked() {
qDeleteAll(m_listWidget->selectedItems());
}