|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
#include "widget.h"
|
|
|
|
|
#include "ui_widget.h"
|
|
|
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
#define MAXITEMS 20
|
|
|
|
|
|
|
|
|
|
Widget::Widget(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, ui(new Ui::Widget)
|
|
|
|
|
, m_settingDlg(new SettingWgt(this))
|
|
|
|
|
, m_udpDataThread(new UdpDataThread(this))
|
|
|
|
|
, m_showSetting(false)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QString filePath = QApplication::applicationDirPath() + "/config/Config.json";
|
|
|
|
|
Common::GetInstance()->loadConfig(filePath);
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
initUI();
|
|
|
|
|
connect(m_settingDlg, &SettingWgt::SettingFinishSig, [this](){
|
|
|
|
|
on_pushButton_setting_clicked();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget::~Widget()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Widget::initUI()
|
|
|
|
|
{
|
|
|
|
|
this->setWindowTitle("");
|
|
|
|
|
//this->setWindowFlags(Qt::Window | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
|
|
|
|
|
this->setWindowFlags(Qt::Window | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint);
|
|
|
|
|
ui->list_log->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
|
|
|
|
layout->addWidget(m_settingDlg);
|
|
|
|
|
ui->widget_setting->setLayout(layout);
|
|
|
|
|
ui->widget_setting->hide();
|
|
|
|
|
ui->lineEdit_snId->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Widget::setSNLineEditFocus()
|
|
|
|
|
{
|
|
|
|
|
// 全选LineEdit并且焦点放在LineEdit上
|
|
|
|
|
ui->lineEdit_snId->selectAll();
|
|
|
|
|
ui->lineEdit_snId->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Widget::checkSNId(const QString &snId)
|
|
|
|
|
{
|
|
|
|
|
if (snId.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, "产品SN错误", "产品SN为空! 请重新扫码!");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
QRegExp reg("[a-z]");
|
|
|
|
|
if (reg.indexIn(snId) != -1)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::information(this,"提示",QString("产品SN(%1)包含小写! 请重新扫码!").arg(snId));
|
|
|
|
|
ui->lineEdit_snId->setText("");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (snId.contains(" "))
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::information(this,"提示",QString("产品SN(%1)包含空格! 请重新扫码!").arg(snId));
|
|
|
|
|
ui->lineEdit_snId->setText("");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Widget::on_pushButton_setting_clicked()
|
|
|
|
|
{
|
|
|
|
|
if (ui->widget_setting->isHidden())
|
|
|
|
|
{
|
|
|
|
|
ui->pushButton_setting->setIcon(QIcon(":/resources/folding.png"));
|
|
|
|
|
m_settingDlg->loadConfig();
|
|
|
|
|
ui->widget_setting->show();
|
|
|
|
|
int currentWidth = this->width();
|
|
|
|
|
this->adjustSize();
|
|
|
|
|
this->resize(currentWidth, this->height()); // 只保持高度变化
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->pushButton_setting->setIcon(QIcon(":/resources/unfolding.png"));
|
|
|
|
|
ui->widget_setting->hide();
|
|
|
|
|
int currentWidth = this->width();
|
|
|
|
|
this->adjustSize();
|
|
|
|
|
this->resize(currentWidth, this->height()); // 只保持高度变化
|
|
|
|
|
setSNLineEditFocus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Widget::addLogItem(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
if (ui->list_log->count() >= MAXITEMS)
|
|
|
|
|
{
|
|
|
|
|
delete ui->list_log->takeItem(0);
|
|
|
|
|
}
|
|
|
|
|
ui->list_log->addItem(text); // 添加新条目
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Widget::on_lineEdit_snId_returnPressed()
|
|
|
|
|
{
|
|
|
|
|
QString snId = ui->lineEdit_snId->text();
|
|
|
|
|
int ret = 0;
|
|
|
|
|
ret = checkSNId(snId);
|
|
|
|
|
if (ret != 0)
|
|
|
|
|
{
|
|
|
|
|
LError("checkSNId error!code:{}", ret);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto selectedProducts = Common::GetInstance()->getSelectedProducts();
|
|
|
|
|
QString productFormat{};
|
|
|
|
|
for (auto& products : selectedProducts.keys())
|
|
|
|
|
{
|
|
|
|
|
if (snId.contains(products))
|
|
|
|
|
{
|
|
|
|
|
productFormat = products;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (productFormat.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::information(this, "警告", "当前SN与启用设值SN不匹配,请检查或重新扫码");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto currWorkMode = Common::GetInstance()->getCurrentWorkMode();
|
|
|
|
|
if (selectedProducts[productFormat] != currWorkMode)
|
|
|
|
|
{
|
|
|
|
|
qDebug()<<"not match!!!";
|
|
|
|
|
m_udpDataThread->sendClose();
|
|
|
|
|
return;
|
|
|
|
|
//TODO:不相等时,需要结束当前的IECS程序,如果为-1,则代表没有IECS程序执行,直接启动IECS程序即可
|
|
|
|
|
//同时需要去IECS程序路径中查找数据库,判断是否使用返修程序
|
|
|
|
|
}
|
|
|
|
|
m_udpDataThread->sendSnId(snId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Widget::on_pushButton_sendSnId_clicked()
|
|
|
|
|
{
|
|
|
|
|
on_lineEdit_snId_returnPressed();
|
|
|
|
|
}
|