widget.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #include "widget.h"
  2. #include "ui_widget.h"
  3. // #include "LHQLogAPI.h"
  4. // #include "lhstylemanager.h"
  5. #include "spdlog/spdlog.h"
  6. // #include "TransmitterswitchInfo.h"
  7. // #include "lhtranmitterswitch.h"
  8. Widget::Widget(QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::Widget)
  11. {
  12. ui->setupUi(this);
  13. ui->pBtn_useEQM->setCheckable(true);
  14. m_tSwitch = new LHTransmitterSwitchAPI();
  15. if(m_tSwitch->loadLibrary())
  16. {
  17. SPDLOG_INFO("load library success");
  18. }else {
  19. SPDLOG_ERROR("load library failed");
  20. }
  21. /* 设置一个布局 */
  22. m_layout = new QVBoxLayout(ui->widget_content);
  23. ui->widget_content->setLayout(m_layout);
  24. /* 添加一个容器 */
  25. QWidget* container = new QWidget(this);
  26. container->setObjectName("container");
  27. m_layout->addWidget(container);
  28. container->setStyleSheet(R"(background: transparent;)");
  29. /* 设置边距为0 */
  30. m_layout->setMargin(20);
  31. m_layout->setSpacing(0);
  32. ui->widget_content->setStyleSheet(R"(background: #000000;)");
  33. /* 初始化WebAPI */
  34. InitData initData;
  35. initData.url = "http://192.1.3.133:31000/v6/";
  36. initData.serverID = "2e36b53ccd2a433b9a803b98d683ed91";
  37. // initData.url = "http://192.1.3.136:31000/v6/";
  38. // initData.serverID = "2e36b53ccd2a433b9a803b98d683ed91";
  39. initData.serverKey = "TMS";
  40. m_tSwitch->DoInit(&initData);
  41. m_tSwitch->DoCreateWindow(1, container);
  42. m_tSwitch->DoGetExecPlanFromEQM();
  43. m_tSwitch->DoSetCallBack(trackCallBack);
  44. // m_tSwitch->DoInitLibrary();
  45. // m_tSwitch->DoCreateOneWindow(0, container);
  46. // m_tSwitch->DoSetOnePageCardNum(4, 2);
  47. // m_tSwitch->DoSetWebAPIInfo(&initData);
  48. ExecPlanInfo info;
  49. info.ChannelID = -1;
  50. info.ChannelName = "";
  51. info.DatabasePath = QApplication::applicationDirPath() + "/db/";
  52. // m_tSwitch->DoSetChannelInfo(&info, true);
  53. // m_tSwitch->DoSetCallBack(trackCallBack);
  54. // m_tSwitch->DoGetExecPlanFromEQM();
  55. m_style = 1;
  56. /* 添加设备信息,测试用 */
  57. // addTestDevice();
  58. SPDLOG_INFO("Widget init success");
  59. }
  60. Widget::~Widget()
  61. {
  62. // if(m_tSwitch != nullptr)
  63. // {
  64. // delete m_tSwitch;
  65. // m_tSwitch = nullptr;
  66. // }
  67. // if(m_layout != nullptr)
  68. // {
  69. // delete m_layout;
  70. // m_layout = nullptr;
  71. // }
  72. delete ui;
  73. }
  74. /* 导入数据按钮 */
  75. void Widget::on_pBtn_getData_clicked()
  76. {
  77. if(m_tSwitch == nullptr)
  78. {
  79. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  80. return;
  81. }
  82. m_tSwitch->DoGetExecPlanFromEQM();
  83. }
  84. /* 导出数据按钮 */
  85. void Widget::on_pBtn_saveData_clicked()
  86. {
  87. if(m_tSwitch == nullptr)
  88. {
  89. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  90. return;
  91. }
  92. // m_tSwitch->DoSaveExecPlanToEQM();
  93. QList<OnePlanItemInfo> listPlan;
  94. ExecPlanConfig config;
  95. m_tSwitch->DoGetPlanData(&listPlan, &config, 1);
  96. SPDLOG_DEBUG("导出数据成功,计划数目: {}", listPlan.size());
  97. }
  98. /* 切换亮色/暗色的按钮 */
  99. void Widget::on_pBtn_light_dark_clicked()
  100. {
  101. if(m_tSwitch == nullptr)
  102. {
  103. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  104. return;
  105. }
  106. if(m_style == 0)
  107. {
  108. m_style = 1;
  109. /* 当前是亮色,设置为暗色 */
  110. m_tSwitch->DoShowWindow(m_style, true);
  111. }else
  112. {
  113. m_style = 0;
  114. m_tSwitch->DoShowWindow(m_style, true);
  115. }
  116. }
  117. /* 切换是否使用EQM数据库 */
  118. void Widget::on_pBtn_useEQM_clicked()
  119. {
  120. if(m_tSwitch == nullptr)
  121. {
  122. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  123. return;
  124. }
  125. ExecPlanInfo info;
  126. info.ChannelID = 13;
  127. info.ChannelName = "频率1";
  128. info.DatabasePath = QApplication::applicationDirPath() + "/db/";
  129. if(ui->pBtn_useEQM->isChecked())
  130. {
  131. /* 使用EQM数据库 */
  132. m_tSwitch->DoSetChannelInfo(&info, true);
  133. m_tSwitch->DoGetExecPlanFromEQM();
  134. }else
  135. {
  136. /* 使用SQLite数据库 */
  137. m_tSwitch->DoSetChannelInfo(&info, false);
  138. }
  139. }
  140. /* 添加测试用的设备信息 */
  141. // void Widget::addTestDevice()
  142. // {
  143. // auto devType = DevTypeContainer.getDevType(955);
  144. // if(devType.PTTypeCode == -1)
  145. // {
  146. // return;
  147. // }
  148. // DeviceInfo devInfo;
  149. // devInfo.devName = "衢州台主发射机";
  150. // devInfo.PTTypeCode = 955;
  151. // devInfo.DTID = 1;
  152. // devInfo.DID = 1;
  153. // devInfo.ChannelID = 1;
  154. // devInfo.DevType = devType;
  155. // DeviceContainer.addDevice(devInfo);
  156. // devInfo.devName = "衢州台备发射机";
  157. // devInfo.PTTypeCode = 955;
  158. // devInfo.DTID = 1;
  159. // devInfo.DID = 2;
  160. // devInfo.ChannelID = 2;
  161. // devInfo.DevType = devType;
  162. // DeviceContainer.addDevice(devInfo);
  163. // }
  164. /* 回调函数 */
  165. void Widget::trackCallBack(int actionID, QString strMemo)
  166. {
  167. SPDLOG_INFO("回调函数: actionID: {}, strMemo: {}", actionID, strMemo.toStdString());
  168. }