File indexing completed on 2024-05-12 15:56:48
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2007 Thorsten Zachmann <zachmann@kde.org> 0003 SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net> 0004 SPDX-FileCopyrightText: 2014-2015 Denis Kuplyakov <dener.kup@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KOSHAPELOADINGCONTEXT_H 0010 #define KOSHAPELOADINGCONTEXT_H 0011 0012 #include <QSet> 0013 #include <QString> 0014 #include <QPair> 0015 0016 #include "kritaflake_export.h" 0017 0018 class KoShapeLayer; 0019 class KoShape; 0020 class KoShapeControllerBase; 0021 class KoLoadingShapeUpdater; 0022 class KoSharedLoadingData; 0023 class KoDocumentResourceManager; 0024 class KoSectionModel; 0025 class QVariant; 0026 class QObject; 0027 class KoStore; 0028 0029 /** 0030 * Context passed to shapes during loading. 0031 * This class holds various variables as well as a context full of variables which all together 0032 * form the context of a loading operation. 0033 */ 0034 class KRITAFLAKE_EXPORT KoShapeLoadingContext 0035 { 0036 public: 0037 /** 0038 * Struct to store data about additional attributes that should be loaded during 0039 * the shape loading. 0040 * 0041 * Make sure all parameters point to const char * that stay around. e.g. The a KoXmlNS or 0042 * a "tag" defined string e.g. 0043 * AdditionalAttributeData( KoXmlNS::presentation, "placeholder", presentation:placeholder" ) 0044 */ 0045 struct AdditionalAttributeData { 0046 AdditionalAttributeData(const QString &ns, const QString &tag, const QString &name) 0047 : ns(ns) 0048 , tag(tag) 0049 , name(name) { 0050 } 0051 0052 const QString ns; 0053 const QString tag; 0054 const QString name; 0055 0056 bool operator==(const AdditionalAttributeData &other) const { 0057 return name == other.name; 0058 } 0059 }; 0060 0061 /** 0062 * constructor 0063 * @param context the context created for generic ODF loading. 0064 * @param documentResources the data of the shape controller. 0065 */ 0066 KoShapeLoadingContext(KoStore *store, KoDocumentResourceManager *documentResources); 0067 0068 /// destructor 0069 ~KoShapeLoadingContext(); 0070 0071 KoStore *store() const; 0072 QString mimeTypeForPath(const QString &href, bool b = true); 0073 0074 /// Returns layer referenced by given name 0075 KoShapeLayer *layer(const QString &layerName); 0076 /// Adds a new layer to be referenced by the given name later 0077 void addLayer(KoShapeLayer *layer, const QString &layerName); 0078 0079 /** 0080 * remove all layers 0081 * 0082 * This can be used for loading different layer sets per page. 0083 */ 0084 void clearLayers(); 0085 0086 /// register the id for a specific shape 0087 void addShapeId(KoShape *shape, const QString &id); 0088 0089 /// return the shape formerly registered using addShapeId() 0090 KoShape *shapeById(const QString &id); 0091 0092 /// register the id for a specific shape sub item 0093 void addShapeSubItemId(KoShape *shape, const QVariant &subItem, const QString &id); 0094 /// return the shape and subitem formerly registered using addShapeSubItemId() 0095 QPair<KoShape *, QVariant> shapeSubItemById(const QString &id); 0096 0097 /** 0098 * call function on the shapeUpdater when the shape with the id shapeid is inserted 0099 * After that destroy the updater. 0100 */ 0101 void updateShape(const QString &id, KoLoadingShapeUpdater *shapeUpdater); 0102 0103 /** 0104 * this checks if there is an updater for this shape if yes it calls it 0105 * this needs to be done via the shape id and 0106 */ 0107 void shapeLoaded(KoShape *shape); 0108 0109 /// Get current z-index 0110 int zIndex(); 0111 0112 /// Set z-index 0113 void setZIndex(int index); 0114 0115 /** 0116 * Add shared data 0117 * 0118 * This can be use to pass data between shapes on loading. E.g. The decoded text styles 0119 * of the TextShape. With that the styles only have to be read once and can be used in 0120 * all shapes that also need them. 0121 * 0122 * The ownership of the added data is passed to the context. The KoShapeLoadingContext will 0123 * delete the added data when it is destroyed. 0124 * 0125 * Data inserted for a specific id will not be overwritten by calling addSharedData with 0126 * the same id again. 0127 * 0128 * You get an assertion when the id is already existing. 0129 * 0130 * @see KoSharedLoadingData 0131 */ 0132 void addSharedData(const QString &id, KoSharedLoadingData *data); 0133 0134 /** 0135 * Get the shared data. 0136 * 0137 * @see KoSharedLoadingData 0138 * 0139 * @param id The id used to identify the shared data. 0140 * @return The shared data for the id or 0 if there is no shared data for the id. 0141 */ 0142 KoSharedLoadingData *sharedData(const QString &id) const; 0143 0144 /** 0145 * @brief Add an additional attribute that should be loaded during shape loading 0146 * 0147 * An application can use that to set the data for additional attributes that should be 0148 * loaded during shape loading. 0149 * If attribute is set it will not change if set again. The tag is used to differentiate 0150 * the attributes 0151 * 0152 * @param attributeData The data describing the additional attribute data 0153 */ 0154 static void addAdditionalAttributeData(const AdditionalAttributeData &attributeData); 0155 0156 /** 0157 * @brief Get the additional attribute data for loading of a shape 0158 * 0159 * This is used by KoShape::loadOdfAttributes to load all additional attributes defined 0160 * in the returned set. 0161 */ 0162 static QSet<AdditionalAttributeData> additionalAttributeData(); 0163 0164 KoDocumentResourceManager *documentResourceManager() const; 0165 /** 0166 * @brief returns the current section model 0167 * @return the pointer to KoSectionModel 0168 */ 0169 KoSectionModel *sectionModel(); 0170 0171 /** 0172 * @brief sets the section model for the loading context 0173 * @param sectionModel the section model to set 0174 */ 0175 void setSectionModel(KoSectionModel *sectionModel); 0176 0177 private: 0178 // to allow only the KoShapeRegistry access to the KoShapeControllerBase 0179 class Private; 0180 Private * const d; 0181 }; 0182 0183 #endif /* KOSHAPELOADINGCONTEXT_H */