2025-06-08 12:48:04 +08:00
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
#include "ui_mainwindow.h"
|
2025-06-19 01:38:50 +08:00
|
|
|
|
#include "resultitem.h"
|
2025-06-08 12:48:04 +08:00
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
#include <QBrush>
|
2025-06-08 23:51:48 +08:00
|
|
|
|
#include <QMessageBox>
|
2025-06-17 00:37:05 +08:00
|
|
|
|
#include <QFileDialog>
|
2025-06-19 01:38:50 +08:00
|
|
|
|
#include <QListWidgetItem>
|
|
|
|
|
|
#include <QtMath>
|
|
|
|
|
|
#include <QThread>
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
#include <QTextCursor>
|
|
|
|
|
|
#include <QStringListModel>
|
|
|
|
|
|
#include "VrLog.h"
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
|
: QMainWindow(parent)
|
|
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置状态栏字体
|
|
|
|
|
|
QFont statusFont = statusBar()->font();
|
2025-06-17 00:37:05 +08:00
|
|
|
|
statusFont.setPointSize(12);
|
2025-06-08 12:48:04 +08:00
|
|
|
|
statusBar()->setFont(statusFont);
|
|
|
|
|
|
|
2025-06-17 00:37:05 +08:00
|
|
|
|
// 设置状态栏颜色和padding
|
|
|
|
|
|
statusBar()->setStyleSheet("QStatusBar { color: rgb(239, 241, 245); padding: 20px; }");
|
|
|
|
|
|
|
|
|
|
|
|
// 启动后自动全屏显示
|
|
|
|
|
|
this->showFullScreen();
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
|
|
|
|
|
// 初始化GraphicsScene
|
|
|
|
|
|
QGraphicsScene* scene = new QGraphicsScene(this);
|
|
|
|
|
|
ui->detect_image->setScene(scene);
|
|
|
|
|
|
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 初始化日志模型
|
|
|
|
|
|
m_logModel = new QStringListModel(this);
|
|
|
|
|
|
ui->detect_log->setModel(m_logModel);
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 原有的状态指示器已删除,状态显示统一在devstatus中处理
|
2025-06-08 23:51:48 +08:00
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
// 连接菜单信号
|
2025-06-08 23:51:48 +08:00
|
|
|
|
// connect(ui->menu_camera, &QMenu::aboutToShow, this, &MainWindow::on_menu_camera_triggered);
|
|
|
|
|
|
// connect(ui->menu_config, &QMenu::aboutToShow, this, &MainWindow::on_menu_config_triggered);
|
|
|
|
|
|
// connect(ui->menu_camera_adjust, &QMenu::aboutToShow, this, &MainWindow::on_menu_camera_adjust_triggered);
|
|
|
|
|
|
|
|
|
|
|
|
// 连接工作状态更新信号槽
|
|
|
|
|
|
connect(this, &MainWindow::workStatusUpdateRequested, this, &MainWindow::updateWorkStatusLabel);
|
|
|
|
|
|
|
|
|
|
|
|
// 连接检测结果更新信号槽
|
|
|
|
|
|
connect(this, &MainWindow::detectionResultUpdateRequested, this, &MainWindow::updateDetectionResultDisplay);
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 连接日志更新信号槽
|
|
|
|
|
|
connect(this, &MainWindow::logUpdateRequested, this, &MainWindow::updateDetectionLog);
|
|
|
|
|
|
|
|
|
|
|
|
// 连接清空日志信号槽
|
|
|
|
|
|
connect(this, &MainWindow::logClearRequested, this, &MainWindow::clearDetectionLogUI);
|
|
|
|
|
|
|
|
|
|
|
|
updateStatusLog(tr("设备开始初始化..."));
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
2025-06-17 00:37:05 +08:00
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
// 初始化模块
|
|
|
|
|
|
Init();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 释放业务逻辑处理类
|
|
|
|
|
|
if (m_presenter) {
|
|
|
|
|
|
delete m_presenter;
|
|
|
|
|
|
m_presenter = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateStatusLog(const QString& message)
|
|
|
|
|
|
{
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 更新状态栏
|
|
|
|
|
|
// statusBar()->showMessage(message);
|
|
|
|
|
|
|
|
|
|
|
|
// 通过信号槽机制更新detect_log控件
|
|
|
|
|
|
emit logUpdateRequested(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::clearDetectionLog()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 通过信号槽机制清空日志
|
|
|
|
|
|
emit logClearRequested();
|
2025-06-08 12:48:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 创建业务逻辑处理类
|
|
|
|
|
|
m_presenter = new GrabBagPresenter();
|
|
|
|
|
|
|
|
|
|
|
|
// 设置状态回调接口
|
|
|
|
|
|
m_presenter->SetStatusCallback(this);
|
|
|
|
|
|
|
2025-06-19 01:38:50 +08:00
|
|
|
|
m_deviceStatusWidget = new devstatus(); //因为初始化回调的数据要存储,所以要在init前创建好
|
|
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
// 初始化业务逻辑
|
|
|
|
|
|
int result = m_presenter->Init();
|
|
|
|
|
|
if (result != 0) {
|
|
|
|
|
|
updateStatusLog(tr("初始化失败,错误码:%1").arg(result));
|
|
|
|
|
|
}
|
2025-06-19 01:38:50 +08:00
|
|
|
|
|
|
|
|
|
|
// 初始化完成后,在detect_result_list中增加设备状态widget
|
|
|
|
|
|
QListWidgetItem* deviceStatusItem = new QListWidgetItem();
|
|
|
|
|
|
deviceStatusItem->setBackground(QBrush(Qt::transparent));
|
|
|
|
|
|
deviceStatusItem->setSizeHint(QSize(272, 200));
|
|
|
|
|
|
|
|
|
|
|
|
ui->detect_result_list->addItem(deviceStatusItem);
|
|
|
|
|
|
ui->detect_result_list->setItemWidget(deviceStatusItem, m_deviceStatusWidget);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置列表视图模式
|
|
|
|
|
|
ui->detect_result_list->setViewMode(QListView::IconMode);
|
|
|
|
|
|
ui->detect_result_list->setResizeMode(QListView::Adjust);
|
|
|
|
|
|
ui->detect_result_list->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
|
|
ui->detect_result_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2025-06-08 12:48:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::displayImage(const QImage& image)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (image.isNull()) {
|
|
|
|
|
|
updateStatusLog(tr("图片无效"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QGraphicsScene* scene = ui->detect_image->scene();
|
|
|
|
|
|
scene->clear();
|
|
|
|
|
|
|
|
|
|
|
|
QPixmap pixmap = QPixmap::fromImage(image);
|
|
|
|
|
|
scene->addPixmap(pixmap);
|
|
|
|
|
|
ui->detect_image->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 添加扩展版本的检测结果函数
|
|
|
|
|
|
void MainWindow::addDetectionResult(const DetectionResult& result)
|
|
|
|
|
|
{
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 清空之前的数据(除了第一个设备状态item)
|
|
|
|
|
|
while (ui->detect_result_list->count() > 1) {
|
|
|
|
|
|
QListWidgetItem* item = ui->detect_result_list->takeItem(1);
|
|
|
|
|
|
delete item;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新现有设备状态显示(第一个item就是设备状态)
|
|
|
|
|
|
if (m_deviceStatusWidget) {
|
|
|
|
|
|
// m_deviceStatusWidget会自动从其内部状态获取设备状态信息
|
|
|
|
|
|
// 不需要手动更新,因为状态变化时会直接更新到widget中
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置为图标模式,实现网格布局(多列显示)
|
|
|
|
|
|
ui->detect_result_list->setViewMode(QListView::IconMode);
|
|
|
|
|
|
ui->detect_result_list->setResizeMode(QListView::Adjust);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置滚动条策略:始终显示垂直滚动条,隐藏水平滚动条
|
|
|
|
|
|
ui->detect_result_list->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
|
|
ui->detect_result_list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
|
|
|
|
|
|
|
// 计算gridWidth:考虑12px间距,确保两列布局
|
|
|
|
|
|
int totalWidth = ui->detect_result_list->width();
|
|
|
|
|
|
int itemSpacing = 12;
|
|
|
|
|
|
int gridWidth = (totalWidth - itemSpacing - 17) / 2; //20是滚动条的宽度
|
|
|
|
|
|
int gridHeight = 200;
|
|
|
|
|
|
|
|
|
|
|
|
ui->detect_result_list->setGridSize(QSize(gridWidth, gridHeight)); // 设置每个格子的大小
|
|
|
|
|
|
ui->detect_result_list->setSpacing(itemSpacing); // 设置item间距为12px
|
|
|
|
|
|
ui->detect_result_list->setFlow(QListView::LeftToRight); // 从左到右排列
|
|
|
|
|
|
ui->detect_result_list->setWrapping(true); // 允许换行
|
|
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
auto layoutIter = result.positionLayout.begin();
|
2025-06-19 01:38:50 +08:00
|
|
|
|
int targetIndex = 1;
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
|
|
|
|
|
while(layoutIter != result.positionLayout.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
auto positionIter = layoutIter->position.begin();
|
|
|
|
|
|
while(positionIter != layoutIter->position.end())
|
|
|
|
|
|
{
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 创建自定义的ResultItem widget
|
|
|
|
|
|
ResultItem* resultWidget = new ResultItem();
|
|
|
|
|
|
|
|
|
|
|
|
// 设置widget的autoFillBackground属性,确保背景色生效
|
|
|
|
|
|
resultWidget->setAutoFillBackground(true);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置检测结果数据,直接使用GrabBagPosition
|
|
|
|
|
|
resultWidget->setResultData(targetIndex, *positionIter);
|
|
|
|
|
|
|
|
|
|
|
|
// 创建QListWidgetItem
|
|
|
|
|
|
QListWidgetItem* item = new QListWidgetItem();
|
|
|
|
|
|
|
|
|
|
|
|
// 设置item背景为透明,让自定义widget的背景显示出来
|
|
|
|
|
|
item->setBackground(QBrush(Qt::transparent));
|
|
|
|
|
|
|
|
|
|
|
|
// 设置item的大小提示 - 应该与gridSize一致
|
|
|
|
|
|
item->setSizeHint(QSize(gridWidth, gridHeight));
|
|
|
|
|
|
|
|
|
|
|
|
// 将item添加到列表
|
|
|
|
|
|
ui->detect_result_list->addItem(item);
|
|
|
|
|
|
|
|
|
|
|
|
// 将自定义widget设置为item的显示内容
|
|
|
|
|
|
ui->detect_result_list->setItemWidget(item, resultWidget);
|
|
|
|
|
|
|
|
|
|
|
|
targetIndex++;
|
2025-06-08 12:48:04 +08:00
|
|
|
|
positionIter++;
|
|
|
|
|
|
}
|
|
|
|
|
|
layoutIter++;
|
2025-06-19 01:38:50 +08:00
|
|
|
|
}
|
2025-06-08 12:48:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_btn_camera_clicked()
|
|
|
|
|
|
{
|
2025-06-08 23:51:48 +08:00
|
|
|
|
// if(nullptr == ui_dialogCamera){
|
|
|
|
|
|
// ui_dialogCamera = new DialogCamera;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// ui_dialogCamera->show();
|
2025-06-08 12:48:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_btn_config_clicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(nullptr == ui_dialogConfig){
|
|
|
|
|
|
ui_dialogConfig = new DialogConfig;
|
|
|
|
|
|
}
|
|
|
|
|
|
ui_dialogConfig->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_btn_flow_clicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 机械臂连接/断开
|
|
|
|
|
|
static bool isConnected = false;
|
|
|
|
|
|
isConnected = !isConnected;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_btn_start_clicked()
|
|
|
|
|
|
{
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 清空检测日志,开始新的检测
|
|
|
|
|
|
clearDetectionLog();
|
|
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
// 使用Presenter启动检测
|
|
|
|
|
|
if (m_presenter) {
|
|
|
|
|
|
m_presenter->StartDetection();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_btn_stop_clicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_presenter) {
|
|
|
|
|
|
m_presenter->StopDetection();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_menu_camera_adjust_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 状态更新槽函数
|
|
|
|
|
|
void MainWindow::OnStatusUpdate(const std::string& statusMessage)
|
|
|
|
|
|
{
|
2025-06-19 01:38:50 +08:00
|
|
|
|
LOG_DEBUG("[UI Display] Status update: %s\n", statusMessage.c_str());
|
2025-06-08 12:48:04 +08:00
|
|
|
|
updateStatusLog(QString::fromStdString(statusMessage));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::OnDetectionResult(const DetectionResult& result)
|
|
|
|
|
|
{
|
2025-06-08 23:51:48 +08:00
|
|
|
|
// 通过信号槽机制更新UI(确保在主线程中执行)
|
|
|
|
|
|
emit detectionResultUpdateRequested(result);
|
2025-06-08 12:48:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::OnCamera1StatusChanged(bool isConnected)
|
|
|
|
|
|
{
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 直接更新设备状态widget
|
|
|
|
|
|
if (m_deviceStatusWidget) {
|
|
|
|
|
|
m_deviceStatusWidget->updateCamera1Status(isConnected);
|
|
|
|
|
|
}
|
2025-06-08 12:48:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 相机2状态更新槽函数
|
|
|
|
|
|
void MainWindow::OnCamera2StatusChanged(bool isConnected)
|
|
|
|
|
|
{
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 直接更新设备状态widget
|
|
|
|
|
|
if (m_deviceStatusWidget) {
|
|
|
|
|
|
m_deviceStatusWidget->updateCamera2Status(isConnected);
|
|
|
|
|
|
}
|
2025-06-08 12:48:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 相机个数更新槽函数
|
|
|
|
|
|
void MainWindow::OnCameraCountChanged(int cameraCount)
|
|
|
|
|
|
{
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 设置设备状态widget中的相机数量
|
|
|
|
|
|
if (m_deviceStatusWidget) {
|
|
|
|
|
|
m_deviceStatusWidget->setCameraCount(cameraCount);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果只有一个相机,更新状态消息
|
2025-06-08 12:48:04 +08:00
|
|
|
|
if (cameraCount < 2) {
|
|
|
|
|
|
// 更新状态消息
|
|
|
|
|
|
updateStatusLog(tr("系统使用单相机模式"));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 更新状态消息
|
|
|
|
|
|
updateStatusLog(tr("系统使用双相机模式"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 机械臂状态更新槽函数
|
|
|
|
|
|
void MainWindow::OnRobotConnectionChanged(bool isConnected)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 直接更新设备状态widget
|
|
|
|
|
|
if (m_deviceStatusWidget) {
|
|
|
|
|
|
m_deviceStatusWidget->updateRobotStatus(isConnected);
|
|
|
|
|
|
}
|
2025-06-08 12:48:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 工作状态更新槽函数
|
|
|
|
|
|
void MainWindow::OnWorkStatusChanged(WorkStatus status)
|
2025-06-08 23:51:48 +08:00
|
|
|
|
{
|
|
|
|
|
|
// 通过信号槽机制更新UI(确保在主线程中执行)
|
|
|
|
|
|
emit workStatusUpdateRequested(status);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateWorkStatusLabel(WorkStatus status)
|
2025-06-08 12:48:04 +08:00
|
|
|
|
{
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 如果状态变为Working,清空检测日志(表示开始新的检测)
|
|
|
|
|
|
if (status == WorkStatus::Working) {
|
|
|
|
|
|
clearDetectionLog();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-08 12:48:04 +08:00
|
|
|
|
// 获取状态对应的显示文本
|
|
|
|
|
|
QString statusText = QString::fromStdString(WorkStatusToString(status));
|
|
|
|
|
|
|
|
|
|
|
|
// 在label_work中显示状态
|
|
|
|
|
|
if (ui->label_work) {
|
|
|
|
|
|
ui->label_work->setText(statusText);
|
|
|
|
|
|
|
|
|
|
|
|
// 根据不同状态设置不同的样式
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
|
case WorkStatus::Ready:
|
|
|
|
|
|
ui->label_work->setStyleSheet("color: green;");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case WorkStatus::Working:
|
|
|
|
|
|
ui->label_work->setStyleSheet("color: blue;");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case WorkStatus::Completed:
|
|
|
|
|
|
ui->label_work->setStyleSheet("color: green; font-weight: bold;");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case WorkStatus::Error:
|
|
|
|
|
|
ui->label_work->setStyleSheet("color: red; font-weight: bold;");
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
ui->label_work->setStyleSheet("");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-08 23:51:48 +08:00
|
|
|
|
void MainWindow::updateDetectionResultDisplay(const DetectionResult& result)
|
|
|
|
|
|
{
|
2025-06-17 00:37:05 +08:00
|
|
|
|
// 显示检测图像
|
2025-06-08 23:51:48 +08:00
|
|
|
|
displayImage(result.image);
|
2025-06-17 00:37:05 +08:00
|
|
|
|
|
|
|
|
|
|
// 更新检测结果到列表
|
2025-06-08 23:51:48 +08:00
|
|
|
|
addDetectionResult(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_action_camera_1_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
IVrEyeDevice* pDevice = m_presenter->GetEyeDevice(0);
|
|
|
|
|
|
if(nullptr == pDevice){
|
|
|
|
|
|
QMessageBox::warning(this, "设备错误", "相机设备未正确初始化!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(nullptr == ui_dialogCamera){
|
|
|
|
|
|
ui_dialogCamera = new DialogCamera(pDevice, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
ui_dialogCamera->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_action_camera_2_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
IVrEyeDevice* pDevice = m_presenter->GetEyeDevice(1);
|
|
|
|
|
|
if(nullptr == pDevice){
|
|
|
|
|
|
QMessageBox::warning(this, "设备错误", "相机设备未正确初始化!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(nullptr == ui_dialogCamera){
|
|
|
|
|
|
ui_dialogCamera = new DialogCamera(pDevice, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
ui_dialogCamera->show();
|
|
|
|
|
|
}
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-06-17 00:37:05 +08:00
|
|
|
|
void MainWindow::on_action_tool_debug_data_triggered()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 打开文件选择对话框
|
|
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(
|
|
|
|
|
|
this,
|
|
|
|
|
|
tr("选择调试数据文件"),
|
|
|
|
|
|
QString(),
|
|
|
|
|
|
tr("激光数据文件 (*.txt);;所有文件 (*.*)")
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (fileName.isEmpty()) {
|
|
|
|
|
|
// 用户取消了文件选择
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查Presenter是否已初始化
|
|
|
|
|
|
if (!m_presenter) {
|
|
|
|
|
|
QMessageBox::warning(this, tr("错误"), tr("系统未正确初始化!"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-19 01:38:50 +08:00
|
|
|
|
// 清空检测日志,开始新的检测
|
|
|
|
|
|
clearDetectionLog();
|
|
|
|
|
|
|
2025-06-17 00:37:05 +08:00
|
|
|
|
std::thread t([this, fileName]() {
|
|
|
|
|
|
updateStatusLog(tr("正在加载调试数据文件: %1").arg(fileName));
|
|
|
|
|
|
int result = m_presenter->LoadDebugDataAndDetect(fileName.toStdString());
|
|
|
|
|
|
|
|
|
|
|
|
if (result == 0) {
|
|
|
|
|
|
updateStatusLog(tr("调试数据加载和检测成功"));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
QString errorMsg = tr("调试数据加载失败,错误码: %1").arg(result);
|
|
|
|
|
|
updateStatusLog(errorMsg);
|
|
|
|
|
|
QMessageBox::warning(this, tr("错误"), errorMsg);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
t.detach();
|
|
|
|
|
|
}
|
2025-06-08 12:48:04 +08:00
|
|
|
|
|
2025-06-19 01:38:50 +08:00
|
|
|
|
void MainWindow::updateDetectionLog(const QString& message)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 在UI线程中更新detect_log控件(QListView)
|
|
|
|
|
|
if (m_logModel) {
|
|
|
|
|
|
// 添加时间戳(包含年月日)
|
|
|
|
|
|
QString timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
|
QString logEntry = QString("[%1] %2").arg(timestamp).arg(message);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前数据
|
|
|
|
|
|
QStringList logList = m_logModel->stringList();
|
|
|
|
|
|
|
|
|
|
|
|
// 添加新的日志条目
|
|
|
|
|
|
logList.append(logEntry);
|
|
|
|
|
|
|
|
|
|
|
|
// 更新模型
|
|
|
|
|
|
m_logModel->setStringList(logList);
|
|
|
|
|
|
|
|
|
|
|
|
// 自动滚动到最底部
|
|
|
|
|
|
QModelIndex lastIndex = m_logModel->index(logList.size() - 1);
|
|
|
|
|
|
ui->detect_log->scrollTo(lastIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::clearDetectionLogUI()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 在UI线程中清空检测日志
|
|
|
|
|
|
if (m_logModel) {
|
|
|
|
|
|
m_logModel->setStringList(QStringList());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|