summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-11-27 14:39:46 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-05-06 11:12:15 +0000
commit4f5c8fecaca5d875b19bc62fd8d8264f16eaedcd (patch)
tree7081fc2deb4a593e90c88fd26ecb5f475bc9447b /tests
parent7bba5a5fc5db6c339d3df4169aabe424f68fe092 (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 Change-Id: I88afba0f897aeef78d4835a3124097fe6fd4d55e Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit 72a5151403f107c445e20cf548ca2e7309c88ce7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-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 a0489e287c..b814058546 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -1716,6 +1716,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()
@@ -1730,6 +1783,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);