Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeLoadingContext.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2007-2009, 2011 Thorsten Zachmann <zachmann@kde.org>
3 SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
4 SPDX-FileCopyrightText: 2014-2015 Denis Kuplyakov <dener.kup@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include <QMultiMap>
10#include <QVariant>
11
13#include "KoShape.h"
14#include "KoSharedLoadingData.h"
16#include "KoMarkerCollection.h"
19
20#include <FlakeDebug.h>
21
23{
24 return qHash(attributeData.name);
25}
26
27static QSet<KoShapeLoadingContext::AdditionalAttributeData> s_additionalAttributes;
28
29class Q_DECL_HIDDEN KoShapeLoadingContext::Private
30{
31public:
32 Private(KoStore *store, KoDocumentResourceManager *resourceManager)
33 : store(store)
34 , zIndex(0)
35 , documentResources(resourceManager)
36 , sectionModel(0)
37 {
38 }
39
41 Q_FOREACH (KoSharedLoadingData * data, sharedData) {
42 delete data;
43 }
44 }
45
47
48 QMap<QString, KoShapeLayer*> layers;
49 QMap<QString, KoShape*> drawIds;
50 QMap<QString, QPair<KoShape *, QVariant> > subIds;
51 QMap<QString, KoSharedLoadingData *> sharedData; //FIXME: use QScopedPointer here to auto delete in destructor
52 int zIndex;
53 QMultiMap<QString, KoLoadingShapeUpdater*> updaterById;
54 QMultiMap<KoShape *, KoLoadingShapeUpdater*> updaterByShape;
56 KoSectionModel *sectionModel; };
57
59 : d(new Private(store, documentResources))
60{
61}
62
67
69{
70 return d->store;
71}
72
73QString KoShapeLoadingContext::mimeTypeForPath(const QString &href, bool b)
74{
75 Q_UNUSED(href);
76 Q_UNUSED(b);
77 return "image/svg+xml";
78}
79
80KoShapeLayer * KoShapeLoadingContext::layer(const QString & layerName)
81{
82 return d->layers.value(layerName, 0);
83}
84
85void KoShapeLoadingContext::addLayer(KoShapeLayer * layer, const QString & layerName)
86{
87 d->layers[ layerName ] = layer;
88}
89
91{
92 d->layers.clear();
93}
94
95void KoShapeLoadingContext::addShapeId(KoShape * shape, const QString & id)
96{
97 d->drawIds.insert(id, shape);
98 auto it(d->updaterById.find(id));
99 while (it != d->updaterById.end() && it.key() == id) {
100 d->updaterByShape.insert(shape, it.value());
101 it = d->updaterById.erase(it);
102 }
103}
104
106{
107 return d->drawIds.value(id, 0);
108}
109
110void KoShapeLoadingContext::addShapeSubItemId(KoShape *shape, const QVariant &subItem, const QString &id)
111{
112 d->subIds.insert(id, QPair<KoShape *, QVariant>(shape, subItem));
113}
114
115QPair<KoShape *, QVariant> KoShapeLoadingContext::shapeSubItemById(const QString &id)
116{
117 return d->subIds.value(id);
118}
119
120
121// TODO make sure to remove the shape from the loading context when loading for it failed and it was deleted. This can also happen when the parent is deleted
122void KoShapeLoadingContext::updateShape(const QString & id, KoLoadingShapeUpdater * shapeUpdater)
123{
124 d->updaterById.insert(id, shapeUpdater);
125}
126
128{
129 auto it(d->updaterByShape.find(shape));
130 while (it != d->updaterByShape.end() && it.key() == shape) {
131 it.value()->update(shape);
132 delete it.value();
133 it = d->updaterByShape.erase(it);
134 }
135}
136
137
139{
140 return d->zIndex++;
141}
142
144{
145 d->zIndex = index;
146}
147
149{
150 auto it(d->sharedData.find(id));
151 // data will not be overwritten
152 if (it == d->sharedData.end()) {
153 d->sharedData.insert(id, data);
154 } else {
155 warnFlake << "The id" << id << "is already registered. Data not inserted";
156 Q_ASSERT(it == d->sharedData.end());
157 }
158}
159
161{
162 KoSharedLoadingData * data = 0;
163 QMap<QString, KoSharedLoadingData*>::const_iterator it(d->sharedData.find(id));
164 if (it != d->sharedData.constEnd()) {
165 data = it.value();
166 }
167 return data;
168}
169
171{
172 s_additionalAttributes.insert(attributeData);
173}
174
175QSet<KoShapeLoadingContext::AdditionalAttributeData> KoShapeLoadingContext::additionalAttributeData()
176{
178}
179
181{
182 return d->documentResources;
183}
184
186{
187 return d->sectionModel;
188}
189
190void KoShapeLoadingContext::setSectionModel(KoSectionModel *sectionModel)
191{
192 d->sectionModel = sectionModel;
193}
#define warnFlake
Definition FlakeDebug.h:16
unsigned int uint
uint qHash(const KoShapeLoadingContext::AdditionalAttributeData &attributeData)
static QSet< KoShapeLoadingContext::AdditionalAttributeData > s_additionalAttributes
void setZIndex(int index)
Set z-index.
void addSharedData(const QString &id, KoSharedLoadingData *data)
KoShapeLayer * layer(const QString &layerName)
Returns layer referenced by given name.
void updateShape(const QString &id, KoLoadingShapeUpdater *shapeUpdater)
QMap< QString, KoShape * > drawIds
void addShapeId(KoShape *shape, const QString &id)
register the id for a specific shape
KoShapeLoadingContext(KoStore *store, KoDocumentResourceManager *documentResources)
KoDocumentResourceManager * documentResourceManager() const
void setSectionModel(KoSectionModel *sectionModel)
sets the section model for the loading context
QMap< QString, KoSharedLoadingData * > sharedData
void shapeLoaded(KoShape *shape)
static QSet< AdditionalAttributeData > additionalAttributeData()
Get the additional attribute data for loading of a shape.
void addShapeSubItemId(KoShape *shape, const QVariant &subItem, const QString &id)
register the id for a specific shape sub item
static void addAdditionalAttributeData(const AdditionalAttributeData &attributeData)
Add an additional attribute that should be loaded during shape loading.
QPair< KoShape *, QVariant > shapeSubItemById(const QString &id)
return the shape and subitem formerly registered using addShapeSubItemId()
KoShape * shapeById(const QString &id)
return the shape formerly registered using addShapeId()
QMap< QString, QPair< KoShape *, QVariant > > subIds
void addLayer(KoShapeLayer *layer, const QString &layerName)
Adds a new layer to be referenced by the given name later.
QString mimeTypeForPath(const QString &href, bool b=true)
QMultiMap< QString, KoLoadingShapeUpdater * > updaterById
QMap< QString, KoShapeLayer * > layers
QMultiMap< KoShape *, KoLoadingShapeUpdater * > updaterByShape
Private(KoStore *store, KoDocumentResourceManager *resourceManager)
KoDocumentResourceManager * documentResources