Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeRegistry.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006 Boudewijn Rempt (boud@valdyas.org)
3 * SPDX-FileCopyrightText: 2006-2007, 2010 Thomas Zander <zander@kde.org>
4 * SPDX-FileCopyrightText: 2006, 2008-2010 Thorsten Zachmann <zachmann@kde.org>
5 * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
6 * SPDX-FileCopyrightText: 2010 Inge Wallin <inge@lysator.liu.se>
7 *
8 * SPDX-License-Identifier: LGPL-2.0-or-later
9 */
10
11// Own
12#include "KoShapeRegistry.h"
13
14#include "KoSvgTextShape.h"
15#include "KoPathShapeFactory.h"
18#include "KoShapeGroup.h"
19#include "KoShapeLayer.h"
20
21#include <KoPluginLoader.h>
22#include <KoXmlNS.h>
23
24#include <QString>
25#include <QHash>
26#include <QMultiMap>
27#include <QPainter>
28#include <QGlobalStatic>
29
30#include <FlakeDebug.h>
31
33
34class Q_DECL_HIDDEN KoShapeRegistry::Private
35{
36public:
39
40 // Map namespace,tagname to priority:factory
41 QHash<QPair<QString, QString>, QMultiMap<int, KoShapeFactoryBase*> > factoryMap;
42};
43
48
50{
51 qDeleteAll(doubleEntries());
52 qDeleteAll(values());
53 delete d;
54}
55
56void KoShapeRegistry::Private::init(KoShapeRegistry *q)
57{
59 config.blacklist = "FlakePluginsDisabled";
60 config.group = "krita";
61 KoPluginLoader::instance()->load(QString::fromLatin1("Krita/Flake"),
62 config);
63 config.blacklist = "ShapePluginsDisabled";
64 KoPluginLoader::instance()->load(QString::fromLatin1("Krita/Shape"),
65 config);
66
67 // Also add our hard-coded basic shapes
68 q->add(new KoSvgTextShapeFactory());
70
71 // Now all shape factories are registered with us, determine their
72 // associated odf tagname & priority and prepare ourselves for
73 // loading ODF.
74
75 QList<KoShapeFactoryBase*> factories = q->values();
76 for (int i = 0; i < factories.size(); ++i) {
77 insertFactory(factories[i]);
78 }
79}
80
82{
83 if (!s_instance.exists()) {
84 s_instance->d->init(s_instance);
85 }
86 return s_instance;
87}
88
90{
91 add(factory);
92 d->insertFactory(factory);
93}
94
95void KoShapeRegistry::Private::insertFactory(KoShapeFactoryBase *factory)
96{
97 const QList<QPair<QString, QStringList> > odfElements(factory->odfElements());
98
99 if (odfElements.isEmpty()) {
100 debugFlake << "Shape factory" << factory->id() << " does not have OdfNamespace defined, ignoring";
101 }
102 else {
103 int priority = factory->loadingPriority();
104 for (QList<QPair<QString, QStringList> >::const_iterator it(odfElements.begin()); it != odfElements.end(); ++it) {
105 foreach (const QString &elementName, (*it).second) {
106 QPair<QString, QString> p((*it).first, elementName);
107
108 QMultiMap<int, KoShapeFactoryBase*> & priorityMap = factoryMap[p];
109
110 priorityMap.insert(priority, factory);
111
112 debugFlake << "Inserting factory" << factory->id() << " for"
113 << p << " with priority "
114 << priority << " into factoryMap making "
115 << priorityMap.size() << " entries. ";
116 }
117 }
118 }
119}
120
121#include "kis_debug.h"
122#include <QMimeDatabase>
123#include <KoUnit.h>
125#include <KoShapeController.h>
126#include <KoShapeGroupCommand.h>
127
128
129QList<KoShapeFactoryBase*> KoShapeRegistry::factoriesForElement(const QString &nameSpace, const QString &elementName)
130{
131 // Pair of namespace, tagname
132 QPair<QString, QString> p = QPair<QString, QString>(nameSpace, elementName);
133
134 QMultiMap<int, KoShapeFactoryBase*> priorityMap = d->factoryMap.value(p);
135 QList<KoShapeFactoryBase*> shapeFactories;
136 // sort list by priority
137 Q_FOREACH (KoShapeFactoryBase *f, priorityMap.values()) {
138 shapeFactories.prepend(f);
139 }
140
141 return shapeFactories;
142}
#define debugFlake
Definition FlakeDebug.h:15
const Params2D p
QList< QString > QStringList
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
QList< KoShapeFactoryBase * > doubleEntries() const
QList< KoShapeFactoryBase * > values() const
Factory for path shapes.
void load(const QString &serviceType, const PluginsConfig &config=PluginsConfig(), QObject *owner=0, bool cache=true)
static KoPluginLoader * instance()
QList< QPair< QString, QStringList > > odfElements() const
QList< KoShapeFactoryBase * > factoriesForElement(const QString &nameSpace, const QString &elementName)
static KoShapeRegistry * instance()
QHash< QPair< QString, QString >, QMultiMap< int, KoShapeFactoryBase * > > factoryMap
~KoShapeRegistry() override
void insertFactory(KoShapeFactoryBase *factory)
void init(KoShapeRegistry *q)
Private *const d
void addFactory(KoShapeFactoryBase *factory)
const char * blacklist
This contains the variable name for the list of plugins (by library name) that will not be loaded.