aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-11-28 14:29:36 +1000
committerQt by Nokia <qt-info@nokia.com>2011-11-29 04:34:11 +0100
commit2e8059bfb80230d82bf98d7791b4dfc1d3706658 (patch)
treef5fa2314bfc8a527cf41f7986e33ed19eeb00ecf /src
parentc648598a8ba8bf72b5d556211df877578d5f5b64 (diff)
Add a length property to TextEdit.
This returns the length of the unformatted text in a TextEdit which should be cheaper to query than the length of the text property and meaningful in the context of the selection and cursor properties. Task-number: QTBUG-18949 Change-Id: Ia25c4553693923f97d299f1fdb8bfcf7f5937b13 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/items/qquicktextedit.cpp19
-rw-r--r--src/declarative/items/qquicktextedit_p.h3
2 files changed, 22 insertions, 0 deletions
diff --git a/src/declarative/items/qquicktextedit.cpp b/src/declarative/items/qquicktextedit.cpp
index 2e799200e6..51231e17de 100644
--- a/src/declarative/items/qquicktextedit.cpp
+++ b/src/declarative/items/qquicktextedit.cpp
@@ -636,6 +636,25 @@ int QQuickTextEdit::lineCount() const
}
/*!
+ \qmlproperty int QtQuick2::TextEdit::length
+
+ Returns the total number of plain text characters in the TextEdit item.
+
+ As this number doesn't include any formatting markup it may not be the same as the
+ length of the string returned by the \l text property.
+
+ This property can be faster than querying the length the \l text property as it doesn't
+ require any copying or conversion of the TextEdit's internal string data.
+*/
+
+int QQuickTextEdit::length() const
+{
+ Q_D(const QQuickTextEdit);
+ // QTextDocument::characterCount() includes the terminating null character.
+ return qMax(0, d->document->characterCount() - 1);
+}
+
+/*!
\qmlproperty real QtQuick2::TextEdit::paintedWidth
Returns the width of the text, including the width past the width
diff --git a/src/declarative/items/qquicktextedit_p.h b/src/declarative/items/qquicktextedit_p.h
index 66b68ffd85..25988959f6 100644
--- a/src/declarative/items/qquicktextedit_p.h
+++ b/src/declarative/items/qquicktextedit_p.h
@@ -73,6 +73,7 @@ class Q_AUTOTEST_EXPORT QQuickTextEdit : public QQuickImplicitSizeItem
Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
Q_PROPERTY(int lineCount READ lineCount NOTIFY lineCountChanged)
+ Q_PROPERTY(int length READ length NOTIFY textChanged)
Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
@@ -161,6 +162,8 @@ public:
int lineCount() const;
+ int length() const;
+
bool isCursorVisible() const;
void setCursorVisible(bool on);