Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquicktextnode.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | namespace { | - | ||||||
9 | - | |||||||
10 | class ProtectedLayoutAccessor: public QAbstractTextDocumentLayout | - | ||||||
11 | { | - | ||||||
12 | public: | - | ||||||
13 | inline QTextCharFormat formatAccessor(int pos) | - | ||||||
14 | { | - | ||||||
15 | return never executed: format(pos);return format(pos); never executed: return format(pos); | 0 | ||||||
16 | } | - | ||||||
17 | }; | - | ||||||
18 | - | |||||||
19 | } | - | ||||||
20 | - | |||||||
21 | - | |||||||
22 | - | |||||||
23 | - | |||||||
24 | QQuickTextNode::QQuickTextNode(QQuickItem *ownerElement) | - | ||||||
25 | : m_cursorNode(nullptr), m_ownerElement(ownerElement), m_useNativeRenderer(false) | - | ||||||
26 | { | - | ||||||
27 | - | |||||||
28 | qsgnode_set_description(this, QLatin1String("text")); | - | ||||||
29 | - | |||||||
30 | } executed 175001 times by 24 tests: end of block Executed by:
| 175001 | ||||||
31 | - | |||||||
32 | QQuickTextNode::~QQuickTextNode() | - | ||||||
33 | { | - | ||||||
34 | qDeleteAll(m_textures); | - | ||||||
35 | } executed 175001 times by 24 tests: end of block Executed by:
| 175001 | ||||||
36 | - | |||||||
37 | QSGGlyphNode *QQuickTextNode::addGlyphs(const QPointF &position, const QGlyphRun &glyphs, const QColor &color, | - | ||||||
38 | QQuickText::TextStyle style, const QColor &styleColor, | - | ||||||
39 | QSGNode *parentNode) | - | ||||||
40 | { | - | ||||||
41 | QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext(); | - | ||||||
42 | QRawFont font = glyphs.rawFont(); | - | ||||||
43 | bool preferNativeGlyphNode = m_useNativeRenderer; | - | ||||||
44 | if (!preferNativeGlyphNode
| 72-249131 | ||||||
45 | QRawFontPrivate *fontPriv = QRawFontPrivate::get(font); | - | ||||||
46 | if (fontPriv->fontEngine->hasUnreliableGlyphOutline()
| 0-249131 | ||||||
47 | preferNativeGlyphNode = true; | - | ||||||
48 | } never executed: else {end of block | 0 | ||||||
49 | QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine; | - | ||||||
50 | preferNativeGlyphNode = !fe->isSmoothlyScalable; | - | ||||||
51 | } executed 249131 times by 24 tests: end of block Executed by:
| 249131 | ||||||
52 | } | - | ||||||
53 | - | |||||||
54 | QSGGlyphNode *node = sg->sceneGraphContext()->createGlyphNode(sg, preferNativeGlyphNode); | - | ||||||
55 | - | |||||||
56 | node->setOwnerElement(m_ownerElement); | - | ||||||
57 | node->setGlyphs(position + QPointF(0, glyphs.rawFont().ascent()), glyphs); | - | ||||||
58 | node->setStyle(style); | - | ||||||
59 | node->setStyleColor(styleColor); | - | ||||||
60 | node->setColor(color); | - | ||||||
61 | node->update(); | - | ||||||
62 | - | |||||||
63 | - | |||||||
64 | - | |||||||
65 | - | |||||||
66 | - | |||||||
67 | - | |||||||
68 | - | |||||||
69 | node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern); | - | ||||||
70 | node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern); | - | ||||||
71 | - | |||||||
72 | if (parentNode == nullptr
| 108-249095 | ||||||
73 | parentNode = this; executed 249095 times by 24 tests: parentNode = this; Executed by:
| 249095 | ||||||
74 | parentNode->appendChildNode(node); | - | ||||||
75 | - | |||||||
76 | return executed 249203 times by 24 tests: node;return node; Executed by:
executed 249203 times by 24 tests: return node; Executed by:
| 249203 | ||||||
77 | } | - | ||||||
78 | - | |||||||
79 | void QQuickTextNode::setCursor(const QRectF &rect, const QColor &color) | - | ||||||
80 | { | - | ||||||
81 | if (m_cursorNode != nullptr
| 0-66 | ||||||
82 | delete m_cursorNode; never executed: delete m_cursorNode; | 0 | ||||||
83 | - | |||||||
84 | QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext(); | - | ||||||
85 | m_cursorNode = sg->sceneGraphContext()->createInternalRectangleNode(rect, color); | - | ||||||
86 | appendChildNode(m_cursorNode); | - | ||||||
87 | } executed 66 times by 4 tests: end of block Executed by:
| 66 | ||||||
88 | - | |||||||
89 | void QQuickTextNode::clearCursor() | - | ||||||
90 | { | - | ||||||
91 | if (m_cursorNode
| 6-54 | ||||||
92 | removeChildNode(m_cursorNode); executed 6 times by 2 tests: removeChildNode(m_cursorNode); Executed by:
| 6 | ||||||
93 | delete m_cursorNode; | - | ||||||
94 | m_cursorNode = nullptr; | - | ||||||
95 | } executed 60 times by 2 tests: end of block Executed by:
| 60 | ||||||
96 | - | |||||||
97 | void QQuickTextNode::addRectangleNode(const QRectF &rect, const QColor &color) | - | ||||||
98 | { | - | ||||||
99 | QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext(); | - | ||||||
100 | appendChildNode(sg->sceneGraphContext()->createInternalRectangleNode(rect, color)); | - | ||||||
101 | } executed 98 times by 4 tests: end of block Executed by:
| 98 | ||||||
102 | - | |||||||
103 | - | |||||||
104 | void QQuickTextNode::addImage(const QRectF &rect, const QImage &image) | - | ||||||
105 | { | - | ||||||
106 | QSGRenderContext *sg = QQuickItemPrivate::get(m_ownerElement)->sceneGraphRenderContext(); | - | ||||||
107 | QSGInternalImageNode *node = sg->sceneGraphContext()->createInternalImageNode(); | - | ||||||
108 | QSGTexture *texture = sg->createTexture(image); | - | ||||||
109 | if (m_ownerElement->smooth()
| 0-30 | ||||||
110 | texture->setFiltering(QSGTexture::Linear); executed 30 times by 2 tests: texture->setFiltering(QSGTexture::Linear); Executed by:
| 30 | ||||||
111 | m_textures.append(texture); | - | ||||||
112 | node->setTargetRect(rect); | - | ||||||
113 | node->setInnerTargetRect(rect); | - | ||||||
114 | node->setTexture(texture); | - | ||||||
115 | if (m_ownerElement->smooth()
| 0-30 | ||||||
116 | node->setFiltering(QSGTexture::Linear); executed 30 times by 2 tests: node->setFiltering(QSGTexture::Linear); Executed by:
| 30 | ||||||
117 | appendChildNode(node); | - | ||||||
118 | node->update(); | - | ||||||
119 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||
120 | - | |||||||
121 | void QQuickTextNode::addTextDocument(const QPointF &position, QTextDocument *textDocument, | - | ||||||
122 | const QColor &textColor, | - | ||||||
123 | QQuickText::TextStyle style, const QColor &styleColor, | - | ||||||
124 | const QColor &anchorColor, | - | ||||||
125 | const QColor &selectionColor, const QColor &selectedTextColor, | - | ||||||
126 | int selectionStart, int selectionEnd) | - | ||||||
127 | { | - | ||||||
128 | QQuickTextNodeEngine engine; | - | ||||||
129 | engine.setTextColor(textColor); | - | ||||||
130 | engine.setSelectedTextColor(selectedTextColor); | - | ||||||
131 | engine.setSelectionColor(selectionColor); | - | ||||||
132 | engine.setAnchorColor(anchorColor); | - | ||||||
133 | engine.setPosition(position); | - | ||||||
134 | - | |||||||
135 | QList<QTextFrame *> frames; | - | ||||||
136 | frames.append(textDocument->rootFrame()); | - | ||||||
137 | while (!frames.isEmpty()
| 84-90 | ||||||
138 | QTextFrame *textFrame = frames.takeFirst(); | - | ||||||
139 | frames.append(textFrame->childFrames()); | - | ||||||
140 | - | |||||||
141 | engine.addFrameDecorations(textDocument, textFrame); | - | ||||||
142 | - | |||||||
143 | if (textFrame->firstPosition() > textFrame->lastPosition()
| 6-84 | ||||||
144 | && textFrame->frameFormat().position() != QTextFrameFormat::InFlow
| 0-6 | ||||||
145 | const int pos = textFrame->firstPosition() - 1; | - | ||||||
146 | ProtectedLayoutAccessor *a = static_cast<ProtectedLayoutAccessor *>(textDocument->documentLayout()); | - | ||||||
147 | QTextCharFormat format = a->formatAccessor(pos); | - | ||||||
148 | QRectF rect = a->frameBoundingRect(textFrame); | - | ||||||
149 | - | |||||||
150 | QTextBlock block = textFrame->firstCursorPosition().block(); | - | ||||||
151 | engine.setCurrentLine(block.layout()->lineForTextPosition(pos - block.position())); | - | ||||||
152 | engine.addTextObject(rect.topLeft(), format, QQuickTextNodeEngine::Unselected, textDocument, | - | ||||||
153 | pos, textFrame->frameFormat().position()); | - | ||||||
154 | } never executed: else {end of block | 0 | ||||||
155 | QTextFrame::iterator it = textFrame->begin(); | - | ||||||
156 | - | |||||||
157 | while (!it.atEnd()
| 90-108 | ||||||
158 | ((!engine.currentLine().isValid()) ? static_cast<void>(0) : qt_assert("!engine.currentLine().isValid()", __FILE__, 214)); | - | ||||||
159 | - | |||||||
160 | QTextBlock block = it.currentBlock(); | - | ||||||
161 | engine.addTextBlock(textDocument, block, position, textColor, anchorColor, selectionStart, selectionEnd); | - | ||||||
162 | ++it; | - | ||||||
163 | } executed 108 times by 2 tests: end of block Executed by:
| 108 | ||||||
164 | } executed 90 times by 2 tests: end of block Executed by:
| 90 | ||||||
165 | } | - | ||||||
166 | - | |||||||
167 | engine.addToSceneGraph(this, style, styleColor); | - | ||||||
168 | } executed 84 times by 2 tests: end of block Executed by:
| 84 | ||||||
169 | - | |||||||
170 | void QQuickTextNode::addTextLayout(const QPointF &position, QTextLayout *textLayout, const QColor &color, | - | ||||||
171 | QQuickText::TextStyle style, const QColor &styleColor, | - | ||||||
172 | const QColor &anchorColor, | - | ||||||
173 | const QColor &selectionColor, const QColor &selectedTextColor, | - | ||||||
174 | int selectionStart, int selectionEnd, | - | ||||||
175 | int lineStart, int lineCount) | - | ||||||
176 | { | - | ||||||
177 | QQuickTextNodeEngine engine; | - | ||||||
178 | engine.setTextColor(color); | - | ||||||
179 | engine.setSelectedTextColor(selectedTextColor); | - | ||||||
180 | engine.setSelectionColor(selectionColor); | - | ||||||
181 | engine.setAnchorColor(anchorColor); | - | ||||||
182 | engine.setPosition(position); | - | ||||||
183 | - | |||||||
184 | - | |||||||
185 | int preeditLength = textLayout->preeditAreaText().length(); | - | ||||||
186 | int preeditPosition = textLayout->preeditAreaPosition(); | - | ||||||
187 | - | |||||||
188 | - | |||||||
189 | QVarLengthArray<QTextLayout::FormatRange> colorChanges; | - | ||||||
190 | engine.mergeFormats(textLayout, &colorChanges); | - | ||||||
191 | - | |||||||
192 | lineCount = lineCount >= 0
| 171-248272 | ||||||
193 | ? qMin(lineStart + lineCount, textLayout->lineCount()) | - | ||||||
194 | : textLayout->lineCount(); | - | ||||||
195 | - | |||||||
196 | for (int i=lineStart; i<lineCount
| 248443-249990 | ||||||
197 | QTextLine line = textLayout->lineAt(i); | - | ||||||
198 | - | |||||||
199 | int start = line.textStart(); | - | ||||||
200 | int length = line.textLength(); | - | ||||||
201 | int end = start + length; | - | ||||||
202 | - | |||||||
203 | - | |||||||
204 | if (preeditPosition >= 0
| 2-249988 | ||||||
205 | && preeditPosition >= start
| 0-2 | ||||||
206 | && preeditPosition < end
| 0-2 | ||||||
207 | end += preeditLength; | - | ||||||
208 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||
209 | - | |||||||
210 | - | |||||||
211 | engine.setCurrentLine(line); | - | ||||||
212 | engine.addGlyphsForRanges(colorChanges, start, end, selectionStart, selectionEnd); | - | ||||||
213 | } executed 249990 times by 24 tests: end of block Executed by:
| 249990 | ||||||
214 | - | |||||||
215 | engine.addToSceneGraph(this, style, styleColor); | - | ||||||
216 | } executed 248443 times by 24 tests: end of block Executed by:
| 248443 | ||||||
217 | - | |||||||
218 | void QQuickTextNode::deleteContent() | - | ||||||
219 | { | - | ||||||
220 | while (firstChild() != nullptr
| 74479-248591 | ||||||
221 | delete firstChild(); executed 74479 times by 10 tests: delete firstChild(); Executed by:
| 74479 | ||||||
222 | m_cursorNode = nullptr; | - | ||||||
223 | qDeleteAll(m_textures); | - | ||||||
224 | m_textures.clear(); | - | ||||||
225 | } executed 248591 times by 24 tests: end of block Executed by:
| 248591 | ||||||
226 | - | |||||||
227 | - | |||||||
Switch to Source code | Preprocessed file |