|
@@ -0,0 +1,132 @@
|
|
|
|
|
+#include "runlogwidget.h"
|
|
|
|
|
+#include "ui_runlogwidget.h"
|
|
|
|
|
+#include "pdu_ctrl.h"
|
|
|
|
|
+#include <QScroller>
|
|
|
|
|
+RunLogWidget::RunLogWidget(QWidget *parent) :
|
|
|
|
|
+ QWidget(parent),
|
|
|
|
|
+ ui(new Ui::RunLogWidget)
|
|
|
|
|
+{
|
|
|
|
|
+ ui->setupUi(this);
|
|
|
|
|
+ InitUI();
|
|
|
|
|
+ currentPage=1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+RunLogWidget::~RunLogWidget()
|
|
|
|
|
+{
|
|
|
|
|
+ delete ui;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void RunLogWidget::UpdateLog()
|
|
|
|
|
+{
|
|
|
|
|
+ calculateTotalPages();
|
|
|
|
|
+ loadPage(currentPage);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void RunLogWidget::InitUI()
|
|
|
|
|
+{
|
|
|
|
|
+ connect(ui->prevButton,SIGNAL(clicked()),this,SLOT(slot_upPage()));
|
|
|
|
|
+ connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(slot_downPage()));
|
|
|
|
|
+ QStringList headers = {"序号", "时间", "类型","记录"};
|
|
|
|
|
+ ui->tableWidget->setColumnCount(4);
|
|
|
|
|
+ ui->tableWidget->setHorizontalHeaderLabels(headers);
|
|
|
|
|
+ // 设置自动调整列宽
|
|
|
|
|
+ ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
|
+ //ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
|
+ ui->tableWidget->verticalHeader()->setVisible(false);
|
|
|
|
|
+ ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
|
+ ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
+
|
|
|
|
|
+// QScroller::grabGesture(ui->tableWidget->viewport(), QScroller::TouchGesture);
|
|
|
|
|
+// QScrollerProperties properties = QScroller::scroller(ui->tableWidget)->scrollerProperties();
|
|
|
|
|
+// properties.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, 0.6); // 惯性系数
|
|
|
|
|
+// properties.setScrollMetric(QScrollerProperties::SnapPositionRatio, 0.2); // 弹性效果
|
|
|
|
|
+// ui->tableWidget->viewport()->setAttribute(Qt::WA_AcceptTouchEvents); // 启用触控事件
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void RunLogWidget::AddRowData(int nIndex, int nType, QString nTime, QString strMSG)
|
|
|
|
|
+{
|
|
|
|
|
+ int row = ui->tableWidget->rowCount();
|
|
|
|
|
+ ui->tableWidget->insertRow(row);
|
|
|
|
|
+
|
|
|
|
|
+ QTableWidgetItem *item = new QTableWidgetItem(QString::number(nIndex));
|
|
|
|
|
+ ui->tableWidget->setItem(row, 0, item);
|
|
|
|
|
+ QTableWidgetItem *item1 = new QTableWidgetItem(nTime);
|
|
|
|
|
+ ui->tableWidget->setItem(row, 1, item1);
|
|
|
|
|
+ QTableWidgetItem *item2 = new QTableWidgetItem(QString::number(nType));
|
|
|
|
|
+ ui->tableWidget->setItem(row, 2, item2);
|
|
|
|
|
+ QString strData=strMSG;
|
|
|
|
|
+ strData.replace("$","");
|
|
|
|
|
+ strData.replace("|","");
|
|
|
|
|
+ QTableWidgetItem *item3 = new QTableWidgetItem(strData);
|
|
|
|
|
+ ui->tableWidget->setItem(row, 3, item3);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void RunLogWidget::ClearList()
|
|
|
|
|
+{
|
|
|
|
|
+ ui->tableWidget->clearContents();
|
|
|
|
|
+ ui->tableWidget->setRowCount(0);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void RunLogWidget::calculateTotalPages()
|
|
|
|
|
+{
|
|
|
|
|
+ QSqlQuery query(pdu_Ctrl::instance()->getDB());
|
|
|
|
|
+ QString strExec="SELECT COUNT(*) FROM Table_AlarmManage";
|
|
|
|
|
+ if (query.exec(strExec) && query.next()) {
|
|
|
|
|
+ int totalRecords = query.value(0).toInt();
|
|
|
|
|
+ totalPages = (totalRecords + perPage - 1) / perPage;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void RunLogWidget::loadPage(int page)
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ QSqlQuery query(pdu_Ctrl::instance()->getDB());
|
|
|
|
|
+ query.prepare(
|
|
|
|
|
+ "SELECT alarmNumber, alarmDate, alarmType, product_id, alarmContent "
|
|
|
|
|
+ "FROM Table_AlarmManage "
|
|
|
|
|
+ "ORDER BY alarmDate DESC "
|
|
|
|
|
+ "LIMIT :limit OFFSET :offset"
|
|
|
|
|
+ );
|
|
|
|
|
+ query.bindValue(":limit", perPage);
|
|
|
|
|
+ query.bindValue(":offset", (page - 1) * perPage);
|
|
|
|
|
+ if (!query.exec()) {
|
|
|
|
|
+ //QMessageBox::warning(this, "Query Error", query.lastError().text());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ ClearList();
|
|
|
|
|
+ while (query.next()) {
|
|
|
|
|
+ int totalRecords = query.value(0).toInt();
|
|
|
|
|
+ //int totalRecords1 = query.value(1).toInt();
|
|
|
|
|
+ int totalRecords2 = query.value(2).toInt();
|
|
|
|
|
+ QString totalRecords3 = query.value(1).toString();
|
|
|
|
|
+ QString totalRecords4 = query.value(4).toString();
|
|
|
|
|
+ AddRowData(totalRecords,totalRecords2,totalRecords3,totalRecords4);
|
|
|
|
|
+ }
|
|
|
|
|
+ ui->tableWidget->resizeColumnsToContents();
|
|
|
|
|
+
|
|
|
|
|
+ ui->labelPage->setText(QString("Page: %1/%2").arg(page).arg(totalPages));
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void RunLogWidget::updateButtons()
|
|
|
|
|
+{
|
|
|
|
|
+ ui->prevButton->setEnabled(currentPage > 1);
|
|
|
|
|
+ ui->nextButton->setEnabled(currentPage < totalPages);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void RunLogWidget::slot_upPage()
|
|
|
|
|
+{
|
|
|
|
|
+ if (currentPage > 1) {
|
|
|
|
|
+ loadPage(--currentPage);
|
|
|
|
|
+ updateButtons();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void RunLogWidget::slot_downPage()
|
|
|
|
|
+{
|
|
|
|
|
+ if (currentPage < totalPages) {
|
|
|
|
|
+ loadPage(++currentPage);
|
|
|
|
|
+ updateButtons();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|