PDA

View Full Version : SVG suggestion



Gopala Krishna
19th October 2007, 20:18
Hello,
I am switching to svg in my app but before that i have some clarifications to be cleared.

Basically i have lots of items on scene arranged as per the required circuit. If i inherit the classes corresponding to these items from QGraphicsSvgItem now, each item inturn inherits QObject - so more bulkier the items become. I don't want this sideeffect.
So i thought of rendering the items using QSvgRenderer on my own. Now here goes my doubts

1) Is it necessary to update the item on QSvgRenderer's repaintNeeded() signal for static(no animation i mean) items ?

2) Should i use different renderers for each type of item or just use a single renderer to render all types of items ?

3) When should i update cache ? (for eg should i update when i do any transformation on item)

marcel
19th October 2007, 21:13
1. No, for static svg items you don't need that signal.
2. I have one word for you(well, maybe two): QGraphicsSVGItem::setSharedRenderer()
3. What cache would be that?

Gopala Krishna
19th October 2007, 21:51
1. No, for static svg items you don't need that signal.

Ok. Infact the code corresponding to QGraphicsSvgItem::setSharedRenderer() doesn't connect the signal at all while it is so done in the constructor! :eek: Is it a bug ?



2. I have one word for you(well, maybe two): QGraphicsSVGItem::setSharedRenderer()

I don't want to use QGraphicsSvgItem at all :) But what i mean to say is, should i have separate renderer's for resistors(shared for all resistors), capacitors.. or all of them in one. Does it make any big difference ?



3. What cache would be that?
Sorry, i didn't clearly state that. By cache i meant QPixmapCache to cache the svg so that i don't need to render everytime. I had a look at the code of QGraphicsSvgItem but i am not sure when am i supposed to update cache ? When exactly should i dirty and reload to cache ?

Gopala Krishna
20th October 2007, 14:57
How can i use level of detail flag while rendering svg items ? Can someone help me when to do what at what ratios for level of details ?

marcel
20th October 2007, 15:14
You'll have to sublcass QGraphicsSvgItem and override paint. Modify the levelofdetail form the style option and call the base class version of paint(the one from QGraphicsSvgItem) with the modified style option.

I don't really know what effects has the level of detail in practice, but you can play with it and find out.

Gopala Krishna
20th October 2007, 15:35
http://labs.trolltech.com/page/Projects/DevDays/DevDays2007
The GraphicsView presentation is really great and gives some info on how you can use level of detail(in optimization section)
My question is what to draw when the level of detail is very less ? In the example the code is as follows


void MyItem::paint(QPainter *painter, const QStyleOption...
{
int lod = option->levelOfDetail;
if (lod >= 1) {
// 1:1 or closer
painter->drawRoundRect(0, 0, 100, 100);
} else if (lod >= 0.5) {
// 1:2 to 1:1
painter->drawRect(0, 0, 100, 100);
} else if (lod >= 0.25) {
// 1:4 to 1:2
painter->fillRect(0, 0, 100, 100);
} else {
// Don't draw at all
}
}