PDA

View Full Version : replot() after changing the x- and yValue of QwtPlotMarker



rambo83
23rd November 2009, 10:43
Hello,

I want to drag my QwtPlotMarker on the plot and thus I have writen the following functions:

void Plot::cursorSelected(const QwtDoublePoint &Point)
{
std::cout << "in Plot::cursorSelected" << std::endl;
const QwtPlotItemList& List = itemList();
QwtPlotItemIterator Iter = List.begin();

selectedPoint = NULL;
std::cout << "selectedPoint = " << selectedPoint << std::endl;
std::cout << "Point = " << Point.x() << ", " << Point.y()<< std::endl;
while(Iter != List.end())
{
QwtPlotItem *pItem = (QwtPlotItem *)(*Iter);

if(pItem->rtti() == QwtPlotItem::Rtti_PlotMarker)
if(pItem->boundingRect().contains(Point)){
std::cout << "MATCH" << std::endl;
selectedPoint = dynamic_cast<QwtPlotMarker*>(pItem);
std::cout << "selectedPoint = " << selectedPoint << std::endl;
}
Iter++;
}
}

void Plot::cursorMoved( const QPoint& Point){
std::cout << "in Plot::cursorMoved" << std::endl;
if(selectedPoint){
double xData = this->invTransform(selectedPoint->xAxis(), Point.x());;
double yData =this->invTransform(selectedPoint->yAxis(), Point.y());;

std::cout << "xData: " << xData <<"yData: " << yData<< std::endl;
selectedPoint->setXValue(xData);
selectedPoint->setYValue(yData);

std::cout << "selectedPoint->xValue(): " << selectedPoint->xValue() <<"selectedPoint->yValue(): " << selectedPoint->yValue()<< std::endl;
this->replot();
}
}

and I get the following output if I drag the Marker:

in Plot::cursorMoved
xData: 0.38022yData: -0.00858369
selectedPoint->xValue(): 0.38022selectedPoint->yValue(): -0.00858369
in Plot::cursorMoved
xData: 0.410989yData: -0.0343348
selectedPoint->xValue(): 0.410989selectedPoint->yValue(): -0.0343348
in Plot::cursorMoved
xData: 0.481319yData: -0.0772532
selectedPoint->xValue(): 0.481319selectedPoint->yValue(): -0.0772532
in Plot::cursorSelected
selectedPoint = 0
Point = 0.481319, -0.0772532


That means the coordinates of the marker are changed, but the command this->replot() does not work because the marker is still on its last position.
Or does I have to repaint/ redraw the marker at new position by calling its member function "draw"?

Help me please.

Thank you