Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/items/qquicktextdocument.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | class QQuickTextDocumentPrivate : public QObjectPrivate | - | ||||||||||||
6 | { | - | ||||||||||||
7 | public: | - | ||||||||||||
8 | QPointer<QTextDocument> document; | - | ||||||||||||
9 | }; | - | ||||||||||||
10 | - | |||||||||||||
11 | - | |||||||||||||
12 | - | |||||||||||||
13 | - | |||||||||||||
14 | - | |||||||||||||
15 | QQuickTextDocument::QQuickTextDocument(QQuickItem *parent) | - | ||||||||||||
16 | : QObject(*(new QQuickTextDocumentPrivate), parent) | - | ||||||||||||
17 | { | - | ||||||||||||
18 | QQuickTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
19 | ((parent) ? static_cast<void>(0) : qt_assert("parent", __FILE__, 85)); | - | ||||||||||||
20 | ((qobject_cast<QQuickTextEdit*>(parent)) ? static_cast<void>(0) : qt_assert("qobject_cast<QQuickTextEdit*>(parent)", __FILE__, 86)); | - | ||||||||||||
21 | d->document = QPointer<QTextDocument>(qobject_cast<QQuickTextEdit*>(parent)->d_func()->document); | - | ||||||||||||
22 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
23 | - | |||||||||||||
24 | - | |||||||||||||
25 | - | |||||||||||||
26 | - | |||||||||||||
27 | QTextDocument* QQuickTextDocument::textDocument() const | - | ||||||||||||
28 | { | - | ||||||||||||
29 | const QQuickTextDocumentPrivate * const d = d_func(); | - | ||||||||||||
30 | return executed 4 times by 1 test: d->document.data();return d->document.data(); Executed by:
executed 4 times by 1 test: return d->document.data(); Executed by:
| 4 | ||||||||||||
31 | } | - | ||||||||||||
32 | - | |||||||||||||
33 | QQuickTextDocumentWithImageResources::QQuickTextDocumentWithImageResources(QQuickItem *parent) | - | ||||||||||||
34 | : QTextDocument(parent), outstanding(0) | - | ||||||||||||
35 | { | - | ||||||||||||
36 | setUndoRedoEnabled(false); | - | ||||||||||||
37 | documentLayout()->registerHandler(QTextFormat::ImageObject, this); | - | ||||||||||||
38 | connect(this, qFlagLocation("2""baseUrlChanged(QUrl)" "\0" __FILE__ ":" "104"), this, qFlagLocation("1""reset()" "\0" __FILE__ ":" "104")); | - | ||||||||||||
39 | } executed 1228 times by 7 tests: end of block Executed by:
| 1228 | ||||||||||||
40 | - | |||||||||||||
41 | QQuickTextDocumentWithImageResources::~QQuickTextDocumentWithImageResources() | - | ||||||||||||
42 | { | - | ||||||||||||
43 | if (!m_resources.isEmpty()
| 10-462 | ||||||||||||
44 | qDeleteAll(m_resources); executed 10 times by 2 tests: qDeleteAll(m_resources); Executed by:
| 10 | ||||||||||||
45 | } executed 472 times by 7 tests: end of block Executed by:
| 472 | ||||||||||||
46 | - | |||||||||||||
47 | QVariant QQuickTextDocumentWithImageResources::loadResource(int type, const QUrl &name) | - | ||||||||||||
48 | { | - | ||||||||||||
49 | QVariant resource = QTextDocument::loadResource(type, name); | - | ||||||||||||
50 | if (resource.isNull()
| 0-62 | ||||||||||||
51 | QQmlContext *context = qmlContext(parent()); | - | ||||||||||||
52 | QUrl url = baseUrl().resolved(name); | - | ||||||||||||
53 | QQuickPixmap *p = loadPixmap(context, url); | - | ||||||||||||
54 | resource = p->image(); | - | ||||||||||||
55 | } executed 62 times by 2 tests: end of block Executed by:
| 62 | ||||||||||||
56 | - | |||||||||||||
57 | return executed 70 times by 2 tests: resource;return resource; Executed by:
executed 70 times by 2 tests: return resource; Executed by:
| 70 | ||||||||||||
58 | } | - | ||||||||||||
59 | - | |||||||||||||
60 | void QQuickTextDocumentWithImageResources::requestFinished() | - | ||||||||||||
61 | { | - | ||||||||||||
62 | outstanding--; | - | ||||||||||||
63 | if (outstanding == 0
| 0-6 | ||||||||||||
64 | markContentsDirty(0, characterCount()); | - | ||||||||||||
65 | imagesLoaded(); | - | ||||||||||||
66 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
67 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
68 | - | |||||||||||||
69 | QSizeF QQuickTextDocumentWithImageResources::intrinsicSize( | - | ||||||||||||
70 | QTextDocument *, int, const QTextFormat &format) | - | ||||||||||||
71 | { | - | ||||||||||||
72 | if (format.isImageFormat()
| 0-108 | ||||||||||||
73 | QTextImageFormat imageFormat = format.toImageFormat(); | - | ||||||||||||
74 | - | |||||||||||||
75 | const int width = qRound(imageFormat.width()); | - | ||||||||||||
76 | const bool hasWidth = imageFormat.hasProperty(QTextFormat::ImageWidth)
| 0-108 | ||||||||||||
77 | const int height = qRound(imageFormat.height()); | - | ||||||||||||
78 | const bool hasHeight = imageFormat.hasProperty(QTextFormat::ImageHeight)
| 0-108 | ||||||||||||
79 | - | |||||||||||||
80 | QSizeF size(width, height); | - | ||||||||||||
81 | if (!hasWidth
| 0-108 | ||||||||||||
82 | QVariant res = resource(QTextDocument::ImageResource, QUrl(imageFormat.name())); | - | ||||||||||||
83 | QImage image = res.value<QImage>(); | - | ||||||||||||
84 | if (image.isNull()
| 48-60 | ||||||||||||
85 | if (!hasWidth
| 0-48 | ||||||||||||
86 | size.setWidth(16); executed 48 times by 2 tests: size.setWidth(16); Executed by:
| 48 | ||||||||||||
87 | if (!hasHeight
| 0-48 | ||||||||||||
88 | size.setHeight(16); executed 48 times by 2 tests: size.setHeight(16); Executed by:
| 48 | ||||||||||||
89 | return executed 48 times by 2 tests: size;return size; Executed by:
executed 48 times by 2 tests: return size; Executed by:
| 48 | ||||||||||||
90 | } | - | ||||||||||||
91 | QSize imgSize = image.size(); | - | ||||||||||||
92 | - | |||||||||||||
93 | if (!hasWidth
| 0-60 | ||||||||||||
94 | if (!hasHeight
| 0-60 | ||||||||||||
95 | size.setWidth(imgSize.width()); executed 60 times by 2 tests: size.setWidth(imgSize.width()); Executed by:
| 60 | ||||||||||||
96 | else | - | ||||||||||||
97 | size.setWidth(qRound(height * (imgSize.width() / (qreal) imgSize.height()))); never executed: size.setWidth(qRound(height * (imgSize.width() / (qreal) imgSize.height()))); | 0 | ||||||||||||
98 | } | - | ||||||||||||
99 | if (!hasHeight
| 0-60 | ||||||||||||
100 | if (!hasWidth
| 0-60 | ||||||||||||
101 | size.setHeight(imgSize.height()); executed 60 times by 2 tests: size.setHeight(imgSize.height()); Executed by:
| 60 | ||||||||||||
102 | else | - | ||||||||||||
103 | size.setHeight(qRound(width * (imgSize.height() / (qreal) imgSize.width()))); never executed: size.setHeight(qRound(width * (imgSize.height() / (qreal) imgSize.width()))); | 0 | ||||||||||||
104 | } | - | ||||||||||||
105 | } executed 60 times by 2 tests: end of block Executed by:
| 60 | ||||||||||||
106 | return executed 60 times by 2 tests: size;return size; Executed by:
executed 60 times by 2 tests: return size; Executed by:
| 60 | ||||||||||||
107 | } | - | ||||||||||||
108 | return never executed: QSizeF();return QSizeF(); never executed: return QSizeF(); | 0 | ||||||||||||
109 | } | - | ||||||||||||
110 | - | |||||||||||||
111 | void QQuickTextDocumentWithImageResources::drawObject( | - | ||||||||||||
112 | QPainter *, const QRectF &, QTextDocument *, int, const QTextFormat &) | - | ||||||||||||
113 | { | - | ||||||||||||
114 | } | - | ||||||||||||
115 | - | |||||||||||||
116 | QImage QQuickTextDocumentWithImageResources::image(const QTextImageFormat &format) const | - | ||||||||||||
117 | { | - | ||||||||||||
118 | QVariant res = resource(QTextDocument::ImageResource, QUrl(format.name())); | - | ||||||||||||
119 | return executed 8 times by 2 tests: res.value<QImage>();return res.value<QImage>(); Executed by:
executed 8 times by 2 tests: return res.value<QImage>(); Executed by:
| 8 | ||||||||||||
120 | } | - | ||||||||||||
121 | - | |||||||||||||
122 | void QQuickTextDocumentWithImageResources::reset() | - | ||||||||||||
123 | { | - | ||||||||||||
124 | clearResources(); | - | ||||||||||||
125 | markContentsDirty(0, characterCount()); | - | ||||||||||||
126 | } executed 346 times by 7 tests: end of block Executed by:
| 346 | ||||||||||||
127 | - | |||||||||||||
128 | QQuickPixmap *QQuickTextDocumentWithImageResources::loadPixmap( | - | ||||||||||||
129 | QQmlContext *context, const QUrl &url) | - | ||||||||||||
130 | { | - | ||||||||||||
131 | - | |||||||||||||
132 | QHash<QUrl, QQuickPixmap *>::Iterator iter = m_resources.find(url); | - | ||||||||||||
133 | - | |||||||||||||
134 | if (iter == m_resources.end()
| 10-52 | ||||||||||||
135 | QQuickPixmap *p = new QQuickPixmap(context->engine(), url); | - | ||||||||||||
136 | iter = m_resources.insert(url, p); | - | ||||||||||||
137 | - | |||||||||||||
138 | if (p->isLoading()
| 4-6 | ||||||||||||
139 | p->connectFinished(this, qFlagLocation("1""requestFinished()" "\0" __FILE__ ":" "205")); | - | ||||||||||||
140 | outstanding++; | - | ||||||||||||
141 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
142 | } executed 10 times by 2 tests: end of block Executed by:
| 10 | ||||||||||||
143 | - | |||||||||||||
144 | QQuickPixmap *p = *iter; | - | ||||||||||||
145 | if (p->isError()
| 30-32 | ||||||||||||
146 | if (!errors.contains(url)
| 6-26 | ||||||||||||
147 | errors.insert(url); | - | ||||||||||||
148 | qmlWarning(parent()) << p->error(); | - | ||||||||||||
149 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||
150 | } executed 32 times by 2 tests: end of block Executed by:
| 32 | ||||||||||||
151 | return executed 62 times by 2 tests: p;return p; Executed by:
executed 62 times by 2 tests: return p; Executed by:
| 62 | ||||||||||||
152 | } | - | ||||||||||||
153 | - | |||||||||||||
154 | void QQuickTextDocumentWithImageResources::clearResources() | - | ||||||||||||
155 | { | - | ||||||||||||
156 | for (QQuickPixmap *pixmap : qAsConst(m_resources)) | - | ||||||||||||
157 | pixmap->clear(this); never executed: pixmap->clear(this); | 0 | ||||||||||||
158 | qDeleteAll(m_resources); | - | ||||||||||||
159 | m_resources.clear(); | - | ||||||||||||
160 | outstanding = 0; | - | ||||||||||||
161 | } executed 1594 times by 7 tests: end of block Executed by:
| 1594 | ||||||||||||
162 | - | |||||||||||||
163 | void QQuickTextDocumentWithImageResources::setText(const QString &text) | - | ||||||||||||
164 | { | - | ||||||||||||
165 | clearResources(); | - | ||||||||||||
166 | - | |||||||||||||
167 | - | |||||||||||||
168 | setHtml(text); | - | ||||||||||||
169 | - | |||||||||||||
170 | - | |||||||||||||
171 | - | |||||||||||||
172 | } executed 196 times by 2 tests: end of block Executed by:
| 196 | ||||||||||||
173 | - | |||||||||||||
174 | QSet<QUrl> QQuickTextDocumentWithImageResources::errors; | - | ||||||||||||
175 | - | |||||||||||||
176 | - | |||||||||||||
177 | - | |||||||||||||
Switch to Source code | Preprocessed file |