summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-01-04 18:24:39 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2022-01-06 22:06:09 +0100
commitf1e60de66540b198d696253ab5148de4fcbff319 (patch)
treef3436cde4094eb9d881f0cfedd3d839350c45f96 /tests/auto/gui/text
parent7b4b5115ddb2d492c476942090a3fa7992e9fa7d (diff)
QTextMarkdownImporter: don't apply text char format to list item block
We want an ordered list item's number to be rendered with default char format, like the others in the same list, even if the list item's text begins with a span that has a different char format. So insert the list item's block with a default char format first, then change the char format of the cursor to suit the text that's about to be inserted. In HTML interpretation, it means the <li> does not have a style, but contains a styled span. Fixes: QTBUG-92445 Task-number: QTBUG-3583 Task-number: QTBUG-99148 Pick-to: 5.15 6.2 6.3 Change-Id: I7eb58a8d1171c16503cac01c8cce109d9f12e1af Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
Diffstat (limited to 'tests/auto/gui/text')
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
index 9b376c41f4..cce3b28bc1 100644
--- a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
@@ -211,6 +211,9 @@ void tst_QTextMarkdownImporter::lists_data()
QTest::newRow("numeric lists nested in empty lists")
<< "- \n 1. a\n 2. b\n- c\n 1.\n + d\n" << 4 << false
<< "- \n 1. a\n 2. b\n- c 1. + d\n";
+ QTest::newRow("styled spans in list items")
+ << "1. normal text\n2. **bold** text\n3. `code` in the item\n4. *italic* text\n5. _underlined_ text\n" << 5 << false
+ << "1. normal text\n2. **bold** text\n3. `code` in the item\n4. *italic* text\n5. _underlined_ text\n";
}
void tst_QTextMarkdownImporter::lists()
@@ -222,11 +225,22 @@ void tst_QTextMarkdownImporter::lists()
QTextDocument doc;
doc.setMarkdown(input); // QTBUG-78870 : don't crash
+
+#ifdef DEBUG_WRITE_HTML
+ {
+ QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".html");
+ out.open(QFile::WriteOnly);
+ out.write(doc.toHtml().toLatin1());
+ out.close();
+ }
+#endif
+
QTextFrame::iterator iterator = doc.rootFrame()->begin();
QTextFrame *currentFrame = iterator.currentFrame();
int i = 0;
int itemCount = 0;
bool emptyItems = true;
+ QString firstItemFontFamily;
while (!iterator.atEnd()) {
// There are no child frames
QCOMPARE(iterator.currentFrame(), currentFrame);
@@ -239,6 +253,21 @@ void tst_QTextMarkdownImporter::lists()
}
qCDebug(lcTests, "%d %s%s", i,
(block.textList() ? "<li>" : "<p>"), qPrintable(block.text()));
+ QTextCharFormat listItemFmt = block.charFormat();
+ QFont listItemFont = listItemFmt.font();
+ // QTextDocumentLayoutPrivate::drawListItem() uses listItemFont to render numbers in an ordered list.
+ // We want that to be consistent, regardless whether the list item's text begins with a styled span.
+ if (firstItemFontFamily.isEmpty())
+ firstItemFontFamily = listItemFont.family();
+ else
+ QCOMPARE(listItemFont.family(), firstItemFontFamily);
+ QCOMPARE(listItemFont.bold(), false);
+ QCOMPARE(listItemFont.italic(), false);
+ QCOMPARE(listItemFont.underline(), false);
+ QCOMPARE(listItemFont.fixedPitch(), false);
+ QCOMPARE(listItemFmt.fontItalic(), false);
+ QCOMPARE(listItemFmt.fontUnderline(), false);
+ QCOMPARE(listItemFmt.fontFixedPitch(), false);
++iterator;
++i;
}