358 lines
11 KiB
C++
358 lines
11 KiB
C++
#include "MainWindow.h"
|
|
#include "ui_MainWindow.h"
|
|
#include <QDebug>
|
|
#include <QMessageBox>
|
|
#include <tsdb_api/CTsdbConn.h>
|
|
#include <tsdb_api/TsdbApi.h>
|
|
#include "dataWorker.h"
|
|
#include "db_his_query_api/DbHisQueryApi.h"
|
|
|
|
#include <QThreadPool>
|
|
using namespace iot_dbms;
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
dataWorker *worker = new dataWorker;
|
|
worker->moveToThread(&workerThread);
|
|
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
|
|
|
|
connect(this, &MainWindow::operate, worker, &dataWorker::doWork);
|
|
connect(worker, &dataWorker::resultReady, this, &MainWindow::handleResults);
|
|
|
|
connect(this, &MainWindow::startTest, worker, &dataWorker::doTest);
|
|
connect(worker, &dataWorker::testResultReady, this, &MainWindow::handleTestResults);
|
|
|
|
connect(this, &MainWindow::insertEvent, worker, &dataWorker::doInsertEvent);
|
|
connect(worker, &dataWorker::InsertEventResultReady, this, &MainWindow::handleEventInsertResults);
|
|
|
|
|
|
connect(this, &MainWindow::deleteWork, worker, &dataWorker::doDel);
|
|
connect(worker, &dataWorker::deleteResultReady, this, &MainWindow::handleDeleteResults);
|
|
|
|
connect(worker, &dataWorker::onErrMsg, this, &MainWindow::onErrMsg);
|
|
connect(worker, &dataWorker::onStatus, this, &MainWindow::onStatus);
|
|
connect(worker, &dataWorker::onTestStatus, this, &MainWindow::onTestStatus);
|
|
connect(worker, &dataWorker::onAddTestRow, this, &MainWindow::onAddTestRow);
|
|
|
|
|
|
|
|
|
|
workerThread.start();
|
|
ui->label_status->setHidden(true);
|
|
|
|
auto date = ui->calendarWidget_startDate->selectedDate();
|
|
date.setDate(date.addYears(-3).year(),date.month(),date.day());
|
|
ui->calendarWidget_startDate->setSelectedDate(date);
|
|
|
|
date = ui->calendarWidget_test->selectedDate();
|
|
date.setDate(date.addYears(-2).year(),date.month(),date.day());
|
|
ui->calendarWidget_test->setSelectedDate(date);
|
|
|
|
// QThreadPool::globalInstance()->setMaxThreadCount(10);
|
|
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
workerThread.quit();
|
|
workerThread.wait();
|
|
|
|
delete ui;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString MainWindow::getPointType()
|
|
{
|
|
if( ui->comboBox_type->currentText() == tr("模拟量")){
|
|
return QString("ai_sample_result");
|
|
}else if( ui->comboBox_type->currentText() == tr("累积量")){
|
|
return QString("acc_sample_result");
|
|
}else if( ui->comboBox_type->currentText() == tr("混合量")){
|
|
return QString("mix_sample_result");
|
|
}else if( ui->comboBox_type->currentText() == tr("数字量")){
|
|
return QString("di_sample_result");
|
|
}else
|
|
return "";
|
|
}
|
|
|
|
int MainWindow::getDeviatType()
|
|
{
|
|
if (ui->comboBox_deviatType->currentText() == tr("左边")){
|
|
return -1;
|
|
}else if (ui->comboBox_deviatType->currentText() == tr("两边")){
|
|
return 0;
|
|
}else {
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_insert_clicked()
|
|
{
|
|
if(QMessageBox::question(this,"提醒","是否插入") != QMessageBox::Yes)
|
|
{
|
|
return;
|
|
}
|
|
|
|
QString address = ui->lineEdit_addr->text();
|
|
QStringList listPoint = ui->plainTextEdit_point->toPlainText().simplified().split(',');
|
|
listPoint.removeAll("");
|
|
for(int i = 0; i < listPoint.size(); i++)
|
|
{
|
|
listPoint[i] = listPoint[i].trimmed();
|
|
}
|
|
QString pointType = getPointType();
|
|
quint64 interval = ui->spinBox_interval->value() * 1000; //ms
|
|
int deviatProb = ui->spinBox_deviatProb->value();
|
|
double normalBase = ui->doubleSpinBox_base->value();
|
|
double normalLength = ui->doubleSpinBox_length->value();
|
|
quint64 starttime = QDateTime(ui->calendarWidget_startDate->selectedDate(),ui->timeEdit_start->time()).toMSecsSinceEpoch();
|
|
quint64 endtime = QDateTime(ui->calendarWidget_endDate->selectedDate(),ui->timeEdit_end->time()).toMSecsSinceEpoch(); // 结束日期加一天
|
|
int deviatType = getDeviatType();
|
|
|
|
bool isDeleteInterval = ui->checkBox_delete->isChecked();
|
|
bool isDeleteAll = ui->checkBox_delAll->isChecked();
|
|
bool isMT = ui->checkBox_mt->isChecked();
|
|
emit operate(listPoint,address,pointType,interval,deviatProb,normalBase,normalLength,starttime,endtime,deviatType,isDeleteInterval,isDeleteAll,isMT);
|
|
ui->pushButton_insert->setEnabled(false);
|
|
ui->pushButton_delete->setEnabled(false);
|
|
ui->label_status->setHidden(false);
|
|
}
|
|
|
|
void MainWindow::onErrMsg(const QString &msg)
|
|
{
|
|
QMessageBox::critical(this,"提醒",msg);
|
|
}
|
|
|
|
void MainWindow::onStatus(const QString &msg)
|
|
{
|
|
ui->label_status->setText(msg);
|
|
}
|
|
|
|
void MainWindow::onTestStatus(const QString &msg)
|
|
{
|
|
ui->plainTextEdit_test_result->appendPlainText(msg);
|
|
}
|
|
|
|
void MainWindow::onAddTestRow(const QStringList &newRow)
|
|
{
|
|
ui->tableWidget->insertRow(ui->tableWidget->rowCount());
|
|
QString newLine;
|
|
for(int i = 0; i < newRow.size(); i++)
|
|
{
|
|
ui->tableWidget->setItem(ui->tableWidget->rowCount()-1, i, new QTableWidgetItem(newRow.at(i)));
|
|
newLine += newRow.at(i) + ",";
|
|
}
|
|
newLine.chop(1);
|
|
ui->plainTextEdit_test_result->appendPlainText(newLine);
|
|
ui->tableWidget->resizeColumnsToContents();
|
|
}
|
|
|
|
void MainWindow::on_comboBox_type_currentTextChanged(const QString &arg1)
|
|
{
|
|
if("数字量" == arg1)
|
|
{
|
|
ui->groupBox->setHidden(true);
|
|
}
|
|
else
|
|
{
|
|
ui->groupBox->setHidden(false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::handleResults(const QString &msg, bool result) {
|
|
ui->label_status->setHidden(true);
|
|
|
|
if(result)
|
|
{
|
|
QMessageBox::information(this,"提醒","插入成功");
|
|
}
|
|
else
|
|
{
|
|
onErrMsg(QString("插入失败:") + msg);
|
|
}
|
|
ui->pushButton_insert->setEnabled(true);
|
|
ui->pushButton_delete->setEnabled(true);
|
|
|
|
}
|
|
|
|
void MainWindow::handleTestResults(const QString &msg, bool result)
|
|
{
|
|
if(result)
|
|
{
|
|
QMessageBox::information(this,"提醒","测试结束");
|
|
}
|
|
else
|
|
{
|
|
onErrMsg(QString("测试失败:") + msg);
|
|
}
|
|
ui->pushButton_start_test->setEnabled(true);
|
|
}
|
|
|
|
void MainWindow::handleDeleteResults(const QString &msg, bool result)
|
|
{
|
|
ui->label_status->setHidden(true);
|
|
|
|
if(result)
|
|
{
|
|
QMessageBox::information(this,"提醒","删除成功");
|
|
}
|
|
else
|
|
{
|
|
onErrMsg(QString("删除失败:") + msg);
|
|
}
|
|
ui->pushButton_insert->setEnabled(true);
|
|
ui->pushButton_delete->setEnabled(true);
|
|
}
|
|
|
|
void MainWindow::handleEventInsertResults(const QString &msg, bool result)
|
|
{
|
|
if(result)
|
|
{
|
|
QMessageBox::information(this,"提醒","生成数据库文件已放至同目录outEvent.sql");
|
|
}
|
|
else
|
|
{
|
|
onErrMsg(QString("插入失败:") + msg);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_pushButton_delete_clicked()
|
|
{
|
|
if(QMessageBox::question(this,"提醒","是否删除") != QMessageBox::Yes)
|
|
{
|
|
return;
|
|
}
|
|
|
|
QString address = ui->lineEdit_addr->text();
|
|
QStringList listPoint = ui->plainTextEdit_point->toPlainText().simplified().split(',');
|
|
listPoint.removeAll("");
|
|
for(int i = 0; i < listPoint.size(); i++)
|
|
{
|
|
listPoint[i] = listPoint[i].trimmed();
|
|
}
|
|
QString pointType = getPointType();
|
|
|
|
quint64 starttime = QDateTime(ui->calendarWidget_startDate->selectedDate(),ui->timeEdit_start->time()).toMSecsSinceEpoch();
|
|
quint64 endtime = QDateTime(ui->calendarWidget_endDate->selectedDate(),ui->timeEdit_end->time()).toMSecsSinceEpoch(); // 结束日期加一天
|
|
bool isDeleteAll = ui->checkBox_delAll->isChecked();
|
|
|
|
emit deleteWork(address,pointType,listPoint,starttime,endtime,isDeleteAll);
|
|
|
|
ui->pushButton_insert->setEnabled(false);
|
|
ui->pushButton_delete->setEnabled(false);
|
|
ui->label_status->setHidden(false);
|
|
|
|
}
|
|
|
|
void MainWindow::on_pushButton_insert_event_clicked()
|
|
{
|
|
if(QMessageBox::question(this,"提醒","是否插入历史数据") != QMessageBox::Yes)
|
|
{
|
|
return;
|
|
}
|
|
|
|
QStringList listPoint = ui->plainTextEdit_point_event->toPlainText().simplified().split(',');
|
|
listPoint.removeAll("");
|
|
for(int i = 0; i < listPoint.size(); i++)
|
|
{
|
|
listPoint[i] = listPoint[i].trimmed();
|
|
}
|
|
|
|
quint64 starttime = QDateTime(ui->calendarWidget_startDate_event->selectedDate(),ui->timeEdit_start_event->time()).toMSecsSinceEpoch();
|
|
quint64 endtime = QDateTime(ui->calendarWidget_endDate_event->selectedDate(),ui->timeEdit_end_event->time()).toMSecsSinceEpoch(); // 结束日期加一天
|
|
|
|
emit insertEvent(
|
|
QStringList()
|
|
<< QString::number( ui->spinBox_alm_type->value() ) // 0
|
|
<< QString::number( ui->spinBox_alm_status->value() ) // 1
|
|
<< QString::number( ui->spinBox_alm_style->value() ) // 2
|
|
<< QString::number( ui->spinBox_location_id->value() ) // 3
|
|
<< QString::number( ui->spinBox_priority->value() ) // 4
|
|
<< QString::number( ui->spinBox_sub_system->value() ) // 5
|
|
<< QString::number( ui->spinBox_dev_type->value() ) //6
|
|
<< QString::number( ui->spinBox_region_id->value() ) // 7
|
|
<< QString::number( ui->spinBox_interval_event->value() ) // 8
|
|
|
|
,
|
|
listPoint,ui->lineEdit_content->text(),starttime,endtime);
|
|
}
|
|
|
|
void MainWindow::on_pushButton_delete_event_clicked()
|
|
{
|
|
onErrMsg(tr("该功能未实现"));
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_checkBox_delAll_clicked(bool checked)
|
|
{
|
|
if(checked)
|
|
{
|
|
ui->checkBox_delete->setChecked(false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_checkBox_delete_clicked(bool checked)
|
|
{
|
|
if(checked)
|
|
{
|
|
ui->checkBox_delAll->setChecked(false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_pushButton_start_test_clicked()
|
|
{
|
|
if(QMessageBox::question(this,"提醒","是否查询") != QMessageBox::Yes)
|
|
{
|
|
|
|
return;
|
|
}
|
|
ui->plainTextEdit_test_result->clear();
|
|
QString headerLine;
|
|
headerLine += QString("结果") + ",";
|
|
headerLine += QString("规模") + ",";
|
|
headerLine += QString("周期") + ",";
|
|
headerLine += QString("开始日期") + ",";
|
|
headerLine += QString("结果日期") + ",";
|
|
headerLine += QString("间隔(s)") + ",";
|
|
headerLine += QString("结果数量") + ",";
|
|
headerLine += QString("方法") + ",";
|
|
headerLine += QString("用时(ms)");
|
|
ui->plainTextEdit_test_result->appendPlainText(headerLine);
|
|
|
|
|
|
while(ui->tableWidget->rowCount() > 0)
|
|
{
|
|
ui->tableWidget->removeRow(0);
|
|
}
|
|
|
|
// 一些参数预先设定
|
|
int timeout = ui->spinBox_timeout->value();
|
|
int base = ui->spinBox_base->value();
|
|
int facor = ui->spinBox_factor->value();
|
|
|
|
QString address = ui->lineEdit_addr_test->text();
|
|
qint64 starttime = QDateTime(ui->calendarWidget_test->selectedDate(),QTime(0,0)).toMSecsSinceEpoch();
|
|
|
|
QStringList listPoint = ui->plainTextEdit_point_test->toPlainText().simplified().split(',');
|
|
listPoint.removeAll("");
|
|
for(int i = 0; i < listPoint.size(); i++)
|
|
{
|
|
listPoint[i] = listPoint[i].trimmed();
|
|
}
|
|
|
|
// todo 这里时间间隔和计算方法以后再做,这里固定填充了
|
|
|
|
emit startTest(timeout,base,facor,listPoint,starttime,address);
|
|
|
|
ui->pushButton_start_test->setEnabled(false);
|
|
|
|
}
|