jianbin.chang常健彬 ce734d1af1 厂家提供原始代码
2025-07-17 08:39:15 +08:00

3097 lines
105 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <Python.h>
#include "micjishu.h"
#include "ui_micjishu.h"
#include<QMessageBox>
#include<QScrollBar>
#include<QGraphicsDropShadowEffect>
#include <QtConcurrent/QtConcurrent>
QString id6;
// extern QString xiangcheng;
// extern QString shenghao;
// int x;
// int y;
QString savelujing2;
QSqlDatabase dbmic;
micjishu::micjishu(QWidget *parent) :
QWidget(parent),
ui(new Ui::micjishu)
{
ui->setupUi(this);
getshui();
m_michistoricalrecords=new michistoricalrecords;
m_ziwai=new ziwai;
connect( m_michistoricalrecords, &michistoricalrecords::fanhui, this, [=](){this->showMaximized();m_michistoricalrecords->hide();});
ui->tableWidget->setRowCount(10);
ui->tableWidget->setColumnCount(10);
for (int i=0;i<=ui->tableWidget->rowCount() ;i++ ) {
ui->tableWidget->setRowHeight(i,35);
}
ui->tableWidget->setColumnWidth(0,45);
ui->tableWidget->setColumnWidth(1,127);
ui->tableWidget->setColumnWidth(2,127);
ui->tableWidget->setColumnWidth(3,127);
ui->tableWidget->setColumnWidth(4,48);
ui->tableWidget->setColumnWidth(5,43);
ui->tableWidget->setColumnWidth(6,68);
ui->tableWidget->setColumnWidth(7,43);
ui->tableWidget->setColumnWidth(8,43);
ui->tableWidget->setColumnWidth(9,73);
ui->tableWidget_2->setRowCount(10);
ui->tableWidget_2->setColumnCount(10);
for (int i=0;i<=ui->tableWidget_2->rowCount() ;i++ ) {
ui->tableWidget_2->setRowHeight(i,35);
}
ui->tableWidget_2->setColumnWidth(0,45);
ui->tableWidget_2->setColumnWidth(1,127);
ui->tableWidget_2->setColumnWidth(2,127);
ui->tableWidget_2->setColumnWidth(3,127);
ui->tableWidget_2->setColumnWidth(4,53);
ui->tableWidget_2->setColumnWidth(5,48);
ui->tableWidget_2->setColumnWidth(6,48);
ui->tableWidget_2->setColumnWidth(7,48);
ui->tableWidget_2->setColumnWidth(8,48);
ui->tableWidget_2->setColumnWidth(9,73);
ui->tableWidget->setHorizontalHeaderLabels(headers);
for (int row = 0; row < 10; ++row) { QTableWidgetItem *item = new QTableWidgetItem(xuhao.at(row));
ui->tableWidget->setItem(row, 0, item);}
ui->tableWidget_2->setHorizontalHeaderLabels(headers);
for (int row = 0; row < 10; ++row) { QTableWidgetItem *item = new QTableWidgetItem(xuhao.at(row));
ui->tableWidget_2->setItem(row, 0, item);}
for (int row = 5; row < ui->tableWidget->rowCount(); ++row) {
ui-> tableWidget->setRowHidden(row, true);
}
for (int row = 0; row <5; ++row) {
ui-> tableWidget_2->setRowHidden(row, true);
}
m_zidingyi=new zidingyi;
ui->pushButton_5->setHidden(true);
ui->widget->setFixedSize(745,520);
ui->label_5->setFixedSize(745,520);
ui->label_6->setFixedSize(745,520);
ui->tableWidget_3->setFixedSize(170,800);
ui->tableWidget_2->setFixedSize(745,210);
ui->tableWidget->setFixedSize(745,210);
ui->pushButton->setFixedSize(120,35);
ui->pushButton_2->setFixedSize(92,35);
ui->pushButton_5->setFixedSize(92,35);
ui->pushButton_9->setFixedSize(92,35);
ui->pushButton_10->setFixedSize(92,35);
ui->tableWidget_2->horizontalHeader()->setFixedHeight(40);
ui->tableWidget->horizontalHeader()->setFixedHeight(40);
ui->widget->setHidden(false);
ui->lineEdit->setFixedSize(170,30);
ui->comboBox->setFixedSize(170,30);
ui->comboBox_2->setFixedSize(170,30);
ui->tableWidget->verticalHeader()->setVisible(false);
ui->tableWidget_2->verticalHeader()->setVisible(false);
m_maxtu=new maxtu;
connect(this, SIGNAL(yuan(QPixmap)),m_maxtu, SLOT(getyuan(QPixmap)));
connect(m_zidingyi, SIGNAL(ming(QString)),this, SLOT(getming(QString)));
connect(this, SIGNAL(shuaxin()),m_michistoricalrecords, SLOT(getshuaxin()));
connect(this,&micjishu::shuaxin,m_michistoricalrecords,&michistoricalrecords::getshuaxin);
ui->label_8->setHidden(true);
ui->label_9->setHidden(true);
ui->label_10->setHidden(true);
ui->label_11->setHidden(true);
ui->label_12->setHidden(true);
ui->pushButton_7->setHidden(true);
ui->label_7->setHidden(true);
setMouseTracking(true);
connect(m_michistoricalrecords, SIGNAL(guan2()), this, SLOT(getguan()));
ui->tableWidget->setShowGrid(false);
ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableWidget_2->setShowGrid(false);
ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableWidget_2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableWidget_3->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableWidget_3->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableWidget_2->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
// 设置鼠标点击行为为不选中任何项
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
ui->tableWidget_2->setSelectionMode(QAbstractItemView::NoSelection);
// 设置鼠标点击行为为不选中任何项
ui->tableWidget_2->setSelectionBehavior(QAbstractItemView::SelectItems);
ui->pushButton_3->setHidden(true);
ui->label_7->setHidden(true);
connect(m_michistoricalrecords, &michistoricalrecords::tuichu2, this, [=](){emit tuichu();});
ui->tableWidget_3->setColumnCount(2);
ui->tableWidget_3->setColumnWidth(0, 170); // 设置第一列宽度示例为100像素
ui->tableWidget_3->setColumnWidth(1, 0); // 将第二列列索引为1的宽度设置为0实现隐藏效果
ui->tableWidget_3->horizontalHeader()->setVisible(false);
ui->tableWidget_3->verticalHeader()->setVisible(false);
connect(ui->tableWidget_3, &QTableWidget::itemClicked, this, &micjishu::on_tableWidget_3_itemClicked);
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
//设置阴影距离
shadow->setOffset(0, 0);
//设置阴影颜色
shadow->setColor(QColor(214, 214, 214));
//设置阴影圆角
shadow->setBlurRadius(30);
//给嵌套QWidget设置阴影
ui->frame->setFixedSize(1570,907);
ui->frame->setGraphicsEffect(shadow);
QGraphicsDropShadowEffect *shadow2 = new QGraphicsDropShadowEffect(this);
//设置阴影距离
shadow2->setOffset(0, 0);
//设置阴影颜色
shadow2->setColor(QColor(214, 214, 214));
//设置阴影圆角
shadow2->setBlurRadius(30);
ui->frame_2->setFixedSize(175,907);
ui->frame_2->setGraphicsEffect(shadow2);
ui->pushButton_4->setFixedSize(170,30);
ui->pushButton_11->setFixedSize(170,30);
// ui->frame_2->setFixedWidth(1720);
ui->checkBox->setHidden(true);
ui->checkBox_2->setHidden(true);
//ui->lineEdit->setHidden(true);
ui->label_3->setHidden(true);
ui->label_4->setHidden(true);
ui->label_15->setHidden(true);
ui->pushButton_6->setHidden(true);
ui->pushButton_8->setHidden(true);
//ui->pushButton_4->setHidden(true);
ui->label_5->setHidden(false);
ui->label_6->setHidden(true);
m_msgBox=new msgBox;
ui->widget_5->setFixedHeight(50);
timer = new QTimer(this);
connect(m_zidingyi,&zidingyi::quxiao,this,[=](){jixu=false;});
ui->comboBox->setCurrentIndex(-1);
ui->comboBox_2->setCurrentIndex(-1);
connect(this, &micjishu::print, m_pp, &printpage::getprint);
}
micjishu::~micjishu()
{
delete ui;
}
void micjishu::setbiaoge()
{
}
void micjishu::getming(QString s)
{
jixu=true;
ui->label_15->clear();
ui->label_15->setText(s);
m_msgBox->show();
}
void micjishu::on_tableWidget_3_itemClicked(QTableWidgetItem *item)
{
// 获取点击的单元格所在的行索引
int row = item->row();
// 获取该行第一列对应的QTableWidgetItem假设第一列存放图片路径相关信息
QTableWidgetItem *pixmapItem = ui->tableWidget_3->item(row, 1);
if (pixmapItem) {
// 获取之前设置的图片路径
QString filePath = pixmapItem->text();
qDebug()<<filePath;
QPixmap pixmap(filePath);
if (!pixmap.isNull()) {
ui->label_6->setPixmap(pixmap);
ui->label_6->setScaledContents(true); // 设置图片自动缩放以适应QLabel大小
}
}
}
void micjishu::MICzhi(){
//ECV值
if(zhong=="新型隐球菌VN"){
qDebug()<<"新型隐球菌VN";
ECVList.append("8");
ECVList.append("0.25");
ECVList.append("0.25");
ECVList.append("0.25");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("8");
ECVList.append(" ");
ECVList.append("0.5");
kongzhi();
}else if(zhong=="格特隐球菌VG"){
ECVList.append("16");
ECVList.append("0.5");
ECVList.append("0.5");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("4");
ECVList.append(" ");
ECVList.append("0.5");
kongzhi();
}else if(zhong=="格特隐球菌VGⅡ"){
ECVList.append("32");
ECVList.append("1");
ECVList.append("0.5");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("32");
ECVList.append(" ");
ECVList.append("1");
kongzhi();
}
else if(zhong=="白念珠菌"){
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("0.06");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("2");
SList.append("≤2");
SList.append(" ");
SList.append("≤0.12");
SList.append(" ");
SList.append(" ");
SList.append("≤0.25");
SList.append("≤0.25");
SList.append(" ");
SList.append("≤0.25");
SList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append("0.25-0.5");
IList.append(" ");
IList.append(" ");
IList.append("0.5");
IList.append("0.5");
IList.append(" ");
IList.append("0.5");
IList.append(" ");
SDDList.append("4");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
RList.append("≥8");
RList.append(" ");
RList.append("≥1");
RList.append(" ");
RList.append(" ");
RList.append("≥1");
RList.append("≥1");
RList.append(" ");
RList.append("≥1");
RList.append(" ");
} else if(zhong=="光滑念珠菌"){
qDebug() << "光滑念珠菌";
ECVList.append(" ");
ECVList.append("4");
ECVList.append("0.25");
ECVList.append("1");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("2");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append("≤0.12");
SList.append("≤0.06");
SList.append(" ");
SList.append("≤0.12");
SList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append("0.25");
IList.append("0.12");
IList.append(" ");
IList.append("0.25");
IList.append(" ");
SDDList.append("≤32");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
RList.append("≥64");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append("≥0.5");
RList.append("≥0.25");
RList.append(" ");
RList.append("≥0.5");
RList.append(" ");
} else if(zhong=="热带念珠菌"){
qDebug() << "热带念珠菌";
ECVList.append(" ");
ECVList.append("0.5");
ECVList.append(" ");
ECVList.append("0.12");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("2");
SList.append("≤2");
SList.append(" ");
SList.append("0.12");
SList.append(" ");
SList.append(" ");
SList.append("≤0.25");
SList.append("≤0.25");
SList.append(" ");
SList.append("≤0.25");
SList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append("0.25-0.5");
IList.append(" ");
IList.append(" ");
IList.append("0.5");
IList.append("0.5");
IList.append(" ");
IList.append("0.5");
IList.append(" ");
SDDList.append("4");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
RList.append("≥8");
RList.append(" ");
RList.append("≥1");
RList.append(" ");
RList.append(" ");
RList.append("≥1");
RList.append("≥1");
RList.append(" ");
RList.append("≥1");
RList.append(" ");
}else if(zhong=="近平滑念珠菌"){
ECVList.append(" ");
ECVList.append("0.5");
ECVList.append(" ");
ECVList.append("0.25");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("1");
SList.append("≤2");
SList.append(" ");
SList.append("0.12");
SList.append(" ");
SList.append(" ");
SList.append("≤2");
SList.append("≤2");
SList.append(" ");
SList.append("≤2");
SList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append("0.25-0.5");
IList.append(" ");
IList.append(" ");
IList.append("4");
IList.append("4");
IList.append(" ");
IList.append("4");
IList.append(" ");
SDDList.append("4");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
RList.append("≥8");
RList.append(" ");
RList.append("≥1");
RList.append(" ");
RList.append(" ");
RList.append("≥8");
RList.append("≥8");
RList.append(" ");
RList.append("≥8");
RList.append(" ");
}else if(zhong=="克柔念珠菌"){
ECVList.append(" ");
ECVList.append("1");
ECVList.append(" ");
ECVList.append("0.5");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("2");
SList.append(" ");
SList.append(" ");
SList.append("≤0.5");
SList.append(" ");
SList.append(" ");
SList.append("≤0.25");
SList.append("≤0.25");
SList.append(" ");
SList.append("≤0.25");
SList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append("1");
IList.append(" ");
IList.append(" ");
IList.append("0.5");
IList.append("0.5");
IList.append(" ");
IList.append("0.5");
IList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
RList.append("≥1");
RList.append(" ");
RList.append("≥2");
RList.append(" ");
RList.append(" ");
RList.append("≥1");
RList.append("≥1");
RList.append(" ");
RList.append("≥1");
RList.append(" ");
}else if(zhong=="季也蒙念珠菌"){
ECVList.append("8");
ECVList.append("2");
ECVList.append(" ");
ECVList.append("0.5");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("2");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append("≤2");
SList.append("≤2");
SList.append(" ");
SList.append("≤2");
SList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append("4");
IList.append("4");
IList.append(" ");
IList.append("4");
IList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append("≥8");
RList.append("≥8");
RList.append(" ");
RList.append("≥8");
RList.append(" ");
}else if(zhong=="都柏林念珠菌"){
ECVList.append("0.5");
ECVList.append("0.25");
ECVList.append(" ");
ECVList.append("0.12");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("0.12");
ECVList.append(" ");
ECVList.append("0.12");
ECVList.append("0.5");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
}else if(zhong=="烟曲霉"){
ECVList.append(" ");
ECVList.append("1");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("1");
ECVList.append("0.5");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("2");
SList.append(" ");
SList.append(" ");
SList.append("≤0.5");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append("1");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append("≥2");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
}
else if(zhong=="黄曲霉"){
ECVList.append(" ");
ECVList.append("1");
ECVList.append("2");
ECVList.append("0.5");
ECVList.append("1");
ECVList.append("0.5");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("4");
kongzhi();
}else if(zhong=="黑曲霉"){
ECVList.append(" ");
ECVList.append("4");
ECVList.append("2");
ECVList.append("2");
ECVList.append("4");
ECVList.append("0.25");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("2");
kongzhi();
}else if(zhong=="土曲霉"){
ECVList.append(" ");
ECVList.append("2");
ECVList.append("2");
ECVList.append("1");
ECVList.append("1");
ECVList.append("0.12");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append("4");
kongzhi();
}else{
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
ECVList.append(" ");
kongzhi();
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item4 = new QTableWidgetItem(ECVList.at(row));
ui->tableWidget->setItem(row, 4, item4);
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item4 = new QTableWidgetItem(SList.at(row));
ui->tableWidget->setItem(row, 5, item4);
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item4 = new QTableWidgetItem(IList.at(row));
ui->tableWidget->setItem(row, 6, item4);
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item4 = new QTableWidgetItem(SDDList.at(row));
ui->tableWidget->setItem(row, 7, item4);
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item4 = new QTableWidgetItem(RList.at(row));
ui->tableWidget->setItem(row, 8, item4);
}
qDebug() << "SList:" << SList;
qDebug() << "IList:" << IList;
qDebug() << "SDDList:" << SDDList;
qDebug() << "RList:" << RList;
};
void micjishu::kongzhi(){
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
SDDList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
IList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
RList.append(" ");
};
void micjishu::usepython()
{
// Py_SetPythonHome(L"C:/ProgramData/Anaconda3");
Py_SetPythonHome(L"D:/python");
Py_Initialize();
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.argv = ['python.py']");
PyRun_SimpleString("sys.path.append('./')");
PyObject* pModule = PyImport_ImportModule("MIC_main");
if (!pModule)
{
PyErr_Print();
qDebug()<<"Cant open python file!\n";
QMessageBox::information(NULL, "提示", "图片识别有误,请重试");
m_msgBox->close();
return; // 提前返回避免继续执行
}
else{
qDebug()<<"file of python ac been opened";}
PyObject* pFunhello= PyObject_GetAttrString(pModule,"main_function");
if(!pFunhello){
qDebug()<<"Get function hello failed";
QMessageBox::information(NULL, "提示", "图片识别有误,请重试");
m_msgBox->close();
return; // 提前返回避免继续执行
}
else
{
PyObject* args = PyTuple_New(7); // 创建一个包含2个元素的元组用于存放参数
// 设置第一个参数这里假设是整数类型设置为10可根据实际需求替换数值
PyObject* arg1 = PyUnicode_FromString("use/MIC/MIC/药敏板药物信息示例/药敏板药物信息示例.xlsx");
PyTuple_SetItem(args, 0, arg1);
PyObject* arg2 = PyUnicode_FromString("use/MIC/MIC/药敏板药物信息示例/药敏板药品判读规则表格.xlsx");
PyTuple_SetItem(args, 1, arg2);
PyObject* arg3 = PyUnicode_FromString("use/MIC/MIC/药敏板药物信息示例/MIC解释标准及ECV值.xlsx");
PyTuple_SetItem(args, 2, arg3);
PyObject* arg4 = PyUnicode_FromString(savelujing2.toUtf8().constData());
PyTuple_SetItem(args, 3, arg4);
PyObject* arg5 = PyUnicode_FromString("use/4.png");
PyTuple_SetItem(args, 4, arg5);
shu= ui->comboBox->currentText();
QByteArray byteArray = shu.toUtf8();
PyObject* arg6 = PyUnicode_FromString(byteArray.constData());
PyTuple_SetItem(args, 5, arg6);
zhong= ui->comboBox_2->currentText();
QByteArray byteArray2 = zhong.toUtf8();
PyObject* arg7 = PyUnicode_FromString(byteArray2.constData());
PyTuple_SetItem(args, 6, arg7);
PyObject* result = PyObject_CallObject(pFunhello, args);
if (!result)
{ PyErr_Print();
qDebug() << "Call function failed";
QMessageBox::information(NULL, "提示", "图片识别有误,请重试");
m_msgBox->close();
return; // 提前返回避免继续执行
}
else
{//配1
//这里是如果能接受返回值
if (PyTuple_Check(result))
{//配2
// 获取元组中的元素个数
Py_ssize_t tupleSize = PyTuple_Size(result);
if (tupleSize == 5)
{
// 获取第一个列表并处理
PyObject* list1 = PyTuple_GetItem(result, 0);
if (PyList_Check(list1))
{
Py_ssize_t list1Size = PyList_Size(list1);
if (list1Size == 10)
{
for (Py_ssize_t i = 0; i < list1Size; ++i) {
PyObject* element = PyList_GetItem(list1, i);
if (PyUnicode_Check(element)) {
const char* str = PyUnicode_AsUTF8(element);
chineseNames.append(QString::fromUtf8(str));
}
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item1 = new QTableWidgetItem(chineseNames.at(row));
ui->tableWidget->setItem(row, 1, item1);
}
}
else
{
qDebug() << "The first returned list does not have 3 elements as expected";
}
}
else
{
qDebug() << "The first element in the returned tuple is not a list as expected";
}
// 获取第二个列表并处理
PyObject* list2 = PyTuple_GetItem(result, 1);
if (PyList_Check(list2))
{
Py_ssize_t list2Size = PyList_Size(list2);
if (list2Size == 10)
{
for (Py_ssize_t i = 0; i < list2Size; ++i) {
PyObject* element = PyList_GetItem(list2, i);
if (PyUnicode_Check(element)) {
const char* str = PyUnicode_AsUTF8(element);
englishNames.append(QString::fromUtf8(str));
}
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item2 = new QTableWidgetItem(englishNames.at(row));
ui->tableWidget->setItem(row, 2, item2);
}
}
else
{
qDebug() << "The second returned list does not have 3 elements as expected";
}
}
else
{
qDebug() << "The second element in the returned tuple is not a list as expected";
}
// 获取第三个列表并处理
PyObject* list3 = PyTuple_GetItem(result, 2);
if (PyList_Check(list3))
{
Py_ssize_t list13Size = PyList_Size(list3);
if (list13Size == 10)
{
for (Py_ssize_t i = 0; i < list13Size; ++i) {
PyObject* element = PyList_GetItem(list3, i);
if (PyUnicode_Check(element)) {
const char* str = PyUnicode_AsUTF8(element);
if(shu=="曲霉属"&&(i==5||i==6||i==8)){
micValues.append(" ");
}else{
micValues.append(QString::fromUtf8(str));
}
}
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item3 = new QTableWidgetItem(micValues.at(row));
ui->tableWidget->setItem(row, 3, item3);
}
}
else
{
qDebug() << "The first returned list does not have 3 elements as expected";
}
}
else
{
qDebug() << "The first element in the returned tuple is not a list as expected";
}
// 获取第四个列表并处理
PyObject* list4 = PyTuple_GetItem(result, 3);
if (PyList_Check(list4))
{
Py_ssize_t list41Size = PyList_Size(list4);
if (list41Size == 10)
{
MICzhi();
for (Py_ssize_t i = 0; i < list41Size; ++i) {
PyObject* element = PyList_GetItem(list4, i);
if (!element || !PyUnicode_Check(element)) {
explanations.append("无效的Python对象");
continue;
}
const char* str = PyUnicode_AsUTF8(element);
if (!str) {
explanations.append("Python字符串转换失败");
continue;
}
// 检查 micValues 和 ECVList 是否越界
if (i >= micValues.size() || i >= ECVList.size()) {
explanations.append("数据不足");
continue;
}
qDebug()<<zhong;
if (zhong == "新型隐球菌VN"&&(i == 0 || i == 1 || i == 2 || i == 3 || i == 7|| i == 9)) {
bool ok1, ok2;
double micValue = micValues[i].toDouble(&ok1);
double ecvValue = ECVList[i].toDouble(&ok2);
if (!ok1 || !ok2) {
explanations.append("数值转换失败");
} else if (micValue <= ecvValue) {
explanations.append("野生型");
} else {
explanations.append("非野生型");
}
} else if (zhong == "新型隐球菌VN"&&(i == 5 || i == 6 || i == 8)) {
explanations.append("天然耐药");
}else if (zhong == "格特隐球菌VG"&&(i == 0 || i == 1 || i == 2 || i == 7|| i == 9)) {
qDebug()<<"格特隐球菌VN";
bool ok1, ok2;
double micValue = micValues[i].toDouble(&ok1);
double ecvValue = ECVList[i].toDouble(&ok2);
if (!ok1 || !ok2) {
explanations.append("数值转换失败");
} else if (micValue <= ecvValue) {
explanations.append("野生型");
} else {
explanations.append("非野生型");
}
} else if (zhong == "格特隐球菌VG"&&(i == 5 || i == 6 || i == 8) ){
explanations.append("天然耐药");
}else if (zhong == "格特隐球菌VGⅡ"&&(i == 0 || i == 1 || i == 2 || i == 7|| i == 9)) {
qDebug()<<"格特隐球菌VGⅡ";
bool ok1, ok2;
double micValue = micValues[i].toDouble(&ok1);
double ecvValue = ECVList[i].toDouble(&ok2);
if (!ok1 || !ok2) {
explanations.append("数值转换失败");
} else if (micValue <= ecvValue) {
explanations.append("野生型");
} else {
explanations.append("非野生型");
}
} else if (zhong == "格特隐球菌VGⅡ"&&(i == 5 || i == 6 || i == 8) ){
explanations.append("天然耐药");
}
else if(shu=="曲霉属"&&i==0){
explanations.append("天然耐药");
}else if(shu=="曲霉属"&&(i==5||i==6||i==8)){
explanations.append("");
//另外需要都ECV值
}else if (zhong == "克柔念珠菌" && i == 0) {
explanations.append("天然耐药");
}
else {
QString utf8Str = QString::fromUtf8(str);
if(utf8Str=="S"){
utf8Str="敏感";
}else if(utf8Str=="I"){
utf8Str="中介";
}else if(utf8Str=="SDD"){
utf8Str="剂量依赖性敏感";
}else if(utf8Str=="R"){
utf8Str="耐药";
}
explanations.append(utf8Str);
qDebug() << "Element at index" << i << ": " << utf8Str;
}
}
qDebug()<<"mic值"<<micValues;
qDebug()<<"ecv值"<<ECVList;
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item4 = new QTableWidgetItem(explanations.at(row));
ui->tableWidget->setItem(row, 9, item4);
}
}
else
{
qDebug() << "The first returned list does not have 3 elements as expected";
}
}
else
{
qDebug() << "The first element in the returned tuple is not a list as expected";
}
// 获取第五个列表并处理
PyObject* MIC_position_list = PyTuple_GetItem(result, 4);
if (PyList_Check(MIC_position_list)) {
Py_ssize_t positionListSize = PyList_Size(MIC_position_list);
for (Py_ssize_t i = 0; i < positionListSize; ++i) {
PyObject* element = PyList_GetItem(MIC_position_list, i);
if (PyTuple_Check(element)) {
Py_ssize_t tupleElementSize = PyTuple_Size(element);
if (tupleElementSize == 2) {
PyObject* xObj = PyTuple_GetItem(element, 0);
PyObject* yObj = PyTuple_GetItem(element, 1);
if (PyLong_Check(xObj) && PyLong_Check(yObj)) {
long x = PyLong_AsLong(xObj);
long y = PyLong_AsLong(yObj);
//qDebug() << "MIC Position: (" << x << ", " << y << ")";
QString positionStr = QString("(%1, %2)").arg(x).arg(y);
positionStrList.append(positionStr);
}
}
}
}
}
chineseNames.clear();
englishNames.clear();
micValues.clear();
explanations.clear();
positionStrList.clear();
ECVList.clear();
SList.clear();
IList.clear();
SDDList.clear();
RList.clear();
//为表格增加序号1-10
for (int row = 0; row < 10; ++row) { QTableWidgetItem *item = new QTableWidgetItem(xuhao.at(row));
ui->tableWidget->setItem(row, 0, item);}
for (int row = 0; row < 10; ++row) { QTableWidgetItem *item = new QTableWidgetItem(xuhao.at(row));
ui->tableWidget_2->setItem(row, 0, item);}
//文字居中
for (int i = 0; i < ui->tableWidget->rowCount(); ++i) {
for (int j = 0; j < ui->tableWidget->columnCount(); ++j) {
QTableWidgetItem *item = ui->tableWidget->item(i, j);
if (item) {
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
}
}
for (int i = 0; i < ui->tableWidget_2->rowCount(); ++i) {
for (int j = 0; j < ui->tableWidget_2->columnCount(); ++j) {
QTableWidgetItem *item = ui->tableWidget_2->item(i, j);
if (item) {
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
}
}
//显示图片
QString aFile = QString("use/4.png");
ui->label_5->setHidden(true);
ui->label_6->setHidden(false);
ui->label_6->setPixmap(aFile);
ui->label_6->setScaledContents(true);
fenge();
QPalette palette = ui->tableWidget->palette();
QColor color2= Qt::white;
QColor color1 = QColor(229,247,255);
for (int i = 0; i < ui->tableWidget->rowCount(); ++i) {
for (int col = 0; col < ui->tableWidget->columnCount(); ++col) {
QTableWidgetItem *item = ui->tableWidget->item(i, col);
if (!item) {
item = new QTableWidgetItem();
ui->tableWidget->setItem(i, col, item);
}
if (i % 2 == 0) {
item->setBackground(QBrush(color1));
} else {
item->setBackground(QBrush(color2));
}
}
}
for (int i = 0; i < ui->tableWidget->rowCount(); ++i) {
for (int col = 0; col < ui->tableWidget->columnCount(); ++col) {
QTableWidgetItem *item = ui->tableWidget_2->item(i, col);
if (!item) {
item = new QTableWidgetItem();
ui->tableWidget->setItem(i, col, item);
}
if (i % 2 == 0) {
item->setBackground(QBrush(color2));
} else {
item->setBackground(QBrush(color1));
}
}
}
get();
QString timeStamp = QDate::currentDate().toString("yyyy-MM-dd");
QString folderName = "use/micpandu/" + timeStamp;
QString timeStampFull = QTime::currentTime().toString("hh-mm-ss");
//如果没有自命名
if(ui->label_15->text().isEmpty()){
savePath3 = folderName + "/" + timeStampFull + "_Y" + ".png";
savePath4 = folderName + "/" + timeStampFull + "_J" + ".png";
savePath5 = folderName + "/" + timeStampFull + ".csv";
QPixmap pixmap = ui->label_5->pixmap();
QPixmap pixmap2 = ui->label_6->pixmap();
// 开启事务,确保操作的原子性
dbmic.transaction();
// 第一步:更新现有行的 xuhao使其序号依次加 1
// 从最大的 xuhao 开始递减更新,避免 xuhao 冲突
QSqlQuery updateQuery(dbmic);
updateQuery.prepare("SELECT MAX(xuhao) FROM micjishu");
if (updateQuery.exec() && updateQuery.next()) {
int maxXuhao = updateQuery.value(0).toInt();
for (int i = maxXuhao; i >= 1; --i) {
QSqlQuery updateXuhaoQuery(dbmic);
updateXuhaoQuery.prepare("UPDATE micjishu SET xuhao = :newXuhao WHERE xuhao = :oldXuhao");
updateXuhaoQuery.bindValue(":newXuhao", i + 1);
updateXuhaoQuery.bindValue(":oldXuhao", i);
if (!updateXuhaoQuery.exec()) {
qDebug() << "更新 xuhao 失败:" << updateXuhaoQuery.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
}
} else {
qDebug() << "获取最大 xuhao 失败:" << updateQuery.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
// 新增:插入多列数据
QSqlQuery query(dbmic);
query.prepare("INSERT INTO micjishu (xuhao, time, yuanshi, jieguo, xiangcheng,junshu,junzhong,weihao,shenghao,caozuo) VALUES ( :xuhao,:time, :yuanshi, :jieguo, :xiangcheng, :junshu, :junzhong, :weihao, :shenghao,:caozuo)");
query.bindValue(":xuhao", 1);
query.bindValue(":time", gettime());
query.bindValue(":yuanshi", savePath3);
query.bindValue(":jieguo", savePath4);
query.bindValue(":xiangcheng", "真菌药敏试剂盒");
query.bindValue(":junshu", ui->comboBox->currentText());
query.bindValue(":junzhong", ui->comboBox_2->currentText());
query.bindValue(":weihao", ui->label_9->text());
query.bindValue(":shenghao", ui->label_10->text());
query.bindValue(":caozuo", savePath5);
if (!query.exec()) {
qDebug() << "插入多列数据失败:" << query.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
// 提交事务
if (dbmic.commit()) {
qDebug() << "数据插入并重新排序成功";
emit shuaxin();
} else {
qDebug() << "事务提交失败:" << dbmic.lastError().text();
}
QTableWidgetItem *filePathItem = new QTableWidgetItem();
filePathItem->setText(savePath4);
QTableWidgetItem *pixmapItem = new QTableWidgetItem();
if (pixmap2.isNull()) {
qDebug() << "图片加载失败,请检查文件路径和图片格式是否正确";
return;
}
// 对图片进行缩放保持长宽比使其适应指定大小这里设置为100x100
pixmap2 = pixmap2.scaled(170, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
pixmapItem->setIcon(QIcon(pixmap2));
ui->tableWidget_3->setIconSize(QSize(170,120));
// 插入新行
ui->tableWidget_3->insertRow(row);
// 将Pixmap对应的Item添加到第一列
ui->tableWidget_3->setItem(row, 0, pixmapItem);
// 将文件路径对应的Item添加到第二列
ui->tableWidget_3->setItem(row, 1, filePathItem);
ui->tableWidget_3->setRowHeight(row,130);
row++;
m_msgBox->close();
}
else{
QString zidingyi=ui->label_15->text();
savePath = folderName + "/" + zidingyi + "_Y" + ".png";
savePath2 = folderName + "/" + zidingyi + "_J" + ".png";
savePath6 = folderName + "/" + zidingyi + ".csv";
QPixmap pixmap = ui->label_5->pixmap();
QPixmap pixmap2 = ui->label_6->pixmap();
// 开启事务,确保操作的原子性
dbmic.transaction();
// 第一步:更新现有行的 xuhao使其序号依次加 1
// 从最大的 xuhao 开始递减更新,避免 xuhao 冲突
QSqlQuery updateQuery(dbmic);
updateQuery.prepare("SELECT MAX(xuhao) FROM micjishu");
if (updateQuery.exec() && updateQuery.next()) {
int maxXuhao = updateQuery.value(0).toInt();
for (int i = maxXuhao; i >= 1; --i) {
QSqlQuery updateXuhaoQuery(dbmic);
updateXuhaoQuery.prepare("UPDATE micjishu SET xuhao = :newXuhao WHERE xuhao = :oldXuhao");
updateXuhaoQuery.bindValue(":newXuhao", i + 1);
updateXuhaoQuery.bindValue(":oldXuhao", i);
if (!updateXuhaoQuery.exec()) {
qDebug() << "更新 xuhao 失败:" << updateXuhaoQuery.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
}
} else {
qDebug() << "获取最大 xuhao 失败:" << updateQuery.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
// 新增:插入多列数据
QSqlQuery query(dbmic);
query.prepare("INSERT INTO micjishu (xuhao, time, yuanshi, jieguo, xiangcheng,junshu,junzhong,weihao,shenghao,caozuo) VALUES ( :xuhao,:time, :yuanshi, :jieguo, :xiangcheng, :junshu, :junzhong, :weihao, :shenghao,:caozuo)");
query.bindValue(":xuhao", 1);
query.bindValue(":time", gettime());
query.bindValue(":yuanshi", savePath);
query.bindValue(":jieguo", savePath2);
query.bindValue(":xiangcheng", "真菌药敏试剂盒");
query.bindValue(":junshu", ui->comboBox->currentText());
query.bindValue(":junzhong", ui->comboBox_2->currentText());
query.bindValue(":weihao", ui->label_9->text());
query.bindValue(":shenghao", ui->label_10->text());
query.bindValue(":caozuo", savePath5);
if (!query.exec()) {
qDebug() << "插入多列数据失败:" << query.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
// 提交事务
if (dbmic.commit()) {
qDebug() << "数据插入并重新排序成功";
emit shuaxin();
} else {
qDebug() << "事务提交失败:" << dbmic.lastError().text();
}
QTableWidgetItem *filePathItem = new QTableWidgetItem();
filePathItem->setText(savePath2);
QTableWidgetItem *pixmapItem = new QTableWidgetItem();
if (pixmap2.isNull()) {
qDebug() << "图片加载失败,请检查文件路径和图片格式是否正确";
return;
}
// 对图片进行缩放保持长宽比使其适应指定大小这里设置为100x100
pixmap2 = pixmap2.scaled(170, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
pixmapItem->setIcon(QIcon(pixmap2));
ui->tableWidget_3->setIconSize(QSize(170,120));
// 插入新行
ui->tableWidget_3->insertRow(row);
// 将Pixmap对应的Item添加到第一列
ui->tableWidget_3->setItem(row, 0, pixmapItem);
// 将文件路径对应的Item添加到第二列
ui->tableWidget_3->setItem(row, 1, filePathItem);
ui->tableWidget_3->setRowHeight(row,130);
row++;
m_msgBox->close();
}
QtConcurrent::run(&micjishu::savezhao, this);
//第五个结束
}
else
{
qDebug() << "Returned tuple does not have 2 elements as expected";
}
}
else
{
qDebug() << "Function did not return a tuple as expected";
}
}//配1
// 释放资源,遵循引用计数规则
}
}
void micjishu::usepython2()
{
PyObject* pModule = PyImport_ImportModule("MIC_main");
if (!pModule)
{
PyErr_Print();
qDebug()<<"Cant open python file!\n";
QMessageBox::information(NULL, "提示", "图片识别有误,请重试");
m_msgBox->close();
return; // 提前返回避免继续执行
}
else{
qDebug()<<"file of python ac been opened";}
PyObject* pFunhello= PyObject_GetAttrString(pModule,"add_position");
if(!pFunhello){
PyErr_Print();
qDebug()<<"Get function hello failed";
QMessageBox::information(NULL, "提示", "图片识别有误,请重试");
m_msgBox->close();
return; // 提前返回避免继续执行
}
else
{
PyObject* args = PyTuple_New(9); // 创建一个包含2个元素的元组用于存放参数
// 设置第一个参数这里假设是整数类型设置为10可根据实际需求替换数值
// 设置第一个参数这里假设是整数类型设置为10可根据实际需求替换数值
PyObject* arg1 = PyUnicode_FromString("use/MIC/MIC/药敏板药物信息示例/药敏板药物信息示例.xlsx");
PyTuple_SetItem(args, 0, arg1);
PyObject* arg2 = PyUnicode_FromString("use/MIC/MIC/药敏板药物信息示例/药敏板药品判读规则表格.xlsx");
PyTuple_SetItem(args, 1, arg2);
PyObject* arg3 = PyUnicode_FromString("use/MIC/MIC/药敏板药物信息示例/MIC解释标准及ECV值.xlsx");
PyTuple_SetItem(args, 2, arg3);
PyObject* arg4 = PyUnicode_FromString("use/MIC/MIC/data/res/img_copy.png");
PyTuple_SetItem(args, 3, arg4);
PyObject* arg5 = PyUnicode_FromString("use/3.png");
PyTuple_SetItem(args, 4, arg5);
float a=x*5.498 ;
float b=y*5.2154;
int xx=a;
int yy=b;
qDebug()<<x;
qDebug()<<y;
qDebug()<<xx;
qDebug()<<yy;
PyObject* arg6 = PyLong_FromLong(xx);
PyTuple_SetItem(args, 5, arg6);
PyObject* arg7 = PyLong_FromLong(yy);
PyTuple_SetItem(args, 6, arg7);
QString shu= ui->comboBox->currentText();
QByteArray byteArray = shu.toUtf8();
PyObject* arg8 = PyUnicode_FromString(byteArray.constData());
PyTuple_SetItem(args, 7, arg8);
QString zhong= ui->comboBox_2->currentText();
QByteArray byteArray2 = zhong.toUtf8();
PyObject* arg9 = PyUnicode_FromString(byteArray2.constData());
PyTuple_SetItem(args, 8, arg9);
PyObject* result = PyObject_CallObject(pFunhello, args);
if (!result)
{ PyErr_Print();
qDebug() << "Call function failed";
QMessageBox::information(NULL, "提示", "图片识别有误,请重试");
m_msgBox->close();
return; // 提前返回避免继续执行
}
else
{
//配1
//这里是如果能接受返回值
if (PyTuple_Check(result))
{//配2
// 获取元组中的元素个数
Py_ssize_t tupleSize = PyTuple_Size(result);
if (tupleSize == 5)
{
// 获取第一个列表并处理
PyObject* list1 = PyTuple_GetItem(result, 0);
if (PyList_Check(list1))
{
Py_ssize_t list1Size = PyList_Size(list1);
if (list1Size == 10)
{
for (Py_ssize_t i = 0; i < list1Size; ++i) {
PyObject* element = PyList_GetItem(list1, i);
if (PyUnicode_Check(element)) {
const char* str = PyUnicode_AsUTF8(element);
chineseNames.append(QString::fromUtf8(str));
}
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item1 = new QTableWidgetItem(chineseNames.at(row));
ui->tableWidget->setItem(row, 1, item1);
}
}
else
{
qDebug() << "The first returned list does not have 3 elements as expected";
}
}
else
{
qDebug() << "The first element in the returned tuple is not a list as expected";
}
// 获取第二个列表并处理
PyObject* list2 = PyTuple_GetItem(result, 1);
if (PyList_Check(list2))
{
Py_ssize_t list2Size = PyList_Size(list2);
if (list2Size == 10)
{
for (Py_ssize_t i = 0; i < list2Size; ++i) {
PyObject* element = PyList_GetItem(list2, i);
if (PyUnicode_Check(element)) {
const char* str = PyUnicode_AsUTF8(element);
englishNames.append(QString::fromUtf8(str));
}
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item2 = new QTableWidgetItem(englishNames.at(row));
ui->tableWidget->setItem(row, 2, item2);
}
}
else
{
qDebug() << "The second returned list does not have 3 elements as expected";
}
}
else
{
qDebug() << "The second element in the returned tuple is not a list as expected";
}
// 获取第三个列表并处理
PyObject* list3 = PyTuple_GetItem(result, 2);
if (PyList_Check(list3))
{
Py_ssize_t list13Size = PyList_Size(list3);
if (list13Size == 10)
{
for (Py_ssize_t i = 0; i < list13Size; ++i) {
PyObject* element = PyList_GetItem(list3, i);
if (PyUnicode_Check(element)) {
const char* str = PyUnicode_AsUTF8(element);
if(shu=="曲霉属"&&(i==5||i==6||i==8)){
micValues.append(" ");
}else{
micValues.append(QString::fromUtf8(str));
}
}
}
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item3 = new QTableWidgetItem(micValues.at(row));
ui->tableWidget->setItem(row, 3, item3);
}
}
else
{
qDebug() << "The first returned list does not have 3 elements as expected";
}
}
else
{
qDebug() << "The first element in the returned tuple is not a list as expected";
}
// 获取第四个列表并处理
PyObject* list4 = PyTuple_GetItem(result, 3);
if (PyList_Check(list4))
{
Py_ssize_t list41Size = PyList_Size(list4);
if (list41Size == 10)
{
MICzhi();
for (Py_ssize_t i = 0; i < list41Size; ++i) {
PyObject* element = PyList_GetItem(list4, i);
if (!element || !PyUnicode_Check(element)) {
explanations.append("无效的Python对象");
continue;
}
const char* str = PyUnicode_AsUTF8(element);
if (!str) {
explanations.append("Python字符串转换失败");
continue;
}
// 检查 micValues 和 ECVList 是否越界
if (i >= micValues.size() || i >= ECVList.size()) {
explanations.append("数据不足");
continue;
}
qDebug()<<zhong;
if (zhong == "新型隐球菌VN"&&(i == 0 || i == 1 || i == 2 || i == 3 || i == 7|| i == 9)) {
bool ok1, ok2;
double micValue = micValues[i].toDouble(&ok1);
double ecvValue = ECVList[i].toDouble(&ok2);
if (!ok1 || !ok2) {
explanations.append("数值转换失败");
} else if (micValue <= ecvValue) {
explanations.append("野生型");
} else {
explanations.append("非野生型");
}
} else if (zhong == "新型隐球菌VN"&&(i == 5 || i == 6 || i == 8)) {
explanations.append("天然耐药");
}else if (zhong == "格特隐球菌VG"&&(i == 0 || i == 1 || i == 2 || i == 7|| i == 9)) {
qDebug()<<"格特隐球菌VN";
bool ok1, ok2;
double micValue = micValues[i].toDouble(&ok1);
double ecvValue = ECVList[i].toDouble(&ok2);
if (!ok1 || !ok2) {
explanations.append("数值转换失败");
} else if (micValue <= ecvValue) {
explanations.append("野生型");
} else {
explanations.append("非野生型");
}
} else if (zhong == "格特隐球菌VG"&&(i == 5 || i == 6 || i == 8) ){
explanations.append("天然耐药");
}else if (zhong == "格特隐球菌VGⅡ"&&(i == 0 || i == 1 || i == 2 || i == 7|| i == 9)) {
qDebug()<<"格特隐球菌VGⅡ";
bool ok1, ok2;
double micValue = micValues[i].toDouble(&ok1);
double ecvValue = ECVList[i].toDouble(&ok2);
if (!ok1 || !ok2) {
explanations.append("数值转换失败");
} else if (micValue <= ecvValue) {
explanations.append("野生型");
} else {
explanations.append("非野生型");
}
} else if (zhong == "格特隐球菌VGⅡ"&&(i == 5 || i == 6 || i == 8) ){
explanations.append("天然耐药");
}
else if(shu=="曲霉属"&&i==0){
explanations.append("天然耐药");
}else if(shu=="曲霉属"&&(i==5||i==6||i==8)){
explanations.append("");
//另外需要都ECV值
}else if (zhong == "克柔念珠菌" && i == 0) {
explanations.append("天然耐药");
}
else {
QString utf8Str = QString::fromUtf8(str);
if(utf8Str=="S"){
utf8Str="敏感";
}else if(utf8Str=="I"){
utf8Str="中介";
}else if(utf8Str=="SDD"){
utf8Str="剂量依赖性敏感";
}else if(utf8Str=="R"){
utf8Str="耐药";
}
explanations.append(utf8Str);
qDebug() << "Element at index" << i << ": " << utf8Str;
}
}
qDebug()<<"mic值"<<micValues;
qDebug()<<"ecv值"<<ECVList;
for (int row = 0; row < 10; ++row)
{
QTableWidgetItem *item4 = new QTableWidgetItem(explanations.at(row));
ui->tableWidget->setItem(row, 9, item4);
}
}
else
{
qDebug() << "The first returned list does not have 3 elements as expected";
}
}
else
{
qDebug() << "The first element in the returned tuple is not a list as expected";
}
// 获取第五个列表并处理
PyObject* MIC_position_list = PyTuple_GetItem(result, 4);
if (PyList_Check(MIC_position_list)) {
Py_ssize_t positionListSize = PyList_Size(MIC_position_list);
for (Py_ssize_t i = 0; i < positionListSize; ++i) {
PyObject* element = PyList_GetItem(MIC_position_list, i);
if (PyTuple_Check(element)) {
Py_ssize_t tupleElementSize = PyTuple_Size(element);
if (tupleElementSize == 2) {
PyObject* xObj = PyTuple_GetItem(element, 0);
PyObject* yObj = PyTuple_GetItem(element, 1);
if (PyLong_Check(xObj) && PyLong_Check(yObj)) {
long x = PyLong_AsLong(xObj);
long y = PyLong_AsLong(yObj);
//qDebug() << "MIC Position: (" << x << ", " << y << ")";
QString positionStr = QString("(%1, %2)").arg(x).arg(y);
positionStrList.append(positionStr);
}
}
}
}
}
}
}
ui->label_5->setHidden(true);
ui->label_6->setHidden(false);
QString aFile = QString("use/3.png");
ui->label_6->setPixmap(aFile);
ui->label_6->setScaledContents(true);
get();
QString folderName;
QString timeStamp = QDate::currentDate().toString("yyyy-MM-dd");
folderName = "use/micpandu/" + timeStamp;
QString timeStampFull = QTime::currentTime().toString("hh-mm-ss");
if(ui->label_15->text().isEmpty()){
savePath5 = folderName + "/" + timeStampFull + ".csv";
savePath44 = folderName + "/" + timeStampFull + "_C" + ".png";
savePath33 = folderName + "/" + timeStampFull + "_Y" + ".png";
QPixmap pixmap = ui->label_5->pixmap();
QPixmap pixmap2 = ui->label_6->pixmap();
// 开启事务,确保操作的原子性
dbmic.transaction();
// 第一步:更新现有行的 xuhao使其序号依次加 1
// 从最大的 xuhao 开始递减更新,避免 xuhao 冲突
QSqlQuery updateQuery(dbmic);
updateQuery.prepare("SELECT MAX(xuhao) FROM micjishu");
if (updateQuery.exec() && updateQuery.next()) {
int maxXuhao = updateQuery.value(0).toInt();
for (int i = maxXuhao; i >= 1; --i) {
QSqlQuery updateXuhaoQuery(dbmic);
updateXuhaoQuery.prepare("UPDATE micjishu SET xuhao = :newXuhao WHERE xuhao = :oldXuhao");
updateXuhaoQuery.bindValue(":newXuhao", i + 1);
updateXuhaoQuery.bindValue(":oldXuhao", i);
if (!updateXuhaoQuery.exec()) {
qDebug() << "更新 xuhao 失败:" << updateXuhaoQuery.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
}
} else {
qDebug() << "获取最大 xuhao 失败:" << updateQuery.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
// 新增:插入多列数据
QSqlQuery query(dbmic);
query.prepare("INSERT INTO micjishu (xuhao, time, yuanshi, jieguo, xiangcheng,junshu,junzhong,weihao,shenghao,caozuo) VALUES ( :xuhao,:time, :yuanshi, :jieguo, :xiangcheng, :junshu, :junzhong, :weihao, :shenghao,:caozuo)");
query.bindValue(":xuhao", 1);
query.bindValue(":time", gettime());
query.bindValue(":yuanshi", savePath33);
query.bindValue(":jieguo", savePath44);
query.bindValue(":xiangcheng", "真菌药敏试剂盒");
query.bindValue(":junshu", ui->comboBox->currentText());
query.bindValue(":junzhong", ui->comboBox_2->currentText());
query.bindValue(":weihao", ui->label_9->text());
query.bindValue(":shenghao", ui->label_10->text());
query.bindValue(":caozuo", savePath5);
if (!query.exec()) {
qDebug() << "插入多列数据失败:" << query.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
// 提交事务
if (dbmic.commit()) {
qDebug() << "数据插入并重新排序成功";
emit shuaxin();
} else {
qDebug() << "事务提交失败:" << dbmic.lastError().text();
}
QTableWidgetItem *filePathItem = new QTableWidgetItem();
filePathItem->setText(savePath44);
QTableWidgetItem *pixmapItem = new QTableWidgetItem();
if (pixmap2.isNull()) {
qDebug() << "图片加载失败,请检查文件路径和图片格式是否正确";
return;
}
// 对图片进行缩放保持长宽比使其适应指定大小这里设置为100x100
pixmap2 = pixmap2.scaled(170, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
pixmapItem->setIcon(QIcon(pixmap2));
ui->tableWidget_3->setIconSize(QSize(170,120));
// 插入新行
ui->tableWidget_3->insertRow(row);
// 将Pixmap对应的Item添加到第一列
ui->tableWidget_3->setItem(row, 0, pixmapItem);
// 将文件路径对应的Item添加到第二列
ui->tableWidget_3->setItem(row, 1, filePathItem);
ui->tableWidget_3->setRowHeight(row,130);
row++;
m_msgBox->close();
}
else{
QString zidingyi=ui->label_15->text();
savePath6 = folderName + "/" + zidingyi + ".csv";
savePath11 = folderName + "/" + zidingyi + "_Y" + ".png";
savePath22 = folderName + "/" + zidingyi + "_C" + ".png";
QPixmap pixmap = ui->label_5->pixmap();
QPixmap pixmap2 = ui->label_6->pixmap();
// 开启事务,确保操作的原子性
dbmic.transaction();
// 第一步:更新现有行的 xuhao使其序号依次加 1
// 从最大的 xuhao 开始递减更新,避免 xuhao 冲突
QSqlQuery updateQuery(dbmic);
updateQuery.prepare("SELECT MAX(xuhao) FROM micjishu");
if (updateQuery.exec() && updateQuery.next()) {
int maxXuhao = updateQuery.value(0).toInt();
for (int i = maxXuhao; i >= 1; --i) {
QSqlQuery updateXuhaoQuery(dbmic);
updateXuhaoQuery.prepare("UPDATE micjishu SET xuhao = :newXuhao WHERE xuhao = :oldXuhao");
updateXuhaoQuery.bindValue(":newXuhao", i + 1);
updateXuhaoQuery.bindValue(":oldXuhao", i);
if (!updateXuhaoQuery.exec()) {
qDebug() << "更新 xuhao 失败:" << updateXuhaoQuery.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
}
} else {
qDebug() << "获取最大 xuhao 失败:" << updateQuery.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
// 新增:插入多列数据
QSqlQuery query(dbmic);
query.prepare("INSERT INTO micjishu (xuhao, time, yuanshi, jieguo, xiangcheng,junshu,junzhong,weihao,shenghao,caozuo) VALUES ( :xuhao,:time, :yuanshi, :jieguo, :xiangcheng, :junshu, :junzhong, :weihao, :shenghao,:caozuo)");
query.bindValue(":xuhao", 1);
query.bindValue(":time", gettime());
query.bindValue(":yuanshi", savePath11);
query.bindValue(":jieguo", savePath22);
query.bindValue(":xiangcheng", "真菌药敏试剂盒");
query.bindValue(":junshu", ui->comboBox->currentText());
query.bindValue(":junzhong", ui->comboBox_2->currentText());
query.bindValue(":weihao", ui->label_9->text());
query.bindValue(":shenghao", ui->label_10->text());
query.bindValue(":caozuo", savePath6);
if (!query.exec()) {
qDebug() << "插入多列数据失败:" << query.lastError().text();
// 回滚事务
dbmic.rollback();
return;
}
// 提交事务
if (dbmic.commit()) {
qDebug() << "数据插入并重新排序成功";
emit shuaxin();
} else {
qDebug() << "事务提交失败:" << dbmic.lastError().text();
}
QTableWidgetItem *filePathItem = new QTableWidgetItem();
filePathItem->setText(savePath22);
QTableWidgetItem *pixmapItem = new QTableWidgetItem();
if (pixmap2.isNull()) {
qDebug() << "图片加载失败,请检查文件路径和图片格式是否正确";
return;
}
// 对图片进行缩放保持长宽比使其适应指定大小这里设置为100x100
pixmap2 = pixmap2.scaled(170, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
pixmapItem->setIcon(QIcon(pixmap2));
ui->tableWidget_3->setIconSize(QSize(170,120));
// 插入新行
ui->tableWidget_3->insertRow(row);
// 将Pixmap对应的Item添加到第一列
ui->tableWidget_3->setItem(row, 0, pixmapItem);
// 将文件路径对应的Item添加到第二列
ui->tableWidget_3->setItem(row, 1, filePathItem);
ui->tableWidget_3->setRowHeight(row,130);
row++;
m_msgBox->close();
}
fenge();
QPalette palette = ui->tableWidget->palette();
QColor color2= Qt::white;
QColor color1 = QColor(229,247,255);
for (int i = 0; i < ui->tableWidget->rowCount(); ++i) {
for (int col = 0; col < ui->tableWidget->columnCount(); ++col) {
QTableWidgetItem *item = ui->tableWidget->item(i, col);
if (!item) {
item = new QTableWidgetItem();
ui->tableWidget->setItem(i, col, item);
}
if (i % 2 == 0) {
item->setBackground(QBrush(color1));
} else {
item->setBackground(QBrush(color2));
}
}
}
for (int i = 0; i < ui->tableWidget->rowCount(); ++i) {
for (int col = 0; col < ui->tableWidget->columnCount(); ++col) {
QTableWidgetItem *item = ui->tableWidget_2->item(i, col);
if (!item) {
item = new QTableWidgetItem();
ui->tableWidget->setItem(i, col, item);
}
if (i % 2 == 0) {
item->setBackground(QBrush(color2));
} else {
item->setBackground(QBrush(color1));
}
}
}
for (int i = 0; i < ui->tableWidget->rowCount(); ++i) {
for (int j = 0; j < ui->tableWidget->columnCount(); ++j) {
QTableWidgetItem *item = ui->tableWidget->item(i, j);
if (item) {
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
}
}
for (int i = 0; i < ui->tableWidget_2->rowCount(); ++i) {
for (int j = 0; j < ui->tableWidget_2->columnCount(); ++j) {
QTableWidgetItem *item = ui->tableWidget_2->item(i, j);
if (item) {
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
}
}
QtConcurrent::run(&micjishu::savezhao2, this);
}
}
}
void micjishu::mouseDoubleClickEvent(QMouseEvent *event)
{
if (ui->label_6->geometry().contains(event->pos())) {
// 判断是否是左键点击
if (event->button() == Qt::LeftButton) {
QPoint posInLabel = event->pos() - ui->label_6->pos();
x = posInLabel.x();
y = posInLabel.y();
m_msgBox->show();
QTimer::singleShot(100,this,[=](){
chineseNames.clear();
englishNames.clear();
micValues.clear();
explanations.clear();
positionStrList.clear();
ECVList.clear();
SList.clear();
IList.clear();
SDDList.clear();
RList.clear();
usepython2();});
// 获取鼠标在全局屏幕上的坐标
QPoint globalPos = event->globalPos();
qDebug() << "在全局屏幕上的左键点击坐标: " << globalPos;
}
}
QWidget::mouseDoubleClickEvent(event);
}
void micjishu::getshui()
{
ui->comboBox->clear();
ui->comboBox_2->clear();
QString queryString = QString("SELECT name FROM junshu");
QSqlQuery mquery;
if (!mquery.exec(queryString)) {
}
while (mquery.next()) {
QVariant value = mquery.value(0);
ui->comboBox->addItem(value.toString());
}
}
void micjishu::on_comboBox_currentIndexChanged(const QString &arg1)
{
}
void micjishu::on_pushButton_4_clicked()
{
// m_michistoricalrecords->showFullScreen();
// m_michistoricalrecords->getshui();
QScrollBar *scrollBar = ui->tableWidget_3->verticalScrollBar();
// 获取当前滚动条的位置
int currentValue = scrollBar->value();
// 向下滑动的偏移量,可以根据需要调整
int offset = 100;
// 设置新的滚动条位置
scrollBar->setValue(currentValue - offset);
}
//拍照
void micjishu::on_pushButton_2_clicked()
{
if(ui->pushButton->text()=="已连接")
{
if(!ui->comboBox->currentText().isEmpty()){
m_zidingyi->exec();
m_zidingyi->focus();
timer->stop();
if(jixu==true){
ui->label_5->setHidden(false);
ui->label_5->clear();
ui->label_6->setHidden(true);
QTimer::singleShot(1,this,[=](){ m_cammer.zhuapai();});
QTimer::singleShot(500,this,[=](){
QPixmap p;
p.load(savelujing2);
// p.load("use/3_Y.png");
ui->label_5->setScaledContents(true);
ui->label_5->setPixmap(p);
QTimer::singleShot(100,this,[=](){
qDebug()<<"开始调用mic算法";
chineseNames.clear();
englishNames.clear();
micValues.clear();
explanations.clear();
positionStrList.clear();
ECVList.clear();
SList.clear();
IList.clear();
SDDList.clear();
RList.clear();
usepython();
});
});
}
}else{
QMessageBox::information(NULL, "提示", "请先选择菌属和菌种" );
}
}else{
QMessageBox::information(NULL, "提示", "请先连接相机" );
}
}
void micjishu::savezhao()
{
QString folderName;
QString timeStamp = QDate::currentDate().toString("yyyy-MM-dd");
folderName = "use/micpandu/" + timeStamp;
QDir dir(folderName);
if (!dir.exists()) {
if (!dir.mkpath(folderName)) {
qDebug() << "Failed to create directory: " << folderName;
return;
}
}
if (ui->label_15->text().isEmpty()) {
QString timeStampFull = QTime::currentTime().toString("hh-mm-ss");
QPixmap pixmap = ui->label_5->pixmap();
QPixmap pixmap2 = ui->label_6->pixmap();
if (pixmap.save(savePath3)) {
qDebug() << "Saved pixmap to: " << savePath3;
} else {
qDebug() << "Failed to save pixmap to: " << savePath3;
}
if (pixmap2.save(savePath4)) {
qDebug() << "Saved pixmap2 to: " << savePath4;
} else {
qDebug() << "Failed to save pixmap2 to: " << savePath4;
}
if (!savePath5.isEmpty()) {
exportTableWidgetToCsv(ui->tableWidget,savePath5);
};
ui->label_7->setText(savePath5);
} else {
QPixmap pixmap = ui->label_5->pixmap();
QPixmap pixmap2 = ui->label_6->pixmap();
if (pixmap.save(savePath)) {
qDebug() << "Saved pixmap to: " << savePath;
} else {
qDebug() << "Failed to save pixmap to: " << savePath;
}
if (pixmap2.save(savePath2)) {
qDebug() << "Saved pixmap2 to: " << savePath2;
} else {
qDebug() << "Failed to save pixmap2 to: " << savePath2;
}
if (!savePath6.isEmpty()) {
exportTableWidgetToCsv(ui->tableWidget,savePath6);
};
ui->label_7->setText(savePath6);
}
}
//重新拍照
void micjishu::on_pushButton_5_clicked()
{
}
void micjishu::on_comboBox_currentTextChanged(const QString &arg1)
{
ui->comboBox_2->clear();
QString sql=QString("select name from junzhong where shuname='%1'").arg(arg1);
qDebug()<<sql;
QSqlQuery mquery;
if (!mquery.exec(sql)) {
}
while (mquery.next()) {
QVariant value = mquery.value(0);
ui->comboBox_2->addItem(value.toString());
}
}
QString micjishu::getname()
{
QString sql=QString("select usersname from users where id='%1'").arg(id6);
qDebug()<<sql;
QSqlQuery query;
if(query.exec(sql))
{
if(query.first()){
QString str1=query.value(0).toString();
qDebug()<<str1;
return str1;
}
}
else
{
qDebug()<<"没查到名字";
}
}
QString micjishu::gettime()
{
QDateTime dateTime= QDateTime::currentDateTime();//获取系统当前的时间
QString str = dateTime .toString("yyyy-MM-dd hh:mm:ss");//格式化时间
return str;
}
//保存
void micjishu::savezhao2()
{
QString folderName;
QString timeStamp = QDate::currentDate().toString("yyyy-MM-dd");
folderName = "use/micpandu/" + timeStamp;
QDir dir(folderName);
if (!dir.exists()) {
if (!dir.mkpath(folderName)) {
qDebug() << "Failed to create directory: " << folderName;
return;
}
}
if (ui->label_15->text().isEmpty()) {
QString timeStampFull = QTime::currentTime().toString("hh-mm-ss");
QPixmap pixmap = ui->label_5->pixmap();
QPixmap pixmap2 = ui->label_6->pixmap();
if (pixmap.save(savePath33)) {
qDebug() << "Saved pixmap to: " << savePath33;
} else {
qDebug() << "Failed to save pixmap to: " << savePath33;
QMessageBox::information(NULL, "提示", "原图保存失败");
}
if (pixmap2.save(savePath44)) {
qDebug() << "Saved pixmap2 to: " << savePath44;
} else {
qDebug() << "Failed to save pixmap2 to: " << savePath44;
QMessageBox::information(NULL, "提示", "结果图保存失败");
}
if (!savePath5.isEmpty()) {
exportTableWidgetToCsv(ui->tableWidget,savePath5);
};
ui->label_7->setText(savePath5);
} else {
QPixmap pixmap = ui->label_5->pixmap();
QPixmap pixmap2 = ui->label_6->pixmap();
if (pixmap.save(savePath11)) {
qDebug() << "Saved pixmap to: " << savePath11;
} else {
qDebug() << "Failed to save pixmap to: " << savePath11;
QMessageBox::information(NULL, "提示", "原图保存失败");
}
if (pixmap2.save(savePath22)) {
qDebug() << "Saved pixmap2 to: " << savePath22;
} else {
QMessageBox::information(NULL, "提示", "结果图保存失败");
qDebug() << "Failed to save pixmap2 to: " << savePath22;
}
if (!savePath6.isEmpty()) {
exportTableWidgetToCsv(ui->tableWidget,savePath6);
};
ui->label_7->setText(savePath6);
}
}
void micjishu::on_pushButton_3_clicked()
{
}
//连接相机
void micjishu::on_pushButton_clicked()
{
ui->widget->setmic();
QTimer::singleShot(100,this,[=](){
if (!ui->widget->CameraOpen())
{
qDebug()<<"shibai";
QMessageBox::information(NULL, "提示", "连接相机失败" );
}
else{qDebug()<<"chenggog";
ui->widget->CameraStart();
ui->widget->resetStatistic();
/* ui->widget->SetExpose()*/;
// m_staticTimer.start(100);
//ui->pushButton_2->setEnabled(true);
ui->pushButton->setText("已连接");
}
SerialPort.setPortName("COM3");
// 打开串口
if(SerialPort.open(QIODevice::ReadWrite))
{
SerialPort.setBaudRate(QSerialPort::Baud9600);
SerialPort.setDataBits(QSerialPort::Data8);
SerialPort.setStopBits(QSerialPort::OneStop);
SerialPort.setParity(QSerialPort::NoParity);
SerialPort.setFlowControl(QSerialPort::NoFlowControl);
qDebug()<<"成功打开串口COM3";
QTimer::singleShot(10,this,[=](){
SerialPort.write("$1101E60");});
QTimer::singleShot(10,this,[=](){
SerialPort.write("$2204C63");});
}
else {
qDebug() << "打开 COM3 失败,原因: " << SerialPort.errorString();
}
});
}
void micjishu::on_radioButton_clicked()
{
}
void micjishu::getkai()
{
qDebug()<<"getkaimic";
ui->pushButton_2->setHidden(false);
// ui->pushButton_2->setEnabled(false);
ui->pushButton_5->setHidden(true);
ui->pushButton->setText("连接相机");
ui->pushButton->setEnabled(true);
ui->label_5->clear();
ui->label_6->clear();
// ui->tableWidget_3->clear();
ui->tableWidget_2->clear();
ui->tableWidget->clear();
// ui->widget->setHidden(true);
//ui->label_5->setHidden(false);
ui->lineEdit->clear();
ui->label_4->setText("条码信息:");
QStringList headers;
headers << "序号"<<"抗菌药物(中文名)" << "抗菌药物(英文名)" << "MIC值(μg/ml)" <<"ECV"<<"S"<<"I"<<"SDD"<<"R"<<"结果";
ui->tableWidget->setHorizontalHeaderLabels(headers);
ui->tableWidget_2->setHorizontalHeaderLabels(headers);
QPalette palette = ui->tableWidget->palette();
QColor color2 = Qt::white;
QColor color1 = QColor(229,247,255);
for (int i = 0; i < ui->tableWidget->rowCount(); ++i) {
for (int col = 0; col < ui->tableWidget->columnCount(); ++col) {
QTableWidgetItem *item = ui->tableWidget->item(i, col);
if (!item) {
item = new QTableWidgetItem();
ui->tableWidget->setItem(i, col, item);
}
if (i % 2 == 0) {
item->setBackground(QBrush(color1));
} else {
item->setBackground(QBrush(color2));
}
}
}
for (int i = 0; i < ui->tableWidget_2->rowCount(); ++i) {
for (int col = 0; col < ui->tableWidget_2->columnCount(); ++col) {
QTableWidgetItem *item = ui->tableWidget_2->item(i, col);
if (!item) {
item = new QTableWidgetItem();
ui->tableWidget_2->setItem(i, col, item);
}
if (i % 2 == 0) {
item->setBackground(QBrush(color2));
} else {
item->setBackground(QBrush(color1));
}
}
}
}
void micjishu::getguan()
{
if( ui->widget->CameraStop()){
qDebug()<<"MICget关1";
}
if(ui->widget->CameraClose())
{
qDebug()<<"MICget关2";
}
SerialPort.write("$2101E63");
QTimer::singleShot(100,this,[=](){
SerialPort.write("$2204C63");
}
);
QTimer::singleShot(500,this,[=](){
SerialPort.close();
SerialPort4.close();
timer->stop();
}
);
}
void micjishu::on_checkBox_clicked()
{ /* if(ui->checkBox->isChecked()){SerialPort.write("$210381C");}
else{SerialPort.write("$220381F");}*/
if(ui->checkBox->isChecked()){
SerialPort.write("$110381F");
}
else {
SerialPort.write("$210381C");
}
}
void micjishu::on_checkBox_2_clicked()
{
if(ui->checkBox_2->isChecked()){SerialPort.write("$1200A66");}
else{SerialPort.write("$2201E60");}
}
//查看
void micjishu::on_pushButton_6_clicked()
{
get();
QTimer::singleShot(100,this,[=](){ QSqlQuery query;
QString targetId = ui->label_8->text();
QString str=QString("SELECT tu FROM yaominban WHERE id = '%1'").arg(targetId);
qDebug()<<str;
query.prepare(str);
query.exec(str);
if (query.next()) {
QByteArray tuData = query.value(0).toByteArray();
// qDebug()<<tuData;
QPixmap pixmap;
if (pixmap.loadFromData(tuData)) {
//ui->label_6->setPixmap(pixmap);
emit yuan(pixmap);
m_maxtu->setWindowModality(Qt::ApplicationModal);
m_maxtu->show();
// ui->label->show();
} else {
qDebug() << "无法从数据加载图片";
}
} else {
qDebug() << "未找到对应id的记录";
}});
// emit yuan(aFile);
// m_maxtu->setWindowModality(Qt::ApplicationModal);
// m_maxtu->show();
}
QString micjishu::getLabelSubstring(QLabel *label, int start, int end)
{
QString text = label->text(); // 获取QLabel中的文本
return text.mid(start, end - start + 1); // 返回从start到end的子字符串
}
void micjishu::get()
{
QString fullText = ui->lineEdit->text();
QStringList parts = fullText.split(" "); // 按空格分割文本为字符串列表
if (parts.size() >= 5) {
// 将分割后的五个部分依次设置到对应的QLabel上
ui->label_8->setText(parts[0]);
//xiangcheng=ui->label_8->text();
ui->label_9->setText(parts[1]);
// 这里假设还有ui->label_10、ui->label_11、ui->label_12等用来显示其他部分
ui->label_10->setText(parts[2]);
// shenghao=ui->label_10->text();
ui->label_11->setText(parts[3]);
ui->label_12->setText(parts[4]);
}
}
void micjishu::on_pushButton_7_clicked()
{
}
#include <QTableWidget>
#include <QFile>
#include <QTextStream>
#include <QDebug>
// 函数用于将QTableWidget的数据导出为CSV格式的文本文件
void micjishu::exportTableWidgetToCsv(QTableWidget* tableWidget, const QString& filePath)
{
QFile file(filePath);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out.setEncoding(QStringConverter::Utf8);
// 写入UTF-8 BOM头如果需要确保文件以UTF-8编码被正确识别可根据实际情况选择是否添加
out << "\xEF\xBB\xBF";
// 获取表头数据并写入文件
QStringList headers;
int columnCount = tableWidget->columnCount();
for (int col = 0; col < columnCount; ++col) {
QTableWidgetItem* headerItem = tableWidget->horizontalHeaderItem(col);
if (headerItem) {
headers.append(headerItem->text());
}
}
for (int col = 0; col < headers.size(); ++col) {
out << headers[col];
if (col < headers.size() - 1) {
out << ",";
}
}
out << "\n";
int rowCount = tableWidget->rowCount();
for (int row = 0; row < rowCount; ++row) {
for (int column = 0; column < columnCount; ++column) {
QTableWidgetItem* item = tableWidget->item(row, column);
if (item) {
out << item->text();
}
if (column < columnCount - 1) {
out << ",";
}
}
out << "\n";
}
file.close();
qDebug() << "TableWidget data exported to CSV file successfully.";
} else {
qDebug() << "Error opening file for writing: " << file.errorString();
}
}
void micjishu::loadCsvToTableWidget(const QString& filePath, QTableWidget* tableWidget)
{
QFile file(filePath);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file);
QString line = in.readLine();
QStringList headers = line.split(",");
tableWidget->setColumnCount(headers.size());
tableWidget->setHorizontalHeaderLabels(headers);
int row = 0;
while (!in.atEnd()) {
line = in.readLine();
QStringList fields = line.split(",");
tableWidget->insertRow(row);
for (int col = 0; col < fields.size(); ++col) {
QTableWidgetItem* item = new QTableWidgetItem(fields[col]);
tableWidget->setItem(row, col, item);
}
row++;
}
file.close();
} else {
// 文件打开失败的处理
qDebug() << "Error opening file: "<< file.errorString();
}
}
void micjishu::fenge()
{
int rows = ui->tableWidget->rowCount();
int cols = ui->tableWidget->columnCount();
for (int row = 0; row < rows; ++row) {
for (int col = 0; col < cols; ++col) {
// 获取源表格中的单元格
QTableWidgetItem* sourceItem = ui->tableWidget->item(row, col);
if (sourceItem) {
// 获取单元格的数据
QVariant data = sourceItem->data(Qt::DisplayRole);
// 创建新的表格单元格用于目标表格
QTableWidgetItem* targetItem = new QTableWidgetItem(data.toString());
// 复制文本对齐方式
targetItem->setTextAlignment(sourceItem->textAlignment());
// 复制背景颜色(如果有设置)
QBrush brush = sourceItem->background();
targetItem->setBackground(brush);
// 在目标表格中设置新的单元格
ui->tableWidget_2->setItem(row, col, targetItem);
}
}
}
}
void micjishu::on_lineEdit_editingFinished()
{/*
ui->lineEdit->clear();
*/
}
void micjishu::on_pushButton_8_clicked()
{
get();
QTimer::singleShot(100,this,[=](){ QSqlQuery query;
QString targetId = ui->label_8->text();
QString str=QString("SELECT name FROM yaominban WHERE id = '%1'").arg(targetId);
qDebug()<<str;
query.prepare(str);
query.exec(str);
if (query.next()) {
QString name=query.value(0).toString();
name=name.simplified();
qDebug()<<name;
ui->lineEdit->setText(name);
ui->label_4->setText("项目名称:");
}
});
}
void micjishu::on_pushButton_9_clicked()
{
// 获取应用程序目录的父目录
QString appDir = QCoreApplication::applicationDirPath();
QDir dir(appDir);
// if (dir.cdUp()) { // 尝试返回上一级目录
// appDir = dir.absolutePath();
// } else {
// qDebug() << "无法返回上一级目录,使用原始目录";
// }
// 构建完整路径
QString initialDir = QDir::toNativeSeparators(appDir + "/use/micpandu");
qDebug() << initialDir;
// 检查目录是否存在
QDir targetDir(initialDir);
if (!targetDir.exists()) {
qDebug() << "目录不存在,使用文档目录作为替代";
initialDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
}
// 创建文件对话框对象
QFileDialog fileDialog;
// 设置文件对话框的标题
fileDialog.setWindowTitle("打开文件");
// 设置文件对话框的文件模式为只允许选择文件
fileDialog.setFileMode(QFileDialog::ExistingFile);
// 设置文件对话框的初始目录
fileDialog.setDirectory(initialDir);
if (fileDialog.exec() == QDialog::Accepted) {
QStringList fileNames = fileDialog.selectedFiles();
// 输出用户选择的文件路径
qDebug() << "选择的文件路径: " << fileNames.at(0);
ui->label_6->setHidden(true);
ui->label_5->setHidden(false);
ui->label_5->setPixmap(fileNames.at(0));
ui->label_5->setScaledContents(true);
int result = QMessageBox::information(NULL, "提示", "是否要将此照片进行重新判读", QMessageBox::Ok | QMessageBox::Cancel);
if (result == QMessageBox::Ok) {
if(!ui->comboBox->currentText().isEmpty()){
m_zidingyi->exec();
timer->stop();
QTimer::singleShot(100,this,[=](){
qDebug()<<"开始调用mic算法";
chineseNames.clear();
englishNames.clear();
micValues.clear();
explanations.clear();
positionStrList.clear();
savelujing2=fileNames.at(0);
usepython();
});
}else{
QMessageBox::information(NULL, "提示", "请先选择菌属和菌种" );
}
}
} else {
// 用户取消了文件选择
qDebug() << "用户取消了文件选择";
}
}
void micjishu::on_radioButton_2_clicked()
{
// ui->stackedWidget->setCurrentIndex(1);
// m_michistoricalrecords->showFullScreen();
// m_michistoricalrecords->getshui();
}
//点击扫码
void micjishu::on_pushButton_10_clicked()
{
// foreach (const QSerialPortInfo &info,QSerialPortInfo::availablePorts())
// {
// QSerialPort serial;
// serial.setPort(info);
// if(serial.open(QIODevice::ReadWrite))
// {
// SerialPort.setPortName("COM4");
// qDebug()<<info.portName();
// }
// }
SerialPort4.setPortName("COM4");
// 打开串口
if(SerialPort4.open(QIODevice::ReadWrite))
{
SerialPort4.setBaudRate(QSerialPort::Baud9600);
SerialPort4.setDataBits(QSerialPort::Data8);
SerialPort4.setStopBits(QSerialPort::OneStop);
SerialPort4.setParity(QSerialPort::NoParity);
SerialPort4.setFlowControl(QSerialPort::NoFlowControl);
qDebug()<<"成功打开COM4";
QTimer::singleShot(100,this,[=](){
QByteArray hexData = QByteArray::fromHex("16 54 0D");
SerialPort4.write(hexData);
// QTimer::singleShot(100,this,[=](){
// QByteArray receivedHexData = SerialPort.readAll();
// ui->lineEdit->setText(receivedHexData);
// qDebug()<<receivedHexData;});
// SerialPort.write("16 54 0D");
// QTimer::singleShot(100,this,[=](){
// QString str=SerialPort.readAll();
// ui->lineEdit->setText(str);
// qDebug()<<str;});
// });
// 将定时器的 timeout 信号连接到自定义的槽函数 timeoutHandler
connect(timer, &QTimer::timeout, this, [=](){
QByteArray receivedHexData = SerialPort4.readAll();
qDebug()<<receivedHexData;
if(receivedHexData!="")
{
ui->lineEdit->setText(receivedHexData);
timer->stop();
receivedHexData="";
}
});
// 启动定时器,设置超时时间为 1000 毫秒(即 1 秒)
timer->start(1000);
});
}
else {
qDebug() << "打开 COM4 失败,原因: " << SerialPort4.errorString();
}
}
void micjishu::on_pushButton_11_clicked()
{
QScrollBar *scrollBar = ui->tableWidget_3->verticalScrollBar();
// 获取当前滚动条的位置
int currentValue = scrollBar->value();
// 向下滑动的偏移量,可以根据需要调整
int offset = 100;
// 设置新的滚动条位置
scrollBar->setValue(currentValue + offset);
}
void micjishu::on_pushButton_12_clicked()
{
m_pp->show();
if(ui->label_15->text().isEmpty()){
emit print(savePath5);
}else{
emit print(savePath6);
}
}