SVG && fast update
-
How about caching the resulting bitmap images? Getting them onto the screen is way faster than rerendering SVG all the time!
The memory overhead of caching should not be too large if it is really only these the states you need to save.
-
It does not really matter how big the change in the SVG is: You end up rerendering the complete SVG image. Rendering SVG is always much slower than just putting a pixmap onto the screen.
Of course you can just cache the area that changes and paste it over the effected area... Just construct a QPixmap of the area by copying it out of the original one and then use the QPainter APIs to paint it to wherever needed.
-
[quote author="Jorj" date="1277798615"]Can't you just use the QPainter architecture to draw circles rather than using SVG at all?[/quote]
No, because user of the application must be able to open his own SVG.
The application must be able to change the state of the element it find in the new SVG. -
Is it possible it would be faster to load using the XML stream option, then you can keep the XML heirachy in memory, change the tag you want, and reload the xml?
However, I think the cache to pixmap is better option...
Qt may benefit from the ability to load an SVG to something like a QPicture, but editable, then you could navigate the heirachy in code not via byte arrays. That would give better performance...
-
Thanks for answer...
[quote author="Jorj" date="1277971476"]Is it possible it would be faster to load using the XML stream option, then you can keep the XML heirachy in memory, change the tag you want, and reload the xml?
[/quote]This is what I do but, after changing the tag I want, actually I call:
@
svgArray = svgXml.toByteArray();
this->load(svgArray);
@The slowest line is:
@
this->load(svgArray);
@[quote author="Jorj" date="1277971476"]
Qt may benefit from the ability to load an SVG to something like a QPicture, but editable, then you could navigate the heirachy in code not via byte arrays. That would give better performance…
[/quote]
I don't understand this solution very well...
To load the svg to a QPicture is possible but how do I change some tag without reloading the svg to the same QPicture...? -
You may get better performance from load if you miss out the toByteArray step... using the QXmlStreamReader construction or load option...
but actually... QXmlStreamReader isn't what i thought it was, only an xml reader, you can't edit it... what you need to be able to do (i dont know if its possible) is to pass the svg renderer the QDomDocument you have containing your svg.
My second solution was more of a pointer to the Qt Trolls, it would be useful if QPicture (or a similar class) had vector editing type functions, but it doesn't, so it wont solve your problem.
My vote is still with bitmap caching, but vector editing - if possible, is cooler.
-
I found a possible solution but I don't know how to use it...
The solution consist in using QSvgRenderer::boundsOnElement .
It seems that it's possible to render only a part of the svg identified by the Id.The step should be:
render the svg in a QImage
update the element in the original svg
render the changed part (with boundsOnElement) in the same QImage
Now I must study how to put the changed element in the same place of the background image to cover the old element.