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>
This commit is contained in:
J-P Nurmi 2015-01-10 23:03:46 +01:00
parent 13c491e6c8
commit cec7dcc723
2 changed files with 46 additions and 2 deletions

View File

@ -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());

View File

@ -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"