[Panel-devel] Patch to cache standard applet background background

Zack Rusin zack at kde.org
Mon Jul 30 09:06:45 CEST 2007


On Sunday 29 July 2007 05:58:28 pm Thomas Georgiou wrote:
> On Sunday 29 July 2007 03:31:38 pm Zack Rusin wrote:
> > +        if (cachedBackground || cachedBackground->size() !=
> > QSize(leftWidth + contentWidth + rightWidth, topHeight + contentHeight +
> > bottomHeight)) {
> > I don't think this part works.
> > if (pointerIsValid || invalidPointer->size() != QSize(...))
> > I guess cachedBackground is always valid.
> > +            if (!cachedBackground) {
> > +                delete cachedBackground;
> > +            }
> >
> > the "if" part is redundant. delete cachedBackground by itself is ok.
>
> This was the only way i could get it to work.  Feel free to try and fix it
> and explain to me why.

Well yeah, of course. You never initialize the cachedBackground pointer so it 
was random garbage and you recompiling with different codepaths made the 
random garbage randomly 0. 
So randomly it just happened to work in this scenario and you, randomly, 
decided that you fixed it =) 
So now maybe "deterministically" for a change, you can initialize the pointer 
and remove the silly "if" :)
(or simply have the qpixmap on the stack in the privates instead of a heap)

> > +        p2->drawPixmap(leftOffset, topOffset, *cachedBackground);
> > this part works by accident (if at all :) ).
>
> Ah, thanks, I'll end the painter next time. Feel free to do it if you want.
> Out of curiosity, what would happen if the painter was a pointer and
> deleted before it was ended?

QPainter desctructor implicitly calls end() on itself if it notices that it's 
still active so it would be ok.

z


More information about the Panel-devel mailing list