summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/qfactoryloader_p.h
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-05-04 15:57:21 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-07 12:57:48 +0200
commit053576e88045642a0d34003d57a2d087cc5d903f (patch)
treec55242cc30ec0e2fdd3e4b913154e0cdacebf5bc /src/corelib/plugin/qfactoryloader_p.h
parent864f930ba9e78dc2239d62bcf4038aead5e0490a (diff)
QFactoryLoader: Add API for supporting the metadata containing keys.
- Add a method returning a QMultiMap<int index, QString key> to QFactoryLoader, determined from metadata(), correctly reflecting the data structure ('Keys' being a list) - Add convenience templates to create plugins via factory interfaces Change-Id: I247749aa3245f635e476605db1c4cd9c74b74dea Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/plugin/qfactoryloader_p.h')
-rw-r--r--src/corelib/plugin/qfactoryloader_p.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/corelib/plugin/qfactoryloader_p.h b/src/corelib/plugin/qfactoryloader_p.h
index ee7a68d6f8..66ded8074b 100644
--- a/src/corelib/plugin/qfactoryloader_p.h
+++ b/src/corelib/plugin/qfactoryloader_p.h
@@ -56,6 +56,7 @@
#include "QtCore/qobject.h"
#include "QtCore/qstringlist.h"
#include "QtCore/qjsonobject.h"
+#include "QtCore/qmap.h"
#include "private/qlibrary_p.h"
#ifndef QT_NO_LIBRARY
@@ -84,11 +85,42 @@ public:
QLibraryPrivate *library(const QString &key) const;
#endif
+ QMultiMap<int, QString> keyMap() const;
+ int indexOf(const QString &needle) const;
+
void update();
static void refreshAll();
};
+template <class PluginInterface, class FactoryInterface>
+ PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key)
+{
+ const int index = loader->indexOf(key);
+ if (index != -1) {
+ QObject *factoryObject = loader->instance(index);
+ if (FactoryInterface *factory = qobject_cast<FactoryInterface *>(factoryObject))
+ if (PluginInterface *result = factory->create(key))
+ return result;
+ }
+ return 0;
+}
+
+template <class PluginInterface, class FactoryInterface, class Parameter1>
+PluginInterface *qLoadPlugin1(const QFactoryLoader *loader,
+ const QString &key,
+ const Parameter1 &parameter1)
+{
+ const int index = loader->indexOf(key);
+ if (index != -1) {
+ QObject *factoryObject = loader->instance(index);
+ if (FactoryInterface *factory = qobject_cast<FactoryInterface *>(factoryObject))
+ if (PluginInterface *result = factory->create(key, parameter1))
+ return result;
+ }
+ return 0;
+}
+
QT_END_NAMESPACE
#endif // QT_NO_LIBRARY