add
This commit is contained in:
@@ -0,0 +1,259 @@
|
||||
#include <qwidget.h>
|
||||
#include <qlabel.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qlayout.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <uiModule/components/fancyButton.h>
|
||||
#include <simpleTools/fileManager.h>
|
||||
#include <appConfig/json/generalJsonParsing.hpp>
|
||||
#include <uiModule/components/fancyDialog.h>
|
||||
#include <opencv.hpp>
|
||||
#include <unordered_map>
|
||||
#include <simpleTools/stringAlgo.h>
|
||||
#include <qmutex.h>
|
||||
#include <appConfig/appConfig.h>
|
||||
#include <qlineedit.h>
|
||||
#include <iostream>
|
||||
#include <appCore.hpp>
|
||||
#include <qtimer.h>
|
||||
class switchProductWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//
|
||||
bool disableTextChange = false;
|
||||
QMutex mutex;
|
||||
std::vector<productDataStruct>productDatas;
|
||||
int* currentProductIndexPtr;
|
||||
//
|
||||
std::string fileDir = "./config/productConfig";
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
fancyButtonText* switchBtn = new fancyButtonText(100, 60, "修改", "修改当前机型");
|
||||
QLabel* armHeartBeatSign = new QLabel();
|
||||
//料号条码输入
|
||||
QLineEdit* partNumberIntputLine = new QLineEdit();
|
||||
|
||||
//运行按钮
|
||||
fancyButtonText* startBtn;
|
||||
//SN条码输入
|
||||
QLineEdit* snIntputLine = new QLineEdit();
|
||||
//SN完成输入后1秒触发
|
||||
QTimer* timer;
|
||||
//料号显示
|
||||
QComboBox* productSelect = new QComboBox(this);
|
||||
QLabel* currentProduct = new QLabel(this);
|
||||
//料号类型
|
||||
QComboBox* productNameTypeSwitch = new QComboBox(this);
|
||||
void clear()
|
||||
{
|
||||
partNumberIntputLine->clear();
|
||||
snIntputLine->clear();
|
||||
}
|
||||
switchProductWidget()
|
||||
{
|
||||
currentProductIndexPtr = &_core._appConfig._switchProductWidgetDataPtr.currentProductIndex;
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::WindowText, Qt::white);
|
||||
QFont font("微软雅黑", 12, QFont::Bold);
|
||||
this->setLayout(layout);
|
||||
{
|
||||
QHBoxLayout* switchLayout = new QHBoxLayout();
|
||||
productNameTypeSwitch->addItem("型号");
|
||||
productNameTypeSwitch->addItem("客户料号");
|
||||
productNameTypeSwitch->addItem("料号");
|
||||
|
||||
productNameTypeSwitch->setPalette(palette);
|
||||
productNameTypeSwitch->setFont(font);
|
||||
productNameTypeSwitch->setFixedWidth(90);
|
||||
switchLayout->addWidget(productNameTypeSwitch);
|
||||
|
||||
productSelect->setPalette(palette);
|
||||
productSelect->setFont(font);
|
||||
|
||||
switchLayout->addWidget(productSelect);
|
||||
productSelect->hide();
|
||||
|
||||
currentProduct->setFont(font);
|
||||
currentProduct->setPalette(palette);
|
||||
|
||||
switchLayout->addWidget(currentProduct);
|
||||
switchLayout->addWidget(switchBtn);
|
||||
|
||||
layout->addLayout(switchLayout);
|
||||
}
|
||||
|
||||
|
||||
QHBoxLayout* hBtnLayout2 = new QHBoxLayout();
|
||||
partNumberIntputLine->setFixedHeight(50);
|
||||
partNumberIntputLine->setFont(font);
|
||||
partNumberIntputLine->setPlaceholderText("料号条码输入");
|
||||
hBtnLayout2->addWidget(partNumberIntputLine);
|
||||
|
||||
QHBoxLayout* hBtnLayout = new QHBoxLayout();
|
||||
startBtn = new fancyButtonText(80, -1, "运行", "运行检测程序");
|
||||
snIntputLine->setFixedHeight(50);
|
||||
snIntputLine->setFont(font);
|
||||
snIntputLine->setPlaceholderText("SN条码输入");
|
||||
hBtnLayout->addWidget(snIntputLine);
|
||||
hBtnLayout->addWidget(startBtn);
|
||||
|
||||
layout->addLayout(hBtnLayout2);
|
||||
layout->addLayout(hBtnLayout);
|
||||
productSelectFresh(0);
|
||||
connect(startBtn, &QPushButton::clicked, this, [=]()
|
||||
{
|
||||
emit startArmProgramSignal(indexFromPartNumber, snIntputLine->text());
|
||||
std::cout << "按下按钮" << std::endl;
|
||||
});
|
||||
connect(switchBtn, &QPushButton::clicked, this, &switchProductWidget::startSwitch);
|
||||
connect(productSelect, &QComboBox::currentTextChanged, this, &switchProductWidget::currentProductSwitch);
|
||||
connect(productSelect, &QComboBox::currentTextChanged, this, [=]()
|
||||
{
|
||||
emit switchProductSignal(productSelect->currentIndex());
|
||||
});
|
||||
connect(productNameTypeSwitch, &QComboBox::currentTextChanged, this, [=]()
|
||||
{
|
||||
productSelectFresh(productNameTypeSwitch->currentIndex());
|
||||
});
|
||||
connect(partNumberIntputLine, &QLineEdit::textChanged, this, [=]()
|
||||
{
|
||||
timer->start();
|
||||
//partNumberIntputLineSlot(partNumberIntputLine->text().toStdString());
|
||||
});
|
||||
timer = new QTimer(this);
|
||||
timer->setInterval(300); // 设置1秒超时
|
||||
timer->setSingleShot(true); // 定时器只触发一次
|
||||
connect(timer, &QTimer::timeout, this, [=]()
|
||||
{
|
||||
partNumberIntputLineSlot(partNumberIntputLine->text().toStdString());
|
||||
});
|
||||
currentProduct->setText("请输入料号");
|
||||
productSelect->hide();
|
||||
switchBtn->hide();
|
||||
startBtn->setDisabled(true);
|
||||
}
|
||||
void productSelectFresh(int index)
|
||||
{
|
||||
int indexTemp = getMax(productSelect->currentIndex(), 0);
|
||||
productSelect->clear();
|
||||
if (_core._appConfig.productDatas.size() == 0)
|
||||
{
|
||||
fancyWarnWindow* warn = new fancyWarnWindow
|
||||
(fancyWarnWindow::Warning, "找不到任何产品配置文件",
|
||||
QString("请查看%1中是否正确存放配置文件").arg(QString::fromStdString(fileDir)), true);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(index)
|
||||
{
|
||||
case 0:
|
||||
for (auto data : _core._appConfig.productDatas)
|
||||
productSelect->addItem(QString::fromStdString(data.name));
|
||||
currentProduct->setText(QString::fromStdString(_core._appConfig.productDatas[indexTemp].name));
|
||||
break;
|
||||
case 1:
|
||||
for (auto data : _core._appConfig.productDatas)
|
||||
productSelect->addItem(QString::fromStdString(data.customerPartNumber));
|
||||
currentProduct->setText(QString::fromStdString(_core._appConfig.productDatas[indexTemp].customerPartNumber));
|
||||
break;
|
||||
case 2:
|
||||
for (auto data : _core._appConfig.productDatas)
|
||||
productSelect->addItem(QString::fromStdString(data.foxconnPartNumber));
|
||||
currentProduct->setText(QString::fromStdString(_core._appConfig.productDatas[indexTemp].foxconnPartNumber));
|
||||
break;
|
||||
}
|
||||
productSelect->setCurrentIndex(indexTemp);
|
||||
siwtchBtnState = 1;
|
||||
startSwitch();
|
||||
}
|
||||
public slots:
|
||||
void setHeatBeat()
|
||||
{
|
||||
|
||||
}
|
||||
void switchStartBtnStatus(bool status)
|
||||
{
|
||||
if (status == true)
|
||||
{
|
||||
startBtn->toDefault();
|
||||
if (disableTextChange == false)
|
||||
startBtn->setText("运行");
|
||||
snIntputLine->setDisabled(false);
|
||||
partNumberIntputLine->setDisabled(false);
|
||||
std::cout << "按下软件运行" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBtn->toRed();
|
||||
if (disableTextChange == false)
|
||||
startBtn->setText("急停");
|
||||
snIntputLine->setDisabled(true);
|
||||
partNumberIntputLine->setDisabled(true);
|
||||
std::cout << "按下软件急停" << std::endl;
|
||||
}
|
||||
}
|
||||
signals:
|
||||
void startArmProgramSignal(int,QString);
|
||||
void switchProductSignal(int);
|
||||
private:
|
||||
int indexFromPartNumber = -1;
|
||||
int siwtchBtnState = 0;
|
||||
private slots:
|
||||
void partNumberIntputLineSlot(std::string partNumber)
|
||||
{
|
||||
int PartNumber_Count = partNumber.length();//循环次数
|
||||
for (auto i = 0; i < PartNumber_Count; i++)
|
||||
{
|
||||
std::string partNumber_Split = partNumber.substr(0, PartNumber_Count - i);
|
||||
auto it = _core._appConfig.partNumberWithIndex.find(partNumber_Split);
|
||||
if (it != _core._appConfig.partNumberWithIndex.end())
|
||||
{
|
||||
int index = _core._appConfig.partNumberWithIndex.find(partNumber_Split)->second;
|
||||
currentProduct->setText(QString::fromStdString(_core._appConfig.productDatas[index].name));
|
||||
*currentProductIndexPtr = index;
|
||||
startBtn->setEnabled(true);
|
||||
indexFromPartNumber = index;
|
||||
snIntputLine->setFocus();
|
||||
emit switchProductSignal(index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
currentProduct->setText("未找到对应料号!");
|
||||
startBtn->setDisabled(true);
|
||||
}
|
||||
}
|
||||
void startSwitch()
|
||||
{
|
||||
if(siwtchBtnState == 0)
|
||||
{
|
||||
currentProduct->hide();
|
||||
productSelect->show();
|
||||
switchBtn->setText("取消");
|
||||
siwtchBtnState = 1;
|
||||
return;
|
||||
}
|
||||
else if (siwtchBtnState == 1)
|
||||
{
|
||||
currentProduct->show();
|
||||
productSelect->hide();
|
||||
switchBtn->setText("修改");
|
||||
siwtchBtnState = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void currentProductSwitch(QString input)
|
||||
{
|
||||
int index = getMax(0,productSelect->currentIndex());
|
||||
*currentProductIndexPtr = index;
|
||||
|
||||
currentProduct->setText(input);
|
||||
//if (siwtchBtnState == 1)
|
||||
// return;
|
||||
startSwitch();
|
||||
}
|
||||
};
|
||||
|
||||
#pragma once
|
||||
Reference in New Issue
Block a user