Hello,
I have implemented the dragging function of some QwtPlotMarkers by using the QwtPlotPicker ( see code below), but I'm not satisfied about the speed of replot, because when I move the items they don't move fluently but with jumps and I can also see the for loop in it, because first one item is moved then the second and so on. How can I move the selected items simultaneously? Help me please.
Thank you
best regards,
Vitali
// this function provides the ability to move items on the plot
void Plot::cursorMoved( const QwtDoublePoint& Point){
if(_mf->getMode() == mainFrame::Recombination){ // allow to move the plot items only in Recombination phase
if(!selected_Points.empty()){ //if the list with selected items is not empty, then...
for(int i=0; i< selected_Points.size(); ++i) {
picker
->setRubberBand
(QwtPicker::NoRubberBand);
// switch off the rubber band during drag process double delta_x = Point.x() - clickpos->x(); // calculate the x difference
double delta_y = Point.y() - clickpos->y(); // calculate the y difference
unsigned idx=_mf->objFunction;
double rangex1[2] = {optProbList[idx]->range_x1[0], optProbList[idx]->range_x1[1]};
double rangex2[2] = {optProbList[idx]->range_x2[0], optProbList[idx]->range_x2[1]};
// set the new coordinates to the moved item, but check first whether the movement is within the valid area
if((selected_Points[i]->xValue() + delta_x) < rangex1[1] && (selected_Points[i]->xValue() + delta_x) > rangex1[0]){
selected_Points[i]->setXValue(selected_Points[i]->xValue() + delta_x);
}
if((selected_Points[i]->yValue() + delta_y) < rangex2[1] && (selected_Points[i]->yValue() + delta_y) > rangex2[0]){
selected_Points[i]->setYValue(selected_Points[i]->yValue() + delta_y);
}
// check which index does this selected item have
int index = (selected_Points[i]->title().text().toInt()); // transform from string to integer
_mf->updateChromosome( selected_Points[i]->value(),index); // update the individuals with new values
}
this->replot(); // replot the plot widget after the selected point was moved
}
else{
picker
->setRubberBand
(QwtPicker::RectRubberBand);
// switch on the rectangle rubber band }
clickpos = new QwtDoublePoint(Point); // update the reference point
}
else return;
}
// this function provides the ability to move items on the plot
void Plot::cursorMoved( const QwtDoublePoint& Point){
if(_mf->getMode() == mainFrame::Recombination){ // allow to move the plot items only in Recombination phase
if(!selected_Points.empty()){ //if the list with selected items is not empty, then...
for(int i=0; i< selected_Points.size(); ++i) {
picker->setRubberBand(QwtPicker::NoRubberBand); // switch off the rubber band during drag process
double delta_x = Point.x() - clickpos->x(); // calculate the x difference
double delta_y = Point.y() - clickpos->y(); // calculate the y difference
unsigned idx=_mf->objFunction;
double rangex1[2] = {optProbList[idx]->range_x1[0], optProbList[idx]->range_x1[1]};
double rangex2[2] = {optProbList[idx]->range_x2[0], optProbList[idx]->range_x2[1]};
// set the new coordinates to the moved item, but check first whether the movement is within the valid area
if((selected_Points[i]->xValue() + delta_x) < rangex1[1] && (selected_Points[i]->xValue() + delta_x) > rangex1[0]){
selected_Points[i]->setXValue(selected_Points[i]->xValue() + delta_x);
}
if((selected_Points[i]->yValue() + delta_y) < rangex2[1] && (selected_Points[i]->yValue() + delta_y) > rangex2[0]){
selected_Points[i]->setYValue(selected_Points[i]->yValue() + delta_y);
}
// check which index does this selected item have
int index = (selected_Points[i]->title().text().toInt()); // transform from string to integer
_mf->updateChromosome( selected_Points[i]->value(),index); // update the individuals with new values
}
this->replot(); // replot the plot widget after the selected point was moved
}
else{
picker->setRubberBand(QwtPicker::RectRubberBand); // switch on the rectangle rubber band
}
clickpos = new QwtDoublePoint(Point); // update the reference point
}
else return;
}
To copy to clipboard, switch view to plain text mode
Bookmarks