summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/accessible/qaccessible.cpp23
-rw-r--r--src/gui/accessible/qplatformaccessibility_qpa.cpp22
-rw-r--r--src/gui/image/qimagereader.cpp59
-rw-r--r--src/gui/image/qimagewriter.cpp54
-rw-r--r--src/gui/image/qpicture.cpp14
-rw-r--r--src/gui/kernel/qgenericpluginfactory_qpa.cpp19
-rw-r--r--src/gui/kernel/qplatformintegrationfactory_qpa.cpp36
-rw-r--r--src/gui/kernel/qplatformthemefactory_qpa.cpp34
-rw-r--r--src/network/bearer/qnetworkconfigmanager_p.cpp17
-rw-r--r--src/printsupport/kernel/qplatformprintplugin.cpp10
-rw-r--r--src/sql/kernel/qsqldatabase.cpp19
-rw-r--r--src/widgets/kernel/qicon.cpp28
-rw-r--r--src/widgets/kernel/qiconloader.cpp2
-rw-r--r--src/widgets/styles/qstylefactory.cpp17
14 files changed, 204 insertions, 150 deletions
diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp
index af75693ca2..b84ecefd73 100644
--- a/src/gui/accessible/qaccessible.cpp
+++ b/src/gui/accessible/qaccessible.cpp
@@ -570,35 +570,28 @@ QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectH
QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
{
accessibility_active = true;
- QAccessibleInterface *iface = 0;
if (!object)
return 0;
const QMetaObject *mo = object->metaObject();
while (mo) {
- const QLatin1String cn(mo->className());
+ const QString cn = QLatin1String(mo->className());
for (int i = qAccessibleFactories()->count(); i > 0; --i) {
InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
- iface = factory(cn, object);
- if (iface)
+ if (QAccessibleInterface *iface = factory(cn, object))
return iface;
}
#ifndef QT_NO_LIBRARY
- QAccessibleFactoryInterface *factory = qobject_cast<QAccessibleFactoryInterface*>(loader()->instance(cn));
- if (factory) {
- iface = factory->create(cn, object);
- if (iface)
- return iface;
- }
+ if (QAccessibleInterface * iface = qLoadPlugin1<QAccessibleInterface, QAccessibleFactoryInterface>(loader(), cn, object))
+ return iface;
#endif
mo = mo->superClass();
}
- if (!iface) {
- if (object == qApp)
- iface = new QAccessibleApplication;
- }
- return iface;
+ if (object == qApp)
+ return new QAccessibleApplication;
+
+ return 0;
}
/*!
diff --git a/src/gui/accessible/qplatformaccessibility_qpa.cpp b/src/gui/accessible/qplatformaccessibility_qpa.cpp
index 7ea5a5d2c8..271f324000 100644
--- a/src/gui/accessible/qplatformaccessibility_qpa.cpp
+++ b/src/gui/accessible/qplatformaccessibility_qpa.cpp
@@ -112,15 +112,21 @@ void QPlatformAccessibility::initialize()
isInit = true; // ### not atomic
#ifndef QT_NO_LIBRARY
- const QStringList l = bridgeloader()->keys();
- for (int i = 0; i < l.count(); ++i) {
- if (QAccessibleBridgeFactoryInterface *factory =
- qobject_cast<QAccessibleBridgeFactoryInterface*>(bridgeloader()->instance(l.at(i)))) {
- QAccessibleBridge * bridge = factory->create(l.at(i));
- if (bridge) {
- bridges()->append(bridge);
- }
+ typedef QMultiMap<int, QString> PluginKeyMap;
+ typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;
+
+ const PluginKeyMap keyMap = bridgeloader()->keyMap();
+ QAccessibleBridgeFactoryInterface *factory = 0;
+ int i = -1;
+ const PluginKeyMapConstIterator cend = keyMap.constEnd();
+ for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) {
+ if (it.key() != i) {
+ i = it.key();
+ factory = qobject_cast<QAccessibleBridgeFactoryInterface*>(bridgeloader()->instance(i));
}
+ if (factory)
+ if (QAccessibleBridge *bridge = factory->create(it.value()))
+ bridges()->append(bridge);
}
#endif
}
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
}
diff --git a/src/gui/kernel/qgenericpluginfactory_qpa.cpp b/src/gui/kernel/qgenericpluginfactory_qpa.cpp
index d4a7a9c20e..90da16f868 100644
--- a/src/gui/kernel/qgenericpluginfactory_qpa.cpp
+++ b/src/gui/kernel/qgenericpluginfactory_qpa.cpp
@@ -79,12 +79,12 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
*/
QObject *QGenericPluginFactory::create(const QString& key, const QString &specification)
{
- QString driver = key.toLower();
+ const QString driver = key.toLower();
#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
#ifndef QT_NO_LIBRARY
- if (QGenericPluginFactoryInterface *factory = qobject_cast<QGenericPluginFactoryInterface*>(loader()->instance(driver)))
- return factory->create(driver, specification);
+ if (QObject *object = qLoadPlugin1<QObject, QGenericPluginFactoryInterface>(loader(), driver, specification))
+ return object;
#endif
#endif
return 0;
@@ -101,11 +101,14 @@ QStringList QGenericPluginFactory::keys()
#if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
#ifndef QT_NO_LIBRARY
- QStringList plugins = loader()->keys();
- for (int i = 0; i < plugins.size(); ++i) {
- if (!list.contains(plugins.at(i)))
- list += plugins.at(i);
- }
+ typedef QMultiMap<int, QString> PluginKeyMap;
+ typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;
+
+ const PluginKeyMap keyMap = loader()->keyMap();
+ const PluginKeyMapConstIterator cend = keyMap.constEnd();
+ for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it)
+ if (!list.contains(it.value()))
+ list += it.value();
#endif //QT_NO_LIBRARY
#endif //QT_MAKEDLL
return list;
diff --git a/src/gui/kernel/qplatformintegrationfactory_qpa.cpp b/src/gui/kernel/qplatformintegrationfactory_qpa.cpp
index 2092f2d0ba..3b05742f09 100644
--- a/src/gui/kernel/qplatformintegrationfactory_qpa.cpp
+++ b/src/gui/kernel/qplatformintegrationfactory_qpa.cpp
@@ -43,6 +43,7 @@
#include <qpa/qplatformintegrationplugin.h>
#include "private/qfactoryloader_p.h"
#include "qmutex.h"
+#include "qdir.h"
#include "qguiapplication.h"
#include "qdebug.h"
@@ -58,26 +59,20 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader,
QPlatformIntegration *QPlatformIntegrationFactory::create(const QString& key, const QString &platformPluginPath)
{
- QPlatformIntegration *ret = 0;
QStringList paramList = key.split(QLatin1Char(':'));
- QString platform = paramList.takeFirst().toLower();
+ const QString platform = paramList.takeFirst().toLower();
#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
// Try loading the plugin from platformPluginPath first:
if (!platformPluginPath.isEmpty()) {
QCoreApplication::addLibraryPath(platformPluginPath);
- if (QPlatformIntegrationFactoryInterface *factory =
- qobject_cast<QPlatformIntegrationFactoryInterface*>(directLoader()->instance(platform)))
- ret = factory->create(key, paramList);
-
- if (ret)
+ if (QPlatformIntegration *ret = qLoadPlugin1<QPlatformIntegration, QPlatformIntegrationFactoryInterface >(directLoader(), platform, paramList))
return ret;
}
- if (QPlatformIntegrationFactoryInterface *factory = qobject_cast<QPlatformIntegrationFactoryInterface*>(loader()->instance(platform)))
- ret = factory->create(platform, paramList);
+ if (QPlatformIntegration *ret = qLoadPlugin1<QPlatformIntegration, QPlatformIntegrationFactoryInterface >(loader(), platform, paramList))
+ return ret;
#endif
-
- return ret;
+ return 0;
}
/*!
@@ -86,23 +81,28 @@ QPlatformIntegration *QPlatformIntegrationFactory::create(const QString& key, co
\sa create()
*/
+
QStringList QPlatformIntegrationFactory::keys(const QString &platformPluginPath)
{
#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
QStringList list;
-
if (!platformPluginPath.isEmpty()) {
QCoreApplication::addLibraryPath(platformPluginPath);
- foreach (const QString &key, directLoader()->keys()) {
- list += key + QString(QLatin1String(" (from %1)")).arg(platformPluginPath);
+ list = directLoader()->keyMap().values();
+ if (!list.isEmpty()) {
+ const QString postFix = QStringLiteral(" (from ")
+ + QDir::toNativeSeparators(platformPluginPath)
+ + QLatin1Char(')');
+ const QStringList::iterator end = list.end();
+ for (QStringList::iterator it = list.begin(); it != end; ++it)
+ (*it).append(postFix);
}
}
-
- list += loader()->keys();
+ list.append(loader()->keyMap().values());
+ return list;
#else
- QStringList list;
+ return QStringList();
#endif
- return list;
}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformthemefactory_qpa.cpp b/src/gui/kernel/qplatformthemefactory_qpa.cpp
index 8294591c4b..c809a7fba3 100644
--- a/src/gui/kernel/qplatformthemefactory_qpa.cpp
+++ b/src/gui/kernel/qplatformthemefactory_qpa.cpp
@@ -41,6 +41,7 @@
#include <qpa/qplatformthemefactory_p.h>
#include <qpa/qplatformthemeplugin.h>
+#include <QDir>
#include "private/qfactoryloader_p.h"
#include "qmutex.h"
@@ -58,26 +59,20 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader,
QPlatformTheme *QPlatformThemeFactory::create(const QString& key, const QString &platformPluginPath)
{
- QPlatformTheme *ret = 0;
QStringList paramList = key.split(QLatin1Char(':'));
- QString platform = paramList.takeFirst().toLower();
+ const QString platform = paramList.takeFirst().toLower();
#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
// Try loading the plugin from platformPluginPath first:
if (!platformPluginPath.isEmpty()) {
QCoreApplication::addLibraryPath(platformPluginPath);
- if (QPlatformThemeFactoryInterface *factory =
- qobject_cast<QPlatformThemeFactoryInterface*>(directLoader()->instance(platform)))
- ret = factory->create(key, paramList);
-
- if (ret)
+ if (QPlatformTheme *ret = qLoadPlugin1<QPlatformTheme, QPlatformThemeFactoryInterface>(directLoader(), platform, paramList))
return ret;
}
- if (QPlatformThemeFactoryInterface *factory = qobject_cast<QPlatformThemeFactoryInterface*>(loader()->instance(platform)))
- ret = factory->create(platform, paramList);
+ if (QPlatformTheme *ret = qLoadPlugin1<QPlatformTheme, QPlatformThemeFactoryInterface>(loader(), platform, paramList))
+ return ret;
#endif
-
- return ret;
+ return 0;
}
/*!
@@ -93,16 +88,21 @@ QStringList QPlatformThemeFactory::keys(const QString &platformPluginPath)
if (!platformPluginPath.isEmpty()) {
QCoreApplication::addLibraryPath(platformPluginPath);
- foreach (const QString &key, directLoader()->keys()) {
- list += key + QString(QLatin1String(" (from %1)")).arg(platformPluginPath);
+ list += directLoader()->keyMap().values();
+ if (!list.isEmpty()) {
+ const QString postFix = QStringLiteral(" (from ")
+ + QDir::toNativeSeparators(platformPluginPath)
+ + QLatin1Char(')');
+ const QStringList::iterator end = list.end();
+ for (QStringList::iterator it = list.begin(); it != end; ++it)
+ (*it).append(postFix);
}
}
-
- list += loader()->keys();
+ list += loader()->keyMap().values();
+ return list;
#else
- QStringList list;
+ return QStringList();
#endif
- return list;
}
QT_END_NAMESPACE
diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp
index 527e55008e..ce04934865 100644
--- a/src/network/bearer/qnetworkconfigmanager_p.cpp
+++ b/src/network/bearer/qnetworkconfigmanager_p.cpp
@@ -366,6 +366,10 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura
void QNetworkConfigurationManagerPrivate::updateConfigurations()
{
+#ifndef QT_NO_LIBRARY
+ typedef QMultiMap<int, QString> PluginKeyMap;
+ typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;
+#endif
QMutexLocker locker(&mutex);
if (firstUpdate) {
@@ -376,15 +380,12 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations()
#ifndef QT_NO_LIBRARY
QBearerEngine *generic = 0;
-
QFactoryLoader *l = loader();
- foreach (const QString &key, l->keys()) {
- QBearerEnginePlugin *plugin = qobject_cast<QBearerEnginePlugin *>(l->instance(key));
- if (plugin) {
- QBearerEngine *engine = plugin->create(key);
- if (!engine)
- continue;
-
+ const PluginKeyMap keyMap = l->keyMap();
+ const PluginKeyMapConstIterator cend = keyMap.constEnd();
+ for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) {
+ const QString &key = it.value();
+ if (QBearerEngine *engine = qLoadPlugin<QBearerEngine, QBearerEnginePlugin>(l, key)) {
if (key == QLatin1String("generic"))
generic = engine;
else
diff --git a/src/printsupport/kernel/qplatformprintplugin.cpp b/src/printsupport/kernel/qplatformprintplugin.cpp
index ec068d87d1..854d8810cc 100644
--- a/src/printsupport/kernel/qplatformprintplugin.cpp
+++ b/src/printsupport/kernel/qplatformprintplugin.cpp
@@ -70,13 +70,9 @@ QPlatformPrinterSupport *QPlatformPrinterSupportPlugin::get()
{
static QPlatformPrinterSupport *singleton = 0;
if (!singleton) {
- QStringList k = loader()->keys();
- if (k.isEmpty())
- return 0;
- QPlatformPrinterSupportPlugin *plugin = qobject_cast<QPlatformPrinterSupportPlugin *>(loader()->instance(k.first()));
- if (!plugin)
- return 0;
- singleton = plugin->create(k.first());
+ const QMultiMap<int, QString> keyMap = loader()->keyMap();
+ if (!keyMap.isEmpty())
+ singleton = qLoadPlugin<QPlatformPrinterSupport, QPlatformPrinterSupportPlugin>(loader(), keyMap.constBegin().value());
}
return singleton;
}
diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp
index f44f475d6c..635ba8b634 100644
--- a/src/sql/kernel/qsqldatabase.cpp
+++ b/src/sql/kernel/qsqldatabase.cpp
@@ -577,11 +577,14 @@ QStringList QSqlDatabase::drivers()
#ifndef QT_NO_LIBRARY
if (QFactoryLoader *fl = loader()) {
- QStringList keys = fl->keys();
- for (QStringList::const_iterator i = keys.constBegin(); i != keys.constEnd(); ++i) {
- if (!list.contains(*i))
- list << *i;
- }
+ typedef QMultiMap<int, QString> PluginKeyMap;
+ typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;
+
+ const PluginKeyMap keyMap = fl->keyMap();
+ const PluginKeyMapConstIterator cend = keyMap.constEnd();
+ for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it)
+ if (!list.contains(it.value()))
+ list << it.value();
}
#endif
@@ -774,10 +777,8 @@ void QSqlDatabasePrivate::init(const QString &type)
}
#ifndef QT_NO_LIBRARY
- if (!driver && loader()) {
- if (QSqlDriverFactoryInterface *factory = qobject_cast<QSqlDriverFactoryInterface*>(loader()->instance(type)))
- driver = factory->create(type);
- }
+ if (!driver && loader())
+ driver = qLoadPlugin<QSqlDriver, QSqlDriverFactoryInterface>(loader(), type);
#endif // QT_NO_LIBRARY
if (!driver) {
diff --git a/src/widgets/kernel/qicon.cpp b/src/widgets/kernel/qicon.cpp
index 62c99a64c8..9c7f8736f0 100644
--- a/src/widgets/kernel/qicon.cpp
+++ b/src/widgets/kernel/qicon.cpp
@@ -816,10 +816,13 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State
QString suffix = info.suffix();
if (!suffix.isEmpty()) {
// first try version 2 engines..
- if (QIconEngineFactoryInterface *factory = qobject_cast<QIconEngineFactoryInterface*>(loader()->instance(suffix))) {
- if (QIconEngine *engine = factory->create(fileName)) {
- d = new QIconPrivate;
- d->engine = engine;
+ const int index = loader()->indexOf(suffix);
+ if (index != -1) {
+ if (QIconEngineFactoryInterface *factory = qobject_cast<QIconEngineFactoryInterface*>(loader()->instance(index))) {
+ if (QIconEngine *engine = factory->create(fileName)) {
+ d = new QIconPrivate;
+ d->engine = engine;
+ }
}
}
}
@@ -1068,12 +1071,17 @@ QDataStream &operator>>(QDataStream &s, QIcon &icon)
icon.d->engine = engine;
engine->read(s);
#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
- } else if (QIconEngineFactoryInterface *factory = qobject_cast<QIconEngineFactoryInterface*>(loader()->instance(key))) {
- if (QIconEngine *engine= factory->create()) {
- icon.d = new QIconPrivate;
- icon.d->engine = engine;
- engine->read(s);
- }
+ } else {
+ const int index = loader()->indexOf(key);
+ if (index != -1) {
+ if (QIconEngineFactoryInterface *factory = qobject_cast<QIconEngineFactoryInterface*>(loader()->instance(index))) {
+ if (QIconEngine *engine= factory->create()) {
+ icon.d = new QIconPrivate;
+ icon.d->engine = engine;
+ engine->read(s);
+ } // factory
+ } // instance
+ } // index
#endif
}
} else if (s.version() == QDataStream::Qt_4_2) {
diff --git a/src/widgets/kernel/qiconloader.cpp b/src/widgets/kernel/qiconloader.cpp
index 38cee3e51f..acbf7c1d07 100644
--- a/src/widgets/kernel/qiconloader.cpp
+++ b/src/widgets/kernel/qiconloader.cpp
@@ -121,7 +121,7 @@ void QIconLoader::ensureInitialized()
QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterface_iid,
QLatin1String("/iconengines"),
Qt::CaseInsensitive);
- if (iconFactoryLoader.keys().contains(QLatin1String("svg")))
+ if (iconFactoryLoader.keyMap().key(QLatin1String("svg"), -1) != -1)
m_supportsSvg = true;
#endif //QT_NO_LIBRARY
}
diff --git a/src/widgets/styles/qstylefactory.cpp b/src/widgets/styles/qstylefactory.cpp
index 9ed452b516..ec29ae7b99 100644
--- a/src/widgets/styles/qstylefactory.cpp
+++ b/src/widgets/styles/qstylefactory.cpp
@@ -181,10 +181,8 @@ QStyle *QStyleFactory::create(const QString& key)
#endif
{ } // Keep these here - they make the #ifdefery above work
#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
- if(!ret) {
- if (QStyleFactoryInterface *factory = qobject_cast<QStyleFactoryInterface*>(loader()->instance(style)))
- ret = factory->create(style);
- }
+ if (!ret)
+ ret = qLoadPlugin<QStyle, QStyleFactoryInterface>(loader(), style);
#endif
if(ret)
ret->setObjectName(style);
@@ -199,10 +197,15 @@ QStyle *QStyleFactory::create(const QString& key)
*/
QStringList QStyleFactory::keys()
{
-#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
- QStringList list = loader()->keys();
-#else
QStringList list;
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
+ typedef QMultiMap<int, QString> PluginKeyMap;
+ typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;
+
+ const PluginKeyMap keyMap = loader()->keyMap();
+ const PluginKeyMap::const_iterator cend = keyMap.constEnd();
+ for (PluginKeyMap::const_iterator it = keyMap.constBegin(); it != cend; ++it)
+ list.append(it.value());
#endif
#ifndef QT_NO_STYLE_WINDOWS
if (!list.contains(QLatin1String("Windows")))