widget.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.serverKey = "TMS";
  37. m_tSwitch->DoInit(&initData);
  38. m_tSwitch->DoCreateWindow(1, container);
  39. // m_tSwitch->DoGetExecPlanFromEQM();
  40. m_tSwitch->DoSetCallBack(trackCallBack);
  41. m_style = 1;
  42. // m_tSwitch->setWebAPIInfo("http://192.1.3.133:31000/v6/", "2e36b53ccd2a433b9a803b98d683ed91", "TMS");
  43. /* 添加设备信息,测试用 */
  44. // addTestDevice();
  45. SPDLOG_INFO("Widget init success");
  46. }
  47. Widget::~Widget()
  48. {
  49. // if(m_tSwitch != nullptr)
  50. // {
  51. // delete m_tSwitch;
  52. // m_tSwitch = nullptr;
  53. // }
  54. // if(m_layout != nullptr)
  55. // {
  56. // delete m_layout;
  57. // m_layout = nullptr;
  58. // }
  59. delete ui;
  60. }
  61. /* 导入数据按钮 */
  62. void Widget::on_pBtn_getData_clicked()
  63. {
  64. if(m_tSwitch == nullptr)
  65. {
  66. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  67. return;
  68. }
  69. m_tSwitch->DoGetExecPlanFromEQM();
  70. }
  71. /* 导出数据按钮 */
  72. void Widget::on_pBtn_saveData_clicked()
  73. {
  74. if(m_tSwitch == nullptr)
  75. {
  76. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  77. return;
  78. }
  79. m_tSwitch->DoSaveExecPlanToEQM();
  80. }
  81. /* 切换亮色/暗色的按钮 */
  82. void Widget::on_pBtn_light_dark_clicked()
  83. {
  84. if(m_tSwitch == nullptr)
  85. {
  86. SPDLOG_DEBUG("TransmitterSwitch is nullptr");
  87. return;
  88. }
  89. if(m_style == 0)
  90. {
  91. m_style = 1;
  92. /* 当前是亮色,设置为暗色 */
  93. m_tSwitch->DoShowWindow(m_style, true);
  94. }else
  95. {
  96. m_style = 0;
  97. m_tSwitch->DoShowWindow(m_style, true);
  98. }
  99. }
  100. /* 添加测试用的设备信息 */
  101. // void Widget::addTestDevice()
  102. // {
  103. // auto devType = DevTypeContainer.getDevType(955);
  104. // if(devType.PTTypeCode == -1)
  105. // {
  106. // return;
  107. // }
  108. // DeviceInfo devInfo;
  109. // devInfo.devName = "衢州台主发射机";
  110. // devInfo.PTTypeCode = 955;
  111. // devInfo.DTID = 1;
  112. // devInfo.DID = 1;
  113. // devInfo.ChannelID = 1;
  114. // devInfo.DevType = devType;
  115. // DeviceContainer.addDevice(devInfo);
  116. // devInfo.devName = "衢州台备发射机";
  117. // devInfo.PTTypeCode = 955;
  118. // devInfo.DTID = 1;
  119. // devInfo.DID = 2;
  120. // devInfo.ChannelID = 2;
  121. // devInfo.DevType = devType;
  122. // DeviceContainer.addDevice(devInfo);
  123. // }
  124. /* 回调函数 */
  125. void Widget::trackCallBack(int actionID, QString strMemo)
  126. {
  127. SPDLOG_INFO("回调函数: actionID: {}, strMemo: {}", actionID, strMemo.toStdString());
  128. }