Warning, file /office/calligra/libs/flake/KoShapeLoadingContext.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2007-2009, 2011 Thorsten Zachmann <zachmann@kde.org> 0003 Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net> 0004 Copyright (C) 2014-2015 Denis Kuplyakov <dener.kup@gmail.com> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #include "KoShapeLoadingContext.h" 0023 #include "KoShape.h" 0024 #include "KoShapeContainer.h" 0025 #include "KoSharedLoadingData.h" 0026 #include "KoShapeBasedDocumentBase.h" 0027 #include "KoImageCollection.h" 0028 #include "KoMarkerCollection.h" 0029 #include "KoDocumentResourceManager.h" 0030 #include "KoLoadingShapeUpdater.h" 0031 0032 #include <FlakeDebug.h> 0033 0034 uint qHash(const KoShapeLoadingContext::AdditionalAttributeData & attributeData) 0035 { 0036 return qHash(attributeData.name); 0037 } 0038 0039 static QSet<KoShapeLoadingContext::AdditionalAttributeData> s_additionlAttributes; 0040 0041 class Q_DECL_HIDDEN KoShapeLoadingContext::Private 0042 { 0043 public: 0044 Private(KoOdfLoadingContext &c, KoDocumentResourceManager *resourceManager) 0045 : context(c) 0046 , zIndex(0) 0047 , documentResources(resourceManager) 0048 , documentRdf(0) 0049 , sectionModel(0) 0050 { 0051 } 0052 0053 ~Private() { 0054 foreach(KoSharedLoadingData * data, sharedData) { 0055 delete data; 0056 } 0057 } 0058 0059 KoOdfLoadingContext &context; 0060 QMap<QString, KoShapeLayer*> layers; 0061 QMap<QString, KoShape*> drawIds; 0062 QMap<QString, QPair<KoShape *, QVariant> > subIds; 0063 QMap<QString, KoSharedLoadingData *> sharedData; //FIXME: use QScopedPointer here to auto delete in destructor 0064 int zIndex; 0065 QMap<QString, KoLoadingShapeUpdater*> updaterById; 0066 QMap<KoShape *, KoLoadingShapeUpdater*> updaterByShape; 0067 KoDocumentResourceManager *documentResources; 0068 QObject *documentRdf; 0069 KoSectionModel *sectionModel; 0070 }; 0071 0072 KoShapeLoadingContext::KoShapeLoadingContext(KoOdfLoadingContext & context, KoDocumentResourceManager *documentResources) 0073 : d(new Private(context, documentResources)) 0074 { 0075 if (d->documentResources) { 0076 KoMarkerCollection *markerCollection = d->documentResources->resource(KoDocumentResourceManager::MarkerCollection).value<KoMarkerCollection*>(); 0077 if (markerCollection) { 0078 markerCollection->loadOdf(*this); 0079 } 0080 } 0081 } 0082 0083 KoShapeLoadingContext::~KoShapeLoadingContext() 0084 { 0085 delete d; 0086 } 0087 0088 KoOdfLoadingContext & KoShapeLoadingContext::odfLoadingContext() 0089 { 0090 return d->context; 0091 } 0092 0093 KoShapeLayer * KoShapeLoadingContext::layer(const QString & layerName) 0094 { 0095 return d->layers.value(layerName, 0); 0096 } 0097 0098 void KoShapeLoadingContext::addLayer(KoShapeLayer * layer, const QString & layerName) 0099 { 0100 d->layers[ layerName ] = layer; 0101 } 0102 0103 void KoShapeLoadingContext::clearLayers() 0104 { 0105 d->layers.clear(); 0106 } 0107 0108 void KoShapeLoadingContext::addShapeId(KoShape * shape, const QString & id) 0109 { 0110 d->drawIds.insert(id, shape); 0111 QMap<QString, KoLoadingShapeUpdater*>::iterator it(d->updaterById.find(id)); 0112 while (it != d->updaterById.end() && it.key() == id) { 0113 d->updaterByShape.insertMulti(shape, it.value()); 0114 it = d->updaterById.erase(it); 0115 } 0116 } 0117 0118 KoShape * KoShapeLoadingContext::shapeById(const QString &id) 0119 { 0120 return d->drawIds.value(id, 0); 0121 } 0122 0123 void KoShapeLoadingContext::addShapeSubItemId(KoShape *shape, const QVariant &subItem, const QString &id) 0124 { 0125 d->subIds.insert(id, QPair<KoShape *, QVariant>(shape, subItem)); 0126 } 0127 0128 QPair<KoShape *, QVariant> KoShapeLoadingContext::shapeSubItemById(const QString &id) 0129 { 0130 return d->subIds.value(id); 0131 } 0132 0133 0134 // 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 0135 void KoShapeLoadingContext::updateShape(const QString & id, KoLoadingShapeUpdater * shapeUpdater) 0136 { 0137 d->updaterById.insertMulti(id, shapeUpdater); 0138 } 0139 0140 void KoShapeLoadingContext::shapeLoaded(KoShape * shape) 0141 { 0142 QMap<KoShape*, KoLoadingShapeUpdater*>::iterator it(d->updaterByShape.find(shape)); 0143 while (it != d->updaterByShape.end() && it.key() == shape) { 0144 it.value()->update(shape); 0145 delete it.value(); 0146 it = d->updaterByShape.erase(it); 0147 } 0148 } 0149 0150 KoImageCollection * KoShapeLoadingContext::imageCollection() 0151 { 0152 return d->documentResources ? d->documentResources->imageCollection() : 0; 0153 } 0154 0155 int KoShapeLoadingContext::zIndex() 0156 { 0157 return d->zIndex++; 0158 } 0159 0160 void KoShapeLoadingContext::setZIndex(int index) 0161 { 0162 d->zIndex = index; 0163 } 0164 0165 void KoShapeLoadingContext::addSharedData(const QString & id, KoSharedLoadingData * data) 0166 { 0167 QMap<QString, KoSharedLoadingData*>::iterator it(d->sharedData.find(id)); 0168 // data will not be overwritten 0169 if (it == d->sharedData.end()) { 0170 d->sharedData.insert(id, data); 0171 } else { 0172 warnFlake << "The id" << id << "is already registered. Data not inserted"; 0173 Q_ASSERT(it == d->sharedData.end()); 0174 } 0175 } 0176 0177 KoSharedLoadingData * KoShapeLoadingContext::sharedData(const QString & id) const 0178 { 0179 KoSharedLoadingData * data = 0; 0180 QMap<QString, KoSharedLoadingData*>::const_iterator it(d->sharedData.find(id)); 0181 if (it != d->sharedData.constEnd()) { 0182 data = it.value(); 0183 } 0184 return data; 0185 } 0186 0187 void KoShapeLoadingContext::addAdditionalAttributeData(const AdditionalAttributeData & attributeData) 0188 { 0189 s_additionlAttributes.insert(attributeData); 0190 } 0191 0192 QSet<KoShapeLoadingContext::AdditionalAttributeData> KoShapeLoadingContext::additionalAttributeData() 0193 { 0194 return s_additionlAttributes; 0195 } 0196 0197 KoDocumentResourceManager *KoShapeLoadingContext::documentResourceManager() const 0198 { 0199 return d->documentResources; 0200 } 0201 0202 QObject *KoShapeLoadingContext::documentRdf() const 0203 { 0204 return d->documentRdf; 0205 } 0206 0207 0208 void KoShapeLoadingContext::setDocumentRdf(QObject *documentRdf) 0209 { 0210 d->documentRdf = documentRdf; 0211 } 0212 0213 KoSectionModel *KoShapeLoadingContext::sectionModel() 0214 { 0215 return d->sectionModel; 0216 } 0217 0218 void KoShapeLoadingContext::setSectionModel(KoSectionModel *sectionModel) 0219 { 0220 d->sectionModel = sectionModel; 0221 }