From 8f3e24c17d6aab9f95bd4dcfb28fc67b3a2768c0 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 31 Oct 2022 18:01:56 +0100 Subject: [PATCH] Clean up QMacMimeRegistry: remove convertor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's not called anywhere, we always get all convertors and iterate over them to find the best match for the relevant context. Change those loops to use ranged for. Task-number: QTBUG-93632 Change-Id: Icb450ca56310a0acab881899234ac647792ce0c9 Reviewed-by: Tor Arne Vestbø Reviewed-by: Timur Pocheptsov --- src/gui/platform/darwin/qmacmimeregistry.mm | 18 ------------------ src/gui/platform/darwin/qmacmimeregistry_p.h | 1 - src/plugins/platforms/cocoa/qmacclipboard.mm | 10 ++++------ 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/gui/platform/darwin/qmacmimeregistry.mm b/src/gui/platform/darwin/qmacmimeregistry.mm index bf69a117b2..14c2ce9978 100644 --- a/src/gui/platform/darwin/qmacmimeregistry.mm +++ b/src/gui/platform/darwin/qmacmimeregistry.mm @@ -77,24 +77,6 @@ void destroyMimeTypes() delete mimes->takeFirst(); } -/* - Returns the most-recently created QMacPasteboardMime of type \a t that can convert - between the \a mime and \a flav formats. Returns 0 if no such convertor - exists. -*/ -QMacInternalPasteboardMime *convertor(uchar t, const QString &mime, QString flav) -{ - MimeList *mimes = globalMimeList(); - for (MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) { -#ifdef DEBUG_MIME_MAPS - qDebug("QMacMimeRegistry::convertor: seeing if converter(%d) can convert %s to %s [%d]", - (*it)->type() & t, qPrintable(mime), qPrintable(flav), (*it)->canConvert(mime,flav)); -#endif - if (((*it)->type() & t) && (*it)->canConvert(mime, flav)) - return (*it); - } - return 0; -} /* Returns a MIME type of type \a t for \a flav, or 0 if none exists. */ diff --git a/src/gui/platform/darwin/qmacmimeregistry_p.h b/src/gui/platform/darwin/qmacmimeregistry_p.h index 8e2a3f7d7a..32dcd221a5 100644 --- a/src/gui/platform/darwin/qmacmimeregistry_p.h +++ b/src/gui/platform/darwin/qmacmimeregistry_p.h @@ -32,7 +32,6 @@ namespace QMacMimeRegistry { Q_GUI_EXPORT void unregisterMimeConverter(QMacInternalPasteboardMime *); Q_GUI_EXPORT QList all(uchar); - Q_GUI_EXPORT QMacInternalPasteboardMime *convertor(uchar, const QString &mime, QString flav); Q_GUI_EXPORT QString flavorToMime(uchar, QString flav); Q_GUI_EXPORT void registerDraggedTypes(const QStringList &types); diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm index 6adc2ce145..9900d0e6a9 100644 --- a/src/plugins/platforms/cocoa/qmacclipboard.mm +++ b/src/plugins/platforms/cocoa/qmacclipboard.mm @@ -299,7 +299,7 @@ QMacPasteboard::setMimeData(QMimeData *mime_src, DataRequestType dataRequestType delete mime; mime = mime_src; - QList availableConverters = QMacMimeRegistry::all(mime_type); + const QList availableConverters = QMacMimeRegistry::all(mime_type); if (mime != nullptr) { clear_helper(); QStringList formats = mime_src->formats(); @@ -316,8 +316,7 @@ QMacPasteboard::setMimeData(QMimeData *mime_src, DataRequestType dataRequestType } for (int f = 0; f < formats.size(); ++f) { QString mimeType = formats.at(f); - for (QList::Iterator it = availableConverters.begin(); it != availableConverters.end(); ++it) { - QMacInternalPasteboardMime *c = (*it); + for (auto *c : availableConverters) { // Hack: The Rtf handler converts incoming Rtf to Html. We do // not want to convert outgoing Html to Rtf but instead keep // posting it as Html. Skip the Rtf handler here. @@ -434,9 +433,8 @@ QMacPasteboard::retrieveData(const QString &format, QMetaType) const return QByteArray(); qCDebug(lcQpaClipboard, "Pasteboard: retrieveData [%s]", qPrintable(format)); - const QList mimes = QMacMimeRegistry::all(mime_type); - for (int mime = 0; mime < mimes.size(); ++mime) { - QMacInternalPasteboardMime *c = mimes.at(mime); + const QList availableConverters = QMacMimeRegistry::all(mime_type); + for (const auto *c : availableConverters) { QString c_flavor = c->flavorFor(format); if (!c_flavor.isEmpty()) { // Converting via PasteboardCopyItemFlavorData below will for some UITs result