1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qgenericpluginfactory.h" |
5 | |
6 | #include "qguiapplication.h" |
7 | #include "private/qfactoryloader_p.h" |
8 | #include "qgenericplugin.h" |
9 | #include "qdebug.h" |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | using namespace Qt::StringLiterals; |
14 | |
15 | Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, gpLoader, |
16 | (QGenericPluginFactoryInterface_iid, "/generic"_L1 , Qt::CaseInsensitive)) |
17 | |
18 | /*! |
19 | \class QGenericPluginFactory |
20 | \ingroup plugins |
21 | \inmodule QtGui |
22 | |
23 | \brief The QGenericPluginFactory class creates plugin drivers. |
24 | |
25 | \sa QGenericPlugin |
26 | */ |
27 | |
28 | /*! |
29 | Creates the driver specified by \a key, using the given \a specification. |
30 | |
31 | Note that the keys are case-insensitive. |
32 | |
33 | \sa keys() |
34 | */ |
35 | QObject *QGenericPluginFactory::create(const QString& key, const QString &specification) |
36 | { |
37 | return qLoadPlugin<QObject, QGenericPlugin>(loader: gpLoader(), key: key.toLower(), args: specification); |
38 | } |
39 | |
40 | /*! |
41 | Returns the list of valid keys, i.e. the available mouse drivers. |
42 | |
43 | \sa create() |
44 | */ |
45 | QStringList QGenericPluginFactory::keys() |
46 | { |
47 | QStringList list; |
48 | |
49 | typedef QMultiMap<int, QString> PluginKeyMap; |
50 | typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; |
51 | |
52 | const PluginKeyMap keyMap = gpLoader()->keyMap(); |
53 | const PluginKeyMapConstIterator cend = keyMap.constEnd(); |
54 | for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) |
55 | if (!list.contains(str: it.value())) |
56 | list += it.value(); |
57 | return list; |
58 | } |
59 | |
60 | QT_END_NAMESPACE |
61 | |