diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index ec97149..51bd09e 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -42,11 +42,24 @@ GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) ui->graphingView->legend->setSelectedFont(legendSelectedFont); ui->graphingView->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items + locationText = new QCPItemText(ui->graphingView); + locationText->position->setType(QCPItemPosition::ptAxisRectRatio); + locationText->position->setCoords(QPointF(0.16, 0.03)); + locationText->setText("X: 0 Y: 0"); + locationText->setFont(legendSelectedFont); + + itemTracer = new QCPItemTracer(ui->graphingView); + itemTracer->setInterpolating(true); + itemTracer->setVisible(false); //no graph selected yet + itemTracer->setStyle(QCPItemTracer::tsCircle); + itemTracer->setSize(20); + // connect slot that ties some axis selections together (especially opposite axes): connect(ui->graphingView, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged())); //connect up the mouse controls connect(ui->graphingView, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress())); connect(ui->graphingView, SIGNAL(plottableDoubleClick(QCPAbstractPlottable*,int,QMouseEvent*)), this, SLOT(plottableDoubleClick(QCPAbstractPlottable*,int,QMouseEvent*))); + connect(ui->graphingView, SIGNAL(plottableClick(QCPAbstractPlottable*,int,QMouseEvent*)), this, SLOT(plottableClick(QCPAbstractPlottable*,int,QMouseEvent*))); connect(ui->graphingView, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel())); // make bottom and left axes transfer their ranges to top and right axes: @@ -208,6 +221,15 @@ void GraphingWindow::updatedFrames(int numFrames) } } +void GraphingWindow::plottableClick(QCPAbstractPlottable* plottable, int dataIdx, QMouseEvent* event) +{ + qDebug() << "plottableClick"; + double x, y; + QCPGraph *graph = reinterpret_cast(plottable); + graph->pixelsToCoords(event->localPos(), x, y); + locationText->setText("X: " + QString::number(x, 'f', 3) + " Y: " + QString::number(y, 'f', 3)); +} + void GraphingWindow::plottableDoubleClick(QCPAbstractPlottable* plottable, int dataIdx, QMouseEvent* event) { Q_UNUSED(dataIdx); @@ -218,6 +240,15 @@ void GraphingWindow::plottableDoubleClick(QCPAbstractPlottable* plottable, int d id = plottable->property("id").toInt(); if (secondsMode) emit sendCenterTimeID(id, coord); else emit sendCenterTimeID(id, coord / 1000000.0); + + double x, y; + QCPGraph *graph = reinterpret_cast(plottable); + graph->pixelsToCoords(event->localPos(), x, y); + locationText->setText("X: " + QString::number(x) + " Y: " + QString::number(y)); + + itemTracer->setGraph(graph); + itemTracer->setVisible(true); + itemTracer->setGraphKey(x); } void GraphingWindow::gotCenterTimeID(int32_t ID, double timestamp) diff --git a/re/graphingwindow.h b/re/graphingwindow.h index 795780b..cc79cbc 100644 --- a/re/graphingwindow.h +++ b/re/graphingwindow.h @@ -46,6 +46,7 @@ private slots: void legendDoubleClick(QCPLegend* legend, QCPAbstractLegendItem* item); void legendSingleClick(QCPLegend* legend, QCPAbstractLegendItem* item); void plottableDoubleClick(QCPAbstractPlottable* plottable,int dataIdx, QMouseEvent* event); + void plottableClick(QCPAbstractPlottable* plottable, int dataIdx, QMouseEvent* event); void selectionChanged(); void mousePress(); void mouseWheel(); @@ -79,6 +80,8 @@ private: QList graphParams; QPen selectedPen; QCPSelectionDecorator *selDecorator; + QCPItemText *locationText; + QCPItemTracer *itemTracer; bool needScaleSetup; //do we need to set x,y graphing extents? bool secondsMode; bool useOpenGL;