kernel/qmimedata.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5struct QMimeDataStruct -
6{ -
7 QString format; -
8 QVariant data; -
9}; -
10 -
11class QMimeDataPrivate : public QObjectPrivate -
12{ -
13 inline QMimeData* q_func() { return static_cast<QMimeData *>(q_ptr); } inline const QMimeData* q_func() const { return static_cast<const QMimeData *>(q_ptr); } friend class QMimeData; -
14public: -
15 void removeData(const QString &format); -
16 void setData(const QString &format, const QVariant &data); -
17 QVariant getData(const QString &format) const; -
18 -
19 QVariant retrieveTypedData(const QString &format, QVariant::Type type) const; -
20 -
21 QList<QMimeDataStruct> dataList; -
22}; -
23 -
24void QMimeDataPrivate::removeData(const QString &format) -
25{ -
26 for (int i=0; i<dataList.size(); i++) {
evaluated: i<dataList.size()
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:72
20-72
27 if (dataList.at(i).format == format) {
evaluated: dataList.at(i).format == format
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:14
6-14
28 dataList.removeAt(i); -
29 return;
executed: return;
Execution Count:6
6
30 } -
31 }
executed: }
Execution Count:14
14
32}
executed: }
Execution Count:72
72
33 -
34void QMimeDataPrivate::setData(const QString &format, const QVariant &data) -
35{ -
36 -
37 removeData(format); -
38 QMimeDataStruct mimeData; -
39 mimeData.format = format; -
40 mimeData.data = data; -
41 dataList += mimeData; -
42}
executed: }
Execution Count:76
76
43 -
44 -
45QVariant QMimeDataPrivate::getData(const QString &format) const -
46{ -
47 QVariant data; -
48 for (int i=0; i<dataList.size(); i++) {
evaluated: i<dataList.size()
TRUEFALSE
yes
Evaluation Count:97
yes
Evaluation Count:9
9-97
49 if (dataList.at(i).format == format) {
evaluated: dataList.at(i).format == format
TRUEFALSE
yes
Evaluation Count:83
yes
Evaluation Count:14
14-83
50 data = dataList.at(i).data; -
51 break;
executed: break;
Execution Count:83
83
52 } -
53 }
executed: }
Execution Count:14
14
54 return data;
executed: return data;
Execution Count:92
92
55} -
56 -
57QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Type type) const -
58{ -
59 const QMimeData * const q = q_func(); -
60 -
61 QVariant data = q->retrieveData(format, type); -
62 -
63 -
64 if (format == QLatin1String("text/plain") && !data.isValid()) {
evaluated: format == QLatin1String("text/plain")
TRUEFALSE
yes
Evaluation Count:63
yes
Evaluation Count:29
evaluated: !data.isValid()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:59
4-63
65 data = retrieveTypedData(QLatin1String("text/uri-list"), QVariant::List); -
66 if (data.type() == QVariant::Url) {
partially evaluated: data.type() == QVariant::Url
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
67 data = QVariant(data.toUrl().toDisplayString()); -
68 } else if (data.type() == QVariant::List) {
evaluated: data.type() == QVariant::List
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
never executed: }
0-2
69 QString text; -
70 int numUrls = 0; -
71 const QList<QVariant> list = data.toList(); -
72 for (int i = 0; i < list.size(); ++i) {
evaluated: i < list.size()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
73 if (list.at(i).type() == QVariant::Url) {
partially evaluated: list.at(i).type() == QVariant::Url
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
74 text.append(list.at(i).toUrl().toDisplayString() + QLatin1Char('\n')); -
75 ++numUrls; -
76 }
executed: }
Execution Count:3
3
77 }
executed: }
Execution Count:3
3
78 if (numUrls == 1)
evaluated: numUrls == 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
79 text.chop(1);
executed: text.chop(1);
Execution Count:1
1
80 data = QVariant(text); -
81 }
executed: }
Execution Count:2
2
82 } -
83 -
84 if (data.type() == type || !data.isValid())
evaluated: data.type() == type
TRUEFALSE
yes
Evaluation Count:70
yes
Evaluation Count:22
evaluated: !data.isValid()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:15
7-70
85 return data;
executed: return data;
Execution Count:77
77
86 -
87 -
88 -
89 -
90 if ((type == QVariant::Url && data.type() == QVariant::List)
partially evaluated: type == QVariant::Url
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
never evaluated: data.type() == QVariant::List
0-15
91 || (type == QVariant::List && data.type() == QVariant::Url))
partially evaluated: type == QVariant::List
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
never evaluated: data.type() == QVariant::Url
0-15
92 return data;
never executed: return data;
0
93 -
94 -
95 if ((type == QVariant::Pixmap && data.type() == QVariant::Image)
partially evaluated: type == QVariant::Pixmap
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
never evaluated: data.type() == QVariant::Image
0-15
96 || (type == QVariant::Image && data.type() == QVariant::Pixmap))
partially evaluated: type == QVariant::Image
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15
never evaluated: data.type() == QVariant::Pixmap
0-15
97 return data;
never executed: return data;
0
98 -
99 if (data.type() == QVariant::ByteArray) {
evaluated: data.type() == QVariant::ByteArray
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:10
5-10
100 -
101 switch(type) { -
102 -
103 case QVariant::String: { -
104 const QByteArray ba = data.toByteArray(); -
105 QTextCodec *codec = QTextCodec::codecForName("utf-8"); -
106 if (format == QLatin1String("text/html"))
evaluated: format == QLatin1String("text/html")
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
107 codec = QTextCodec::codecForHtml(ba, codec);
executed: codec = QTextCodec::codecForHtml(ba, codec);
Execution Count:1
1
108 return codec->toUnicode(ba);
executed: return codec->toUnicode(ba);
Execution Count:5
5
109 } -
110 -
111 case QVariant::Color: { -
112 QVariant newData = data; -
113 newData.convert(QVariant::Color); -
114 return newData;
never executed: return newData;
0
115 } -
116 case QVariant::List: { -
117 if (format != QLatin1String("text/uri-list"))
never evaluated: format != QLatin1String("text/uri-list")
0
118 break;
never executed: break;
0
119 -
120 } -
121 case QVariant::Url: { -
122 QByteArray ba = data.toByteArray(); -
123 -
124 -
125 -
126 if (ba.endsWith('\0'))
never evaluated: ba.endsWith('\0')
0
127 ba.chop(1);
never executed: ba.chop(1);
0
128 -
129 QList<QByteArray> urls = ba.split('\n'); -
130 QList<QVariant> list; -
131 for (int i = 0; i < urls.size(); ++i) {
never evaluated: i < urls.size()
0
132 QByteArray ba = urls.at(i).trimmed(); -
133 if (!ba.isEmpty())
never evaluated: !ba.isEmpty()
0
134 list.append(QUrl::fromEncoded(ba));
never executed: list.append(QUrl::fromEncoded(ba));
0
135 }
never executed: }
0
136 return list;
never executed: return list;
0
137 } -
138 default: -
139 break;
never executed: break;
0
140 } -
141 -
142 } else if (type == QVariant::ByteArray) {
never executed: }
partially evaluated: type == QVariant::ByteArray
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
143 -
144 -
145 switch(data.type()) { -
146 case QVariant::ByteArray: -
147 case QVariant::Color: -
148 return data.toByteArray();
never executed: return data.toByteArray();
0
149 case QVariant::String: -
150 return data.toString().toUtf8();
executed: return data.toString().toUtf8();
Execution Count:10
10
151 case QVariant::Url: -
152 return data.toUrl().toEncoded();
never executed: return data.toUrl().toEncoded();
0
153 case QVariant::List: { -
154 -
155 QByteArray result; -
156 QList<QVariant> list = data.toList(); -
157 for (int i = 0; i < list.size(); ++i) {
never evaluated: i < list.size()
0
158 if (list.at(i).type() == QVariant::Url) {
never evaluated: list.at(i).type() == QVariant::Url
0
159 result += list.at(i).toUrl().toEncoded(); -
160 result += "\r\n"; -
161 }
never executed: }
0
162 }
never executed: }
0
163 if (!result.isEmpty())
never evaluated: !result.isEmpty()
0
164 return result;
never executed: return result;
0
165 break;
never executed: break;
0
166 } -
167 default: -
168 break;
never executed: break;
0
169 } -
170 }
never executed: }
0
171 return data;
never executed: return data;
0
172} -
173QMimeData::QMimeData() -
174 : QObject(*new QMimeDataPrivate, 0) -
175{ -
176}
executed: }
Execution Count:167
167
177 -
178 -
179 -
180 -
181QMimeData::~QMimeData() -
182{ -
183} -
184QList<QUrl> QMimeData::urls() const -
185{ -
186 const QMimeDataPrivate * const d = d_func(); -
187 QVariant data = d->retrieveTypedData(QLatin1String("text/uri-list"), QVariant::List); -
188 QList<QUrl> urls; -
189 if (data.type() == QVariant::Url)
partially evaluated: data.type() == QVariant::Url
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
190 urls.append(data.toUrl());
never executed: urls.append(data.toUrl());
0
191 else if (data.type() == QVariant::List) {
partially evaluated: data.type() == QVariant::List
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
192 QList<QVariant> list = data.toList(); -
193 for (int i = 0; i < list.size(); ++i) {
evaluated: i < list.size()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
194 if (list.at(i).type() == QVariant::Url)
partially evaluated: list.at(i).type() == QVariant::Url
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
195 urls.append(list.at(i).toUrl());
executed: urls.append(list.at(i).toUrl());
Execution Count:3
3
196 }
executed: }
Execution Count:3
3
197 }
executed: }
Execution Count:2
2
198 return urls;
executed: return urls;
Execution Count:2
2
199} -
200void QMimeData::setUrls(const QList<QUrl> &urls) -
201{ -
202 QMimeDataPrivate * const d = d_func(); -
203 QList<QVariant> list; -
204 for (int i = 0; i < urls.size(); ++i)
evaluated: i < urls.size()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
205 list.append(urls.at(i));
executed: list.append(urls.at(i));
Execution Count:3
3
206 -
207 d->setData(QLatin1String("text/uri-list"), list); -
208}
executed: }
Execution Count:2
2
209bool QMimeData::hasUrls() const -
210{ -
211 return hasFormat(QLatin1String("text/uri-list"));
executed: return hasFormat(QLatin1String("text/uri-list"));
Execution Count:13
13
212} -
213QString QMimeData::text() const -
214{ -
215 const QMimeDataPrivate * const d = d_func(); -
216 QVariant data = d->retrieveTypedData(QLatin1String("text/plain"), QVariant::String); -
217 return data.toString();
executed: return data.toString();
Execution Count:51
51
218} -
219 -
220 -
221 -
222 -
223 -
224 -
225 -
226void QMimeData::setText(const QString &text) -
227{ -
228 QMimeDataPrivate * const d = d_func(); -
229 d->setData(QLatin1String("text/plain"), text); -
230}
executed: }
Execution Count:30
30
231 -
232 -
233 -
234 -
235 -
236 -
237 -
238bool QMimeData::hasText() const -
239{ -
240 return hasFormat(QLatin1String("text/plain")) || hasUrls();
executed: return hasFormat(QLatin1String("text/plain")) || hasUrls();
Execution Count:17
17
241} -
242 -
243 -
244 -
245 -
246 -
247 -
248 -
249QString QMimeData::html() const -
250{ -
251 const QMimeDataPrivate * const d = d_func(); -
252 QVariant data = d->retrieveTypedData(QLatin1String("text/html"), QVariant::String); -
253 return data.toString();
executed: return data.toString();
Execution Count:3
3
254} -
255 -
256 -
257 -
258 -
259 -
260 -
261 -
262void QMimeData::setHtml(const QString &html) -
263{ -
264 QMimeDataPrivate * const d = d_func(); -
265 d->setData(QLatin1String("text/html"), html); -
266}
executed: }
Execution Count:2
2
267 -
268 -
269 -
270 -
271 -
272 -
273 -
274bool QMimeData::hasHtml() const -
275{ -
276 return hasFormat(QLatin1String("text/html"));
executed: return hasFormat(QLatin1String("text/html"));
Execution Count:11
11
277} -
278QVariant QMimeData::imageData() const -
279{ -
280 const QMimeDataPrivate * const d = d_func(); -
281 return d->retrieveTypedData(QLatin1String("application/x-qt-image"), QVariant::Image);
executed: return d->retrieveTypedData(QLatin1String("application/x-qt-image"), QVariant::Image);
Execution Count:3
3
282} -
283void QMimeData::setImageData(const QVariant &image) -
284{ -
285 QMimeDataPrivate * const d = d_func(); -
286 d->setData(QLatin1String("application/x-qt-image"), image); -
287}
executed: }
Execution Count:2
2
288 -
289 -
290 -
291 -
292 -
293 -
294 -
295bool QMimeData::hasImage() const -
296{ -
297 return hasFormat(QLatin1String("application/x-qt-image"));
executed: return hasFormat(QLatin1String("application/x-qt-image"));
Execution Count:5
5
298} -
299QVariant QMimeData::colorData() const -
300{ -
301 const QMimeDataPrivate * const d = d_func(); -
302 return d->retrieveTypedData(QLatin1String("application/x-color"), QVariant::Color);
executed: return d->retrieveTypedData(QLatin1String("application/x-color"), QVariant::Color);
Execution Count:2
2
303} -
304void QMimeData::setColorData(const QVariant &color) -
305{ -
306 QMimeDataPrivate * const d = d_func(); -
307 d->setData(QLatin1String("application/x-color"), color); -
308}
executed: }
Execution Count:3
3
309bool QMimeData::hasColor() const -
310{ -
311 return hasFormat(QLatin1String("application/x-color"));
executed: return hasFormat(QLatin1String("application/x-color"));
Execution Count:6
6
312} -
313 -
314 -
315 -
316 -
317 -
318QByteArray QMimeData::data(const QString &mimeType) const -
319{ -
320 const QMimeDataPrivate * const d = d_func(); -
321 QVariant data = d->retrieveTypedData(mimeType, QVariant::ByteArray); -
322 return data.toByteArray();
executed: return data.toByteArray();
Execution Count:27
27
323} -
324void QMimeData::setData(const QString &mimeType, const QByteArray &data) -
325{ -
326 QMimeDataPrivate * const d = d_func(); -
327 d->setData(mimeType, QVariant(data)); -
328}
executed: }
Execution Count:37
37
329bool QMimeData::hasFormat(const QString &mimeType) const -
330{ -
331 return formats().contains(mimeType);
executed: return formats().contains(mimeType);
Execution Count:72
72
332} -
333QStringList QMimeData::formats() const -
334{ -
335 const QMimeDataPrivate * const d = d_func(); -
336 QStringList list; -
337 for (int i=0; i<d->dataList.size(); i++)
evaluated: i<d->dataList.size()
TRUEFALSE
yes
Evaluation Count:55
yes
Evaluation Count:72
55-72
338 list += d->dataList.at(i).format;
executed: list += d->dataList.at(i).format;
Execution Count:55
55
339 return list;
executed: return list;
Execution Count:72
72
340} -
341QVariant QMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const -
342{ -
343 (void)type;; -
344 const QMimeDataPrivate * const d = d_func(); -
345 return d->getData(mimeType);
executed: return d->getData(mimeType);
Execution Count:92
92
346} -
347 -
348 -
349 -
350 -
351void QMimeData::clear() -
352{ -
353 QMimeDataPrivate * const d = d_func(); -
354 d->dataList.clear(); -
355}
executed: }
Execution Count:13
13
356 -
357 -
358 -
359 -
360 -
361 -
362void QMimeData::removeFormat(const QString &mimeType) -
363{ -
364 QMimeDataPrivate * const d = d_func(); -
365 d->removeData(mimeType); -
366}
executed: }
Execution Count:2
2
367 -
368 -
369 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial