diff --git a/tool/netserver/form/frmmain.cpp b/tool/netserver/form/frmmain.cpp index 842bdd8..23f98f5 100644 --- a/tool/netserver/form/frmmain.cpp +++ b/tool/netserver/form/frmmain.cpp @@ -53,72 +53,14 @@ void frmMain::append1(int type, const QString &data, bool clear) { static int currentCount = 0; static int maxCount = 100; - - if (clear) { - ui->txtMain1->clear(); - currentCount = 0; - return; - } - - if (currentCount >= maxCount) { - ui->txtMain1->clear(); - currentCount = 0; - } - - //过滤回车换行符 - QString strData = data.left(500); - strData = strData.replace("\r", ""); - strData = strData.replace("\n", ""); - - //不同类型不同颜色显示 - QString strType; - if (type == 0) { - strType = "发送"; - ui->txtMain1->setTextColor(QColor("darkgreen")); - } else { - strType = "接收"; - ui->txtMain1->setTextColor(QColor("red")); - } - - strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData); - ui->txtMain1->append(strData); - currentCount++; + QtHelper::appendMsg(ui->txtMain1, type, data.left(500), maxCount, currentCount, clear); } void frmMain::append2(int type, const QString &data, bool clear) { static int currentCount = 0; static int maxCount = 100; - - if (clear) { - ui->txtMain2->clear(); - currentCount = 0; - return; - } - - if (currentCount >= maxCount) { - ui->txtMain2->clear(); - currentCount = 0; - } - - //过滤回车换行符 - QString strData = data.left(500); - strData = strData.replace("\r", ""); - strData = strData.replace("\n", ""); - - //不同类型不同颜色显示 - QString strType; - if (type == 0) { - strType = "发送"; - ui->txtMain2->setTextColor(QColor("darkgreen")); - } else { - strType = "接收"; - ui->txtMain2->setTextColor(QColor("red")); - } - - strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData); - ui->txtMain2->append(strData); - currentCount++; + QtHelper::appendMsg(ui->txtMain2, type, data.left(500), maxCount, currentCount, clear); } void frmMain::clientConnected1(const QString &ip, int port, const QString &deviceID) diff --git a/tool/nettool/form/frmtcpclient.cpp b/tool/nettool/form/frmtcpclient.cpp index c0004bc..92f475f 100644 --- a/tool/nettool/form/frmtcpclient.cpp +++ b/tool/nettool/form/frmtcpclient.cpp @@ -54,7 +54,7 @@ void frmTcpClient::initForm() //填充数据到下拉框 ui->cboxInterval->addItems(AppData::Intervals); ui->cboxData->addItems(AppData::Datas); - AppData::loadIP(ui->cboxBindIP); + AppData::loadIP(ui->cboxBindIP); } void frmTcpClient::initConfig() @@ -130,64 +130,28 @@ void frmTcpClient::append(int type, const QString &data, bool clear) { static int currentCount = 0; static int maxCount = 100; - - if (clear) { - ui->txtMain->clear(); - currentCount = 0; - return; - } - - if (currentCount >= maxCount) { - ui->txtMain->clear(); - currentCount = 0; - } - - if (ui->ckShow->isChecked()) { - return; - } - - //过滤回车换行符 - QString strData = data; - strData = strData.replace("\r", ""); - strData = strData.replace("\n", ""); - - //不同类型不同颜色显示 - QString strType; - if (type == 0) { - strType = "发送"; - ui->txtMain->setTextColor(QColor("#22A3A9")); - } else if (type == 1) { - strType = "接收"; - ui->txtMain->setTextColor(QColor("#753775")); - } else { - strType = "错误"; - ui->txtMain->setTextColor(QColor("#D64D54")); - } - - strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData); - ui->txtMain->append(strData); - currentCount++; + QtHelper::appendMsg(ui->txtMain, type, data, maxCount, currentCount, clear, ui->ckShow->isChecked()); } void frmTcpClient::connected() { isOk = true; ui->btnConnect->setText("断开"); - append(0, "服务器连接"); - append(0, QString("本地地址: %1 本地端口: %2").arg(socket->localAddress().toString()).arg(socket->localPort())); - append(0, QString("远程地址: %1 远程端口: %2").arg(socket->peerAddress().toString()).arg(socket->peerPort())); + append(2, "服务器连接"); + append(4, QString("本地地址: %1 本地端口: %2").arg(socket->localAddress().toString()).arg(socket->localPort())); + append(4, QString("远程地址: %1 远程端口: %2").arg(socket->peerAddress().toString()).arg(socket->peerPort())); } void frmTcpClient::disconnected() { isOk = false; ui->btnConnect->setText("连接"); - append(1, "服务器断开"); + append(2, "服务器断开"); } void frmTcpClient::error() { - append(2, socket->errorString()); + append(3, socket->errorString()); } void frmTcpClient::readData() diff --git a/tool/nettool/form/frmtcpserver.cpp b/tool/nettool/form/frmtcpserver.cpp index 9fa55c2..79dc5a0 100644 --- a/tool/nettool/form/frmtcpserver.cpp +++ b/tool/nettool/form/frmtcpserver.cpp @@ -125,48 +125,12 @@ void frmTcpServer::append(int type, const QString &data, bool clear) { static int currentCount = 0; static int maxCount = 100; - - if (clear) { - ui->txtMain->clear(); - currentCount = 0; - return; - } - - if (currentCount >= maxCount) { - ui->txtMain->clear(); - currentCount = 0; - } - - if (ui->ckShow->isChecked()) { - return; - } - - //过滤回车换行符 - QString strData = data; - strData = strData.replace("\r", ""); - strData = strData.replace("\n", ""); - - //不同类型不同颜色显示 - QString strType; - if (type == 0) { - strType = "发送"; - ui->txtMain->setTextColor(QColor("#22A3A9")); - } else if (type == 1) { - strType = "接收"; - ui->txtMain->setTextColor(QColor("#753775")); - } else { - strType = "错误"; - ui->txtMain->setTextColor(QColor("#D64D54")); - } - - strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData); - ui->txtMain->append(strData); - currentCount++; + QtHelper::appendMsg(ui->txtMain, type, data, maxCount, currentCount, clear, ui->ckShow->isChecked()); } void frmTcpServer::connected(const QString &ip, int port) { - append(0, QString("[%1:%2] %3").arg(ip).arg(port).arg("客户端上线")); + append(2, QString("[%1:%2] %3").arg(ip).arg(port).arg("客户端上线")); QString str = QString("%1:%2").arg(ip).arg(port); ui->listWidget->addItem(str); @@ -192,7 +156,7 @@ void frmTcpServer::disconnected(const QString &ip, int port) void frmTcpServer::error(const QString &ip, int port, const QString &error) { - append(2, QString("[%1:%2] %3").arg(ip).arg(port).arg(error)); + append(3, QString("[%1:%2] %3").arg(ip).arg(port).arg(error)); } void frmTcpServer::sendData(const QString &ip, int port, const QString &data) @@ -210,10 +174,10 @@ void frmTcpServer::on_btnListen_clicked() if (ui->btnListen->text() == "监听") { isOk = server->start(); if (isOk) { - append(0, "监听成功"); + append(2, "监听成功"); ui->btnListen->setText("关闭"); } else { - append(2, QString("监听失败: %1").arg(server->errorString())); + append(3, QString("监听失败: %1").arg(server->errorString())); } } else { isOk = false; diff --git a/tool/nettool/form/frmudpclient.cpp b/tool/nettool/form/frmudpclient.cpp index 15621a7..89ba991 100644 --- a/tool/nettool/form/frmudpclient.cpp +++ b/tool/nettool/form/frmudpclient.cpp @@ -126,48 +126,12 @@ void frmUdpClient::append(int type, const QString &data, bool clear) { static int currentCount = 0; static int maxCount = 100; - - if (clear) { - ui->txtMain->clear(); - currentCount = 0; - return; - } - - if (currentCount >= maxCount) { - ui->txtMain->clear(); - currentCount = 0; - } - - if (ui->ckShow->isChecked()) { - return; - } - - //过滤回车换行符 - QString strData = data; - strData = strData.replace("\r", ""); - strData = strData.replace("\n", ""); - - //不同类型不同颜色显示 - QString strType; - if (type == 0) { - strType = "发送"; - ui->txtMain->setTextColor(QColor("#22A3A9")); - } else if (type == 1) { - strType = "接收"; - ui->txtMain->setTextColor(QColor("#753775")); - } else { - strType = "错误"; - ui->txtMain->setTextColor(QColor("#D64D54")); - } - - strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData); - ui->txtMain->append(strData); - currentCount++; + QtHelper::appendMsg(ui->txtMain, type, data, maxCount, currentCount, clear, ui->ckShow->isChecked()); } void frmUdpClient::error() { - append(2, socket->errorString()); + append(3, socket->errorString()); } void frmUdpClient::readData() diff --git a/tool/nettool/form/frmudpserver.cpp b/tool/nettool/form/frmudpserver.cpp index 7f5625e..cbecfc2 100644 --- a/tool/nettool/form/frmudpserver.cpp +++ b/tool/nettool/form/frmudpserver.cpp @@ -123,48 +123,12 @@ void frmUdpServer::append(int type, const QString &data, bool clear) { static int currentCount = 0; static int maxCount = 100; - - if (clear) { - ui->txtMain->clear(); - currentCount = 0; - return; - } - - if (currentCount >= maxCount) { - ui->txtMain->clear(); - currentCount = 0; - } - - if (ui->ckShow->isChecked()) { - return; - } - - //过滤回车换行符 - QString strData = data; - strData = strData.replace("\r", ""); - strData = strData.replace("\n", ""); - - //不同类型不同颜色显示 - QString strType; - if (type == 0) { - strType = "发送"; - ui->txtMain->setTextColor(QColor("#22A3A9")); - } else if (type == 1) { - strType = "接收"; - ui->txtMain->setTextColor(QColor("#753775")); - } else { - strType = "错误"; - ui->txtMain->setTextColor(QColor("#D64D54")); - } - - strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData); - ui->txtMain->append(strData); - currentCount++; + QtHelper::appendMsg(ui->txtMain, type, data, maxCount, currentCount, clear, ui->ckShow->isChecked()); } void frmUdpServer::error() { - append(2, socket->errorString()); + append(3, socket->errorString()); } void frmUdpServer::readData() @@ -242,10 +206,10 @@ void frmUdpServer::on_btnListen_clicked() if (ui->btnListen->text() == "监听") { bool ok = socket->bind(QHostAddress(AppConfig::UdpListenIP), AppConfig::UdpListenPort); if (ok) { - append(0, "监听成功"); + append(2, "监听成功"); ui->btnListen->setText("关闭"); } else { - append(2, QString("监听失败: %1").arg(socket->errorString())); + append(3, QString("监听失败: %1").arg(socket->errorString())); } } else { socket->abort(); diff --git a/tool/nettool/form/frmwebclient.cpp b/tool/nettool/form/frmwebclient.cpp index d949868..c731011 100644 --- a/tool/nettool/form/frmwebclient.cpp +++ b/tool/nettool/form/frmwebclient.cpp @@ -123,64 +123,28 @@ void frmWebClient::append(int type, const QString &data, bool clear) { static int currentCount = 0; static int maxCount = 100; - - if (clear) { - ui->txtMain->clear(); - currentCount = 0; - return; - } - - if (currentCount >= maxCount) { - ui->txtMain->clear(); - currentCount = 0; - } - - if (ui->ckShow->isChecked()) { - return; - } - - //过滤回车换行符 - QString strData = data; - strData = strData.replace("\r", ""); - strData = strData.replace("\n", ""); - - //不同类型不同颜色显示 - QString strType; - if (type == 0) { - strType = "发送"; - ui->txtMain->setTextColor(QColor("#22A3A9")); - } else if (type == 1) { - strType = "接收"; - ui->txtMain->setTextColor(QColor("#753775")); - } else { - strType = "错误"; - ui->txtMain->setTextColor(QColor("#D64D54")); - } - - strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData); - ui->txtMain->append(strData); - currentCount++; + QtHelper::appendMsg(ui->txtMain, type, data, maxCount, currentCount, clear, ui->ckShow->isChecked()); } void frmWebClient::connected() { isOk = true; ui->btnConnect->setText("断开"); - append(0, "服务器连接"); - append(0, QString("本地地址: %1 本地端口: %2").arg(socket->localAddress().toString()).arg(socket->localPort())); - append(0, QString("远程地址: %1 远程端口: %2").arg(socket->peerAddress().toString()).arg(socket->peerPort())); + append(2, "服务器连接"); + append(4, QString("本地地址: %1 本地端口: %2").arg(socket->localAddress().toString()).arg(socket->localPort())); + append(4, QString("远程地址: %1 远程端口: %2").arg(socket->peerAddress().toString()).arg(socket->peerPort())); } void frmWebClient::disconnected() { isOk = false; ui->btnConnect->setText("连接"); - append(1, "服务器断开"); + append(2, "服务器断开"); } void frmWebClient::error() { - append(2, socket->errorString()); + append(4, socket->errorString()); } void frmWebClient::sendData(const QString &data) diff --git a/tool/nettool/form/frmwebserver.cpp b/tool/nettool/form/frmwebserver.cpp index cf64127..433d183 100644 --- a/tool/nettool/form/frmwebserver.cpp +++ b/tool/nettool/form/frmwebserver.cpp @@ -123,48 +123,12 @@ void frmWebServer::append(int type, const QString &data, bool clear) { static int currentCount = 0; static int maxCount = 100; - - if (clear) { - ui->txtMain->clear(); - currentCount = 0; - return; - } - - if (currentCount >= maxCount) { - ui->txtMain->clear(); - currentCount = 0; - } - - if (ui->ckShow->isChecked()) { - return; - } - - //过滤回车换行符 - QString strData = data; - strData = strData.replace("\r", ""); - strData = strData.replace("\n", ""); - - //不同类型不同颜色显示 - QString strType; - if (type == 0) { - strType = "发送"; - ui->txtMain->setTextColor(QColor("#22A3A9")); - } else if (type == 1) { - strType = "接收"; - ui->txtMain->setTextColor(QColor("#753775")); - } else { - strType = "错误"; - ui->txtMain->setTextColor(QColor("#D64D54")); - } - - strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData); - ui->txtMain->append(strData); - currentCount++; + QtHelper::appendMsg(ui->txtMain, type, data, maxCount, currentCount, clear, ui->ckShow->isChecked()); } void frmWebServer::connected(const QString &ip, int port) { - append(0, QString("[%1:%2] %3").arg(ip).arg(port).arg("客户端上线")); + append(2, QString("[%1:%2] %3").arg(ip).arg(port).arg("客户端上线")); QString str = QString("%1:%2").arg(ip).arg(port); ui->listWidget->addItem(str); @@ -190,7 +154,7 @@ void frmWebServer::disconnected(const QString &ip, int port) void frmWebServer::error(const QString &ip, int port, const QString &error) { - append(2, QString("[%1:%2] %3").arg(ip).arg(port).arg(error)); + append(4, QString("[%1:%2] %3").arg(ip).arg(port).arg(error)); } void frmWebServer::sendData(const QString &ip, int port, const QString &data) @@ -208,10 +172,10 @@ void frmWebServer::on_btnListen_clicked() if (ui->btnListen->text() == "监听") { isOk = server->start(); if (isOk) { - append(0, "监听成功"); + append(2, "监听成功"); ui->btnListen->setText("关闭"); } else { - append(2, QString("监听失败: %1").arg(server->errorString())); + append(3, QString("监听失败: %1").arg(server->errorString())); } } else { isOk = false;