Browse Source

fix: iterate all blocks

refactor: block iteration loop

refactor: replaced checks with chop()
pull/4239/head
ezavod 9 years ago
parent
commit
7a5c5a86fd
  1. 49
      src/chatlog/content/text.cpp

49
src/chatlog/content/text.cpp

@ -337,32 +337,39 @@ QString Text::extractSanitizedText(int from, int to) const
return ""; return "";
QString txt; QString txt;
QTextBlock block = doc->firstBlock();
for (QTextBlock::Iterator itr = block.begin(); itr != block.end(); ++itr) { QTextBlock begin = doc->findBlock(from);
int pos = QTextBlock end = doc->findBlock(to);
itr.fragment() for (QTextBlock block = begin; block != end.next() && block.isValid(); block = block.next()) {
.position(); // fragment position -> position of the first character in the fragment for (QTextBlock::Iterator itr = block.begin(); itr != block.end(); ++itr) {
int pos =
if (itr.fragment().charFormat().isImageFormat()) { itr.fragment()
QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat(); .position(); // fragment position -> position of the first character in the fragment
QString key = imgFmt.name(); // img key (eg. key::D for :D)
QString rune = key.mid(4); if (itr.fragment().charFormat().isImageFormat()) {
QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat();
if (pos >= from && pos < to) { QString key = imgFmt.name(); // img key (eg. key::D for :D)
txt += rune; QString rune = key.mid(4);
++pos;
} if (pos >= from && pos < to) {
} else { txt += rune;
for (QChar c : itr.fragment().text()) { ++pos;
if (pos >= from && pos < to) }
txt += c; } else {
for (QChar c : itr.fragment().text()) {
++pos; if (pos >= from && pos < to)
txt += c;
++pos;
}
} }
} }
txt += '\n';
} }
txt.chop(1);
return txt; return txt;
} }

Loading…
Cancel
Save