From 0d5c370bc4ebd74beac4bd14c693054c6f9e28d7 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Thu, 29 Oct 2015 22:32:27 -0400 Subject: [PATCH] Added more control options to graphing window, updated version number The graphing window now can be zoomed via the context menu or with the + and - keys. Also, you can reset to a "good" view of all the graphs from the context menu. --- config.h | 2 +- flowviewwindow.cpp | 6 ++- graphingwindow.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++ graphingwindow.h | 4 ++ 4 files changed, 103 insertions(+), 3 deletions(-) diff --git a/config.h b/config.h index c960bb1..d70123e 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 139 +#define VERSION 140 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/flowviewwindow.cpp b/flowviewwindow.cpp index 7a42058..b52766e 100644 --- a/flowviewwindow.cpp +++ b/flowviewwindow.cpp @@ -87,14 +87,14 @@ FlowViewWindow::FlowViewWindow(const QVector *frames, QWidget *parent) connect(ui->flowView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestFlow(QPoint))); playbackTimer->setInterval(ui->spinPlayback->value()); //set the timer to the default value of the control - - installEventFilter(this); } void FlowViewWindow::showEvent(QShowEvent* event) { QDialog::showEvent(event); + installEventFilter(this); + readSettings(); refreshIDList(); @@ -109,6 +109,8 @@ void FlowViewWindow::showEvent(QShowEvent* event) FlowViewWindow::~FlowViewWindow() { + removeEventFilter(this); + delete ui; playbackTimer->stop(); diff --git a/graphingwindow.cpp b/graphingwindow.cpp index 33ba21c..10f9205 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -76,6 +76,7 @@ GraphingWindow::~GraphingWindow() void GraphingWindow::showEvent(QShowEvent* event) { QDialog::showEvent(event); + installEventFilter(this); readSettings(); ui->graphingView->replot(); } @@ -83,6 +84,7 @@ void GraphingWindow::showEvent(QShowEvent* event) void GraphingWindow::closeEvent(QCloseEvent *event) { Q_UNUSED(event); + removeEventFilter(this); writeSettings(); } @@ -306,6 +308,90 @@ void GraphingWindow::mouseWheel() ui->graphingView->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical); } +bool GraphingWindow::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyRelease) { + QKeyEvent *keyEvent = static_cast(event); + switch (keyEvent->key()) + { + case Qt::Key_Plus: + zoomIn(); + break; + case Qt::Key_Minus: + zoomOut(); + break; + } + return true; + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } +} + +void GraphingWindow::resetView() +{ + double yminval=10000000.0, ymaxval = -1000000.0; + double xminval=10000000000.0, xmaxval = -10000000000.0; + for (int i = 0; i < graphParams.count(); i++) + { + for (int j = 0; j < graphParams[i].x.count(); j++) + { + if (graphParams[i].x[j] < xminval) xminval = graphParams[i].x[j]; + if (graphParams[i].x[j] > xmaxval) xmaxval = graphParams[i].x[j]; + if (graphParams[i].y[j] < yminval) yminval = graphParams[i].y[j]; + if (graphParams[i].y[j] > ymaxval) ymaxval = graphParams[i].y[j]; + } + } + + ui->graphingView->xAxis->setRange(xminval, xmaxval); + ui->graphingView->yAxis->setRange(yminval, ymaxval); + ui->graphingView->axisRect()->setupFullAxesBox(); + + ui->graphingView->replot(); +} + +void GraphingWindow::zoomIn() +{ + QCPRange xrange = ui->graphingView->xAxis->range(); + QCPRange yrange = ui->graphingView->yAxis->range(); + if (ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spAxis)) + { + ui->graphingView->xAxis->scaleRange(0.666, xrange.center()); + } + + else if (ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spAxis)) + { + ui->graphingView->yAxis->scaleRange(0.666, yrange.center()); + } + else + { + ui->graphingView->xAxis->scaleRange(0.666, xrange.center()); + ui->graphingView->yAxis->scaleRange(0.666, yrange.center()); + } + ui->graphingView->replot(); +} + +void GraphingWindow::zoomOut() +{ + QCPRange xrange = ui->graphingView->xAxis->range(); + QCPRange yrange = ui->graphingView->yAxis->range(); + if (ui->graphingView->xAxis->selectedParts().testFlag(QCPAxis::spAxis)) + { + ui->graphingView->xAxis->scaleRange(1.5, xrange.center()); + } + + else if (ui->graphingView->yAxis->selectedParts().testFlag(QCPAxis::spAxis)) + { + ui->graphingView->yAxis->scaleRange(1.5, yrange.center()); + } + else + { + ui->graphingView->xAxis->scaleRange(1.5, xrange.center()); + ui->graphingView->yAxis->scaleRange(1.5, yrange.center()); + } + ui->graphingView->replot(); +} + void GraphingWindow::removeSelectedGraph() { if (ui->graphingView->selectedGraphs().size() > 0) @@ -386,11 +472,19 @@ void GraphingWindow::contextMenuRequest(QPoint pos) menu->addAction(tr("Add new graph"), this, SLOT(addNewGraph())); if (ui->graphingView->selectedGraphs().size() > 0) { + menu->addSeparator(); menu->addAction(tr("Edit selected graph"), this, SLOT(editSelectedGraph())); menu->addAction(tr("Remove selected graph"), this, SLOT(removeSelectedGraph())); } if (ui->graphingView->graphCount() > 0) + { + menu->addSeparator(); menu->addAction(tr("Remove all graphs"), this, SLOT(removeAllGraphs())); + } + menu->addSeparator(); + menu->addAction(tr("Reset View"), this, SLOT(resetView())); + menu->addAction(tr("Zoom In"), this, SLOT(zoomIn())); + menu->addAction(tr("Zoom Out"), this, SLOT(zoomOut())); } menu->popup(ui->graphingView->mapToGlobal(pos)); diff --git a/graphingwindow.h b/graphingwindow.h index cdd97e5..fb96302 100644 --- a/graphingwindow.h +++ b/graphingwindow.h @@ -60,6 +60,9 @@ private slots: void editSelectedGraph(); void updatedFrames(int); void gotCenterTimeID(int32_t ID, double timestamp); + void resetView(); + void zoomIn(); + void zoomOut(); signals: void sendCenterTimeID(int32_t ID, double timestamp); @@ -78,6 +81,7 @@ private: void closeEvent(QCloseEvent *event); void readSettings(); void writeSettings(); + bool eventFilter(QObject *obj, QEvent *event); }; #endif // GRAPHINGWINDOW_H