#include "widget.h" #include "ui_widget.h" // #include "LHQLogAPI.h" // #include "lhstylemanager.h" #include "spdlog/spdlog.h" // #include "TransmitterswitchInfo.h" // #include "lhtranmitterswitch.h" Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); ui->pBtn_useEQM->setCheckable(true); m_tSwitch = new LHTransmitterSwitchAPI(); if(m_tSwitch->loadLibrary()) { SPDLOG_INFO("load library success"); }else { SPDLOG_ERROR("load library failed"); } /* 设置一个布局 */ m_layout = new QVBoxLayout(ui->widget_content); ui->widget_content->setLayout(m_layout); /* 添加一个容器 */ QWidget* container = new QWidget(this); container->setObjectName("container"); m_layout->addWidget(container); container->setStyleSheet(R"(background: transparent;)"); /* 设置边距为0 */ m_layout->setMargin(20); m_layout->setSpacing(0); ui->widget_content->setStyleSheet(R"(background: #000000;)"); /* 初始化WebAPI */ InitData initData; initData.url = "http://192.1.3.133:31000/v6/"; initData.serverID = "2e36b53ccd2a433b9a803b98d683ed91"; // initData.url = "http://192.1.3.136:31000/v6/"; // initData.serverID = "2e36b53ccd2a433b9a803b98d683ed91"; initData.serverKey = "TMS"; m_tSwitch->DoInit(&initData); m_tSwitch->DoCreateWindow(1, container); m_tSwitch->DoGetExecPlanFromEQM(); m_tSwitch->DoSetCallBack(trackCallBack); // m_tSwitch->DoInitLibrary(); // m_tSwitch->DoCreateOneWindow(0, container); // m_tSwitch->DoSetOnePageCardNum(4, 2); // m_tSwitch->DoSetWebAPIInfo(&initData); ExecPlanInfo info; info.ChannelID = -1; info.ChannelName = ""; info.DatabasePath = QApplication::applicationDirPath() + "/db/"; // m_tSwitch->DoSetChannelInfo(&info, true); // m_tSwitch->DoSetCallBack(trackCallBack); // m_tSwitch->DoGetExecPlanFromEQM(); m_style = 1; /* 添加设备信息,测试用 */ // addTestDevice(); SPDLOG_INFO("Widget init success"); } Widget::~Widget() { // if(m_tSwitch != nullptr) // { // delete m_tSwitch; // m_tSwitch = nullptr; // } // if(m_layout != nullptr) // { // delete m_layout; // m_layout = nullptr; // } delete ui; } /* 导入数据按钮 */ void Widget::on_pBtn_getData_clicked() { if(m_tSwitch == nullptr) { SPDLOG_DEBUG("TransmitterSwitch is nullptr"); return; } m_tSwitch->DoGetExecPlanFromEQM(); } /* 导出数据按钮 */ void Widget::on_pBtn_saveData_clicked() { if(m_tSwitch == nullptr) { SPDLOG_DEBUG("TransmitterSwitch is nullptr"); return; } // m_tSwitch->DoSaveExecPlanToEQM(); QList listPlan; ExecPlanConfig config; m_tSwitch->DoGetPlanData(&listPlan, &config, 1); SPDLOG_DEBUG("导出数据成功,计划数目: {}", listPlan.size()); } /* 切换亮色/暗色的按钮 */ void Widget::on_pBtn_light_dark_clicked() { if(m_tSwitch == nullptr) { SPDLOG_DEBUG("TransmitterSwitch is nullptr"); return; } if(m_style == 0) { m_style = 1; /* 当前是亮色,设置为暗色 */ m_tSwitch->DoShowWindow(m_style, true); }else { m_style = 0; m_tSwitch->DoShowWindow(m_style, true); } } /* 切换是否使用EQM数据库 */ void Widget::on_pBtn_useEQM_clicked() { if(m_tSwitch == nullptr) { SPDLOG_DEBUG("TransmitterSwitch is nullptr"); return; } ExecPlanInfo info; info.ChannelID = 13; info.ChannelName = "频率1"; info.DatabasePath = QApplication::applicationDirPath() + "/db/"; if(ui->pBtn_useEQM->isChecked()) { /* 使用EQM数据库 */ m_tSwitch->DoSetChannelInfo(&info, true); m_tSwitch->DoGetExecPlanFromEQM(); }else { /* 使用SQLite数据库 */ m_tSwitch->DoSetChannelInfo(&info, false); } } /* 添加测试用的设备信息 */ // void Widget::addTestDevice() // { // auto devType = DevTypeContainer.getDevType(955); // if(devType.PTTypeCode == -1) // { // return; // } // DeviceInfo devInfo; // devInfo.devName = "衢州台主发射机"; // devInfo.PTTypeCode = 955; // devInfo.DTID = 1; // devInfo.DID = 1; // devInfo.ChannelID = 1; // devInfo.DevType = devType; // DeviceContainer.addDevice(devInfo); // devInfo.devName = "衢州台备发射机"; // devInfo.PTTypeCode = 955; // devInfo.DTID = 1; // devInfo.DID = 2; // devInfo.ChannelID = 2; // devInfo.DevType = devType; // DeviceContainer.addDevice(devInfo); // } /* 回调函数 */ void Widget::trackCallBack(int actionID, QString strMemo) { SPDLOG_INFO("回调函数: actionID: {}, strMemo: {}", actionID, strMemo.toStdString()); }