Hi guys,
i try to select the graph that is selected by clicking on its legend item... at the Moment, i react to the legendClick()
Signal of legend
connect(ui->plotter, SIGNAL(legendClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(plotterLegendClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)));
Inside the SLOT, i try to find the graph by its Name:
void MainWindow::plotterLegendClick(QCPLegend *l, QCPAbstractLegendItem *ai, QMouseEvent *me) { for(int i=0; i<l->parentPlot()->graphCount(); i++) { if(l->parentPlot()->graph(i)->name() == ((QCPPlottableLegendItem*)ai)->plottable()->name()) { l->parentPlot()->graph(i)->setSelected(!l->parentPlot()->graph(i)->selected()); ui->statusBar->showMessage("Selected Graph: \"" + l->parentPlot()->graph(i)->name() + "\""); } else { l->parentPlot()->graph(i)->setSelected(false); } } }
It seems that there is a Problem with the casting of ((QCPPlottableLegendItem*)ai)
.
Is it possible to check whether ai is of type QCPPlottableLegendItem
? Or is there another, better way to do this?