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 --- .../qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp | 31 ++++++++-------------- tests/benchmarks/gui/text/qtext/main.cpp | 14 +++++----- 2 files changed, 18 insertions(+), 27 deletions(-) (limited to 'tests') 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