eyemapwidget.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #include "eyemapwidget.h"
  2. #include "ui_eyemapwidget.h"
  3. #include <QDebug>
  4. #include <QFile>
  5. #include <QDateTime>
  6. #include "settingnum.h"
  7. #include "OneEyeMap.h"
  8. #include "EyeMapInfo.h"
  9. #include "paramconfig.h"
  10. #include "warning.h"
  11. #include "OscDataInfo.h"
  12. #include "OneOsc.h"
  13. EyeMapWidget::EyeMapWidget(QWidget *parent) :
  14. QWidget(parent),
  15. ui(new Ui::EyeMapWidget)
  16. {
  17. ui->setupUi(this);
  18. m_logger = spdlog::get("EyeMap");
  19. if(m_logger == nullptr)
  20. {
  21. qDebug() << "获取 EyeMap logger 失败";
  22. return;
  23. }
  24. /* 设置软件名称 */
  25. this->setWindowTitle("EyePattern");
  26. /* 设置无边框和自动全屏 */
  27. this->setWindowFlags(Qt::FramelessWindowHint);
  28. this->setWindowState(Qt::WindowFullScreen);
  29. /* 打印一些基础信息 */
  30. SPDLOG_LOGGER_INFO(m_logger, "屏幕分辨率:{}x{}", this->width(), this->height());
  31. /* 加载QSS文件 */
  32. QFile fileQss(":/qss/EyeMapWidget/EyeMapWidget.qss");
  33. if(fileQss.open(QFile::ReadOnly))
  34. {
  35. QString qss = fileQss.readAll();
  36. this->setStyleSheet(qss);
  37. fileQss.close();
  38. } else
  39. {
  40. SPDLOG_LOGGER_ERROR(m_logger, "加载QSS文件失败");
  41. }
  42. /* 获取日期和时间,启动时间定时器 */
  43. QDate date = QDate::currentDate();
  44. QString strDate = date.toString("yyyy-MM-dd");
  45. QString strWeek = date.toString("dddd");
  46. ui->label_date->setText(strDate + " " + strWeek);
  47. QDateTime time = QDateTime::currentDateTime();
  48. QString strTime = time.toString("hh:mm:ss");
  49. ui->label_time->setText(strTime);
  50. m_timerTime.setTimerType(Qt::PreciseTimer);
  51. m_timerTime.setSingleShot(false);
  52. initEyeMap();
  53. /* 连接信号和槽 */
  54. connect(ui->pBtn_exit, &QPushButton::clicked, this, &EyeMapWidget::do_exit);
  55. connect(&m_timerTime, &QTimer::timeout, this, &EyeMapWidget::do_timeWalk);
  56. connect(ui->pBtn_settingNum, &QPushButton::clicked, this, &EyeMapWidget::do_pBtnSettingNum);
  57. connect(ui->pBtn_settingScale, &QPushButton::clicked, this, &EyeMapWidget::do_pBtnSettingParam);
  58. m_timerTime.start(1000);
  59. }
  60. EyeMapWidget::~EyeMapWidget()
  61. {
  62. /* 停止采集数据 */
  63. GOscDataInfo.stopAllCapture();
  64. delete ui;
  65. }
  66. /* 开始采集 */
  67. void EyeMapWidget::startCapture()
  68. {
  69. GOscDataInfo.startAllCapture();
  70. }
  71. void EyeMapWidget::do_exit()
  72. {
  73. Warning warning;
  74. warning.setText("是否退出程序?");
  75. warning.exec();
  76. if(!warning.isOk())
  77. {
  78. return;
  79. }
  80. /* 更新GEyeMapInfo的初始化数据,防止这个类析构了一起把8个眼图模块都析构了,数据消失了 */
  81. GEyeMapInfo.updateInitEyeMapInfo();
  82. GEyeMapInfo.row = m_row;
  83. GEyeMapInfo.column = m_column;
  84. GEyeMapInfo.updateSaveFile();
  85. this->close();
  86. }
  87. /* 时间跳动槽函数 */
  88. void EyeMapWidget::do_timeWalk()
  89. {
  90. /* 获取时间 */
  91. QTime time = QTime::currentTime();
  92. QString strTime = time.toString("hh:mm:ss");
  93. ui->label_time->setText(strTime);
  94. }
  95. /* 设置眼图个数页面的槽函数 */
  96. void EyeMapWidget::do_pBtnSettingNum()
  97. {
  98. std::shared_ptr<SettingNum> settingNum = std::make_shared<SettingNum>();
  99. // for(const auto &it : GEyeMapInfo.getEyeMapList())
  100. // {
  101. // SPDLOG_LOGGER_DEBUG(m_logger, "眼图序号: {}, 通道号:{} ", it->getNum(), it->getChannelInfo().channelName.toStdString());
  102. // }
  103. /* 弹窗不能设置父指针,这里川润 父指针给内部其他组件使用 */
  104. settingNum->setParentPtr(this);
  105. /* 设置眼图显示的个数 */
  106. settingNum->setRowAndColumn(m_row, m_column);
  107. /* 设置可选的通道信息,每次获取一次就刷新一次状态 */
  108. settingNum->setChannelList(GEyeMapInfo.getChannelInfo());
  109. /* 设置每个项的信息 */
  110. settingNum->setEveryEyeMapInfo(GEyeMapInfo.getEyeMapInfo());
  111. settingNum->exec();
  112. /* 判断是否点击的是ok,是则重新布局 */
  113. if(!settingNum->isOk)
  114. {
  115. return;
  116. }
  117. /* 先暂停所有的采集 */
  118. GOscDataInfo.stopAllCapture();
  119. m_row = settingNum->m_row;
  120. m_column = settingNum->m_column;
  121. /* 排列布局眼图 */
  122. eyeMapLayout();
  123. /* 重置眼图数据矩阵 */
  124. resetMatrix();
  125. /* 开启采集 */
  126. GOscDataInfo.startAllCapture();
  127. }
  128. /* 设置眼图参数的槽函数 */
  129. void EyeMapWidget::do_pBtnSettingParam()
  130. {
  131. std::shared_ptr<ParamConfig> paramConfig = std::make_shared<ParamConfig>();
  132. paramConfig->createItem(GEyeMapInfo.getEyeMapInfo());
  133. paramConfig->exec();
  134. /* 判断是否点击了确定按钮 */
  135. if(!paramConfig->isOk)
  136. {
  137. return;
  138. }
  139. GOscDataInfo.stopAllCapture();
  140. /* 重置眼图数据矩阵 */
  141. resetMatrix();
  142. /* 根据已经被更新好的全局眼图参数,对示波器类单独设置 */
  143. for(const auto &it : GEyeMapInfo.getEyeMapList())
  144. {
  145. /* 根据通道号更新电压值 */
  146. GOscDataInfo.setVoltageRange(it->getChannelInfo().channel, it->getVoltageRange());
  147. /* 更新时间刻度 */
  148. GOscDataInfo.setTimeGridValue(it->getChannelInfo().channel, it->getTimeGridValue());
  149. }
  150. /* 开启采集 */
  151. GOscDataInfo.startAllCapture();
  152. }
  153. /* 初始化眼图 */
  154. void EyeMapWidget::initEyeMap()
  155. {
  156. /* 创建8个眼图 */
  157. for(const auto &it : GEyeMapInfo.listInitEyeMapInfo)
  158. {
  159. OneEyeMap* oneEyeMap = new OneEyeMap(ui->widget_container);
  160. // oneEyeMap->setUID(it.uid);
  161. oneEyeMap->setNum(it.num);
  162. oneEyeMap->setTitle(it.title);
  163. oneEyeMap->setTitleBarColor(it.titleBarColor);
  164. oneEyeMap->setVoltageRange(it.voltageRange);
  165. oneEyeMap->setChannelInfo(it.channelInfo);
  166. oneEyeMap->setTimeGridValue(it.tGridValue);
  167. /* 将眼图显示实例和示波器实例对应上 */
  168. oneEyeMap->getOneOscFromGlobalOscData();
  169. oneEyeMap->hide();
  170. GEyeMapInfo.addEyeMapPtr(oneEyeMap);
  171. /* 设置示波器类的初始化信息 */
  172. GOscDataInfo.setVoltageRange(it.channelInfo.channel, it.voltageRange);
  173. GOscDataInfo.setTimeGridValue(it.channelInfo.channel, it.tGridValue);
  174. }
  175. m_row = GEyeMapInfo.row;
  176. m_column = GEyeMapInfo.column;
  177. /* 排列眼图,在排列的过程中,会对示波器设置是否有显示的眼图 */
  178. eyeMapLayout();
  179. /* 根据示波器打开的情况判断是刷新网格还是显示“暂无设备” */
  180. for(const auto &it : GOscDataInfo.getOsc())
  181. {
  182. GEyeMapInfo.setEyeMapOscOpen(it->getOscNum(), it->isOpen());
  183. }
  184. update();
  185. }
  186. /**
  187. * @brief 排列眼图布局,在排列的过程中会设置眼图是否有显示
  188. *
  189. */
  190. void EyeMapWidget::eyeMapLayout()
  191. {
  192. // SPDLOG_LOGGER_DEBUG(m_logger, "眼图显示区域总大小: width = {}, height = {}", ui->widget_container->width(), ui->widget_container->height());
  193. /* 计算每个模块的大小 */
  194. int oneWidth = 0;
  195. int oneHeight = 0;
  196. // for(const auto &it : GEyeMapInfo.getEyeMapList())
  197. // {
  198. // if(it->isVisible())
  199. // {
  200. // m_showNum++;
  201. // }
  202. // }
  203. int num = m_row * m_column;
  204. if(num == 0)
  205. {
  206. return;
  207. }
  208. /* 只有1个 */
  209. else if (num == 1)
  210. {
  211. oneWidth = ui->widget_container->width() - m_marginLeft - m_marginRight;
  212. oneHeight = ui->widget_container->height() - m_marginTop - m_marginBottom;
  213. }
  214. /* 两个 */
  215. else if(num == 2)
  216. {
  217. oneWidth = (ui->widget_container->width() - m_marginLeft - m_marginRight);
  218. oneHeight = ( ui->widget_container->height() - m_marginTop - m_marginBottom - m_spacing ) / 2;
  219. }
  220. /* 4、6、8个 */
  221. else if(num == 4 || num == 6 || num == 8)
  222. {
  223. oneWidth = (ui->widget_container->width() - m_marginLeft - m_marginRight - m_spacing) / 2;
  224. oneHeight = ( ui->widget_container->height() - m_marginTop - m_marginBottom - (m_spacing * (num / 2 - 1)) ) / (num / 2);
  225. }
  226. /* 重新设置每个模块的大小 */
  227. for(const auto &it : GEyeMapInfo.getEyeMapList())
  228. {
  229. it->resize(oneWidth, oneHeight);
  230. // SPDLOG_LOGGER_DEBUG(m_logger, "oneWidth = {}, oneHeight = {}, OneEyeMap.width = {}, OneEyeMap.height = {}", oneWidth, oneHeight, it->width(), it->height());
  231. }
  232. /* 排列位置 */
  233. for(const auto &it : GEyeMapInfo.getEyeMapList())
  234. {
  235. if(num == 1)
  236. {
  237. it->move(m_marginLeft, m_marginTop);
  238. break;
  239. }
  240. else if(num == 2)
  241. {
  242. int row = it->getNum() % 2 == 1 ? 0 : 1;
  243. int dx = m_marginLeft;
  244. int dy = m_marginTop + row * (oneHeight + m_spacing);
  245. it->move(dx, dy);
  246. if(it->getNum() == 2)
  247. {
  248. break;
  249. }
  250. }
  251. else
  252. {
  253. /* 奇数放左边,偶数放右边 */
  254. int mapNum = it->getNum();
  255. int row = ( mapNum - 1) / 2;
  256. int column = ( mapNum % 2 == 1 ) ? 0 : 1;
  257. int dx = m_marginLeft + column * (oneWidth + m_spacing);
  258. int dy = m_marginTop + row * (oneHeight + m_spacing);
  259. it->move(dx, dy);
  260. // if(mapNum == num)
  261. // {
  262. // break;
  263. // }
  264. }
  265. }
  266. /* 设置显示或隐藏 */
  267. for(const auto &it : GEyeMapInfo.getEyeMapList())
  268. {
  269. // SPDLOG_LOGGER_DEBUG(m_logger, "设置显示: 序号: {}, 通道: {}, 是否显示: {}", it->getNum(), it->getChannelInfo().channelName.toStdString(), it->getShow());
  270. if((it->getNum() <= num) && (it->getNum() != 0))
  271. {
  272. it->setShow(true);
  273. } else
  274. {
  275. it->setShow(false);
  276. }
  277. }
  278. }
  279. /* 清空数据矩阵内容 */
  280. void EyeMapWidget::resetMatrix()
  281. {
  282. /* 重新初始化数据矩阵 */
  283. GOscDataInfo.resetDevMatrix();
  284. /* 重新初始化眼图模块的颜色矩阵 */
  285. GEyeMapInfo.resetAllEyeMap();
  286. }