From 89ca64e301776fe73e4032657909d2ef59e63611 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Wed, 16 Sep 2015 22:35:32 -0400 Subject: [PATCH] Initial simple implemention of an idea to turn graphs into spreadsheets that are nicely formatted. --- graphingwindow.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++ graphingwindow.h | 1 + 2 files changed, 56 insertions(+) diff --git a/graphingwindow.cpp b/graphingwindow.cpp index f790375..5a343ef 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -382,6 +382,7 @@ void GraphingWindow::contextMenuRequest(QPoint pos) menu->addAction(tr("Save graph image to file"), this, SLOT(saveGraphs())); menu->addAction(tr("Save graph definitions to file"), this, SLOT(saveDefinitions())); menu->addAction(tr("Load graph definitions from file"), this, SLOT(loadDefinitions())); + menu->addAction(tr("Save spreadsheet of data"), this, SLOT(saveSpreadsheet())); menu->addAction(tr("Add new graph"), this, SLOT(addNewGraph())); if (ui->graphingView->selectedGraphs().size() > 0) { @@ -432,6 +433,60 @@ void GraphingWindow::saveGraphs() } } +void GraphingWindow::saveSpreadsheet() +{ + QString filename; + QFileDialog dialog(this); + + QStringList filters; + filters.append(QString(tr("Spreadsheet (*.csv)"))); + + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setNameFilters(filters); + dialog.setViewMode(QFileDialog::Detail); + dialog.setAcceptMode(QFileDialog::AcceptSave); + + if (dialog.exec() == QDialog::Accepted) + { + filename = dialog.selectedFiles()[0]; + if (!filename.contains('.')) filename += ".csv"; + + QFile *outFile = new QFile(filename); + + if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) + return; + + /* + * save some data + * The problem here is that we've got X number of graphs that all have different + * timestamps but a spreadsheet would be best if each graph were taken at the same slice + * such that you have a list of slices with the value of each graph at that slice. + * + * But, for now export each graph in turn with the proper timestamp for each piece of data + * and a reference for which graph it came from. This is better than nothing. + */ + + QList::iterator iter; + int graphNum = 0; + for (iter = graphParams.begin(); iter != graphParams.end(); ++iter) + { + for (int j = 0; j < iter->x.count(); j++) + { + outFile->write(QString::number(iter->x[j]).toUtf8()); + outFile->putChar(','); + outFile->write(QString::number(graphNum).toUtf8()); + outFile->putChar(','); + outFile->write(QString::number(iter->y[j]).toUtf8()); + outFile->write("\n"); + } + graphNum++; + } + + outFile->close(); + } + +} + void GraphingWindow::saveDefinitions() { QString filename; diff --git a/graphingwindow.h b/graphingwindow.h index f59c31e..cdd97e5 100644 --- a/graphingwindow.h +++ b/graphingwindow.h @@ -51,6 +51,7 @@ private slots: void contextMenuRequest(QPoint pos); void moveLegend(); void saveGraphs(); + void saveSpreadsheet(); void saveDefinitions(); void loadDefinitions(); void addNewGraph();