text/qtextimagehandler.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format) -
6{ -
7 QPixmap pm; -
8 -
9 QString name = format.name(); -
10 if (name.startsWith(QLatin1String(":/")))
evaluated: name.startsWith(QLatin1String(":/"))
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:10
3-10
11 name.prepend(QLatin1String("qrc"));
executed: name.prepend(QLatin1String("qrc"));
Execution Count:3
3
12 QUrl url = QUrl(name); -
13 const QVariant data = doc->resource(QTextDocument::ImageResource, url); -
14 if (data.type() == QVariant::Pixmap || data.type() == QVariant::Image) {
partially evaluated: data.type() == QVariant::Pixmap
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
evaluated: data.type() == QVariant::Image
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:7
0-13
15 pm = qvariant_cast<QPixmap>(data); -
16 } else if (data.type() == QVariant::ByteArray) {
executed: }
Execution Count:6
partially evaluated: data.type() == QVariant::ByteArray
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
17 pm.loadFromData(data.toByteArray()); -
18 }
never executed: }
0
19 -
20 if (pm.isNull()) {
evaluated: pm.isNull()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:6
6-7
21 QString context; -
22 -
23 -
24 -
25 -
26 -
27 -
28 QImage img; -
29 if (img.isNull()) {
partially evaluated: img.isNull()
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
30 name = format.name(); -
31 if (name.isEmpty() || !img.load(name))
evaluated: name.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:6
partially evaluated: !img.load(name)
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
32 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
executed: return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
Execution Count:7
7
33 }
never executed: }
0
34 pm = QPixmap::fromImage(img); -
35 doc->addResource(QTextDocument::ImageResource, url, pm); -
36 }
never executed: }
0
37 -
38 return pm;
executed: return pm;
Execution Count:6
6
39} -
40 -
41static QSize getPixmapSize(QTextDocument *doc, const QTextImageFormat &format) -
42{ -
43 QPixmap pm; -
44 -
45 const bool hasWidth = format.hasProperty(QTextFormat::ImageWidth); -
46 const int width = qRound(format.width()); -
47 const bool hasHeight = format.hasProperty(QTextFormat::ImageHeight); -
48 const int height = qRound(format.height()); -
49 -
50 QSize size(width, height); -
51 if (!hasWidth || !hasHeight) {
evaluated: !hasWidth
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:5
partially evaluated: !hasHeight
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-11
52 pm = getPixmap(doc, format); -
53 if (!hasWidth) {
partially evaluated: !hasWidth
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-11
54 if (!hasHeight)
partially evaluated: !hasHeight
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-11
55 size.setWidth(pm.width());
executed: size.setWidth(pm.width());
Execution Count:11
11
56 else -
57 size.setWidth(qRound(height * (pm.width() / (qreal) pm.height())));
never executed: size.setWidth(qRound(height * (pm.width() / (qreal) pm.height())));
0
58 } -
59 if (!hasHeight) {
partially evaluated: !hasHeight
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-11
60 if (!hasWidth)
partially evaluated: !hasWidth
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-11
61 size.setHeight(pm.height());
executed: size.setHeight(pm.height());
Execution Count:11
11
62 else -
63 size.setHeight(qRound(width * (pm.height() / (qreal) pm.width())));
never executed: size.setHeight(qRound(width * (pm.height() / (qreal) pm.width())));
0
64 } -
65 }
executed: }
Execution Count:11
11
66 -
67 qreal scale = 1.0; -
68 QPaintDevice *pdev = doc->documentLayout()->paintDevice(); -
69 if (pdev) {
evaluated: pdev
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:10
6-10
70 if (pm.isNull())
partially evaluated: pm.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
71 pm = getPixmap(doc, format);
never executed: pm = getPixmap(doc, format);
0
72 if (!pm.isNull())
partially evaluated: !pm.isNull()
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
73 scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
executed: scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
Execution Count:6
6
74 }
executed: }
Execution Count:6
6
75 size *= scale; -
76 -
77 return size;
executed: return size;
Execution Count:16
16
78} -
79 -
80static QImage getImage(QTextDocument *doc, const QTextImageFormat &format) -
81{ -
82 QImage image; -
83 -
84 QString name = format.name(); -
85 if (name.startsWith(QLatin1String(":/")))
never evaluated: name.startsWith(QLatin1String(":/"))
0
86 name.prepend(QLatin1String("qrc"));
never executed: name.prepend(QLatin1String("qrc"));
0
87 QUrl url = QUrl(name); -
88 const QVariant data = doc->resource(QTextDocument::ImageResource, url); -
89 if (data.type() == QVariant::Image) {
never evaluated: data.type() == QVariant::Image
0
90 image = qvariant_cast<QImage>(data); -
91 } else if (data.type() == QVariant::ByteArray) {
never executed: }
never evaluated: data.type() == QVariant::ByteArray
0
92 image.loadFromData(data.toByteArray()); -
93 }
never executed: }
0
94 -
95 if (image.isNull()) {
never evaluated: image.isNull()
0
96 QString context; -
97 -
98 -
99 -
100 -
101 -
102 -
103 -
104 if (image.isNull()) {
never evaluated: image.isNull()
0
105 name = format.name(); -
106 if (name.isEmpty() || !image.load(name))
never evaluated: name.isEmpty()
never evaluated: !image.load(name)
0
107 return QImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
never executed: return QImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
0
108 }
never executed: }
0
109 doc->addResource(QTextDocument::ImageResource, url, image); -
110 }
never executed: }
0
111 -
112 return image;
never executed: return image;
0
113} -
114 -
115static QSize getImageSize(QTextDocument *doc, const QTextImageFormat &format) -
116{ -
117 QImage image; -
118 -
119 const bool hasWidth = format.hasProperty(QTextFormat::ImageWidth); -
120 const int width = qRound(format.width()); -
121 const bool hasHeight = format.hasProperty(QTextFormat::ImageHeight); -
122 const int height = qRound(format.height()); -
123 -
124 QSize size(width, height); -
125 if (!hasWidth || !hasHeight) {
never evaluated: !hasWidth
never evaluated: !hasHeight
0
126 image = getImage(doc, format); -
127 if (!hasWidth)
never evaluated: !hasWidth
0
128 size.setWidth(image.width());
never executed: size.setWidth(image.width());
0
129 if (!hasHeight)
never evaluated: !hasHeight
0
130 size.setHeight(image.height());
never executed: size.setHeight(image.height());
0
131 }
never executed: }
0
132 -
133 qreal scale = 1.0; -
134 QPaintDevice *pdev = doc->documentLayout()->paintDevice(); -
135 if (pdev) {
never evaluated: pdev
0
136 if (image.isNull())
never evaluated: image.isNull()
0
137 image = getImage(doc, format);
never executed: image = getImage(doc, format);
0
138 if (!image.isNull())
never evaluated: !image.isNull()
0
139 scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
never executed: scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
0
140 }
never executed: }
0
141 size *= scale; -
142 -
143 return size;
never executed: return size;
0
144} -
145 -
146QTextImageHandler::QTextImageHandler(QObject *parent) -
147 : QObject(parent) -
148{ -
149}
executed: }
Execution Count:314
314
150 -
151QSizeF QTextImageHandler::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) -
152{ -
153 (void)posInDocument; -
154 const QTextImageFormat imageFormat = format.toImageFormat(); -
155 -
156 if (QCoreApplication::instance()->thread() != QThread::currentThread())
partially evaluated: QCoreApplication::instance()->thread() != QThread::currentThread()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16
0-16
157 return getImageSize(doc, imageFormat);
never executed: return getImageSize(doc, imageFormat);
0
158 return getPixmapSize(doc, imageFormat);
executed: return getPixmapSize(doc, imageFormat);
Execution Count:16
16
159} -
160 -
161QImage QTextImageHandler::image(QTextDocument *doc, const QTextImageFormat &imageFormat) -
162{ -
163 qt_noop(); -
164 -
165 return getImage(doc, imageFormat);
never executed: return getImage(doc, imageFormat);
0
166} -
167 -
168void QTextImageHandler::drawObject(QPainter *p, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) -
169{ -
170 (void)posInDocument; -
171 const QTextImageFormat imageFormat = format.toImageFormat(); -
172 -
173 if (QCoreApplication::instance()->thread() != QThread::currentThread()) {
partially evaluated: QCoreApplication::instance()->thread() != QThread::currentThread()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
174 const QImage image = getImage(doc, imageFormat); -
175 p->drawImage(rect, image, image.rect()); -
176 } else {
never executed: }
0
177 const QPixmap pixmap = getPixmap(doc, imageFormat); -
178 p->drawPixmap(rect, pixmap, pixmap.rect()); -
179 }
executed: }
Execution Count:2
2
180} -
181 -
182 -
183 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial