129 lines
3.5 KiB
C++
129 lines
3.5 KiB
C++
#include <QMessageBox>
|
||
#include "measureSettingDlg.h"
|
||
#include "bayInfoDlg.h"
|
||
#include "graphicsDataModel/fixedPortsModel.h"
|
||
#include "graphicsItem/graphicsBaseItem.h"
|
||
#include "baseProperty.h"
|
||
#include "ui_measureSettingDlg.h"
|
||
|
||
MeasureSettingDlg::MeasureSettingDlg(QWidget *parent)
|
||
: QDialog(parent)
|
||
, ui(new Ui::measureSettingDlg)
|
||
,_pBay(nullptr)
|
||
{
|
||
ui->setupUi(this);
|
||
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
||
initial();
|
||
}
|
||
|
||
MeasureSettingDlg::~MeasureSettingDlg()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
void MeasureSettingDlg::initial()
|
||
{
|
||
connect(ui->btn_ok,&QPushButton::clicked,this,&MeasureSettingDlg::onOkClicked);
|
||
connect(ui->btn_cancel,&QPushButton::clicked,this,&MeasureSettingDlg::onCancelClicked);
|
||
connect(ui->cb_tag,&QComboBox::textActivated,this,&MeasureSettingDlg::onTagChanged);
|
||
connect(ui->cb_name,&QComboBox::textActivated,this,&MeasureSettingDlg::onNameChanged);
|
||
|
||
// 设置正则验证器:1-5000整数
|
||
QRegularExpression regExp("^(?:[1-9]|[1-9]\\d{1,2}|[1-4]\\d{3}|5000)$");
|
||
QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp,ui->le_size);
|
||
ui->le_size->setValidator(validator);
|
||
}
|
||
|
||
void MeasureSettingDlg::showDlg()
|
||
{
|
||
clearData();
|
||
QStringList lstTag;
|
||
QStringList lstName;
|
||
show();
|
||
if(_pBay){
|
||
auto lst = _pBay->getValidType();
|
||
for(auto& item:lst){
|
||
lstTag.append(item.tag);
|
||
lstName.append(item.name);
|
||
}
|
||
ui->cb_tag->addItems(lstTag);
|
||
ui->cb_name->addItems(lstName);
|
||
|
||
QStringList lstDevice;
|
||
if(_pBay){
|
||
FixedPortsModel* pModel = _pBay->getModelController();
|
||
if(pModel){
|
||
auto map = pModel->allItems();
|
||
for(auto& pItem:map){
|
||
auto pPro = pItem->getProperty();
|
||
if(pPro){
|
||
lstDevice.append(pPro->tag()); //根据本图的图元获取对应设备名
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
ui->cb_equip->addItems(lstDevice);
|
||
BaseProperty* pro = _pBay->getProperty();
|
||
if(pro){
|
||
ui->cb_equip->setCurrentText(pro->tag());
|
||
}
|
||
}
|
||
}
|
||
|
||
void MeasureSettingDlg::clearData()
|
||
{
|
||
if(ui->cb_tag->count())
|
||
ui->cb_tag->clear();
|
||
if(ui->cb_name->count())
|
||
ui->cb_name->clear();
|
||
ui->le_port->clear();
|
||
ui->le_size->clear();
|
||
}
|
||
|
||
void MeasureSettingDlg::onOkClicked()
|
||
{
|
||
MeasurementInfo info;
|
||
info.tag = ui->cb_tag->currentText();
|
||
info.name = ui->cb_name->currentText();
|
||
info.equipment = ui->cb_equip->currentText();
|
||
info.channel = ui->le_port->text();
|
||
info.type = ui->cb_type->currentText();
|
||
info.size = ui->le_size->text().toInt();
|
||
if(info.channel.isEmpty() || info.size == 0){
|
||
QMessageBox::information(NULL, QString("提示"), QString::fromWCharArray(L"参数未设置完毕"));
|
||
return;
|
||
}
|
||
|
||
if(_pBay)
|
||
_pBay->addMeasure(info);
|
||
hide();
|
||
}
|
||
|
||
void MeasureSettingDlg::onCancelClicked()
|
||
{
|
||
hide();
|
||
}
|
||
|
||
void MeasureSettingDlg::onTagChanged(const QString& str)
|
||
{
|
||
auto lst = _pBay->getValidType();
|
||
for(auto& item:lst){
|
||
if(item.tag == str){
|
||
ui->cb_name->setCurrentText(item.name);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
void MeasureSettingDlg::onNameChanged(const QString& str)
|
||
{
|
||
auto lst = _pBay->getValidType();
|
||
for(auto& item:lst){
|
||
if(item.name == str){
|
||
ui->cb_tag->setCurrentText(item.tag);
|
||
return;
|
||
}
|
||
}
|
||
}
|