123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- #include "eyemapwidget.h"
- #include "ui_eyemapwidget.h"
- #include <QDebug>
- #include <QFile>
- #include <QDateTime>
- #include "settingnum.h"
- #include "OneEyeMap.h"
- #include "EyeMapInfo.h"
- #include "paramconfig.h"
- #include "warning.h"
- #include "OscDataInfo.h"
- #include "OneOsc.h"
- EyeMapWidget::EyeMapWidget(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::EyeMapWidget)
- {
- ui->setupUi(this);
- m_logger = spdlog::get("EyeMap");
- if(m_logger == nullptr)
- {
- qDebug() << "获取 EyeMap logger 失败";
- return;
- }
- /* 设置软件名称 */
- this->setWindowTitle("EyePattern");
- /* 设置无边框和自动全屏 */
- this->setWindowFlags(Qt::FramelessWindowHint);
- this->setWindowState(Qt::WindowFullScreen);
- /* 打印一些基础信息 */
- SPDLOG_LOGGER_INFO(m_logger, "屏幕分辨率:{}x{}", this->width(), this->height());
- /* 加载QSS文件 */
- QFile fileQss(":/qss/EyeMapWidget/EyeMapWidget.qss");
- if(fileQss.open(QFile::ReadOnly))
- {
- QString qss = fileQss.readAll();
- this->setStyleSheet(qss);
- fileQss.close();
- } else
- {
- SPDLOG_LOGGER_ERROR(m_logger, "加载QSS文件失败");
- }
- /* 获取日期和时间,启动时间定时器 */
- QDate date = QDate::currentDate();
- QString strDate = date.toString("yyyy-MM-dd");
- QString strWeek = date.toString("dddd");
- ui->label_date->setText(strDate + " " + strWeek);
- QDateTime time = QDateTime::currentDateTime();
- QString strTime = time.toString("hh:mm:ss");
- ui->label_time->setText(strTime);
- m_timerTime.setTimerType(Qt::PreciseTimer);
- m_timerTime.setSingleShot(false);
- initEyeMap();
- /* 连接信号和槽 */
- connect(ui->pBtn_exit, &QPushButton::clicked, this, &EyeMapWidget::do_exit);
- connect(&m_timerTime, &QTimer::timeout, this, &EyeMapWidget::do_timeWalk);
- connect(ui->pBtn_settingNum, &QPushButton::clicked, this, &EyeMapWidget::do_pBtnSettingNum);
- connect(ui->pBtn_settingScale, &QPushButton::clicked, this, &EyeMapWidget::do_pBtnSettingParam);
- m_timerTime.start(1000);
- }
- EyeMapWidget::~EyeMapWidget()
- {
- /* 停止采集数据 */
- GOscDataInfo.stopAllCapture();
- delete ui;
- }
- /* 开始采集 */
- void EyeMapWidget::startCapture()
- {
- GOscDataInfo.startAllCapture();
- }
- void EyeMapWidget::do_exit()
- {
- Warning warning;
- warning.setText("是否退出程序?");
- warning.exec();
- if(!warning.isOk())
- {
- return;
- }
- /* 更新GEyeMapInfo的初始化数据,防止这个类析构了一起把8个眼图模块都析构了,数据消失了 */
- GEyeMapInfo.updateInitEyeMapInfo();
- GEyeMapInfo.row = m_row;
- GEyeMapInfo.column = m_column;
- GEyeMapInfo.updateSaveFile();
- this->close();
- }
- /* 时间跳动槽函数 */
- void EyeMapWidget::do_timeWalk()
- {
- /* 获取时间 */
- QTime time = QTime::currentTime();
- QString strTime = time.toString("hh:mm:ss");
- ui->label_time->setText(strTime);
- }
- /* 设置眼图个数页面的槽函数 */
- void EyeMapWidget::do_pBtnSettingNum()
- {
- std::shared_ptr<SettingNum> settingNum = std::make_shared<SettingNum>();
- // for(const auto &it : GEyeMapInfo.getEyeMapList())
- // {
- // SPDLOG_LOGGER_DEBUG(m_logger, "眼图序号: {}, 通道号:{} ", it->getNum(), it->getChannelInfo().channelName.toStdString());
- // }
- /* 弹窗不能设置父指针,这里川润 父指针给内部其他组件使用 */
- settingNum->setParentPtr(this);
- /* 设置眼图显示的个数 */
- settingNum->setRowAndColumn(m_row, m_column);
- /* 设置每个项的信息 */
- settingNum->setEveryEyeMapInfo(GEyeMapInfo.getEyeMapInfo());
- /* 设置可选的通道信息 */
- settingNum->setChannelList(GEyeMapInfo.getChannelInfo());
- settingNum->exec();
- /* 判断是否点击的是ok,是则重新布局 */
- if(!settingNum->isOk)
- {
- return;
- }
- /* 先暂停所有的采集 */
- GOscDataInfo.stopAllCapture();
- m_row = settingNum->m_row;
- m_column = settingNum->m_column;
- /* 排列布局眼图 */
- eyeMapLayout();
- /* 重置眼图数据矩阵 */
- resetMatrix();
-
- /* 开启采集 */
- GOscDataInfo.startAllCapture();
- }
- /* 设置眼图参数的槽函数 */
- void EyeMapWidget::do_pBtnSettingParam()
- {
- std::shared_ptr<ParamConfig> paramConfig = std::make_shared<ParamConfig>();
- paramConfig->createItem(GEyeMapInfo.getEyeMapInfo());
- paramConfig->exec();
- /* 判断是否点击了确定按钮 */
- if(!paramConfig->isOk)
- {
- return;
- }
- GOscDataInfo.stopAllCapture();
- /* 重置眼图数据矩阵 */
- resetMatrix();
- /* 根据已经被更新好的全局眼图参数,对示波器类单独设置 */
- for(const auto &it : GEyeMapInfo.getEyeMapList())
- {
- /* 根据通道号更新电压值 */
- GOscDataInfo.setVoltageRange(it->getChannelInfo().channel, it->getVoltageRange());
- /* 更新时间刻度 */
- GOscDataInfo.setTimeGridValue(it->getChannelInfo().channel, it->getTimeGridValue());
- }
- /* 开启采集 */
- GOscDataInfo.startAllCapture();
- }
- /* 初始化眼图 */
- void EyeMapWidget::initEyeMap()
- {
- /* 创建8个眼图 */
- for(const auto &it : GEyeMapInfo.listInitEyeMapInfo)
- {
- OneEyeMap* oneEyeMap = new OneEyeMap(ui->widget_container);
- // oneEyeMap->setUID(it.uid);
- oneEyeMap->setNum(it.num);
- oneEyeMap->setTitle(it.title);
- oneEyeMap->setTitleBarColor(it.titleBarColor);
- oneEyeMap->setVoltageRange(it.voltageRange);
- oneEyeMap->setChannelInfo(it.channelInfo);
- oneEyeMap->setTimeGridValue(it.tGridValue);
- /* 将眼图显示实例和示波器实例对应上 */
- oneEyeMap->getOneOscFromGlobalOscData();
- oneEyeMap->hide();
- GEyeMapInfo.addEyeMapPtr(oneEyeMap);
-
- /* 设置示波器类的初始化信息 */
- GOscDataInfo.setVoltageRange(it.channelInfo.channel, it.voltageRange);
- GOscDataInfo.setTimeGridValue(it.channelInfo.channel, it.tGridValue);
- }
- m_row = GEyeMapInfo.row;
- m_column = GEyeMapInfo.column;
- /* 排列眼图,在排列的过程中,会对示波器设置是否有显示的眼图 */
- eyeMapLayout();
- /* 根据示波器打开的情况判断是刷新网格还是显示“暂无设备” */
- for(const auto &it : GOscDataInfo.getOsc())
- {
- GEyeMapInfo.setEyeMapOscOpen(it->getOscNum(), it->isOpen());
- }
- update();
- }
- /**
- * @brief 排列眼图布局,在排列的过程中会设置眼图是否有显示
- *
- */
- void EyeMapWidget::eyeMapLayout()
- {
- // SPDLOG_LOGGER_DEBUG(m_logger, "眼图显示区域总大小: width = {}, height = {}", ui->widget_container->width(), ui->widget_container->height());
- /* 计算每个模块的大小 */
- int oneWidth = 0;
- int oneHeight = 0;
- // for(const auto &it : GEyeMapInfo.getEyeMapList())
- // {
- // if(it->isVisible())
- // {
- // m_showNum++;
- // }
- // }
- int num = m_row * m_column;
- if(num == 0)
- {
- return;
- }
- /* 只有1个 */
- else if (num == 1)
- {
- oneWidth = ui->widget_container->width() - m_marginLeft - m_marginRight;
- oneHeight = ui->widget_container->height() - m_marginTop - m_marginBottom;
- }
- /* 两个 */
- else if(num == 2)
- {
- oneWidth = (ui->widget_container->width() - m_marginLeft - m_marginRight);
- oneHeight = ( ui->widget_container->height() - m_marginTop - m_marginBottom - m_spacing ) / 2;
- }
- /* 4、6、8个 */
- else if(num == 4 || num == 6 || num == 8)
- {
- oneWidth = (ui->widget_container->width() - m_marginLeft - m_marginRight - m_spacing) / 2;
- oneHeight = ( ui->widget_container->height() - m_marginTop - m_marginBottom - (m_spacing * (num / 2 - 1)) ) / (num / 2);
- }
- /* 重新设置每个模块的大小 */
- for(const auto &it : GEyeMapInfo.getEyeMapList())
- {
- it->resize(oneWidth, oneHeight);
- // SPDLOG_LOGGER_DEBUG(m_logger, "oneWidth = {}, oneHeight = {}, OneEyeMap.width = {}, OneEyeMap.height = {}", oneWidth, oneHeight, it->width(), it->height());
- }
- /* 排列位置 */
- for(const auto &it : GEyeMapInfo.getEyeMapList())
- {
- if(num == 1)
- {
- it->move(m_marginLeft, m_marginTop);
- break;
- }
- else if(num == 2)
- {
- int row = it->getNum() % 2 == 1 ? 0 : 1;
- int dx = m_marginLeft;
- int dy = m_marginTop + row * (oneHeight + m_spacing);
- it->move(dx, dy);
- if(it->getNum() == 2)
- {
- break;
- }
- }
- else
- {
- /* 奇数放左边,偶数放右边 */
- int mapNum = it->getNum();
- int row = ( mapNum - 1) / 2;
- int column = ( mapNum % 2 == 1 ) ? 0 : 1;
- int dx = m_marginLeft + column * (oneWidth + m_spacing);
- int dy = m_marginTop + row * (oneHeight + m_spacing);
- it->move(dx, dy);
- // if(mapNum == num)
- // {
- // break;
- // }
- }
- }
- /* 设置显示或隐藏 */
- for(const auto &it : GEyeMapInfo.getEyeMapList())
- {
- // SPDLOG_LOGGER_DEBUG(m_logger, "设置显示: 序号: {}, 通道: {}, 是否显示: {}", it->getNum(), it->getChannelInfo().channelName.toStdString(), it->getShow());
- if((it->getNum() <= num) && (it->getNum() != 0))
- {
- it->setShow(true);
- } else
- {
- it->setShow(false);
- }
- }
- }
- /* 清空数据矩阵内容 */
- void EyeMapWidget::resetMatrix()
- {
- /* 重新初始化数据矩阵 */
- GOscDataInfo.resetDevMatrix();
- /* 重新初始化眼图模块的颜色矩阵 */
- GEyeMapInfo.resetAllEyeMap();
- }
|