eyemapwidget.cpp 9.0 KB

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