summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
diff options
context:
space:
mode:
authorSanthosh Kumar <santhosh.kumar.selvaraj@qt.io>2024-03-22 15:16:29 +0100
committerSanthosh Kumar <santhosh.kumar.selvaraj@qt.io>2024-04-18 10:57:50 +0200
commit26e75d452eeb2762fa3ece1c63e94d01587c6260 (patch)
tree1078b078a8cd80a5360246dcf04194cacc5c38ef /tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
parentade33a91442f8085a7ddeb8e6fdf33463103b119 (diff)
Support rendering CSS 'border' property for html table
We supported CSS 'border-width', 'border-style' and 'border-color' for HTML tables since 8a9bec35fb0c60a0e5990c1a12ffe6f39fdbf2d. Now we also support the 'border' property, which is shorthand to set all four borders' width, style and color. Fixes: QTBUG-123167 Pick-to: 6.7 6.6 Change-Id: I5f29b94ab9facf412a9c230d554efb5c69368b6b Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/gui/text/qtexttable/tst_qtexttable.cpp')
-rw-r--r--tests/auto/gui/text/qtexttable/tst_qtexttable.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
index 6fb5858c64..d0e1e1cd74 100644
--- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
+++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
@@ -75,6 +75,8 @@ private slots:
#endif
void checkBorderAttributes_data();
void checkBorderAttributes();
+ void checkTableBorderAttributes_data();
+ void checkTableBorderAttributes();
#ifndef QT_NO_WIDGETS
void columnWidthWithSpans();
@@ -1261,6 +1263,72 @@ void tst_QTextTable::checkBorderAttributes()
}
}
+void tst_QTextTable::checkTableBorderAttributes_data()
+{
+ QTest::addColumn<QString>("html");
+ QTest::addColumn<qreal>("tableBorderWidth");
+ QTest::addColumn<QTextFrameFormat::BorderStyle>("tableBorderStyle");
+ QTest::addColumn<QBrush>("tableBorderBrush");
+
+ const QString tableHtmlStart = QStringLiteral("<html><head><style>");
+ const QString tableHtmlEnd1 = QStringLiteral("</style></head><body>"
+ "<table><tr><td>One</td><td>Two</td></tr></table>"
+ "</body></html>");
+ const QString tableHtmlEnd2 = QStringLiteral("</style></head><body>"
+ "<table border=10><tr><td>One</td><td>Two</td></tr></table>"
+ "</body></html>");
+
+ QTest::newRow("table-border-attributes-shorthand")
+ << QString("%1"
+ "table {"
+ "border: 2px solid red;"
+ "}"
+ "%2").arg(tableHtmlStart).arg(tableHtmlEnd1)
+ << 2.0 << QTextFrameFormat::BorderStyle_Solid << QBrush(Qt::red);
+
+ QTest::newRow("table-border-attributes-explicit")
+ << QString("%1"
+ "table {"
+ "border-width: 2px;"
+ "border-color: red;"
+ "border-style: dashed;"
+ "}"
+ "%2").arg(tableHtmlStart).arg(tableHtmlEnd1)
+ << 2.0 << QTextFrameFormat::BorderStyle_Dashed << QBrush(Qt::red);
+
+ QTest::newRow("table-border-override")
+ << QString("%1"
+ "table {"
+ "border: 2px solid red;"
+ "}"
+ "%2").arg(tableHtmlStart).arg(tableHtmlEnd2)
+ << 2.0 << QTextFrameFormat::BorderStyle_Solid << QBrush(Qt::red);
+
+ QTest::newRow("table-border-default")
+ << QString("%1"
+ "%2").arg(tableHtmlStart).arg(tableHtmlEnd2)
+ << 10.0 << QTextFrameFormat::BorderStyle_Outset << QBrush(Qt::darkGray);
+}
+
+void tst_QTextTable::checkTableBorderAttributes()
+{
+ QFETCH(QString, html);
+ QFETCH(qreal, tableBorderWidth);
+ QFETCH(QTextFrameFormat::BorderStyle, tableBorderStyle);
+ QFETCH(QBrush, tableBorderBrush);
+
+ QTextDocument doc;
+ doc.setHtml(html);
+ QTextCursor cursor(doc.firstBlock());
+ cursor.movePosition(QTextCursor::Right);
+
+ QTextTable *currentTable = cursor.currentTable();
+ QVERIFY(currentTable);
+ QCOMPARE(currentTable->format().border(), tableBorderWidth);
+ QCOMPARE(currentTable->format().borderStyle(), tableBorderStyle);
+ QCOMPARE(currentTable->format().borderBrush(), tableBorderBrush);
+}
+
#ifndef QT_NO_WIDGETS
void tst_QTextTable::columnWidthWithSpans()
{