2036 lines
60 KiB
C++
2036 lines
60 KiB
C++
#include "resultview.h"
|
|
#include "imagereslistview.h"
|
|
#include "waitwidget.h"
|
|
|
|
#include <QThread>
|
|
#include <QHBoxLayout>
|
|
#include <QVBoxLayout>
|
|
#include <QGridLayout>
|
|
#include <QDebug>
|
|
#include <QHeaderView>
|
|
#include <QLatin1Char> //格式化字符串
|
|
#include <QFile>
|
|
#include <QPainter>
|
|
#include <QPalette>
|
|
#include <QtConcurrent> //异步线程
|
|
#include <QFuture>
|
|
#include <QFutureWatcher>
|
|
#include <QTextCodec>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
#include "toolkit.h"
|
|
#include "ExtendedGroupBox.h"
|
|
#include "myGroupWidget.h"
|
|
|
|
|
|
/**
|
|
qCopyDirectory -- 拷贝目录
|
|
fromDir : 源目录 传进来的是绝对路径,absolutePath
|
|
toDir : 目标目录
|
|
bCoverIfFileExists : ture:同名时覆盖 false:同名时跳过
|
|
返回: ture拷贝成功 false:拷贝未完成
|
|
例如:
|
|
QDir fromDir("D:\Wiz");
|
|
QDir toDir("D:\qwe4");
|
|
*/
|
|
bool qCopyDirectory(const QString& fromDir, const QString& toDir, bool bCoverIfFileExists)
|
|
{
|
|
QDir formDir_;
|
|
formDir_.setPath(fromDir);
|
|
QDir toDir_;
|
|
toDir_.setPath(toDir);
|
|
if (!toDir_.exists())
|
|
{
|
|
if (!toDir_.mkdir(toDir_.absolutePath()))
|
|
return false;
|
|
}
|
|
|
|
QFileInfoList fileInfoList = formDir_.entryInfoList();
|
|
foreach(QFileInfo fileInfo, fileInfoList)
|
|
{
|
|
if (fileInfo.fileName() == "." || fileInfo.fileName() == "..")
|
|
continue;
|
|
|
|
//拷贝子目录
|
|
if (fileInfo.isDir())
|
|
{
|
|
//递归调用拷贝
|
|
if (!qCopyDirectory(fileInfo.filePath(), toDir_.filePath(fileInfo.fileName()), true))
|
|
return false;
|
|
}
|
|
//拷贝子文件
|
|
else
|
|
{
|
|
if (bCoverIfFileExists && toDir_.exists(fileInfo.fileName()))
|
|
{
|
|
toDir_.remove(fileInfo.fileName());
|
|
}
|
|
if (!QFile::copy(fileInfo.filePath(), toDir_.filePath(fileInfo.fileName())))
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
ResultView::ResultView(QWidget* parent)
|
|
{
|
|
setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::MSWindowsFixedSizeDialogHint
|
|
| Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
|
|
|
|
}
|
|
|
|
ResultView::~ResultView()
|
|
{
|
|
|
|
if (m_search)
|
|
{
|
|
delete m_search;
|
|
m_search = nullptr;
|
|
}
|
|
if (m_resultlist)
|
|
{
|
|
delete m_resultlist;
|
|
m_resultlist = nullptr;
|
|
}
|
|
if (m_timelist)
|
|
{
|
|
delete m_timelist;
|
|
m_timelist = nullptr;
|
|
}
|
|
if (m_waitwidget) {
|
|
delete m_waitwidget;
|
|
m_waitwidget = nullptr;
|
|
}
|
|
}
|
|
|
|
void ResultView::initwidget()
|
|
{
|
|
QString m_style = "QWidget{background-color: rgb(70, 70, 70);}";
|
|
|
|
// 控件初始化
|
|
|
|
|
|
m_search = new SearchLineEdit(this);
|
|
m_resultlist = new ImageResListView(this);
|
|
m_timelist = new RightWindow(this);
|
|
m_waitwidget = new WaitProgressWidget(this);
|
|
|
|
m_search->my_SetFont(m_Font);
|
|
m_resultlist->my_SetFont(m_Font);
|
|
|
|
m_search->setPath(currPath);
|
|
m_resultlist->setPath(currPath);
|
|
m_timelist->m_statist->setPath(currPath);
|
|
|
|
QVBoxLayout* mainWidgetLayout = new QVBoxLayout(this);
|
|
QWidget* mainWidget = new QWidget;
|
|
mainWidget->setMouseTracking(true);
|
|
mainWidgetLayout->addWidget(mainWidget);
|
|
mainWidgetLayout->setMargin(0);
|
|
|
|
|
|
QHBoxLayout* phLayout = new QHBoxLayout();
|
|
|
|
phLayout->addWidget(m_search);
|
|
phLayout->addWidget(m_resultlist);
|
|
phLayout->addWidget(m_timelist);
|
|
|
|
phLayout->setStretchFactor(m_search, 3);
|
|
phLayout->setStretchFactor(m_resultlist, 8);
|
|
phLayout->setStretchFactor(m_timelist, 3);
|
|
phLayout->setContentsMargins(5, 5, 5, 5);
|
|
|
|
mainWidget->setLayout(phLayout);
|
|
|
|
// 设置背景属性
|
|
|
|
mainWidget->setStyleSheet(m_style);
|
|
|
|
// 信号关联
|
|
connect(m_search, &SearchLineEdit::waitSearch, [this](bool isok) {
|
|
isok ? waitstart() : waitstop();
|
|
});
|
|
connect(m_resultlist, &ImageResListView::waitSearch, [this](bool isok) {
|
|
isok ? waitstart() : waitstop();
|
|
});
|
|
connect(m_timelist->m_statist, &TimeList::waitSearch, [this](bool isok) {
|
|
isok ? waitstart() : waitstop();
|
|
});
|
|
|
|
// 点击时间段,刷新产品SN
|
|
connect(m_timelist->m_statist, &TimeList::searchTimeList, [this](QString datatime, int tlabel) {
|
|
if (m_search->getSearch()) {
|
|
m_search->stopSearch();
|
|
while (!m_search->getSearch())
|
|
{
|
|
QThread::msleep(10);
|
|
}
|
|
forRefreshDatatime= datatime;
|
|
forRefreshTlabel = tlabel;
|
|
m_search->GetDataTimeList(datatime, tlabel);
|
|
}
|
|
else {
|
|
forRefreshDatatime = datatime;
|
|
forRefreshTlabel = tlabel;
|
|
m_search->GetDataTimeList(datatime, tlabel);
|
|
}
|
|
m_resultlist->clearAll();
|
|
});
|
|
|
|
// 时间修改,清空SN列表
|
|
connect(m_timelist->m_statist, &TimeList::changeData, m_search, &SearchLineEdit::clearList);
|
|
connect(m_timelist->m_statist, &TimeList::changeData, m_resultlist, &ImageResListView::clearAll);
|
|
|
|
// 点击SN,刷新产品结果图片列表
|
|
connect(m_search, &SearchLineEdit::checkResult, m_resultlist, &ImageResListView::getCodeSN);
|
|
|
|
// 刷新图片保存根目录
|
|
connect(this, &ResultView::LoadSavepath, [this](QString path) {
|
|
|
|
// 读取配置文件 设置路径
|
|
// 读取产品结果
|
|
{
|
|
QString csvpath = path;
|
|
// 读取每日csv
|
|
QStringList lines; //配置信息列表
|
|
QFile configFile;
|
|
configFile.setFileName(csvpath);
|
|
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QTextStream stream_text(&configFile);
|
|
// //可读取中文
|
|
stream_text.seek(0);
|
|
while (!stream_text.atEnd())
|
|
{
|
|
lines.push_back(gb2312ToUtf8(stream_text.readLine()));
|
|
}
|
|
|
|
}
|
|
else {
|
|
qDebug() << "read csv " << csvpath << " failed!" << endl;
|
|
}
|
|
configFile.close();
|
|
if (lines.count() == 0)return ;
|
|
QStringList sas;
|
|
for each (auto lis in lines) {
|
|
if (lis.indexOf("DET_PATH") != -1)sas.append(lis.split(",").at(2));
|
|
else if (lis.indexOf("ORI_PATH") != -1)sas.append(lis.split(",").at(2));
|
|
else {};
|
|
}
|
|
if (sas.count() %2==0) {
|
|
m_search->setSavePath(sas);
|
|
m_resultlist->setSavePath(sas);
|
|
}
|
|
else
|
|
{
|
|
qDebug() << "配置文件格式不正确!%2!=0";
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
//生成结果汇总
|
|
connect(this, &ResultView::getResultRepot, m_search, &SearchLineEdit::GetResultRepot);
|
|
timer.start(5000);
|
|
QDateTime currentDateTime;
|
|
QObject::connect(&timer, &QTimer::timeout, [this]() {
|
|
if (forRefreshDatatime.compare("") == false)
|
|
return;
|
|
if (m_search->getSearch()) {
|
|
m_search->stopSearch();
|
|
while (!m_search->getSearch())
|
|
{
|
|
QThread::msleep(10);
|
|
}
|
|
m_search->RefreshDataTimeList(forRefreshDatatime, forRefreshTlabel);
|
|
}
|
|
else {
|
|
|
|
m_search->RefreshDataTimeList(forRefreshDatatime, forRefreshTlabel);
|
|
}
|
|
//m_resultlist->clearAll();
|
|
});
|
|
}
|
|
|
|
void ResultView::Load_Param_Config(const QString path)
|
|
{
|
|
if (path.isEmpty())return;
|
|
emit m_timelist->Loadparam(path);
|
|
}
|
|
|
|
void ResultView::Save_Param_Config(const QString path)
|
|
{
|
|
if (path.isEmpty())return;
|
|
emit m_timelist->Saveparam(path);
|
|
}
|
|
|
|
void ResultView::mouseMoveEvent(QMouseEvent* event)
|
|
{
|
|
setCursor(Qt::ArrowCursor);
|
|
emit mouseRecover();
|
|
}
|
|
|
|
|
|
void ResultView::waitstart(int msec)
|
|
{
|
|
if (m_waitwidget) {
|
|
m_waitwidget->start(msec);
|
|
}
|
|
}
|
|
|
|
void ResultView::waitstop()
|
|
{
|
|
if (m_waitwidget) {
|
|
m_waitwidget->stop(true);
|
|
}
|
|
}
|
|
|
|
SearchLineEdit::SearchLineEdit(QWidget* parent)
|
|
{
|
|
setMouseTracking(true);
|
|
// SavePath.append(QString::fromUtf8("\\192.168.1.120\\111"));//结果地址 工控机1
|
|
// SavePath.append(QString::fromUtf8("C:/111"));
|
|
// SavePath.append(QString::fromUtf8("D:/111"));
|
|
|
|
// SavePath.append(QString::fromUtf8("\\192.168.1.120\\Ori"));//原图地址 工控机1
|
|
// SavePath.append(QString::fromUtf8("\\192.168.1.130\\Ori"));
|
|
// SavePath.append(QString::fromUtf8("D:/Ori"));
|
|
SavePath.append(QString::fromUtf8("D:\\CCD\\111"));//结果地址 工控机1
|
|
SavePath.append(QString::fromUtf8("D:\\CCD\\yuantu"));//原图地址 工控机1
|
|
{
|
|
QString Station1 = "\\Station1";
|
|
QString Station2 = "\\Station2";
|
|
QString Station3 = "\\Station3";
|
|
QString Station4 = "\\Station4";
|
|
QString Station5 = "\\Station5";
|
|
stationLists << Station1 << Station2 << Station3 << Station4 << Station5;
|
|
}
|
|
|
|
|
|
|
|
this->setAttribute(Qt::WA_StyledBackground);
|
|
}
|
|
|
|
SearchLineEdit::~SearchLineEdit()
|
|
{
|
|
|
|
if (m_Line_SN_TIME_RESULT)
|
|
{
|
|
delete m_Line_SN_TIME_RESULT;
|
|
m_Line_SN_TIME_RESULT = nullptr;
|
|
}
|
|
if (m_SearchButton)
|
|
{
|
|
delete m_SearchButton;
|
|
m_SearchButton = nullptr;
|
|
}
|
|
if (m_pActionCopy)
|
|
{
|
|
delete m_pActionCopy;
|
|
m_pActionCopy = nullptr;
|
|
}
|
|
if (m_pActionEsc)
|
|
{
|
|
delete m_pActionEsc;
|
|
m_pActionEsc = nullptr;
|
|
}
|
|
if (m_pContextMenu)
|
|
{
|
|
delete m_pContextMenu;
|
|
m_pContextMenu = nullptr;
|
|
}
|
|
|
|
if (m_result_List)
|
|
{
|
|
delete m_result_List;
|
|
m_result_List = nullptr;
|
|
}
|
|
}
|
|
|
|
void SearchLineEdit::initwidget()
|
|
{
|
|
|
|
QPalette palette;
|
|
palette.setColor(QPalette::WindowText, Qt::red);
|
|
QString QToolbutton_style_sheet = "QToolButton{font-size: 20px;color:rgb(147,147,147);background-color: rgb(80, 80, 80);border:0px}"
|
|
"QToolButton:hover{color:rgb(147,147,147);background-color: rgb(53, 53, 53);border:0px}";
|
|
|
|
QString tabel_sheet = QString(
|
|
"QTableWidget{ color:black; \
|
|
background-color:rgb(85,85,85);\
|
|
selection-color:rgb(255, 255, 255); \
|
|
selection-background-color:rgb(100,149,237);\
|
|
border:0px;\
|
|
font: 8pt 'Microsoft YaHei' ;}"
|
|
"QHeaderView::section:horizontal{ /*设置标题(水平的)*/\
|
|
border: 1px solid rgb(178, 178, 178); /*白色间隔*/\
|
|
border - bottom: 0px;/*下边框不需要颜色*/\
|
|
color: rgb(244, 244, 244);\
|
|
background: transparent;\
|
|
padding - left: 2px;\
|
|
min - width:60px;}");
|
|
// 初始化控件
|
|
m_Font.setFamily("Microsoft YaHei");
|
|
m_Font.setPixelSize(18);
|
|
m_text = new QLabel(this);
|
|
seach_init = QString::fromUtf8("搜索说明:请先在右侧选中日历和对应的小时段或全天,再输入SN/时间/结果,点击按钮或回车均可搜索.搜索不到可能原因:未扫到码或未启动软件.");
|
|
seach_end = QString::fromUtf8("检索完成! ");
|
|
seach_start = QString::fromUtf8("正在检索.....请勿搜索SN ");
|
|
m_text->setText(seach_init);
|
|
m_text->setFont(m_Font);
|
|
m_text->setTextInteractionFlags(Qt::NoTextInteraction);
|
|
m_text->setWordWrap(true);//自动换行
|
|
m_text->setPalette(palette);
|
|
|
|
|
|
m_Line_SN_TIME_RESULT = new QLineEdit(this);
|
|
m_Line_SN_TIME_RESULT->setPlaceholderText("search SN、TIME、OK/NG");
|
|
m_Font.setPixelSize(20);
|
|
m_Line_SN_TIME_RESULT->setFont(m_Font);
|
|
palette.setColor(QPalette::Text, Qt::white);
|
|
m_Line_SN_TIME_RESULT->setPalette(palette);
|
|
m_Line_SN_TIME_RESULT->setObjectName(QString::fromUtf8("m_search_LineEdit"));
|
|
|
|
|
|
m_SearchButton = new QToolButton(this);
|
|
QPixmap m_map;
|
|
m_map.load(currPath + "/Icon/搜索_1.png");
|
|
m_map = m_map.scaled(32, 32, Qt::KeepAspectRatio);
|
|
m_SearchButton->setIcon(m_map);
|
|
|
|
m_SearchButton->setStyleSheet(QToolbutton_style_sheet);
|
|
|
|
// 列表属性设置
|
|
m_result_List = new QTableWidget(this);
|
|
|
|
m_result_List->verticalHeader()->setHidden(true);//取消行号
|
|
m_result_List->horizontalHeader()->setHighlightSections(false);//取消表头选中高亮
|
|
m_result_List->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//自适应表格宽度
|
|
//m_result_List->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //隐藏垂直滚动条
|
|
m_result_List->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //隐藏水平滚动条
|
|
m_result_List->setSelectionBehavior(QAbstractItemView::SelectRows);//整行选中
|
|
m_result_List->setSelectionMode(QAbstractItemView::MultiSelection);//单选
|
|
m_result_List->setEditTriggers(QAbstractItemView::NoEditTriggers); //禁止编辑表格
|
|
m_result_List->setFont(m_Font);
|
|
m_result_List->setObjectName(QString::fromUtf8("m_search_TableWidget"));
|
|
|
|
|
|
|
|
QHBoxLayout* mainWidgetLayout = new QHBoxLayout(this);
|
|
QWidget* mainWidget = new QWidget;
|
|
mainWidget->setMouseTracking(true);
|
|
mainWidgetLayout->addWidget(mainWidget);
|
|
mainWidgetLayout->setMargin(0);
|
|
// 设置控件布局
|
|
QGridLayout* pLayout = new QGridLayout();
|
|
|
|
pLayout->addWidget(m_Line_SN_TIME_RESULT, 0, 0, 1, 3);
|
|
pLayout->addWidget(m_SearchButton, 0, 3, 1, 1);
|
|
pLayout->addWidget(m_text, 1, 0, 2, 4);
|
|
pLayout->addWidget(m_result_List, 5, 0, 10, 4);
|
|
pLayout->setContentsMargins(1, 1, 1, 1);
|
|
mainWidget->setLayout(pLayout);
|
|
|
|
////初始化表头
|
|
m_result_List->setColumnCount(3);
|
|
QStringList header;
|
|
header << QString::fromUtf8("时间") << QString::fromUtf8("条码") << QString::fromUtf8("结果");
|
|
m_result_List->setHorizontalHeaderLabels(header); //设置水平表头
|
|
m_result_List->setStyleSheet(tabel_sheet);
|
|
//m_result_List->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);//自适应表格宽度
|
|
m_result_List->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);//自适应表格宽度
|
|
|
|
//新增加右键菜单
|
|
m_result_List->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
// 搜索按钮 关联信号
|
|
connect(m_SearchButton, &QToolButton::clicked, [this]() {
|
|
//判断文本框内容
|
|
//if (!this->m_Line_SN_TIME_RESULT->text().isEmpty() )
|
|
{
|
|
emit Send_Search_SN_TIME_RESULT(m_Line_SN_TIME_RESULT->text());
|
|
QThread::msleep(500);
|
|
}
|
|
});
|
|
|
|
connect(this, &SearchLineEdit::Send_Search_SN_TIME_RESULT, [this](QString res) {
|
|
|
|
if (m_text->text().indexOf(QString::fromUtf8("正在检索")) != -1) {
|
|
//判断当前是否处于刷新状态
|
|
|
|
return;
|
|
}
|
|
if (res.isEmpty()) {
|
|
if (search_resultList.count() > 0) {
|
|
Load_Time_resultlist(str_resultList);
|
|
search_name = res;
|
|
search_resultList.clear();
|
|
return;
|
|
}
|
|
if (m_result_List->rowCount() <= 0 && str_resultList.count() > 0) {
|
|
Load_Time_resultlist(str_resultList);
|
|
search_name = res;
|
|
search_resultList.clear();
|
|
}
|
|
return;
|
|
}
|
|
else if (res == search_name) {
|
|
return;
|
|
}
|
|
else {
|
|
search_name = res;
|
|
search_resultList.clear();
|
|
for each (auto var in str_resultList) {
|
|
if (var.indexOf(res) != -1) {
|
|
search_resultList.append(var);
|
|
}
|
|
}
|
|
|
|
Search_Result_List(search_resultList);
|
|
}
|
|
|
|
});
|
|
|
|
connect(m_result_List, &QTableWidget::cellClicked, [this](int row, int col) {
|
|
if (row != -1) {
|
|
if (row < m_result_List->rowCount()) {
|
|
QString path;
|
|
if (row<search_resultList.size()) {
|
|
path = search_resultList.at(row);
|
|
}
|
|
else if(row<str_resultList.size()) {
|
|
path = str_resultList.at(row);
|
|
}
|
|
else {
|
|
return;
|
|
}
|
|
|
|
emit checkResult(path);
|
|
}
|
|
}
|
|
});
|
|
|
|
//创建菜单项
|
|
m_pContextMenu = new QMenu(this);
|
|
m_pActionCopy = new QAction(this);
|
|
m_pActionCopy->setText(QString::fromUtf8("拷贝原图"));
|
|
m_pActionEsc = new QAction(this);
|
|
m_pActionEsc->setText(QString::fromUtf8("取消选中"));
|
|
m_pContextMenu->addAction(m_pActionCopy);
|
|
m_pContextMenu->addAction(m_pActionEsc);
|
|
connect(m_pContextMenu, &QMenu::triggered, [this](QAction* act) {
|
|
if (act == m_pActionCopy)
|
|
{
|
|
QList<QTableWidgetSelectionRange> ranges = m_result_List->selectedRanges();
|
|
QStringList list_lable;
|
|
if (ranges.count() == 0)
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < ranges.count(); i++)
|
|
{
|
|
int topRow = ranges.at(i).topRow();
|
|
|
|
int bottomRow = ranges.at(i).bottomRow();
|
|
|
|
for (int j = topRow; j <= bottomRow; j++)
|
|
{
|
|
if (j < search_resultList.size()) {
|
|
list_lable.append( search_resultList.at(j));
|
|
}
|
|
else if (j < str_resultList.size()) {
|
|
list_lable.append( str_resultList.at(j));
|
|
}
|
|
else {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
QString new_dir = "D:/Out_def_Ori";//结果路径
|
|
for each (auto res in list_lable) {
|
|
QStringList pp = res.split(",");
|
|
if (pp.size() != 2)continue;
|
|
QString input_SN = pp.at(0).split("_").at(1);//04QCB17940000HCCG9001350
|
|
//time2会显示 invalid 数据无效,未根据设定的格式,设置日期
|
|
QStringList times = pp.at(0).split("_").at(0).split("-");
|
|
QString day_time_file = QString("%1-%2-%3").arg(times.at(0), times.at(1), times.at(2));//2022-12-18
|
|
QString hour_time_file = times.at(3) + "H";//13H
|
|
QString Ori_Path_1 = "//DESKTOP-STATION/Ori/" + day_time_file + "/" + hour_time_file;
|
|
QString Ori_Path_2 = "//192.168.2.52/Ori/" + day_time_file + "/" + hour_time_file;
|
|
QString Ori_Path_3 = "D:/Ori/" + day_time_file + "/" + hour_time_file;
|
|
|
|
QStringList show_SN_File_Path1 = addNextDirectory(Ori_Path_1, true, "");
|
|
QStringList show_SN_File_Path2 = addNextDirectory(Ori_Path_2, true, "");
|
|
QStringList show_SN_File_Path3 = addNextDirectory(Ori_Path_3, true, "");
|
|
for (int i = 0; i < show_SN_File_Path1.size(); i++)
|
|
{
|
|
QString del_Ori_SN = show_SN_File_Path1.at(i).split('/').last();//04QCB17940000HCCG9001350
|
|
if (input_SN == del_Ori_SN)
|
|
{
|
|
QString del_new_dir = new_dir + "/" + input_SN;//D:/Out_def_Ori/04QCB17940000HCCG9001350
|
|
createMultipleFoldes(del_new_dir);
|
|
qCopyDirectory(show_SN_File_Path1[i], del_new_dir, false);
|
|
break;
|
|
}
|
|
}
|
|
QThread::msleep(100);
|
|
for (int i = 0; i < show_SN_File_Path2.size(); i++)
|
|
{
|
|
QString del_Ori_SN = show_SN_File_Path2.at(i).split('/').last();//04QCB17940000HCCG9001350
|
|
if (input_SN == del_Ori_SN)
|
|
{
|
|
QString del_new_dir = new_dir + "/" + input_SN;//D:/Out_def_Ori/04QCB17940000HCCG9001350
|
|
createMultipleFoldes(del_new_dir);
|
|
qCopyDirectory(show_SN_File_Path2[i], del_new_dir, false);
|
|
break;
|
|
}
|
|
}
|
|
QThread::msleep(100);
|
|
for (int i = 0; i < show_SN_File_Path3.size(); i++)
|
|
{
|
|
QString del_Ori_SN = show_SN_File_Path3.at(i).split('/').last();//04QCB17940000HCCG9001350
|
|
if (input_SN == del_Ori_SN)
|
|
{
|
|
QString del_new_dir = new_dir + "/" + input_SN;//D:/Out_def_Ori/04QCB17940000HCCG9001350
|
|
createMultipleFoldes(del_new_dir);
|
|
qCopyDirectory(show_SN_File_Path3[i], del_new_dir, false);
|
|
break;
|
|
}
|
|
}
|
|
QThread::msleep(100);
|
|
}
|
|
|
|
|
|
}
|
|
else {
|
|
m_result_List->clearSelection();
|
|
}
|
|
});
|
|
connect(m_result_List, &QTableWidget::customContextMenuRequested, [this](const QPoint& pos) {
|
|
QTableWidgetItem* item = m_result_List->itemAt(pos);
|
|
if (item != nullptr) {
|
|
m_pContextMenu->exec(QCursor::pos());
|
|
}
|
|
}
|
|
);
|
|
|
|
}
|
|
|
|
void SearchLineEdit::setSavePath(const QStringList& path)
|
|
{
|
|
SavePath = path;
|
|
}
|
|
|
|
int SearchLineEdit::getSearch() {
|
|
return search_start;
|
|
}
|
|
|
|
void SearchLineEdit::stopSearch()
|
|
{
|
|
search_start = 0;
|
|
QThread::msleep(10);
|
|
}
|
|
|
|
void SearchLineEdit::Load_Time_resultlist(const QStringList& resultlist)
|
|
{
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
return;
|
|
}
|
|
m_text->setText(seach_start);
|
|
//emit waitSearch();
|
|
if (m_result_List) {
|
|
m_result_List->clearContents();
|
|
m_result_List->setRowCount(0);
|
|
|
|
}
|
|
int show_num = 800;
|
|
for (int i = 0; i < resultlist.size(); i++) {
|
|
if (show_num > 0) {
|
|
upListShow(resultlist.at(i));
|
|
--show_num;
|
|
}
|
|
|
|
}
|
|
isRuning = 0;
|
|
m_text->setText(seach_end);
|
|
//emit waitSearch(false);
|
|
qApp->processEvents();
|
|
}
|
|
|
|
void SearchLineEdit::GetCodeResuleInfos(const QStringList names) {
|
|
qDebug() << QString::fromUtf8("#########################结果汇总开始##########################");
|
|
|
|
QStringList NGnameList;
|
|
|
|
//NGnameList << QString::fromUtf8("TL_气泡异物_") << QString::fromUtf8("TF_气泡异物_") << QString::fromUtf8("TR_气泡异物_") << QString::fromUtf8("TB_气泡异物_") \
|
|
// << QString::fromUtf8("TL_严重凹坑_") << QString::fromUtf8("TF_严重凹坑_") << QString::fromUtf8("TR_严重凹坑_") << QString::fromUtf8("TB_严重凹坑_") \
|
|
// << QString::fromUtf8("TL_严重白点_") << QString::fromUtf8("TF_严重白点_") << QString::fromUtf8("TR_严重白点_") << QString::fromUtf8("TB_严重白点_") \
|
|
// << QString::fromUtf8("TL_其他NG_") << QString::fromUtf8("TF_其他NG_") << QString::fromUtf8("TR_其他NG_") << QString::fromUtf8("TB_其他NG_") \
|
|
// << QString::fromUtf8("TL_指纹脏污_") << QString::fromUtf8("TF_指纹脏污_") << QString::fromUtf8("TR_指纹脏污_") << QString::fromUtf8("TB_指纹脏污_") \
|
|
// << QString::fromUtf8("TL_异物_") << QString::fromUtf8("TF_异物_") << QString::fromUtf8("TR_异物_") << QString::fromUtf8("TB_异物_");
|
|
//NGnameList << QString::fromUtf8("TL_气泡异物_") << QString::fromUtf8("TF_气泡异物_") << QString::fromUtf8("TR_气泡异物_") << QString::fromUtf8("TB_气泡异物_")\
|
|
|
|
//NGnameList << QString::fromUtf8("TL_气泡_") << QString::fromUtf8("TF_气泡_") << QString::fromUtf8("TR_气泡_") << QString::fromUtf8("TB_气泡_") \
|
|
//<< QString::fromUtf8("TL_严重凹坑_") << QString::fromUtf8("TF_严重凹坑_") << QString::fromUtf8("TR_严重凹坑_") << QString::fromUtf8("TB_严重凹坑_") \
|
|
//<< QString::fromUtf8("TL_严重白点_") << QString::fromUtf8("TF_严重白点_") << QString::fromUtf8("TR_严重白点_") << QString::fromUtf8("TB_严重白点_") \
|
|
//<< QString::fromUtf8("TL_其他NG_") << QString::fromUtf8("TF_其他NG_") << QString::fromUtf8("TR_其他NG_") << QString::fromUtf8("TB_其他NG_") \
|
|
//<< QString::fromUtf8("TL_指纹脏污_") << QString::fromUtf8("TF_指纹脏污_") << QString::fromUtf8("TR_指纹脏污_") << QString::fromUtf8("TB_指纹脏污_") \
|
|
//<< QString::fromUtf8("TL_异物_") << QString::fromUtf8("TF_异物_") << QString::fromUtf8("TR_异物_") << QString::fromUtf8("TB_异物_")\
|
|
//<< QString::fromUtf8("TU_TUNG_") << QString::fromUtf8("TD_划伤_") << QString::fromUtf8("TD_底部不良_") << QString::fromUtf8("TU_极柱NG_") << QString::fromUtf8("TU_绝缘片NG_")\
|
|
//<< QString::fromUtf8("DE2_长棱NG_") << QString::fromUtf8("DE4_长棱NG_") << QString::fromUtf8("DE1_短棱NG_") << QString::fromUtf8("DE3_短棱NG_")\
|
|
//<< QString::fromUtf8("ME1_中棱NG_") << QString::fromUtf8("ME2_中棱NG_") << QString::fromUtf8("ME3_中棱NG_") << QString::fromUtf8("ME4_中棱NG_")\
|
|
//<< QString::fromUtf8("POS3_极柱划伤_") << QString::fromUtf8("POS3_极柱磕伤_") << QString::fromUtf8("POS3_极柱脏污_")<< QString::fromUtf8("POS3_极柱眼不良_") \
|
|
//<< QString::fromUtf8("NEG3_极柱划伤_") << QString::fromUtf8("NEG3_极柱磕伤_") << QString::fromUtf8("NEG3_极柱脏污_")<< QString::fromUtf8("NEG3_极柱眼不良_") \
|
|
//<< QString::fromUtf8("PRO3_PRO脏污_") << QString::fromUtf8("PRO3_PRO水渍电解液_") << QString::fromUtf8("PRO3_PRO其他NG_") ;
|
|
NGnameList << QString::fromUtf8("气泡_") << QString::fromUtf8("异物") << QString::fromUtf8("严重凹坑") << QString::fromUtf8("TL_严重白点")<< QString::fromUtf8("其他NG") \
|
|
<< QString::fromUtf8("指纹脏污") << QString::fromUtf8("划伤") << QString::fromUtf8("底部不良") << QString::fromUtf8("绝缘片翘起") \
|
|
<< QString::fromUtf8("长棱边NG") << QString::fromUtf8("中棱边NG") << QString::fromUtf8("短棱边NG") \
|
|
<< QString::fromUtf8("极柱划伤") << QString::fromUtf8("极柱磕伤") << QString::fromUtf8("极柱脏污")<< QString::fromUtf8("极柱眼不良") \
|
|
<< QString::fromUtf8("防爆阀脏污") << QString::fromUtf8("防爆阀水渍电解液") << QString::fromUtf8("防爆阀贴歪") ;
|
|
|
|
QFile data("./00000outDat.csv"); // 以上两行用时间戳作为文件名
|
|
if (!data.open(QFile::WriteOnly | QFile::Truncate)) // 打开文件
|
|
{
|
|
return;
|
|
}
|
|
QTextStream out(&data); // 输入流
|
|
QString ONES = "SN,";
|
|
for each (auto v in NGnameList) {
|
|
ONES.append(v + ",过检/漏检,");
|
|
}
|
|
ONES.append("\n");
|
|
out << ONES;
|
|
int add_count = 0;
|
|
int dirnum = 0; int all_num = names.size();
|
|
for each(auto sn in names) {
|
|
//遍历SN
|
|
QStringList pp = sn.split(",");
|
|
if (pp.count() != 2||pp.at(1).indexOf("OK")!=-1) continue;
|
|
|
|
QString SN = pp.at(0).split("_").at(1);
|
|
//time2会显示 invalid 数据无效,未根据设定的格式,设置日期
|
|
QStringList times = pp.at(0).split("_").at(0).split("-");
|
|
|
|
QString day_time = QString("%1-%2-%3").arg(times.at(0), times.at(1), times.at(2));
|
|
|
|
QString h_time = times.at(3);
|
|
QStringList paths;
|
|
/*////////
|
|
表一: SN
|
|
|
|
*////////
|
|
QMap<QString, int> init1;
|
|
for each (auto v in NGnameList) {
|
|
init1.insert(v, 0);
|
|
}
|
|
|
|
for (int i = 0; i < SavePath.size(); i++) {
|
|
auto var = SavePath.at(i);
|
|
//QString resultDir = QString("%1/%2/%3H/%4").arg(var, day_time, h_time, pp.at(0));
|
|
QString resultDir = QString("%1/%2/%3H").arg(var, day_time, h_time);
|
|
if (!isFileExist(resultDir)) {
|
|
qDebug() << QString::fromUtf8("结果文件夹不存在 ") << resultDir << endl;
|
|
continue;
|
|
}
|
|
for each (auto var in stationLists) {
|
|
if (var.indexOf("T") != -1 && var.indexOf("3D")!=-1)continue;
|
|
var.replace("\\","/");
|
|
//遍历文件夹下csv
|
|
QString csvpath = QString("%1%2").arg(resultDir, var);
|
|
ReadCSVInfos(var.split("/").last(), csvpath, init1);
|
|
|
|
}
|
|
}
|
|
QString ONES = SN.append(",");
|
|
for each (auto v in NGnameList) {
|
|
ONES.append(QString::number(init1[v]));
|
|
ONES.append(", ,");
|
|
|
|
}
|
|
ONES.append("\n");
|
|
out << ONES;
|
|
qDebug() << QString::fromUtf8("[ %1 : %2 ] SN : %3 ").arg(QString::number(dirnum), QString::number(all_num), SN) << endl;
|
|
dirnum++;
|
|
}
|
|
|
|
data.close();
|
|
return ;
|
|
}
|
|
|
|
void SearchLineEdit::ReadCSVInfos(const QString top, const QString station, QMap<QString, int>& resultsMap) {
|
|
|
|
//QMap<QString, int>resultsMap;//缺陷名,缺陷数
|
|
QDir dir;
|
|
dir.setPath(station);
|
|
dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
|
QFileInfoList list = dir.entryInfoList();
|
|
if (list.count()) {
|
|
for each (auto var in list) {
|
|
if (var.suffix() == "csv"&&var.fileName().indexOf("OK")==-1) {
|
|
//读取文件
|
|
QString csvpath = var.absoluteFilePath();
|
|
// 读取每日csv
|
|
QStringList lines; //配置信息列表
|
|
QFile configFile;
|
|
configFile.setFileName(csvpath);
|
|
bool isUtf8 = true;
|
|
if (FileCharacterEncoding(csvpath) == EncodingFormat::ANSI)isUtf8 = false;
|
|
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QTextStream stream_text(&configFile);
|
|
stream_text.seek(0);
|
|
|
|
while (!stream_text.atEnd())
|
|
{
|
|
lines.push_back(gb2312ToUtf8(stream_text.readLine()));
|
|
}
|
|
}
|
|
else {
|
|
qDebug() << "read csv " << csvpath << " failed!" << endl;
|
|
}
|
|
configFile.close();
|
|
if (lines.count() > 2) {
|
|
for (int a = 2; a < lines.count(); a++) {
|
|
QStringList l_p = lines.at(a).split(",");
|
|
if(l_p.at(0)!="") {
|
|
resultsMap.insert(top +"_"+ l_p.at(0), l_p.at(1).split("|").at(0).toInt());
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void SearchLineEdit::Search_Result_List(const QStringList& searchlist)
|
|
{
|
|
m_text->setText(seach_start);
|
|
if (m_result_List) {
|
|
m_result_List->clearContents();
|
|
m_result_List->setRowCount(0);
|
|
}
|
|
|
|
|
|
//emit waitSearch();
|
|
|
|
for (int i = 0; i < searchlist.size(); i++) {
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
upListShow(searchlist.at(i));
|
|
|
|
}
|
|
|
|
//emit waitSearch(false);
|
|
m_text->setText(seach_end);
|
|
isRuning = 0;
|
|
qApp->processEvents();
|
|
}
|
|
|
|
void SearchLineEdit::GetResultRepot()
|
|
{
|
|
if (getResult)return;
|
|
QFutureWatcher<void>* pwatcher = nullptr;
|
|
pwatcher = new QFutureWatcher<void>;
|
|
|
|
//把扫描到的信息输出
|
|
QFuture<void> future = QtConcurrent::run([=]()
|
|
{
|
|
GetCodeResuleInfos(str_resultList);
|
|
//耗时操作
|
|
});
|
|
|
|
connect(pwatcher, &QFutureWatcher<void>::finished, this, [=]()
|
|
{
|
|
getResult = 0;
|
|
//主线程操作
|
|
qDebug() << QString::fromUtf8("#########################结果汇总完成##########################");
|
|
qApp->processEvents();
|
|
});
|
|
|
|
pwatcher->setFuture(future);
|
|
}
|
|
|
|
void SearchLineEdit::clearList()
|
|
{
|
|
if (!isRuning&& m_text->text().indexOf(QString::fromUtf8("正在检索")) != -1) {
|
|
isRuning = 1;
|
|
}
|
|
while (isRuning) {
|
|
QThread::msleep(1);
|
|
qApp->processEvents();
|
|
}
|
|
m_result_List->clearContents();//清理列表
|
|
m_result_List->setRowCount(0);
|
|
str_resultList.clear();
|
|
search_resultList.clear();
|
|
search_name = "";
|
|
m_Line_SN_TIME_RESULT->setText(search_name);
|
|
qApp->processEvents();
|
|
}
|
|
/// <summary>
|
|
/// 搜索SN
|
|
/// </summary>
|
|
/// <param name="res每行数据"></param>
|
|
void SearchLineEdit::upListShow(const QString res)
|
|
{
|
|
|
|
QStringList dirArray = res.split(",");
|
|
QString result_ng = dirArray.at(1);
|
|
qDebug() << dirArray.at(1) << dirArray.at(0);
|
|
QString timetemp = dirArray.at(0).split("_").at(0);
|
|
QString tempSN = dirArray.at(0).split("_").at(1);
|
|
//QString tempSN = (dirArray.at(0).split("//").at(1)).split("-").at(0);
|
|
//QString timetemp = "16H";
|
|
//QString tempSN = "ABCSASASCAASASD-0";
|
|
|
|
QTableWidgetItem* item = new QTableWidgetItem(timetemp);
|
|
QTableWidgetItem* item0 = new QTableWidgetItem(tempSN);
|
|
QTableWidgetItem* item1 = new QTableWidgetItem(result_ng);
|
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
QColor ptr = ok_color;
|
|
if (result_ng.indexOf("OK") != -1) {
|
|
ptr = ok_color;
|
|
}
|
|
else if (result_ng.indexOf("NG") != -1) {
|
|
ptr = ng_color;
|
|
}
|
|
else {
|
|
ptr = er_color;
|
|
}
|
|
item->setBackgroundColor(ptr);
|
|
item0->setBackgroundColor(ptr);
|
|
item1->setBackgroundColor(ptr);
|
|
int row = m_result_List->rowCount();
|
|
m_result_List->setRowCount(row + 1);//总行数增加1
|
|
m_result_List->setItem(row, 0, item);
|
|
m_result_List->setItem(row, 1, item0);
|
|
m_result_List->setItem(row, 2, item1);
|
|
qApp->processEvents();
|
|
}
|
|
bool SearchLineEdit::checkSameData(const QString res)//检查是否有相同数据,有则返回true
|
|
{
|
|
QStringList dirArray = res.split(",");
|
|
QString result_ng = dirArray.at(1);
|
|
qDebug() << dirArray.at(1) << dirArray.at(0);
|
|
QString timetemp = dirArray.at(0).split("_").at(0);
|
|
QString tempSN = dirArray.at(0).split("_").at(1);
|
|
|
|
int row = m_result_List->rowCount();
|
|
for (int i = 0; i < row; i++)
|
|
{
|
|
if (m_result_List->item(i, 1)->text().compare(tempSN) == false)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
void SearchLineEdit::GetDataTimeCSV(const QStringList Datatime,const QString day) {
|
|
|
|
QDateTime datetime = QDateTime::currentDateTime();
|
|
QString now = datetime.toString("yyyy-MM-dd");
|
|
QString path = QString("./DataSheet/statics_%1.csv").arg(day);
|
|
if (!isFileExist(path)) {
|
|
|
|
|
|
QStringList Datatimes;
|
|
Datatimes << QString::fromUtf8("时间段,良品数,不良品数,良品率");
|
|
for (int i = 0; i < 24; i++) {
|
|
QString time = QString("%1H").arg(i, 2, 10, QLatin1Char('0'));
|
|
int app = -1;
|
|
for (auto var = 0; var < Datatime.size(); var++) {
|
|
if (Datatime[var].indexOf(time) != -1) {
|
|
app = var;
|
|
break;
|
|
}
|
|
};
|
|
if (app >= 0) {
|
|
Datatimes << Datatime[app];
|
|
}
|
|
else {
|
|
|
|
time.append(",0,0,100.00");
|
|
|
|
Datatimes << time;
|
|
}
|
|
|
|
}
|
|
WriteTXTCfg(Datatimes, path);
|
|
}
|
|
|
|
}
|
|
void SearchLineEdit::GetDataTimeList2(const QString Datatime, int tim_label)
|
|
{
|
|
while (m_text->text().indexOf(QString::fromUtf8("正在检索")) != -1) {
|
|
//判断当前是否处于刷新状态
|
|
QThread::msleep(100);
|
|
qApp->processEvents();
|
|
|
|
}
|
|
// 清理SN列表
|
|
clearList();
|
|
isRuning = 0;//刷新
|
|
|
|
qApp->processEvents();
|
|
m_datatime = Datatime;
|
|
QDateTime datetime = QDateTime::currentDateTime();
|
|
QString now = datetime.toString("yyyy-MM-dd");
|
|
QString resultDir = QString("%1/%2").arg(SavePath.at(0), Datatime);
|
|
if (Datatime != now) {
|
|
if (!isFileExist(resultDir)) {
|
|
search_start = 0;
|
|
qDebug() << QString::fromUtf8("结果文件夹不存在 ") << resultDir << endl;
|
|
return;
|
|
}
|
|
}
|
|
qDebug() << resultDir;
|
|
for (auto a : SavePath)
|
|
qDebug() << a;
|
|
// 开始检索
|
|
m_text->setText(seach_start);
|
|
|
|
QFutureWatcher<void>* pwatcher = nullptr;
|
|
pwatcher = new QFutureWatcher<void>;
|
|
|
|
//把扫描到的信息输出
|
|
QFuture<void> future = QtConcurrent::run([=]()
|
|
{qDebug() << "";
|
|
});
|
|
|
|
connect(pwatcher, &QFutureWatcher<void>::finished, this, [=]()
|
|
{
|
|
m_text->setText(seach_end);
|
|
isRuning = 0;
|
|
qApp->processEvents();
|
|
});
|
|
pwatcher->setFuture(future);
|
|
qApp->processEvents();
|
|
}
|
|
void SearchLineEdit::GetDataTimeList(const QString Datatime, int tim_label)
|
|
{
|
|
while (m_text->text().indexOf(QString::fromUtf8("正在检索")) != -1) {
|
|
//判断当前是否处于刷新状态
|
|
QThread::msleep(100);
|
|
qApp->processEvents();
|
|
|
|
}
|
|
// 清理SN列表
|
|
clearList();
|
|
isRuning = 0;//刷新
|
|
|
|
qApp->processEvents();
|
|
m_datatime = Datatime;
|
|
QDateTime datetime = QDateTime::currentDateTime();
|
|
QString now = datetime.toString("yyyy-MM-dd");
|
|
QString resultDir = QString("%1/%2").arg(SavePath.at(0), Datatime);
|
|
if (Datatime != now) {
|
|
if (!isFileExist(resultDir)) {
|
|
search_start = 0;
|
|
qDebug() << QString::fromUtf8("结果文件夹不存在 ") << resultDir << endl;
|
|
return;
|
|
}
|
|
}
|
|
qDebug() << resultDir;
|
|
for (auto a : SavePath)
|
|
qDebug() << a;
|
|
// 开始检索
|
|
m_text->setText(seach_start);
|
|
|
|
QFutureWatcher<void>* pwatcher = nullptr;
|
|
pwatcher = new QFutureWatcher<void>;
|
|
//str_resultList.append(QString("%1,%2").arg("camera3P_ABCSASASCAASASD_-0-14-25-06", "D://CCD//result//2023-07-27//16H//ABCSASASCAASASD-0//"));
|
|
//把扫描到的信息输出
|
|
QFuture<void> future = QtConcurrent::run([=]() { searchProgram(resultDir, Datatime, tim_label); });
|
|
|
|
connect(pwatcher, &QFutureWatcher<void>::finished, this, [=]()
|
|
{
|
|
m_text->setText(seach_end);
|
|
isRuning = 0;
|
|
qApp->processEvents();
|
|
});
|
|
pwatcher->setFuture(future);
|
|
qApp->processEvents();
|
|
}
|
|
void SearchLineEdit::searchProgram(const QString& resultDir, const QString& Datatime, const int & tim_label)
|
|
{
|
|
search_start = 1;
|
|
int show_num = 800;
|
|
QString csvpath = QString("%1/Data_%2.csv").arg(resultDir, Datatime);
|
|
// 判断D盘汇总文件是否存在,没有去C盘找
|
|
if (!isFileExist(csvpath))
|
|
csvpath = QString("%1/%2/Data_%3.csv").arg(SavePath.at(1), Datatime, Datatime);
|
|
std::cout << csvpath.toStdString() << endl;
|
|
QFile configFile;
|
|
configFile.setFileName(csvpath);
|
|
// csv 查询汇总日志 // 文件夹查询
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) //如果csv存在
|
|
{
|
|
QTextStream stream_text(&configFile);
|
|
QStringList lines;
|
|
stream_text.setCodec(QTextCodec::codecForName("utf-8"));
|
|
//可读取中文
|
|
stream_text.seek(0);
|
|
while (!stream_text.atEnd())
|
|
{
|
|
|
|
lines.push_back(/*gb2312ToUtf8*/(stream_text.readLine()));
|
|
}
|
|
lines.removeFirst();
|
|
configFile.close();
|
|
|
|
|
|
// 遍历列表信息
|
|
//对应全天
|
|
if (tim_label == 24)
|
|
{
|
|
// 记录 检测良率
|
|
QStringList Tp;
|
|
int all_num = 0;
|
|
int ok_num = 0;
|
|
QString times_day = "25H";
|
|
for each (auto var in lines) {
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
if (var.split(",").size() < 3)continue;//防止空文件夾
|
|
QStringList strList = var.split(",");
|
|
QString oldtimes = strList.at(0);// .split("-").at(3) + "H";
|
|
if (!oldtimes.isEmpty() && oldtimes != times_day) {
|
|
QString times = times_day + QString::fromUtf8(",%1,%2,%3").arg(QString::number(ok_num), QString::number(all_num - ok_num), QString::number(double((float)ok_num / (all_num) * 100.00), 'f', 2));
|
|
Tp << times;
|
|
all_num = 0;
|
|
ok_num = 0;
|
|
times_day = oldtimes;
|
|
}
|
|
all_num++;
|
|
|
|
QString result_ng = QString::fromUtf8("待下料");
|
|
QString name = var.split(",").at(2).split("/").last();
|
|
if (str_resultList.contains(name))continue;
|
|
else {
|
|
result_ng = var.split(",").at(3);
|
|
str_resultList.append(QString("%1,%2").arg(name, result_ng));
|
|
if (show_num > 0) {
|
|
upListShow(QString("%1,%2").arg(name, result_ng));
|
|
--show_num;
|
|
}
|
|
}
|
|
if (result_ng.indexOf("OK") != -1)ok_num++;
|
|
|
|
}
|
|
GetDataTimeCSV(Tp, Datatime);
|
|
}
|
|
//其他时间段
|
|
else {
|
|
QString time = QString("%1H").arg(tim_label, 2, 10, QLatin1Char('0'));
|
|
|
|
for each (auto var in lines) {
|
|
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
if (var.split(",").size() < 3)continue;//防止空文件夾
|
|
QString result_ng = QString::fromUtf8("待下料");//这是结果,OKNG
|
|
//QString name = var.split(",").at(2).split("/").last();//文件名?
|
|
//QString oldtimes = var.split(",").at(0).split("-").at(3) + "H";//时间
|
|
//QString name = "16H//02YCE01D3D0003133-0//camera1-SprfDiffuseReflectionImage-17-15-32.bmp";//文件名?
|
|
QString name = var.split(",").at(2).split("/").last();
|
|
QString oldtimes = var.split(",").at(0);//时间
|
|
if (str_resultList.contains(name) || oldtimes != time)continue;
|
|
else {
|
|
result_ng = var.split(",").at(3);
|
|
str_resultList.append(QString("%1,%2").arg(name, result_ng));
|
|
if (show_num > 0) {
|
|
upListShow(QString("%1,%2").arg(name, result_ng));
|
|
--show_num;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (tim_label == 24) //全天
|
|
{
|
|
for (int i = 0; i < SavePath.size(); i++) {
|
|
auto var = SavePath.at(i);
|
|
QStringList Dirlists = addNextDirectory(var);//所有日期
|
|
QString resultDir = QString("%1/%2/").arg(var, Datatime);
|
|
if (!isFileExist(resultDir)) {
|
|
qDebug() << QString::fromUtf8("结果文件夹不存在 ") << resultDir << endl;
|
|
continue;
|
|
}
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QStringList Times = addNextDirectory(resultDir);//日期下所有时间段
|
|
QStringList Tp;
|
|
for each (auto tm in Times) {
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QStringList Dirs = addNextDirectory(tm);//产品SN
|
|
int dirnum = 0; int all_num = Dirs.size();
|
|
int ok_num = 0;
|
|
for each (auto dir in Dirs)
|
|
{
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
|
|
QString name = dir.split("/").last();
|
|
qDebug() << name;
|
|
if (str_resultList.contains(name))continue;
|
|
QString result_ng = QString::fromUtf8("待下料");
|
|
// 读取产品结果
|
|
{
|
|
QString csvpath = QString("%1/Result.txt").arg(dir);
|
|
{
|
|
// 读取每日csv
|
|
QStringList lines; //配置信息列表
|
|
QFile configFile;
|
|
configFile.setFileName(csvpath);
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QTextStream stream_text(&configFile);
|
|
stream_text.setCodec(QTextCodec::codecForName("utf-8"));
|
|
//可读取中文
|
|
stream_text.seek(0);
|
|
while (!stream_text.atEnd())
|
|
{
|
|
lines.push_back(gb2312ToUtf8(stream_text.readLine()));
|
|
}
|
|
|
|
}
|
|
else {
|
|
qDebug() << "read csv " << csvpath << " failed!" << endl;
|
|
|
|
}
|
|
configFile.close();
|
|
|
|
|
|
if (lines.count() != 0) {
|
|
result_ng = lines.at(0).split(",").at(3);
|
|
}
|
|
else {
|
|
continue;
|
|
}
|
|
if (result_ng.indexOf("OK") != -1)ok_num++;
|
|
}
|
|
|
|
}
|
|
str_resultList.append(QString("%1,%2").arg(name, result_ng));
|
|
if (show_num > 0) {
|
|
upListShow(QString("%1,%2").arg(name, result_ng));
|
|
--show_num;
|
|
}
|
|
|
|
|
|
qDebug() << QString::fromUtf8("[%1][ %2 : %3 ] SN : %4 ").arg(tm, QString::number(dirnum), QString::number(all_num), name) << endl;
|
|
/// csv读取
|
|
dirnum++;
|
|
}
|
|
QString tt = tm.mid(tm.lastIndexOf("/") + 1);
|
|
QString times = tt.append(QString::fromUtf8(",%1,%2,%3").arg(QString::number(ok_num), QString::number(all_num - ok_num), QString::number(double((float)ok_num / (all_num) * 100.00), 'f', 2)));
|
|
Tp << times;
|
|
}
|
|
GetDataTimeCSV(Tp, Datatime);
|
|
}
|
|
|
|
|
|
}
|
|
else {
|
|
for (int i = 0; i < 1; i++)//遍历所有结果路径
|
|
{
|
|
auto var = SavePath.at(i);
|
|
QStringList Dirlists = addNextDirectory(var);//所有日期
|
|
QString time = QString("%1H").arg(tim_label, 2, 10, QLatin1Char('0'));
|
|
QString resultDir = QString("%1/%2/%3/").arg(var, Datatime, time);
|
|
if (!isFileExist(resultDir)) {
|
|
qDebug() << QString::fromUtf8("结果文件夹不存在 ") << resultDir << endl;
|
|
continue;
|
|
}
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QStringList Dirs = addNextDirectory(resultDir);//产品SN
|
|
int dirnum = 0; int all_num = Dirs.size();
|
|
for each (auto dir in Dirs)
|
|
{
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QString name = dir.split("/").last();
|
|
qDebug() << name;
|
|
if (str_resultList.contains(name))continue;
|
|
QString result_ng = QString::fromUtf8("待下料");
|
|
// 读取产品结果
|
|
{
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QString csvpath = QString("%1/Result.txt").arg(dir);
|
|
{
|
|
// 读取每日csv
|
|
qDebug() << csvpath;
|
|
QStringList lines; //配置信息列表
|
|
QFile configFile;
|
|
configFile.setFileName(csvpath);
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QTextStream stream_text(&configFile);
|
|
stream_text.setCodec(QTextCodec::codecForName("utf-8"));
|
|
//可读取中文
|
|
stream_text.seek(0);
|
|
while (!stream_text.atEnd())
|
|
{
|
|
lines.push_back(gb2312ToUtf8(stream_text.readLine()));
|
|
}
|
|
|
|
}
|
|
else {
|
|
qDebug() << "read csv " << csvpath << " failed!" << endl;
|
|
|
|
}
|
|
configFile.close();
|
|
|
|
if (lines.count() != 0) {
|
|
result_ng = lines.at(0).split(",").at(3);
|
|
}
|
|
else {
|
|
continue;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
str_resultList.append(QString("%1,%2").arg(name, result_ng));
|
|
if (show_num > 0) {
|
|
upListShow(QString("%1,%2").arg(name, result_ng));
|
|
--show_num;
|
|
}
|
|
qDebug() << QString::fromUtf8("[ %1 : %2 ] SN : %3 ").arg(QString::number(dirnum), QString::number(all_num), name) << endl;
|
|
/// csv读取
|
|
dirnum++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
search_start = 0;
|
|
|
|
|
|
}
|
|
void SearchLineEdit::RefreshDataTimeList(const QString Datatime, int tim_label)
|
|
{
|
|
while (m_text->text().indexOf(QString::fromUtf8("正在检索")) != -1) {
|
|
//判断当前是否处于刷新状态
|
|
QThread::msleep(100);
|
|
qApp->processEvents();
|
|
|
|
}
|
|
// 清理SN列表
|
|
//clearList();
|
|
isRuning = 0;//刷新
|
|
|
|
qApp->processEvents();
|
|
m_datatime = Datatime;
|
|
QDateTime datetime = QDateTime::currentDateTime();
|
|
QString now = datetime.toString("yyyy-MM-dd");
|
|
QString resultDir = QString("%1/%2").arg(SavePath.at(0), Datatime);
|
|
if (Datatime != now) {
|
|
if (!isFileExist(resultDir)) {
|
|
search_start = 0;
|
|
qDebug() << QString::fromUtf8("结果文件夹不存在 ") << resultDir << endl;
|
|
return;
|
|
}
|
|
}
|
|
qDebug() << resultDir;
|
|
for (auto a : SavePath)
|
|
qDebug() << a;
|
|
// 开始检索
|
|
//m_text->setText(seach_start);
|
|
|
|
QFutureWatcher<void>* pwatcher = nullptr;
|
|
pwatcher = new QFutureWatcher<void>;
|
|
//str_resultList.append(QString("%1,%2").arg("camera3P_ABCSASASCAASASD_-0-14-25-06", "D://CCD//result//2023-07-27//16H//ABCSASASCAASASD-0//"));
|
|
//把扫描到的信息输出
|
|
QFuture<void> future = QtConcurrent::run([=]() { refreshProgram(resultDir, Datatime, tim_label); });
|
|
|
|
connect(pwatcher, &QFutureWatcher<void>::finished, this, [=]()
|
|
{
|
|
m_text->setText(seach_end);
|
|
isRuning = 0;
|
|
qApp->processEvents();
|
|
});
|
|
pwatcher->setFuture(future);
|
|
qApp->processEvents();
|
|
}
|
|
void SearchLineEdit::refreshProgram(const QString& resultDir, const QString& Datatime, const int& tim_label)
|
|
{
|
|
search_start = 1;
|
|
int show_num = 800;
|
|
QString csvpath = QString("%1/Data_%2.csv").arg(resultDir, Datatime);
|
|
// 判断D盘汇总文件是否存在,没有去C盘找
|
|
if (!isFileExist(csvpath))
|
|
csvpath = QString("%1/%2/Data_%3.csv").arg(SavePath.at(1), Datatime, Datatime);
|
|
std::cout << csvpath.toStdString() << endl;
|
|
QFile configFile;
|
|
configFile.setFileName(csvpath);
|
|
// csv 查询汇总日志 // 文件夹查询
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) //如果csv存在
|
|
{
|
|
QTextStream stream_text(&configFile);
|
|
QStringList lines;
|
|
stream_text.setCodec(QTextCodec::codecForName("utf-8"));
|
|
//可读取中文
|
|
stream_text.seek(0);
|
|
while (!stream_text.atEnd())
|
|
{
|
|
|
|
lines.push_back(/*gb2312ToUtf8*/(stream_text.readLine()));
|
|
}
|
|
lines.removeFirst();
|
|
int rowsSkip = m_result_List->rowCount();
|
|
configFile.close();
|
|
// 遍历列表信息
|
|
//对应全天
|
|
int count = 0;
|
|
if (tim_label == 24)
|
|
{
|
|
// 记录 检测良率
|
|
QStringList Tp;
|
|
int all_num = 0;
|
|
int ok_num = 0;
|
|
QString times_day = "25H";
|
|
for each (auto var in lines) {
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
|
|
if (var.split(",").size() < 3)continue;//防止空文件夾
|
|
QStringList strList = var.split(",");
|
|
QString oldtimes = strList.at(0);// .split("-").at(3) + "H";
|
|
if (!oldtimes.isEmpty() && oldtimes != times_day) {
|
|
QString times = times_day + QString::fromUtf8(",%1,%2,%3").arg(QString::number(ok_num), QString::number(all_num - ok_num), QString::number(double((float)ok_num / (all_num) * 100.00), 'f', 2));
|
|
Tp << times;
|
|
all_num = 0;
|
|
ok_num = 0;
|
|
times_day = oldtimes;
|
|
}
|
|
all_num++;
|
|
|
|
QString result_ng = QString::fromUtf8("待下料");
|
|
QString name = var.split(",").at(2).split("/").last();
|
|
if (str_resultList.contains(name))continue;
|
|
else {
|
|
if (rowsSkip != count)
|
|
{
|
|
count++;
|
|
continue;
|
|
}
|
|
result_ng = var.split(",").at(3);
|
|
str_resultList.append(QString("%1,%2").arg(name, result_ng));
|
|
if (show_num > 0) {
|
|
QString str = QString("%1,%2").arg(name, result_ng);
|
|
|
|
upListShow(QString("%1,%2").arg(name, result_ng));
|
|
--show_num;
|
|
|
|
}
|
|
}
|
|
if (result_ng.indexOf("OK") != -1)ok_num++;
|
|
|
|
}
|
|
GetDataTimeCSV(Tp, Datatime);
|
|
}
|
|
//其他时间段
|
|
else {
|
|
QString time = QString("%1H").arg(tim_label, 2, 10, QLatin1Char('0'));
|
|
|
|
for each (auto var in lines) {
|
|
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
|
|
if (var.split(",").size() < 3)continue;//防止空文件夾
|
|
QString result_ng = QString::fromUtf8("待下料");//这是结果,OKNG
|
|
//QString name = var.split(",").at(2).split("/").last();//文件名?
|
|
//QString oldtimes = var.split(",").at(0).split("-").at(3) + "H";//时间
|
|
//QString name = "16H//02YCE01D3D0003133-0//camera1-SprfDiffuseReflectionImage-17-15-32.bmp";//文件名?
|
|
QString name = var.split(",").at(2).split("/").last();
|
|
QString oldtimes = var.split(",").at(0);//时间
|
|
if (str_resultList.contains(name) || oldtimes != time)continue;
|
|
else {
|
|
if (rowsSkip != count)
|
|
{
|
|
count++;
|
|
continue;
|
|
}
|
|
|
|
|
|
result_ng = var.split(",").at(3);
|
|
str_resultList.append(QString("%1,%2").arg(name, result_ng));
|
|
if (show_num > 0) {
|
|
QString str = QString("%1,%2").arg(name, result_ng);
|
|
|
|
upListShow(QString("%1,%2").arg(name, result_ng));
|
|
--show_num;
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (tim_label == 24) //全天
|
|
{
|
|
for (int i = 0; i < SavePath.size(); i++) {
|
|
auto var = SavePath.at(i);
|
|
QStringList Dirlists = addNextDirectory(var);//所有日期
|
|
QString resultDir = QString("%1/%2/").arg(var, Datatime);
|
|
if (!isFileExist(resultDir)) {
|
|
qDebug() << QString::fromUtf8("结果文件夹不存在 ") << resultDir << endl;
|
|
continue;
|
|
}
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QStringList Times = addNextDirectory(resultDir);//日期下所有时间段
|
|
QStringList Tp;
|
|
for each (auto tm in Times) {
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QStringList Dirs = addNextDirectory(tm);//产品SN
|
|
int dirnum = 0; int all_num = Dirs.size();
|
|
int ok_num = 0;
|
|
for each (auto dir in Dirs)
|
|
{
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
|
|
QString name = dir.split("/").last();
|
|
qDebug() << name;
|
|
if (str_resultList.contains(name))continue;
|
|
QString result_ng = QString::fromUtf8("待下料");
|
|
// 读取产品结果
|
|
{
|
|
QString csvpath = QString("%1/Result.txt").arg(dir);
|
|
{
|
|
// 读取每日csv
|
|
QStringList lines; //配置信息列表
|
|
QFile configFile;
|
|
configFile.setFileName(csvpath);
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QTextStream stream_text(&configFile);
|
|
stream_text.setCodec(QTextCodec::codecForName("utf-8"));
|
|
//可读取中文
|
|
stream_text.seek(0);
|
|
while (!stream_text.atEnd())
|
|
{
|
|
lines.push_back(gb2312ToUtf8(stream_text.readLine()));
|
|
}
|
|
|
|
}
|
|
else {
|
|
qDebug() << "read csv " << csvpath << " failed!" << endl;
|
|
|
|
}
|
|
configFile.close();
|
|
|
|
|
|
if (lines.count() != 0) {
|
|
result_ng = lines.at(0).split(",").at(3);
|
|
}
|
|
else {
|
|
continue;
|
|
}
|
|
if (result_ng.indexOf("OK") != -1)ok_num++;
|
|
}
|
|
|
|
}
|
|
str_resultList.append(QString("%1,%2").arg(name, result_ng));
|
|
if (show_num > 0) {
|
|
QString str = QString("%1,%2").arg(name, result_ng);
|
|
|
|
upListShow(QString("%1,%2").arg(name, result_ng));
|
|
--show_num;
|
|
|
|
}
|
|
|
|
|
|
qDebug() << QString::fromUtf8("[%1][ %2 : %3 ] SN : %4 ").arg(tm, QString::number(dirnum), QString::number(all_num), name) << endl;
|
|
/// csv读取
|
|
dirnum++;
|
|
}
|
|
QString tt = tm.mid(tm.lastIndexOf("/") + 1);
|
|
QString times = tt.append(QString::fromUtf8(",%1,%2,%3").arg(QString::number(ok_num), QString::number(all_num - ok_num), QString::number(double((float)ok_num / (all_num) * 100.00), 'f', 2)));
|
|
Tp << times;
|
|
}
|
|
GetDataTimeCSV(Tp, Datatime);
|
|
}
|
|
|
|
|
|
}
|
|
else {
|
|
for (int i = 0; i < 1; i++)//遍历所有结果路径
|
|
{
|
|
auto var = SavePath.at(i);
|
|
QStringList Dirlists = addNextDirectory(var);//所有日期
|
|
QString time = QString("%1H").arg(tim_label, 2, 10, QLatin1Char('0'));
|
|
QString resultDir = QString("%1/%2/%3/").arg(var, Datatime, time);
|
|
if (!isFileExist(resultDir)) {
|
|
qDebug() << QString::fromUtf8("结果文件夹不存在 ") << resultDir << endl;
|
|
continue;
|
|
}
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QStringList Dirs = addNextDirectory(resultDir);//产品SN
|
|
int dirnum = 0; int all_num = Dirs.size();
|
|
for each (auto dir in Dirs)
|
|
{
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QString name = dir.split("/").last();
|
|
qDebug() << name;
|
|
if (str_resultList.contains(name))continue;
|
|
QString result_ng = QString::fromUtf8("待下料");
|
|
// 读取产品结果
|
|
{
|
|
if (isRuning) {
|
|
//判断当前是否处于刷新状态
|
|
break;
|
|
}
|
|
QString csvpath = QString("%1/Result.txt").arg(dir);
|
|
{
|
|
// 读取每日csv
|
|
qDebug() << csvpath;
|
|
QStringList lines; //配置信息列表
|
|
QFile configFile;
|
|
configFile.setFileName(csvpath);
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QTextStream stream_text(&configFile);
|
|
stream_text.setCodec(QTextCodec::codecForName("utf-8"));
|
|
//可读取中文
|
|
stream_text.seek(0);
|
|
while (!stream_text.atEnd())
|
|
{
|
|
lines.push_back(gb2312ToUtf8(stream_text.readLine()));
|
|
}
|
|
|
|
}
|
|
else {
|
|
qDebug() << "read csv " << csvpath << " failed!" << endl;
|
|
|
|
}
|
|
configFile.close();
|
|
|
|
if (lines.count() != 0) {
|
|
result_ng = lines.at(0).split(",").at(3);
|
|
}
|
|
else {
|
|
continue;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
str_resultList.append(QString("%1,%2").arg(name, result_ng));
|
|
if (show_num > 0) {
|
|
QString str = QString("%1,%2").arg(name, result_ng);
|
|
|
|
upListShow(QString("%1,%2").arg(name, result_ng));
|
|
--show_num;
|
|
|
|
}
|
|
qDebug() << QString::fromUtf8("[ %1 : %2 ] SN : %3 ").arg(QString::number(dirnum), QString::number(all_num), name) << endl;
|
|
/// csv读取
|
|
dirnum++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
search_start = 0;
|
|
|
|
|
|
}
|
|
void SearchLineEdit::keyReleaseEvent(QKeyEvent* e)
|
|
{
|
|
if (e->key() == Qt::Key_Return) {
|
|
//if (!this->m_Line_SN_TIME_RESULT->text().isEmpty())
|
|
if (this->focusWidget()->objectName() == m_Line_SN_TIME_RESULT->objectName())
|
|
{
|
|
emit Send_Search_SN_TIME_RESULT(m_Line_SN_TIME_RESULT->text());
|
|
QThread::msleep(500);
|
|
}
|
|
}
|
|
else {
|
|
|
|
}
|
|
}
|
|
|
|
void SearchLineEdit::mouseMoveEvent(QMouseEvent* event)
|
|
{
|
|
setCursor(Qt::ArrowCursor);
|
|
}
|
|
|
|
|
|
|
|
TimeList::TimeList(QWidget* parent)
|
|
{
|
|
this->setMouseTracking(true);
|
|
this->setAttribute(Qt::WA_StyledBackground);
|
|
|
|
m_Font = this->font();
|
|
}
|
|
|
|
TimeList::~TimeList()
|
|
{
|
|
if (m_cal)
|
|
{
|
|
delete m_cal;
|
|
m_cal = nullptr;
|
|
}
|
|
if (m_result_List)
|
|
{
|
|
delete m_result_List;
|
|
m_result_List = nullptr;
|
|
}
|
|
}
|
|
|
|
void TimeList::initwidget()
|
|
{
|
|
QString tabel_sheet = QString(
|
|
"QTableWidget{ color:black; \
|
|
background-color:rgb(85,85,85);\
|
|
selection-color:rgb(255, 255, 255); \
|
|
selection-background-color:rgb(100,149,237);\
|
|
border:0px;\
|
|
font: 8pt 'Microsoft YaHei' ;}"
|
|
"QHeaderView::section:horizontal{ /*设置标题(水平的)*/\
|
|
border: 1px solid rgb(178, 178, 178); /*白色间隔*/\
|
|
border - bottom: 0px;/*下边框不需要颜色*/\
|
|
color: rgb(244, 244, 244);\
|
|
background: transparent;\
|
|
padding - left: 2px;\
|
|
min - width:60px;}");
|
|
QString cal_sheet = QString(
|
|
"QWidget{background-color: rgb(70, 70, 70);}"
|
|
"alternate - background - color: rgb(50, 50, 50); "
|
|
"background - color: rgb(52, 52, 52);"
|
|
"selection - background - color: rgb(191, 191, 191); "
|
|
);
|
|
|
|
// 初始化控件
|
|
m_cal = new QCalendarWidget(this);
|
|
m_cal->setFont(m_Font);
|
|
m_cal->setSelectionMode(QCalendarWidget::SingleSelection);//单选
|
|
m_cal->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);//隐藏周数
|
|
m_cal->setStyleSheet(cal_sheet);
|
|
|
|
|
|
m_result_List = new QTableWidget(this);
|
|
|
|
|
|
m_result_List->verticalHeader()->setHidden(true);//取消行号
|
|
m_result_List->horizontalHeader()->setHighlightSections(false);//取消表头选中高亮
|
|
m_result_List->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//自适应表格宽度
|
|
m_result_List->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //隐藏垂直滚动条
|
|
m_result_List->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //隐藏水平滚动条
|
|
m_result_List->setSelectionBehavior(QAbstractItemView::SelectRows);//整行选中
|
|
m_result_List->setSelectionMode(QAbstractItemView::SingleSelection);//单选
|
|
m_result_List->setEditTriggers(QAbstractItemView::NoEditTriggers); //禁止编辑表格
|
|
|
|
// 设置控件布局
|
|
QHBoxLayout* mainWidgetLayout = new QHBoxLayout(this);
|
|
QWidget* mainWidget = new QWidget;
|
|
mainWidget->setMouseTracking(true);
|
|
mainWidgetLayout->addWidget(mainWidget);
|
|
mainWidgetLayout->setMargin(0);
|
|
|
|
QVBoxLayout* pvLayout = new QVBoxLayout();
|
|
pvLayout->addWidget(m_cal);
|
|
pvLayout->addWidget(m_result_List);
|
|
pvLayout->setStretchFactor(m_cal, 3);
|
|
pvLayout->setStretchFactor(m_result_List, 5);
|
|
pvLayout->setContentsMargins(7, 0, 7, 0);
|
|
|
|
mainWidget->setLayout(pvLayout);
|
|
|
|
////初始化表头
|
|
m_result_List->setColumnCount(4);
|
|
m_result_List->setRowCount(25);
|
|
QStringList header;
|
|
header << QString::fromUtf8("时间段") << QString::fromUtf8("良品数") << QString::fromUtf8("不良数") << QString::fromUtf8("良品率");
|
|
m_result_List->setHorizontalHeaderLabels(header); //设置水平表头
|
|
m_result_List->setStyleSheet(tabel_sheet);
|
|
DataChange();
|
|
|
|
// 信号处理
|
|
connect(m_cal, &QCalendarWidget::selectionChanged, this, &TimeList::DataChange);
|
|
connect(m_result_List, &QTableWidget::cellClicked, [this](int row, int col) {
|
|
if (row != time_Label) {
|
|
time_Label = row;
|
|
emit searchTimeList(m_datatime, time_Label);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
bool TimeList::GupListData(const QString csvpath) {
|
|
|
|
|
|
// 读取每日csv
|
|
QStringList lines; //配置信息列表
|
|
QFile configFile;
|
|
configFile.setFileName(csvpath);
|
|
if (configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
QTextStream stream_text(&configFile);
|
|
//可读取中文
|
|
stream_text.seek(0);
|
|
while (!stream_text.atEnd())
|
|
{
|
|
lines.push_back(stream_text.readLine());
|
|
}
|
|
|
|
}
|
|
else {
|
|
qDebug() << "read csv " << csvpath << " failed!" << endl;
|
|
return -1;
|
|
}
|
|
configFile.close();
|
|
|
|
if (lines.count() == 0)return 0;
|
|
|
|
/// csv读取
|
|
|
|
int ok = 0, ng = 0;
|
|
for (int i = 0; i < 24; i++) {
|
|
QString time = QString("%1H").arg(i, 2, 10, QLatin1Char('0'));
|
|
int index = lines.at(i + 1).indexOf(time);
|
|
if (index != -1) {
|
|
QStringList lp = lines.at(i + 1).split(",");
|
|
if (lp.size() == 4) {
|
|
QTableWidgetItem* item = new QTableWidgetItem(lp.at(0));
|
|
QTableWidgetItem* item0 = new QTableWidgetItem(lp.at(1));
|
|
QTableWidgetItem* item1 = new QTableWidgetItem(lp.at(2));
|
|
QTableWidgetItem* item2 = new QTableWidgetItem(lp.at(3) + ("%"));
|
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item2->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
QColor ptr = ok_color;
|
|
if (lp.at(3).toDouble() < OK_arg) {
|
|
ptr = ng_color;
|
|
}
|
|
item->setBackgroundColor(ptr);
|
|
item0->setBackgroundColor(ptr);
|
|
item1->setBackgroundColor(ptr);
|
|
item2->setBackgroundColor(ptr);
|
|
|
|
m_result_List->setItem(i, 0, item);
|
|
m_result_List->setItem(i, 1, item0);
|
|
m_result_List->setItem(i, 2, item1);
|
|
m_result_List->setItem(i, 3, item2);
|
|
|
|
|
|
ok += lp.at(1).toInt();
|
|
ng += lp.at(2).toInt();
|
|
|
|
}
|
|
else {
|
|
QTableWidgetItem* item = new QTableWidgetItem(time);
|
|
QTableWidgetItem* item0 = new QTableWidgetItem(QString::fromUtf8("数据被修改"));
|
|
QTableWidgetItem* item1 = new QTableWidgetItem(QString::number(0));
|
|
QTableWidgetItem* item2 = new QTableWidgetItem(QString::fromStdString("?").append("%"));
|
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item2->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
QColor ptr = ng_color;
|
|
item->setBackgroundColor(ptr);
|
|
item0->setBackgroundColor(ptr);
|
|
item1->setBackgroundColor(ptr);
|
|
item2->setBackgroundColor(ptr);
|
|
|
|
m_result_List->setItem(i, 0, item);
|
|
m_result_List->setItem(i, 1, item0);
|
|
m_result_List->setItem(i, 2, item1);
|
|
m_result_List->setItem(i, 3, item2);
|
|
|
|
}
|
|
|
|
}
|
|
else {
|
|
QTableWidgetItem* item = new QTableWidgetItem(time);
|
|
QTableWidgetItem* item0 = new QTableWidgetItem(QString::fromUtf8("数据被修改"));
|
|
QTableWidgetItem* item1 = new QTableWidgetItem(QString::number(0));
|
|
QTableWidgetItem* item2 = new QTableWidgetItem(QString::fromStdString("?").append("%"));
|
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item2->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
QColor ptr = ng_color;
|
|
item->setBackgroundColor(ptr);
|
|
item0->setBackgroundColor(ptr);
|
|
item1->setBackgroundColor(ptr);
|
|
item2->setBackgroundColor(ptr);
|
|
|
|
m_result_List->setItem(i, 0, item);
|
|
m_result_List->setItem(i, 1, item0);
|
|
m_result_List->setItem(i, 2, item1);
|
|
m_result_List->setItem(i, 3, item2);
|
|
|
|
}
|
|
|
|
}
|
|
QTableWidgetItem* item = new QTableWidgetItem(QString::fromUtf8("全天"));
|
|
QTableWidgetItem* item0 = new QTableWidgetItem(QString::number(ok));
|
|
QTableWidgetItem* item1 = new QTableWidgetItem(QString::number(ng));
|
|
QTableWidgetItem* item2 = new QTableWidgetItem(QString::number(double((float)ok / (ng + ok) * 100.00), 'f', 2).append("%"));
|
|
item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item0->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item1->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
item2->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
QColor ptr = ok_color;
|
|
if (((float)ok / (ng + ok)) * 100.00 < OK_arg) {
|
|
ptr = ng_color;
|
|
}
|
|
item->setBackgroundColor(ptr);
|
|
item0->setBackgroundColor(ptr);
|
|
item1->setBackgroundColor(ptr);
|
|
item2->setBackgroundColor(ptr);
|
|
|
|
m_result_List->setItem(24, 0, item);
|
|
m_result_List->setItem(24, 1, item0);
|
|
m_result_List->setItem(24, 2, item1);
|
|
m_result_List->setItem(24, 3, item2);
|
|
|
|
|
|
qApp->processEvents();
|
|
return 1;
|
|
}
|
|
|
|
|
|
void TimeList::DataChange()
|
|
{
|
|
time_Label = -1;
|
|
m_result_List->setFocus();
|
|
// 清空产品列表
|
|
emit changeData();
|
|
|
|
emit waitSearch();
|
|
m_result_List->clearContents();//清理列表
|
|
|
|
qApp->processEvents();
|
|
|
|
m_datatime = m_cal->selectedDate().toString("yyyy-MM-dd");
|
|
QString csvpath = QString("%1/%2/statics_%3.csv").arg(currPath, DataSheetpath, m_datatime);
|
|
if (isFileExist(csvpath)) {
|
|
GupListData(csvpath);//查询汇总文件
|
|
}
|
|
else {
|
|
qDebug() << " " << csvpath << " failed!" << endl;
|
|
csvpath = QString("%1/%2/statics_default.csv").arg(currPath, DataSheetpath);
|
|
if (isFileExist(csvpath)) {
|
|
GupListData(csvpath);//默认空,查询汇总文件
|
|
}
|
|
}
|
|
|
|
QThread::msleep(1000);
|
|
emit waitSearch(false);
|
|
qApp->processEvents();
|
|
|
|
|
|
}
|
|
|
|
|
|
void TimeList::mouseMoveEvent(QMouseEvent* event)
|
|
{
|
|
setCursor(Qt::ArrowCursor);
|
|
}
|
|
|
|
|
|
RightWindow::RightWindow(QWidget* parent) : QTabWidget(parent)
|
|
{
|
|
|
|
setMouseTracking(true);
|
|
this->setAttribute(Qt::WA_StyledBackground);
|
|
this->tabBar()->setStyleSheet("QTabBar::tab{border:none;background-color:rgb(50,50,50);color:rgb(188, 188, 188);font:15px 'Microsoft YaHei'; min-width:97px ;min-height:26px;}"
|
|
"QTabBar::tab:hover{background-color:rgb(50,50,50);color:rgb(255, 255, 255);font:16px 'Microsoft YaHei'}"
|
|
"QTabBar::tab:selected{background-color:rgb(218,102,53);color:rgb(255, 255, 255);font:16px 'Microsoft YaHei'}");
|
|
this->setDocumentMode(true);
|
|
|
|
initwidget();
|
|
}
|
|
|
|
RightWindow::~RightWindow()
|
|
{
|
|
if (m_param) {
|
|
delete m_param;
|
|
m_param = nullptr;
|
|
}
|
|
|
|
|
|
|
|
if (m_statist) {
|
|
delete m_statist;
|
|
m_statist = nullptr;
|
|
}
|
|
}
|
|
|
|
void RightWindow::initwidget()
|
|
{
|
|
m_param = new MyParamSet;
|
|
m_statist = new TimeList;
|
|
|
|
addTab(m_param, QString::fromUtf8("参数设置"));
|
|
addTab(m_statist, QString::fromUtf8("统计报表"));
|
|
connect(this, &RightWindow::Loadparam, m_param, &MyParamSet::UpParData);
|
|
connect(this, &RightWindow::Saveparam, m_param, &MyParamSet::SaveParData);
|
|
}
|