widget.cpp 5.6 KB

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