From 8caafce0222b8fc71a4f343d60327fe2094bcd29 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Thu, 4 Jun 2015 21:08:25 -0400 Subject: [PATCH] Graphing window now retains your current view when graphs are added and subtracted unless you get down to no graphs. This makes it easier to load lots of graphs and do work without having the graph constantly resize. --- graphingwindow.cpp | 17 ++++++++++++++--- graphingwindow.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/graphingwindow.cpp b/graphingwindow.cpp index 74ab87a..831c23e 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -58,6 +58,8 @@ GraphingWindow::GraphingWindow(QVector *frames, QWidget *parent) : selectedPen.setWidth(1); selectedPen.setColor(Qt::blue); + + needScaleSetup = true; } GraphingWindow::~GraphingWindow() @@ -82,6 +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; for (int i = 0; i < graphParams.count(); i++) { createGraph(graphParams[i], false); //regenerate each one @@ -225,6 +228,9 @@ void GraphingWindow::removeSelectedGraph() graphParams.removeAt(idx); ui->graphingView->removeGraph(ui->graphingView->selectedGraphs().first()); + + if (graphParams.count() == 0) needScaleSetup = true; + ui->graphingView->replot(); } } @@ -255,6 +261,7 @@ void GraphingWindow::removeAllGraphs() { ui->graphingView->clearGraphs(); graphParams.clear(); + needScaleSetup = true; ui->graphingView->replot(); } @@ -425,9 +432,13 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) graphPen.setWidth(1); ui->graphingView->graph()->setPen(graphPen); - ui->graphingView->xAxis->setRange(xminval, xmaxval); - ui->graphingView->yAxis->setRange(yminval, ymaxval); - ui->graphingView->axisRect()->setupFullAxesBox(); + if (needScaleSetup) + { + needScaleSetup = false; + ui->graphingView->xAxis->setRange(xminval, xmaxval); + ui->graphingView->yAxis->setRange(yminval, ymaxval); + ui->graphingView->axisRect()->setupFullAxesBox(); + } ui->graphingView->replot(); } diff --git a/graphingwindow.h b/graphingwindow.h index b259872..0b7b49b 100644 --- a/graphingwindow.h +++ b/graphingwindow.h @@ -55,6 +55,7 @@ private: QVector *modelFrames; QList graphParams; QPen selectedPen; + bool needScaleSetup; //do we need to set x,y graphing extents?s void showParamsDialog(int idx); };