191 lines
5.4 KiB
C++
191 lines
5.4 KiB
C++
#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/fancyWarnWindow.h>
|
|
#include <opencv.hpp>
|
|
#include <handleAi/handleAiSimpleDet.h>
|
|
#include <unordered_map>
|
|
#include <simpleTools/stringAlgo.h>
|
|
#include <qmutex.h>
|
|
#include <appConfig/appConfig.h>
|
|
#include <qlineedit.h>
|
|
#include <iostream>
|
|
#include <appCore.hpp>
|
|
class switchProductWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
//
|
|
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();
|
|
fancyButtonText* startBtn;
|
|
QLineEdit* snIntputLine = new QLineEdit();
|
|
//料号显示
|
|
QComboBox* productSelect = new QComboBox(this);
|
|
QLabel* currentProduct = new QLabel(this);
|
|
//料号类型
|
|
QComboBox* productNameTypeSwitch = new QComboBox(this);
|
|
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);
|
|
}
|
|
snIntputLine->setFixedHeight(50);
|
|
snIntputLine->setFont(font);
|
|
|
|
QHBoxLayout* hBtnLayout = new QHBoxLayout();
|
|
startBtn = new fancyButtonText(80, -1, "运行", "运行检测程序");
|
|
hBtnLayout->addWidget(snIntputLine);
|
|
hBtnLayout->addWidget(startBtn);
|
|
|
|
layout->addLayout(hBtnLayout);
|
|
productSelectFresh(0);
|
|
connect(startBtn, &QPushButton::clicked, this, [=]()
|
|
{
|
|
emit startArmProgramSignal(productSelect->currentIndex(), 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());
|
|
});
|
|
}
|
|
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)));
|
|
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();
|
|
startBtn->setText("运行");
|
|
snIntputLine->setDisabled(false);
|
|
std::cout << "按下软件运行" << std::endl;
|
|
}
|
|
else
|
|
{
|
|
startBtn->toRed();
|
|
startBtn->setText("急停");
|
|
snIntputLine->setDisabled(true);
|
|
std::cout << "按下软件急停" << std::endl;
|
|
}
|
|
}
|
|
signals:
|
|
void startArmProgramSignal(int,QString);
|
|
void switchProductSignal(int);
|
|
private:
|
|
int siwtchBtnState = 0;
|
|
private slots:
|
|
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 = productSelect->currentIndex();
|
|
*currentProductIndexPtr = index;
|
|
|
|
currentProduct->setText(input);
|
|
//if (siwtchBtnState == 1)
|
|
// return;
|
|
startSwitch();
|
|
}
|
|
};
|
|
|
|
#pragma once |