From 2a1073be9c3ff1a16c489aa581ca332a914954e3 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Thu, 7 Dec 2017 19:52:52 +0300 Subject: [PATCH] Splitting has been fixed --- common.pri | 2 +- limereport/items/lrtextitem.cpp | 60 +++++++++++++-------------------- limereport/items/lrtextitem.h | 3 +- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/common.pri b/common.pri index 91c0016..5fba043 100644 --- a/common.pri +++ b/common.pri @@ -62,7 +62,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MINOR = 4 -LIMEREPORT_VERSION_RELEASE = 52 +LIMEREPORT_VERSION_RELEASE = 54 LIMEREPORT_VERSION = '\\"$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}\\"' DEFINES += LIMEREPORT_VERSION_STR=\"$${LIMEREPORT_VERSION}\" diff --git a/limereport/items/lrtextitem.cpp b/limereport/items/lrtextitem.cpp index 09c8988..8c01e87 100644 --- a/limereport/items/lrtextitem.cpp +++ b/limereport/items/lrtextitem.cpp @@ -777,50 +777,39 @@ bool TextItem::canBeSplitted(int height) const return height > m_firstLineSize; } -QString TextItem::getTextPart(int height, int skipHeight){ - int linesHeight = 0; +QString TextItem::extractText(QTextBlock& curBlock, int height){ int curLine = 0; -// int textPos = 0; + int linesHeight = 0; + QString resultText; + for (;curBlock != curBlock.document()->end() || curLine<=curBlock.lineCount(); curBlock = curBlock.next(), curLine = 0, resultText += '\n' ){ + linesHeight+=curBlock.blockFormat().topMargin(); + for (;curLine < curBlock.layout()->lineCount(); curLine++){ + linesHeight += curBlock.layout()->lineAt(curLine).height() + lineSpacing(); + if (height > 0 && linesHeight > (height-borderLineSize() * 2)) {goto loop_exit;} + resultText += curBlock.text().mid(curBlock.layout()->lineAt(curLine).textStart(), + curBlock.layout()->lineAt(curLine).textLength()); + } + } + loop_exit: return resultText; +} +QString TextItem::getTextPart(int height, int skipHeight){ + + QString resultText = ""; TextPtr text = textDocument(); text->size().height(); + QTextBlock curBlock = text->begin(); QTextCursor cursor(text.data()); cursor.movePosition(QTextCursor::Start); - QTextBlock curBlock = text->begin(); - QString resultText = ""; if (skipHeight > 0){ - for (;curBlock != text->end() || curLine<=curBlock.lineCount(); curBlock = curBlock.next(), curLine = 0){ - linesHeight+=curBlock.blockFormat().topMargin(); - for (;curLine < curBlock.layout()->lineCount(); curLine++){ - linesHeight += curBlock.layout()->lineAt(curLine).rect().height() + lineSpacing(); - if (linesHeight > (skipHeight-(/*fakeMarginSize()*2+*/borderLineSize() * 2))) {goto loop_exit;} - cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, curBlock.layout()->lineAt(curLine).textLength()); - } - } - loop_exit: cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::MoveAnchor); + resultText = extractText(curBlock, skipHeight); + cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, resultText.length()); } - linesHeight = 0; + resultText = extractText(curBlock, height); + cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, resultText.length()); - for (;curBlock != text->end() || curLinelineCount(); curLine++){ -// if (resultText == "") textPos = curBlock.layout()->lineAt(curLine).textStart(); - linesHeight += curBlock.layout()->lineAt(curLine).height() + lineSpacing(); - if ( (height>0) && (linesHeight>(height-(/*fakeMarginSize()*2+*/borderLineSize()*2))) ) { - linesHeight-=curBlock.layout()->lineAt(curLine).height(); - goto loop_exit1; - } -// QString fragment = curBlock.text().mid(curBlock.layout()->lineAt(curLine).textStart(), -// curBlock.layout()->lineAt(curLine).textLength()); -// resultText+=fragment; - cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, curBlock.layout()->lineAt(curLine).textLength()); - } - } - loop_exit1:; - cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); if (allowHTML()){ resultText = cursor.selection().toHtml(); resultText.remove(""); @@ -829,10 +818,7 @@ QString TextItem::getTextPart(int height, int skipHeight){ resultText = cursor.selection().toPlainText(); } -// resultText.chop(1); - -// QScopedPointer context(new HtmlContext(m_strText)); - return resultText;//context->extendTextByTags(resultText,textPos); + return resultText; } void TextItem::restoreLinksEvent() diff --git a/limereport/items/lrtextitem.h b/limereport/items/lrtextitem.h index 6dc735b..f743d3d 100644 --- a/limereport/items/lrtextitem.h +++ b/limereport/items/lrtextitem.h @@ -181,7 +181,7 @@ private: QString formatDateTime(const QDateTime &value); QString formatNumber(const double value); QString formatFieldValue(); - + QString extractText(QTextBlock& curBlock, int height); TextPtr textDocument() const; private: QString m_strText; @@ -208,6 +208,7 @@ private: TextItem* m_follower; qreal m_textIndent; Qt::LayoutDirection m_textLayoutDirection; + }; }