my qt program visualizes some geo-data for which I am using GraphicsView with custom QGraphicsItems. The program offers the possibility to choose a new sceneRect with a custom QRubberBand. Everything is working fine so far, but everytime I try to perform a selection over areas containing about 215.000 QGraphicsItems the painting of the QRubberBand is stuttering. It's worse when I zoom out so much that the 215.000 QGraphicsItems lie within about 50*50 pixels.
Any ideas to solve this problem?
It doesn't make sense to try to display that many items in such a minute area. That's 86 items per pixel... I think you should start optimizing that so that you draw at most 1% of those items at that zoom level, though I guess aiming for 0.1% would be better.
Thanks for your reply. That's what I wanted to do anyways, but I thought there might be something I could do before. Is there some way to find out if a pixel is already painted to avoid being redrawn 215.000 times?
That is the wrong way to go about it. Please study the Graphics View demo with the chips. Also: think about the level of detail you need when you have zoomed out that much. What information is still important? What is not? Take a look at how Google Maps or Marble changes what details are visible on a map at each zoom level, and get some inspiration from that. Use those insights to avoid rendering whole classes of items on your map, and to simplify the rendering of other classes of objects (don't try to render a complex 20 point polygon if it is going to be projected on a 2x2 pixel area anyway).
Huh? I cannot remember any level of detail implementation in the chips demo. I guess I'll have to take another look at it.
Thank you for the help Andre, I see what you mean.
edit Thread can be closed...
I'm afraid it hast nothing to do with the drawing. I cleared the drawing function of my 215.000 elements so they are not drawn at all (no matter what level of detail is...)
As long as the items lie withing the scene and I try to open my RubberBand in the area where they should be drawn, my RubberBand keeps stuttering.
Will I have to remove them from the scene and add them again later? My experience with clearing a GraphicsScene is that performance is suffering from that so i won't win anything...
No, it has to do with the number of items in the view that has to be intersected with the rubberband area, I think. To solve that, you'll have to do more than disable the drawing, I think. However, my experience with map drawing apps pre-dates QGraphicsView, so it was not based on that.
I implemented a quadtree, dividing the whole scene into parts. These parts are now QGraphicsItems on which I paint my 215.000 Elements. The scene now only contains about 360 items, which is equivalent to the leafs of my QuadTree and the performance is way better now.
But if I do so, I will not be able to choose elements of my 215.000 bulk with itemAt(...). Since the GraphicsView does not seem to be capable of dealing with a huge amount of datasets I think I have to think of a method of making these painted elements selectable, or am I mistaken?
I would think of grouping items. At a certain zoom level you cannot distinguish single items anyways.
If I use
@void QGraphicsItemGroup::addToGroup ( QGraphicsItem * item )@
will the RubberBand intersection be tested only against the group or will it still be tested against every member of the group?