widget.cpp 5.5 KB

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