[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: design discussion: caching QTextFormat for faster text loading
From:       zander () kde ! org
Date:       2010-08-16 14:06:26
Message-ID: 201008161606.26651.zander () kde ! org
[Download RAW message or body]

On Monday 16. August 2010 15.25.28 Jos van den Oever wrote:
> > Using format classes would not work as we need to be able to layer
> > styles. Specifically if you have a parag style with a child parag style
> > then the child can (but doesn't have to) override one property of the
> > parent.
> 
> Exactly, this would not work for single styles.

your 'this' naturally refers back to your suggestion to use QTextFormat 
internally in the styles.

> That is why i think we
> should  not put caching in the styles but in a different class, that takes
> layering into account. 

This is a jump that I don't follow; you jumped from my suggested solution 
which would work to your suggested solution that doesn't work and conclude 
that my suggested conclusion would therefor not work. Call me confused :)

Read my first reply to this thread again for the overview the 
paragraphStyle::apply strategy and the code snipped I pasted too for the same.  
If you try it out, I think it will become clearer.
> To construct these QTextFormat objects
> you would call Ko*Style::applyStyle(QTextFormat& format), which would add
> the styles. So:
> 
>   QTextCharFormat format;
>   d->applyStyle(format);
>   p1->applyStyle(format);
>   c1->applyStyle(format);
>   cursor.setCharFormat(format);

Notice that just calling applyStyle once on the leaf is enough. They are 
stacked internally.

> I do not understand how this works. You get the format for the block and
> then  apply it to the block.

The suggestion is to store the conversion of one known block format to another 
block format and instead of recreating it each time you just grab it from the 
cache and set it.
So the cache stores the transformation. A 'from' and a 'to'.
The code I pasted checks for a cache hit, and the hit then means we can avoid 
the slow merging and instead just use the already before calculated format and 
just set that on the block.

> Why would that be needed? It seems the block
> already has the right format.

As said, its not about setting the same, thats indeed silly. I may be blond, 
but not that blond :P

> And what happens if the block has two block
> formats? 

A block can not have more than one blockformat.

> Is this example for KoParagraphStyle or for KoCharacterStyle? I

My example is purely paragraph style. The simpler one. To avoid confusion :)

> would think this is the way to go if you want to stick to calling
> applyStyle on blocks:
> 
> applyStyle(QTextBlock &b) {
>     QTextCursor cursor(b);
>     QTextFormat f = b.blockFormat();
>     if (f.isValid()) {
>         // there is already a style, a merge is needed
>         cursor.mergeBlockFormat(d->format);
>     } else {
>         cursor.setBlockFormat(d->format);
>     }
> }

Curious; there always is a style. So this code would not really have any 
effect. And you seem to store the format on the paragraph style which I pointed 
out can't work. You seemed to agree with that before. See top of this email.

-- 
Thomas Zander
_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic