Warning, file /office/calligra/libs/flake/KoShapeSavingContext.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) 2004-2006 David Faure <faure@kde.org>
0003    Copyright (C) 2007-2008 Thorsten Zachmann <zachmann@kde.org>
0004    Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
0005    Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com>
0006 
0007    This library is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU Library General Public
0009    License as published by the Free Software Foundation; either
0010    version 2 of the License, or (at your option) any later version.
0011 
0012    This library is distributed in the hope that it will be useful,
0013    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    Library General Public License for more details.
0016 
0017    You should have received a copy of the GNU Library General Public License
0018    along with this library; see the file COPYING.LIB.  If not, write to
0019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #ifndef KOSHAPESAVINGCONTEXT_H
0024 #define KOSHAPESAVINGCONTEXT_H
0025 
0026 #include "flake_export.h"
0027 
0028 #include <KoElementReference.h>
0029 #include <QMap>
0030 
0031 class KoShape;
0032 class KoXmlWriter;
0033 class KoGenStyles;
0034 class KoDataCenterBase;
0035 class KoEmbeddedDocumentSaver;
0036 class KoImageData;
0037 class KoMarker;
0038 class KoShapeLayer;
0039 class KoStore;
0040 class KoSharedSavingData;
0041 class KoShapeSavingContextPrivate;
0042 
0043 class QImage;
0044 class QTransform;
0045 
0046 /**
0047  * The set of data for the ODF file format used during saving of a shape.
0048  */
0049 class FLAKE_EXPORT KoShapeSavingContext
0050 {
0051 public:
0052     /// The Style used for saving the shape
0053     enum ShapeSavingOption {
0054         /**
0055          * If set the style of family presentation ('pr') is used,
0056          * See OpenDocument 9.2.15 Common Drawing Shape Attributes / Style
0057          */
0058         PresentationShape = 1,
0059         /**
0060          * Save the draw:id used for referencing the shape. If draw:id is saved, xml:id is also
0061          * saved.
0062          * See OpenDocument 9.2.15 Common Drawing Shape Attributes / ID
0063          */
0064         DrawId = 2,
0065         /**
0066          * If set the automatic style will be marked as being needed in styles.xml
0067          */
0068         AutoStyleInStyleXml = 4,
0069         /**
0070          * If set duplicate master pages will be merged to one
0071          */
0072         UniqueMasterPages = 8,
0073         /**
0074          * If set the z-index is saved in the shape
0075          */
0076         ZIndex = 16
0077     };
0078     Q_DECLARE_FLAGS(ShapeSavingOptions, ShapeSavingOption)
0079 
0080     /**
0081      * @brief Constructor
0082      * @param xmlWriter used for writing the xml
0083      * @param mainStyles for saving the styles
0084      * @param embeddedSaver for saving embedded documents
0085      */
0086     KoShapeSavingContext(KoXmlWriter &xmlWriter, KoGenStyles &mainStyles,
0087                          KoEmbeddedDocumentSaver &embeddedSaver);
0088     virtual ~KoShapeSavingContext();
0089 
0090     /**
0091      * @brief Get the xml writer
0092      *
0093      * @return xmlWriter
0094      */
0095     KoXmlWriter &xmlWriter();
0096 
0097     /**
0098      * @brief Set the xml writer
0099      *
0100      * Change the xmlWriter that is used in the Context e.g. for saving to styles.xml
0101      * instead of content.xml
0102      *
0103      * @param xmlWriter to use
0104      */
0105     void setXmlWriter(KoXmlWriter &xmlWriter);
0106 
0107     /**
0108      * @brief Get the main styles
0109      *
0110      * @return main styles
0111      */
0112     KoGenStyles &mainStyles();
0113 
0114     /**
0115      * @brief Get the embedded document saver
0116      *
0117      * @return embedded document saver
0118      */
0119     KoEmbeddedDocumentSaver &embeddedSaver();
0120 
0121     /**
0122      * @brief Check if an option is set
0123      *
0124      * @return ture if the option is set, false otherwise
0125      */
0126     bool isSet(ShapeSavingOption option) const;
0127 
0128     /**
0129      * @brief Set the options to use
0130      *
0131      * @param options to use
0132      */
0133     void setOptions(ShapeSavingOptions options);
0134 
0135     /// add an option to the set of options stored on this context, will leave the other options intact.
0136     void addOption(ShapeSavingOption option);
0137 
0138     /// remove an option, will leave the other options intact.
0139     void removeOption(ShapeSavingOption option);
0140 
0141     /**
0142      * @brief Get the options used
0143      *
0144      * @return options used
0145      */
0146     ShapeSavingOptions options() const;
0147 
0148 
0149     /**
0150      * @brief xmlid returns an element reference that can be related to the given referent. If there is a
0151      *   prefix given, this prefix will be used in addition to either the counter or the uuid.
0152      * @param referent the object we are referring to
0153      * @param prefix a prefix for the xml:id string
0154      * @param counter if counter is true, shapesavingcontext will use a counter to create the xml:id
0155      * @return a KoElementReference; if insert is false and referent doesn't exist yet in the list, the elementreference will be invalid.
0156      */
0157     KoElementReference xmlid(const void *referent, const QString& prefix = QString(), KoElementReference::GenerationOption counter = KoElementReference::UUID);
0158 
0159     /**
0160      * @brief existingXmlid retrieve an existing xml id or invalid xml id if the referent object doesn't exist
0161      */
0162     KoElementReference existingXmlid(const void *referent);
0163 
0164     /**
0165      * @brief Clear out all given draw ids
0166      * @param prefix: removes all xml:id's that have the given prefix.
0167      *
0168      * This is needed for checking if master pages are the same. In normal saving
0169      * this should not be called.
0170      *
0171      * @see KoPAPastePage::process
0172      */
0173     void clearXmlIds(const QString &prefix);
0174 
0175     /**
0176      * Adds a layer to save into a layer-set in styles.xml according to 9.1.2/9.1.3 odf spec
0177      * @param layer the layer to save
0178      */
0179     void addLayerForSaving(const KoShapeLayer *layer);
0180 
0181     /**
0182      * Saves the layers added with addLayerForSaving to the xml writer
0183      */
0184     void saveLayerSet(KoXmlWriter &xmlWriter) const;
0185 
0186     /**
0187      * remove all layers
0188      *
0189      * This can be used for saving different layer sets per page.
0190      */
0191     void clearLayers();
0192 
0193     /**
0194      * Get the image href under which the image will be saved in the store
0195      */
0196     QString imageHref(const KoImageData *image);
0197 
0198     /**
0199      * Get the image href under which the image will be save in the store
0200      *
0201      * This should only be used for temporary images that are onle there during
0202      * saving, e.g. a pixmap representation of a draw:frame
0203      */
0204     QString imageHref(const QImage &image);
0205 
0206     /**
0207      * Get the images that needs to be saved to the store
0208      */
0209     QMap<qint64, QString> imagesToSave();
0210 
0211     /**
0212      * Get the reference to use for the marker lookup
0213      */
0214     QString markerRef(const KoMarker *marker);
0215 
0216     /**
0217      * Add data center
0218      */
0219     void addDataCenter(KoDataCenterBase *dataCenter);
0220 
0221     /**
0222      * Save the data centers
0223      *
0224      * This calls KoDataCenterBase::completeSaving()
0225      * @returns false if an error occurred, which typically cancels the save.
0226      */
0227     bool saveDataCenter(KoStore *store, KoXmlWriter *manifestWriter);
0228 
0229     /**
0230      * Add shared data
0231      *
0232      * This can be use to pass data between shapes on saving. E.g. The presentation page layout
0233      * styles. With that e.g. the styles only need to be saved once and can be used everywhere
0234      * without creating them again.
0235      *
0236      * The ownership of the added data is passed to the context. The KoShapeSavingContext will
0237      * delete the added data when it is destroyed.
0238      *
0239      * Data inserted for a specific id will not be overwritten by calling addSharedData with
0240      * the same id again.
0241      *
0242      * You get an assertion when the id is already existing.
0243      *
0244      * @see KoSharedSavingData
0245      */
0246     void addSharedData(const QString &id, KoSharedSavingData *data);
0247 
0248     /**
0249      * Get the shared data.
0250      *
0251      * @see KoSharedLoadingData
0252      *
0253      * @param id The id used to identify the shared data.
0254      * @return The shared data for the id or 0 if there is no shared data for the id.
0255      */
0256     KoSharedSavingData *sharedData(const QString &id) const;
0257 
0258     /**
0259      * Add an offset that will be applied to the shape position when saved
0260      *
0261      * This is needed e.g. for shapes anchored to a text shape as the position is
0262      * saved as offset to the anchor.
0263      *
0264      * @param shape The shape for which the offset should be added.
0265      * @param matrix The offset which should be applied on saving the position.
0266      */
0267     void addShapeOffset(const KoShape *shape, const QTransform &matrix);
0268 
0269     /**
0270      * Remove an offset from the saved offset list
0271      *
0272      * @param shape The shape for which the offset should be removed.
0273      */
0274     void removeShapeOffset(const KoShape *shape);
0275 
0276     /**
0277      * Get the offset that will be applied to the shape position when saved.
0278      *
0279      * @param shape The shape for which the offset should be get.
0280      * @return the saved offset or QTransform() when offset is not set.
0281      */
0282     QTransform shapeOffset(const KoShape *shape) const;
0283 
0284     /**
0285      * Set stylen family to @p name
0286      * E.g "ch" for chart family
0287      */
0288     void setStyleFamily(const QString &name);
0289     /**
0290      * @return the style family
0291      * If PresentationShape is set the style of family presentation is used,
0292      * else if style family is not empty, it is used,
0293      * else family graphic is used.
0294      * See OpenDocument 9.2.15 Common Drawing Shape Attributes / Style
0295      */
0296     QString styleFamily() const;
0297 
0298 private:
0299     KoShapeSavingContextPrivate * const d;
0300 };
0301 
0302 Q_DECLARE_OPERATORS_FOR_FLAGS(KoShapeSavingContext::ShapeSavingOptions)
0303 
0304 #endif // KOSHAPESAVINGCONTEXT_H