From 74c19d2c8951c9a1dfa4bc0e1cf7e6e0ccb19706 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Wed, 3 Jun 2015 22:45:16 -0400 Subject: [PATCH] Implementation of refresh on file load and frame clearing for Graphing window. Clear old frames when loading new file. Updated version. --- graphingwindow.cpp | 32 ++++++++++++++++++++++++++++++-- graphingwindow.h | 3 ++- mainwindow.cpp | 7 +++++-- mainwindow.h | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/graphingwindow.cpp b/graphingwindow.cpp index b5abc31..49f9774 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -1,6 +1,7 @@ #include "graphingwindow.h" #include "ui_graphingwindow.h" #include "newgraphdialog.h" +#include "mainwindow.h" #include GraphingWindow::GraphingWindow(QVector *frames, QWidget *parent) : @@ -47,6 +48,8 @@ GraphingWindow::GraphingWindow(QVector *frames, QWidget *parent) : connect(ui->graphingView, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart))); connect(ui->graphingView, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*))); + connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); + // setup policy and connect slot for context menu popup: ui->graphingView->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->graphingView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint))); @@ -63,8 +66,33 @@ GraphingWindow::~GraphingWindow() void GraphingWindow::showEvent(QShowEvent* event) { QDialog::showEvent(event); + ui->graphingView->replot(); } +void GraphingWindow::updatedFrames(int numFrames) +{ + if (numFrames == -1) //all frames deleted. Kill the display + { + removeAllGraphs(); + } + else if (numFrames == -2) //all new set of frames. Reset + { + //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 + for (int i = 0; i < graphParams.count(); i++) + { + createGraph(graphParams[i], false); //regenerate each one + } + ui->graphingView->replot(); //now, redisplay them all + } + else //just got some new frames. See if they are relevant. + { + } +} + + + void GraphingWindow::titleDoubleClick(QMouseEvent* event, QCPPlotTitle* title) { Q_UNUSED(event) @@ -279,7 +307,7 @@ void GraphingWindow::addNewGraph() showParamsDialog(-1); } -void GraphingWindow::createGraph(GraphParams ¶ms) +void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) { int tempVal; float minval=1000000, maxval = -100000; @@ -376,7 +404,7 @@ void GraphingWindow::createGraph(GraphParams ¶ms) } ui->graphingView->addGraph(); params.ref = ui->graphingView->graph(); - graphParams.append(params); + if (createGraphParam) graphParams.append(params); ui->graphingView->graph()->setSelectedBrush(Qt::NoBrush); ui->graphingView->graph()->setSelectedPen(selectedPen); ui->graphingView->graph()->setName(QString("Graph %1").arg(ui->graphingView->graphCount()-1)); diff --git a/graphingwindow.h b/graphingwindow.h index 461559b..b259872 100644 --- a/graphingwindow.h +++ b/graphingwindow.h @@ -45,8 +45,9 @@ private slots: void contextMenuRequest(QPoint pos); void moveLegend(); void addNewGraph(); - void createGraph(GraphParams ¶ms); + void createGraph(GraphParams ¶ms, bool createGraphParam = true); void editSelectedGraph(); + void updatedFrames(int); private: Ui::GraphingWindow *ui; diff --git a/mainwindow.cpp b/mainwindow.cpp index 3cce0da..77a0f52 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -557,8 +557,8 @@ void MainWindow::loadLogFile(QString filename) { QList tokens = line.split(' '); QList timeToks = tokens[0].split(':'); - timeStamp = (timeToks[0].toInt() * (1000 * 1000 * 60 * 60)) + (timeToks[1].toInt() * (1000 * 1000 * 60)) - + (timeToks[2].toInt() * (1000 * 1000)) + (timeToks[3].toInt() * 100); + timeStamp = (timeToks[0].toInt() * (1000ul * 1000ul * 60ul * 60ul)) + (timeToks[1].toInt() * (1000ul * 1000ul * 60ul)) + + (timeToks[2].toInt() * (1000ul * 1000ul)) + (timeToks[3].toInt() * 100ul); thisFrame.timestamp = timeStamp; thisFrame.ID = tokens[3].right(tokens[3].length() - 2).toInt(NULL, 16); if (tokens[4] == "s") thisFrame.extended = false; @@ -670,6 +670,9 @@ void MainWindow::handleLoadFile() filename = dialog.selectedFiles()[0]; } + ui->canFramesView->scrollToTop(); + model->clearFrames(); + if (dialog.selectedNameFilter() == filters[0]) loadCRTDFile(filename); if (dialog.selectedNameFilter() == filters[1]) loadNativeCSVFile(filename); if (dialog.selectedNameFilter() == filters[2]) loadGenericCSVFile(filename); diff --git a/mainwindow.h b/mainwindow.h index 8b9b693..51dc29a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -14,7 +14,7 @@ #include "dbchandler.h" #include "dbcmaineditor.h" -#define VERSION 107 +#define VERSION 108 namespace Ui { class MainWindow;