1 | /* |
2 | SPDX-FileCopyrightText: 2001-2010 Christoph Cullmann <cullmann@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "katedocument.h" |
8 | |
9 | #include <KPluginFactory> |
10 | |
11 | /** |
12 | * wrapper factory to be sure nobody external deletes our kateglobal object |
13 | * each instance will just increment the reference counter of our internal |
14 | * super private global instance ;) |
15 | */ |
16 | class KateFactory : public KPluginFactory |
17 | { |
18 | Q_OBJECT |
19 | |
20 | Q_PLUGIN_METADATA(IID KPluginFactory_iid FILE "katepart.json" ) |
21 | |
22 | Q_INTERFACES(KPluginFactory) |
23 | |
24 | public: |
25 | /** |
26 | * This function is called when the factory asked to create an Object. |
27 | * |
28 | * You may reimplement it to provide a very flexible factory. This is especially useful to |
29 | * provide generic factories for plugins implemented using a scripting language. |
30 | * |
31 | * \param iface The staticMetaObject::className() string identifying the plugin interface that |
32 | * was requested. E.g. for KCModule plugins this string will be "KCModule". |
33 | * \param parentWidget Only used if the requested plugin is a KPart. |
34 | * \param parent The parent object for the plugin object. |
35 | * \param args A plugin specific list of arbitrary arguments. |
36 | */ |
37 | QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &) override |
38 | { |
39 | // iface == classname to construct |
40 | const QByteArray classname(iface); |
41 | |
42 | // default to the kparts::* behavior of having one single widget() if the user don't requested a pure document |
43 | const bool bWantSingleView = (classname != "KTextEditor::Document" ); |
44 | |
45 | // should we be readonly? |
46 | const bool bWantReadOnly = (classname == "KParts::ReadOnlyPart" ); |
47 | |
48 | // construct right part variant |
49 | KTextEditor::DocumentPrivate *part = new KTextEditor::DocumentPrivate(metaData(), bWantSingleView, bWantReadOnly, parentWidget, parent); |
50 | part->setReadWrite(!bWantReadOnly); |
51 | return part; |
52 | } |
53 | }; |
54 | |
55 | #include "katepart.moc" |
56 | |