summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qiosclipboard.mm
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2017-03-31 14:08:28 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2017-04-18 08:22:38 +0000
commit6d3c4833c26cced876ed57e9f158fbade5b2679c (patch)
tree1fa9a93cf4e6d4a8f0b6a468ce8e0270a14d98ff /src/plugins/platforms/ios/qiosclipboard.mm
parent7fffc04335fa63e754655bd15ff4286837d1737b (diff)
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. Task-number: QTBUG-57428 Change-Id: I67054424fe8c45873bab8305e7b44de939aae0fb Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/ios/qiosclipboard.mm')
-rw-r--r--src/plugins/platforms/ios/qiosclipboard.mm14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/plugins/platforms/ios/qiosclipboard.mm b/src/plugins/platforms/ios/qiosclipboard.mm
index ef3b453bbf..15deb3332e 100644
--- a/src/plugins/platforms/ios/qiosclipboard.mm
+++ b/src/plugins/platforms/ios/qiosclipboard.mm
@@ -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 (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;