Fix users of QTextLayout::additionalFormats to use the new API

QTextLayout::additionalFormats setters and getters using QList<FormatRange> 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 <ritt.ks@gmail.com>
bb10
Marc Mutz 2014-02-21 15:15:29 +01:00 committed by Konstantin Ritt
parent 9eff0dd19d
commit 87d57d1994
10 changed files with 40 additions and 44 deletions

View File

@ -7441,7 +7441,7 @@ start_lengthVariant:
}
}
QList<QTextLayout::FormatRange> underlineFormats;
QVector<QTextLayout::FormatRange> 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();

View File

@ -90,13 +90,13 @@ void QSyntaxHighlighterPrivate::applyFormatChanges()
QTextLayout *layout = currentBlock.layout();
QList<QTextLayout::FormatRange> ranges = layout->additionalFormats();
QVector<QTextLayout::FormatRange> ranges = layout->formats();
const int preeditAreaStart = layout->preeditAreaPosition();
const int preeditAreaLength = layout->preeditAreaText().length();
if (preeditAreaLength != 0) {
QList<QTextLayout::FormatRange>::Iterator it = ranges.begin();
QVector<QTextLayout::FormatRange>::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;

View File

@ -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();

View File

@ -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::FormatRange> QTextLayout::formats() const
*/
void QTextLayout::clearAdditionalFormats()
{
setAdditionalFormats(QList<FormatRange>());
clearFormats();
}
/*!

View File

@ -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<FormatRange> &overrides);
QList<FormatRange> additionalFormats() const;

View File

@ -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<QTextLayout::FormatRange> formats;
QVector<QTextLayout::FormatRange> formats;
formats.append(range);
layout.setAdditionalFormats(formats);
layout.setFormats(formats);
}
setupTextLayout(&layout);

View File

@ -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<QTextLayout::FormatRange> formats;
QVector<QTextLayout::FormatRange> 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();

View File

@ -2029,7 +2029,7 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
QTextLayout *layout = block.layout();
if (isGettingInput)
layout->setPreeditArea(cursor.position() - block.position(), e->preeditString());
QList<QTextLayout::FormatRange> overrides;
QVector<QTextLayout::FormatRange> 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();
}

View File

@ -120,7 +120,7 @@ void tst_QSyntaxHighlighter::cleanup()
class TestHighlighter : public QSyntaxHighlighter
{
public:
inline TestHighlighter(const QList<QTextLayout::FormatRange> &fmts, QTextDocument *parent)
inline TestHighlighter(const QVector<QTextLayout::FormatRange> &fmts, QTextDocument *parent)
: QSyntaxHighlighter(parent), formats(fmts), highlighted(false), callCount(0) {}
inline TestHighlighter(QObject *parent)
: QSyntaxHighlighter(parent) {}
@ -138,24 +138,15 @@ public:
++callCount;
}
QList<QTextLayout::FormatRange> formats;
QVector<QTextLayout::FormatRange> 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<QTextLayout::FormatRange> formats;
QVector<QTextLayout::FormatRange> 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<QTextLayout::FormatRange> formats;
QVector<QTextLayout::FormatRange> 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<QTextLayout::FormatRange> formats;
QVector<QTextLayout::FormatRange> 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<QTextLayout::FormatRange> formats;
QVector<QTextLayout::FormatRange> formats;
QTextLayout::FormatRange range;
range.start = 0;
range.length = 10;

View File

@ -42,7 +42,7 @@
#include <QBuffer>
#include <qtest.h>
Q_DECLARE_METATYPE(QList<QTextLayout::FormatRange>)
Q_DECLARE_METATYPE(QVector<QTextLayout::FormatRange>)
class tst_QText: public QObject
{
@ -324,13 +324,13 @@ void tst_QText::layout()
void tst_QText::formattedLayout_data()
{
QTest::addColumn<QString>("text");
QTest::addColumn<QList<QTextLayout::FormatRange> >("ranges");
QTest::addColumn<QVector<QTextLayout::FormatRange> >("ranges");
QTextCharFormat format;
format.setForeground(QColor("steelblue"));
{
QList<QTextLayout::FormatRange> ranges;
QVector<QTextLayout::FormatRange> ranges;
QTextLayout::FormatRange formatRange;
formatRange.format = format;
@ -341,7 +341,7 @@ void tst_QText::formattedLayout_data()
QTest::newRow("short-single") << m_shortLorem << ranges;
}
{
QList<QTextLayout::FormatRange> ranges;
QVector<QTextLayout::FormatRange> 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<QTextLayout::FormatRange>, ranges);
QFETCH(QVector<QTextLayout::FormatRange>, ranges);
QTextLayout layout(text);
layout.setAdditionalFormats(ranges);
layout.setFormats(ranges);
setupTextLayout(&layout);
QBENCHMARK {
QTextLayout layout(text);
layout.setAdditionalFormats(ranges);
layout.setFormats(ranges);
setupTextLayout(&layout);
}
}