diff --git a/mainwindow.cpp b/mainwindow.cpp index a79397b..6f547c7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -277,55 +277,27 @@ void MainWindow::constructBaseUI() { void MainWindow::displayInfo(bool suc, QString info) {} -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { - /** - * @brief QT初始化 - */ - ui->setupUi(this); - m_mainWindow = this; - qRegisterMetaType("int32_t"); - qRegisterMetaType("uint32_t"); - qRegisterMetaType("float"); - qRegisterMetaType>("function"); - qRegisterMetaType("QFunction"); - connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); - - /** - * @brief 页面逻辑初始化 - */ - constructBaseUI(); - constructAppUI(); - - /** - * @brief 业务逻辑构造 - */ - G_QTDataChannel.init(); - G_WaveDataChannel.init(); - ElectrocardiographTester::ins()->initialize(&G_QTDataChannel); -} -MainWindow::~MainWindow() { delete ui; } - -void MainWindow::processException(zexception &e) { // - instructionPreviewShow("%s:%s", e.what(), hrs_ecode2str((ify_hrs_error_code_t)e.ecode())); -} - -void MainWindow::constructAppUI() { - { - QWidget *tab = allocNewTab("测试TAB"); - { - { - QGroupBox *box = allocNewBox(tab, "测试BOX", 4); - allocNewButtonStyle1(box, "测试按钮1", {"123", "456"}, // - [](int argn, const char **args) { m_mainWindow->instructionPreviewShow("测试按钮1"); }); - allocNewButtonStyle1(box, "测试按钮1", {"123"}, // - [](int argn, const char **args) { m_mainWindow->instructionPreviewShow("测试按钮1"); }); - endAllocNewBox(box); - } - } - endAllocNewTab(tab); - } -} +/*********************************************************************************************************************** + * 页面构造工具 * + ***********************************************************************************************************************/ +/** + * @brief 构造样式如下 + * + * +TAB---------------------------------+ + * |---BOX---------------------------| + * | |Button|Param|Param| | + * | |Button|Param|Param| | + * | |Button|Param|Param| | + * |---------------------------------| + * |---BOX---------------------------| + * | |Button|Param|Param| | + * | |Button|Param|Param| | + * | |Button|Param|Param| | + * |---------------------------------| + * + * + */ QWidget *MainWindow::allocNewTab(QString zh_name) { QWidget *newtab = new QWidget(); QVBoxLayout *verticalLayout = new QVBoxLayout(newtab); // 设置布局 @@ -360,7 +332,7 @@ void MainWindow::endAllocNewBox(QGroupBox *box) { // layout->addItem(verticalSpacer, layout->rowCount(), 0, 1, 1); } -void MainWindow::allocNewButtonStyle1(QWidget *box, QString zh_name, QStringList params, std::function onButtonClick) { // +void MainWindow::addNewButtonStyle1(QWidget *box, QString zh_name, QStringList params, std::function onButtonClick) { // QGridLayout *layout = qobject_cast(box->layout()); int rowcnt = layout->rowCount(); @@ -375,12 +347,76 @@ void MainWindow::allocNewButtonStyle1(QWidget *box, QString zh_name, QStringList button->setSizePolicy(sizePolicy); layout->addWidget(button, rowcnt, 0, 1, 1); + QList lineEdits; + for (int i = 0; i < params.size(); i++) { QLineEdit *lineEdit = new QLineEdit(box); lineEdit->setMinimumHeight(30); // lineEdit->sizePolicy().setHorizontalStretch(1); lineEdit->setSizePolicy(sizePolicy); lineEdit->setPlaceholderText(params[i]); + lineEdits.push_back(lineEdit); layout->addWidget(lineEdit, rowcnt, i + 1, 1, 1); } + + connect(button, &QPushButton::clicked, this, [onButtonClick, lineEdits]() { + vector params; + for (int i = 0; i < lineEdits.size(); i++) { + params.push_back(lineEdits[i]->text().toStdString()); + } + char *args[params.size()]; + for (int i = 0; i < params.size(); i++) { + args[i] = (char *)params[i].c_str(); + } + onButtonClick(params.size(), (const char **)args); + }); +} + +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + /** + * @brief QT初始化 + */ + ui->setupUi(this); + m_mainWindow = this; + qRegisterMetaType("int32_t"); + qRegisterMetaType("uint32_t"); + qRegisterMetaType("float"); + qRegisterMetaType>("function"); + qRegisterMetaType("QFunction"); + connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); + + /** + * @brief 页面逻辑初始化 + */ + constructBaseUI(); + constructAppUI(); + + /** + * @brief 业务逻辑构造 + */ + G_QTDataChannel.init(); + G_WaveDataChannel.init(); + ElectrocardiographTester::ins()->initialize(&G_QTDataChannel); +} +MainWindow::~MainWindow() { delete ui; } + +void MainWindow::processException(zexception &e) { // + instructionPreviewShow("%s:%s", e.what(), hrs_ecode2str((ify_hrs_error_code_t)e.ecode())); +} + +void MainWindow::constructAppUI() { + { + QWidget *tab = allocNewTab("测试TAB"); + { + QGroupBox *box = allocNewBox(tab, "测试BOX", 4); + addNewButtonStyle1(box, "测试按钮1", {"123", "456", "789"}, [](int argn, const char **args) {}); + addNewButtonStyle1(box, "测试按钮1", {"123"}, [](int argn, const char **args) {}); + endAllocNewBox(box); + } + endAllocNewTab(tab); + } + + + + } diff --git a/mainwindow.h b/mainwindow.h index e9daf97..df4770b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -110,7 +110,7 @@ class MainWindow : public QMainWindow { QWidget *allocNewTab(QString zh_name); QGroupBox *allocNewBox(QWidget *tab, QString zh_name, int column); - void allocNewButtonStyle1(QWidget *box, QString zh_name, QStringList params, std::function onButtonClick); + void addNewButtonStyle1(QWidget *box, QString zh_name, QStringList params, std::function onButtonClick); void endAllocNewBox(QGroupBox *box); void endAllocNewTab(QWidget *tab); }; diff --git a/mainwindow.ui b/mainwindow.ui index f16c61c..52cd606 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -881,222 +881,8 @@ p, li { white-space: pre-wrap; } Qt::DefaultContextMenu - 0 + -1 - - - - - - - - - 设备信息 - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 1 - 0 - - - - - 0 - 30 - - - - 读取设备状态信息 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 1 - 0 - - - - - 0 - 30 - - - - 读取设备SN - - - - - - - - 2 - 0 - - - - - 0 - 30 - - - - 读取设备版本信息 - - - - - - - - 1 - 0 - - - - - 0 - 30 - - - - 读取传感器信息 - - - - - - - - 1 - 0 - - - - - 0 - 30 - - - - 同步时间 - - - - - - - - 1 - 0 - - - - - 0 - 30 - - - - 读取设备时间 - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 123 - - - - - - 设备信息 - - - - - - - 1 - 0 - - - - - 0 - 30 - - - - 读取设备版本信息 - - - - - - - PushButton - - - - - - - -