iOS: add support for adding mimetypes other than text on the clipboard
A QVariant can only be converted to a QByteArray if it has user type
QMetaType::QByteArray or QMetaType::QString. The way it stood, we
always tried to convert the mime data to a QByteArray, and
then put the result into a QVariant. This would fail if the mime
data contained e.g a QPixmap.
This patch will inspect what kind of data the QMimeData contains, and
convert it to a QVariant using the expected API.
Backport of 6d3c483
Task-number: QTBUG-57428
Task-number: QTBUG-63660
Change-Id: I09b4a94aef7b52773e1a79c468ead71b36dfbfc5
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
parent
fc98878658
commit
6c1a2224f3
|
|
@ -227,7 +227,19 @@ void QIOSClipboard::setMimeData(QMimeData *mimeData, QClipboard::Mode mode)
|
|||
if (uti.isEmpty() || !converter->canConvert(mimeType, uti))
|
||||
continue;
|
||||
|
||||
QByteArray byteArray = converter->convertFromMime(mimeType, mimeData->data(mimeType), uti).first();
|
||||
QVariant mimeDataAsVariant;
|
||||
if (mimeData->hasImage()) {
|
||||
mimeDataAsVariant = mimeData->imageData();
|
||||
} else if (mimeData->hasUrls()) {
|
||||
QVariantList urlList;
|
||||
for (const QUrl &url : mimeData->urls())
|
||||
urlList << url;
|
||||
mimeDataAsVariant = QVariant(urlList);
|
||||
} else {
|
||||
mimeDataAsVariant = QVariant(mimeData->data(mimeType));
|
||||
}
|
||||
|
||||
QByteArray byteArray = converter->convertFromMime(mimeType, mimeDataAsVariant, uti).first();
|
||||
NSData *nsData = [NSData dataWithBytes:byteArray.constData() length:byteArray.size()];
|
||||
[pbItem setValue:nsData forKey:uti.toNSString()];
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue