From 280a3e11d7b3f5d44d237c9003f198d6505a385a Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 13 Aug 2017 18:01:05 -0400 Subject: [PATCH] Fixes to Flowview and Graphing windows to make them work with new QCustomPlot version --- re/flowviewwindow.cpp | 4 ++-- re/graphingwindow.cpp | 28 +++++++++++++++++++++++++--- re/graphingwindow.h | 2 ++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/re/flowviewwindow.cpp b/re/flowviewwindow.cpp index c4ca24e..2b24f6f 100644 --- a/re/flowviewwindow.cpp +++ b/re/flowviewwindow.cpp @@ -708,8 +708,8 @@ void FlowViewWindow::updateGraphLocation() { if (secondsMode) { - /* ui->graphView->xAxis->setRange(frameCache[start].timestamp / 1000000.0, frameCache[end].timestamp / 1000000.0); + /* ui->graphView->xAxis->setTickStep((frameCache[end].timestamp - frameCache[start].timestamp)/ 3000000.0); ui->graphView->xAxis->setSubTickCount(0); ui->graphView->xAxis->setNumberFormat("f"); @@ -718,8 +718,8 @@ void FlowViewWindow::updateGraphLocation() } else { - /* ui->graphView->xAxis->setRange(frameCache[start].timestamp, frameCache[end].timestamp); + /* ui->graphView->xAxis->setTickStep((frameCache[end].timestamp - frameCache[start].timestamp)/ 3.0); ui->graphView->xAxis->setSubTickCount(0); ui->graphView->xAxis->setNumberFormat("f"); diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index 78219ca..f3b24a3 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -55,6 +55,7 @@ GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) //connect(ui->graphingView, SIGNAL(titleDoubleClick(QMouseEvent*,QCPTextElement*)), this, SLOT(titleDoubleClick(QMouseEvent*,QCPTextElement*))); 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(ui->graphingView, SIGNAL(legendClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendSingleClick(QCPLegend*,QCPAbstractLegendItem*))); connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); @@ -230,9 +231,27 @@ void GraphingWindow::axisLabelDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart } } +void GraphingWindow::legendSingleClick(QCPLegend *legend, QCPAbstractLegendItem *item) +{ + // select a graph by clicking on the legend + qDebug() << "Legend Single Click " << item; + Q_UNUSED(legend) + if (item) // only react if item was clicked (user could have clicked on border padding of legend where there is no item, then item is 0) + { + QCPPlottableLegendItem *plItem = qobject_cast(item); + QCPGraph *pGraph = qobject_cast(plItem->plottable()); + QCPDataSelection sel; + QCPDataRange rang; + rang.setBegin(0); + rang.setEnd(pGraph->dataCount()); + sel.addDataRange(rang); + pGraph->setSelection(sel); + } +} + void GraphingWindow::legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item) { - // Rename a graph by double clicking on its legend item + // edit a graph by double clicking on its legend item qDebug() << "Legend Double Click " << item; Q_UNUSED(legend) if (item) // only react if item was clicked (user could have clicked on border padding of legend where there is no item, then item is 0) @@ -1008,8 +1027,11 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) graphParams.append(params); refParam = &graphParams.last(); } - //ui->graphingView->graph()->setSelectedBrush(Qt::NoBrush); - //ui->graphingView->graph()->setSelectedPen(selectedPen); + + selDecorator = new QCPSelectionDecorator(); //this has to be a pointer as it is freed internally to qcustomplot classes + selDecorator->setBrush(Qt::NoBrush); + selDecorator->setPen(selectedPen); + ui->graphingView->graph()->setSelectionDecorator(selDecorator); if (params.graphName == NULL || params.graphName.length() == 0) { diff --git a/re/graphingwindow.h b/re/graphingwindow.h index 1113f08..08920c7 100644 --- a/re/graphingwindow.h +++ b/re/graphingwindow.h @@ -43,6 +43,7 @@ private slots: void titleDoubleClick(QMouseEvent *event, QCPTextElement *title); void axisLabelDoubleClick(QCPAxis* axis, QCPAxis::SelectablePart part); void legendDoubleClick(QCPLegend* legend, QCPAbstractLegendItem* item); + void legendSingleClick(QCPLegend* legend, QCPAbstractLegendItem* item); void plottableDoubleClick(QCPAbstractPlottable* plottable,int dataIdx, QMouseEvent* event); void selectionChanged(); void mousePress(); @@ -75,6 +76,7 @@ private: const QVector *modelFrames; QList graphParams; QPen selectedPen; + QCPSelectionDecorator *selDecorator; bool needScaleSetup; //do we need to set x,y graphing extents? bool secondsMode;