diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-05-08 13:14:09 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-09 13:40:23 +0200 |
commit | 4e4403d69c60ea6429b3ad5e7898a84b1dc92be5 (patch) | |
tree | 4d8c3f222412438643fe54508036a452c6967152 /src/gui/image | |
parent | b316c3ac5e4acac75505bfd77677cecc181599af (diff) |
No longer use deprecated methods for plugin loading.
Change-Id: I19c66b1c41ea4dd236726c86d7d071b210ec9244
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/gui/image')
-rw-r--r-- | src/gui/image/qimagereader.cpp | 59 | ||||
-rw-r--r-- | src/gui/image/qimagewriter.cpp | 54 | ||||
-rw-r--r-- | src/gui/image/qpicture.cpp | 14 |
3 files changed, 85 insertions, 42 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index fe14a45dcb..02c01f9866 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -224,15 +224,18 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, QImageIOHandler *handler = 0; #ifndef QT_NO_LIBRARY + typedef QMultiMap<int, QString> PluginKeyMap; + typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; + // check if we have plugins that support the image format QFactoryLoader *l = loader(); - QStringList keys = l->keys(); + const PluginKeyMap keyMap = l->keyMap(); #endif QByteArray suffix; #ifdef QIMAGEREADER_DEBUG qDebug() << "QImageReader::createReadHandler( device =" << (void *)device << ", format =" << format << ")," - << keys.size() << "plugins available: " << keys; + << keyMap.values().size() << "plugins available: " << keyMap.values(); #endif #ifndef QT_NO_LIBRARY @@ -246,7 +249,7 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, qDebug() << "QImageReader::createReadHandler: device is a file:" << file->fileName(); #endif if (!(suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1()).isEmpty()) { - int index = keys.indexOf(QString::fromLatin1(suffix)); + const int index = keyMap.key(QString::fromLatin1(suffix), -1); if (index != -1) { #ifdef QIMAGEREADER_DEBUG qDebug() << "QImageReader::createReadHandler: suffix recognized; the" @@ -269,13 +272,16 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, // check if the plugin that claims support for this format can load // from this device with this format. const qint64 pos = device ? device->pos() : 0; - QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(QString::fromLatin1(suffix))); - if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) { - handler = plugin->create(device, testFormat); + const int index = keyMap.key(QString::fromLatin1(suffix), -1); + if (index != -1) { + QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(index)); + if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) { + handler = plugin->create(device, testFormat); #ifdef QIMAGEREADER_DEBUG - qDebug() << "QImageReader::createReadHandler: using the" << suffix - << "plugin"; + qDebug() << "QImageReader::createReadHandler: using the" << suffix + << "plugin"; #endif + } } if (device && !device->isSequential()) device->seek(pos); @@ -287,9 +293,10 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, const qint64 pos = device ? device->pos() : 0; if (autoDetectImageFormat) { - for (int i = 0; i < keys.size(); ++i) { + const int keyCount = keyMap.keys().size(); + for (int i = 0; i < keyCount; ++i) { if (i != suffixPluginIndex) { - QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i))); + QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i)); if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) { #ifdef QIMAGEREADER_DEBUG qDebug() << "QImageReader::createReadHandler: the" << keys.at(i) << "plugin can read this format"; @@ -300,12 +307,15 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, } } } else { - QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(QLatin1String(testFormat))); - if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) { + const int testIndex = keyMap.key(QLatin1String(testFormat), -1); + if (testIndex != -1) { + QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(testIndex)); + if (plugin && plugin->capabilities(device, testFormat) & QImageIOPlugin::CanRead) { #ifdef QIMAGEREADER_DEBUG - qDebug() << "QImageReader::createReadHandler: the" << testFormat << "plugin can read this format"; + qDebug() << "QImageReader::createReadHandler: the" << testFormat << "plugin can read this format"; #endif - handler = plugin->create(device, testFormat); + handler = plugin->create(device, testFormat); + } } } if (device && !device->isSequential()) @@ -363,9 +373,10 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device, if (!handler && (autoDetectImageFormat || ignoresFormatAndExtension)) { // check if any of our plugins recognize the file from its contents. const qint64 pos = device ? device->pos() : 0; - for (int i = 0; i < keys.size(); ++i) { + const int keyCount = keyMap.keys().size(); + for (int i = 0; i < keyCount; ++i) { if (i != suffixPluginIndex) { - QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i))); + QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i)); if (plugin && plugin->capabilities(device, QByteArray()) & QImageIOPlugin::CanRead) { handler = plugin->create(device, testFormat); #ifdef QIMAGEREADER_DEBUG @@ -1413,6 +1424,12 @@ QByteArray QImageReader::imageFormat(QIODevice *device) return format; } +#ifndef QT_NO_LIBRARY +void supportedImageHandlerFormats(QFactoryLoader *loader, + QImageIOPlugin::Capability cap, + QSet<QByteArray> *result); +#endif + /*! Returns the list of image formats supported by QImageReader. @@ -1442,6 +1459,7 @@ QByteArray QImageReader::imageFormat(QIODevice *device) \sa setFormat(), QImageWriter::supportedImageFormats(), QImageIOPlugin */ + QList<QByteArray> QImageReader::supportedImageFormats() { QSet<QByteArray> formats; @@ -1449,14 +1467,7 @@ QList<QByteArray> QImageReader::supportedImageFormats() formats << _qt_BuiltInFormats[i].extension; #ifndef QT_NO_LIBRARY - QFactoryLoader *l = loader(); - QStringList keys = l->keys(); - - for (int i = 0; i < keys.count(); ++i) { - QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i))); - if (plugin && plugin->capabilities(0, keys.at(i).toLatin1()) & QImageIOPlugin::CanRead) - formats << keys.at(i).toLatin1(); - } + supportedImageHandlerFormats(loader(), QImageIOPlugin::CanRead, &formats); #endif // QT_NO_LIBRARY QList<QByteArray> sortedFormats; diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp index 8395f9d216..43a93d75c2 100644 --- a/src/gui/image/qimagewriter.cpp +++ b/src/gui/image/qimagewriter.cpp @@ -136,9 +136,12 @@ static QImageIOHandler *createWriteHandlerHelper(QIODevice *device, QImageIOHandler *handler = 0; #ifndef QT_NO_LIBRARY + typedef QMultiMap<int, QString> PluginKeyMap; + typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; + // check if any plugins can write the image QFactoryLoader *l = loader(); - QStringList keys = l->keys(); + const PluginKeyMap keyMap = l->keyMap(); int suffixPluginIndex = -1; #endif @@ -149,7 +152,7 @@ static QImageIOHandler *createWriteHandlerHelper(QIODevice *device, if (QFile *file = qobject_cast<QFile *>(device)) { if (!(suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1()).isEmpty()) { #ifndef QT_NO_LIBRARY - int index = keys.indexOf(QString::fromLatin1(suffix)); + const int index = keyMap.key(QString::fromLatin1(suffix), -1); if (index != -1) suffixPluginIndex = index; #endif @@ -163,9 +166,12 @@ static QImageIOHandler *createWriteHandlerHelper(QIODevice *device, if (suffixPluginIndex != -1) { // when format is missing, check if we can find a plugin for the // suffix. - QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(QString::fromLatin1(suffix))); - if (plugin && (plugin->capabilities(device, suffix) & QImageIOPlugin::CanWrite)) - handler = plugin->create(device, suffix); + const int index = keyMap.key(QString::fromLatin1(suffix), -1); + if (index != -1) { + QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(index)); + if (plugin && (plugin->capabilities(device, suffix) & QImageIOPlugin::CanWrite)) + handler = plugin->create(device, suffix); + } } #endif // QT_NO_LIBRARY @@ -210,8 +216,9 @@ static QImageIOHandler *createWriteHandlerHelper(QIODevice *device, #ifndef QT_NO_LIBRARY if (!testFormat.isEmpty()) { - for (int i = 0; i < keys.size(); ++i) { - QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i))); + const int keyCount = keyMap.keys().size(); + for (int i = 0; i < keyCount; ++i) { + QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(i)); if (plugin && (plugin->capabilities(device, testFormat) & QImageIOPlugin::CanWrite)) { delete handler; handler = plugin->create(device, testFormat); @@ -647,6 +654,31 @@ bool QImageWriter::supportsOption(QImageIOHandler::ImageOption option) const return d->handler->supportsOption(option); } + +#ifndef QT_NO_LIBRARY +void supportedImageHandlerFormats(QFactoryLoader *loader, + QImageIOPlugin::Capability cap, + QSet<QByteArray> *result) +{ + typedef QMultiMap<int, QString> PluginKeyMap; + typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; + + const PluginKeyMap keyMap = loader->keyMap(); + const PluginKeyMapConstIterator cend = keyMap.constEnd(); + int i = -1; + QImageIOPlugin *plugin = 0; + for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) { + if (it.key() != i) { + i = it.key(); + plugin = qobject_cast<QImageIOPlugin *>(loader->instance(i)); + } + const QByteArray key = it.value().toLatin1(); + if (plugin && (plugin->capabilities(0, key) & cap) != 0) + result->insert(key); + } +} +#endif // QT_NO_LIBRARY + /*! Returns the list of image formats supported by QImageWriter. @@ -696,13 +728,7 @@ QList<QByteArray> QImageWriter::supportedImageFormats() #endif #ifndef QT_NO_LIBRARY - QFactoryLoader *l = loader(); - QStringList keys = l->keys(); - for (int i = 0; i < keys.count(); ++i) { - QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(keys.at(i))); - if (plugin && (plugin->capabilities(0, keys.at(i).toLatin1()) & QImageIOPlugin::CanWrite) != 0) - formats << keys.at(i).toLatin1(); - } + supportedImageHandlerFormats(loader(), QImageIOPlugin::CanWrite, &formats); #endif // QT_NO_LIBRARY QList<QByteArray> sortedFormats; diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 8bb9f211e8..0544d3d431 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -1400,14 +1400,20 @@ Q_GLOBAL_STATIC(QPHList, pictureHandlers) void qt_init_picture_plugins() { #ifndef QT_NO_LIBRARY + typedef QMultiMap<int, QString> PluginKeyMap; + typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; + static QBasicMutex mutex; QMutexLocker locker(&mutex); static QFactoryLoader loader(QPictureFormatInterface_iid, QStringLiteral("/pictureformats")); - QStringList keys = loader.keys(); - for (int i = 0; i < keys.count(); ++i) - if (QPictureFormatInterface *format = qobject_cast<QPictureFormatInterface*>(loader.instance(keys.at(i)))) - format->installIOHandler(keys.at(i)); + + const PluginKeyMap keyMap = loader.keyMap(); + const PluginKeyMapConstIterator cend = keyMap.constEnd(); + for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) { + if (QPictureFormatInterface *format = qobject_cast<QPictureFormatInterface*>(loader.instance(it.key()))) + format->installIOHandler(it.value()); + } #endif } |