diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 113f83b..a8f4891 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -115,5 +115,5 @@ } // 4. 在界面上简单显示相差数据结果 -// emit this->sendDataToDraw(counterData); + emit this->sendDataToDraw(counterData); } diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 113f83b..a8f4891 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -115,5 +115,5 @@ } // 4. 在界面上简单显示相差数据结果 -// emit this->sendDataToDraw(counterData); + emit this->sendDataToDraw(counterData); } diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 6059e0b..a3729d2 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -4,6 +4,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include CounterWindow::CounterWindow(QWidget *parent) : QWidget(parent), @@ -23,22 +29,31 @@ CounterDevice * device = new CounterDevice(this); // -// connect(device, &CounterDevice::sendDataToDraw, -// this, &CounterWindow::drawPhaseDataOnPage); + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); device->setComName(comDevList.at(i)); device->setBaudRate(baudRate); device->setDevCode(devCodeList.at(i)); -// this->deviceList.append(device); + this->deviceList.append(device); device->initSerialPort(); // device->startWork(); } - timer = new QTimer(this); - timer->start(1000 * 10); + for (int i = 0; i < this->deviceList.size(); i++) + { + QWidget * devWidget = new QWidget(this->ui->stackedWidget); + ui->stackedWidget->addWidget(devWidget); + devWidgetList.append(devWidget); + + this->generateWidgetForDevice(devCodeList.at(i), i); + } + +// timer = new QTimer(this); +// timer->start(1000 * 10); } CounterWindow::~CounterWindow() @@ -46,12 +61,6 @@ delete ui; } -void CounterWindow::on_pushButton_clicked() -{ - connect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); -} - void CounterWindow::mockOneFrame() { qlonglong deviceId = 9101; @@ -88,8 +97,110 @@ } } -void CounterWindow::on_pushButton_2_clicked() +void CounterWindow::generateWidgetForDevice(QString devCode, int index) { - disconnect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); + // 顶部切换widget + QWidget * switchWidget = new QWidget(this->devWidgetList.at(index)); + switchWidget->setGeometry(0, 0, 1024, 50); + + // 显示数据的区域 + QWidget * gridWidget = new QWidget(this->devWidgetList.at(index)); + gridWidget->setGeometry(0, 50, 1024, 670); + + // 顶部水平布局,用于排布按钮 + QHBoxLayout * hLayout = new QHBoxLayout(switchWidget); + + // 文本 + QLabel * label = new QLabel(switchWidget); + label->setText("设备编号:" + devCode); + label->setFont(QFont("微软雅黑", 12)); + hLayout->addWidget(label); + + // 按钮 + for (int i = 0; i < this->deviceList.size(); i++) + { + QPushButton * butt5 = new QPushButton(this->deviceList.at(i)->getDevCode()); + hLayout->addWidget(butt5); + + connect(butt5, &QPushButton::clicked, [=](){ + this->ui->stackedWidget->setCurrentIndex(i); + }); + } + + // Grid布局 + QGridLayout * gridLayout = new QGridLayout(gridWidget); + gridLayout->setSpacing(10); + + QList channelModelList; + QStringList labels = QObject::trUtf8("时间,clock").simplified().split(","); + + for (int i = 0; i < 16; i++) + { + QTableView * channelTable = new QTableView(gridWidget); + QStandardItemModel * model = new QStandardItemModel(channelTable); + + model->setHorizontalHeaderLabels(labels); + + channelTable->setModel(model); + + gridLayout->addWidget(channelTable, i / 4, i % 4); + + channelTable->verticalHeader()->hide(); + channelTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + channelTable->scrollToBottom(); + + channelModelList.append(model); + } + + this->tableModelList.append(channelModelList); +} + +void CounterWindow::drawCounterDataOnPage(CounterDataDto * counterData) +{ + // 1. 判断数据属于哪个设备,显示在不同的widget上 + + // 2. 循环设置各个tableView + QList devChannels = this->tableModelList.at(0); // 暂时写死 + QList row; + QStandardItem * itemTm = 0; + QStandardItem * itemData = 0; + itemTm = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); + itemData = new QStandardItem(QString("%1").arg(counterData->channelData)); + + row.append(itemTm); + row.append(itemData); + + QStandardItemModel * model; + model = devChannels.at(counterData->channelId - 1); + if (model->rowCount() >= 20) + { + model->removeRows(0, model->rowCount()); + } + + model->insertRow(0, row); + + +// for (int i = 0; i < counterData->channelData.size(); i++) +// { +// if (counterData->channelActive.at(i).toInt() == 1) +// { +// QList row; +// QStandardItem * item = 0; +// QStandardItem * item2 = 0; +// item = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); +// item2 = new QStandardItem(QString("%1").arg(counterData->channelData.at(i))); + +// row.append(item); +// row.append(item2); + +// QStandardItemModel * model; +// model = devChannels.at(i); +// if (model->rowCount() >= 60) +// { +// model->removeRows(0, model->rowCount()); +// } + +// model->insertRow(0, row); +// } +// } } diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 113f83b..a8f4891 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -115,5 +115,5 @@ } // 4. 在界面上简单显示相差数据结果 -// emit this->sendDataToDraw(counterData); + emit this->sendDataToDraw(counterData); } diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 6059e0b..a3729d2 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -4,6 +4,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include CounterWindow::CounterWindow(QWidget *parent) : QWidget(parent), @@ -23,22 +29,31 @@ CounterDevice * device = new CounterDevice(this); // -// connect(device, &CounterDevice::sendDataToDraw, -// this, &CounterWindow::drawPhaseDataOnPage); + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); device->setComName(comDevList.at(i)); device->setBaudRate(baudRate); device->setDevCode(devCodeList.at(i)); -// this->deviceList.append(device); + this->deviceList.append(device); device->initSerialPort(); // device->startWork(); } - timer = new QTimer(this); - timer->start(1000 * 10); + for (int i = 0; i < this->deviceList.size(); i++) + { + QWidget * devWidget = new QWidget(this->ui->stackedWidget); + ui->stackedWidget->addWidget(devWidget); + devWidgetList.append(devWidget); + + this->generateWidgetForDevice(devCodeList.at(i), i); + } + +// timer = new QTimer(this); +// timer->start(1000 * 10); } CounterWindow::~CounterWindow() @@ -46,12 +61,6 @@ delete ui; } -void CounterWindow::on_pushButton_clicked() -{ - connect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); -} - void CounterWindow::mockOneFrame() { qlonglong deviceId = 9101; @@ -88,8 +97,110 @@ } } -void CounterWindow::on_pushButton_2_clicked() +void CounterWindow::generateWidgetForDevice(QString devCode, int index) { - disconnect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); + // 顶部切换widget + QWidget * switchWidget = new QWidget(this->devWidgetList.at(index)); + switchWidget->setGeometry(0, 0, 1024, 50); + + // 显示数据的区域 + QWidget * gridWidget = new QWidget(this->devWidgetList.at(index)); + gridWidget->setGeometry(0, 50, 1024, 670); + + // 顶部水平布局,用于排布按钮 + QHBoxLayout * hLayout = new QHBoxLayout(switchWidget); + + // 文本 + QLabel * label = new QLabel(switchWidget); + label->setText("设备编号:" + devCode); + label->setFont(QFont("微软雅黑", 12)); + hLayout->addWidget(label); + + // 按钮 + for (int i = 0; i < this->deviceList.size(); i++) + { + QPushButton * butt5 = new QPushButton(this->deviceList.at(i)->getDevCode()); + hLayout->addWidget(butt5); + + connect(butt5, &QPushButton::clicked, [=](){ + this->ui->stackedWidget->setCurrentIndex(i); + }); + } + + // Grid布局 + QGridLayout * gridLayout = new QGridLayout(gridWidget); + gridLayout->setSpacing(10); + + QList channelModelList; + QStringList labels = QObject::trUtf8("时间,clock").simplified().split(","); + + for (int i = 0; i < 16; i++) + { + QTableView * channelTable = new QTableView(gridWidget); + QStandardItemModel * model = new QStandardItemModel(channelTable); + + model->setHorizontalHeaderLabels(labels); + + channelTable->setModel(model); + + gridLayout->addWidget(channelTable, i / 4, i % 4); + + channelTable->verticalHeader()->hide(); + channelTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + channelTable->scrollToBottom(); + + channelModelList.append(model); + } + + this->tableModelList.append(channelModelList); +} + +void CounterWindow::drawCounterDataOnPage(CounterDataDto * counterData) +{ + // 1. 判断数据属于哪个设备,显示在不同的widget上 + + // 2. 循环设置各个tableView + QList devChannels = this->tableModelList.at(0); // 暂时写死 + QList row; + QStandardItem * itemTm = 0; + QStandardItem * itemData = 0; + itemTm = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); + itemData = new QStandardItem(QString("%1").arg(counterData->channelData)); + + row.append(itemTm); + row.append(itemData); + + QStandardItemModel * model; + model = devChannels.at(counterData->channelId - 1); + if (model->rowCount() >= 20) + { + model->removeRows(0, model->rowCount()); + } + + model->insertRow(0, row); + + +// for (int i = 0; i < counterData->channelData.size(); i++) +// { +// if (counterData->channelActive.at(i).toInt() == 1) +// { +// QList row; +// QStandardItem * item = 0; +// QStandardItem * item2 = 0; +// item = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); +// item2 = new QStandardItem(QString("%1").arg(counterData->channelData.at(i))); + +// row.append(item); +// row.append(item2); + +// QStandardItemModel * model; +// model = devChannels.at(i); +// if (model->rowCount() >= 60) +// { +// model->removeRows(0, model->rowCount()); +// } + +// model->insertRow(0, row); +// } +// } } diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index c95eebc..d231f5d 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -2,6 +2,8 @@ #define COUNTERWINDOW_H #include +#include + #include "common/utils/SettingConfig.h" #include "common/utils/QKafkaUtil.h" #include "CounterDevice.h" @@ -18,17 +20,23 @@ explicit CounterWindow(QWidget *parent = nullptr); ~CounterWindow(); +public slots: + void drawCounterDataOnPage(CounterDataDto * counterData); + private slots: - void on_pushButton_clicked(); - void mockOneFrame(); - void on_pushButton_2_clicked(); - private: Ui::CounterWindow *ui; QTimer * timer; + + QList devWidgetList; + + QList deviceList; + QList> tableModelList; + + void generateWidgetForDevice(QString devCode, int index); }; #endif // COUNTERWINDOW_H diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 113f83b..a8f4891 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -115,5 +115,5 @@ } // 4. 在界面上简单显示相差数据结果 -// emit this->sendDataToDraw(counterData); + emit this->sendDataToDraw(counterData); } diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 6059e0b..a3729d2 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -4,6 +4,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include CounterWindow::CounterWindow(QWidget *parent) : QWidget(parent), @@ -23,22 +29,31 @@ CounterDevice * device = new CounterDevice(this); // -// connect(device, &CounterDevice::sendDataToDraw, -// this, &CounterWindow::drawPhaseDataOnPage); + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); device->setComName(comDevList.at(i)); device->setBaudRate(baudRate); device->setDevCode(devCodeList.at(i)); -// this->deviceList.append(device); + this->deviceList.append(device); device->initSerialPort(); // device->startWork(); } - timer = new QTimer(this); - timer->start(1000 * 10); + for (int i = 0; i < this->deviceList.size(); i++) + { + QWidget * devWidget = new QWidget(this->ui->stackedWidget); + ui->stackedWidget->addWidget(devWidget); + devWidgetList.append(devWidget); + + this->generateWidgetForDevice(devCodeList.at(i), i); + } + +// timer = new QTimer(this); +// timer->start(1000 * 10); } CounterWindow::~CounterWindow() @@ -46,12 +61,6 @@ delete ui; } -void CounterWindow::on_pushButton_clicked() -{ - connect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); -} - void CounterWindow::mockOneFrame() { qlonglong deviceId = 9101; @@ -88,8 +97,110 @@ } } -void CounterWindow::on_pushButton_2_clicked() +void CounterWindow::generateWidgetForDevice(QString devCode, int index) { - disconnect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); + // 顶部切换widget + QWidget * switchWidget = new QWidget(this->devWidgetList.at(index)); + switchWidget->setGeometry(0, 0, 1024, 50); + + // 显示数据的区域 + QWidget * gridWidget = new QWidget(this->devWidgetList.at(index)); + gridWidget->setGeometry(0, 50, 1024, 670); + + // 顶部水平布局,用于排布按钮 + QHBoxLayout * hLayout = new QHBoxLayout(switchWidget); + + // 文本 + QLabel * label = new QLabel(switchWidget); + label->setText("设备编号:" + devCode); + label->setFont(QFont("微软雅黑", 12)); + hLayout->addWidget(label); + + // 按钮 + for (int i = 0; i < this->deviceList.size(); i++) + { + QPushButton * butt5 = new QPushButton(this->deviceList.at(i)->getDevCode()); + hLayout->addWidget(butt5); + + connect(butt5, &QPushButton::clicked, [=](){ + this->ui->stackedWidget->setCurrentIndex(i); + }); + } + + // Grid布局 + QGridLayout * gridLayout = new QGridLayout(gridWidget); + gridLayout->setSpacing(10); + + QList channelModelList; + QStringList labels = QObject::trUtf8("时间,clock").simplified().split(","); + + for (int i = 0; i < 16; i++) + { + QTableView * channelTable = new QTableView(gridWidget); + QStandardItemModel * model = new QStandardItemModel(channelTable); + + model->setHorizontalHeaderLabels(labels); + + channelTable->setModel(model); + + gridLayout->addWidget(channelTable, i / 4, i % 4); + + channelTable->verticalHeader()->hide(); + channelTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + channelTable->scrollToBottom(); + + channelModelList.append(model); + } + + this->tableModelList.append(channelModelList); +} + +void CounterWindow::drawCounterDataOnPage(CounterDataDto * counterData) +{ + // 1. 判断数据属于哪个设备,显示在不同的widget上 + + // 2. 循环设置各个tableView + QList devChannels = this->tableModelList.at(0); // 暂时写死 + QList row; + QStandardItem * itemTm = 0; + QStandardItem * itemData = 0; + itemTm = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); + itemData = new QStandardItem(QString("%1").arg(counterData->channelData)); + + row.append(itemTm); + row.append(itemData); + + QStandardItemModel * model; + model = devChannels.at(counterData->channelId - 1); + if (model->rowCount() >= 20) + { + model->removeRows(0, model->rowCount()); + } + + model->insertRow(0, row); + + +// for (int i = 0; i < counterData->channelData.size(); i++) +// { +// if (counterData->channelActive.at(i).toInt() == 1) +// { +// QList row; +// QStandardItem * item = 0; +// QStandardItem * item2 = 0; +// item = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); +// item2 = new QStandardItem(QString("%1").arg(counterData->channelData.at(i))); + +// row.append(item); +// row.append(item2); + +// QStandardItemModel * model; +// model = devChannels.at(i); +// if (model->rowCount() >= 60) +// { +// model->removeRows(0, model->rowCount()); +// } + +// model->insertRow(0, row); +// } +// } } diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index c95eebc..d231f5d 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -2,6 +2,8 @@ #define COUNTERWINDOW_H #include +#include + #include "common/utils/SettingConfig.h" #include "common/utils/QKafkaUtil.h" #include "CounterDevice.h" @@ -18,17 +20,23 @@ explicit CounterWindow(QWidget *parent = nullptr); ~CounterWindow(); +public slots: + void drawCounterDataOnPage(CounterDataDto * counterData); + private slots: - void on_pushButton_clicked(); - void mockOneFrame(); - void on_pushButton_2_clicked(); - private: Ui::CounterWindow *ui; QTimer * timer; + + QList devWidgetList; + + QList deviceList; + QList> tableModelList; + + void generateWidgetForDevice(QString devCode, int index); }; #endif // COUNTERWINDOW_H diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui deleted file mode 100644 index a0d666c..0000000 --- a/CounterAcq/CounterWindow.ui +++ /dev/null @@ -1,45 +0,0 @@ - - - CounterWindow - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - 100 - 40 - 181 - 51 - - - - Mock ClockDiff Data - - - - - - 100 - 120 - 181 - 41 - - - - Stop Mock - - - - - - diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 113f83b..a8f4891 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -115,5 +115,5 @@ } // 4. 在界面上简单显示相差数据结果 -// emit this->sendDataToDraw(counterData); + emit this->sendDataToDraw(counterData); } diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 6059e0b..a3729d2 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -4,6 +4,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include CounterWindow::CounterWindow(QWidget *parent) : QWidget(parent), @@ -23,22 +29,31 @@ CounterDevice * device = new CounterDevice(this); // -// connect(device, &CounterDevice::sendDataToDraw, -// this, &CounterWindow::drawPhaseDataOnPage); + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); device->setComName(comDevList.at(i)); device->setBaudRate(baudRate); device->setDevCode(devCodeList.at(i)); -// this->deviceList.append(device); + this->deviceList.append(device); device->initSerialPort(); // device->startWork(); } - timer = new QTimer(this); - timer->start(1000 * 10); + for (int i = 0; i < this->deviceList.size(); i++) + { + QWidget * devWidget = new QWidget(this->ui->stackedWidget); + ui->stackedWidget->addWidget(devWidget); + devWidgetList.append(devWidget); + + this->generateWidgetForDevice(devCodeList.at(i), i); + } + +// timer = new QTimer(this); +// timer->start(1000 * 10); } CounterWindow::~CounterWindow() @@ -46,12 +61,6 @@ delete ui; } -void CounterWindow::on_pushButton_clicked() -{ - connect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); -} - void CounterWindow::mockOneFrame() { qlonglong deviceId = 9101; @@ -88,8 +97,110 @@ } } -void CounterWindow::on_pushButton_2_clicked() +void CounterWindow::generateWidgetForDevice(QString devCode, int index) { - disconnect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); + // 顶部切换widget + QWidget * switchWidget = new QWidget(this->devWidgetList.at(index)); + switchWidget->setGeometry(0, 0, 1024, 50); + + // 显示数据的区域 + QWidget * gridWidget = new QWidget(this->devWidgetList.at(index)); + gridWidget->setGeometry(0, 50, 1024, 670); + + // 顶部水平布局,用于排布按钮 + QHBoxLayout * hLayout = new QHBoxLayout(switchWidget); + + // 文本 + QLabel * label = new QLabel(switchWidget); + label->setText("设备编号:" + devCode); + label->setFont(QFont("微软雅黑", 12)); + hLayout->addWidget(label); + + // 按钮 + for (int i = 0; i < this->deviceList.size(); i++) + { + QPushButton * butt5 = new QPushButton(this->deviceList.at(i)->getDevCode()); + hLayout->addWidget(butt5); + + connect(butt5, &QPushButton::clicked, [=](){ + this->ui->stackedWidget->setCurrentIndex(i); + }); + } + + // Grid布局 + QGridLayout * gridLayout = new QGridLayout(gridWidget); + gridLayout->setSpacing(10); + + QList channelModelList; + QStringList labels = QObject::trUtf8("时间,clock").simplified().split(","); + + for (int i = 0; i < 16; i++) + { + QTableView * channelTable = new QTableView(gridWidget); + QStandardItemModel * model = new QStandardItemModel(channelTable); + + model->setHorizontalHeaderLabels(labels); + + channelTable->setModel(model); + + gridLayout->addWidget(channelTable, i / 4, i % 4); + + channelTable->verticalHeader()->hide(); + channelTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + channelTable->scrollToBottom(); + + channelModelList.append(model); + } + + this->tableModelList.append(channelModelList); +} + +void CounterWindow::drawCounterDataOnPage(CounterDataDto * counterData) +{ + // 1. 判断数据属于哪个设备,显示在不同的widget上 + + // 2. 循环设置各个tableView + QList devChannels = this->tableModelList.at(0); // 暂时写死 + QList row; + QStandardItem * itemTm = 0; + QStandardItem * itemData = 0; + itemTm = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); + itemData = new QStandardItem(QString("%1").arg(counterData->channelData)); + + row.append(itemTm); + row.append(itemData); + + QStandardItemModel * model; + model = devChannels.at(counterData->channelId - 1); + if (model->rowCount() >= 20) + { + model->removeRows(0, model->rowCount()); + } + + model->insertRow(0, row); + + +// for (int i = 0; i < counterData->channelData.size(); i++) +// { +// if (counterData->channelActive.at(i).toInt() == 1) +// { +// QList row; +// QStandardItem * item = 0; +// QStandardItem * item2 = 0; +// item = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); +// item2 = new QStandardItem(QString("%1").arg(counterData->channelData.at(i))); + +// row.append(item); +// row.append(item2); + +// QStandardItemModel * model; +// model = devChannels.at(i); +// if (model->rowCount() >= 60) +// { +// model->removeRows(0, model->rowCount()); +// } + +// model->insertRow(0, row); +// } +// } } diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index c95eebc..d231f5d 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -2,6 +2,8 @@ #define COUNTERWINDOW_H #include +#include + #include "common/utils/SettingConfig.h" #include "common/utils/QKafkaUtil.h" #include "CounterDevice.h" @@ -18,17 +20,23 @@ explicit CounterWindow(QWidget *parent = nullptr); ~CounterWindow(); +public slots: + void drawCounterDataOnPage(CounterDataDto * counterData); + private slots: - void on_pushButton_clicked(); - void mockOneFrame(); - void on_pushButton_2_clicked(); - private: Ui::CounterWindow *ui; QTimer * timer; + + QList devWidgetList; + + QList deviceList; + QList> tableModelList; + + void generateWidgetForDevice(QString devCode, int index); }; #endif // COUNTERWINDOW_H diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui deleted file mode 100644 index a0d666c..0000000 --- a/CounterAcq/CounterWindow.ui +++ /dev/null @@ -1,45 +0,0 @@ - - - CounterWindow - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - 100 - 40 - 181 - 51 - - - - Mock ClockDiff Data - - - - - - 100 - 120 - 181 - 41 - - - - Stop Mock - - - - - - diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp index 3870199..2da13b2 100644 --- a/CounterAcq/common/utils/QSerialPortUtil.cpp +++ b/CounterAcq/common/utils/QSerialPortUtil.cpp @@ -30,7 +30,7 @@ QTimer * timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); - timer->start(1000 * 5); + timer->start(1000); // } } diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 113f83b..a8f4891 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -115,5 +115,5 @@ } // 4. 在界面上简单显示相差数据结果 -// emit this->sendDataToDraw(counterData); + emit this->sendDataToDraw(counterData); } diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 6059e0b..a3729d2 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -4,6 +4,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include CounterWindow::CounterWindow(QWidget *parent) : QWidget(parent), @@ -23,22 +29,31 @@ CounterDevice * device = new CounterDevice(this); // -// connect(device, &CounterDevice::sendDataToDraw, -// this, &CounterWindow::drawPhaseDataOnPage); + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); device->setComName(comDevList.at(i)); device->setBaudRate(baudRate); device->setDevCode(devCodeList.at(i)); -// this->deviceList.append(device); + this->deviceList.append(device); device->initSerialPort(); // device->startWork(); } - timer = new QTimer(this); - timer->start(1000 * 10); + for (int i = 0; i < this->deviceList.size(); i++) + { + QWidget * devWidget = new QWidget(this->ui->stackedWidget); + ui->stackedWidget->addWidget(devWidget); + devWidgetList.append(devWidget); + + this->generateWidgetForDevice(devCodeList.at(i), i); + } + +// timer = new QTimer(this); +// timer->start(1000 * 10); } CounterWindow::~CounterWindow() @@ -46,12 +61,6 @@ delete ui; } -void CounterWindow::on_pushButton_clicked() -{ - connect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); -} - void CounterWindow::mockOneFrame() { qlonglong deviceId = 9101; @@ -88,8 +97,110 @@ } } -void CounterWindow::on_pushButton_2_clicked() +void CounterWindow::generateWidgetForDevice(QString devCode, int index) { - disconnect(timer, &QTimer::timeout, - this, &CounterWindow::mockOneFrame); + // 顶部切换widget + QWidget * switchWidget = new QWidget(this->devWidgetList.at(index)); + switchWidget->setGeometry(0, 0, 1024, 50); + + // 显示数据的区域 + QWidget * gridWidget = new QWidget(this->devWidgetList.at(index)); + gridWidget->setGeometry(0, 50, 1024, 670); + + // 顶部水平布局,用于排布按钮 + QHBoxLayout * hLayout = new QHBoxLayout(switchWidget); + + // 文本 + QLabel * label = new QLabel(switchWidget); + label->setText("设备编号:" + devCode); + label->setFont(QFont("微软雅黑", 12)); + hLayout->addWidget(label); + + // 按钮 + for (int i = 0; i < this->deviceList.size(); i++) + { + QPushButton * butt5 = new QPushButton(this->deviceList.at(i)->getDevCode()); + hLayout->addWidget(butt5); + + connect(butt5, &QPushButton::clicked, [=](){ + this->ui->stackedWidget->setCurrentIndex(i); + }); + } + + // Grid布局 + QGridLayout * gridLayout = new QGridLayout(gridWidget); + gridLayout->setSpacing(10); + + QList channelModelList; + QStringList labels = QObject::trUtf8("时间,clock").simplified().split(","); + + for (int i = 0; i < 16; i++) + { + QTableView * channelTable = new QTableView(gridWidget); + QStandardItemModel * model = new QStandardItemModel(channelTable); + + model->setHorizontalHeaderLabels(labels); + + channelTable->setModel(model); + + gridLayout->addWidget(channelTable, i / 4, i % 4); + + channelTable->verticalHeader()->hide(); + channelTable->setEditTriggers(QAbstractItemView::NoEditTriggers); + channelTable->scrollToBottom(); + + channelModelList.append(model); + } + + this->tableModelList.append(channelModelList); +} + +void CounterWindow::drawCounterDataOnPage(CounterDataDto * counterData) +{ + // 1. 判断数据属于哪个设备,显示在不同的widget上 + + // 2. 循环设置各个tableView + QList devChannels = this->tableModelList.at(0); // 暂时写死 + QList row; + QStandardItem * itemTm = 0; + QStandardItem * itemData = 0; + itemTm = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); + itemData = new QStandardItem(QString("%1").arg(counterData->channelData)); + + row.append(itemTm); + row.append(itemData); + + QStandardItemModel * model; + model = devChannels.at(counterData->channelId - 1); + if (model->rowCount() >= 20) + { + model->removeRows(0, model->rowCount()); + } + + model->insertRow(0, row); + + +// for (int i = 0; i < counterData->channelData.size(); i++) +// { +// if (counterData->channelActive.at(i).toInt() == 1) +// { +// QList row; +// QStandardItem * item = 0; +// QStandardItem * item2 = 0; +// item = new QStandardItem(QString("%1").arg(counterData->timestamp.mid(11, 12))); +// item2 = new QStandardItem(QString("%1").arg(counterData->channelData.at(i))); + +// row.append(item); +// row.append(item2); + +// QStandardItemModel * model; +// model = devChannels.at(i); +// if (model->rowCount() >= 60) +// { +// model->removeRows(0, model->rowCount()); +// } + +// model->insertRow(0, row); +// } +// } } diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index c95eebc..d231f5d 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -2,6 +2,8 @@ #define COUNTERWINDOW_H #include +#include + #include "common/utils/SettingConfig.h" #include "common/utils/QKafkaUtil.h" #include "CounterDevice.h" @@ -18,17 +20,23 @@ explicit CounterWindow(QWidget *parent = nullptr); ~CounterWindow(); +public slots: + void drawCounterDataOnPage(CounterDataDto * counterData); + private slots: - void on_pushButton_clicked(); - void mockOneFrame(); - void on_pushButton_2_clicked(); - private: Ui::CounterWindow *ui; QTimer * timer; + + QList devWidgetList; + + QList deviceList; + QList> tableModelList; + + void generateWidgetForDevice(QString devCode, int index); }; #endif // COUNTERWINDOW_H diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui deleted file mode 100644 index a0d666c..0000000 --- a/CounterAcq/CounterWindow.ui +++ /dev/null @@ -1,45 +0,0 @@ - - - CounterWindow - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - 100 - 40 - 181 - 51 - - - - Mock ClockDiff Data - - - - - - 100 - 120 - 181 - 41 - - - - Stop Mock - - - - - - diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp index 3870199..2da13b2 100644 --- a/CounterAcq/common/utils/QSerialPortUtil.cpp +++ b/CounterAcq/common/utils/QSerialPortUtil.cpp @@ -30,7 +30,7 @@ QTimer * timer = new QTimer(this); connect(timer, &QTimer::timeout, this, &QSerialPortUtil::mockReceivData); - timer->start(1000 * 5); + timer->start(1000); // } } diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini index fdc1c17..0840fa9 100644 --- a/CounterAcq/conf/config.ini +++ b/CounterAcq/conf/config.ini @@ -4,7 +4,7 @@ baudRate=115200 [kafka] -neekKafka=1 +needKafka=1 brokers="111.198.10.15:12502" dataTopic="cppTest"