From 59a29e765c9c2c2711f24c36a06747199b5a5956 Mon Sep 17 00:00:00 2001 From: "Brian T. Rice" Date: Sat, 13 Mar 2021 15:38:01 -0800 Subject: [PATCH] GraphWindow: support double-clicking the axis to resize it to the data --- re/graphingwindow.cpp | 13 ++++++++----- re/graphingwindow.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index 331de61..8056276 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -68,7 +68,7 @@ GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) connect(ui->graphingView->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->graphingView->yAxis2, SLOT(setRange(QCPRange))); //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(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisDoubleClick(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*))); @@ -294,11 +294,10 @@ void GraphingWindow::titleDoubleClick(QMouseEvent* event, QCPTextElement* title) editSelectedGraph(); } -void GraphingWindow::axisLabelDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part) +void GraphingWindow::axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part) { - qDebug() << "axisLabelDoubleClick"; - // Set an axis label by double clicking on it - if (part == QCPAxis::spAxisLabel) // only react when the actual axis label is clicked, not tick label or axis backbone + qDebug() << "axisDoubleClick"; + if (part == QCPAxis::spAxisLabel) // Set an axis label by double clicking on it { bool ok; QString newLabel = QInputDialog::getText(this, "SavvyCAN Graphing", "New axis label:", QLineEdit::Normal, axis->label(), &ok); @@ -307,6 +306,10 @@ void GraphingWindow::axisLabelDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart axis->setLabel(newLabel); ui->graphingView->replot(); } + } else if (part == QCPAxis::spAxis) // Resize an axis to fit by double clicking it + { + axis->rescale(true); + ui->graphingView->replot(); } } diff --git a/re/graphingwindow.h b/re/graphingwindow.h index 34fece5..664ad58 100644 --- a/re/graphingwindow.h +++ b/re/graphingwindow.h @@ -47,7 +47,7 @@ public: private slots: void titleDoubleClick(QMouseEvent *event, QCPTextElement *title); - void axisLabelDoubleClick(QCPAxis* axis, QCPAxis::SelectablePart part); + void axisDoubleClick(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);