From 87d57d19941fba4a921020480ca5761f23536c93 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 21 Feb 2014 15:15:29 +0100 Subject: Fix users of QTextLayout::additionalFormats to use the new API QTextLayout::additionalFormats setters and getters using QList have been deprecated; port to the QVector versions. Moved op== definition for FormatRange needed in tst_qsyntaxhighlighter.cpp to a friend declaration in FormatRange itself, because MSVC 2008 doesn't find it otherwise. Change-Id: Ibab6589df057f02377d895079b56395859e3401e Reviewed-by: Konstantin Ritt --- src/gui/painting/qpainter.cpp | 4 +-- src/gui/text/qsyntaxhighlighter.cpp | 8 +++--- src/gui/text/qtextdocument.cpp | 2 +- src/gui/text/qtextlayout.cpp | 4 +-- src/gui/text/qtextlayout.h | 5 ++++ src/widgets/graphicsview/qgraphicsitem.cpp | 4 +-- src/widgets/widgets/qwidgetlinecontrol.cpp | 6 ++--- src/widgets/widgets/qwidgettextcontrol.cpp | 6 ++--- .../qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp | 31 ++++++++-------------- tests/benchmarks/gui/text/qtext/main.cpp | 14 +++++----- 10 files changed, 40 insertions(+), 44 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 973c9da96c..c17ea9c878 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -7441,7 +7441,7 @@ start_lengthVariant: } } - QList underlineFormats; + QVector underlineFormats; int length = offset - old_offset; if ((hidemnmemonic || showmnemonic) && maxUnderlines > 0) { QChar *cout = text.data() + old_offset; @@ -7515,7 +7515,7 @@ start_lengthVariant: engine.forceJustification = true; QTextLayout textLayout(&engine); textLayout.setCacheEnabled(true); - textLayout.setAdditionalFormats(underlineFormats); + textLayout.setFormats(underlineFormats); if (finalText.isEmpty()) { height = fm.height(); diff --git a/src/gui/text/qsyntaxhighlighter.cpp b/src/gui/text/qsyntaxhighlighter.cpp index 162c646a98..f180a839b7 100644 --- a/src/gui/text/qsyntaxhighlighter.cpp +++ b/src/gui/text/qsyntaxhighlighter.cpp @@ -90,13 +90,13 @@ void QSyntaxHighlighterPrivate::applyFormatChanges() QTextLayout *layout = currentBlock.layout(); - QList ranges = layout->additionalFormats(); + QVector ranges = layout->formats(); const int preeditAreaStart = layout->preeditAreaPosition(); const int preeditAreaLength = layout->preeditAreaText().length(); if (preeditAreaLength != 0) { - QList::Iterator it = ranges.begin(); + QVector::Iterator it = ranges.begin(); while (it != ranges.end()) { if (it->start >= preeditAreaStart && it->start + it->length <= preeditAreaStart + preeditAreaLength) { @@ -142,7 +142,7 @@ void QSyntaxHighlighterPrivate::applyFormatChanges() } if (formatsChanged) { - layout->setAdditionalFormats(ranges); + layout->setFormats(ranges); doc->markContentsDirty(currentBlock.position(), currentBlock.length()); } } @@ -329,7 +329,7 @@ void QSyntaxHighlighter::setDocument(QTextDocument *doc) QTextCursor cursor(d->doc); cursor.beginEditBlock(); for (QTextBlock blk = d->doc->begin(); blk.isValid(); blk = blk.next()) - blk.layout()->clearAdditionalFormats(); + blk.layout()->clearFormats(); cursor.endEditBlock(); } d->doc = doc; diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index d3b70aaf26..3d248f4afc 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1949,7 +1949,7 @@ void QTextDocument::print(QPagedPaintDevice *printer) const for (QTextBlock srcBlock = firstBlock(), dstBlock = clonedDoc->firstBlock(); srcBlock.isValid() && dstBlock.isValid(); srcBlock = srcBlock.next(), dstBlock = dstBlock.next()) { - dstBlock.layout()->setAdditionalFormats(srcBlock.layout()->additionalFormats()); + dstBlock.layout()->setFormats(srcBlock.layout()->formats()); } QAbstractTextDocumentLayout *layout = doc->documentLayout(); diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index dabe06fa88..c42054c07c 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE for a specified area in the text layout's content. \inmodule QtGui - \sa QTextLayout::setAdditionalFormats(), QTextLayout::draw() + \sa QTextLayout::setFormats(), QTextLayout::draw() */ /*! @@ -541,7 +541,7 @@ QVector QTextLayout::formats() const */ void QTextLayout::clearAdditionalFormats() { - setAdditionalFormats(QList()); + clearFormats(); } /*! diff --git a/src/gui/text/qtextlayout.h b/src/gui/text/qtextlayout.h index ce092e0928..9709af4fd1 100644 --- a/src/gui/text/qtextlayout.h +++ b/src/gui/text/qtextlayout.h @@ -125,6 +125,11 @@ public: int start; int length; QTextCharFormat format; + + friend bool operator==(const FormatRange &lhs, const FormatRange &rhs) + { return lhs.start == rhs.start && lhs.length == rhs.length && lhs.format == rhs.format; } + friend bool operator!=(const FormatRange &lhs, const FormatRange &rhs) + { return !operator==(lhs, rhs); } }; void setAdditionalFormats(const QList &overrides); QList additionalFormats() const; diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index cd30410097..d0a16690e6 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -10829,9 +10829,9 @@ void QGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic range.start = 0; range.length = layout.text().length(); range.format.setTextOutline(d->pen); - QList formats; + QVector formats; formats.append(range); - layout.setAdditionalFormats(formats); + layout.setFormats(formats); } setupTextLayout(&layout); diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 759e41a5fa..3cd0277f77 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -189,7 +189,7 @@ void QWidgetLineControl::commitPreedit() m_preeditCursor = 0; setPreeditArea(-1, QString()); - m_textLayout.clearAdditionalFormats(); + m_textLayout.clearFormats(); updateDisplayText(/*force*/ true); #endif } @@ -557,7 +557,7 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event) const int oldPreeditCursor = m_preeditCursor; m_preeditCursor = event->preeditString().length(); m_hideCursor = false; - QList formats; + QVector formats; for (int i = 0; i < event->attributes().size(); ++i) { const QInputMethodEvent::Attribute &a = event->attributes().at(i); if (a.type == QInputMethodEvent::Cursor) { @@ -574,7 +574,7 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event) } } } - m_textLayout.setAdditionalFormats(formats); + m_textLayout.setFormats(formats); updateDisplayText(/*force*/ true); if (cursorPositionChanged) emitCursorPositionChanged(); diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 53b2406fc1..a46abf374d 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -2029,7 +2029,7 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) QTextLayout *layout = block.layout(); if (isGettingInput) layout->setPreeditArea(cursor.position() - block.position(), e->preeditString()); - QList overrides; + QVector overrides; const int oldPreeditCursor = preeditCursor; preeditCursor = e->preeditString().length(); hideCursor = false; @@ -2049,7 +2049,7 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) } } } - layout->setAdditionalFormats(overrides); + layout->setFormats(overrides); cursor.endEditBlock(); @@ -2878,7 +2878,7 @@ void QWidgetTextControlPrivate::commitPreedit() QTextBlock block = cursor.block(); QTextLayout *layout = block.layout(); layout->setPreeditArea(-1, QString()); - layout->clearAdditionalFormats(); + layout->clearFormats(); cursor.endEditBlock(); } diff --git a/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp b/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp index 014ed4c7c8..c0b0738e2a 100644 --- a/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp +++ b/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp @@ -120,7 +120,7 @@ void tst_QSyntaxHighlighter::cleanup() class TestHighlighter : public QSyntaxHighlighter { public: - inline TestHighlighter(const QList &fmts, QTextDocument *parent) + inline TestHighlighter(const QVector &fmts, QTextDocument *parent) : QSyntaxHighlighter(parent), formats(fmts), highlighted(false), callCount(0) {} inline TestHighlighter(QObject *parent) : QSyntaxHighlighter(parent) {} @@ -138,24 +138,15 @@ public: ++callCount; } - QList formats; + QVector formats; bool highlighted; int callCount; QString highlightedText; }; -QT_BEGIN_NAMESPACE -bool operator==(const QTextLayout::FormatRange &lhs, const QTextLayout::FormatRange &rhs) -{ - return lhs.start == rhs.start - && lhs.length == rhs.length - && lhs.format == rhs.format; -} -QT_END_NAMESPACE - void tst_QSyntaxHighlighter::basic() { - QList formats; + QVector formats; QTextLayout::FormatRange range; range.start = 0; range.length = 2; @@ -179,7 +170,7 @@ void tst_QSyntaxHighlighter::basic() QVERIFY(hl->highlighted); QVERIFY(lout->documentChangedCalled); - QVERIFY(doc->begin().layout()->additionalFormats() == formats); + QVERIFY(doc->begin().layout()->formats() == formats); } class CommentTestHighlighter : public QSyntaxHighlighter @@ -222,7 +213,7 @@ void tst_QSyntaxHighlighter::basicTwo() void tst_QSyntaxHighlighter::removeFormatsOnDelete() { - QList formats; + QVector formats; QTextLayout::FormatRange range; range.start = 0; range.length = 9; @@ -237,9 +228,9 @@ void tst_QSyntaxHighlighter::removeFormatsOnDelete() QVERIFY(lout->documentChangedCalled); lout->documentChangedCalled = false; - QVERIFY(!doc->begin().layout()->additionalFormats().isEmpty()); + QVERIFY(!doc->begin().layout()->formats().isEmpty()); delete hl; - QVERIFY(doc->begin().layout()->additionalFormats().isEmpty()); + QVERIFY(doc->begin().layout()->formats().isEmpty()); QVERIFY(lout->documentChangedCalled); } @@ -405,7 +396,7 @@ void tst_QSyntaxHighlighter::highlightToEndOfDocument2() void tst_QSyntaxHighlighter::preservePreeditArea() { - QList formats; + QVector formats; QTextLayout::FormatRange range; range.start = 0; range.length = 8; @@ -432,12 +423,12 @@ void tst_QSyntaxHighlighter::preservePreeditArea() hl->callCount = 0; cursor.beginEditBlock(); - layout->setAdditionalFormats(formats); + layout->setFormats(formats); cursor.endEditBlock(); QCOMPARE(hl->callCount, 1); - formats = layout->additionalFormats(); + formats = layout->formats(); QCOMPARE(formats.count(), 3); range = formats.at(0); @@ -483,7 +474,7 @@ void tst_QSyntaxHighlighter::avoidUnnecessaryRehighlight() void tst_QSyntaxHighlighter::noContentsChangedDuringHighlight() { - QList formats; + QVector formats; QTextLayout::FormatRange range; range.start = 0; range.length = 10; diff --git a/tests/benchmarks/gui/text/qtext/main.cpp b/tests/benchmarks/gui/text/qtext/main.cpp index 224d9619ec..f20b3f6cce 100644 --- a/tests/benchmarks/gui/text/qtext/main.cpp +++ b/tests/benchmarks/gui/text/qtext/main.cpp @@ -42,7 +42,7 @@ #include #include -Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QVector) class tst_QText: public QObject { @@ -324,13 +324,13 @@ void tst_QText::layout() void tst_QText::formattedLayout_data() { QTest::addColumn("text"); - QTest::addColumn >("ranges"); + QTest::addColumn >("ranges"); QTextCharFormat format; format.setForeground(QColor("steelblue")); { - QList ranges; + QVector ranges; QTextLayout::FormatRange formatRange; formatRange.format = format; @@ -341,7 +341,7 @@ void tst_QText::formattedLayout_data() QTest::newRow("short-single") << m_shortLorem << ranges; } { - QList ranges; + QVector ranges; QString text = m_lorem.repeated(100); const int width = 1; @@ -360,15 +360,15 @@ void tst_QText::formattedLayout_data() void tst_QText::formattedLayout() { QFETCH(QString, text); - QFETCH(QList, ranges); + QFETCH(QVector, ranges); QTextLayout layout(text); - layout.setAdditionalFormats(ranges); + layout.setFormats(ranges); setupTextLayout(&layout); QBENCHMARK { QTextLayout layout(text); - layout.setAdditionalFormats(ranges); + layout.setFormats(ranges); setupTextLayout(&layout); } } -- cgit v1.2.3