Add a circle on the selected graph where you double clicked on it. Also show text with the coordinates at the clicked graph location

This commit is contained in:
Collin Kidder
2017-12-14 21:47:18 -05:00
parent a3a2186357
commit b7e8429222
2 changed files with 34 additions and 0 deletions
+31
View File
@@ -42,11 +42,24 @@ GraphingWindow::GraphingWindow(const QVector<CANFrame> *frames, QWidget *parent)
ui->graphingView->legend->setSelectedFont(legendSelectedFont); ui->graphingView->legend->setSelectedFont(legendSelectedFont);
ui->graphingView->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items 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 slot that ties some axis selections together (especially opposite axes):
connect(ui->graphingView, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged())); connect(ui->graphingView, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
//connect up the mouse controls //connect up the mouse controls
connect(ui->graphingView, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress())); 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(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())); connect(ui->graphingView, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
// make bottom and left axes transfer their ranges to top and right axes: // 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<QCPGraph *>(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) void GraphingWindow::plottableDoubleClick(QCPAbstractPlottable* plottable, int dataIdx, QMouseEvent* event)
{ {
Q_UNUSED(dataIdx); Q_UNUSED(dataIdx);
@@ -218,6 +240,15 @@ void GraphingWindow::plottableDoubleClick(QCPAbstractPlottable* plottable, int d
id = plottable->property("id").toInt(); id = plottable->property("id").toInt();
if (secondsMode) emit sendCenterTimeID(id, coord); if (secondsMode) emit sendCenterTimeID(id, coord);
else emit sendCenterTimeID(id, coord / 1000000.0); else emit sendCenterTimeID(id, coord / 1000000.0);
double x, y;
QCPGraph *graph = reinterpret_cast<QCPGraph *>(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) void GraphingWindow::gotCenterTimeID(int32_t ID, double timestamp)
+3
View File
@@ -46,6 +46,7 @@ private slots:
void legendDoubleClick(QCPLegend* legend, QCPAbstractLegendItem* item); void legendDoubleClick(QCPLegend* legend, QCPAbstractLegendItem* item);
void legendSingleClick(QCPLegend* legend, QCPAbstractLegendItem* item); void legendSingleClick(QCPLegend* legend, QCPAbstractLegendItem* item);
void plottableDoubleClick(QCPAbstractPlottable* plottable,int dataIdx, QMouseEvent* event); void plottableDoubleClick(QCPAbstractPlottable* plottable,int dataIdx, QMouseEvent* event);
void plottableClick(QCPAbstractPlottable* plottable, int dataIdx, QMouseEvent* event);
void selectionChanged(); void selectionChanged();
void mousePress(); void mousePress();
void mouseWheel(); void mouseWheel();
@@ -79,6 +80,8 @@ private:
QList<GraphParams> graphParams; QList<GraphParams> graphParams;
QPen selectedPen; QPen selectedPen;
QCPSelectionDecorator *selDecorator; QCPSelectionDecorator *selDecorator;
QCPItemText *locationText;
QCPItemTracer *itemTracer;
bool needScaleSetup; //do we need to set x,y graphing extents? bool needScaleSetup; //do we need to set x,y graphing extents?
bool secondsMode; bool secondsMode;
bool useOpenGL; bool useOpenGL;