PDA

View Full Version : QGraphics View Scene performance with polylines



iampowerslave
15th November 2010, 17:03
Hi.

After seeking for a couple of months, couldn't find anything that helps us develop a fast graphics application that deals with polylines (or Polygons).

What we are dealing with, is similar to the QWTPlot, but QWT doesn't fits us. I know there are many things that I will need to explain, and I can't get a shorter "demo" app right now to upload.

I've tried QWT and it's fast. I've tried to trace the code, and it does the same we do, unless it's setting some special QT stuff regionally that we don't know about. But looking from the ->Paint and back, it's mostly the same, even does more array copying and applies manipulation that we are avoiding.

The basic deal is, we have a QGraphicsView, ripped from the Chip example, we cleaned up everything and left the window with the controls.

Now we read from ASCII files a set of pairs into a list of QPointF

We changed the Scales and Transforms to set one scale relative to meters, according to the screen DPI and then we draw the list of QPointF as a Polyline inside the painter of a QGraphicsItem.

When we draw about 6 (six) Items. Each of them have 40k pairs, it draws fast, but as we scroll down it start to get sluggish. If we zoom out it also gets sluggish.

Unfortunately if we turn the drawing upside down (since the chip has a rotate feature) it still works the same way, the bottom that is UP now, is fast, and as we scroll down, it turns sluggish.

There are no re-paints as we scroll since putting a breakpoint on the ->Paint does not stop.

How did we "solved" it?

We broke down the 40k points into 1k point pieces. We do instance this new QGraphicsItem giving it the same list of QPointF but we tell it to start at point A and end at B (which is A+1000) and now it's INCREDIBLY fast.

On one side, we have to deal with 40 pieces (Items) instead of one. But the BoundingRect of each is limited to it's bounds, everything outside can't be seen. So only the pieces that are inside the view are drawn. That's good.

But the weird thing is, when we zoom out to fit EVERYTHING into the view, it's still fast. How is it that fast when it has to draw EVERYTHING like it did before splitting into 1Ks?

Downsides are, the connection between each of this pieces is wrong when the pen is not continous since the pen ends at one position and then starts from 0 again.

Is there any way to make only one piece and make it render fast?

Thanks.

David.