kernel/qmimedata.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qmimedata.h" -
43 -
44#include "private/qobject_p.h" -
45#include "qurl.h" -
46#include "qstringlist.h" -
47#include "qtextcodec.h" -
48 -
49QT_BEGIN_NAMESPACE -
50 -
51struct QMimeDataStruct -
52{ -
53 QString format; -
54 QVariant data; -
55}; -
56 -
57class QMimeDataPrivate : public QObjectPrivate -
58{ -
59 Q_DECLARE_PUBLIC(QMimeData) -
60public: -
61 void removeData(const QString &format); -
62 void setData(const QString &format, const QVariant &data); -
63 QVariant getData(const QString &format) const; -
64 -
65 QVariant retrieveTypedData(const QString &format, QVariant::Type type) const; -
66 -
67 QList<QMimeDataStruct> dataList; -
68}; -
69 -
70void QMimeDataPrivate::removeData(const QString &format) -
71{ -
72 for (int i=0; i<dataList.size(); i++) {
evaluated: i<dataList.size()
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:72
20-72
73 if (dataList.at(i).format == format) {
evaluated: dataList.at(i).format == format
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:14
6-14
74 dataList.removeAt(i);
executed (the execution status of this line is deduced): dataList.removeAt(i);
-
75 return;
executed: return;
Execution Count:6
6
76 } -
77 }
executed: }
Execution Count:14
14
78}
executed: }
Execution Count:72
72
79 -
80void QMimeDataPrivate::setData(const QString &format, const QVariant &data) -
81{ -
82 // remove it first if the format is already here. -
83 removeData(format);
executed (the execution status of this line is deduced): removeData(format);
-
84 QMimeDataStruct mimeData;
executed (the execution status of this line is deduced): QMimeDataStruct mimeData;
-
85 mimeData.format = format;
executed (the execution status of this line is deduced): mimeData.format = format;
-
86 mimeData.data = data;
executed (the execution status of this line is deduced): mimeData.data = data;
-
87 dataList += mimeData;
executed (the execution status of this line is deduced): dataList += mimeData;
-
88}
executed: }
Execution Count:76
76
89 -
90 -
91QVariant QMimeDataPrivate::getData(const QString &format) const -
92{ -
93 QVariant data;
executed (the execution status of this line is deduced): QVariant data;
-
94 for (int i=0; i<dataList.size(); i++) {
evaluated: i<dataList.size()
TRUEFALSE
yes
Evaluation Count:97
yes
Evaluation Count:9
9-97
95 if (dataList.at(i).format == format) {
evaluated: dataList.at(i).format == format
TRUEFALSE
yes
Evaluation Count:83
yes
Evaluation Count:14
14-83
96 data = dataList.at(i).data;
executed (the execution status of this line is deduced): data = dataList.at(i).data;
-
97 break;
executed: break;
Execution Count:83
83
98 } -
99 }
executed: }
Execution Count:14
14
100 return data;
executed: return data;
Execution Count:92
92
101} -
102 -
103QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Type type) const -
104{ -
105 Q_Q(const QMimeData);
executed (the execution status of this line is deduced): const QMimeData * const q = q_func();
-
106 -
107 QVariant data = q->retrieveData(format, type);
executed (the execution status of this line is deduced): QVariant data = q->retrieveData(format, type);
-
108 -
109 // Text data requested: fallback to URL data if available -
110 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
111 data = retrieveTypedData(QLatin1String("text/uri-list"), QVariant::List);
executed (the execution status of this line is deduced): data = retrieveTypedData(QLatin1String("text/uri-list"), QVariant::List);
-
112 if (data.type() == QVariant::Url) {
partially evaluated: data.type() == QVariant::Url
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
113 data = QVariant(data.toUrl().toDisplayString());
never executed (the execution status of this line is deduced): data = QVariant(data.toUrl().toDisplayString());
-
114 } else if (data.type() == QVariant::List) {
never executed: }
evaluated: data.type() == QVariant::List
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2
0-2
115 QString text;
executed (the execution status of this line is deduced): QString text;
-
116 int numUrls = 0;
executed (the execution status of this line is deduced): int numUrls = 0;
-
117 const QList<QVariant> list = data.toList();
executed (the execution status of this line is deduced): const QList<QVariant> list = data.toList();
-
118 for (int i = 0; i < list.size(); ++i) {
evaluated: i < list.size()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
119 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
120 text.append(list.at(i).toUrl().toDisplayString() + QLatin1Char('\n'));
executed (the execution status of this line is deduced): text.append(list.at(i).toUrl().toDisplayString() + QLatin1Char('\n'));
-
121 ++numUrls;
executed (the execution status of this line is deduced): ++numUrls;
-
122 }
executed: }
Execution Count:3
3
123 }
executed: }
Execution Count:3
3
124 if (numUrls == 1)
evaluated: numUrls == 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
125 text.chop(1); // no final '\n' if there's only one URL
executed: text.chop(1);
Execution Count:1
1
126 data = QVariant(text);
executed (the execution status of this line is deduced): data = QVariant(text);
-
127 }
executed: }
Execution Count:2
2
128 } -
129 -
130 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
131 return data;
executed: return data;
Execution Count:77
77
132 -
133 // provide more conversion possiblities than just what QVariant provides -
134 -
135 // URLs can be lists as well... -
136 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
137 || (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
138 return data;
never executed: return data;
0
139 -
140 // images and pixmaps are interchangeable -
141 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
142 || (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
143 return data;
never executed: return data;
0
144 -
145 if (data.type() == QVariant::ByteArray) {
evaluated: data.type() == QVariant::ByteArray
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:10
5-10
146 // see if we can convert to the requested type -
147 switch(type) { -
148#ifndef QT_NO_TEXTCODEC -
149 case QVariant::String: { -
150 const QByteArray ba = data.toByteArray();
executed (the execution status of this line is deduced): const QByteArray ba = data.toByteArray();
-
151 QTextCodec *codec = QTextCodec::codecForName("utf-8");
executed (the execution status of this line is deduced): QTextCodec *codec = QTextCodec::codecForName("utf-8");
-
152 if (format == QLatin1String("text/html"))
evaluated: format == QLatin1String("text/html")
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
153 codec = QTextCodec::codecForHtml(ba, codec);
executed: codec = QTextCodec::codecForHtml(ba, codec);
Execution Count:1
1
154 return codec->toUnicode(ba);
executed: return codec->toUnicode(ba);
Execution Count:5
5
155 } -
156#endif // QT_NO_TEXTCODEC -
157 case QVariant::Color: { -
158 QVariant newData = data;
never executed (the execution status of this line is deduced): QVariant newData = data;
-
159 newData.convert(QVariant::Color);
never executed (the execution status of this line is deduced): newData.convert(QVariant::Color);
-
160 return newData;
never executed: return newData;
0
161 } -
162 case QVariant::List: { -
163 if (format != QLatin1String("text/uri-list"))
never evaluated: format != QLatin1String("text/uri-list")
0
164 break;
never executed: break;
0
165 // fall through -
166 } -
167 case QVariant::Url: { -
168 QByteArray ba = data.toByteArray();
never executed (the execution status of this line is deduced): QByteArray ba = data.toByteArray();
-
169 // Qt 3.x will send text/uri-list with a trailing -
170 // null-terminator (that is *not* sent for any other -
171 // text/* mime-type), so chop it off -
172 if (ba.endsWith('\0'))
never evaluated: ba.endsWith('\0')
0
173 ba.chop(1);
never executed: ba.chop(1);
0
174 -
175 QList<QByteArray> urls = ba.split('\n');
never executed (the execution status of this line is deduced): QList<QByteArray> urls = ba.split('\n');
-
176 QList<QVariant> list;
never executed (the execution status of this line is deduced): QList<QVariant> list;
-
177 for (int i = 0; i < urls.size(); ++i) {
never evaluated: i < urls.size()
0
178 QByteArray ba = urls.at(i).trimmed();
never executed (the execution status of this line is deduced): QByteArray ba = urls.at(i).trimmed();
-
179 if (!ba.isEmpty())
never evaluated: !ba.isEmpty()
0
180 list.append(QUrl::fromEncoded(ba));
never executed: list.append(QUrl::fromEncoded(ba));
0
181 }
never executed: }
0
182 return list;
never executed: return list;
0
183 } -
184 default: -
185 break;
never executed: break;
0
186 } -
187 -
188 } else if (type == QVariant::ByteArray) {
never executed: }
partially evaluated: type == QVariant::ByteArray
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
189 -
190 // try to convert to bytearray -
191 switch(data.type()) { -
192 case QVariant::ByteArray: -
193 case QVariant::Color: -
194 return data.toByteArray();
never executed: return data.toByteArray();
0
195 case QVariant::String: -
196 return data.toString().toUtf8();
executed: return data.toString().toUtf8();
Execution Count:10
10
197 case QVariant::Url: -
198 return data.toUrl().toEncoded();
never executed: return data.toUrl().toEncoded();
0
199 case QVariant::List: { -
200 // has to be list of URLs -
201 QByteArray result;
never executed (the execution status of this line is deduced): QByteArray result;
-
202 QList<QVariant> list = data.toList();
never executed (the execution status of this line is deduced): QList<QVariant> list = data.toList();
-
203 for (int i = 0; i < list.size(); ++i) {
never evaluated: i < list.size()
0
204 if (list.at(i).type() == QVariant::Url) {
never evaluated: list.at(i).type() == QVariant::Url
0
205 result += list.at(i).toUrl().toEncoded();
never executed (the execution status of this line is deduced): result += list.at(i).toUrl().toEncoded();
-
206 result += "\r\n";
never executed (the execution status of this line is deduced): result += "\r\n";
-
207 }
never executed: }
0
208 }
never executed: }
0
209 if (!result.isEmpty())
never evaluated: !result.isEmpty()
0
210 return result;
never executed: return result;
0
211 break;
never executed: break;
0
212 } -
213 default: -
214 break;
never executed: break;
0
215 } -
216 }
never executed: }
0
217 return data;
never executed: return data;
0
218} -
219 -
220/*! -
221 \class QMimeData -
222 \inmodule QtCore -
223 \brief The QMimeData class provides a container for data that records information -
224 about its MIME type. -
225 -
226 QMimeData is used to describe information that can be stored in -
227 the \l{QClipboard}{clipboard}, and transferred via the \l{drag -
228 and drop} mechanism. QMimeData objects associate the data that -
229 they hold with the corresponding MIME types to ensure that -
230 information can be safely transferred between applications, and -
231 copied around within the same application. -
232 -
233 QMimeData objects are usually created using \c new and supplied -
234 to QDrag or QClipboard objects. This is to enable Qt to manage -
235 the memory that they use. -
236 -
237 A single QMimeData object can store the same data using several -
238 different formats at the same time. The formats() function -
239 returns a list of the available formats in order of preference. -
240 The data() function returns the raw data associated with a MIME -
241 type, and setData() allows you to set the data for a MIME type. -
242 -
243 For the most common MIME types, QMimeData provides convenience -
244 functions to access the data: -
245 -
246 \table -
247 \header \li Tester \li Getter \li Setter \li MIME Types -
248 \row \li hasText() \li text() \li setText() \li \c text/plain -
249 \row \li hasHtml() \li html() \li setHtml() \li \c text/html -
250 \row \li hasUrls() \li urls() \li setUrls() \li \c text/uri-list -
251 \row \li hasImage() \li imageData() \li setImageData() \li \c image/ * -
252 \row \li hasColor() \li colorData() \li setColorData() \li \c application/x-color -
253 \endtable -
254 -
255 For example, if your write a widget that accepts URL drags, you -
256 would end up writing code like this: -
257 -
258 \snippet code/src_corelib_kernel_qmimedata.cpp 0 -
259 -
260 There are three approaches for storing custom data in a QMimeData -
261 object: -
262 -
263 \list 1 -
264 \li Custom data can be stored directly in a QMimeData object as a -
265 QByteArray using setData(). For example: -
266 -
267 \snippet code/src_corelib_kernel_qmimedata.cpp 1 -
268 -
269 \li We can subclass QMimeData and reimplement hasFormat(), -
270 formats(), and retrieveData(). -
271 -
272 \li If the drag and drop operation occurs within a single -
273 application, we can subclass QMimeData and add extra data in -
274 it, and use a qobject_cast() in the receiver's drop event -
275 handler. For example: -
276 -
277 \snippet code/src_corelib_kernel_qmimedata.cpp 2 -
278 \endlist -
279 -
280 \section1 Platform-Specific MIME Types -
281 -
282 On Windows, formats() will also return custom formats available -
283 in the MIME data, using the \c{x-qt-windows-mime} subtype to -
284 indicate that they represent data in non-standard formats. -
285 The formats will take the following form: -
286 -
287 \snippet code/src_corelib_kernel_qmimedata.cpp 3 -
288 -
289 The following are examples of custom MIME types: -
290 -
291 \snippet code/src_corelib_kernel_qmimedata.cpp 4 -
292 -
293 The \c value declaration of each format describes the way in which the -
294 data is encoded. -
295 -
296 On Windows, the MIME format does not always map directly to the -
297 clipboard formats. Qt provides QWindowsMime to map clipboard -
298 formats to open-standard MIME formats. Similarly, the -
299 QMacPasteboardMime maps MIME to Mac flavors. -
300 -
301 \sa QClipboard, QDragEnterEvent, QDragMoveEvent, QDropEvent, QDrag, -
302 QWindowsMime, QMacPasteboardMime, {Drag and Drop} -
303*/ -
304 -
305/*! -
306 Constructs a new MIME data object with no data in it. -
307*/ -
308QMimeData::QMimeData() -
309 : QObject(*new QMimeDataPrivate, 0) -
310{ -
311}
executed: }
Execution Count:167
167
312 -
313/*! -
314 Destroys the MIME data object. -
315*/ -
316QMimeData::~QMimeData() -
317{ -
318} -
319 -
320/*! -
321 Returns a list of URLs contained within the MIME data object. -
322 -
323 URLs correspond to the MIME type \c text/uri-list. -
324 -
325 \sa hasUrls(), data() -
326*/ -
327QList<QUrl> QMimeData::urls() const -
328{ -
329 Q_D(const QMimeData);
executed (the execution status of this line is deduced): const QMimeDataPrivate * const d = d_func();
-
330 QVariant data = d->retrieveTypedData(QLatin1String("text/uri-list"), QVariant::List);
executed (the execution status of this line is deduced): QVariant data = d->retrieveTypedData(QLatin1String("text/uri-list"), QVariant::List);
-
331 QList<QUrl> urls;
executed (the execution status of this line is deduced): QList<QUrl> urls;
-
332 if (data.type() == QVariant::Url)
partially evaluated: data.type() == QVariant::Url
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
333 urls.append(data.toUrl());
never executed: urls.append(data.toUrl());
0
334 else if (data.type() == QVariant::List) {
partially evaluated: data.type() == QVariant::List
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
335 QList<QVariant> list = data.toList();
executed (the execution status of this line is deduced): QList<QVariant> list = data.toList();
-
336 for (int i = 0; i < list.size(); ++i) {
evaluated: i < list.size()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
337 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
338 urls.append(list.at(i).toUrl());
executed: urls.append(list.at(i).toUrl());
Execution Count:3
3
339 }
executed: }
Execution Count:3
3
340 }
executed: }
Execution Count:2
2
341 return urls;
executed: return urls;
Execution Count:2
2
342} -
343 -
344/*! -
345 Sets the URLs stored in the MIME data object to those specified by \a urls. -
346 -
347 URLs correspond to the MIME type \c text/uri-list. -
348 -
349 Since Qt 5.0, setUrls also exports the urls as plain text, if setText -
350 was not called before, to make it possible to drop them into any lineedit -
351 and text editor. -
352 -
353 \sa hasUrls(), setData() -
354*/ -
355void QMimeData::setUrls(const QList<QUrl> &urls) -
356{ -
357 Q_D(QMimeData);
executed (the execution status of this line is deduced): QMimeDataPrivate * const d = d_func();
-
358 QList<QVariant> list;
executed (the execution status of this line is deduced): QList<QVariant> list;
-
359 for (int i = 0; i < urls.size(); ++i)
evaluated: i < urls.size()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
360 list.append(urls.at(i));
executed: list.append(urls.at(i));
Execution Count:3
3
361 -
362 d->setData(QLatin1String("text/uri-list"), list);
executed (the execution status of this line is deduced): d->setData(QLatin1String("text/uri-list"), list);
-
363}
executed: }
Execution Count:2
2
364 -
365/*! -
366 Returns true if the object can return a list of urls; otherwise -
367 returns false. -
368 -
369 URLs correspond to the MIME type \c text/uri-list. -
370 -
371 \sa setUrls(), urls(), hasFormat() -
372*/ -
373bool QMimeData::hasUrls() const -
374{ -
375 return hasFormat(QLatin1String("text/uri-list"));
executed: return hasFormat(QLatin1String("text/uri-list"));
Execution Count:13
13
376} -
377 -
378 -
379/*! -
380 Returns a plain text (MIME type \c text/plain) representation of -
381 the data. -
382 -
383 \sa hasText(), html(), data() -
384*/ -
385QString QMimeData::text() const -
386{ -
387 Q_D(const QMimeData);
executed (the execution status of this line is deduced): const QMimeDataPrivate * const d = d_func();
-
388 QVariant data = d->retrieveTypedData(QLatin1String("text/plain"), QVariant::String);
executed (the execution status of this line is deduced): QVariant data = d->retrieveTypedData(QLatin1String("text/plain"), QVariant::String);
-
389 return data.toString();
executed: return data.toString();
Execution Count:51
51
390} -
391 -
392/*! -
393 Sets \a text as the plain text (MIME type \c text/plain) used to -
394 represent the data. -
395 -
396 \sa hasText(), setHtml(), setData() -
397*/ -
398void QMimeData::setText(const QString &text) -
399{ -
400 Q_D(QMimeData);
executed (the execution status of this line is deduced): QMimeDataPrivate * const d = d_func();
-
401 d->setData(QLatin1String("text/plain"), text);
executed (the execution status of this line is deduced): d->setData(QLatin1String("text/plain"), text);
-
402}
executed: }
Execution Count:30
30
403 -
404/*! -
405 Returns true if the object can return plain text (MIME type \c -
406 text/plain); otherwise returns false. -
407 -
408 \sa setText(), text(), hasHtml(), hasFormat() -
409*/ -
410bool QMimeData::hasText() const -
411{ -
412 return hasFormat(QLatin1String("text/plain")) || hasUrls();
executed: return hasFormat(QLatin1String("text/plain")) || hasUrls();
Execution Count:17
17
413} -
414 -
415/*! -
416 Returns a string if the data stored in the object is HTML (MIME -
417 type \c text/html); otherwise returns an empty string. -
418 -
419 \sa hasHtml(), setData() -
420*/ -
421QString QMimeData::html() const -
422{ -
423 Q_D(const QMimeData);
executed (the execution status of this line is deduced): const QMimeDataPrivate * const d = d_func();
-
424 QVariant data = d->retrieveTypedData(QLatin1String("text/html"), QVariant::String);
executed (the execution status of this line is deduced): QVariant data = d->retrieveTypedData(QLatin1String("text/html"), QVariant::String);
-
425 return data.toString();
executed: return data.toString();
Execution Count:3
3
426} -
427 -
428/*! -
429 Sets \a html as the HTML (MIME type \c text/html) used to -
430 represent the data. -
431 -
432 \sa hasHtml(), setText(), setData() -
433*/ -
434void QMimeData::setHtml(const QString &html) -
435{ -
436 Q_D(QMimeData);
executed (the execution status of this line is deduced): QMimeDataPrivate * const d = d_func();
-
437 d->setData(QLatin1String("text/html"), html);
executed (the execution status of this line is deduced): d->setData(QLatin1String("text/html"), html);
-
438}
executed: }
Execution Count:2
2
439 -
440/*! -
441 Returns true if the object can return HTML (MIME type \c -
442 text/html); otherwise returns false. -
443 -
444 \sa setHtml(), html(), hasFormat() -
445*/ -
446bool QMimeData::hasHtml() const -
447{ -
448 return hasFormat(QLatin1String("text/html"));
executed: return hasFormat(QLatin1String("text/html"));
Execution Count:11
11
449} -
450 -
451/*! -
452 Returns a QVariant storing a QImage if the object can return an -
453 image; otherwise returns a null variant. -
454 -
455 A QVariant is used because QMimeData belongs to the Qt Core -
456 module, whereas QImage belongs to Qt GUI. To convert the -
457 QVariant to a QImage, simply use qvariant_cast(). For example: -
458 -
459 \snippet code/src_corelib_kernel_qmimedata.cpp 5 -
460 -
461 \sa hasImage() -
462*/ -
463QVariant QMimeData::imageData() const -
464{ -
465 Q_D(const QMimeData);
executed (the execution status of this line is deduced): const QMimeDataPrivate * const d = d_func();
-
466 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
467} -
468 -
469/*! -
470 Sets the data in the object to the given \a image. -
471 -
472 A QVariant is used because QMimeData belongs to the Qt Core -
473 module, whereas QImage belongs to Qt GUI. The conversion -
474 from QImage to QVariant is implicit. For example: -
475 -
476 \snippet code/src_corelib_kernel_qmimedata.cpp 6 -
477 -
478 \sa hasImage(), setData() -
479*/ -
480void QMimeData::setImageData(const QVariant &image) -
481{ -
482 Q_D(QMimeData);
executed (the execution status of this line is deduced): QMimeDataPrivate * const d = d_func();
-
483 d->setData(QLatin1String("application/x-qt-image"), image);
executed (the execution status of this line is deduced): d->setData(QLatin1String("application/x-qt-image"), image);
-
484}
executed: }
Execution Count:2
2
485 -
486/*! -
487 Returns true if the object can return an image; otherwise returns -
488 false. -
489 -
490 \sa setImageData(), imageData(), hasFormat() -
491*/ -
492bool QMimeData::hasImage() const -
493{ -
494 return hasFormat(QLatin1String("application/x-qt-image"));
executed: return hasFormat(QLatin1String("application/x-qt-image"));
Execution Count:5
5
495} -
496 -
497/*! -
498 Returns a color if the data stored in the object represents a -
499 color (MIME type \c application/x-color); otherwise returns a -
500 null variant. -
501 -
502 A QVariant is used because QMimeData belongs to the Qt Core -
503 module, whereas QColor belongs to Qt GUI. To convert the -
504 QVariant to a QColor, simply use qvariant_cast(). For example: -
505 -
506 \snippet code/src_corelib_kernel_qmimedata.cpp 7 -
507 -
508 \sa hasColor(), setColorData(), data() -
509*/ -
510QVariant QMimeData::colorData() const -
511{ -
512 Q_D(const QMimeData);
executed (the execution status of this line is deduced): const QMimeDataPrivate * const d = d_func();
-
513 return d->retrieveTypedData(QLatin1String("application/x-color"), QVariant::Color);
executed: return d->retrieveTypedData(QLatin1String("application/x-color"), QVariant::Color);
Execution Count:2
2
514} -
515 -
516/*! -
517 Sets the color data in the object to the given \a color. -
518 -
519 Colors correspond to the MIME type \c application/x-color. -
520 -
521 \sa hasColor(), setData() -
522*/ -
523void QMimeData::setColorData(const QVariant &color) -
524{ -
525 Q_D(QMimeData);
executed (the execution status of this line is deduced): QMimeDataPrivate * const d = d_func();
-
526 d->setData(QLatin1String("application/x-color"), color);
executed (the execution status of this line is deduced): d->setData(QLatin1String("application/x-color"), color);
-
527}
executed: }
Execution Count:3
3
528 -
529 -
530/*! -
531 Returns true if the object can return a color (MIME type \c -
532 application/x-color); otherwise returns false. -
533 -
534 \sa setColorData(), colorData(), hasFormat() -
535*/ -
536bool QMimeData::hasColor() const -
537{ -
538 return hasFormat(QLatin1String("application/x-color"));
executed: return hasFormat(QLatin1String("application/x-color"));
Execution Count:6
6
539} -
540 -
541/*! -
542 Returns the data stored in the object in the format described by -
543 the MIME type specified by \a mimeType. -
544*/ -
545QByteArray QMimeData::data(const QString &mimeType) const -
546{ -
547 Q_D(const QMimeData);
executed (the execution status of this line is deduced): const QMimeDataPrivate * const d = d_func();
-
548 QVariant data = d->retrieveTypedData(mimeType, QVariant::ByteArray);
executed (the execution status of this line is deduced): QVariant data = d->retrieveTypedData(mimeType, QVariant::ByteArray);
-
549 return data.toByteArray();
executed: return data.toByteArray();
Execution Count:27
27
550} -
551 -
552/*! -
553 Sets the data associated with the MIME type given by \a mimeType -
554 to the specified \a data. -
555 -
556 For the most common types of data, you can call the higher-level -
557 functions setText(), setHtml(), setUrls(), setImageData(), and -
558 setColorData() instead. -
559 -
560 Note that if you want to use a custom data type in an item view drag and drop -
561 operation, you must register it as a Qt \l{QMetaType}{meta type}, using the -
562 Q_DECLARE_METATYPE() macro, and implement stream operators for it. The stream -
563 operators must then be registered with the qRegisterMetaTypeStreamOperators() -
564 function. -
565 -
566 \sa hasFormat(), QMetaType, qRegisterMetaTypeStreamOperators() -
567*/ -
568void QMimeData::setData(const QString &mimeType, const QByteArray &data) -
569{ -
570 Q_D(QMimeData);
executed (the execution status of this line is deduced): QMimeDataPrivate * const d = d_func();
-
571 d->setData(mimeType, QVariant(data));
executed (the execution status of this line is deduced): d->setData(mimeType, QVariant(data));
-
572}
executed: }
Execution Count:37
37
573 -
574/*! -
575 Returns true if the object can return data for the MIME type -
576 specified by \a mimeType; otherwise returns false. -
577 -
578 For the most common types of data, you can call the higher-level -
579 functions hasText(), hasHtml(), hasUrls(), hasImage(), and -
580 hasColor() instead. -
581 -
582 \sa formats(), setData(), data() -
583*/ -
584bool QMimeData::hasFormat(const QString &mimeType) const -
585{ -
586 return formats().contains(mimeType);
executed: return formats().contains(mimeType);
Execution Count:72
72
587} -
588 -
589/*! -
590 Returns a list of formats supported by the object. This is a list -
591 of MIME types for which the object can return suitable data. The -
592 formats in the list are in a priority order. -
593 -
594 For the most common types of data, you can call the higher-level -
595 functions hasText(), hasHtml(), hasUrls(), hasImage(), and -
596 hasColor() instead. -
597 -
598 \sa hasFormat(), setData(), data() -
599*/ -
600QStringList QMimeData::formats() const -
601{ -
602 Q_D(const QMimeData);
executed (the execution status of this line is deduced): const QMimeDataPrivate * const d = d_func();
-
603 QStringList list;
executed (the execution status of this line is deduced): QStringList list;
-
604 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
605 list += d->dataList.at(i).format;
executed: list += d->dataList.at(i).format;
Execution Count:55
55
606 return list;
executed: return list;
Execution Count:72
72
607} -
608 -
609/*! -
610 Returns a variant with the given \a type containing data for the -
611 MIME type specified by \a mimeType. If the object does not -
612 support the MIME type or variant type given, a null variant is -
613 returned instead. -
614 -
615 This function is called by the general data() getter and by the -
616 convenience getters (text(), html(), urls(), imageData(), and -
617 colorData()). You can reimplement it if you want to store your -
618 data using a custom data structure (instead of a QByteArray, -
619 which is what setData() provides). You would then also need -
620 to reimplement hasFormat() and formats(). -
621 -
622 \sa data() -
623*/ -
624QVariant QMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const -
625{ -
626 Q_UNUSED(type);
executed (the execution status of this line is deduced): (void)type;;
-
627 Q_D(const QMimeData);
executed (the execution status of this line is deduced): const QMimeDataPrivate * const d = d_func();
-
628 return d->getData(mimeType);
executed: return d->getData(mimeType);
Execution Count:92
92
629} -
630 -
631/*! -
632 Removes all the MIME type and data entries in the object. -
633*/ -
634void QMimeData::clear() -
635{ -
636 Q_D(QMimeData);
executed (the execution status of this line is deduced): QMimeDataPrivate * const d = d_func();
-
637 d->dataList.clear();
executed (the execution status of this line is deduced): d->dataList.clear();
-
638}
executed: }
Execution Count:13
13
639 -
640/*! -
641 \since 4.4 -
642 -
643 Removes the data entry for \a mimeType in the object. -
644*/ -
645void QMimeData::removeFormat(const QString &mimeType) -
646{ -
647 Q_D(QMimeData);
executed (the execution status of this line is deduced): QMimeDataPrivate * const d = d_func();
-
648 d->removeData(mimeType);
executed (the execution status of this line is deduced): d->removeData(mimeType);
-
649}
executed: }
Execution Count:2
2
650 -
651QT_END_NAMESPACE -
652 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial