refactor CSV format output

This commit is contained in:
Axel Kohlmeyer
2023-10-03 12:10:44 -04:00
parent b5dae4024a
commit 918705ce2f

View File

@ -150,23 +150,21 @@ void ChartWindow::exportCsv()
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QFile file(fileName); QFile file(fileName);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream out(&file);
out.setRealNumberPrecision(8);
file.write("Step"); out << "Step";
for (auto &c : charts) { for (auto &c : charts)
file.write(","); out << ',' << c->get_title();
file.write(c->get_title()); out << '\n';
}
file.write("\n");
int lines = charts[0]->get_count(); int lines = charts[0]->get_count();
for (int i = 0; i < lines; ++i) { for (int i = 0; i < lines; ++i) {
// timestep // timestep
file.write(QString::number(charts[0]->get_step(i)).toLocal8Bit()); out << charts[0]->get_step(i);
for (auto &c : charts) { for (auto &c : charts)
file.write(","); out << ',' << c->get_data(i);
file.write(QString::number(c->get_data(i)).toLocal8Bit()); out << '\n';
}
file.write("\n");
} }
file.close(); file.close();
} }