fix KoTextWriter::saveParagraph(...) to not crash on QTextDocuments without a KoTextRangeManager

REVIEW: 108868

BUG: 314676

thanks boemann for review
parent 854d29ef
......@@ -747,13 +747,15 @@ void KoTextWriter::Private::saveParagraph(const QTextBlock &block, int from, int
inlineRdf->saveOdf(context, writer, xmlid);
}
const KoTextRangeManager *mgr = KoTextDocument(block.document()).textRangeManager();
const KoTextRangeManager *textRangeManager = KoTextDocument(block.document()).textRangeManager();
// write tags for ranges which end at the first position of the block
const QHash<int, KoTextRange *> endingTextRangesAtStart =
mgr->textRangesChangingWithin(block.position(), block.position(), globalFrom, globalTo);
foreach (const KoTextRange *range, endingTextRangesAtStart) {
range->saveOdf(context, block.position(), KoTextRange::EndTag);
if (textRangeManager) {
// write tags for ranges which end at the first position of the block
const QHash<int, KoTextRange *> endingTextRangesAtStart =
textRangeManager->textRangesChangingWithin(block.position(), block.position(), globalFrom, globalTo);
foreach (const KoTextRange *range, endingTextRangesAtStart) {
range->saveOdf(context, block.position(), KoTextRange::EndTag);
}
}
QString previousFragmentLink;
......@@ -834,9 +836,10 @@ void KoTextWriter::Private::saveParagraph(const QTextBlock &block, int from, int
// get all text ranges which start before this inline object
// or end directly after it (+1 to last position for that)
const QHash<int, KoTextRange *> textRanges =
mgr->textRangesChangingWithin(currentFragment.position(), currentFragment.position()+1,
globalFrom, (globalTo==-1)?-1:globalTo+1);
const QHash<int, KoTextRange *> textRanges = textRangeManager ?
textRangeManager->textRangesChangingWithin(currentFragment.position(), currentFragment.position()+1,
globalFrom, (globalTo==-1)?-1:globalTo+1) :
QHash<int, KoTextRange *>();
// get all text ranges which start before this
const QList<KoTextRange *> textRangesBefore = textRanges.values(currentFragment.position());
// write tags for ranges which start before this content or at positioned at it
......@@ -907,7 +910,9 @@ void KoTextWriter::Private::saveParagraph(const QTextBlock &block, int from, int
int spanTo = to == -1 ? fragmentEnd : (fragmentEnd > to ? to : fragmentEnd);
// get all text ranges which change within this span
// or end directly after it (+1 to last position to include those)
const QHash<int, KoTextRange *> textRanges = mgr->textRangesChangingWithin(spanFrom, spanTo, globalFrom, (globalTo==-1)?-1:globalTo+1);
const QHash<int, KoTextRange *> textRanges = textRangeManager ?
textRangeManager->textRangesChangingWithin(spanFrom, spanTo, globalFrom, (globalTo==-1)?-1:globalTo+1) :
QHash<int, KoTextRange *>();
// avoid mid, if possible
if (spanFrom != fragmentStart || spanTo != fragmentEnd || !textRanges.isEmpty()) {
if (textRanges.isEmpty()) {
......@@ -961,11 +966,11 @@ void KoTextWriter::Private::saveParagraph(const QTextBlock &block, int from, int
writer->endElement();
}
if (it.atEnd() && ((to == -1) || (lastEndPosition <= to))) {
if (it.atEnd() && textRangeManager && ((to == -1) || (lastEndPosition <= to))) {
// write tags for ranges which start at the last position of the block,
// i.e. at the position after the last (text) fragment
const QHash<int, KoTextRange *> startingTextRangesAtEnd =
mgr->textRangesChangingWithin(lastEndPosition, lastEndPosition, globalFrom, globalTo);
textRangeManager->textRangesChangingWithin(lastEndPosition, lastEndPosition, globalFrom, globalTo);
foreach (const KoTextRange *range, startingTextRangesAtEnd) {
range->saveOdf(context, lastEndPosition, KoTextRange::StartTag);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment