-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpingtimetable.cpp
More file actions
51 lines (37 loc) · 1.24 KB
/
pingtimetable.cpp
File metadata and controls
51 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "pingtimetable.hpp"
#include "ui_pingtimetable.h"
#include <QFileDialog>
#include <QMessageBox>
#include <fstream>
PingTimeTable::PingTimeTable(QWidget *parent) :
QDialog(parent),
ui(new Ui::PingTimeTable){
ui->setupUi(this);
connect(this->ui->saveAsTextButton, &QPushButton::released, [=](){
QString path = QFileDialog::getSaveFileName(this, "Save as text", "", "Text files (*.txt)");
if(path.length() == 0)
return;
std::ofstream output(path.toStdString());
if(output.is_open() == false){
QMessageBox::critical(this, "Error", "File creating error");
return;
}
for(int32_t row = 0; row < this->ui->pingTimeTable->rowCount(); ++row)
output << this->ui->pingTimeTable->item(row, 0)->text().toStdString() << '\n';
output.close();
});
}
PingTimeTable::~PingTimeTable()
{
delete ui;
}
void PingTimeTable::showTime(const QString &hostname, const QVector<double> &time){
this->ui->hostname->setText(hostname);
while(this->ui->pingTimeTable->rowCount() != 0)
this->ui->pingTimeTable->removeRow(0);
for(const auto value : time){
int row = this->ui->pingTimeTable->rowCount();
this->ui->pingTimeTable->insertRow(row);
this->ui->pingTimeTable->setItem(row, 0, new QTableWidgetItem(QString::number(value)));
}
}