diff options
-rw-r--r-- | src/gui/text/qtextdocument_p.cpp | 2 | ||||
-rw-r--r-- | src/gui/text/qtextformat.cpp | 17 | ||||
-rw-r--r-- | src/gui/text/qtextformat_p.h | 5 | ||||
-rw-r--r-- | tests/auto/gui/text/qtextformat/tst_qtextformat.cpp | 28 |
4 files changed, 37 insertions, 15 deletions
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 7107c7c26e..7341fa8e83 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -265,7 +265,7 @@ void QTextDocumentPrivate::clear() unreachableCharacterCount = 0; modifiedState = 0; modified = false; - formats = QTextFormatCollection(); + formats.clear(); int len = fragments.length(); fragments.clear(); blocks.clear(); diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 39fec032dc..36e0a77bd0 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -3371,22 +3371,15 @@ QTextTableCellFormat::QTextTableCellFormat(const QTextFormat &fmt) // ------------------------------------------------------ - -QTextFormatCollection::QTextFormatCollection(const QTextFormatCollection &rhs) -{ - formats = rhs.formats; - objFormats = rhs.objFormats; -} - -QTextFormatCollection &QTextFormatCollection::operator=(const QTextFormatCollection &rhs) +QTextFormatCollection::~QTextFormatCollection() { - formats = rhs.formats; - objFormats = rhs.objFormats; - return *this; } -QTextFormatCollection::~QTextFormatCollection() +void QTextFormatCollection::clear() { + formats.clear(); + objFormats.clear(); + hashes.clear(); } int QTextFormatCollection::indexForFormat(const QTextFormat &format) diff --git a/src/gui/text/qtextformat_p.h b/src/gui/text/qtextformat_p.h index f05bfaff71..3557c17a97 100644 --- a/src/gui/text/qtextformat_p.h +++ b/src/gui/text/qtextformat_p.h @@ -63,8 +63,7 @@ public: QTextFormatCollection() {} ~QTextFormatCollection(); - QTextFormatCollection(const QTextFormatCollection &rhs); - QTextFormatCollection &operator=(const QTextFormatCollection &rhs); + void clear(); inline QTextFormat objectFormat(int objectIndex) const { return format(objectFormatIndex(objectIndex)); } @@ -104,6 +103,8 @@ public: private: QFont defaultFnt; + + Q_DISABLE_COPY(QTextFormatCollection) }; QT_END_NAMESPACE 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" |