add export to YAML to chart viewer
This commit is contained in:
@ -36,7 +36,9 @@
|
||||
using namespace QtCharts;
|
||||
|
||||
ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
|
||||
QWidget(parent), menu(new QMenuBar), file(new QMenu("&File")), filename(_filename)
|
||||
QWidget(parent), menu(new QMenuBar), file(new QMenu("&File")),
|
||||
saveAsAct(nullptr), exportCsvAct(nullptr), exportDatAct(nullptr), exportYamlAct(nullptr),
|
||||
closeAct(nullptr), stopAct(nullptr), quitAct(nullptr), filename(_filename)
|
||||
{
|
||||
auto *top = new QHBoxLayout;
|
||||
menu->addMenu(file);
|
||||
@ -61,6 +63,8 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
|
||||
exportCsvAct->setIcon(QIcon(":/icons/application-calc.png"));
|
||||
exportDatAct = file->addAction("Export data to &Gnuplot...", this, &ChartWindow::exportDat);
|
||||
exportDatAct->setIcon(QIcon(":/icons/application-plot.png"));
|
||||
exportYamlAct = file->addAction("Export data to &YAML...", this, &ChartWindow::exportYaml);
|
||||
exportYamlAct->setIcon(QIcon(":/icons/yaml-file-icon.png"));
|
||||
file->addSeparator();
|
||||
stopAct = file->addAction("Stop &Run", this, &ChartWindow::stop_run);
|
||||
stopAct->setIcon(QIcon(":/icons/process-stop.png"));
|
||||
@ -227,6 +231,40 @@ void ChartWindow::exportCsv()
|
||||
}
|
||||
}
|
||||
}
|
||||
void ChartWindow::exportYaml()
|
||||
{
|
||||
if (charts.empty()) return;
|
||||
QString defaultname = filename + ".yaml";
|
||||
if (filename.isEmpty()) defaultname = "lammpsdata.yaml";
|
||||
QString fileName = QFileDialog::getSaveFileName(this, "Save Chart as YAML data", defaultname,
|
||||
"Image Files (*.yaml, *.yml)");
|
||||
if (!fileName.isEmpty()) {
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
QTextStream out(&file);
|
||||
out.setRealNumberPrecision(8);
|
||||
out << "---\n";
|
||||
|
||||
out << "keywords: ['Step'";
|
||||
for (auto &c : charts)
|
||||
out << ", " << c->get_title();
|
||||
out << "]\n";
|
||||
|
||||
out << "data: \n";
|
||||
int lines = charts[0]->get_count();
|
||||
for (int i = 0; i < lines; ++i) {
|
||||
// timestep
|
||||
out << " - [" << charts[0]->get_step(i);
|
||||
// data
|
||||
for (auto &c : charts)
|
||||
out << ", " << c->get_data(i);
|
||||
out << "]\n";
|
||||
}
|
||||
out << "...\n";
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChartWindow::change_chart(int)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user