代码拉取完成,页面将自动刷新
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include "endpointcli.h"
#include <QFileDialog>
#include <QDateTime>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->textEdit->setText("");
ui->textEdit->setTextColor(Qt::green);
ui->textEdit->setStyleSheet("QTextEdit{background-color: black;}");
m_ixchariotDialog = new IxchariotPairDialog();
m_endpointCli = new EndpointCli();
EndpointStatus epRes;
epRes = m_endpointCli->CheckIxchariotLibEnv();
if( EP_OK != epRes)
{
ui->textEdit->append(m_endpointCli->GetErrorInformation());
}
RefreshPairList();
ui->stopBtn->setEnabled(false);
m_endpointStatus = 0;
m_checkEndpointTimer = new QTimer(this);
connect(m_checkEndpointTimer, SIGNAL(timeout()), this, SLOT(checkEndpointTimerTimeout()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::RefreshPairList()
{
ui->pairList->clear();
for (int i=0; i<m_pairList.length(); i++) {
PairInfo pairItemInfo = m_pairList.at(i);
QString title = QString::number(i+1) + ". " + pairItemInfo.ip1 + " > " + pairItemInfo.ip2 + "\t Protocol: " + pairItemInfo.networkProtocol;
title = title + " Count: " + QString::number(pairItemInfo.pairCount) + " Script: "+ pairItemInfo.pairScriptPath;
ui->pairList->insertItem(i, title);
}
ui->pairList->insertItem(m_pairList.length(), "点此添加IxChariot条目");
ui->pairList->item(m_pairList.length())->setTextColor(Qt::red);
}
void MainWindow::on_pairList_itemDoubleClicked(QListWidgetItem *item)
{
//m_endpointCli->GetEndpointTestResult();
//return ;
if(m_endpointStatus != 0)
{
return ;
}
if(!item->text().compare("点此添加IxChariot条目", Qt::CaseInsensitive))
{
ui->textEdit->append("准备添加 IxChariot Pair 页面");
m_ixchariotDialog->SetIxchariotModeForCreat(1);
int res = m_ixchariotDialog->exec();
if(!res) {
ui->textEdit->append("取消添加");
return ;
}
PairInfo pairInfo = m_ixchariotDialog->GetIxchariotPairInfo();
m_pairList.push_back(pairInfo);
ui->textEdit->append(QString("IxChariot Pair %1条添加成功").arg(pairInfo.pairCount));
RefreshPairList();
}
else
{
ui->textEdit->append("准备编辑 IxChariot Pair 页面");
m_ixchariotDialog->SetIxchariotModeForCreat(0);
QString itemTitle = item->text();
int index = itemTitle.left(itemTitle.indexOf('.')).toInt();
m_ixchariotDialog->SetIxchariotPairInfo(m_pairList.at(index-1));
int res = m_ixchariotDialog->exec();
if(0==res) {
ui->textEdit->append("取消编辑");
return ;
}
// delete
if(2==res) {
m_pairList.erase(m_pairList.begin()+index-1);
}
// save
PairInfo pairInfo = m_ixchariotDialog->GetIxchariotPairInfo();
for (QVector<PairInfo>::iterator iter = m_pairList.begin(); iter != m_pairList.end(); iter++)
{
if((iter-m_pairList.begin())==(index-1))
{
*iter = pairInfo;
break;
}
}
ui->textEdit->append("保存成功");
RefreshPairList();
}
}
void MainWindow::on_chooseResultPathBtn_clicked()
{
if(m_endpointStatus != 0)
{
return ;
}
QString filename = QFileDialog::getSaveFileName(
this,
tr("选择跑流结果保存位置"),
"test_result_" + QDateTime::currentDateTime().toString("MMdd-hhmmss")+ ".tst",
"Script files (*.tst);;All files(*.*)");
if(filename.length()>0)
{
ui->resultEdit->setText(filename);
}
}
void MainWindow::on_startBtn_clicked()
{
if(m_pairList.length()==0)
{
QMessageBox::information(this, "tips", "pair条目为空,请先添加pair条目");
return ;
}
if(ui->resultEdit->text().length()==0)
{
QMessageBox::information(this, "tips", "请先选择结果保存位置");
return ;
}
if(ui->resultEdit->text().contains(QRegExp("[\\x4e00-\\x9fa5]+")))
{
QMessageBox::information(this, "tips", "路径中不能有中文字符");
return ;
}
if(m_endpointCli->CheckIxchariotLibEnv() != EP_OK)
{
QMessageBox::information(this,"tips","please check Ixchariot sdk enviroment");
}
// m_endpointCli->testFunc();
int res = m_endpointCli->StartTask(m_pairList,ui->resultEdit->text(),ui->testTimeBox->value(), ui->timeoutBox->value());
if(res==0)
{
ui->testTimeBox->setReadOnly(true);
ui->timeoutBox->setReadOnly(true);
m_endpointStatus = 1;
m_checkEndpointTimer->start(1000);
ui->textEdit->append("开始测试...");
ui->textEdit->append(QString("测试时间:%1秒").arg(ui->testTimeBox->value()));
ui->textEdit->append(QString("测试结果文件:%1").arg(ui->resultEdit->text()));
}
}
void MainWindow::checkEndpointTimerTimeout()
{
int runtime = 0;
int status;
status = m_endpointCli->GetEndpointStatus(runtime);
if(status==EP_TASK_RUNNING)
{
ui->progressBar->setValue(runtime*100/ui->testTimeBox->value());
ui->remainDurationEdit->setText(QString::number(ui->testTimeBox->value()-runtime));
ui->startBtn->setEnabled(false);
ui->stopBtn->setEnabled(true);
}
if(status==EP_TASK_FINISHED)
{
m_checkEndpointTimer->stop();
ui->progressBar->setValue(100);
ui->remainDurationEdit->setText("已完成");
ui->startBtn->setEnabled(true);
ui->stopBtn->setEnabled(false);
double throughputRes;
m_endpointCli->GetEndpointTestResult(throughputRes);
ui->textEdit->append("测试完成");
ui->textEdit->append(QString("本次测试结果: %1Mbps.").arg(throughputRes));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。