Merge pull request #316 from zero-motorcycle-community/graph-window-doubleclick-axis

GraphWindow: support rescaling the view or each axis to the data
This commit is contained in:
Collin Kidder
2021-03-18 19:47:47 -04:00
committed by GitHub
2 changed files with 27 additions and 6 deletions
+24 -5
View File
@@ -68,7 +68,7 @@ GraphingWindow::GraphingWindow(const QVector<CANFrame> *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
{
this->rescaleAxis(axis);
ui->graphingView->replot();
}
}
@@ -583,6 +586,18 @@ void GraphingWindow::removeAllGraphs()
}
}
void GraphingWindow::rescaleAxis(QCPAxis *axis)
{
axis->rescale(true);
}
void GraphingWindow::rescaleToData()
{
this->rescaleAxis(ui->graphingView->xAxis);
this->rescaleAxis(ui->graphingView->yAxis);
ui->graphingView->replot();
}
void GraphingWindow::toggleFollowMode()
{
followGraphEnd = !followGraphEnd;
@@ -624,6 +639,10 @@ void GraphingWindow::contextMenuRequest(QPoint pos)
}
menu->addSeparator();
menu->addAction(tr("Reset View"), this, SLOT(resetView()));
if (ui->graphingView->graphCount() > 0)
{
menu->addAction(tr("Rescale to data"), this, SLOT(rescaleToData()));
}
menu->addAction(tr("Zoom In"), this, SLOT(zoomIn()));
menu->addAction(tr("Zoom Out"), this, SLOT(zoomOut()));
}
+3 -1
View File
@@ -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);
@@ -63,6 +63,8 @@ private slots:
void saveSpreadsheet();
void saveDefinitions();
void loadDefinitions();
void rescaleAxis(QCPAxis* axis);
void rescaleToData();
void toggleFollowMode();
void addNewGraph();
void createGraph(GraphParams &params, bool createGraphParam = true);