feat(production): 界面表格优化
This commit is contained in:
+1
-1
@@ -35,8 +35,8 @@ activeAlarm=507
|
||||
currentStep=200
|
||||
checkResult=201
|
||||
errorCode=202
|
||||
|
||||
;robot signals
|
||||
|
||||
rackPickCommand=800
|
||||
rackPickFeedback=807
|
||||
frontLoadCommand=803
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <QFormLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
@@ -212,9 +211,8 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
processTable->setColumnCount(4);
|
||||
processTable->setHorizontalHeaderLabels(
|
||||
QStringList() << "工序" << "状态" << "次数" << "耗时");
|
||||
processTable->horizontalHeader()->setStretchLastSection(true);
|
||||
processTable->horizontalHeader()->setSectionResizeMode(
|
||||
0, QHeaderView::Stretch);
|
||||
UiHelpers::configureTableColumns(
|
||||
processTable, QList<int>() << 180 << 120 << 70 << 100);
|
||||
processTable->verticalHeader()->setVisible(false);
|
||||
processTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
processTable->setAlternatingRowColors(true);
|
||||
@@ -224,7 +222,9 @@ DashboardPage::DashboardPage(QWidget *parent)
|
||||
|
||||
ui->recentLogTable->setColumnCount(5);
|
||||
ui->recentLogTable->setHorizontalHeaderLabels(QStringList() << "时间" << "类型" << "模块" << "内容" << "状态");
|
||||
ui->recentLogTable->horizontalHeader()->setStretchLastSection(true);
|
||||
UiHelpers::configureTableColumns(
|
||||
ui->recentLogTable, QList<int>() << 80 << 100 << 100 << 300 << 80,
|
||||
3, 60);
|
||||
ui->recentLogTable->verticalHeader()->setVisible(false);
|
||||
ui->recentLogTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->recentLogTable->setAlternatingRowColors(true);
|
||||
@@ -383,7 +383,9 @@ void DashboardPage::addLog(const QString &type, const QString &module, const QSt
|
||||
<< QDateTime::currentDateTime().toString("HH:mm:ss")
|
||||
<< type << module << content << status;
|
||||
for (int col = 0; col < values.size(); ++col) {
|
||||
ui->recentLogTable->setItem(0, col, new QTableWidgetItem(values.at(col)));
|
||||
QTableWidgetItem *item = new QTableWidgetItem(values.at(col));
|
||||
if (col == 3) item->setTextAlignment(Qt::AlignCenter);
|
||||
ui->recentLogTable->setItem(0, col, item);
|
||||
}
|
||||
while (ui->recentLogTable->rowCount() > 8) {
|
||||
ui->recentLogTable->removeRow(ui->recentLogTable->rowCount() - 1);
|
||||
|
||||
+12
-3
@@ -1,10 +1,10 @@
|
||||
#include "devicepage.h"
|
||||
#include "ui_devicepage.h"
|
||||
#include "uihelpers.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QTableWidget>
|
||||
#include <QTableWidgetItem>
|
||||
@@ -28,7 +28,11 @@ void DevicePage::setupTable()
|
||||
table->setColumnCount(5);
|
||||
table->setHorizontalHeaderLabels(QStringList()
|
||||
<< "设备/信号" << "连接状态" << "运行状态" << "当前动作" << "最后更新时间");
|
||||
table->horizontalHeader()->setStretchLastSection(true);
|
||||
table->horizontalHeaderItem(0)->setTextAlignment(Qt::AlignCenter);
|
||||
const int dateTimeWidth = UiHelpers::textColumnWidth(
|
||||
table, "2026-10-30 23:59:59");
|
||||
UiHelpers::configureTableColumns(
|
||||
table, QList<int>() << 110 << 100 << 110 << 210 << dateTimeWidth);
|
||||
table->verticalHeader()->setVisible(false);
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
table->setAlternatingRowColors(true);
|
||||
@@ -39,7 +43,9 @@ void DevicePage::setupTable()
|
||||
<< "安全门 3" << "急停" << "PLC 活动报警";
|
||||
table->setRowCount(names.size());
|
||||
for (int row = 0; row < names.size(); ++row) {
|
||||
table->setItem(row, 0, new QTableWidgetItem(names.at(row)));
|
||||
QTableWidgetItem *item = new QTableWidgetItem(names.at(row));
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
table->setItem(row, 0, item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +59,9 @@ void DevicePage::setRow(int row, const QStringList &values)
|
||||
table->setItem(row, column, item);
|
||||
}
|
||||
item->setText(values.at(column));
|
||||
if (column == 0) {
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-3
@@ -1,5 +1,6 @@
|
||||
#include "logpage.h"
|
||||
#include "ui_logpage.h"
|
||||
#include "uihelpers.h"
|
||||
|
||||
#include "../models/logrecord.h"
|
||||
#include "../repositories/logrepository.h"
|
||||
@@ -7,7 +8,6 @@
|
||||
#include <QAbstractItemView>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QHeaderView>
|
||||
#include <QTableWidget>
|
||||
#include <QTableWidgetItem>
|
||||
|
||||
@@ -19,7 +19,12 @@ LogPage::LogPage(QWidget *parent)
|
||||
|
||||
ui->logTable->setColumnCount(6);
|
||||
ui->logTable->setHorizontalHeaderLabels(QStringList() << "时间" << "类型" << "模块" << "动作" << "内容" << "状态");
|
||||
ui->logTable->horizontalHeader()->setStretchLastSection(true);
|
||||
const int dateTimeWidth = UiHelpers::textColumnWidth(
|
||||
ui->logTable, "2026-10-30 23:59:59");
|
||||
UiHelpers::configureTableColumns(
|
||||
ui->logTable,
|
||||
QList<int>() << dateTimeWidth << 100 << 100 << 110 << 360 << 80,
|
||||
4, 60);
|
||||
ui->logTable->verticalHeader()->setVisible(false);
|
||||
ui->logTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
ui->logTable->setAlternatingRowColors(true);
|
||||
@@ -67,6 +72,8 @@ void LogPage::addLogRow(const QString &time, const QString &type, const QString
|
||||
const QStringList values = QStringList()
|
||||
<< time << type << module << action << content << status;
|
||||
for (int col = 0; col < values.size(); ++col) {
|
||||
ui->logTable->setItem(0, col, new QTableWidgetItem(values.at(col)));
|
||||
QTableWidgetItem *item = new QTableWidgetItem(values.at(col));
|
||||
if (col == 4) item->setTextAlignment(Qt::AlignCenter);
|
||||
ui->logTable->setItem(0, col, item);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,12 +1,12 @@
|
||||
#include "orderpage.h"
|
||||
#include "ui_orderpage.h"
|
||||
#include "uihelpers.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFormLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
@@ -58,7 +58,12 @@ OrderPage::OrderPage(QWidget *parent)
|
||||
<< "订单编号" << "生产号" << "图纸号" << "批次号" << "计划"
|
||||
<< "OK" << "NG" << "状态" << "检测模式" << "起始托盘"
|
||||
<< "起始位置" << "开始时间" << "结束时间" << "备注");
|
||||
table->horizontalHeader()->setStretchLastSection(true);
|
||||
const int dateTimeWidth = UiHelpers::textColumnWidth(
|
||||
table, "2026-10-30 23:59:59");
|
||||
UiHelpers::configureTableColumns(
|
||||
table, QList<int>() << 120 << 105 << 105 << 100 << 65 << 55 << 55
|
||||
<< 80 << 105 << 80 << 80 << dateTimeWidth
|
||||
<< dateTimeWidth << 120);
|
||||
table->verticalHeader()->setVisible(false);
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
table->setAlternatingRowColors(true);
|
||||
|
||||
@@ -297,6 +297,12 @@ void QualityPage::setupInspectionTab()
|
||||
QStringList() << "时间" << "订单号" << "工件条码" << "托盘" << "位置"
|
||||
<< "模式" << "检测面" << "结果" << "原始结果"
|
||||
<< "来源" << "耗时" << "次数");
|
||||
const int dateTimeWidth = UiHelpers::textColumnWidth(
|
||||
inspectionTable, "2026-10-30 23:59:59");
|
||||
UiHelpers::configureTableColumns(
|
||||
inspectionTable,
|
||||
QList<int>() << dateTimeWidth << 110 << 150 << 85 << 65 << 90
|
||||
<< 75 << 75 << 85 << 90 << 90 << 65);
|
||||
inspectionMessageLabel = new QLabel;
|
||||
}
|
||||
|
||||
@@ -314,6 +320,8 @@ void QualityPage::setupStatisticsTab()
|
||||
statisticsMessageLabel = new QLabel;
|
||||
sideStatisticsTable = UiHelpers::makeTable(
|
||||
QStringList() << "检测面" << "合格" << "不合格" << "记录数");
|
||||
UiHelpers::configureTableColumns(
|
||||
sideStatisticsTable, QList<int>() << 120 << 100 << 100 << 110);
|
||||
addTableRow(sideStatisticsTable, QStringList() << "正面" << "-" << "-" << "-");
|
||||
addTableRow(sideStatisticsTable, QStringList() << "反面" << "-" << "-" << "-");
|
||||
}
|
||||
@@ -328,12 +336,23 @@ void QualityPage::setupTraceTab()
|
||||
traceInspectionTable = UiHelpers::makeTable(
|
||||
QStringList() << "时间" << "模式" << "检测面" << "结果" << "原始结果"
|
||||
<< "来源" << "耗时" << "次数");
|
||||
const int dateTimeWidth = UiHelpers::textColumnWidth(
|
||||
traceInspectionTable, "2026-10-30 23:59:59");
|
||||
UiHelpers::configureTableColumns(
|
||||
traceInspectionTable,
|
||||
QList<int>() << dateTimeWidth << 90 << 75 << 75 << 85 << 90 << 90 << 65);
|
||||
traceProcessTable = UiHelpers::makeTable(
|
||||
QStringList() << "开始时间" << "工序" << "状态" << "结果" << "来源"
|
||||
<< "PLC步骤" << "耗时" << "次数");
|
||||
UiHelpers::configureTableColumns(
|
||||
traceProcessTable,
|
||||
QList<int>() << dateTimeWidth << 130 << 100 << 80 << 90 << 80 << 90 << 65);
|
||||
traceHistoryTable = UiHelpers::makeTable(
|
||||
QStringList() << "时间" << "状态变化" << "工序" << "来源"
|
||||
<< "原因" << "耗时" << "说明");
|
||||
UiHelpers::configureTableColumns(
|
||||
traceHistoryTable,
|
||||
QList<int>() << dateTimeWidth << 150 << 120 << 90 << 160 << 90 << 200);
|
||||
}
|
||||
|
||||
void QualityPage::loadInspectionRecords()
|
||||
|
||||
+120
-1
@@ -1,9 +1,12 @@
|
||||
#include "uihelpers.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QEvent>
|
||||
#include <QFrame>
|
||||
#include <QFontMetrics>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QObject>
|
||||
#include <QSize>
|
||||
#include <QSizePolicy>
|
||||
#include <QTableWidget>
|
||||
@@ -26,6 +29,105 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class ResponsiveTableColumns : public QObject
|
||||
{
|
||||
public:
|
||||
ResponsiveTableColumns(QTableWidget *table, const QList<int> &baseWidths,
|
||||
int cappedColumn, int maximumSharePercent)
|
||||
: QObject(table)
|
||||
, m_table(table)
|
||||
, m_baseWidths(baseWidths)
|
||||
, m_cappedColumn(cappedColumn)
|
||||
, m_maximumSharePercent(qBound(1, maximumSharePercent, 100))
|
||||
{
|
||||
table->installEventFilter(this);
|
||||
table->viewport()->installEventFilter(this);
|
||||
applyWidths();
|
||||
}
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override
|
||||
{
|
||||
if ((watched == m_table || watched == m_table->viewport())
|
||||
&& (event->type() == QEvent::Resize
|
||||
|| event->type() == QEvent::Show
|
||||
|| event->type() == QEvent::LayoutRequest)) {
|
||||
applyWidths();
|
||||
}
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
private:
|
||||
void applyWidths()
|
||||
{
|
||||
if (m_applying || !m_table || m_baseWidths.size() != m_table->columnCount()) {
|
||||
return;
|
||||
}
|
||||
const int availableWidth = m_table->viewport()->width();
|
||||
if (availableWidth <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int baseTotal = 0;
|
||||
for (int width : m_baseWidths) {
|
||||
baseTotal += qMax(1, width);
|
||||
}
|
||||
const int layoutWidth = qMax(availableWidth, baseTotal);
|
||||
QList<int> widths;
|
||||
int allocated = 0;
|
||||
for (int width : m_baseWidths) {
|
||||
const int scaled = qMax(1, int(qint64(qMax(1, width)) * layoutWidth / baseTotal));
|
||||
widths.append(scaled);
|
||||
allocated += scaled;
|
||||
}
|
||||
for (int column = 0; allocated < layoutWidth; ++column, ++allocated) {
|
||||
widths[column % widths.size()] += 1;
|
||||
}
|
||||
|
||||
if (m_cappedColumn >= 0 && m_cappedColumn < widths.size()) {
|
||||
const int maximumWidth = layoutWidth * m_maximumSharePercent / 100;
|
||||
const int surplus = qMax(0, widths.at(m_cappedColumn) - maximumWidth);
|
||||
const int otherBaseTotal = baseTotal - qMax(1, m_baseWidths.at(m_cappedColumn));
|
||||
if (surplus > 0 && otherBaseTotal > 0) {
|
||||
widths[m_cappedColumn] = maximumWidth;
|
||||
int distributed = 0;
|
||||
for (int column = 0; column < widths.size(); ++column) {
|
||||
if (column == m_cappedColumn) {
|
||||
continue;
|
||||
}
|
||||
const int addition = int(
|
||||
qint64(surplus) * qMax(1, m_baseWidths.at(column)) / otherBaseTotal);
|
||||
widths[column] += addition;
|
||||
distributed += addition;
|
||||
}
|
||||
for (int column = 0; distributed < surplus; ++column) {
|
||||
const int target = column % widths.size();
|
||||
if (target == m_cappedColumn) {
|
||||
continue;
|
||||
}
|
||||
widths[target] += 1;
|
||||
++distributed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_applying = true;
|
||||
QHeaderView *header = m_table->horizontalHeader();
|
||||
for (int column = 0; column < widths.size(); ++column) {
|
||||
if (header->sectionSize(column) != widths.at(column)) {
|
||||
header->resizeSection(column, widths.at(column));
|
||||
}
|
||||
}
|
||||
m_applying = false;
|
||||
}
|
||||
|
||||
QTableWidget *m_table;
|
||||
QList<int> m_baseWidths;
|
||||
int m_cappedColumn;
|
||||
int m_maximumSharePercent;
|
||||
bool m_applying = false;
|
||||
};
|
||||
|
||||
QFrame *makeCard(const QString &title)
|
||||
{
|
||||
QFrame *card = new QFrame;
|
||||
@@ -74,7 +176,6 @@ QTableWidget *makeTable(const QStringList &headers)
|
||||
{
|
||||
QTableWidget *table = new QTableWidget(0, headers.size());
|
||||
table->setHorizontalHeaderLabels(headers);
|
||||
table->horizontalHeader()->setStretchLastSection(true);
|
||||
table->verticalHeader()->setVisible(false);
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
@@ -82,6 +183,24 @@ QTableWidget *makeTable(const QStringList &headers)
|
||||
return table;
|
||||
}
|
||||
|
||||
int textColumnWidth(const QTableWidget *table, const QString &text)
|
||||
{
|
||||
return table ? QFontMetrics(table->font()).horizontalAdvance(text) + 28 : 0;
|
||||
}
|
||||
|
||||
void configureTableColumns(QTableWidget *table, const QList<int> &baseWidths,
|
||||
int cappedColumn, int maximumSharePercent)
|
||||
{
|
||||
if (!table || table->columnCount() <= 0
|
||||
|| baseWidths.size() != table->columnCount()) return;
|
||||
QHeaderView *header = table->horizontalHeader();
|
||||
header->setStretchLastSection(false);
|
||||
header->setMinimumSectionSize(1);
|
||||
header->setSectionResizeMode(QHeaderView::Fixed);
|
||||
table->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
new ResponsiveTableColumns(table, baseWidths, cappedColumn, maximumSharePercent);
|
||||
}
|
||||
|
||||
void addRow(QTableWidget *table, const QStringList &values)
|
||||
{
|
||||
const int row = table->rowCount();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef UIHELPERS_H
|
||||
#define UIHELPERS_H
|
||||
|
||||
#include <QList>
|
||||
#include <QStringList>
|
||||
|
||||
class QFrame;
|
||||
@@ -14,6 +15,9 @@ QLabel *makeBadge(const QString &text, const QString &color);
|
||||
QLabel *makeStatusCell(const QString &text, const QString &color);
|
||||
QLabel *makeSquareStatusCell(const QString &text, const QString &color);
|
||||
QTableWidget *makeTable(const QStringList &headers);
|
||||
int textColumnWidth(const QTableWidget *table, const QString &text);
|
||||
void configureTableColumns(QTableWidget *table, const QList<int> &baseWidths,
|
||||
int cappedColumn = -1, int maximumSharePercent = 100);
|
||||
void addRow(QTableWidget *table, const QStringList &values);
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.11.0, 2026-10-30T00:02:56. -->
|
||||
<!-- Written by QtCreator 4.11.0, 2026-10-30T17:56:26. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ void Widget::setupMainArea(QVBoxLayout *rootLayout)
|
||||
navList = new QListWidget;
|
||||
navList->setFixedWidth(170);
|
||||
navList->addItems(QStringList() << "控制面板" << "订单管理" << "料架/托盘"
|
||||
<< "设备状态" << "日志" << "质量管理" << "视觉引导");
|
||||
<< "设备状态" << "日志记录" << "质量管理" << "视觉引导");
|
||||
navList->setCurrentRow(0);
|
||||
bodyLayout->addWidget(navList);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user