Warning, file /office/calligra/libs/flake/KoShapeLoadingContext.h 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 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 #ifndef KOSHAPELOADINGCONTEXT_H
0023 #define KOSHAPELOADINGCONTEXT_H
0024 
0025 #include <QSet>
0026 #include <QString>
0027 #include <QVariant>
0028 #include <QPair>
0029 
0030 #include "flake_export.h"
0031 
0032 class KoOdfLoadingContext;
0033 class KoShapeLayer;
0034 class KoShape;
0035 class KoShapeBasedDocumentBase;
0036 class KoLoadingShapeUpdater;
0037 class KoImageCollection;
0038 class KoSharedLoadingData;
0039 class KoDocumentResourceManager;
0040 class KoSectionModel;
0041 
0042 /**
0043  * Context passed to shapes during loading.
0044  * This class holds various variables as well as a context full of variables which all together
0045  * form the context of a loading operation.
0046  */
0047 class FLAKE_EXPORT KoShapeLoadingContext
0048 {
0049 public:
0050     /**
0051      * Struct to store data about additional attributes that should be loaded during
0052      * the shape loading.
0053      *
0054      * Make sure all parameters point to const char * that stay around. e.g. The a KoXmlNS or
0055      * a "tag" defined string e.g.
0056      * AdditionalAttributeData( KoXmlNS::presentation, "placeholder", presentation:placeholder" )
0057      */
0058     struct AdditionalAttributeData {
0059         AdditionalAttributeData(const QString &ns, const QString &tag, const QString &name)
0060                 : ns(ns)
0061                 , tag(tag)
0062                 , name(name) {
0063         }
0064 
0065         const QString ns;
0066         const QString tag;
0067         const QString name;
0068 
0069         bool operator==(const AdditionalAttributeData &other) const {
0070             return name == other.name;
0071         }
0072     };
0073 
0074     /**
0075      * constructor
0076      * @param context the context created for generic ODF loading.
0077      * @param documentResources the data of the shape controller.
0078      */
0079     KoShapeLoadingContext(KoOdfLoadingContext &context, KoDocumentResourceManager *documentResources);
0080 
0081     /// destructor
0082     ~KoShapeLoadingContext();
0083 
0084     /// return the embedded loading context
0085     KoOdfLoadingContext &odfLoadingContext();
0086 
0087     /// Returns layer referenced by given name
0088     KoShapeLayer *layer(const QString &layerName);
0089     /// Adds a new layer to be referenced by the given name later
0090     void addLayer(KoShapeLayer *layer, const QString &layerName);
0091 
0092     /**
0093      * remove all layers
0094      *
0095      * This can be used for loading different layer sets per page.
0096      */
0097     void clearLayers();
0098 
0099     /// register the id for a specific shape
0100     void addShapeId(KoShape *shape, const QString &id);
0101     /// return the shape formerly registered using addShapeId()
0102     KoShape *shapeById(const QString &id);
0103 
0104     /// register the id for a specific shape sub item
0105     void addShapeSubItemId(KoShape *shape, const QVariant &subItem, const QString &id);
0106     /// return the shape and subitem formerly registered using addShapeSubItemId()
0107     QPair<KoShape *, QVariant> shapeSubItemById(const QString &id);
0108 
0109     /**
0110      * call function on the shapeUpdater when the shape with the id shapeid is inserted
0111      * After that destroy the updater.
0112      */
0113     void updateShape(const QString &id, KoLoadingShapeUpdater *shapeUpdater);
0114 
0115     /**
0116      * this checks if there is an updater for this shape if yes it calls it
0117      * this needs to be done via the shape id and
0118      */
0119     void shapeLoaded(KoShape *shape);
0120 
0121     /// Returns the image collection for loading images
0122     KoImageCollection *imageCollection();
0123 
0124     /// Get current z-index
0125     int zIndex();
0126 
0127     /// Set z-index
0128     void setZIndex(int index);
0129 
0130     /**
0131      * Add shared data
0132      *
0133      * This can be use to pass data between shapes on loading. E.g. The decoded text styles
0134      * of the TextShape. With that the styles only have to be read once and can be used in
0135      * all shapes that also need them.
0136      *
0137      * The ownership of the added data is passed to the context. The KoShapeLoadingContext will
0138      * delete the added data when it is destroyed.
0139      *
0140      * Data inserted for a specific id will not be overwritten by calling addSharedData with
0141      * the same id again.
0142      *
0143      * You get an assertion when the id is already existing.
0144      *
0145      * @see KoSharedLoadingData
0146      */
0147     void addSharedData(const QString &id, KoSharedLoadingData *data);
0148 
0149     /**
0150      * Get the shared data.
0151      *
0152      * @see KoSharedLoadingData
0153      *
0154      * @param id The id used to identify the shared data.
0155      * @return The shared data for the id or 0 if there is no shared data for the id.
0156      */
0157     KoSharedLoadingData *sharedData(const QString &id) const;
0158 
0159     /**
0160      * @brief Add an additional attribute that should be loaded during shape loading
0161      *
0162      * An application can use that to set the data for additional attributes that should be
0163      * loaded during shape loading.
0164      * If attribute is set it will not change if set again. The tag is used to differentiate
0165      * the attributes
0166      *
0167      * @param attributeData The data describing the additional attribute data
0168      */
0169     static void addAdditionalAttributeData(const AdditionalAttributeData &attributeData);
0170 
0171     /**
0172      * @brief Get the additional attribute data for loading of a shape
0173      *
0174      * This is used by KoShape::loadOdfAttributes to load all additional attributes defined
0175      * in the returned set.
0176      */
0177     static QSet<AdditionalAttributeData> additionalAttributeData();
0178 
0179     KoDocumentResourceManager *documentResourceManager() const;
0180 
0181     /**
0182      * @brief get the rdf document
0183      * @return the rdf document, or 0 if there is none set/
0184      */
0185     QObject *documentRdf() const;
0186 
0187     /**
0188      * @brief setDocumentRdf sets the rdf document for the loading context
0189      * @param documentRdf the rdf document -- it needs to have been loaded already
0190      */
0191     void setDocumentRdf(QObject *documentRdf);
0192 
0193     /**
0194      * @brief returns the current section model
0195      * @return the pointer to KoSectionModel
0196      */
0197     KoSectionModel *sectionModel();
0198 
0199     /**
0200      * @brief sets the section model for the loading context
0201      * @param sectionModel the section model to set
0202      */
0203     void setSectionModel(KoSectionModel *sectionModel);
0204 
0205 private:
0206     // to allow only the KoShapeRegistry access to the KoShapeBasedDocumentBase
0207     class Private;
0208     Private * const d;
0209 };
0210 
0211 #endif /* KOSHAPELOADINGCONTEXT_H */