PDA

View Full Version : Dragging a QGraphicsItemGroup to an other position in the scene



samsam
16th July 2009, 12:44
Hello @ everyone her,

I am currently implementing a representation of some measurement values in a 2d-plane.
There is a huge amount of items (one pixel long QLineF 's) in the scene (up to 1 million) and a few graphs consisting of about 100 - 200 QLineF ' s.



bool myGraph::insertGraphIntoScene(QList <QPointF> &list, QColor col)
{
if(list.size() == 0)
return false;

else if(list.size() <2)
{
if(myLineGroupGraph == NULL)
myLineGroupGraph = new QGraphicsItemGroup();

QPointF p = list.at(0);
QGraphicsLineItem * line = new QGraphicsLineItem(p.x(),p.y(),p.x(),p.y());
line->setPen(col);

// get the line that crosses y-axis
if(p.x() == center.x())
lineThroughYAxis = line;


myLineGroupGraph->addToGroup(line);
scene.addItem(myLineGroupGraph);
}

else
{
if(myLineGroupGraph == NULL)
myLineGroupGraph = new QGraphicsItemGroup();
int i = 0;
QPointF p1,p2;
QGraphicsLineItem * line;
while(list.size() > i+2)
{
p1 = list.at(i);
p2 = list.at(i+1);

line = new QGraphicsLineItem(p1.x(),p1.y(),p2.x(),p2.y());
line->setPen(col);
myLineGroupGraph->addToGroup(line);
i++;
}

scene.addItem(myLineGroupGraph);
}
return true;
}



Now as seen in my code I have grouped all lines the curve consists of into myLineGroupGraph. Since I need to be able to click onto the curve and drag it up and down along the y axis, I am looking for a fast way to do so.

By calling



myLineGroupGraph->moveBy(...,...);

I can move the itemgroup up and down but it takes ages.

the viewportupdate is set to QGraphicsView::SmartViewportUpdate
I have tried QGraphicsView::FullViewportUpdate too.

Got any idea how to optimize implementation of the curve so the dragging gets faster?