summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextobject.cpp
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2014-01-30 01:59:00 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-30 12:43:33 +0100
commit2e1609f3e399ac6be91266a27e7e436ab07ae3df (patch)
tree26b56649c52f9d51012973b285365e4d79ae68fb /src/gui/text/qtextobject.cpp
parentd8225fab8fb8b21fb5d35968d9edb5340b76bcc2 (diff)
Introduce QTextBlock::textFormats()
A convenient way to obtain the block format ranges that should be applied to the block text. Change-Id: I220429b7c9c592c4880357c0d7b1b21f6c1c11f3 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/gui/text/qtextobject.cpp')
-rw-r--r--src/gui/text/qtextobject.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/gui/text/qtextobject.cpp b/src/gui/text/qtextobject.cpp
index d1a39c6ab6..bd1e970583 100644
--- a/src/gui/text/qtextobject.cpp
+++ b/src/gui/text/qtextobject.cpp
@@ -1233,6 +1233,56 @@ QString QTextBlock::text() const
return text;
}
+/*!
+ \since 5.3
+
+ Returns the block's text format options as a list of continuous ranges
+ of QTextCharFormat. The range's character format is used when inserting text
+ within the range boundaries.
+
+ \sa charFormat(), blockFormat()
+*/
+QList<QTextLayout::FormatRange> QTextBlock::textFormats() const
+{
+ QList<QTextLayout::FormatRange> formats;
+ if (!p || !n)
+ return formats;
+
+ const QTextFormatCollection *formatCollection = p->formatCollection();
+
+ int start = 0;
+ int cur = start;
+ int format = -1;
+
+ const int pos = position();
+ QTextDocumentPrivate::FragmentIterator it = p->find(pos);
+ QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1); // -1 to omit the block separator char
+ for (; it != end; ++it) {
+ const QTextFragmentData * const frag = it.value();
+ if (format != it.value()->format) {
+ if (cur - start > 0) {
+ QTextLayout::FormatRange range;
+ range.start = start;
+ range.length = cur - start;
+ range.format = formatCollection->charFormat(format);
+ formats.append(range);
+ }
+
+ format = frag->format;
+ start = cur;
+ }
+ cur += frag->size_array[0];
+ }
+ if (cur - start > 0) {
+ QTextLayout::FormatRange range;
+ range.start = start;
+ range.length = cur - start;
+ range.format = formatCollection->charFormat(format);
+ formats.append(range);
+ }
+
+ return formats;
+}
/*!
Returns the text document this text block belongs to, or 0 if the