1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/* This file is part of the KDE project
Copyright (C) 2007-2009, 2011 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoShapeLoadingContext.h"
#include "KoShape.h"
#include "KoShapeContainer.h"
#include "KoSharedLoadingData.h"
#include "KoShapeBasedDocumentBase.h"
#include "KoImageCollection.h"
#include "KoMarkerCollection.h"
#include "KoDocumentResourceManager.h"
#include "KoLoadingShapeUpdater.h"
#include <kdebug.h>
uint qHash(const KoShapeLoadingContext::AdditionalAttributeData & attributeData)
{
return qHash(attributeData.name);
}
static QSet<KoShapeLoadingContext::AdditionalAttributeData> s_additionlAttributes;
class KoShapeLoadingContext::Private
{
public:
Private(KoOdfLoadingContext &c, KoDocumentResourceManager *resourceManager)
: context(c),
zIndex(0),
documentResources(resourceManager),
documentRdf(0)
{
}
~Private() {
foreach(KoSharedLoadingData * data, sharedData) {
delete data;
}
}
KoOdfLoadingContext &context;
QMap<QString, KoShapeLayer*> layers;
QMap<QString, KoShape*> drawIds;
QMap<QString, QPair<KoShape *, QVariant> > subIds;
QMap<QString, KoSharedLoadingData*> sharedData;
int zIndex;
QMap<QString, KoLoadingShapeUpdater*> updaterById;
QMap<KoShape *, KoLoadingShapeUpdater*> updaterByShape;
KoDocumentResourceManager *documentResources;
QObject *documentRdf;
};
KoShapeLoadingContext::KoShapeLoadingContext(KoOdfLoadingContext & context, KoDocumentResourceManager *documentResources)
: d(new Private(context, documentResources))
{
if (d->documentResources) {
KoMarkerCollection *markerCollection = d->documentResources->resource(KoDocumentResourceManager::MarkerCollection).value<KoMarkerCollection*>();
if (markerCollection) {
markerCollection->loadOdf(*this);
}
}
}
KoShapeLoadingContext::~KoShapeLoadingContext()
{
delete d;
}
KoOdfLoadingContext & KoShapeLoadingContext::odfLoadingContext()
{
return d->context;
}
KoShapeLayer * KoShapeLoadingContext::layer(const QString & layerName)
{
return d->layers.value(layerName, 0);
}
void KoShapeLoadingContext::addLayer(KoShapeLayer * layer, const QString & layerName)
{
d->layers[ layerName ] = layer;
}
void KoShapeLoadingContext::clearLayers()
{
d->layers.clear();
}
void KoShapeLoadingContext::addShapeId(KoShape * shape, const QString & id)
{
d->drawIds.insert(id, shape);
QMap<QString, KoLoadingShapeUpdater*>::iterator it(d->updaterById.find(id));
while (it != d->updaterById.end() && it.key() == id) {
d->updaterByShape.insertMulti(shape, it.value());
it = d->updaterById.erase(it);
}
}
KoShape * KoShapeLoadingContext::shapeById(const QString &id)
{
return d->drawIds.value(id, 0);
}
void KoShapeLoadingContext::addShapeSubItemId(KoShape *shape, const QVariant &subItem, const QString &id)
{
d->subIds.insert(id, QPair<KoShape *, QVariant>(shape, subItem));
}
QPair<KoShape *, QVariant> KoShapeLoadingContext::shapeSubItemById(const QString &id)
{
return d->subIds.value(id);
}
// 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
void KoShapeLoadingContext::updateShape(const QString & id, KoLoadingShapeUpdater * shapeUpdater)
{
d->updaterById.insertMulti(id, shapeUpdater);
}
void KoShapeLoadingContext::shapeLoaded(KoShape * shape)
{
QMap<KoShape*, KoLoadingShapeUpdater*>::iterator it(d->updaterByShape.find(shape));
while (it != d->updaterByShape.end() && it.key() == shape) {
it.value()->update(shape);
delete it.value();
it = d->updaterByShape.erase(it);
}
}
KoImageCollection * KoShapeLoadingContext::imageCollection()
{
return d->documentResources ? d->documentResources->imageCollection() : 0;
}
int KoShapeLoadingContext::zIndex()
{
return d->zIndex++;
}
void KoShapeLoadingContext::setZIndex(int index)
{
d->zIndex = index;
}
void KoShapeLoadingContext::addSharedData(const QString & id, KoSharedLoadingData * data)
{
QMap<QString, KoSharedLoadingData*>::iterator it(d->sharedData.find(id));
// data will not be overwritten
if (it == d->sharedData.end()) {
d->sharedData.insert(id, data);
} else {
kWarning(30006) << "The id" << id << "is already registered. Data not inserted";
Q_ASSERT(it == d->sharedData.end());
}
}
KoSharedLoadingData * KoShapeLoadingContext::sharedData(const QString & id) const
{
KoSharedLoadingData * data = 0;
QMap<QString, KoSharedLoadingData*>::const_iterator it(d->sharedData.find(id));
if (it != d->sharedData.constEnd()) {
data = it.value();
}
return data;
}
void KoShapeLoadingContext::addAdditionalAttributeData(const AdditionalAttributeData & attributeData)
{
s_additionlAttributes.insert(attributeData);
}
QSet<KoShapeLoadingContext::AdditionalAttributeData> KoShapeLoadingContext::additionalAttributeData()
{
return s_additionlAttributes;
}
KoDocumentResourceManager *KoShapeLoadingContext::documentResourceManager() const
{
return d->documentResources;
}
QObject *KoShapeLoadingContext::documentRdf() const
{
return d->documentRdf;
}
void KoShapeLoadingContext::setDocumentRdf(QObject *documentRdf)
{
d->documentRdf = documentRdf;
}
|