widget.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. m_tSwitch = new LHTransmitterSwitchAPI();
  14. if(m_tSwitch->loadLibrary())
  15. {
  16. SPDLOG_INFO("load library success");
  17. }else {
  18. SPDLOG_ERROR("load library failed");
  19. }
  20. /* 设置一个布局 */
  21. m_layout = new QVBoxLayout(ui->widget_content);
  22. ui->widget_content->setLayout(m_layout);
  23. /* 添加一个容器 */
  24. QWidget* container = new QWidget(this);
  25. container->setObjectName("container");
  26. m_layout->addWidget(container);
  27. container->setStyleSheet(R"(background: transparent;)");
  28. /* 设置边距为0 */
  29. m_layout->setMargin(20);
  30. m_layout->setSpacing(0);
  31. ui->widget_content->setStyleSheet(R"(background: #000000;)");
  32. /* 初始化WebAPI */
  33. InitData initData;
  34. initData.url = "http://192.1.3.133:31000/v6/";
  35. initData.serverID = "2e36b53ccd2a433b9a803b98d683ed91";
  36. // initData.url = "http://192.1.3.136:31000/v6/";
  37. // initData.serverID = "2e36b53ccd2a433b9a803b98d683ed91";
  38. initData.serverKey = "TMS";
  39. m_tSwitch->DoInit(&initData);
  40. m_tSwitch->DoCreateWindow(1, container);
  41. m_tSwitch->DoGetExecPlanFromEQM();
  42. m_tSwitch->DoSetCallBack(trackCallBack);
  43. m_style = 1;
  44. // m_tSwitch->setWebAPIInfo("http://192.1.3.133:31000/v6/", "2e36b53ccd2a433b9a803b98d683ed91", "TMS");
  45. /* 添加设备信息,测试用 */
  46. // addTestDevice();
  47. SPDLOG_INFO("Widget init success");
  48. }
  49. Widget::~Widget()
  50. {
  51. // if(m_tSwitch != nullptr)
  52. // {
  53. // delete m_tSwitch;
  54. // m_tSwitch = nullptr;
  55. // }
  56. // if(m_layout != nullptr)
  57. // {
  58. // delete m_layout;
  59. // m_layout = nullptr;
  60. // }
  61. delete ui;
  62. }
  63. /* 导入数据按钮 */
  64. void Widget::on_pBtn_getData_clicked()
  65. {
  66. if(m_tSwitch == nullptr)
  67. {
  68. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  69. return;
  70. }
  71. m_tSwitch->DoGetExecPlanFromEQM();
  72. }
  73. /* 导出数据按钮 */
  74. void Widget::on_pBtn_saveData_clicked()
  75. {
  76. if(m_tSwitch == nullptr)
  77. {
  78. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  79. return;
  80. }
  81. m_tSwitch->DoSaveExecPlanToEQM();
  82. }
  83. /* 切换亮色/暗色的按钮 */
  84. void Widget::on_pBtn_light_dark_clicked()
  85. {
  86. if(m_tSwitch == nullptr)
  87. {
  88. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  89. return;
  90. }
  91. if(m_style == 0)
  92. {
  93. m_style = 1;
  94. /* 当前是亮色,设置为暗色 */
  95. m_tSwitch->DoShowWindow(m_style, true);
  96. }else
  97. {
  98. m_style = 0;
  99. m_tSwitch->DoShowWindow(m_style, true);
  100. }
  101. }
  102. /* 添加测试用的设备信息 */
  103. // void Widget::addTestDevice()
  104. // {
  105. // auto devType = DevTypeContainer.getDevType(955);
  106. // if(devType.PTTypeCode == -1)
  107. // {
  108. // return;
  109. // }
  110. // DeviceInfo devInfo;
  111. // devInfo.devName = "衢州台主发射机";
  112. // devInfo.PTTypeCode = 955;
  113. // devInfo.DTID = 1;
  114. // devInfo.DID = 1;
  115. // devInfo.ChannelID = 1;
  116. // devInfo.DevType = devType;
  117. // DeviceContainer.addDevice(devInfo);
  118. // devInfo.devName = "衢州台备发射机";
  119. // devInfo.PTTypeCode = 955;
  120. // devInfo.DTID = 1;
  121. // devInfo.DID = 2;
  122. // devInfo.ChannelID = 2;
  123. // devInfo.DevType = devType;
  124. // DeviceContainer.addDevice(devInfo);
  125. // }
  126. /* 回调函数 */
  127. void Widget::trackCallBack(int actionID, QString strMemo)
  128. {
  129. SPDLOG_INFO("回调函数: actionID: {}, strMemo: {}", actionID, strMemo.toStdString());
  130. }