Review-request: Fix copy+paste sections (bug 271029)

C. Boemann cbo at boemann.dk
Thu May 26 09:17:04 BST 2011


On Thursday 26 May 2011 02:20:35 Sebastian Sauer wrote:
> The problem is that on copy+paste text in Words we create ODF ouf of a
> fragment. That fragment can contains SectionEnd's without SectionStart's
> (or the other way around which would probably produce invalid XML? That
> case is not handled with this patch :-/ ). That results then in an assert.
> See bug 271029 for more details.
> 
> Attached patch fixes the assert with the document attached to the
> bugreport. But I am not sure if it's complete cause, as I wrote above, we
> need to take also the inverse case into account somehow and I am atm not
> sure how. Maybe we can just write endElement()'s till the styleStack
> isEmpty or so?
> 
> diff --git a/libs/kotext/opendocument/KoTextWriter.cpp
> b/libs/kotext/opendocument/KoTextWriter.cpp
> index a938aa0..b61e0d5 100644
> --- a/libs/kotext/opendocument/KoTextWriter.cpp
> +++ b/libs/kotext/opendocument/KoTextWriter.cpp
> @@ -135,6 +135,7 @@ public:
>          ,  splitEndBlockNumber(-1)
>          ,  splitRegionOpened(false)
>          ,  splitIdCounter(1)
> +        ,  sectionLevel(0)
>          ,  deleteMergeRegionOpened(false)
>          ,  deleteMergeEndBlockNumber(-1)
>      {
> @@ -208,6 +209,7 @@ public:
>      int splitEndBlockNumber;
>      bool splitRegionOpened;
>      bool splitIdCounter;
> +    int sectionLevel;
> 
>      //For saving of delete-changes that result in a merge between two
> elements
>      bool deleteMergeRegionOpened;
> @@ -1676,6 +1678,7 @@ void 
KoTextWriter::Private::writeBlocks(QTextDocument
> *document, int from, int t
>              QVariant v = format.property(KoParagraphStyle::SectionStart);
>              KoSection* section = (KoSection*)(v.value<void*>());
>              if (section) {
> +                sectionLevel++;
>                  section->saveOdf(context);
>              }
>          }
> @@ -1731,7 +1734,8 @@ void 
KoTextWriter::Private::writeBlocks(QTextDocument
> *document, int from, int t
>          if (format.hasProperty(KoParagraphStyle::SectionEnd)) {
>              QVariant v = format.property(KoParagraphStyle::SectionEnd);
>              KoSectionEnd* section = (KoSectionEnd*)(v.value<void*>());
> -            if (section) {
> +            if (section && sectionLevel >= 1) {
> +                --sectionLevel;
>                  section->saveOdf(context);
>              }
>          }
> _______________________________________________
> calligra-devel mailing list
> calligra-devel at kde.org
> https://mail.kde.org/mailman/listinfo/calligra-devel
yeah i think it's okay

though the reverse case is just as important, and can be solved by
while (sectionLevel > 0) {
    KoSectionEnd sectionEnd;
    sectionEnd.saveOdf(context);
    --sectionLevel;
}

placed at the end

We should probably place a warning inside that saveOdf method not to add any 
specifics (maybe make the method static)



More information about the calligra-devel mailing list