OpenCoverage

qquickfontloader.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickfontloader.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14class QQuickFontObject : public QObject-
15{-
16public:-
17#pragma GCC diagnostic push-
18-
19#pragma GCC diagnostic ignored "-Wsuggest-override"-
20 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private:-
21#pragma GCC diagnostic ignored "-Wattributes"-
22 __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
23#pragma GCC diagnostic pop-
24 struct QPrivateSignal {};-
25-
26public:-
27 explicit QQuickFontObject(int _id = -1);-
28-
29-
30 void download(const QUrl &url, QNetworkAccessManager *manager);-
31-
32public :-
33 void fontDownloaded(const QString&, QQuickFontLoader::Status);-
34-
35private:-
36 int redirectCount = 0;-
37 QNetworkReply *reply = nullptr;-
38-
39private :-
40 void replyFinished();-
41-
42-
43public:-
44 int id;-
45-
46 QQuickFontObject(const QQuickFontObject &) = delete; QQuickFontObject &operator=(const QQuickFontObject &) = delete;-
47};-
48-
49QQuickFontObject::QQuickFontObject(int _id)-
50 : QObject(nullptr), id(_id)-
51{-
52}
executed 22 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
22
53-
54-
55void QQuickFontObject::download(const QUrl &url, QNetworkAccessManager *manager)-
56{-
57 QNetworkRequest req(url);-
58 req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);-
59 reply = manager->get(req);-
60 QObject::connect(reply, qFlagLocation("2""finished()" "\0" __FILE__ ":" "104"), this, qFlagLocation("1""replyFinished()" "\0" __FILE__ ":" "104"));-
61}
executed 14 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
14
62-
63void QQuickFontObject::replyFinished()-
64{-
65 if (reply
replyDescription
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
FALSEnever evaluated
) {
0-14
66 redirectCount++;-
67 if (redirectCount < 16
redirectCount < 16Description
TRUEevaluated 14 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
FALSEnever evaluated
) {
0-14
68 QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);-
69 if (redirect.isValid()
redirect.isValid()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickfontloader
FALSEevaluated 12 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
) {
2-12
70 QUrl url = reply->url().resolved(redirect.toUrl());-
71 QNetworkAccessManager *manager = reply->manager();-
72 reply->deleteLater();-
73 reply = nullptr;-
74 download(url, manager);-
75 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_qquickfontloader
2
76 }-
77 }
executed 12 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
12
78 redirectCount = 0;-
79-
80 if (!reply->error()
!reply->error()Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_qquickfontloader
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
) {
6
81 id = QFontDatabase::addApplicationFontFromData(reply->readAll());-
82 if (id != -1
id != -1Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_qquickfontloader
FALSEnever evaluated
)
0-6
83 fontDownloaded(QFontDatabase::applicationFontFamilies(id).at(0), QQuickFontLoader::Ready);
executed 6 times by 1 test: fontDownloaded(QFontDatabase::applicationFontFamilies(id).at(0), QQuickFontLoader::Ready);
Executed by:
  • tst_qquickfontloader
6
84 else-
85 fontDownloaded(QString(), QQuickFontLoader::Error);
never executed: fontDownloaded(QString(), QQuickFontLoader::Error);
0
86 } else {-
87 QMessageLogger(__FILE__, 131, __PRETTY_FUNCTION__).warning("%s: Unable to load font '%s': %s", __PRETTY_FUNCTION__,-
88 QtPrivate::asString(reply->url().toString()).toLocal8Bit().constData(), QtPrivate::asString(reply->errorString()).toLocal8Bit().constData());-
89 fontDownloaded(QString(), QQuickFontLoader::Error);-
90 }
executed 6 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
6
91 reply->deleteLater();-
92 reply = nullptr;-
93 }
executed 12 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
12
94}
executed 12 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
12
95-
96-
97class QQuickFontLoaderPrivate : public QObjectPrivate-
98{-
99 inline QQuickFontLoader* q_func() { return static_cast<QQuickFontLoader *>(q_ptr); } inline const QQuickFontLoader* q_func() const { return static_cast<const QQuickFontLoader *>(q_ptr); } friend class QQuickFontLoader;-
100-
101public:-
102 QQuickFontLoaderPrivate() {}-
103-
104 QUrl url;-
105 QString name;-
106 QQuickFontLoader::Status status = QQuickFontLoader::Null;-
107};-
108-
109static void q_QFontLoaderFontsStaticReset();-
110static void q_QFontLoaderFontsAddReset()-
111{-
112 qAddPostRoutine(q_QFontLoaderFontsStaticReset);-
113}
executed 10 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
10
114class QFontLoaderFonts-
115{-
116public:-
117 QFontLoaderFonts()-
118 {-
119 qAddPostRoutine(q_QFontLoaderFontsStaticReset);-
120 qAddPreRoutine(q_QFontLoaderFontsAddReset);-
121 }
executed 6 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
6
122-
123 ~QFontLoaderFonts()-
124 {-
125 qRemovePostRoutine(q_QFontLoaderFontsStaticReset);-
126 reset();-
127 }
executed 6 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
6
128-
129-
130 void reset()-
131 {-
132 QVector<QQuickFontObject *> deleted;-
133 QHash<QUrl, QQuickFontObject*>::iterator it;-
134 for (it = map.begin(); it != map.end()
it != map.end()Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
; ++it) {
22
135 if (!deleted.contains(it.value())
!deleted.contains(it.value())Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
FALSEnever evaluated
) {
0-22
136 deleted.append(it.value());-
137 delete it.value();-
138 }
executed 22 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
22
139 }
executed 22 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
22
140 map.clear();-
141 }
executed 22 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
22
142-
143 QHash<QUrl, QQuickFontObject *> map;-
144};-
145namespace { namespace Q_QGS_fontLoaderFonts { typedef QFontLoaderFonts Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
guard.load() =...c::InitializedDescription
TRUEevaluated 6 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
FALSEnever evaluated
) guard.store(QtGlobalStatic::Destroyed);
executed 6 times by 3 tests: guard.store(QtGlobalStatic::Destroyed);
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
}
executed 6 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
}; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return
executed 78 times by 3 tests: return &holder.value;
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
&holder.value;
executed 78 times by 3 tests: return &holder.value;
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
} } } static QGlobalStatic<QFontLoaderFonts, Q_QGS_fontLoaderFonts::innerFunction, Q_QGS_fontLoaderFonts::guard> fontLoaderFonts;;
0-78
146-
147static void q_QFontLoaderFontsStaticReset()-
148{-
149 fontLoaderFonts()->reset();-
150}
executed 16 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
16
151QQuickFontLoader::QQuickFontLoader(QObject *parent)-
152 : QObject(*(new QQuickFontLoaderPrivate), parent)-
153{-
154}
executed 30 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
30
155-
156QQuickFontLoader::~QQuickFontLoader()-
157{-
158}-
159-
160-
161-
162-
163-
164QUrl QQuickFontLoader::source() const-
165{-
166 const QQuickFontLoaderPrivate * const d = d_func();-
167 return
executed 20 times by 1 test: return d->url;
Executed by:
  • tst_qquickfontloader
d->url;
executed 20 times by 1 test: return d->url;
Executed by:
  • tst_qquickfontloader
20
168}-
169-
170void QQuickFontLoader::setSource(const QUrl &url)-
171{-
172 QQuickFontLoaderPrivate * const d = d_func();-
173 if (url == d->url
url == d->urlDescription
TRUEnever evaluated
FALSEevaluated 32 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
)
0-32
174 return;
never executed: return;
0
175 d->url = url;-
176 sourceChanged();-
177-
178 QString localFile = QQmlFile::urlToLocalFileOrQrc(d->url);-
179 if (!localFile.isEmpty()
!localFile.isEmpty()Description
TRUEevaluated 18 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
FALSEevaluated 14 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
) {
14-18
180 if (!fontLoaderFonts()->map.contains(d->url)
!fontLoaderFon...ntains(d->url)Description
TRUEevaluated 12 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_qquickfontloader
) {
6-12
181 int id = QFontDatabase::addApplicationFont(localFile);-
182 if (id != -1
id != -1Description
TRUEevaluated 10 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickfontloader
) {
2-10
183 updateFontInfo(QFontDatabase::applicationFontFamilies(id).at(0), Ready);-
184 QQuickFontObject *fo = new QQuickFontObject(id);-
185 fontLoaderFonts()->map[d->url] = fo;-
186 }
executed 10 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
else {
10
187 updateFontInfo(QString(), Error);-
188 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_qquickfontloader
2
189 } else {-
190 updateFontInfo(QFontDatabase::applicationFontFamilies(fontLoaderFonts()->map.value(d->url)->id).at(0), Ready);-
191 }
executed 6 times by 1 test: end of block
Executed by:
  • tst_qquickfontloader
6
192 } else {-
193 if (!fontLoaderFonts()->map.contains(d->url)
!fontLoaderFon...ntains(d->url)Description
TRUEevaluated 12 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickfontloader
) {
2-12
194-
195 QQuickFontObject *fo = new QQuickFontObject;-
196 fontLoaderFonts()->map[d->url] = fo;-
197 fo->download(d->url, qmlEngine(this)->networkAccessManager());-
198 d->status = Loading;-
199 statusChanged();-
200 QObject::connect(fo, qFlagLocation("2""fontDownloaded(QString,QQuickFontLoader::Status)" "\0" __FILE__ ":" "272"),-
201 this, qFlagLocation("1""updateFontInfo(QString,QQuickFontLoader::Status)" "\0" __FILE__ ":" "273"));-
202-
203-
204-
205 }
executed 12 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
else {
12
206 QQuickFontObject *fo = fontLoaderFonts()->map.value(d->url);-
207 if (fo->id == -1
fo->id == -1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qquickfontloader
) {
0-2
208-
209 d->status = Loading;-
210 statusChanged();-
211 QObject::connect(fo, qFlagLocation("2""fontDownloaded(QString,QQuickFontLoader::Status)" "\0" __FILE__ ":" "283"),-
212 this, qFlagLocation("1""updateFontInfo(QString,QQuickFontLoader::Status)" "\0" __FILE__ ":" "284"));-
213-
214-
215-
216 }
never executed: end of block
0
217 else-
218 updateFontInfo(QFontDatabase::applicationFontFamilies(fo->id).at(0), Ready);
executed 2 times by 1 test: updateFontInfo(QFontDatabase::applicationFontFamilies(fo->id).at(0), Ready);
Executed by:
  • tst_qquickfontloader
2
219 }-
220 }-
221}-
222-
223void QQuickFontLoader::updateFontInfo(const QString& name, QQuickFontLoader::Status status)-
224{-
225 QQuickFontLoaderPrivate * const d = d_func();-
226-
227 if (name != d->name
name != d->nameDescription
TRUEevaluated 26 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
) {
6-26
228 d->name = name;-
229 nameChanged();-
230 }
executed 26 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
26
231 if (status != d->status
status != d->statusDescription
TRUEevaluated 28 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qquickfontloader
) {
4-28
232 if (status == Error
status == ErrorDescription
TRUEevaluated 8 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
FALSEevaluated 20 times by 3 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
)
8-20
233 qmlWarning(this) << "Cannot load font: \"" << d->url.toString() << '"';
executed 8 times by 2 tests: qmlWarning(this) << "Cannot load font: \"" << d->url.toString() << '"';
Executed by:
  • tst_examples
  • tst_qquickfontloader
8
234 d->status = status;-
235 statusChanged();-
236 }
executed 28 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
28
237}
executed 32 times by 3 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
32
238QString QQuickFontLoader::name() const-
239{-
240 const QQuickFontLoaderPrivate * const d = d_func();-
241 return
executed 112 times by 3 tests: return d->name;
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
d->name;
executed 112 times by 3 tests: return d->name;
Executed by:
  • tst_examples
  • tst_qquickfontloader
  • tst_qquickfontloader_static
112
242}-
243-
244void QQuickFontLoader::setName(const QString &name)-
245{-
246 QQuickFontLoaderPrivate * const d = d_func();-
247 if (d->name == name
d->name == nameDescription
TRUEnever evaluated
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • tst_examples
  • tst_qquickfontloader
)
0-6
248 return;
never executed: return;
0
249 d->name = name;-
250 nameChanged();-
251 d->status = Ready;-
252 statusChanged();-
253}
executed 6 times by 2 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickfontloader
6
254QQuickFontLoader::Status QQuickFontLoader::status() const-
255{-
256 const QQuickFontLoaderPrivate * const d = d_func();-
257 return
executed 728 times by 2 tests: return d->status;
Executed by:
  • tst_examples
  • tst_qquickfontloader
d->status;
executed 728 times by 2 tests: return d->status;
Executed by:
  • tst_examples
  • tst_qquickfontloader
728
258}-
259-
260-
261-
262-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.0