code_production/app/HGProductionTool/form_burnmode.cpp

352 lines
10 KiB
C++

#include "form_burnmode.h"
#include "ui_form_burnmode.h"
#include "dialog_setburnsn.h"
#include "hgscanner.h"
#include "mainwindow.h"
#include "analysisjson.h"
#include "base/HGBase.h"
#include <QMessageBox>
#include <QLineEdit>
#include <QInputDialog>
Form_BurnMode::Form_BurnMode(class MainWindow *mainwnd, QWidget *parent) :
QWidget(parent),
m_curIndex(0),
m_mainwnd(mainwnd),
ui(new Ui::Form_BurnMode)
{
ui->setupUi(this);
connect(this, SIGNAL(testResult(bool)), this, SLOT(on_testResult(bool)), Qt::QueuedConnection);
initTableWidget();
}
Form_BurnMode::~Form_BurnMode()
{
delete ui;
}
void Form_BurnMode::addDevice(DeviceManager *devManager)
{
ui->tableWidget->setRowCount(m_curIndex + 1);
ui->tableWidget->setItem(m_curIndex, 0, new QTableWidgetItem(QString::number(m_curIndex + 1)));
ui->tableWidget->item(m_curIndex, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
QTableWidgetItem *check = new QTableWidgetItem();
check->setCheckState(Qt::Unchecked);
ui->tableWidget->setItem(m_curIndex, 1, check);
ui->tableWidget->item(m_curIndex, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui->tableWidget->setItem(m_curIndex, 2, new QTableWidgetItem(devManager->getDevName()));
ui->tableWidget->item(m_curIndex, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
QTableWidgetItem *item = ui->tableWidget->item(m_curIndex, 1);
QVariant var = QVariant::fromValue((void*)devManager);
item->setData(Qt::UserRole, var);
updatetablewidget();
m_curIndex++;
}
void Form_BurnMode::deleteDevice(QString devName)
{
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
QTableWidgetItem *item2 = ui->tableWidget->item(i, 2);
if (devName!= nullptr && item != nullptr)
{
if (devName == item2->text())
{
DeviceManager *devManager = (DeviceManager*)item->data(Qt::UserRole).value<void*>();
delete devManager;
ui->tableWidget->removeRow(i);
m_curIndex--;
break;
}
}
}
updatetablewidget();
}
void Form_BurnMode::on_testResult(bool setStatus)
{
m_mainwnd->releaseTesting();
}
void Form_BurnMode::initTableWidget()
{
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->setColumnCount(3);
ui->tableWidget->horizontalHeader()->setDefaultSectionSize(200);
// ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
QStringList header;
header<< tr("ID") << tr("selected") << tr("device");
ui->tableWidget->setHorizontalHeaderLabels(header);
QFont font = ui->tableWidget->horizontalHeader()->font();
font.setBold(true);
ui->tableWidget->horizontalHeader()->setFont(font);
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
ui->tableWidget->verticalHeader()->setDefaultSectionSize(10);
ui->tableWidget->setFrameShape(QFrame::NoFrame);
ui->tableWidget->setShowGrid(true);
ui->tableWidget->verticalHeader()->setVisible(false);
// ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableWidget->horizontalHeader()->setFixedHeight(30);
ui->tableWidget->clearContents();
}
void Form_BurnMode::updatetablewidget()
{
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
{
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(QString::number(i + 1)));
}
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
if (item != nullptr)
item->setCheckState(Qt::Checked);
}
ui->cbox_selectAll->setChecked(true);
}
void Form_BurnMode::on_cbox_selectAll_stateChanged(int arg1)
{
(void)arg1;
bool check = ui->cbox_selectAll->isChecked();
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
if (item != nullptr)
{
if (check)
item->setCheckState(Qt::Checked);
else
item->setCheckState(Qt::Unchecked);
}
}
}
void Form_BurnMode::on_pbtn_burn_clicked()
{
int select = 0;
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
if (item != nullptr && Qt::Checked == item->checkState())
{
select++;
}
}
if (select == 0)
{
QMessageBox::information(this, tr("tips"), tr("Please check a devices at least"));
return;
}
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
if (item != nullptr && Qt::Checked == item->checkState())
{
DeviceManager *devManager = (DeviceManager*)item->data(Qt::UserRole).value<void*>();
devManager->setBurnMode();
}
}
}
//void Form_BurnMode::on_pbtn_setSn_clicked()
//{
// int select = 0;
// for(int i = 0; i < ui->tableWidget->rowCount(); i++)
// {
// QTableWidgetItem *item = ui->tableWidget->item(i, 1);
// if (item != nullptr && Qt::Checked == item->checkState())
// {
// select++;
// }
// }
// if (select == 0)
// {
// QMessageBox::information(this, tr("tips"), tr("Please check a devices to set sn at least"));
// return;
// }
// else if (select > 1)
// {
// QMessageBox::information(this, tr("tips"), tr("Please check single devices to set sn"));
// return;
// }
// else if (select == 1)
// {
// for(int i = 0; i < ui->tableWidget->rowCount(); i++)
// {
// QTableWidgetItem *item = ui->tableWidget->item(i, 1);
// QTableWidgetItem *item2 = ui->tableWidget->item(i, 3);
// if (item != nullptr && Qt::Checked == item->checkState())
// {
// Dialog_SetBurnSn dlg(item2->text(), this);
// if (dlg.exec())
// {
// DeviceManager *devManager = (DeviceManager*)item->data(Qt::UserRole).value<void*>();
// devManager->setSn(dlg.getSn());
// item2->setText(devManager->getUpdatedSn());
// break;
// }
// }
// }
// }
//}
DeviceManager::DeviceManager(class MainWindow *mainwnd, class Form_BurnMode *burnMode, SANE_Handle handle, const QString & devName)
{
m_mainwnd = mainwnd;
m_burnMode = burnMode;
m_handle = handle;
m_devName = devName;
m_hg = new hgscanner(nullptr, m_burnMode, nullptr, m_handle);
}
DeviceManager::~DeviceManager()
{
delete m_hg;
m_hg = nullptr;
sane_close(m_handle);
}
QString DeviceManager::getDevName()
{
return m_devName;
}
void DeviceManager::setBurnMode()
{
const wchar_t *p = L"1";
m_mainwnd->addTestingRef();
func_test_go(HGPDTTOOLDB_NAME_REBOOT_DEVICE, p, m_hg);
}
//void DeviceManager::setSn(QString sn)
//{
// LPWRITECFG p = new WRITECFG;
// std::wstring sn2 = sn.toStdWString();
// p->cat = WRITE_CAT_SERIALNUM;
// p->val = (void*)sn2.c_str();
// m_mainwnd->addTestingRef();
// func_test_go(WRITE_CFG_NAME, (const wchar_t*)p, m_hg);
// setGlobalCfg();
// delete p;
//}
//QString DeviceManager::getUpdatedSn()
//{
// return m_mainwnd->getDevSn(m_handle);
//}
//void DeviceManager::setGlobalCfg()
//{
// HGChar cfgPath[512] = {0};
// HGBase_GetConfigPath(cfgPath, 512);
// HGBase_CreateDir(cfgPath);
// strcat(cfgPath, m_devType.toStdString().c_str());
// strcat(cfgPath, ".json");
// HGPdtToolDb_DownloadFile(m_pdtToolDbuserMgr, m_devType.toStdString().c_str(), cfgPath);
// AnalysisJson analysisJson(QString::fromStdString(cfgPath));
// assert(nullptr != m_hg);
// AnalysisJson::json_global jsonGlobal = analysisJson.GetGlobal();
// LPWRITECFG lp = new WRITECFG;
// VIDPID vidpid;
// vidpid.VID = jsonGlobal.vid_to;
// vidpid.PID = jsonGlobal.pid_to;
// int vidpidValue = vidpid.Value;
// lp->cat = WRITE_CAT_VID_PID;
// lp->val = (void*)&vidpidValue;
// m_mainwnd->addTestingRef();
// func_test_go(WRITE_CFG_NAME, (const wchar_t*)lp, m_hg);
// int speedMode = jsonGlobal.speed_mode ;
// lp->cat = WRITE_CAT_SPEED;
// lp->val = (void*)&speedMode;
// m_mainwnd->addTestingRef();
// func_test_go(WRITE_CFG_NAME, (const wchar_t*)lp, m_hg);
// int sleepTime = jsonGlobal.sleep_time;
// lp->cat = WRITE_CAT_SLEEP;
// lp->val = (void*)&sleepTime;
// m_mainwnd->addTestingRef();
// func_test_go(WRITE_CFG_NAME, (const wchar_t*)lp, m_hg);
// delete lp;
//}
void Form_BurnMode::on_tableWidget_itemDoubleClicked(QTableWidgetItem *item)
{
int row = item->row();
QTableWidgetItem *item2 = ui->tableWidget->item(row, 1);
if (item2->checkState() == Qt::Checked)
{
item2->setCheckState(Qt::Unchecked);
}
else
{
item2->setCheckState(Qt::Checked);
}
}
void Form_BurnMode::on_pbtn_close_clicked()
{
int select = 0;
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
if (item != nullptr && Qt::Checked == item->checkState())
{
select++;
}
}
if (select == 0)
{
QMessageBox::information(this, tr("tips"), tr("Please check a devices at least"));
return;
}
int rowCount = ui->tableWidget->rowCount();
for (int i = rowCount - 1; i >= 0; --i)
{
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
if (item != nullptr && Qt::Checked == item->checkState())
{
DeviceManager *devManager = (DeviceManager*)item->data(Qt::UserRole).value<void*>();
delete devManager;
ui->tableWidget->removeRow(i);
m_curIndex--;
}
}
updatetablewidget();
}