Krita Source Code Documentation
Loading...
Searching...
No Matches
KoXmlWriter.h
Go to the documentation of this file.
1/* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2004 David Faure <faure@kde.org>
3 SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
4 SPDX-FileCopyrightText: 2011 Lukáš Tvrdý <lukas.tvrdy@ixonos.com>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef XMLWRITER_H
10#define XMLWRITER_H
11
12#include <QDebug>
13#include <QMap>
14#include <QIODevice>
15
16#include "kritastore_export.h"
17
23class KRITASTORE_EXPORT KoXmlWriter
24{
25public:
30 explicit KoXmlWriter(QIODevice* dev, int indentLevel = 0);
31
34
43 void startDocument(const char* rootElemName, const char* publicId = 0, const char* systemId = 0);
44
46 void endDocument();
47
55 void startElement(const char* tagName, bool indentInside = true);
56
61 inline void addAttribute(const char* attrName, const QString& value) {
62 addAttribute(attrName, value.toUtf8());
63 }
67 inline void addAttribute(const char* attrName, int value) {
68 addAttribute(attrName, QByteArray::number(value));
69 }
73 inline void addAttribute(const char* attrName, uint value) {
74 addAttribute(attrName, QByteArray::number(value));
75 }
80 inline void addAttribute(const char* attrName, bool value) {
81 addAttribute(attrName, value ? "true" : "false");
82 }
88 void addAttribute(const char* attrName, double value);
89
95 void addAttribute(const char* attrName, float value);
96
98 void addAttribute(const char* attrName, const QByteArray& value);
99
103 void addAttribute(const char* attrName, const char* value);
104
109 void endElement();
110
115 inline void addTextNode(const QString& str) {
116 addTextNode(str.toUtf8());
117 }
118
120 void addTextNode(const QByteArray& cstr);
121
129 void addTextNode(const char* cstr);
130
138 void addCompleteElement(QIODevice* dev);
139
140 // #### Maybe we want to subclass KoXmlWriter for manifest files.
148 void addManifestEntry(const QString& fullPath, const QString& mediaType);
149
150private:
151 struct Tag {
152 Tag(const char *t = 0, bool ind = true)
153 : hasChildren(false)
154 , lastChildIsText(false)
155 , openingTagClosed(false)
156 , indentInside(ind)
157 {
158 tagName = new char[qstrlen(t) + 1];
159 qstrcpy(tagName, t);
160 }
161
163 delete[] tagName;
164 }
165
166 Tag(const Tag &original)
167 {
168 tagName = new char[qstrlen(original.tagName) + 1];
169 qstrcpy(tagName, original.tagName);
170
171 hasChildren = original.hasChildren;
172 lastChildIsText = original.lastChildIsText;
173 openingTagClosed = original.openingTagClosed;
174 indentInside = original.indentInside;
175 }
176
177 char *tagName {0};
178 bool hasChildren : 1;
181 bool indentInside : 1;
182 };
183
185 void writeIndent();
186
187 void writeCString(const char* cstr);
188
189 void writeChar(char c);
190
191
192 inline void closeStartElement(Tag& tag) {
193 if (!tag.openingTagClosed) {
194 tag.openingTagClosed = true;
195 writeChar('>');
196 }
197 }
198 char *escapeForXML(const char* source, int length) const;
199 bool prepareForChild(bool indentInside = true);
200 void prepareForTextNode();
201
202 class Private;
203 Private * const d;
204
205 KoXmlWriter(const KoXmlWriter &); // forbidden
206 KoXmlWriter& operator=(const KoXmlWriter &); // forbidden
207};
208
209#endif /* XMLWRITER_H */
210
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
float value(const T *src, size_t ch)
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
unsigned int uint
Private *const d
KoXmlWriter(const KoXmlWriter &)
KoXmlWriter & operator=(const KoXmlWriter &)
void addTextNode(const QString &str)
void closeStartElement(Tag &tag)
void addAttribute(const char *attrName, bool value)
Definition KoXmlWriter.h:80
void addAttribute(const char *attrName, const QString &value)
Definition KoXmlWriter.h:61
void addAttribute(const char *attrName, uint value)
Definition KoXmlWriter.h:73
void addAttribute(const char *attrName, int value)
Definition KoXmlWriter.h:67
bool indentInside
whether to indent the contents of this tag
bool openingTagClosed
true once the '>' in <tag a="b"> is written out
bool lastChildIsText
last child is a text node
Tag(const Tag &original)
bool hasChildren
element or text children
Tag(const char *t=0, bool ind=true)