Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeSavingContext.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2004-2006 David Faure <faure@kde.org>
3 SPDX-FileCopyrightText: 2007-2009, 2011 Thorsten Zachmann <zachmann@kde.org>
4 SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
5 SPDX-FileCopyrightText: 2010 Benjamin Port <port.benjamin@gmail.com>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
11
12#include "KoShapeLayer.h"
13#include "KoMarker.h"
14
15#include <KoXmlWriter.h>
16#include <KoStore.h>
17#include <KoStoreDevice.h>
18#include <KoSharedSavingData.h>
19
20#include <FlakeDebug.h>
21#include <QUuid>
22#include <QImage>
23#include <KisMimeDatabase.h>
24
26public:
29
31 KoShapeSavingContext::ShapeSavingOptions savingOptions;
32
34 QMap<QString, KoSharedSavingData*> sharedData;
35
36 QMap<qint64, QString> imageNames;
38 QMap<QString, QImage> images;
39
40 QHash<const KoShape *, QTransform> shapeOffsets;
41 QMap<const KoMarker *, QString> markerRefs;
42
43 QMap<QString, int> referenceCounters;
44 QMap<QString, QList<const void*> > prefixedReferences;
45
46};
47
49 : xmlWriter(&w)
50 , imageId(0)
51{
52}
53
55{
56 Q_FOREACH (KoSharedSavingData * data, sharedData) {
57 delete data;
58 }
59}
60
62 : d(new KoShapeSavingContextPrivate(xmlWriter))
63{
64 // by default allow saving of draw:id + xml:id
66}
67
72
77
82
84{
85 return d->savingOptions & option;
86}
87
88void KoShapeSavingContext::setOptions(ShapeSavingOptions options)
89{
91}
92
93KoShapeSavingContext::ShapeSavingOptions KoShapeSavingContext::options() const
94{
95 return d->savingOptions;
96}
97
102
104{
105 if (isSet(option))
106 d->savingOptions = d->savingOptions ^ option; // xor to remove it.
107}
108
110{
111 if (layer && ! d->layers.contains(layer))
112 d->layers.append(layer);
113}
114
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}
129
131{
132 d->layers.clear();
133}
134
136{
137 return d->imageNames;
138}
139
141{
142 return QString();
143}
144
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}
156
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}
166
167void KoShapeSavingContext::addShapeOffset(const KoShape *shape, const QTransform &m)
168{
169 d->shapeOffsets.insert(shape, m);
170}
171
173{
174 d->shapeOffsets.remove(shape);
175}
176
177QTransform KoShapeSavingContext::shapeOffset(const KoShape *shape) const
178{
179 return d->shapeOffsets.value(shape, QTransform());
180}
#define warnFlake
Definition FlakeDebug.h:16
QMap< const KoMarker *, QString > markerRefs
QMap< QString, KoSharedSavingData * > sharedData
KoShapeSavingContext::ShapeSavingOptions savingOptions
QMap< QString, int > referenceCounters
QMap< qint64, QString > imageNames
QMap< QString, QList< const void * > > prefixedReferences
QList< const KoShapeLayer * > layers
QHash< const KoShape *, QTransform > shapeOffsets
void removeShapeOffset(const KoShape *shape)
ShapeSavingOptions options() const
Get the options used.
void setOptions(ShapeSavingOptions options)
Set the options to use.
QTransform shapeOffset(const KoShape *shape) const
void saveLayerSet(KoXmlWriter &xmlWriter) const
bool isSet(ShapeSavingOption option) const
Check if an option is set.
void addShapeOffset(const KoShape *shape, const QTransform &matrix)
QString markerRef(const KoMarker *marker)
void addSharedData(const QString &id, KoSharedSavingData *data)
QMap< qint64, QString > imagesToSave()
KoShapeSavingContextPrivate *const d
void removeOption(ShapeSavingOption option)
remove an option, will leave the other options intact.
void setXmlWriter(KoXmlWriter &xmlWriter)
Set the xml writer.
ShapeSavingOption
The Style used for saving the shape.
KoXmlWriter & xmlWriter()
Get the xml writer.
KoSharedSavingData * sharedData(const QString &id) const
KoShapeSavingContext(KoXmlWriter &xmlWriter)
Constructor.
void addOption(ShapeSavingOption option)
add an option to the set of options stored on this context, will leave the other options intact.
void addLayerForSaving(const KoShapeLayer *layer)
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