You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
470 lines
14 KiB
C++
470 lines
14 KiB
C++
#include "qcheckdatadlg.h"
|
|
#include "qstandarditemmodel.h"
|
|
#include "qmessagebox.h"
|
|
#include "qfontmetrics.h"
|
|
#include <QDir>
|
|
#include <QSettings>
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
QCheckDataDlg::QCheckDataDlg(QWidget *parent)
|
|
: QDialog(parent), m_db(NULL), nPrevNum(0), nTotlaNumber(0)
|
|
{
|
|
ui.setupUi(this);
|
|
|
|
QString m_AppPath = QApplication::applicationDirPath();
|
|
QString m_CfgPath = m_AppPath + QString("//user//systemConfig.ini");
|
|
QSettings setting(m_CfgPath, QSettings::IniFormat);
|
|
QString m_CurLanguage = setting.value("language/select", "Chinese").toString();
|
|
SetLanguage(m_CurLanguage);
|
|
|
|
m_ViewImg = new QTpGraphView;
|
|
connect(ui.m_pbCheck, SIGNAL(clicked()), this, SLOT(onCheckOutData()));
|
|
connect(ui.Prev_checkShengchang, SIGNAL(clicked()), this, SLOT(onChenckButton()));
|
|
connect(ui.Next_checkShengchang, SIGNAL(clicked()), this, SLOT(onChenckButton()));
|
|
connect(ui.m_pbCount, SIGNAL(clicked()), this, SLOT(onChenckButton()));
|
|
setWindowIcon(QIcon(":/leaper/app.png"));
|
|
pShowName_label = ui.check_fileName;
|
|
pShowName_label->clear();
|
|
|
|
check_showImg_label = ui.check_showImg_label;
|
|
check_showImg_label->clear();
|
|
QGridLayout *pGrid = new QGridLayout(this);
|
|
pGrid->addWidget(m_ViewImg);
|
|
check_showImg_label->setLayout(pGrid);
|
|
|
|
m_tableModel = new QStandardItemModel;
|
|
tableView = ui.tableView;
|
|
connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTBUI_ItemClick(const QModelIndex &)));
|
|
tableView->setModel(m_tableModel);
|
|
textBrowser = ui.textBrowser;
|
|
|
|
pStartTimeEdit = ui.dateTimeEdit_start;
|
|
pEndTimeEdit = ui.dateTimeEdit_end;
|
|
QDateTime nDateTime = QDateTime::currentDateTime();
|
|
nDateTime.setTime(QTime(0, 0, 0));
|
|
pStartTimeEdit->setDateTime(nDateTime);
|
|
pEndTimeEdit->setDateTime(QDateTime::currentDateTime());
|
|
Qt::WindowFlags flags = Qt::Dialog;
|
|
flags |= Qt::WindowMinMaxButtonsHint;
|
|
flags |= Qt::WindowCloseButtonHint;
|
|
setWindowFlags(flags);
|
|
setPageShow(0, 0);
|
|
}
|
|
|
|
QCheckDataDlg::~QCheckDataDlg()
|
|
{
|
|
if (m_tableModel)
|
|
{
|
|
delete m_tableModel;
|
|
m_tableModel = NULL;
|
|
}
|
|
if (m_ViewImg){
|
|
delete m_ViewImg;
|
|
m_ViewImg = NULL;
|
|
}
|
|
}
|
|
|
|
void QCheckDataDlg::createHeader()
|
|
{
|
|
QStringList listStr;
|
|
listStr.append(QObject::tr("时间"));
|
|
listStr.append(QObject::tr("型号"));
|
|
listStr.append(QObject::tr("matchScore"));
|
|
listStr.append(QObject::tr("BenchMark"));
|
|
listStr.append(QObject::tr("Angle"));
|
|
listStr.append(QObject::tr("errorType"));
|
|
listStr.append(QObject::tr("resultTip"));
|
|
listStr.append(QObject::tr("工位"));
|
|
m_tableModel->setHorizontalHeaderLabels(listStr);
|
|
}
|
|
|
|
void QCheckDataDlg::updateModelShowLog(QSqlQuery &sql)
|
|
{
|
|
m_tableModel->clear();
|
|
m_strMap.clear();
|
|
createHeader();
|
|
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);//自适应行宽
|
|
int nIndex = 0;
|
|
while (sql.next())
|
|
{
|
|
/*这里下面是统计查询到的通道对应的产品总数*/
|
|
QString time = sql.value("time").toString();
|
|
QString dAngle = sql.value("dAngle").toString();
|
|
QString matchScore = sql.value("matchScore").toString().left(5);
|
|
QString errorType = sql.value("errorType").toString();
|
|
QString resultTip = sql.value("resultTip").toString();
|
|
QString threshBenchMark = sql.value("threshBenchMark").toString();
|
|
QString stationName = sql.value("stationName").toString();
|
|
QString strFilename = sql.value("value1").toString();//取出保存图片的路径名
|
|
//QByteArray picByte = sql.value("image").toByteArray();
|
|
QString strModelName = sql.value("value2").toString();
|
|
//QImage img = QImage::fromData(picByte);
|
|
|
|
m_tableModel->setItem(nIndex, 0, new QStandardItem(time));
|
|
m_tableModel->setItem(nIndex, 1, new QStandardItem(strModelName));
|
|
m_tableModel->setItem(nIndex, 2, new QStandardItem(matchScore));
|
|
m_tableModel->setItem(nIndex, 3, new QStandardItem(threshBenchMark));
|
|
m_tableModel->setItem(nIndex, 4, new QStandardItem(dAngle));
|
|
m_tableModel->setItem(nIndex, 5, new QStandardItem(errorType));
|
|
m_tableModel->setItem(nIndex, 6, new QStandardItem(resultTip));
|
|
m_tableModel->setItem(nIndex, 7, new QStandardItem(stationName));
|
|
m_strMap.insert(time, strFilename);
|
|
pShowName_label->setText(strFilename);
|
|
nIndex++;
|
|
}
|
|
|
|
ui.showNum_Label_Checkdata->setText(QString(QObject::tr("共显示%1条记录")).arg(nIndex));
|
|
tableView->setModel(m_tableModel);
|
|
|
|
int page = nPrevNum / getLimitNumber();
|
|
int totalPage = nTotlaNumber / getLimitNumber();
|
|
setPageShow(page+1, totalPage+1);
|
|
}
|
|
|
|
int QCheckDataDlg::getLimitNumber()
|
|
{
|
|
int num = ui.LineNumber_checkShengchang->text().toInt();
|
|
if (num > 1)
|
|
return num;
|
|
else
|
|
{
|
|
ui.LineNumber_checkShengchang->setText("50");
|
|
return 50;
|
|
}
|
|
|
|
}
|
|
int QCheckDataDlg::getTotalNumber()
|
|
{
|
|
QString startTime = pStartTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz");
|
|
QString endTime = pEndTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz");
|
|
QString stationName = getStationName();
|
|
int errorType = getErrorType();
|
|
QString strSql = QString();
|
|
if (stationName == QObject::tr("全部")&&errorType == 0)
|
|
strSql = QString("select count(uid) from RltTable where time >'%1' and time <'%2' ").arg(startTime).arg(endTime);
|
|
else if (stationName == QObject::tr("全部") && errorType == 1)
|
|
strSql = QString("select count(uid) from RltTable where time >'%1' and time <'%2' and errorType != '%3'").arg(startTime).arg(endTime).arg(0);
|
|
else if (stationName != QObject::tr("全部") && errorType == 1)
|
|
strSql = QString("select count(uid) from RltTable where time >'%1' and time <'%2' and errorType != '%3' and stationName == '%4' ").arg(startTime).arg(endTime).arg(0).arg(stationName);
|
|
else
|
|
strSql = QString("select count(uid) from RltTable where time >'%1' and time <'%2' and stationName == '%3'").arg(startTime).arg(endTime).arg(stationName);
|
|
|
|
QSqlQuery sqlquery;
|
|
m_db->checkoutData(strSql, sqlquery);
|
|
int totalNumber =0;
|
|
while (sqlquery.next())
|
|
{
|
|
QSqlRecord record = sqlquery.record();
|
|
QString fieldName = record.fieldName(0);
|
|
QString num = sqlquery.value(0).toString();
|
|
totalNumber = num.toInt();
|
|
// /*这里下面是统计查询到的通道对应的产品总数*/
|
|
}
|
|
return totalNumber;
|
|
}
|
|
Q_SLOT void QCheckDataDlg::onCheckOutData()
|
|
{
|
|
nTotlaNumber = 0;
|
|
nPrevNum = 0;
|
|
int limitNum = getLimitNumber();
|
|
nTotlaNumber = getTotalNumber();
|
|
|
|
onCheckOutData(limitNum, nPrevNum);
|
|
}
|
|
|
|
void QCheckDataDlg::onCheckOutData(int nLimitNum, int nPrenum)
|
|
{
|
|
QString startTime = pStartTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz");
|
|
QString endTime = pEndTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz");
|
|
QString stationName = getStationName();
|
|
int errorType = getErrorType();
|
|
QString strSql = QString();
|
|
if (stationName == QObject::tr("全部")&&errorType == 0)
|
|
strSql=QString("select * from RltTable where time >'%1' and time <'%2' LIMIT %3 OFFSET %4 ").arg(startTime).arg(endTime).arg(nLimitNum).arg(nPrenum);
|
|
else if (stationName == QObject::tr("全部") && errorType == 1)
|
|
strSql = QString("select * from RltTable where time >'%1' and time <'%2' and errorType != '%3' LIMIT %4 OFFSET %5 ").arg(startTime).arg(endTime).arg(0).arg(nLimitNum).arg(nPrenum);
|
|
else if (stationName != QObject::tr("全部") && errorType == 1)
|
|
strSql = QString("select * from RltTable where time >'%1' and time <'%2' and errorType != '%3' and stationName == '%4' LIMIT %5 OFFSET %6 ").arg(startTime).arg(endTime).arg(0).arg(stationName).arg(nLimitNum).arg(nPrenum);
|
|
else
|
|
strSql = QString("select * from RltTable where time >'%1' and time <'%2' and stationName == '%3' LIMIT %4 OFFSET %5 ").arg(startTime).arg(endTime).arg(stationName).arg(nLimitNum).arg(nPrenum);
|
|
QSqlQuery sqlquery;
|
|
m_db->checkoutData(strSql, sqlquery);
|
|
updateModelShowLog(sqlquery);
|
|
}
|
|
|
|
Q_SLOT void QCheckDataDlg::onChenckButton()
|
|
{
|
|
QString strObjName = sender()->objectName();
|
|
if (strObjName == "Next_checkShengchang")
|
|
{
|
|
if (nTotlaNumber <= 0)
|
|
return;
|
|
if (nPrevNum > nTotlaNumber)
|
|
return;
|
|
nPrevNum += getLimitNumber();
|
|
if (nPrevNum > nTotlaNumber)
|
|
{
|
|
nPrevNum -= getLimitNumber();
|
|
QMessageBox infobox(QMessageBox::Information, QObject::tr("提醒"), QObject::tr("已经是最后一页了"), QMessageBox::Ok, NULL);
|
|
infobox.setWindowIcon(QIcon(":/leaper/app.png"));
|
|
infobox.setButtonText(QMessageBox::Ok, QString(QObject::tr("确认")));
|
|
infobox.exec();
|
|
return;
|
|
}
|
|
onCheckOutData(getLimitNumber(), nPrevNum);
|
|
}
|
|
else if (strObjName == "Prev_checkShengchang")
|
|
{
|
|
if (nTotlaNumber <= 0)
|
|
return;
|
|
if (nPrevNum < 0)
|
|
return;
|
|
nPrevNum -= getLimitNumber();
|
|
if (nPrevNum < 0)
|
|
{
|
|
nPrevNum = 0;
|
|
QMessageBox infobox(QMessageBox::Information, QObject::tr("提醒"), QObject::tr("已经是第一页了"), QMessageBox::Ok, NULL);
|
|
infobox.setWindowIcon(QIcon(":/leaper/app.png"));
|
|
infobox.setButtonText(QMessageBox::Ok, QString(QObject::tr("确认")));
|
|
infobox.exec();
|
|
return;
|
|
}
|
|
onCheckOutData(getLimitNumber(), nPrevNum);
|
|
}
|
|
else if (strObjName == "m_pbCount")
|
|
{
|
|
QString startTime = pStartTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz");
|
|
QString endTime = pEndTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz");
|
|
QString stationName = getStationName();
|
|
QString strSql = QString();
|
|
if (stationName == QObject::tr("全部"))
|
|
strSql = QString("select errorType,count(uid) from RltTable where time >'%1' and time <'%2' group by errorType order by errorType").arg(startTime).arg(endTime);
|
|
else
|
|
strSql = QString("select errorType,count(uid) from RltTable where time >'%1' and time <'%2' and stationName == '%3' group by errorType order by errorType").arg(startTime).arg(endTime).arg(stationName);
|
|
|
|
QSqlQuery sqlquery;
|
|
m_db->checkoutData(strSql, sqlquery);
|
|
QMap<QString, int> nCountMap;
|
|
|
|
while (sqlquery.next())
|
|
{
|
|
QSqlRecord record = sqlquery.record();
|
|
QString fieldName = record.fieldName(0);
|
|
QString nType = sqlquery.value(0).toString();
|
|
int count = sqlquery.value(1).toInt();
|
|
nCountMap.insert(nType, count);
|
|
}
|
|
int TotalNumber = 0;
|
|
int ErrorNumber = 0;
|
|
textBrowser->clear();
|
|
for (QMap<QString, int>::iterator its = nCountMap.begin(); its != nCountMap.end();++its)
|
|
{
|
|
QString strKey = its.key();
|
|
int nValue = nCountMap.value(strKey);
|
|
QString str;
|
|
if (strKey != "0")
|
|
str = QString("errorType:%1 Sum:%2;").arg(strKey).arg(nValue);
|
|
else
|
|
str = QString("goodType Sum:%2;").arg(nValue);
|
|
TotalNumber += nValue;
|
|
if (strKey != "0")
|
|
{
|
|
ErrorNumber += nValue;
|
|
}
|
|
textBrowser->append(str);
|
|
}
|
|
QString strEnd = QString("ErrorNumber:%1\nTotalNumber:%2").arg(ErrorNumber).arg(TotalNumber);
|
|
textBrowser->append(strEnd);
|
|
}
|
|
}
|
|
|
|
void QCheckDataDlg::setStationNames(QStringList listNames)
|
|
{
|
|
ui.comboBox_station->addItems(listNames);
|
|
}
|
|
|
|
QString QCheckDataDlg::getStationName()
|
|
{
|
|
return ui.comboBox_station->currentText();
|
|
}
|
|
|
|
int QCheckDataDlg::getErrorType()
|
|
{
|
|
QString str = ui.comboBox_errorType->currentText();
|
|
if (str == QObject::tr("全部"))
|
|
return 0;
|
|
else
|
|
return 1;
|
|
}
|
|
|
|
void QCheckDataDlg::setPageShow(int page,int totalPage)
|
|
{
|
|
QString str = QString(QObject::tr("第%1页 共%2页")).arg(page).arg(totalPage);
|
|
ui.showPage_Label_Checkdata->setText(str);
|
|
}
|
|
|
|
void QCheckDataDlg::changeEvent(QEvent *event)
|
|
{
|
|
if (event->type() == QEvent::LanguageChange)
|
|
{
|
|
ui.retranslateUi(this);
|
|
}
|
|
}
|
|
|
|
Q_SLOT void QCheckDataDlg::onTBUI_ItemClick(const QModelIndex & index)
|
|
{
|
|
QModelIndex nindex = m_tableModel->index(index.row(), 0);
|
|
QString str = nindex.data().toString();
|
|
if (m_strMap.size() > 0)
|
|
{
|
|
QString strFileName = m_strMap.value(str);
|
|
|
|
if (check_showImg_label)
|
|
{
|
|
QPixmap npixmap;
|
|
QString appPath = QApplication::applicationDirPath();
|
|
npixmap.load(strFileName);
|
|
m_ViewImg->setImg(npixmap);
|
|
if (!npixmap.isNull()){
|
|
if (pShowName_label)
|
|
{
|
|
QFontMetrics fontMetrics(this->font());
|
|
int fontSize = fontMetrics.width(strFileName);
|
|
QString str = strFileName;
|
|
if (fontSize > pShowName_label->width())
|
|
{
|
|
str = fontMetrics.elidedText(strFileName, Qt::ElideRight, pShowName_label->width());
|
|
}
|
|
pShowName_label->setText(str);
|
|
}
|
|
}
|
|
else{
|
|
if (pShowName_label){
|
|
pShowName_label->setText(QObject::tr("无图片(或图片已过期/已被删除)"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Q_SLOT void QCheckDataDlg::onSlowPixmap(QSqlQuery sql)
|
|
{
|
|
static bool nFlag = false;
|
|
if (nFlag == true)
|
|
return;
|
|
nFlag = true;
|
|
|
|
sql.next();
|
|
double dHight = sql.value("hight").toDouble();
|
|
QByteArray pic = sql.value("pic").toByteArray();
|
|
QImage img = QImage::fromData(pic);
|
|
QSize s = img.size();
|
|
QPixmap m_Pix = QPixmap::fromImage(img);
|
|
|
|
{
|
|
int dhight = m_Pix.height();
|
|
int dwidth = m_Pix.width();
|
|
double nRate = m_Pix.width()*1.0 / m_Pix.height();
|
|
int scarew = 150;
|
|
int scareh = 150 * 1.0 / nRate;
|
|
|
|
if (scareh > 150)
|
|
{
|
|
scarew = 150;
|
|
scareh = 150 * 1.0 / nRate;
|
|
}
|
|
|
|
if (check_showImg_label)
|
|
{
|
|
m_ViewImg->setImg(m_Pix);
|
|
}
|
|
}
|
|
//label_6->setPixmap(m_Pix.scaled(WHEEL_PIC_SIZE, WHEEL_PIC_SIZE));
|
|
nFlag = false;
|
|
}
|
|
|
|
//======系统翻译相关
|
|
void QCheckDataDlg::SearchQmFile(const QString & strDir)
|
|
{
|
|
QDir dir(strDir);
|
|
if (!dir.exists())
|
|
{
|
|
return;
|
|
}
|
|
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
|
dir.setSorting(QDir::DirsFirst); // 文件夹优先
|
|
// 转换成一个List
|
|
QFileInfoList list = dir.entryInfoList();
|
|
if (list.size() < 1)
|
|
{
|
|
return;
|
|
}
|
|
int i = 0;
|
|
do
|
|
{
|
|
QFileInfo fileInfo = list.at(i);
|
|
QString tt = fileInfo.fileName();
|
|
// 如果是文件夹
|
|
bool bisDir = fileInfo.isDir();
|
|
if (bisDir)
|
|
{
|
|
SearchQmFile(fileInfo.filePath());
|
|
}
|
|
else
|
|
{
|
|
bool bQm = fileInfo.fileName().endsWith(".qm");
|
|
SetTranslator(fileInfo.filePath());
|
|
}
|
|
i++;
|
|
} while (i < list.size());
|
|
}
|
|
void QCheckDataDlg::rmTranslator()
|
|
{
|
|
if (m_VecTranPtr.size() > 0)
|
|
{
|
|
while (m_VecTranPtr.size())
|
|
{
|
|
QTranslator *pVa = m_VecTranPtr.takeFirst();
|
|
qApp->removeTranslator(pVa);
|
|
delete pVa;
|
|
pVa = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
void QCheckDataDlg::SetLanguage(QString strLangage)
|
|
{
|
|
QString strDirPath = QString(QCoreApplication::applicationDirPath() + "/language/");
|
|
QString translatorFileName = strLangage;
|
|
if (!translatorFileName.isEmpty())
|
|
{
|
|
rmTranslator();
|
|
QLocale::setDefault(QLocale(translatorFileName));
|
|
|
|
QString transDir = strDirPath + translatorFileName;
|
|
SearchQmFile(transDir);
|
|
}
|
|
}
|
|
|
|
void QCheckDataDlg::SetTranslator(const QString strPath)
|
|
{
|
|
if (strPath.isEmpty())
|
|
{
|
|
return;
|
|
}
|
|
QTranslator *pTrans = new QTranslator;
|
|
if (pTrans->load(strPath)) // 如果加载成功
|
|
{
|
|
qApp->installTranslator(pTrans);
|
|
m_VecTranPtr.append(pTrans);
|
|
}
|
|
else
|
|
{
|
|
delete pTrans;
|
|
pTrans = NULL;
|
|
}
|
|
}
|