Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.8.1
-
None
Description
In my application, I wish to handle tiff clipboard data (of UTI type public.tiff) different than the implementation in QMacPasteboardMimeTiff (I don't want the data to pass through a QImage).
I have written my own subclass of QMacPasteboardMime that does exactly what I want, and it works correctly.
The documentation of QMacPasteboardMime (http://qt-project.org/doc/qt-4.8/qmacpasteboardmime.html) states:
"When working with MIME data, Qt will interate through all instances of QMacPasteboardMime to find an instance that can convert to, or from, a specific MIME type. It will do this by calling canConvert() on each instance, starting with (and choosing) the last created instance first. The actual conversions will be done by using convertToMime() and convertFromMime()."
I am instantiating my subclass of QMacPasteboardMime (call it MyMacPasteboardMimeTiff) after my application's QApplication object is created (the base QMacPasteboardMime class is created in the QApplication initialization code).
My problem is that my MyMacPasteboardMimeTiff::mimeFor(), canConvert(), etc. methods never get called. This is because QMacPasteboardMime::flavorToMime(), which gets called when QMimeData::formats() is called, uses this code:
QString QMacPasteboardMime::flavorToMime(uchar t, QString flav) { MimeList *mimes = globalMimeList(); for(MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) { #ifdef DEBUG_MIME_MAPS qDebug("QMacMIme::flavorToMime: attempting %s (%d) for flavor %d[%c%c%c%c] [%s]", (*it)->convertorName().toLatin1().constData(), (*it)->type & t, flav, (flav >> 24) & 0xFF, (flav >> 16) & 0xFF, (flav >> 8) & 0xFF, (flav) & 0xFF, (*it)->mimeFor(flav).toLatin1().constData()); #endif if((*it)->type & t) { QString mimeType = (*it)->mimeFor(flav); if(!mimeType.isNull()) return mimeType; } } return QString(); }
So contrary to what the documentation states/implies, QMacPasteboardMimeTiff::mimeFor() ends up getting called before MyMacPasteboardMimeTiff::mimeFor() gets called. Since QMacPasteboardMimeTiff supports the public.tiff UTI, it ends up being used to do the conversion from the clipboard's data to MIME data.
The Windows class that is equivalent to QMacPasteboardMime, QWindowsMime, does iterate from the last instantiated subclass to the first, allowing me to override the handling of any clipboard type.