summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-01-10 23:03:46 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-01-22 00:22:53 +0100
commitcec7dcc723cd234c9bbb9d7df78fd96820523e87 (patch)
treec43b98312cd7fd0d44b63dfb08c4b49ca5649e03
parent13c491e6c8e9be0ec77e11fba02824acf7bb4eac (diff)
QTextDocumentLayout: handle QTextBlock visibility
Task-number: QTBUG-10153 Change-Id: I0420b9c59a7a437da28675349c14e84bfa4aea54 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/gui/text/qtextdocumentlayout.cpp6
-rw-r--r--tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp42
2 files changed, 46 insertions, 2 deletions
diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp
index a96a8e18e6..141e91c3c9 100644
--- a/src/gui/text/qtextdocumentlayout.cpp
+++ b/src/gui/text/qtextdocumentlayout.cpp
@@ -1267,7 +1267,7 @@ void QTextDocumentLayoutPrivate::drawBlock(const QPointF &offset, QPainter *pain
const QTextLayout *tl = bl.layout();
QRectF r = tl->boundingRect();
r.translate(offset + tl->position());
- if (context.clip.isValid() && (r.bottom() < context.clip.y() || r.top() > context.clip.bottom()))
+ if (!bl.isVisible() || (context.clip.isValid() && (r.bottom() < context.clip.y() || r.top() > context.clip.bottom())))
return;
// LDEBUG << debug_indent << "drawBlock" << bl.position() << "at" << offset << "br" << tl->boundingRect();
@@ -2557,6 +2557,8 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi
QTextLayoutStruct *layoutStruct, int layoutFrom, int layoutTo, const QTextBlockFormat *previousBlockFormat)
{
Q_Q(QTextDocumentLayout);
+ if (!bl.isVisible())
+ return;
QTextLayout *tl = bl.layout();
const int blockLength = bl.length();
@@ -3242,7 +3244,7 @@ QRectF QTextDocumentLayoutPrivate::frameBoundingRectInternal(QTextFrame *frame)
QRectF QTextDocumentLayout::blockBoundingRect(const QTextBlock &block) const
{
Q_D(const QTextDocumentLayout);
- if (d->docPrivate->pageSize.isNull() || !block.isValid())
+ if (d->docPrivate->pageSize.isNull() || !block.isValid() || !block.isVisible())
return QRectF();
d->ensureLayoutedByPosition(block.position() + block.length());
QTextFrame *frame = d->document->frameAt(block.position());
diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp
index e95de3df45..51e993a7d6 100644
--- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp
+++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp
@@ -67,6 +67,7 @@ private slots:
void clippedTableCell();
void floatingTablePageBreak();
void imageAtRightAlignedTab();
+ void blockVisibility();
private:
QTextDocument *doc;
@@ -312,5 +313,46 @@ void tst_QTextDocumentLayout::imageAtRightAlignedTab()
QCOMPARE(doc->idealWidth(), 300.0);
}
+void tst_QTextDocumentLayout::blockVisibility()
+{
+ QTextCursor cursor(doc);
+ for (int i = 0; i < 10; ++i) {
+ if (!doc->isEmpty())
+ cursor.insertBlock();
+ cursor.insertText(QString::number(i));
+ }
+
+ qreal margin = doc->documentMargin();
+ QSizeF emptySize(2 * margin, 2 * margin);
+ QSizeF halfSize = doc->size();
+ halfSize.rheight() -= 2 * margin;
+ halfSize.rheight() /= 2;
+ halfSize.rheight() += 2 * margin;
+
+ for (int i = 0; i < 10; i += 2) {
+ QTextBlock block = doc->findBlockByNumber(i);
+ block.setVisible(false);
+ doc->markContentsDirty(block.position(), block.length());
+ }
+
+ QCOMPARE(doc->size(), halfSize);
+
+ for (int i = 1; i < 10; i += 2) {
+ QTextBlock block = doc->findBlockByNumber(i);
+ block.setVisible(false);
+ doc->markContentsDirty(block.position(), block.length());
+ }
+
+ QCOMPARE(doc->size(), emptySize);
+
+ for (int i = 0; i < 10; i += 2) {
+ QTextBlock block = doc->findBlockByNumber(i);
+ block.setVisible(true);
+ doc->markContentsDirty(block.position(), block.length());
+ }
+
+ QCOMPARE(doc->size(), halfSize);
+}
+
QTEST_MAIN(tst_QTextDocumentLayout)
#include "tst_qtextdocumentlayout.moc"