2024-09-12 16:23:44 +08:00
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QAbstractTableModel>
|
|
|
|
|
#include <QTableView>
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QCursor>
|
|
|
|
|
|
2024-11-08 16:11:31 +08:00
|
|
|
|
#include <hv/hlog.h>
|
|
|
|
|
|
2024-09-12 16:23:44 +08:00
|
|
|
|
#include "globalparameters.h"
|
|
|
|
|
#include "mytablemodel.h"
|
2024-11-08 16:11:31 +08:00
|
|
|
|
#include "kutilities.h"
|
2024-09-12 16:23:44 +08:00
|
|
|
|
|
|
|
|
|
AppData::~AppData()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppData::AppData(token)
|
|
|
|
|
{
|
|
|
|
|
lstDataTableHeaderText << ("Status")
|
|
|
|
|
<< ("Parameter")
|
|
|
|
|
<< ("Value")
|
|
|
|
|
<< ("Unit")
|
|
|
|
|
<< ("Time");
|
|
|
|
|
|
|
|
|
|
nTimeOut = 5000;
|
|
|
|
|
qsDestinationIp = "127.0.0.1";
|
|
|
|
|
|
|
|
|
|
qsLastErrorString = "OK";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppCommon::AppCommon(token)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppCommon::~AppCommon()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppCommon::InitializeTableView(MyTableModel *model, QTableView *tableView)
|
|
|
|
|
{
|
|
|
|
|
//设置tableview的model
|
|
|
|
|
model->setHeadData(AppData::getInstance()->lstDataTableHeaderText);
|
|
|
|
|
tableView->setModel(model);
|
|
|
|
|
|
2024-09-14 13:01:48 +08:00
|
|
|
|
QHeaderView* pHeaderView = tableView->horizontalHeader();
|
|
|
|
|
//pHeaderView->setStyleSheet("QHeaderView::section {color: black;padding-left: 4px;border: 1px solid #6c6c6c;}");
|
|
|
|
|
pHeaderView->setStyleSheet("QHeaderView::section{background:lightgray;}");
|
|
|
|
|
|
|
|
|
|
// pHeaderView->setSectionResizeMode(QHeaderView::Stretch); //Stretch
|
|
|
|
|
|
|
|
|
|
pHeaderView->setHidden(false); //false 显示行号列 true Hide
|
|
|
|
|
//pHeaderView->setVisible(true);
|
|
|
|
|
//pHeaderView->setFixedHeight(40);
|
2024-09-12 16:23:44 +08:00
|
|
|
|
|
|
|
|
|
//点击表时不对表头行光亮(获取焦点)
|
2024-09-14 13:01:48 +08:00
|
|
|
|
pHeaderView->setHighlightSections(false);
|
|
|
|
|
//pHeaderView->setDefaultSectionSize(35);
|
|
|
|
|
|
|
|
|
|
// //设置表头字体加粗
|
|
|
|
|
// QFont font = pHeaderView->font();
|
|
|
|
|
// font.setBold(true);
|
|
|
|
|
// pHeaderView->setFont(font);
|
|
|
|
|
|
|
|
|
|
//设置表头字体
|
|
|
|
|
pHeaderView->setFont(QFont("Arial", 12));
|
|
|
|
|
|
|
|
|
|
// 设置表头列宽自动调整
|
2024-11-08 16:11:31 +08:00
|
|
|
|
for (int i = 0; i < model->columnCount(); ++i)
|
|
|
|
|
{
|
2024-09-14 13:01:48 +08:00
|
|
|
|
pHeaderView->setSectionResizeMode(i, QHeaderView::Stretch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 允许用户通过拖动表头边缘调整列宽
|
|
|
|
|
pHeaderView->setSectionResizeMode(QHeaderView::Interactive);
|
2024-09-12 16:23:44 +08:00
|
|
|
|
|
|
|
|
|
tableView->verticalHeader()->setDefaultSectionSize(30); //行高
|
|
|
|
|
|
|
|
|
|
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
|
|
|
|
|
tableView->setAlternatingRowColors(true);
|
|
|
|
|
tableView->setTextElideMode(Qt::ElideMiddle);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//所有单元格的字体 设置成一样
|
|
|
|
|
tableView->setFont(QFont("Arial", 9));
|
|
|
|
|
|
|
|
|
|
//设置表格数据区内的所有单元格都不允许编辑
|
|
|
|
|
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
2024-09-13 12:53:02 +08:00
|
|
|
|
#if 0
|
2024-09-12 16:23:44 +08:00
|
|
|
|
//设置列宽
|
|
|
|
|
int w = tableView->width();
|
|
|
|
|
int base = w /(AppData::getInstance()->lstDataTableHeaderText.count()-1);
|
|
|
|
|
tableView->setColumnWidth(0,base-45);
|
|
|
|
|
tableView->setColumnWidth(1,base-20);
|
|
|
|
|
tableView->setColumnWidth(2,base+30);
|
|
|
|
|
tableView->setColumnWidth(3,base+10);
|
|
|
|
|
tableView->setColumnWidth(4,base);
|
2024-09-13 12:53:02 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2024-09-12 16:23:44 +08:00
|
|
|
|
tableView->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CWaitorCursor::CWaitorCursor()
|
|
|
|
|
{
|
|
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CWaitorCursor::~CWaitorCursor()
|
|
|
|
|
{
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
}
|
2024-11-08 16:11:31 +08:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
|
/// \brief AppTcpClient
|
|
|
|
|
///
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
AppTcpClient::~AppTcpClient()
|
|
|
|
|
{
|
|
|
|
|
if (m_tcpclient)
|
|
|
|
|
{
|
|
|
|
|
m_tcpclient->stop();
|
|
|
|
|
delete m_tcpclient;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AppTcpClient::AppTcpClient(token)
|
|
|
|
|
:m_tcpclient(nullptr), m_connfd(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-11 15:28:31 +08:00
|
|
|
|
void onMessage(const hv::SocketChannelPtr& channel, hv::Buffer* buf)
|
|
|
|
|
{
|
|
|
|
|
hlogd("TCP Client<==\n%s", Kutilities::printHex((void*)buf->data(),(int)buf->size()).c_str());
|
|
|
|
|
}
|
2024-11-08 16:11:31 +08:00
|
|
|
|
|
|
|
|
|
int AppTcpClient::Initialize(QString remote_host, int remote_port)
|
|
|
|
|
{
|
|
|
|
|
using namespace hv;
|
2024-11-11 15:28:31 +08:00
|
|
|
|
|
2024-11-08 16:11:31 +08:00
|
|
|
|
if (!m_tcpclient || !m_tcpclient->isConnected())
|
|
|
|
|
{
|
|
|
|
|
if (m_tcpclient)
|
|
|
|
|
{
|
|
|
|
|
m_tcpclient->stop();
|
|
|
|
|
delete m_tcpclient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_tcpclient = new hv::TcpClient();
|
2024-11-11 15:28:31 +08:00
|
|
|
|
|
2024-11-08 16:11:31 +08:00
|
|
|
|
m_connfd = m_tcpclient->createsocket(remote_port, remote_host.toStdString().c_str());
|
|
|
|
|
if (m_connfd < 0)
|
|
|
|
|
{
|
|
|
|
|
return -20;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-11 15:28:31 +08:00
|
|
|
|
//m_tcpclient->onMessage = onMessage;
|
2024-11-08 16:11:31 +08:00
|
|
|
|
|
|
|
|
|
reconn_setting_t reconn;
|
|
|
|
|
reconn_setting_init(&reconn);
|
|
|
|
|
reconn.min_delay = 1000;
|
|
|
|
|
reconn.max_delay = 10000;
|
|
|
|
|
reconn.delay_policy = 2;
|
|
|
|
|
//reconn.max_retry_cnt = 50;
|
|
|
|
|
m_tcpclient->setReconnect(&reconn);
|
|
|
|
|
|
|
|
|
|
m_tcpclient->start();
|
|
|
|
|
}
|
|
|
|
|
return m_connfd;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-11 15:28:31 +08:00
|
|
|
|
void AppTcpClient::resetOnMessageCallbackFunction(onMessageCallbackFunc &func)
|
2024-11-08 16:11:31 +08:00
|
|
|
|
{
|
2024-11-11 15:28:31 +08:00
|
|
|
|
m_tcpclient->onMessage = func;
|
2024-11-08 16:11:31 +08:00
|
|
|
|
}
|
2024-11-11 15:28:31 +08:00
|
|
|
|
|