summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/text/qtexttable/tst_qtexttable.cpp')
-rw-r--r--tests/auto/gui/text/qtexttable/tst_qtexttable.cpp148
1 files changed, 105 insertions, 43 deletions
diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
index 405537cc59..6fb5858c64 100644
--- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
+++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
@@ -1,35 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
-
+#include <qbuffer.h>
#include <qtextdocument.h>
#include <qtextdocumentfragment.h>
#include <qtexttable.h>
@@ -44,6 +19,7 @@
#include <QPainter>
#include <QPaintEngine>
#endif
+#include <private/qtextdocumentlayout_p.h>
#include <private/qpagedpaintdevice_p.h>
typedef QList<int> IntList;
@@ -100,6 +76,13 @@ private slots:
void checkBorderAttributes_data();
void checkBorderAttributes();
+#ifndef QT_NO_WIDGETS
+ void columnWidthWithSpans();
+
+ void columnWidthWithImage_data();
+ void columnWidthWithImage();
+#endif
+
private:
QTextTable *create2x2Table();
QTextTable *create4x4Table();
@@ -138,7 +121,7 @@ void tst_QTextTable::variousTableModifications()
QTextTableFormat tableFmt;
QTextTable *tab = cursor.insertTable(2, 2, tableFmt);
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
QCOMPARE(tab, cursor.currentTable());
QCOMPARE(tab->columns(), 2);
QCOMPARE(tab->rows(), 2);
@@ -193,14 +176,14 @@ void tst_QTextTable::variousTableModifications()
cursor.movePosition(QTextCursor::NextBlock);
QCOMPARE(cursor.position(), 1);
cursor.deleteChar();
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
cursor.movePosition(QTextCursor::NextBlock);
QCOMPARE(cursor.position(), 2);
cursor.deleteChar();
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
cursor.deletePreviousChar();
QCOMPARE(cursor.position(), 2);
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
QTextTable *table = cursor.currentTable();
QCOMPARE(table->rows(), 2);
@@ -209,16 +192,16 @@ void tst_QTextTable::variousTableModifications()
table->insertRows(2, 1);
QCOMPARE(table->rows(), 3);
QCOMPARE(table->columns(), 2);
- QCOMPARE(doc->toPlainText().length(), 7);
+ QCOMPARE(doc->toPlainText().size(), 7);
table->insertColumns(2, 2);
QCOMPARE(table->rows(), 3);
QCOMPARE(table->columns(), 4);
- QCOMPARE(doc->toPlainText().length(), 13);
+ QCOMPARE(doc->toPlainText().size(), 13);
table->resize(4, 5);
QCOMPARE(table->rows(), 4);
QCOMPARE(table->columns(), 5);
- QCOMPARE(doc->toPlainText().length(), 21);
+ QCOMPARE(doc->toPlainText().size(), 21);
}
void tst_QTextTable::tableShrinking()
@@ -226,7 +209,7 @@ void tst_QTextTable::tableShrinking()
QTextTableFormat tableFmt;
cursor.insertTable(3, 4, tableFmt);
- QCOMPARE(doc->toPlainText().length(), 13);
+ QCOMPARE(doc->toPlainText().size(), 13);
QTextTable *table = cursor.currentTable();
QCOMPARE(table->rows(), 3);
@@ -235,16 +218,16 @@ void tst_QTextTable::tableShrinking()
table->removeRows(1, 1);
QCOMPARE(table->rows(), 2);
QCOMPARE(table->columns(), 4);
- QCOMPARE(doc->toPlainText().length(), 9);
+ QCOMPARE(doc->toPlainText().size(), 9);
table->removeColumns(1, 2);
QCOMPARE(table->rows(), 2);
QCOMPARE(table->columns(), 2);
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
table->resize(1, 1);
QCOMPARE(table->rows(), 1);
QCOMPARE(table->columns(), 1);
- QCOMPARE(doc->toPlainText().length(), 2);
+ QCOMPARE(doc->toPlainText().size(), 2);
}
void tst_QTextTable::spans()
@@ -269,7 +252,7 @@ void tst_QTextTable::variousModifications2()
QTextTableFormat tableFmt;
cursor.insertTable(2, 5, tableFmt);
- QCOMPARE(doc->toPlainText().length(), 11);
+ QCOMPARE(doc->toPlainText().size(), 11);
QTextTable *table = cursor.currentTable();
QCOMPARE(cursor.position(), 1);
QCOMPARE(table->rows(), 2);
@@ -1156,7 +1139,7 @@ void tst_QTextTable::QTBUG31330_renderBackground()
cell.setFormat(cellFormat);
QTextCursor tc = cell.firstCursorPosition();
- for (int i = 0; i < 60; ++i) {
+ for (int i = 0; i < 100; ++i) {
tc.insertBlock();
}
QTBUG31330_PaintDevice::PaintEngine engine;
@@ -1165,8 +1148,8 @@ void tst_QTextTable::QTBUG31330_renderBackground()
doc.print(&paintDevice);
QVERIFY(paintDevice.pages >= 2);
- QCOMPARE(engine.rects.count(), paintDevice.pages);
- for (int i = 0; i < engine.rects.count(); ++i) {
+ QCOMPARE(engine.rects.size(), paintDevice.pages);
+ for (int i = 0; i < engine.rects.size(); ++i) {
QRectF rect = engine.rects[i];
QVERIFY(rect.top() > 0);
QVERIFY(rect.bottom() < 1000);
@@ -1278,5 +1261,84 @@ void tst_QTextTable::checkBorderAttributes()
}
}
+#ifndef QT_NO_WIDGETS
+void tst_QTextTable::columnWidthWithSpans()
+{
+ cleanup();
+ init();
+ QTextTable *table = cursor.insertTable(4, 4);
+ QTextEdit textEdit;
+ textEdit.setDocument(doc);
+ textEdit.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&textEdit));
+
+ for (int i = 0; i < table->columns(); ++i)
+ table->cellAt(0, i).firstCursorPosition().insertText(QString("Header %1").arg(i));
+
+ QTextBlock block = table->cellAt(0, 0).firstCursorPosition().block();
+ const QRectF beforeRect = table->document()->documentLayout()->blockBoundingRect(block);
+ table->mergeCells(1, 0, 1, table->columns());
+ block = table->cellAt(0, 0).firstCursorPosition().block();
+ const QRectF afterRect = table->document()->documentLayout()->blockBoundingRect(block);
+ QCOMPARE(afterRect, beforeRect);
+}
+
+void tst_QTextTable::columnWidthWithImage_data()
+{
+ const auto imageHtml = [](int width, int height) {
+ QImage image(width, height, QImage::Format_RGB32);
+ image.fill(Qt::red);
+ QByteArray imageBytes;
+ QBuffer buffer(&imageBytes);
+ buffer.open(QIODevice::WriteOnly);
+ image.save(&buffer, "png");
+ return QString("<td><img src='data:image/png;base64,%1'/></td>").arg(imageBytes.toBase64());
+ };
+
+ QTest::addColumn<QString>("leftHtml");
+ QTest::addColumn<QString>("rightHtml");
+ QTest::addColumn<QSize>("imageSize");
+ QTest::addRow("image")
+ << imageHtml(500, 32) << "<td></td>" << QSize(500, 32);
+ QTest::addRow("image, text")
+ << imageHtml(32, 32) << "<td>abc</td>" << QSize(32, 32);
+ QTest::addRow("image, 100%% text")
+ << imageHtml(32, 32) << "<td style='background-color: grey' width='100%'>abc</td>"
+ << QSize(32, 32);
+ QTest::addRow("image, image")
+ << imageHtml(256, 32) << imageHtml(256, 32) << QSize(256, 32);
+}
+
+void tst_QTextTable::columnWidthWithImage()
+{
+ const QString tableTemplate = "<table><tr>%1 %2</tr></table>";
+
+ QFETCH(QString, leftHtml);
+ QFETCH(QString, rightHtml);
+ QFETCH(QSize, imageSize);
+
+ QTextDocument doc;
+ doc.setHtml(tableTemplate.arg(leftHtml).arg(rightHtml));
+ QTextEdit textEdit;
+ textEdit.setDocument(&doc);
+ textEdit.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&textEdit));
+
+ QTextCursor cursor(doc.firstBlock());
+ cursor.movePosition(QTextCursor::Right);
+
+ QTextTable *currentTable = cursor.currentTable();
+ QVERIFY(currentTable);
+
+ QTextBlock block = currentTable->cellAt(0, 0).firstCursorPosition().block();
+ const QRectF leftRect = currentTable->document()->documentLayout()->blockBoundingRect(block);
+ block = currentTable->cellAt(0, 1).firstCursorPosition().block();
+ const QRectF rightRect = currentTable->document()->documentLayout()->blockBoundingRect(block);
+ QCOMPARE(leftRect.size().toSize(), imageSize);
+ QVERIFY(rightRect.left() > leftRect.right());
+}
+#endif
+
+
QTEST_MAIN(tst_QTextTable)
#include "tst_qtexttable.moc"