diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-06-06 15:16:59 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-12 00:18:15 +0200 |
commit | 7f526c40345a360cd0f5fa5b707c66ec4612bbec (patch) | |
tree | e5dda29a6a6e0ebfdbd10e1d368094fdce8e75cf /src | |
parent | 95aa526987a2ef536c07d2607e8fdfc21c3e9096 (diff) |
Add QQuickTextEdit::append()
This makes it possible to append text more efficiently than
appending to the text -property, and also avoids weird rich
text formatting issues with the latter approach.
Task-number: QTBUG-31575
Change-Id: Id621773588b94e36f8f0b9eb6b22590e9db62811
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquicktextedit.cpp | 39 | ||||
-rw-r--r-- | src/quick/items/qquicktextedit_p.h | 1 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 6b851903fc..92e81e06cf 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -272,6 +272,12 @@ QString QQuickTextEdit::text() const The text to display. If the text format is AutoText the text edit will automatically determine whether the text should be treated as rich text. This determination is made using Qt::mightBeRichText(). + + The text-property is mostly suitable for setting the initial content and + handling modifications to relatively small text content. The append(), + insert() and remove() methods provide more fine-grained control and + remarkably better performance for modifying especially large rich text + content. */ void QQuickTextEdit::setText(const QString &text) { @@ -2533,4 +2539,37 @@ void QQuickTextEdit::hoverLeaveEvent(QHoverEvent *event) d->control->processEvent(event, QPointF(-d->xoff, -d->yoff)); } +/*! + \qmlmethod void QtQuick2::TextEdit::append(string text) + \since QtQuick 2.2 + + Appends a new paragraph with \a text to the end of the TextEdit. + + In order to append without inserting a new paragraph, + call \c myTextEdit.insert(myTextEdit.length, text) instead. +*/ +void QQuickTextEdit::append(const QString &text) +{ + Q_D(QQuickTextEdit); + QTextCursor cursor(d->document); + cursor.beginEditBlock(); + cursor.movePosition(QTextCursor::End); + + if (!d->document->isEmpty()) + cursor.insertBlock(); + +#ifndef QT_NO_TEXTHTMLPARSER + if (d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(text))) { + cursor.insertHtml(text); + } else { + cursor.insertText(text); + } +#else + cursor.insertText(text); +#endif // QT_NO_TEXTHTMLPARSER + + cursor.endEditBlock(); + d->control->updateCursorRectangle(false); +} + QT_END_NAMESPACE diff --git a/src/quick/items/qquicktextedit_p.h b/src/quick/items/qquicktextedit_p.h index 1e038640ca..69ffad7e70 100644 --- a/src/quick/items/qquicktextedit_p.h +++ b/src/quick/items/qquicktextedit_p.h @@ -314,6 +314,7 @@ public Q_SLOTS: void redo(); void insert(int position, const QString &text); void remove(int start, int end); + Q_REVISION(2) void append(const QString &text); private Q_SLOTS: void q_textChanged(); |