From 07c208955e9db5450ff07e42bb1e78a3ef064009 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Fri, 12 Apr 2024 14:40:07 +0800 Subject: [PATCH] update --- .vscode/settings.json | 4 +- CMakeLists.txt | 2 + libzqt/zui/z_function_list_box.cpp | 11 ++-- libzqt/zui/z_reg_table_list_box.cpp | 69 +++++++++++++++++++++ libzqt/zui/z_reg_table_list_box.hpp | 120 ++++++++++++++++++++++++++++++++++++ libzqt/zui/zq_vtab_page.cpp | 7 ++- libzqt/zui/zq_vtab_page.hpp | 4 +- libzqt/zui/zui.hpp | 5 ++ mainwindow.cpp | 30 +++++++++ mainwindow.ui | 46 +++++++------- src/main.cpp | 1 - 11 files changed, 266 insertions(+), 33 deletions(-) create mode 100644 libzqt/zui/zui.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json index 55e691f..c0d4b4e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -92,7 +92,9 @@ "qcombobox": "cpp", "qvariant": "cpp", "qlineedit": "cpp", - "qhboxlayout": "cpp" + "qhboxlayout": "cpp", + "qformlayout": "cpp", + "qtextbrowser": "cpp" }, "files.autoGuessEncoding": false, } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index a1d01f9..5e3afee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,8 @@ set(PROJECT_SOURCES libzqt/zui/z_function_list_box.cpp libzqt/zui/zq_vtab_page.cpp + + libzqt/zui/z_reg_table_list_box.cpp ) diff --git a/libzqt/zui/z_function_list_box.cpp b/libzqt/zui/z_function_list_box.cpp index 4aaee71..c055bd9 100644 --- a/libzqt/zui/z_function_list_box.cpp +++ b/libzqt/zui/z_function_list_box.cpp @@ -4,8 +4,6 @@ using namespace iflytop; using namespace std; ZQFunctionListBox::ZQFunctionListBox(QWidget *parent, const QString &title, int column) : QGroupBox(parent) { // - QVBoxLayout *tablayout = qobject_cast(parent->layout()); - // Box init this->setTitle(title); QGridLayout *layout = new QGridLayout(this); @@ -15,13 +13,14 @@ ZQFunctionListBox::ZQFunctionListBox(QWidget *parent, const QString &title, int m_column = column; // add QSpacer - QSpacerItem *verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); + QSpacerItem *verticalSpacer = new QSpacerItem(20, 100, QSizePolicy::Minimum, QSizePolicy::Expanding); m_verticalSpacer = verticalSpacer; - // m_itermNum++; + + // add Spacer m_layout->addItem(m_verticalSpacer, 0, 0, 1, 1); - // m_layout->removeItem(m_verticalSpacer); - tablayout->addWidget(this); + // add Box To Tab + parent->layout()->addWidget(this); } void ZQFunctionListBox::regOnException(function onException) { m_onException = onException; } diff --git a/libzqt/zui/z_reg_table_list_box.cpp b/libzqt/zui/z_reg_table_list_box.cpp index e69de29..d53025e 100644 --- a/libzqt/zui/z_reg_table_list_box.cpp +++ b/libzqt/zui/z_reg_table_list_box.cpp @@ -0,0 +1,69 @@ +#include "z_reg_table_list_box.hpp" + +using namespace iflytop; +using namespace std; +/*********************************************************************************************************************** + * ZRegItem * + ***********************************************************************************************************************/ +ZRegItem::ZRegItem(QWidget *parent, QString &title, int addr, ZRegItem::reg_flag_t flag) : QFrame(parent) { + m_layout = new QHBoxLayout(parent); + this->setLayout(m_layout); + m_layout->setMargin(0); + // m_layout->setSpacing(0); + + m_horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + m_lable = new QLabel(title, this); + m_val = new QLineEdit(this); + m_writeButton = new QPushButton("写", this); + m_readButton = new QPushButton("读", this); + + // m_lable->setAlignment(Qt::AlignRight); + + m_lable->setMinimumSize(50, 30); + m_val->setMinimumSize(100, 30); + m_writeButton->setMinimumSize(100, 30); + m_readButton->setMinimumSize(100, 30); + + m_layout->addWidget(m_lable); + m_layout->addWidget(m_val); + m_layout->addItem(m_horizontalSpacer); + m_layout->addWidget(m_readButton); + m_layout->addWidget(m_writeButton); +} +/*********************************************************************************************************************** + * ZRegTableList * + ***********************************************************************************************************************/ +ZRegTableList::ZRegTableList(QWidget *parent, const QString &title) : QGroupBox(title) { + // fatherLayout + m_layout = new QVBoxLayout(this); + this->setLayout(m_layout); + parent->layout()->addWidget(this); + + // add FunctionList to + m_funcBox = new ZQFunctionListBox(this, "", 4); + m_funcBox->newFunc("读全部", {}, [this](int argn, const char **args) { + for (auto &item : m_regMap) { + } + }); + m_layout->addWidget(m_funcBox); + + // add box to parent + m_regBox = new QGroupBox("寄存器列表", this); + m_regBoxLayout = new QVBoxLayout(this); + m_regBox->setLayout(m_regBoxLayout); + + m_layout->addWidget(m_regBox); + +} + +void ZRegTableList::regOnException(function onException) {} +void ZRegTableList::addReg(QString title, int addr, ZRegItem::reg_flag_t flag) { + ZRegItem *item = new ZRegItem(this, title, addr, flag); + m_regBoxLayout->addWidget(item); + m_regMap[title] = item; +} + +void ZRegTableList::addSpacer() { + m_layout->addItem(new QSpacerItem(20, 100, QSizePolicy::Minimum, QSizePolicy::Expanding)); + m_regBoxLayout->addItem(new QSpacerItem(20, 100, QSizePolicy::Minimum, QSizePolicy::Expanding)); +} \ No newline at end of file diff --git a/libzqt/zui/z_reg_table_list_box.hpp b/libzqt/zui/z_reg_table_list_box.hpp index e69de29..6d39a67 100644 --- a/libzqt/zui/z_reg_table_list_box.hpp +++ b/libzqt/zui/z_reg_table_list_box.hpp @@ -0,0 +1,120 @@ +#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 "../zexception.hpp" +#include "z_function_list_box.hpp" + +namespace iflytop { +using namespace std; + +/** + * @brief 构造样式如下 + * + * +TAB---------------------------------+ + * |---BOX---------------------------| + * | 读全部 | + * | |Lable|Val| 读|写 | + * | |Lable|Val| 读|写 | + * | |Lable|Val| 读|写 | + * | |Lable|Val| 读|写 | + * | |Lable|Val| 读|写 | + * | |Lable|Val| 读|写 | + * |---------------------------------| + * + */ + +class ZRegItem : public QFrame { + Q_OBJECT + public: + typedef enum { + kr = 1 << 0, + kw = 1 << 1, + krw = kr | kw, + khex = 1 << 2, + kdec = 1 << 3, + kfloat = 1 << 4, + kstr = 1 << 5, + kbinary = 1 << 6, + } reg_flag_t; + + private: + QHBoxLayout *m_layout = nullptr; + QLabel *m_lable; + QLineEdit *m_val; + QPushButton *m_writeButton; + QPushButton *m_readButton; + + QSpacerItem *m_horizontalSpacer; + + QString m_title; + int m_addr; + reg_flag_t m_flag; + + public: + ZRegItem(QWidget *parent, QString &title, int addr, ZRegItem::reg_flag_t flag); +}; + +class ZRegTableList : public QGroupBox { + Q_OBJECT + public: + function m_onException; + + private: + /** + * @brief layout + * + * VBoxLayout + * FunctonListBox + * Button,param,param + * Button,param,param + * RegBox + * Lable Val Spacer Button0 Button1 + * + */ + + QVBoxLayout *m_layout = nullptr; + ZQFunctionListBox *m_funcBox; + + QGroupBox *m_regBox = nullptr; + QVBoxLayout *m_regBoxLayout = nullptr; + + QMap m_regMap; + + public: + ZRegTableList(QWidget *parent, const QString &title); + + void regOnException(function onException); + void addReg(QString title, int addr, ZRegItem::reg_flag_t flag); + void addSpacer(); +}; +} // namespace iflytop diff --git a/libzqt/zui/zq_vtab_page.cpp b/libzqt/zui/zq_vtab_page.cpp index 382109a..c1637d5 100644 --- a/libzqt/zui/zq_vtab_page.cpp +++ b/libzqt/zui/zq_vtab_page.cpp @@ -13,4 +13,9 @@ ZQVTabPage::ZQVTabPage(QTabWidget *fathertab, const QString &zh_name) : QWidget( } void ZQVTabPage::addBox(QGroupBox *box) { m_layout->addWidget(box); -} \ No newline at end of file +} + +void ZQVTabPage::addSpacer() { + m_verticalSpacer = new QSpacerItem(20, 1000, QSizePolicy::Minimum, QSizePolicy::Expanding); + m_layout->addItem(m_verticalSpacer); +} diff --git a/libzqt/zui/zq_vtab_page.hpp b/libzqt/zui/zq_vtab_page.hpp index fec6276..a832b12 100644 --- a/libzqt/zui/zq_vtab_page.hpp +++ b/libzqt/zui/zq_vtab_page.hpp @@ -33,7 +33,6 @@ #include "../zexception.hpp" - namespace iflytop { using namespace std; class ZQVTabPage : public QWidget { @@ -43,8 +42,11 @@ class ZQVTabPage : public QWidget { QVBoxLayout *m_layout; int m_itermNum = 0; + QSpacerItem *m_verticalSpacer = nullptr; + public: ZQVTabPage(QTabWidget *fathertab, const QString &zh_name); void addBox(QGroupBox *box); + void addSpacer(); }; } // namespace iflytop diff --git a/libzqt/zui/zui.hpp b/libzqt/zui/zui.hpp new file mode 100644 index 0000000..616cd62 --- /dev/null +++ b/libzqt/zui/zui.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include "z_function_list_box.hpp" +#include "zq_vtab_page.hpp" +#include "z_reg_table_list_box.hpp" \ No newline at end of file diff --git a/mainwindow.cpp b/mainwindow.cpp index bc1471b..ea4e6d8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -15,6 +15,9 @@ #include "zexception.hpp" #include "zui/z_function_list_box.hpp" #include "zui/zq_vtab_page.hpp" +// +#include "zui/zui.hpp" + using namespace std; using namespace iflytop; using namespace zcr; @@ -331,10 +334,37 @@ void MainWindow::processException(const zexception &e) { // void MainWindow::constructAppUI() { { ZQVTabPage *tab = new ZQVTabPage(ui->buttonTabWidget, "模块操作"); + ZQFunctionListBox *box = new ZQFunctionListBox(tab, "模块基础操作", 4); box->regOnException([this](const zexception &e) { processException(e); }); box->newFunc("扫描模块", {"deviceId"}, [](int argn, const char **args) { // IflytopCanbusMaster::ins()->callcmd(atoi(args[0]), kmodule_ping); }); + box->newFunc("扫描模块", {"deviceId"}, [](int argn, const char **args) { // + IflytopCanbusMaster::ins()->callcmd(atoi(args[0]), kmodule_ping); + }); + box->newFunc("扫描模块", {"deviceId"}, [](int argn, const char **args) { // + IflytopCanbusMaster::ins()->callcmd(atoi(args[0]), kmodule_ping); + }); + + ZQFunctionListBox *box2 = new ZQFunctionListBox(tab, "模块基础操作", 4); + box2->regOnException([this](const zexception &e) { processException(e); }); + box2->newFunc("扫描模块", {"deviceId"}, [](int argn, const char **args) { // + IflytopCanbusMaster::ins()->callcmd(atoi(args[0]), kmodule_ping); + }); + + tab->addSpacer(); + } + + { + ZQVTabPage *tab = new ZQVTabPage(ui->buttonTabWidget, "寄存器操作"); + + ZRegTableList *tableBox = new ZRegTableList(tab, "寄存器操作"); + tableBox->addReg("123", 1, ZRegItem::krw); + tableBox->addReg("234", 1, ZRegItem::krw); + tableBox->addReg("345", 1, ZRegItem::krw); + tableBox->addSpacer(); + + tab->addSpacer(); } } diff --git a/mainwindow.ui b/mainwindow.ui index e4ab154..399a50c 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -937,12 +937,24 @@ p, li { white-space: pre-wrap; } 波形串口设置 - - - - 打开 + + + + + + + Qt::Vertical - + + + 20 + 40 + + + + + + @@ -951,8 +963,12 @@ p, li { white-space: pre-wrap; } - - + + + + 打开 + + @@ -961,9 +977,6 @@ p, li { white-space: pre-wrap; } - - - @@ -971,19 +984,6 @@ p, li { white-space: pre-wrap; } - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/src/main.cpp b/src/main.cpp index 367181f..277c72d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,6 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); - ZLOGI(TAG, "camera_light_src_timing_controller"); ZLOGI(TAG, "maufacturer : %s", MAUFACTURER); ZLOGI(TAG, "version : %d.0.0", VERSION);