summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-11-27 14:39:46 +0100
committerAndy Shaw <andy.shaw@qt.io>2021-05-05 15:14:12 +0000
commit72a5151403f107c445e20cf548ca2e7309c88ce7 (patch)
tree5a7587af47453e9da5a02fbb917d1a4e7a0a3e4a /tests/auto/gui
parent38f4e1f3e75c4761daf0bf0473c6805e5170fb17 (diff)
Write out the HTML correctly for nested lists
When we are having nested lists then we need to ensure that the HTML is outputted correctly so that the closing list and item tags are placed in the right order. [ChangeLog][QtGui][QTextDocument] The output of toHtml() now handles nested lists correctly. Fixes: QTBUG-88374 Pick-to: 6.1 5.15 Change-Id: I88afba0f897aeef78d4835a3124097fe6fd4d55e Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 43278d4d26..281d7e7d5c 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -1717,6 +1717,59 @@ void tst_QTextDocument::toHtml_data()
<< QString("EMPTYBLOCK") +
QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blah</li></ul>");
}
+ {
+ CREATE_DOC_AND_CURSOR();
+ const QString listHtml = "<ul><li>item-1</li><li>item-2<ul><li>item-2.1</li><li>item-2.2"
+ "<ul><li>item-2.2.1</li></ul></li><li>item-2.3<ul><li>item-2.3.1"
+ "</li></ul></li></ul></li><li>item-3</li></ul>";
+ cursor.insertHtml(listHtml);
+
+ QTest::newRow("nested-lists-one") << QTextDocumentFragment(&doc)
+ << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; "
+ "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
+ "item-1</li>\n<li DEFAULTBLOCKSTYLE>item-2\n<ul DEFAULTULSTYLE 2;\"><li "
+ "DEFAULTBLOCKSTYLE>item-2.1</li>\n<li DEFAULTBLOCKSTYLE>item-2.2\n<ul "
+ "DEFAULTULSTYLE 3;\"><li DEFAULTBLOCKSTYLE>item-2.2.1</li></ul></li>\n"
+ "<li DEFAULTBLOCKSTYLE>item-2.3\n<ul DEFAULTULSTYLE 3;\"><li DEFAULTBLOCKSTYLE>"
+ "item-2.3.1</li></ul></li></ul></li>\n<li DEFAULTLASTLISTYLE>item-3</li></ul>");
+ }
+ {
+ CREATE_DOC_AND_CURSOR();
+ const QString listHtml = "<ul><li>item-1</li><li>item-2<ul><li>item-2.1</li></ul></li></ul>";
+ cursor.insertHtml(listHtml);
+
+ QTest::newRow("nested-lists-two") << QTextDocumentFragment(&doc)
+ << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; "
+ "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
+ "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\"><li "
+ "DEFAULTBLOCKSTYLE>item-2.1</li></ul></li></ul>");
+ }
+ {
+ CREATE_DOC_AND_CURSOR();
+ const QString listHtml = "<ul><li>item-1</li><li>item-2<ul><li>item-2.1</li><li>item-2.2"
+ "</li></ul></li></ul>";
+ cursor.insertHtml(listHtml);
+
+ QTest::newRow("nested-lists-three") << QTextDocumentFragment(&doc)
+ << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; "
+ "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
+ "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\"><li "
+ "DEFAULTBLOCKSTYLE>item-2.1</li>\n<li DEFAULTBLOCKSTYLE>item-2.2</li></ul>"
+ "</li></ul>");
+ }
+ {
+ CREATE_DOC_AND_CURSOR();
+ const QString listHtml = "<ul><li>item-1.1</li><li>item-1.2<li></ul>"
+ "<ul><li>item-2.1</li></ul>";
+ cursor.insertHtml(listHtml);
+
+ QTest::newRow("not-nested-list") << QTextDocumentFragment(&doc)
+ << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; "
+ "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
+ "item-1.1</li>\n<li DEFAULTBLOCKSTYLE>item-1.2</li></ul>\n<ul DEFAULTULSTYLE 1;\">"
+ "<li style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; "
+ "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">item-2.1</li></ul>");
+ }
}
void tst_QTextDocument::toHtml()
@@ -1731,6 +1784,11 @@ void tst_QTextDocument::toHtml()
expectedOutput.replace("OPENDEFAULTBLOCKSTYLE", "style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;");
expectedOutput.replace("DEFAULTBLOCKSTYLE", "style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"");
expectedOutput.replace("EMPTYBLOCK", "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p>\n");
+ expectedOutput.replace("DEFAULTULSTYLE", "style=\"margin-top: 0px; margin-bottom: 0px; "
+ "margin-left: 0px; margin-right: 0px; -qt-list-indent:");
+ expectedOutput.replace("DEFAULTLASTLISTYLE", "style=\" margin-top:0px; margin-bottom:12px; "
+ "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"");
+
if (expectedOutput.endsWith(QLatin1Char('\n')))
expectedOutput.chop(1);
expectedOutput.append(htmlTail);