From 90b48a70ffb64d97211150fa0849dc0fa0023b7d Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 20 Feb 2017 10:55:59 +0100 Subject: QTextFormatCollection: replace copy ctor and op= with clear() operator=, which was only used for clearing, wasn't clearing the hash. This led to a mismatch between the vector and the hash (given that the hash points into the vector). Spotted by interrupting kmail in gdb, and it was in this code iterating over a 2000 entries hash (the first vector entries not matching the hash, this code keep appending new entries for the same formats). This fixes QTBUG-8862 again, the initial fix having been accidentally reverted in 467b15a. Change-Id: Ia34b3d002a0199e1930431a4bbdb2ec981ed4ffc Task-number: QTBUG-8862 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../auto/gui/text/qtextformat/tst_qtextformat.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/auto/gui') diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp index 71ee980de1..b8afd6a447 100644 --- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp +++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp @@ -60,6 +60,7 @@ private slots: void setFont(); void setFont_collection_data(); void setFont_collection(); + void clearCollection(); }; /*! \internal @@ -640,5 +641,32 @@ void tst_QTextFormat::setFont_collection() } } +void tst_QTextFormat::clearCollection() +{ + QTextFormatCollection collection; + QFont f; + f.setUnderline(true); + collection.setDefaultFont(f); + QTextCharFormat charFormat; + charFormat.setFontStyleHint(QFont::SansSerif); + int formatIndex = collection.indexForFormat(charFormat); + QCOMPARE(formatIndex, 0); + QTextCharFormat charFormat2; + charFormat2.setUnderlineStyle(QTextCharFormat::SingleUnderline); + int formatIndex2 = collection.indexForFormat(charFormat2); + QCOMPARE(formatIndex2, 1); + QCOMPARE(collection.formats.count(), 2); + QCOMPARE(collection.hashes.count(), 2); + QCOMPARE(collection.defaultFont(), f); + + collection.clear(); + QCOMPARE(collection.formats.count(), 0); + QCOMPARE(collection.hashes.count(), 0); + QCOMPARE(collection.indexForFormat(charFormat2), 0); + QCOMPARE(collection.formats.count(), 1); + QCOMPARE(collection.hashes.count(), 1); + QCOMPARE(collection.defaultFont(), f); // kept, QTextDocument::clear or setPlainText should not reset the font set by setDefaultFont +} + QTEST_MAIN(tst_QTextFormat) #include "tst_qtextformat.moc" -- cgit v1.2.3