Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeSavingContext Class Reference

#include <KoShapeSavingContext.h>

Public Types

enum  ShapeSavingOption {
  PresentationShape = 1 , DrawId = 2 , AutoStyleInStyleXml = 4 , UniqueMasterPages = 8 ,
  ZIndex = 16
}
 The Style used for saving the shape. More...
 

Public Member Functions

void addLayerForSaving (const KoShapeLayer *layer)
 
void addOption (ShapeSavingOption option)
 add an option to the set of options stored on this context, will leave the other options intact.
 
void addShapeOffset (const KoShape *shape, const QTransform &matrix)
 
void addSharedData (const QString &id, KoSharedSavingData *data)
 
void clearLayers ()
 
QMap< qint64, QString > imagesToSave ()
 
bool isSet (ShapeSavingOption option) const
 Check if an option is set.
 
 KoShapeSavingContext (KoXmlWriter &xmlWriter)
 Constructor.
 
QString markerRef (const KoMarker *marker)
 
ShapeSavingOptions options () const
 Get the options used.
 
void removeOption (ShapeSavingOption option)
 remove an option, will leave the other options intact.
 
void removeShapeOffset (const KoShape *shape)
 
void saveLayerSet (KoXmlWriter &xmlWriter) const
 
void setOptions (ShapeSavingOptions options)
 Set the options to use.
 
void setXmlWriter (KoXmlWriter &xmlWriter)
 Set the xml writer.
 
QTransform shapeOffset (const KoShape *shape) const
 
KoSharedSavingDatasharedData (const QString &id) const
 
KoXmlWriterxmlWriter ()
 Get the xml writer.
 
virtual ~KoShapeSavingContext ()
 

Private Attributes

KoShapeSavingContextPrivate *const d
 

Detailed Description

The set of data for the ODF file format used during saving of a shape.

Definition at line 31 of file KoShapeSavingContext.h.

Member Enumeration Documentation

◆ ShapeSavingOption

The Style used for saving the shape.

Enumerator
PresentationShape 

If set the style of family presentation is used, when not set the family graphic is used. See OpenDocument 9.2.15 Common Drawing Shape Attributes / Style

DrawId 

Save the draw:id used for referencing the shape. If draw:id is saved, xml:id is also saved. See OpenDocument 9.2.15 Common Drawing Shape Attributes / ID

AutoStyleInStyleXml 

If set the automatic style will be marked as being needed in styles.xml

UniqueMasterPages 

If set duplicate master pages will be merged to one

ZIndex 

If set the z-index is saved in the shape

Definition at line 35 of file KoShapeSavingContext.h.

Constructor & Destructor Documentation

◆ KoShapeSavingContext()

KoShapeSavingContext::KoShapeSavingContext ( KoXmlWriter & xmlWriter)

Constructor.

Parameters
xmlWriterused for writing the xml
mainStylesfor saving the styles
embeddedSaverfor saving embedded documents

Definition at line 61 of file KoShapeSavingContext.cpp.

63{
64 // by default allow saving of draw:id + xml:id
66}
KoShapeSavingContextPrivate *const d
KoXmlWriter & xmlWriter()
Get the xml writer.
void addOption(ShapeSavingOption option)
add an option to the set of options stored on this context, will leave the other options intact.

References addOption(), and DrawId.

◆ ~KoShapeSavingContext()

KoShapeSavingContext::~KoShapeSavingContext ( )
virtual

Definition at line 68 of file KoShapeSavingContext.cpp.

69{
70 delete d;
71}

References d.

Member Function Documentation

◆ addLayerForSaving()

void KoShapeSavingContext::addLayerForSaving ( const KoShapeLayer * layer)

Adds a layer to save into a layer-set in styles.xml according to 9.1.2/9.1.3 odf spec

Parameters
layerthe layer to save

Definition at line 109 of file KoShapeSavingContext.cpp.

110{
111 if (layer && ! d->layers.contains(layer))
112 d->layers.append(layer);
113}
QList< const KoShapeLayer * > layers

References d, and KoShapeSavingContextPrivate::layers.

◆ addOption()

void KoShapeSavingContext::addOption ( ShapeSavingOption option)

add an option to the set of options stored on this context, will leave the other options intact.

Definition at line 98 of file KoShapeSavingContext.cpp.

99{
100 d->savingOptions = d->savingOptions | option;
101}
KoShapeSavingContext::ShapeSavingOptions savingOptions

References d, and KoShapeSavingContextPrivate::savingOptions.

◆ addShapeOffset()

void KoShapeSavingContext::addShapeOffset ( const KoShape * shape,
const QTransform & matrix )

Add an offset that will be applied to the shape position when saved

This is needed e.g. for shapes anchored to a text shape as the position is saved as offset to the anchor.

Parameters
shapeThe shape for which the offset should be added.
matrixThe offset which should be applied on saving the position.

Definition at line 167 of file KoShapeSavingContext.cpp.

168{
169 d->shapeOffsets.insert(shape, m);
170}
QHash< const KoShape *, QTransform > shapeOffsets

References d, and KoShapeSavingContextPrivate::shapeOffsets.

◆ addSharedData()

void KoShapeSavingContext::addSharedData ( const QString & id,
KoSharedSavingData * data )

Add shared data

This can be use to pass data between shapes on saving. E.g. The presentation page layout styles. With that e.g. the styles only need to be saved once and can be used everywhere without creating them again.

The ownership of the added data is passed to the context. The KoShapeSavingContext will delete the added data when it is destroyed.

Data inserted for a specific id will not be overwritten by calling addSharedData with the same id again.

You get an assertion when the id is already existing.

See also
KoSharedSavingData

Definition at line 145 of file KoShapeSavingContext.cpp.

146{
147 QMap<QString, KoSharedSavingData*>::iterator it(d->sharedData.find(id));
148 // data will not be overwritten
149 if (it == d->sharedData.end()) {
150 d->sharedData.insert(id, data);
151 } else {
152 warnFlake << "The id" << id << "is already registered. Data not inserted";
153 Q_ASSERT(it == d->sharedData.end());
154 }
155}
#define warnFlake
Definition FlakeDebug.h:16
QMap< QString, KoSharedSavingData * > sharedData

References d, KoShapeSavingContextPrivate::sharedData, and warnFlake.

◆ clearLayers()

void KoShapeSavingContext::clearLayers ( )

remove all layers

This can be used for saving different layer sets per page.

Definition at line 130 of file KoShapeSavingContext.cpp.

131{
132 d->layers.clear();
133}

References d, and KoShapeSavingContextPrivate::layers.

◆ imagesToSave()

QMap< qint64, QString > KoShapeSavingContext::imagesToSave ( )

Get the images that needs to be saved to the store

Definition at line 135 of file KoShapeSavingContext.cpp.

136{
137 return d->imageNames;
138}
QMap< qint64, QString > imageNames

References d, and KoShapeSavingContextPrivate::imageNames.

◆ isSet()

bool KoShapeSavingContext::isSet ( ShapeSavingOption option) const

Check if an option is set.

Returns
true if the option is set, false otherwise

Definition at line 83 of file KoShapeSavingContext.cpp.

84{
85 return d->savingOptions & option;
86}

References d, and KoShapeSavingContextPrivate::savingOptions.

◆ markerRef()

QString KoShapeSavingContext::markerRef ( const KoMarker * marker)

Get the reference to use for the marker lookup

Definition at line 140 of file KoShapeSavingContext.cpp.

141{
142 return QString();
143}

◆ options()

KoShapeSavingContext::ShapeSavingOptions KoShapeSavingContext::options ( ) const

Get the options used.

Returns
options used

Definition at line 93 of file KoShapeSavingContext.cpp.

94{
95 return d->savingOptions;
96}

References d, and KoShapeSavingContextPrivate::savingOptions.

◆ removeOption()

void KoShapeSavingContext::removeOption ( ShapeSavingOption option)

remove an option, will leave the other options intact.

Definition at line 103 of file KoShapeSavingContext.cpp.

104{
105 if (isSet(option))
106 d->savingOptions = d->savingOptions ^ option; // xor to remove it.
107}
bool isSet(ShapeSavingOption option) const
Check if an option is set.

References d, isSet(), and KoShapeSavingContextPrivate::savingOptions.

◆ removeShapeOffset()

void KoShapeSavingContext::removeShapeOffset ( const KoShape * shape)

Remove an offset from the saved offset list

Parameters
shapeThe shape for which the offset should be removed.

Definition at line 172 of file KoShapeSavingContext.cpp.

173{
174 d->shapeOffsets.remove(shape);
175}

References d, and KoShapeSavingContextPrivate::shapeOffsets.

◆ saveLayerSet()

void KoShapeSavingContext::saveLayerSet ( KoXmlWriter & xmlWriter) const

Saves the layers added with addLayerForSaving to the xml writer

Definition at line 115 of file KoShapeSavingContext.cpp.

116{
117 xmlWriter.startElement("draw:layer-set");
118 Q_FOREACH (const KoShapeLayer * layer, d->layers) {
119 xmlWriter.startElement("draw:layer");
120 xmlWriter.addAttribute("draw:name", layer->name());
121 if (layer->isGeometryProtected())
122 xmlWriter.addAttribute("draw:protected", "true");
123 if (! layer->isVisible(false))
124 xmlWriter.addAttribute("draw:display", "none");
125 xmlWriter.endElement(); // draw:layer
126 }
127 xmlWriter.endElement(); // draw:layer-set
128}
bool isGeometryProtected() const
Definition KoShape.cpp:1024
QString name() const
Definition KoShape.cpp:1150
bool isVisible(bool recursive=true) const
Definition KoShape.cpp:979
void startElement(const char *tagName, bool indentInside=true)
void endElement()
void addAttribute(const char *attrName, const QString &value)
Definition KoXmlWriter.h:61

References KoXmlWriter::addAttribute(), d, KoXmlWriter::endElement(), KoShape::isGeometryProtected(), KoShape::isVisible(), KoShapeSavingContextPrivate::layers, KoShape::name(), KoXmlWriter::startElement(), and xmlWriter().

◆ setOptions()

void KoShapeSavingContext::setOptions ( ShapeSavingOptions options)

Set the options to use.

Parameters
optionsto use

Definition at line 88 of file KoShapeSavingContext.cpp.

89{
91}
ShapeSavingOptions options() const
Get the options used.

References d, options(), and KoShapeSavingContextPrivate::savingOptions.

◆ setXmlWriter()

void KoShapeSavingContext::setXmlWriter ( KoXmlWriter & xmlWriter)

Set the xml writer.

Change the xmlWriter that is used in the Context e.g. for saving to styles.xml instead of content.xml

Parameters
xmlWriterto use

Definition at line 78 of file KoShapeSavingContext.cpp.

References d, KoShapeSavingContextPrivate::xmlWriter, and xmlWriter().

◆ shapeOffset()

QTransform KoShapeSavingContext::shapeOffset ( const KoShape * shape) const

Get the offset that will be applied to the shape position when saved.

Parameters
shapeThe shape for which the offset should be get.
Returns
the saved offset or QTransform() when offset is not set.

Definition at line 177 of file KoShapeSavingContext.cpp.

178{
179 return d->shapeOffsets.value(shape, QTransform());
180}

References d, and KoShapeSavingContextPrivate::shapeOffsets.

◆ sharedData()

KoSharedSavingData * KoShapeSavingContext::sharedData ( const QString & id) const

Get the shared data.

See also
KoSharedLoadingData
Parameters
idThe id used to identify the shared data.
Returns
The shared data for the id or 0 if there is no shared data for the id.

Definition at line 157 of file KoShapeSavingContext.cpp.

158{
159 KoSharedSavingData * data = 0;
160 QMap<QString, KoSharedSavingData*>::const_iterator it(d->sharedData.constFind(id));
161 if (it != d->sharedData.constEnd()) {
162 data = it.value();
163 }
164 return data;
165}

References d, and KoShapeSavingContextPrivate::sharedData.

◆ xmlWriter()

KoXmlWriter & KoShapeSavingContext::xmlWriter ( )

Get the xml writer.

Returns
xmlWriter

Definition at line 73 of file KoShapeSavingContext.cpp.

74{
75 return *d->xmlWriter;
76}

References d, and KoShapeSavingContextPrivate::xmlWriter.

Member Data Documentation

◆ d

KoShapeSavingContextPrivate* const KoShapeSavingContext::d
private

Definition at line 200 of file KoShapeSavingContext.h.


The documentation for this class was generated from the following files: