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->setRowAndColumn(m_row, m_column);
  103. /* 设置每个项的信息 */
  104. settingNum->setEveryEyeMapInfo(GEyeMapInfo.getEyeMapInfo());
  105. /* 设置可选的通道信息 */
  106. settingNum->setChannelList(GEyeMapInfo.getChannelInfo());
  107. settingNum->exec();
  108. /* 判断是否点击的是ok,是则重新布局 */
  109. if(!settingNum->isOk)
  110. {
  111. return;
  112. }
  113. /* 先暂停所有的采集 */
  114. GOscDataInfo.stopAllCapture();
  115. m_row = settingNum->m_row;
  116. m_column = settingNum->m_column;
  117. eyeMapLayout();
  118. /* 重置眼图数据矩阵 */
  119. resetMatrix();
  120. /* 开启采集 */
  121. GOscDataInfo.startAllCapture();
  122. }
  123. /* 设置眼图参数的槽函数 */
  124. void EyeMapWidget::do_pBtnSettingParam()
  125. {
  126. std::shared_ptr<ParamConfig> paramConfig = std::make_shared<ParamConfig>();
  127. paramConfig->createItem(GEyeMapInfo.getEyeMapInfo());
  128. paramConfig->exec();
  129. /* 判断是否点击了确定按钮 */
  130. if(!paramConfig->isOk)
  131. {
  132. return;
  133. }
  134. GOscDataInfo.stopAllCapture();
  135. /* 重置眼图数据矩阵 */
  136. resetMatrix();
  137. /* 根据已经被更新好的全局眼图参数,对示波器类单独设置 */
  138. for(const auto &it : GEyeMapInfo.getEyeMapList())
  139. {
  140. /* 根据通道号更新电压值 */
  141. GOscDataInfo.setVoltageRange(it->getChannelInfo().channel, it->getVoltageRange());
  142. /* 更新时间刻度 */
  143. GOscDataInfo.setTimeGridValue(it->getChannelInfo().channel, it->getTimeGridValue());
  144. }
  145. /* 开启采集 */
  146. GOscDataInfo.startAllCapture();
  147. }
  148. /* 初始化眼图 */
  149. void EyeMapWidget::initEyeMap()
  150. {
  151. /* 创建8个眼图 */
  152. for(const auto &it : GEyeMapInfo.listInitEyeMapInfo)
  153. {
  154. OneEyeMap* oneEyeMap = new OneEyeMap(ui->widget_container);
  155. oneEyeMap->setNum(it.num);
  156. oneEyeMap->setTitle(it.title);
  157. oneEyeMap->setTitleBarColor(it.titleBarColor);
  158. oneEyeMap->setVoltageRange(it.voltageRange);
  159. oneEyeMap->setChannelInfo(it.channelInfo);
  160. oneEyeMap->setTimeGridValue(it.tGridValue);
  161. oneEyeMap->setEyeDataPtrFromOscData(it.channelInfo.channel);
  162. oneEyeMap->hide();
  163. GEyeMapInfo.addEyeMapPtr(oneEyeMap);
  164. }
  165. m_row = GEyeMapInfo.row;
  166. m_column = GEyeMapInfo.column;
  167. eyeMapLayout();
  168. /* 根据示波器打开的情况判断是刷新网格还是显示“暂无设备” */
  169. for(const auto &it : GOscDataInfo.getOsc())
  170. {
  171. GEyeMapInfo.setEyeMapOscOpen(it->getOscNum(), it->isOpen());
  172. }
  173. update();
  174. }
  175. /* 排列眼图布局 */
  176. void EyeMapWidget::eyeMapLayout()
  177. {
  178. // SPDLOG_LOGGER_DEBUG(m_logger, "眼图显示区域总大小: width = {}, height = {}", ui->widget_container->width(), ui->widget_container->height());
  179. /* 计算每个模块的大小 */
  180. int oneWidth = 0;
  181. int oneHeight = 0;
  182. // for(const auto &it : GEyeMapInfo.getEyeMapList())
  183. // {
  184. // if(it->isVisible())
  185. // {
  186. // m_showNum++;
  187. // }
  188. // }
  189. int num = m_row * m_column;
  190. if(num == 0)
  191. {
  192. return;
  193. }
  194. /* 只有1个 */
  195. else if (num == 1)
  196. {
  197. oneWidth = ui->widget_container->width() - m_marginLeft - m_marginRight;
  198. oneHeight = ui->widget_container->height() - m_marginTop - m_marginBottom;
  199. }
  200. /* 两个 */
  201. else if(num == 2)
  202. {
  203. oneWidth = (ui->widget_container->width() - m_marginLeft - m_marginRight);
  204. oneHeight = ( ui->widget_container->height() - m_marginTop - m_marginBottom - m_spacing ) / 2;
  205. }
  206. /* 4、6、8个 */
  207. else if(num == 4 || num == 6 || num == 8)
  208. {
  209. oneWidth = (ui->widget_container->width() - m_marginLeft - m_marginRight - m_spacing) / 2;
  210. oneHeight = ( ui->widget_container->height() - m_marginTop - m_marginBottom - (m_spacing * (num / 2 - 1)) ) / (num / 2);
  211. }
  212. /* 重新设置每个模块的大小 */
  213. for(const auto &it : GEyeMapInfo.getEyeMapList())
  214. {
  215. it->resize(oneWidth, oneHeight);
  216. // SPDLOG_LOGGER_DEBUG(m_logger, "oneWidth = {}, oneHeight = {}, OneEyeMap.width = {}, OneEyeMap.height = {}", oneWidth, oneHeight, it->width(), it->height());
  217. }
  218. /* 排列位置 */
  219. for(const auto &it : GEyeMapInfo.getEyeMapList())
  220. {
  221. if(num == 1)
  222. {
  223. it->move(m_marginLeft, m_marginTop);
  224. break;
  225. }
  226. else if(num == 2)
  227. {
  228. int row = it->getNum() % 2 == 1 ? 0 : 1;
  229. int dx = m_marginLeft;
  230. int dy = m_marginTop + row * (oneHeight + m_spacing);
  231. it->move(dx, dy);
  232. if(it->getNum() == 2)
  233. {
  234. break;
  235. }
  236. }
  237. else
  238. {
  239. /* 奇数放左边,偶数放右边 */
  240. int row = ( it->getNum() - 1) / 2;
  241. int column = ( it->getNum() % 2 == 1 ) ? 0 : 1;
  242. int dx = m_marginLeft + column * (oneWidth + m_spacing);
  243. int dy = m_marginTop + row * (oneHeight + m_spacing);
  244. it->move(dx, dy);
  245. if(it->getNum() == num)
  246. {
  247. break;
  248. }
  249. }
  250. }
  251. /* 设置显示或隐藏 */
  252. for(const auto &it : GEyeMapInfo.getEyeMapList())
  253. {
  254. if(it->getNum() <= num)
  255. {
  256. it->setShow(true);
  257. } else
  258. {
  259. it->setShow(false);
  260. }
  261. }
  262. }
  263. /* 清空数据矩阵内容 */
  264. void EyeMapWidget::resetMatrix()
  265. {
  266. /* 重新初始化数据矩阵 */
  267. GOscDataInfo.resetDataMatrix();
  268. /* 每个眼图模块的大小都是一样的,所以这里获取序号为1的眼图大小,1号是肯定会显示的 */
  269. auto pEyeMap = GEyeMapInfo.findEyeMap(1);
  270. if(pEyeMap == nullptr)
  271. {
  272. return;
  273. }
  274. auto size = pEyeMap->getEyeMapSize();
  275. GOscDataInfo.resetColorMatrix(size.width(), size.height());
  276. }