Test for quadratic behaviour when rendering long line in QTextEdit
QTextEdit showing long lines using lots of text format (for example with a syntax highlighter) used to expose a quadratic behaviour which make it impossible to edit files with long lines. It was fiexed in the few previous commit Task-number: QTBUG-8389 Change-Id: Ib7203497a7699a85ae1dfb70fe65d5fb36884b58 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>bb10
parent
b1e082ec9f
commit
4d5f3cf627
|
|
@ -62,6 +62,7 @@
|
|||
|
||||
#include <qabstracttextdocumentlayout.h>
|
||||
#include <qtextdocumentfragment.h>
|
||||
#include <qsyntaxhighlighter.h>
|
||||
|
||||
#include "../../../shared/platforminputcontext.h"
|
||||
#include <private/qinputmethod_p.h>
|
||||
|
|
@ -212,6 +213,8 @@ private slots:
|
|||
void inputMethodQueryImHints_data();
|
||||
void inputMethodQueryImHints();
|
||||
|
||||
void highlightLongLine();
|
||||
|
||||
private:
|
||||
void createSelection();
|
||||
int blockCount() const;
|
||||
|
|
@ -2483,5 +2486,38 @@ void tst_QTextEdit::inputMethodQueryImHints()
|
|||
QCOMPARE(static_cast<Qt::InputMethodHints>(value.toInt()), hints);
|
||||
}
|
||||
|
||||
void tst_QTextEdit::highlightLongLine()
|
||||
{
|
||||
QTextEdit edit;
|
||||
edit.setAcceptRichText(false);
|
||||
edit.setWordWrapMode(QTextOption::NoWrap);
|
||||
|
||||
QString singeLongLine;
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
singeLongLine += "0123456789";
|
||||
edit.setPlainText(singeLongLine);
|
||||
|
||||
class NumHighlighter : public QSyntaxHighlighter {
|
||||
public:
|
||||
explicit NumHighlighter(QTextDocument*doc) : QSyntaxHighlighter(doc) {};
|
||||
virtual void highlightBlock(const QString& text) {
|
||||
// odd number in bold
|
||||
QTextCharFormat format;
|
||||
format.setFontWeight(QFont::Bold);
|
||||
for (int i = 0; i < text.size(); ++i) {
|
||||
if (text.at(i).unicode() % 2)
|
||||
setFormat(i, 1, format);
|
||||
}
|
||||
}
|
||||
};
|
||||
NumHighlighter nh(edit.document());
|
||||
edit.show();
|
||||
QTest::qWaitForWindowActive(edit.windowHandle());
|
||||
QCoreApplication::processEvents();
|
||||
//If there is a quadratic behaviour, this would take forever.
|
||||
QVERIFY(true);
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(tst_QTextEdit)
|
||||
#include "tst_qtextedit.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue