diff --git a/src/corelib/plugin/qfactoryloader_p.h b/src/corelib/plugin/qfactoryloader_p.h index ee07084180..a4690c3f03 100644 --- a/src/corelib/plugin/qfactoryloader_p.h +++ b/src/corelib/plugin/qfactoryloader_p.h @@ -85,6 +85,23 @@ public: QObject *instance(int index) const; }; +#ifdef Q_COMPILER_VARIADIC_TEMPLATES + +template +PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key, Args &&...args) +{ + const int index = loader->indexOf(key); + if (index != -1) { + QObject *factoryObject = loader->instance(index); + if (FactoryInterface *factory = qobject_cast(factoryObject)) + if (PluginInterface *result = factory->create(key, std::forward(args)...)) + return result; + } + return nullptr; +} + +#else + template PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key) { @@ -98,21 +115,57 @@ template return 0; } -template -PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, +template +PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key, - const Parameter1 ¶meter1) + P1 &&p1) { const int index = loader->indexOf(key); if (index != -1) { QObject *factoryObject = loader->instance(index); if (FactoryInterface *factory = qobject_cast(factoryObject)) - if (PluginInterface *result = factory->create(key, parameter1)) + if (PluginInterface *result = factory->create(key, std::forward(p1))) return result; } return 0; } +template +PluginInterface *qLoadPlugin(const QFactoryLoader *loader, + const QString &key, + P1 &&p1, P2 &&p2) +{ + const int index = loader->indexOf(key); + if (index != -1) { + QObject *factoryObject = loader->instance(index); + if (FactoryInterface *factory = qobject_cast(factoryObject)) + if (PluginInterface *result = factory->create(key, std::forward(p1), std::forward(p2))) + return result; + } + return 0; +} + +template +PluginInterface *qLoadPlugin(const QFactoryLoader *loader, + const QString &key, + P1 &&p1, P2 &&p2, P3 &&p3) +{ + const int index = loader->indexOf(key); + if (index != -1) { + QObject *factoryObject = loader->instance(index); + if (FactoryInterface *factory = qobject_cast(factoryObject)) + if (PluginInterface *result = factory->create(key, std::forward(p1), std::forward(p2), std::forward(p3))) + return result; + } + return 0; +} + +#endif + +template +Q_DECL_DEPRECATED PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, const QString &key, Arg &&arg) +{ return qLoadPlugin(loader, key, std::forward(arg)); } + QT_END_NAMESPACE #endif // QT_NO_QOBJECT diff --git a/src/gui/kernel/qgenericpluginfactory.cpp b/src/gui/kernel/qgenericpluginfactory.cpp index d7b9bfba06..15fa094f54 100644 --- a/src/gui/kernel/qgenericpluginfactory.cpp +++ b/src/gui/kernel/qgenericpluginfactory.cpp @@ -71,7 +71,7 @@ QObject *QGenericPluginFactory::create(const QString& key, const QString &specif { #if (!defined(Q_OS_WIN32) || defined(QT_SHARED)) && !defined(QT_NO_LIBRARY) const QString driver = key.toLower(); - if (QObject *object = qLoadPlugin1(loader(), driver, specification)) + if (QObject *object = qLoadPlugin(loader(), driver, specification)) return object; #else // (!Q_OS_WIN32 || QT_SHARED) && !QT_NO_LIBRARY Q_UNUSED(key) diff --git a/src/gui/kernel/qplatforminputcontextfactory.cpp b/src/gui/kernel/qplatforminputcontextfactory.cpp index fedf940dda..c80797d884 100644 --- a/src/gui/kernel/qplatforminputcontextfactory.cpp +++ b/src/gui/kernel/qplatforminputcontextfactory.cpp @@ -69,7 +69,7 @@ QPlatformInputContext *QPlatformInputContextFactory::create(const QString& key) QStringList paramList = key.split(QLatin1Char(':')); const QString platform = paramList.takeFirst().toLower(); - QPlatformInputContext *ic = qLoadPlugin1 + QPlatformInputContext *ic = qLoadPlugin (loader(), platform, paramList); if (ic && ic->isValid()) return ic; diff --git a/src/gui/kernel/qplatformintegrationfactory.cpp b/src/gui/kernel/qplatformintegrationfactory.cpp index d109ceb2f0..2c8a7ce0f8 100644 --- a/src/gui/kernel/qplatformintegrationfactory.cpp +++ b/src/gui/kernel/qplatformintegrationfactory.cpp @@ -50,30 +50,19 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader, (QPlatformIntegrationFactoryInterface_iid, QLatin1String(""), Qt::CaseInsensitive)) #endif // !QT_NO_LIBRARY -static inline QPlatformIntegration *loadIntegration(QFactoryLoader *loader, const QString &key, const QStringList ¶meters, int &argc, char ** argv) -{ - const int index = loader->indexOf(key); - if (index != -1) { - if (QPlatformIntegrationPlugin *factory = qobject_cast(loader->instance(index))) - if (QPlatformIntegration *result = factory->create(key, parameters, argc, argv)) - return result; - } - return 0; -} - QPlatformIntegration *QPlatformIntegrationFactory::create(const QString &platform, const QStringList ¶mList, int &argc, char **argv, const QString &platformPluginPath) { #ifndef QT_NO_LIBRARY // Try loading the plugin from platformPluginPath first: if (!platformPluginPath.isEmpty()) { QCoreApplication::addLibraryPath(platformPluginPath); - if (QPlatformIntegration *ret = loadIntegration(directLoader(), platform, paramList, argc, argv)) + if (QPlatformIntegration *ret = qLoadPlugin(directLoader(), platform, paramList, argc, argv)) return ret; } #else Q_UNUSED(platformPluginPath); #endif - return loadIntegration(loader(), platform, paramList, argc, argv); + return qLoadPlugin(loader(), platform, paramList, argc, argv); } /*! diff --git a/src/gui/kernel/qplatformthemefactory.cpp b/src/gui/kernel/qplatformthemefactory.cpp index bcc37dad06..a89e3088ea 100644 --- a/src/gui/kernel/qplatformthemefactory.cpp +++ b/src/gui/kernel/qplatformthemefactory.cpp @@ -51,23 +51,22 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, directLoader, QPlatformTheme *QPlatformThemeFactory::create(const QString& key, const QString &platformPluginPath) { +#ifndef QT_NO_LIBRARY QStringList paramList = key.split(QLatin1Char(':')); const QString platform = paramList.takeFirst().toLower(); -#ifndef QT_NO_LIBRARY // Try loading the plugin from platformPluginPath first: if (!platformPluginPath.isEmpty()) { QCoreApplication::addLibraryPath(platformPluginPath); - if (QPlatformTheme *ret = qLoadPlugin1(directLoader(), platform, paramList)) + if (QPlatformTheme *ret = qLoadPlugin(directLoader(), platform, paramList)) return ret; } - if (QPlatformTheme *ret = qLoadPlugin1(loader(), platform, paramList)) - return ret; + return qLoadPlugin(loader(), platform, paramList); #else Q_UNUSED(key); Q_UNUSED(platformPluginPath); -#endif return 0; +#endif } /*!