Question about loading and default list/bib/ToC styles

Elvis Stansvik elvstone at gmail.com
Tue May 28 10:25:40 BST 2013


2013/5/28 Gopalakrishna Bhat <gopalakbhat at gmail.com>

>
>
>
> On Tue, May 28, 2013 at 8:56 AM, Thorsten Zachmann <t.zachmann at zagge.de>wrote:
>
>> On Monday 27 May 2013 21:19:56 Elvis Stansvik wrote:
>> > Hi all,
>> >
>> > Currently trying to track down a bug and realized I'm a little unsure
>> about
>> > something.
>> >
>> > The style manager creates a bunch of default list/bibliography/ToC
>> styles
>> > upon construction. What should we do if, during loading, we encounter a
>> > style who's name clashes with one of these default styles?
>> >
>> > Intuitively I think we should replace the default style with the one
>> found
>> > in the ODT, but since the code doesn't seem to do this currently, I
>> thought
>> > I'd ask.
>>
>> I think so too. Maybe rename the one found in the defaults.
>>
> +1 to this but there is a catch here. If we do it this way there will be
> more default styles that is created on each roundtrip
> viz
> DefaultStyle
> DefaultStyle_Save1
> DefaultStyle_Save2.....
> which is unused.
>
> What we could do is save the DefaultStyle only if it used in the document.
>
>

Right. But that would not help with documents already out there, or
documents not produced by us.

What Camilla suggested to me on IRC, and which I think sounds sensible, is
to make the creation of the default styles happen lazily.

If I understand her right, instead of the style manager creating the
default ToC/bibliography styles in its constructor, it would be given an
API like:

/**
 * Returns a table of contents entry style for the given @a outlineLevel.
 *
 * If there's no such style in the manager, a default one will be created
and returned.
 */
KoParagraphStyle *tableOfContentsEntryStyle(int outlineLevel);

/**
 * Returns a bibliography entry style for the given @a bibliographyType.
 *
 * If there's no such style in the manager, a default one will be created
and returned.
 */
KoParagraphStyle *bibliographyEntryStyle(const QString &bibliographyType);

As en example, the first one would be something like:

KoParagraphStyle *KoStyleManager::tableOfContentsEntryStyle(int
outlineLevel) {
    ParagraphStyle *tocStyle = paragraphStyle(QString("Contents
%1").arg(outlineLevel));
    if (!tocStyle) {
        tocStyle = new KoParagraphStyle();
        tocStyle->setName(QString("Contents %1").arg(outlineLevel));
        tocStyle->setLeftMargin(QTextLength(QTextLength::FixedLength,
(outlineLevel - 1) * 8));
        add(tocStyle);
    }
    return tocStyle;
}

And the code that uses the existing defaultTableOfContentsEntryStyle(int)/
defaultBibliographyEntryStyle(QString) API would then be updated to use the
new API. From a brief search, this seems to be ToCGenerator,
TableOfContentsEntryModel, TableOfContentsTemplate, BibliographyGenerator
and BibliographyTemplate.

Was this what you had in mind Camilla? What do others think?

Then the default styles would not be in the manager at loading time, so no
clash would occur. And if the ODF has styles named e.g. "Contents N", they
would be the ones picked up.

Regards,
Elvis


>> Thorsten
>> _______________________________________________
>> calligra-devel mailing list
>> calligra-devel at kde.org
>> https://mail.kde.org/mailman/listinfo/calligra-devel
>>
>
> With regards,
> Gopalakrishna
>
> --
> My blog http://gkbhat.blogspot.com
>
> _______________________________________________
> calligra-devel mailing list
> calligra-devel at kde.org
> https://mail.kde.org/mailman/listinfo/calligra-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/calligra-devel/attachments/20130528/56be87f7/attachment.htm>


More information about the calligra-devel mailing list