After a crazy six-days holiday in Brazil and some never-ending flights I’m finally home and just to make it even better, Monday morning started with a head-on-brick-wall problem.

To put it shortly, adding objects to a QML maps appears to take linear time on the amount of mapObjects the map already holds. For some this might seem “not that bad” but it is. Basically, after adding 300 objects it’ll take approximately a second to add the 301th object. If you think in terms of “objects to be added”, the complete operation will be in O[n²].

(CHECK END OF ARTICLE FOR AN UPDATE & WORKAROUND)

Time for each insertion


I’ve already tried many different ways to add objects to the map (in addition to Map.addMapObject) without much improvement. I reckon the problem is that some checks/redrawing (prob O[n logn]) are performed at EVERY insertion and there’s no addMapObjectsList method that would first add all objects and then process/draw/check all items at the end on a single pass/go. . Am I missing something here or this feature/method is lacking only for simple laziness?

Related source seem to be at: https://qt.gitorious.org/qt-mobility/qt-mobility/blobs/master/src/location/maps/qgeomapdata.cpp#line454 which then goes to https://qt.gitorious.org/qt-mobility/qt-mobility/blobs/master/src/location/maps/qgeomapgroupobject.cpp#line158 .

Running out of ideas here except to lower the number of mapObjects …..

UPDATE: The real reason for such a bad performance is really only the (kind of) lack of a “addMapObjectsList”. Every time ONE item is added to the map, all items currently on the map are added. The solution (which becomes pretty obvious when you look at the source) is to add everything to a single MapGroup which wasn’t added to any map yet. Doing this the items are added but now drawn since there’s now linked map element. After all your items are added to this “root” MapGroup, adding that map group to the Map element will take linear time on the number of elements which is ok. Lots more info here .

« »