From 246153fc8fa3520ed854f4a6eaaa7a5bf2ac3e27 Mon Sep 17 00:00:00 2001 From: HwangKC Date: Mon, 11 Nov 2024 15:28:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90page=20control=EF=BC=8C?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=95=B0=E6=8D=AE=E7=9A=84=E7=BF=BB=E9=A1=B5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/emsConfigurer/datafetcher.cpp | 4 +- applications/emsConfigurer/datafetcher.h | 2 +- .../emsConfigurer/devicepropertypage.cpp | 205 +++++++++++++++++- .../emsConfigurer/devicepropertypage.h | 41 ++++ .../formserialportsettingdialog.cpp | 2 +- .../emsConfigurer/globalparameters.cpp | 21 +- applications/emsConfigurer/globalparameters.h | 4 +- applications/emsConfigurer/hv_tcpclient.h | 7 +- applications/emsConfigurer/kutilities.cpp | 2 +- applications/emsConfigurer/maindialog.cpp | 12 + applications/emsConfigurer/maindialog.h | 3 + applications/emsConfigurer/mainwindow.cpp | 23 +- applications/emsConfigurer/mainwindow.h | 4 + applications/emsConfigurer/mainwindow.ui | 14 +- applications/emsConfigurer/mysqlutils.cpp | 50 +++-- applications/emsConfigurer/mysqlutils.h | 2 +- 16 files changed, 328 insertions(+), 68 deletions(-) diff --git a/applications/emsConfigurer/datafetcher.cpp b/applications/emsConfigurer/datafetcher.cpp index 5ba3949..84efd80 100644 --- a/applications/emsConfigurer/datafetcher.cpp +++ b/applications/emsConfigurer/datafetcher.cpp @@ -13,9 +13,9 @@ DataFetcher::~DataFetcher() } -bool DataFetcher::Fetch(TableData& tbl_data) +bool DataFetcher::Fetch(TableData& tbl_data,int fetch_rows) { - int rows = MysqlUtils::getInstance()->RetrieveTableData(tbl_data); + int rows = MysqlUtils::getInstance()->RetrieveTableData(tbl_data,fetch_rows); if (rows < 0) { hloge("Failed to retrieve signal data"); diff --git a/applications/emsConfigurer/datafetcher.h b/applications/emsConfigurer/datafetcher.h index c356884..d44a162 100644 --- a/applications/emsConfigurer/datafetcher.h +++ b/applications/emsConfigurer/datafetcher.h @@ -12,7 +12,7 @@ public: virtual ~DataFetcher(); public: - virtual bool Fetch(TableData& tbl_data); + virtual bool Fetch(TableData& tbl_data,int fetch_rows = 1000); protected: int VerifyStatus(); diff --git a/applications/emsConfigurer/devicepropertypage.cpp b/applications/emsConfigurer/devicepropertypage.cpp index 44b6869..7f6b5ec 100644 --- a/applications/emsConfigurer/devicepropertypage.cpp +++ b/applications/emsConfigurer/devicepropertypage.cpp @@ -12,6 +12,9 @@ #include "globalparameters.h" #include "mytablemodel.h" +#define PAGES_FORMAT_STRING ("Total %1 Pages, Current No.%2 Page") +#define PER_PAGE_SIZE (30) + DevicePropertyPage::DevicePropertyPage(QWidget *parent) : QWidget(parent),m_pTableView(nullptr),m_pButton(nullptr) { @@ -113,6 +116,22 @@ void DevicePropertyPage::InitializeTable() m_pTableView = new QTableView(this); m_pButton = new QPushButton(tr("Refresh"), this); + m_pFirstButton = new QPushButton(tr("First"), this); + m_pForwardButton = new QPushButton(tr("Forward"), this); + m_pNextButton = new QPushButton(tr("Next"), this); + m_pLastButton = new QPushButton(tr("Last"), this); + + m_pGotoPageNumberLineEdit = new QLineEdit(tr("1"), this); + m_pGotoPageNumberLineEdit->setFixedWidth(40); + m_pValidator = new QIntValidator(this); + m_pGotoPageNumberLineEdit->setValidator(m_pValidator); + m_pValidator->setRange(0, 100); + + m_pGotoPageNumberLabel = new QLabel(tr("Page"), this); + m_pGotoPageNumberButton = new QPushButton(tr("Goto"), this); + + m_pPagesLabel = new QLabel(tr("Total %d Pages, Current No.%d Page"), this); + // 创建主布局 QVBoxLayout *mainLayout = new QVBoxLayout(this); @@ -123,7 +142,26 @@ void DevicePropertyPage::InitializeTable() // 创建一个水平布局来包含按钮 QHBoxLayout *buttonLayout = new QHBoxLayout(); buttonLayout->addStretch(); // 让按钮保持在右侧 + + buttonLayout->addWidget(m_pPagesLabel); + QSpacerItem *spacer0 = new QSpacerItem(10, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + buttonLayout->addItem(spacer0); + + + buttonLayout->addWidget(m_pFirstButton); + buttonLayout->addWidget(m_pForwardButton); + buttonLayout->addWidget(m_pNextButton); + buttonLayout->addWidget(m_pLastButton); + + QSpacerItem *spacer = new QSpacerItem(10, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + buttonLayout->addItem(spacer); + + buttonLayout->addWidget(m_pGotoPageNumberLabel); + buttonLayout->addWidget(m_pGotoPageNumberLineEdit); + buttonLayout->addWidget(m_pGotoPageNumberButton); + buttonLayout->addWidget(m_pButton); + buttonLayout->setContentsMargins(0, 0, 0, 0); // 取消按钮的边距 // 将表格视图和按钮布局添加到主布局 @@ -139,18 +177,13 @@ void DevicePropertyPage::InitializeTable() connect(m_pTableView, &QTableView::doubleClicked, this, &DevicePropertyPage::onTableViewDoubleClicked); connect(m_pButton, &QPushButton::clicked, this, &DevicePropertyPage::onButtonClicked); - setLayout(mainLayout); -} + connect(m_pFirstButton, &QPushButton::clicked, this, &DevicePropertyPage::onFirstButtonClicked); + connect(m_pLastButton, &QPushButton::clicked, this, &DevicePropertyPage::onLastButtonClicked); + connect(m_pForwardButton, &QPushButton::clicked, this, &DevicePropertyPage::onForwardButtonClicked); + connect(m_pNextButton, &QPushButton::clicked, this, &DevicePropertyPage::onNextButtonClicked); + connect(m_pGotoPageNumberButton, &QPushButton::clicked, this, &DevicePropertyPage::onGotoButtonClicked); -void DevicePropertyPage::Refresh() -{ - QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - TableData tbl_data; - if (Fetch(tbl_data)) - { - m_myModel->setModelData(tbl_data); - } - QGuiApplication::restoreOverrideCursor(); + setLayout(mainLayout); } void DevicePropertyPage::setBaseType(unsigned int base, unsigned int mask) @@ -159,7 +192,6 @@ void DevicePropertyPage::setBaseType(unsigned int base, unsigned int mask) mask_code = mask; } - void DevicePropertyPage::onButtonClicked() { m_pTimer->stop(); @@ -167,6 +199,86 @@ void DevicePropertyPage::onButtonClicked() Refresh(); } +void DevicePropertyPage::Refresh() +{ + QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + m_TotalTableData.clear(); + if (Fetch(m_TotalTableData,106)) + { + PageDataProcess(); + m_myModel->setModelData(m_currentPageData); + } + updatePageButtonState(); + updatePageLabel(); + QGuiApplication::restoreOverrideCursor(); +} + +int DevicePropertyPage::PageDataProcess() +{ + //获取数据总数 + m_totalRows = m_TotalTableData.size(); + + m_totalPageCount = 1; + m_currentPage = 1; + + m_currentPageData.clear(); + + if (m_totalRows <= PER_PAGE_SIZE) + { + m_currentPageData = m_TotalTableData; + + return 1; + } + + m_totalPageCount = int(m_totalRows / PER_PAGE_SIZE) + 1; + m_currentPageData = m_TotalTableData.mid(0, PER_PAGE_SIZE); + + return 1; +} + +void DevicePropertyPage::updatePageLabel() +{ + QString s = QString(PAGES_FORMAT_STRING).arg(m_totalPageCount).arg(m_currentPage); + m_pPagesLabel->setText(s); +} + +void DevicePropertyPage::updatePageButtonState() +{ + if ( m_currentPage == m_totalPageCount) //翻到底了,超过最大的页数 + { + m_pNextButton->setEnabled(false); + m_pForwardButton->setEnabled(true); + m_pLastButton->setEnabled(false); + m_pFirstButton->setEnabled(true); + } + else if (m_currentPage == 1) //翻到头了 + { + m_pNextButton->setEnabled(true); + m_pForwardButton->setEnabled(false); + m_pLastButton->setEnabled(true); + m_pFirstButton->setEnabled(false); + } + else if (m_currentPage < m_totalPageCount) //页数在中间状态 + { + m_pNextButton->setEnabled(true); + m_pForwardButton->setEnabled(true); + m_pLastButton->setEnabled(true); + m_pFirstButton->setEnabled(true); + } + else + { + assert(false); + } +} + +void DevicePropertyPage::pageTo(int page) +{ + m_currentPageData.clear(); + int numLeftElements = m_totalRows - (page - 1) * PER_PAGE_SIZE; + int numElements = numLeftElements >= PER_PAGE_SIZE ? PER_PAGE_SIZE : numLeftElements; + m_currentPageData = m_TotalTableData.mid((page-1) * PER_PAGE_SIZE, numElements); + m_myModel->setModelData(m_currentPageData); +} void DevicePropertyPage::onTableViewDoubleClicked(const QModelIndex &index) { @@ -176,6 +288,75 @@ void DevicePropertyPage::onTableViewDoubleClicked(const QModelIndex &index) QVariant datatemp=model->data(mindex); } +void DevicePropertyPage::onFirstButtonClicked() +{ + m_currentPage = 1; + + updatePageButtonState(); + + pageTo(m_currentPage); + + updatePageLabel(); +} + +void DevicePropertyPage::onLastButtonClicked() +{ + m_currentPage = m_totalPageCount; + + updatePageButtonState(); + + pageTo(m_currentPage); + + updatePageLabel(); +} + +void DevicePropertyPage::onForwardButtonClicked() +{ + m_currentPage--; + + updatePageButtonState(); + + m_currentPageData.clear(); + + pageTo(m_currentPage); + + updatePageLabel(); +} + +void DevicePropertyPage::onNextButtonClicked() +{ + m_currentPage++; + + updatePageButtonState(); + + m_currentPageData.clear(); + + pageTo(m_currentPage); + + updatePageLabel(); +} + +void DevicePropertyPage::onGotoButtonClicked() +{ + int page = m_pGotoPageNumberLineEdit->text().toInt(); + if (page <=0 || page>m_totalPageCount) + { + QString s = QString(tr("Page number should be large than 0 and less than %1 !")).arg(m_totalPageCount); + QMessageBox::critical(this, tr("Critical Message"),s); + return ; + } + + m_currentPage = page; + + updatePageButtonState(); + + m_currentPageData.clear(); + + pageTo(m_currentPage); + + updatePageLabel(); +} + void DevicePropertyPage::resizeEvent(QResizeEvent *event) { QWidget::resizeEvent(event); diff --git a/applications/emsConfigurer/devicepropertypage.h b/applications/emsConfigurer/devicepropertypage.h index f9393c9..67a0301 100644 --- a/applications/emsConfigurer/devicepropertypage.h +++ b/applications/emsConfigurer/devicepropertypage.h @@ -4,6 +4,10 @@ #pragma execution_character_set("utf-8") #include +#include +#include +#include + #include "datafetcher.h" class MyTableModel; @@ -37,18 +41,55 @@ protected: // 重写resizeEvent,当QTableView窗口大小变化时按比例调整列宽 void resizeEvent(QResizeEvent *event) override; + //处理分页数据 + int PageDataProcess(); + + //更新页数显示 + void updatePageLabel(); + + //更新翻页按钮状态 + void updatePageButtonState(); + + //翻倒第i页 + void pageTo(int page); + private slots: void onButtonClicked(); void onTableViewDoubleClicked(const QModelIndex &index); + void onFirstButtonClicked(); + void onLastButtonClicked(); + void onForwardButtonClicked(); + void onNextButtonClicked(); + void onGotoButtonClicked(); private: unsigned int filterBaseType; unsigned int mask_code; QTableView* m_pTableView; QPushButton* m_pButton; + + QPushButton* m_pForwardButton; + QPushButton* m_pNextButton; + QPushButton* m_pFirstButton; + QPushButton* m_pLastButton; + + QIntValidator* m_pValidator; + QLabel* m_pGotoPageNumberLabel; + QLineEdit* m_pGotoPageNumberLineEdit; + QPushButton* m_pGotoPageNumberButton; + + QLabel* m_pPagesLabel; + QVector columnWidths; // 存储初始列宽 +private: + TableData m_TotalTableData; + TableData m_currentPageData; + + int m_totalPageCount; //总页数 + int m_currentPage; //当前页 + int m_totalRows; //数据总行数 }; #endif // DEVICEPROPERTYPAGE_H diff --git a/applications/emsConfigurer/formserialportsettingdialog.cpp b/applications/emsConfigurer/formserialportsettingdialog.cpp index 79c7086..f63a16c 100644 --- a/applications/emsConfigurer/formserialportsettingdialog.cpp +++ b/applications/emsConfigurer/formserialportsettingdialog.cpp @@ -1,4 +1,4 @@ -#include "formserialportsettingdialog.h" +#include "formserialportsettingdialog.h" #include "ui_formserialportsettingdialog.h" #include diff --git a/applications/emsConfigurer/globalparameters.cpp b/applications/emsConfigurer/globalparameters.cpp index fd129d2..140af8a 100644 --- a/applications/emsConfigurer/globalparameters.cpp +++ b/applications/emsConfigurer/globalparameters.cpp @@ -136,13 +136,15 @@ AppTcpClient::AppTcpClient(token) { } -void onMessage(const hv::SocketChannelPtr& channel, hv::Buffer* buf); - +void onMessage(const hv::SocketChannelPtr& channel, hv::Buffer* buf) +{ + hlogd("TCP Client<==\n%s", Kutilities::printHex((void*)buf->data(),(int)buf->size()).c_str()); +} int AppTcpClient::Initialize(QString remote_host, int remote_port) { using namespace hv; - + if (!m_tcpclient || !m_tcpclient->isConnected()) { if (m_tcpclient) @@ -152,18 +154,14 @@ int AppTcpClient::Initialize(QString remote_host, int remote_port) } m_tcpclient = new hv::TcpClient(); + m_connfd = m_tcpclient->createsocket(remote_port, remote_host.toStdString().c_str()); if (m_connfd < 0) { return -20; } - m_tcpclient->onMessage = onMessage; - - //m_tcpclient.onMessage = [](const SocketChannelPtr& channel, Buffer* buf) - //{ - // hlogi("<==\n%s", Kutilities::printHex((void*)buf->data(),(int)buf->size()).c_str()); - //}; + //m_tcpclient->onMessage = onMessage; reconn_setting_t reconn; reconn_setting_init(&reconn); @@ -178,7 +176,8 @@ int AppTcpClient::Initialize(QString remote_host, int remote_port) return m_connfd; } -void onMessage(const hv::SocketChannelPtr& channel, hv::Buffer* buf) +void AppTcpClient::resetOnMessageCallbackFunction(onMessageCallbackFunc &func) { - hlogi("<==\n%s", Kutilities::printHex((void*)buf->data(),(int)buf->size()).c_str()); + m_tcpclient->onMessage = func; } + diff --git a/applications/emsConfigurer/globalparameters.h b/applications/emsConfigurer/globalparameters.h index 595ca85..1bb3e4d 100644 --- a/applications/emsConfigurer/globalparameters.h +++ b/applications/emsConfigurer/globalparameters.h @@ -134,6 +134,7 @@ public: void InitializeTableView(MyTableModel* model,QTableView* tableView); }; +typedef std::function onMessageCallbackFunc; class AppTcpClient:public Singleton { @@ -144,7 +145,8 @@ public: AppTcpClient(const AppTcpClient&)=delete; AppTcpClient& operator =(const AppTcpClient&)= delete; - int Initialize(QString remote_host, int remote_port=DEVICE_SERVER_PORT); + int Initialize(QString remote_host,int remote_port=DEVICE_SERVER_PORT); + void resetOnMessageCallbackFunction(onMessageCallbackFunc& func); public: hv::TcpClient* m_tcpclient; diff --git a/applications/emsConfigurer/hv_tcpclient.h b/applications/emsConfigurer/hv_tcpclient.h index 3d8fabd..2182285 100644 --- a/applications/emsConfigurer/hv_tcpclient.h +++ b/applications/emsConfigurer/hv_tcpclient.h @@ -226,14 +226,17 @@ public: bool isConnected() { - if (channel == NULL) return false; + if (channel == NULL) + return false; return channel->isConnected(); } // send thread-safe int send(const void* data, int size) { - if (!isConnected()) return -1; + if (!isConnected()) + return -1; + return channel->write(data, size); } int send(Buffer* buf) diff --git a/applications/emsConfigurer/kutilities.cpp b/applications/emsConfigurer/kutilities.cpp index 356aa24..efa292c 100644 --- a/applications/emsConfigurer/kutilities.cpp +++ b/applications/emsConfigurer/kutilities.cpp @@ -1,4 +1,4 @@ -#include "kutilities.h" +#include "kutilities.h" #include #include #include diff --git a/applications/emsConfigurer/maindialog.cpp b/applications/emsConfigurer/maindialog.cpp index 1b1eab1..31b1a85 100644 --- a/applications/emsConfigurer/maindialog.cpp +++ b/applications/emsConfigurer/maindialog.cpp @@ -14,6 +14,9 @@ #include #include +#include + +#include "kutilities.h" #include "devicepropertypage.h" #include "formserialportsettingdialog.h" @@ -29,6 +32,10 @@ MainDialog::MainDialog(QWidget *parent) : // Load the window state loadWindowState(); + + //设置返回消息回调 + onMessageCallbackFunc f = std::bind(&MainDialog::onMessage, this, std::placeholders::_1, std::placeholders::_2); + AppTcpClient::getInstance()->resetOnMessageCallbackFunction(f); } MainDialog::~MainDialog() @@ -240,3 +247,8 @@ void MainDialog::onToolRefreshClicked() { QMessageBox::information(this, "Refresh Button Clicked", "Refresh"); } + +void MainDialog::onMessage(const hv::SocketChannelPtr& channel, hv::Buffer* buf) +{ + hlogd("MainDialog <==\n%s", Kutilities::printHex((void*)buf->data(),(int)buf->size()).c_str()); +} diff --git a/applications/emsConfigurer/maindialog.h b/applications/emsConfigurer/maindialog.h index bce63ef..0708ccf 100644 --- a/applications/emsConfigurer/maindialog.h +++ b/applications/emsConfigurer/maindialog.h @@ -8,6 +8,7 @@ #include #include #include +#include namespace Ui { @@ -29,6 +30,8 @@ public: public slots: void changePage(QListWidgetItem *current, QListWidgetItem *previous); + //接收服务器返回消息的函数 + void onMessage(const hv::SocketChannelPtr& channel, hv::Buffer* buf); private slots: void onToolButton1Clicked(); diff --git a/applications/emsConfigurer/mainwindow.cpp b/applications/emsConfigurer/mainwindow.cpp index a7c5100..71b835a 100644 --- a/applications/emsConfigurer/mainwindow.cpp +++ b/applications/emsConfigurer/mainwindow.cpp @@ -8,7 +8,7 @@ #include #include "MainDialog.h" #include "mysqlutils.h" - +#include "kutilities.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -69,24 +69,37 @@ bool MainWindow::testDatabase() return true; } +void MainWindow::onMessage(const hv::SocketChannelPtr& channel, hv::Buffer* buf) +{ + hlogd("MainWindow<==\n%s", Kutilities::printHex((void*)buf->data(),(int)buf->size()).c_str()); +} + bool MainWindow::testServerEcho() { using namespace hv; QString svr = ui->serverIp->text(); - int connfd = AppTcpClient::getInstance()->Initialize("127.0.0.1",DEVICE_SERVER_PORT); + int connfd = AppTcpClient::getInstance()->Initialize(svr,DEVICE_SERVER_PORT); if (connfd <= 0) { - hloge("failed to connect to device data service ..."); + hloge("failed to create socket for connecting to device data service ..."); return false; } - hlogi("connect to device data service port %d, connfd=%d ...", DEVICE_SERVER_PORT, connfd); + hlogi("create socket for connecting to device data service port %d, connfd=%d ...", DEVICE_SERVER_PORT, connfd); + + CWaitorCursor wait1; + + hv_msleep(500); + + //设置返回消息回调 + onMessageCallbackFunc f = std::bind(&MainWindow::onMessage, this, std::placeholders::_1, std::placeholders::_2); + AppTcpClient::getInstance()->resetOnMessageCallbackFunction(f); unsigned char frame[10] = { 0x02, 0x01,0x00,0x00,0x00, 0x00,0xEE,0xFF,0xEE,0xFF}; int cnt = AppTcpClient::getInstance()->m_tcpclient->send((void*)frame,10); - hlogd("send %d bytes, connfd=%d ...", cnt, connfd); + hlogd("send %d bytes test echo signal, connfd=%d ...", cnt, connfd); return cnt > 0 ? true : false; } diff --git a/applications/emsConfigurer/mainwindow.h b/applications/emsConfigurer/mainwindow.h index 97a2d4b..f066cc2 100644 --- a/applications/emsConfigurer/mainwindow.h +++ b/applications/emsConfigurer/mainwindow.h @@ -3,6 +3,7 @@ #pragma execution_character_set("utf-8") #include +#include class MainDialog; @@ -21,6 +22,9 @@ public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); +public: + void onMessage(const hv::SocketChannelPtr& channel, hv::Buffer* buf); + protected: void setIp(const QString &ip); bool testDatabase(); diff --git a/applications/emsConfigurer/mainwindow.ui b/applications/emsConfigurer/mainwindow.ui index affc7ff..2c8b207 100644 --- a/applications/emsConfigurer/mainwindow.ui +++ b/applications/emsConfigurer/mainwindow.ui @@ -39,17 +39,16 @@ - 160 + 100 50 - 240 + 391 61 - 宋体 - false - false + 28 + true @@ -83,9 +82,8 @@ - 宋体 - false - false + 12 + true diff --git a/applications/emsConfigurer/mysqlutils.cpp b/applications/emsConfigurer/mysqlutils.cpp index 7c53fb4..b933828 100644 --- a/applications/emsConfigurer/mysqlutils.cpp +++ b/applications/emsConfigurer/mysqlutils.cpp @@ -1,4 +1,4 @@ -#include "mysqlutils.h" +#include "mysqlutils.h" #include #include @@ -148,13 +148,15 @@ void MysqlUtils::CloseDatabase() #endif } -int MysqlUtils::RetrieveTableData(TableData& tbl_data) +int MysqlUtils::RetrieveTableData(TableData& tbl_data,int retrieve_rows) { #if 1 MYSQL_RES* res; MYSQL_ROW row; //执行SQL 查询 - if (mysql_query(m_DbConnection, "SELECT * FROM `hjems`.`tbl_data` ORDER BY data_timestamp LIMIT 0,100")) + QString sql = QString("SELECT * FROM `hjems`.`tbl_data` ORDER BY data_timestamp LIMIT 0,%1").arg(retrieve_rows); + + if (mysql_query(m_DbConnection, sql.toStdString().c_str())) { hloge( "Error: %s", mysql_error(m_DbConnection) ) ; return -1; @@ -162,33 +164,35 @@ int MysqlUtils::RetrieveTableData(TableData& tbl_data) res = mysql_use_result(m_DbConnection); + int j = 0; while ((row = mysql_fetch_row(res)) != NULL) { + ModelItem item; - // item.status = STATUS_WARN; - // item.ParameterName= "Visual Leak Detector detected 1 memory leak (84 bytes)"; - // item.sampleTime = "2024-9-10 11:22:33.444"; - // item.unit = "C"; - // item.value = "100"; - // tbl_data.append(item); + item.status = STATUS_WARN; + item.ParameterName= "Visual Leak Detector detected 1 memory leak (84 bytes)"; + item.sampleTime = "2024-9-10 11:22:33.444"; + item.unit = "C"; + item.value = QString("%1").arg(j++).toStdString(); + tbl_data.append(item); std::string buf; for (unsigned int i = 0; i < mysql_num_fields(res); ++i) { - qDebug() << mysql_fetch_field_direct(res,i)->name ; - QString field_name (mysql_fetch_field_direct(res,i)->name); - if (field_name == "data_timestamp") - { - item.sampleTime = row[i]; - qDebug() << row[i]; - } - else if (field_name == "data_content") - { - std::string v(row[i]); - qDebug() << Kutilities::printHex(v.c_str(),v.length()).c_str(); - ZipUtils::DecompressString(v.c_str(),v.length(),buf); - qDebug() << buf.c_str(); - } + // qDebug() << mysql_fetch_field_direct(res,i)->name ; + // QString field_name (mysql_fetch_field_direct(res,i)->name); + // if (field_name == "data_timestamp") + // { + // item.sampleTime = row[i]; + // qDebug() << row[i]; + // } + // else if (field_name == "data_content") + // { + // std::string v(row[i]); + // qDebug() << Kutilities::printHex(v.c_str(),v.length()).c_str(); + // ZipUtils::DecompressString(v.c_str(),v.length(),buf); + // qDebug() << buf.c_str(); + // } } qDebug() << "\r\n"; } diff --git a/applications/emsConfigurer/mysqlutils.h b/applications/emsConfigurer/mysqlutils.h index 0cedc6f..9d1046f 100644 --- a/applications/emsConfigurer/mysqlutils.h +++ b/applications/emsConfigurer/mysqlutils.h @@ -31,7 +31,7 @@ public: void CloseDatabase(); bool OpenDatabase(const std::string& server = "127.0.0.1", int dbport = 3306, const std::string& dbuser = "root", const std::string& dbpasswd = "Hj57471000", const std::string& database="hjems"); - int RetrieveTableData(TableData& tbl_data); + int RetrieveTableData(TableData& tbl_data,int retrieve_rows=100); private: #ifdef _USING_QT_MYSQL_CONNECTOR_