From bab4f3f9f4f6a6cbfd53707432ff7161e657df56 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 4 Aug 2024 20:18:49 +0800 Subject: [PATCH] update --- src/app/main.cpp | 4 +- src/zqui/channelmgr/qt_serial_datachannel.hpp | 2 +- src/zqui/mainpage/mainwindow.cpp | 34 +++++++ src/zqui/mainpage/mainwindow.h | 11 ++ src/zqui/mainpage/mainwindow.ui | 140 ++++++++++++++++++++++++-- src/zqui/zqui.cpp | 80 +++++++++++++++ src/zqui/zqui.hpp | 82 +++++++++++++++ 7 files changed, 344 insertions(+), 9 deletions(-) create mode 100644 src/zqui/zqui.cpp create mode 100644 src/zqui/zqui.hpp diff --git a/src/app/main.cpp b/src/app/main.cpp index 361a991..7314ebd 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -19,6 +19,7 @@ #include #include "zqui/mainpage/mainwindow.h" +#include "zqui/zqui.hpp" // #include // @@ -33,7 +34,6 @@ int main(int argc, char *argv[]) { WSAStartup(MAKEWORD(2, 2), &wsaData); QApplication a(argc, argv); - MainWindow w; - w.show(); + ZQUI::ins()->initialize(); return a.exec(); } diff --git a/src/zqui/channelmgr/qt_serial_datachannel.hpp b/src/zqui/channelmgr/qt_serial_datachannel.hpp index be9453f..52a13bb 100644 --- a/src/zqui/channelmgr/qt_serial_datachannel.hpp +++ b/src/zqui/channelmgr/qt_serial_datachannel.hpp @@ -54,7 +54,7 @@ class QTSerialChannel { bool open(); void close(); - bool setBaudRate(qint32 baudRate) { m_baudRate = baudRate; } + void setBaudRate(qint32 baudRate) { m_baudRate = baudRate; } qint32 baudRate() const { return m_baudRate; } void setPortName(string name) { m_name = name; } diff --git a/src/zqui/mainpage/mainwindow.cpp b/src/zqui/mainpage/mainwindow.cpp index f957055..a2c1c73 100644 --- a/src/zqui/mainpage/mainwindow.cpp +++ b/src/zqui/mainpage/mainwindow.cpp @@ -7,7 +7,10 @@ #include #include "./ui_mainwindow.h" +#include "zqui/base/QFunction.hpp" #include "zqui/channelmgr/channelmgr.hpp" +// +#include "zqui/zqui.hpp" // #include "app/syncbox16ch.h" // #include "version.h" @@ -91,3 +94,34 @@ void MainWindow::timerEvent(QTimerEvent *event) { // fillinSerialPort(); // } } + +void MainWindow::iShow(QString content) { + QString info; + info.append(content); + ui->CmdBrowser->append(info); +} +void MainWindow::iClear() { ui->CmdBrowser->clear(); } + +void MainWindow::reportShow(QString content) { + QString info; + info.append(content); + ui->ReportBrowser->append(info); +} +void MainWindow::reportClear() { ui->ReportBrowser->clear(); } + +void MainWindow::binaryShow(QString content) { + QString info; + info.append(content); + ui->BinaryBrowser->append(info); +} +void MainWindow::binaryClear() { ui->BinaryBrowser->clear(); } + +void MainWindow::setConnectedStatus(bool connect) { + if (connect) { + ui->DeviceConnectStateTB->setText("已连接"); + ui->DeviceConnectStateTB->setStyleSheet("color: green"); + } else { + ui->DeviceConnectStateTB->setText("未连接"); + ui->DeviceConnectStateTB->setStyleSheet("color: red"); + } +} diff --git a/src/zqui/mainpage/mainwindow.h b/src/zqui/mainpage/mainwindow.h index 0bf808b..5760a3c 100644 --- a/src/zqui/mainpage/mainwindow.h +++ b/src/zqui/mainpage/mainwindow.h @@ -45,6 +45,17 @@ class MainWindow : public QMainWindow { MainWindow(QWidget *parent = nullptr); ~MainWindow() {}; + public: + void iShow(QString content); + void iClear(); + + void reportShow(QString content); + void reportClear(); + + void binaryShow(QString content); + void binaryClear(); + void setConnectedStatus(bool connect); + private slots: void on_serialPortCB_customContextMenuRequested(const QPoint &pos); bool eventFilter(QObject *watched, QEvent *event); diff --git a/src/zqui/mainpage/mainwindow.ui b/src/zqui/mainpage/mainwindow.ui index bef4366..0b1e657 100644 --- a/src/zqui/mainpage/mainwindow.ui +++ b/src/zqui/mainpage/mainwindow.ui @@ -655,6 +655,12 @@ QGroupBox:title { + + 0 + + + 0 + @@ -702,6 +708,94 @@ QGroupBox:title { + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + false + + + 状态 + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 设备连接状态 + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 2 + + + + + + + + + + 软件信息 + + + + + Qt::Vertical @@ -714,10 +808,19 @@ QGroupBox:title { - - + + + + + 0 + 0 + + - + <a href="www.iflytop.com">www.iflytop.com + + + true @@ -785,7 +888,7 @@ QGroupBox:title { QTabWidget::Rounded - 1 + 0 Qt::ElideLeft @@ -798,7 +901,7 @@ QGroupBox:title { - 指令 + 指令交互 @@ -823,7 +926,7 @@ QGroupBox:title { - 上报 + 上报数据流 @@ -846,6 +949,31 @@ QGroupBox:title { + + + 二进制流 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + diff --git a/src/zqui/zqui.cpp b/src/zqui/zqui.cpp new file mode 100644 index 0000000..5228dce --- /dev/null +++ b/src/zqui/zqui.cpp @@ -0,0 +1,80 @@ +#include "zqui.hpp" + +#include "zqui/mainpage/mainwindow.h" + +using namespace std; +#define TAG "ZQUI" + +/*********************************************************************************************************************** + * PreviewShow * + ***********************************************************************************************************************/ +MainWindow *pmainW; + +ZQUI *ZQUI::ins() { + static ZQUI instance; + return &instance; +} + +void ZQUI::iShow(const char *fmt, ...) { + va_list args; + va_start(args, fmt); + char buf[1024] = {0}; + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + QString text(buf); + pmainW->iShow(text); +} +void ZQUI::iRawShow(const char *fmt, ...) { + va_list args; + va_start(args, fmt); + char buf[1024] = {0}; + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + QString text(buf); + pmainW->iShow(text); +} +void ZQUI::iClear() { pmainW->iClear(); } + +void ZQUI::reportShow(const char *fmt, ...) { + va_list args; + va_start(args, fmt); + char buf[1024] = {0}; + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + QString text(buf); + pmainW->reportShow(text); +} +void ZQUI::reportClear() { pmainW->reportClear(); } + +void ZQUI::binaryShow(const char *fmt, ...) { + va_list args; + va_start(args, fmt); + char buf[1024] = {0}; + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + QString text(buf); + pmainW->binaryShow(text); +} +void ZQUI::binaryClear() { pmainW->binaryClear(); } + +void ZQUI::initialize() { + qRegisterMetaType("int32_t"); + qRegisterMetaType("uint32_t"); + qRegisterMetaType("float"); + qRegisterMetaType>("function"); + qRegisterMetaType("QFunction"); + connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); + + pmainW = new MainWindow(); + pmainW->show(); +} +void ZQUI::doinui(function dowhat) { + emit doinui_signal(QFunction([dowhat]() { + if (dowhat) dowhat(); + })); +} +void ZQUI::doinui_slot(QFunction func) { + if (func.get()) func.get()(); +} + +void ZQUI::setDeviceConnectedStatus(bool connect) { pmainW->setConnectedStatus(connect); } diff --git a/src/zqui/zqui.hpp b/src/zqui/zqui.hpp new file mode 100644 index 0000000..6829249 --- /dev/null +++ b/src/zqui/zqui.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "base/QFunction.hpp" + +class ZQUI : public QObject { + Q_OBJECT + public: + typedef std::function display_fn_t; + typedef std::function display_clear_fn_t; + + + public: + static ZQUI *ins(); + + void initialize(); + + void doinui(std::function dowhat); + + void iShow(const char *fmt, ...); + void iRawShow(const char *fmt, ...); + void iClear(); + + void reportShow(const char *fmt, ...); + void reportClear(); + + void binaryShow(const char *fmt, ...); + void binaryClear(); + + void setDeviceConnectedStatus(bool connect); + + private slots: + void doinui_slot(QFunction); + + signals: + void doinui_signal(QFunction); +}; + +#define ISHOW(fmt, ...) ZQUI::ins()->iShow(fmt, ##__VA_ARGS__) +#define IRSHOW(fmt, ...) ZQUI::ins()->iRawShow(fmt, ##__VA_ARGS__) +#define ICLEAR() ZQUI::ins()->iClear() + +#define RSHOW(fmt, ...) ZQUI::ins()->reportShow(fmt, ##__VA_ARGS__) +#define RCLEAR() ZQUI::ins()->reportClear() + +#define BSHOW(fmt, ...) ZQUI::ins()->binaryShow(fmt, ##__VA_ARGS__) +#define BCLEAR() ZQUI::ins()->binaryClear() + +#define DOINUI(fn) ZQUI::ins()->doinui(fn) \ No newline at end of file