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.

195 lines
4.5 KiB
C++

5 years ago
#include "lpReport.h"
#include "qtimedlg.h"
#include <QSqlQuery>
#include <QFileDialog>
#include <QTextStream>
#include "QProgressDialog"
#include "qsavecsvthread.h"
#include "checkthread.h"
#include "QCompleter"
#include "qreportwidget.h"
#include <QDebug>
#include "ModelDB.h"
#pragma execution_character_set("utf-8")
#define _QSQLITE_WHEELHUBWF_NAME "wheelhubwf.db"
#define WHEEL_DB_FILE "\\pattern\\modelTemplate.db"
5 years ago
lpReport::lpReport(QWidget *parent)
: QMainWindow(parent)
{
//加载语言设置
QSettings languageSetting("hubdetect.ini", QSettings::IniFormat);
QString strLanguage = languageSetting.value("language", "Chinese").toString();
SetLanguage(strLanguage);
qRegisterMetaType<QSqlQuery>("QSqlQuery");
ui.setupUi(this);
//历史数据初始化
5 years ago
QString strDbPath = QApplication::applicationDirPath() + "\\" + _QSQLITE_WHEELHUBWF_NAME;
m_pDb = new DetectDataDB(strDbPath);
m_pDb->InitDatabase();
m_pDb->ReadOutTimeData(m_Totaltime);
//模板型号列表数据库初始化 获取所有的型号列表
5 years ago
QString strModelPath = QApplication::applicationDirPath() + "\\" + WHEEL_DB_FILE;
m_pModeDB = new ModelDB(strModelPath);
m_pModeDB->InitDatabase();
m_strListModelName = m_pModeDB->ReadAllModes();
5 years ago
setWindowTitle(tr("数据记录查看"));
setWindowIcon(QIcon(":/lpReport/Resources/Log.png"));
int nItenCount = ui.check_listWidget->count();
for (int nIndex = 0; nIndex < nItenCount; nIndex++)
{
QListWidgetItem *itenn = ui.check_listWidget->item(nIndex);
QSize s = itenn->sizeHint();
itenn->setSizeHint(QSize(s.width(), 45));
}
connect(ui.check_listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(onSetCurrentIndex(int)));
connect(this, SIGNAL(sgSetCurrentIndex(int)), ui.stackedWidget, SLOT(setCurrentIndex(int)));
m_pModeCheckUI = new ModeCheckDlg();
m_pModeCountUI = new ModeCountDlg();
m_pValueUI = new ValueCheckDlg();
ui.stackedWidget->insertWidget(0, m_pModeCheckUI);
ui.stackedWidget->insertWidget(1, m_pModeCountUI);
ui.stackedWidget->insertWidget(2, m_pValueUI);
5 years ago
if (m_pModeCheckUI)
5 years ago
{
m_pModeCheckUI->setDBPtr(m_pDb);
m_pModeCheckUI->initParam(m_Totaltime, m_strListModelName);
5 years ago
}
if (m_pModeCountUI)
5 years ago
{
m_pModeCountUI->setDBPtr(m_pDb);
m_pModeCountUI->initParam(m_Totaltime, m_strListModelName);
5 years ago
}
if (m_pValueUI)
5 years ago
{
m_pValueUI->setDBPtr(m_pDb);
m_pValueUI->initParam(m_Totaltime, m_strListModelName);
5 years ago
}
}
lpReport::~lpReport()
5 years ago
{
if (m_pModeCheckUI)
5 years ago
{
delete m_pModeCheckUI;
m_pModeCheckUI = nullptr;
5 years ago
}
if (m_pModeCountUI)
5 years ago
{
delete m_pModeCountUI;
m_pModeCountUI = nullptr;
5 years ago
}
if (m_pValueUI)
5 years ago
{
delete m_pValueUI;
m_pValueUI = nullptr;
5 years ago
}
if (m_pModeDB)
5 years ago
{
delete m_pModeDB;
m_pModeDB = nullptr;
5 years ago
}
if (m_pDb)
5 years ago
{
delete m_pDb;
m_pDb = nullptr;
5 years ago
}
}
void lpReport::timerEvent(QTimerEvent *event)
5 years ago
{
}
Q_SLOT void lpReport::onSetCurrentIndex(int nIndex)
{
ui.label_Title->setText(ui.check_listWidget->item(nIndex)->data(0).toString());
emit(sgSetCurrentIndex(nIndex));
}
void lpReport::SetLanguage(QString strLanguage)
{
QString strDirPath = QString(QCoreApplication::applicationDirPath() + "/language/");
QString translatorFileName = strLanguage;
if (!translatorFileName.isEmpty())
{
if (m_VecTranPtr.size() > 0)
{
while (m_VecTranPtr.size())
{
QTranslator *pVa = m_VecTranPtr.takeFirst();
qApp->removeTranslator(pVa);
delete pVa;
pVa = NULL;
}
}
//if (strLangage == "Chinese")
// return;
QLocale::setDefault(QLocale(translatorFileName));
QString transDir = strDirPath + translatorFileName;
SearchQmFile(transDir);
}
}
void lpReport::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 lpReport::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;
}
}