From 1b67ac5cf49e01c415635033eb6816f6b01b1cf6 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 7 Jun 2015 22:41:57 -0400 Subject: [PATCH] Added ability to save an image of the graph, fixed graphing so that timing is relative to the start of the capture (this makes viewing one capture after another with the same graphs much easier). Fixed rescale when importing a new file (no longer rescales). The bottom line is that it'll be a lot easier to work with graphing of multiple files now. --- graphingwindow.cpp | 45 +++++++++++++++++++++++++++++++++++++++------ graphingwindow.h | 1 + mainwindow.h | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/graphingwindow.cpp b/graphingwindow.cpp index fe2e49c..d955cde 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -84,7 +84,7 @@ void GraphingWindow::updatedFrames(int numFrames) //there shouldn't be any need to actually remove the graphs. //regenerate them instead ui->graphingView->clearGraphs(); //temporarily remove the graphs from the graph view - needScaleSetup = true; + //needScaleSetup = true; for (int i = 0; i < graphParams.count(); i++) { createGraph(graphParams[i], false); //regenerate each one @@ -96,8 +96,6 @@ void GraphingWindow::updatedFrames(int numFrames) } } - - void GraphingWindow::titleDoubleClick(QMouseEvent* event, QCPPlotTitle* title) { Q_UNUSED(event) @@ -277,21 +275,48 @@ void GraphingWindow::contextMenuRequest(QPoint pos) menu->addAction(tr("Move to top right"), this, SLOT(moveLegend()))->setData((int)(Qt::AlignTop|Qt::AlignRight)); menu->addAction(tr("Move to bottom right"), this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignRight)); menu->addAction(tr("Move to bottom left"), this, SLOT(moveLegend()))->setData((int)(Qt::AlignBottom|Qt::AlignLeft)); - } else // general context menu on graphs requested + } + else // general context menu on graphs requested { + menu->addAction(tr("Save Graphs to File"), this, SLOT(saveGraphs())); menu->addAction(tr("Add new graph"), this, SLOT(addNewGraph())); if (ui->graphingView->selectedGraphs().size() > 0) { menu->addAction(tr("Edit selected graph"), this, SLOT(editSelectedGraph())); - menu->addAction(tr("Remove selected graph"), this, SLOT(removeSelectedGraph())); + menu->addAction(tr("Remove selected graph"), this, SLOT(removeSelectedGraph())); } if (ui->graphingView->graphCount() > 0) - menu->addAction(tr("Remove all graphs"), this, SLOT(removeAllGraphs())); + menu->addAction(tr("Remove all graphs"), this, SLOT(removeAllGraphs())); } menu->popup(ui->graphingView->mapToGlobal(pos)); } +void GraphingWindow::saveGraphs() +{ + QString filename; + QFileDialog dialog(this); + + QStringList filters; + filters.append(QString(tr("PDF Files (*.pdf)"))); + filters.append(QString(tr("PNG Files (*.png)"))); + filters.append(QString(tr("JPEG Files (*.jpg)"))); + + 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 (dialog.selectedNameFilter() == filters[0]) ui->graphingView->savePdf(filename, true, 0, 0); + if (dialog.selectedNameFilter() == filters[1]) ui->graphingView->savePng(filename, 0, 0); + if (dialog.selectedNameFilter() == filters[2]) ui->graphingView->saveJpg(filename, 0, 0); + } +} + void GraphingWindow::showParamsDialog(int idx = -1) { NewGraphDialog *thisDialog = new NewGraphDialog(); @@ -419,6 +444,14 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) if (x[j] > xmaxval) xmaxval = x[j]; } } + + for (int ct = 0; ct < x.count(); ct++) + { + x[ct] -= xminval; + } + xmaxval -= xminval; + xminval = 0; + ui->graphingView->addGraph(); params.ref = ui->graphingView->graph(); if (createGraphParam) graphParams.append(params); diff --git a/graphingwindow.h b/graphingwindow.h index 0b7b49b..5ed42fd 100644 --- a/graphingwindow.h +++ b/graphingwindow.h @@ -44,6 +44,7 @@ private slots: void removeAllGraphs(); void contextMenuRequest(QPoint pos); void moveLegend(); + void saveGraphs(); void addNewGraph(); void createGraph(GraphParams ¶ms, bool createGraphParam = true); void editSelectedGraph(); diff --git a/mainwindow.h b/mainwindow.h index ae46268..341a101 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -14,7 +14,7 @@ #include "dbchandler.h" #include "dbcmaineditor.h" -#define VERSION 110 +#define VERSION 111 namespace Ui { class MainWindow;