widget.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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.userPermission = 1;
  38. // initData.url = "http://192.1.3.136:31000/v6/";
  39. // initData.serverID = "2e36b53ccd2a433b9a803b98d683ed91";
  40. initData.serverKey = "TMS";
  41. m_tSwitch->DoInit(&initData);
  42. m_tSwitch->DoCreateWindow(1, container);
  43. m_tSwitch->DoGetExecPlanFromEQM();
  44. m_tSwitch->DoSetCallBack(trackCallBack);
  45. // m_tSwitch->DoInitLibrary();
  46. // m_tSwitch->DoCreateOneWindow(0, container);
  47. // m_tSwitch->DoSetOnePageCardNum(4, 2);
  48. // m_tSwitch->DoSetWebAPIInfo(&initData);
  49. ExecPlanInfo info;
  50. info.ChannelID = -1;
  51. info.ChannelName = "";
  52. info.DatabasePath = QApplication::applicationDirPath() + "/db/";
  53. // m_tSwitch->DoSetChannelInfo(&info, true);
  54. // m_tSwitch->DoSetCallBack(trackCallBack);
  55. // m_tSwitch->DoGetExecPlanFromEQM();
  56. m_style = 1;
  57. /* 添加设备信息,测试用 */
  58. // addTestDevice();
  59. SPDLOG_INFO("Widget init success");
  60. }
  61. Widget::~Widget()
  62. {
  63. // if(m_tSwitch != nullptr)
  64. // {
  65. // delete m_tSwitch;
  66. // m_tSwitch = nullptr;
  67. // }
  68. // if(m_layout != nullptr)
  69. // {
  70. // delete m_layout;
  71. // m_layout = nullptr;
  72. // }
  73. delete ui;
  74. }
  75. /* 导入数据按钮 */
  76. void Widget::on_pBtn_getData_clicked()
  77. {
  78. if(m_tSwitch == nullptr)
  79. {
  80. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  81. return;
  82. }
  83. m_tSwitch->DoGetExecPlanFromEQM();
  84. }
  85. /* 导出数据按钮 */
  86. void Widget::on_pBtn_saveData_clicked()
  87. {
  88. if(m_tSwitch == nullptr)
  89. {
  90. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  91. return;
  92. }
  93. // m_tSwitch->DoSaveExecPlanToEQM();
  94. QList<OnePlanItemInfo> listPlan;
  95. ExecPlanConfig config;
  96. m_tSwitch->DoGetPlanData(&listPlan, &config, 1);
  97. SPDLOG_DEBUG("导出数据成功,计划数目: {}", listPlan.size());
  98. }
  99. /* 切换亮色/暗色的按钮 */
  100. void Widget::on_pBtn_light_dark_clicked()
  101. {
  102. if(m_tSwitch == nullptr)
  103. {
  104. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  105. return;
  106. }
  107. if(m_style == 0)
  108. {
  109. m_style = 1;
  110. /* 当前是亮色,设置为暗色 */
  111. m_tSwitch->DoShowWindow(m_style, true);
  112. }else
  113. {
  114. m_style = 0;
  115. m_tSwitch->DoShowWindow(m_style, true);
  116. }
  117. }
  118. /* 切换是否使用EQM数据库 */
  119. void Widget::on_pBtn_useEQM_clicked()
  120. {
  121. if(m_tSwitch == nullptr)
  122. {
  123. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  124. return;
  125. }
  126. ExecPlanInfo info;
  127. info.ChannelID = 13;
  128. info.ChannelName = "频率1";
  129. info.DatabasePath = QApplication::applicationDirPath() + "/db/";
  130. if(ui->pBtn_useEQM->isChecked())
  131. {
  132. /* 使用EQM数据库 */
  133. m_tSwitch->DoSetChannelInfo(&info, true);
  134. m_tSwitch->DoGetExecPlanFromEQM();
  135. }else
  136. {
  137. /* 使用SQLite数据库 */
  138. m_tSwitch->DoSetChannelInfo(&info, false);
  139. }
  140. }
  141. /* 切换用户权限 */
  142. void Widget::on_pBtn_changeUser_clicked()
  143. {
  144. if(m_tSwitch == nullptr)
  145. {
  146. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  147. return;
  148. }
  149. if(m_userPermission == 0)
  150. {
  151. m_userPermission = 1;
  152. /* 设置为普通用户 */
  153. m_tSwitch->DoSetUserPermission(m_userPermission);
  154. ui->pBtn_changeUser->setText("普通用户");
  155. }else
  156. {
  157. m_userPermission = 0;
  158. /* 设置为管理员 */
  159. m_tSwitch->DoSetUserPermission(m_userPermission);
  160. ui->pBtn_changeUser->setText("管理员");
  161. }
  162. }
  163. /* 添加测试用的设备信息 */
  164. // void Widget::addTestDevice()
  165. // {
  166. // auto devType = DevTypeContainer.getDevType(955);
  167. // if(devType.PTTypeCode == -1)
  168. // {
  169. // return;
  170. // }
  171. // DeviceInfo devInfo;
  172. // devInfo.devName = "衢州台主发射机";
  173. // devInfo.PTTypeCode = 955;
  174. // devInfo.DTID = 1;
  175. // devInfo.DID = 1;
  176. // devInfo.ChannelID = 1;
  177. // devInfo.DevType = devType;
  178. // DeviceContainer.addDevice(devInfo);
  179. // devInfo.devName = "衢州台备发射机";
  180. // devInfo.PTTypeCode = 955;
  181. // devInfo.DTID = 1;
  182. // devInfo.DID = 2;
  183. // devInfo.ChannelID = 2;
  184. // devInfo.DevType = devType;
  185. // DeviceContainer.addDevice(devInfo);
  186. // }
  187. /* 回调函数 */
  188. void Widget::trackCallBack(int actionID, QString strMemo)
  189. {
  190. SPDLOG_INFO("回调函数: actionID: {}, strMemo: {}", actionID, strMemo.toStdString());
  191. }