Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the qmake application of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef XMLOUTPUT_H
43#define XMLOUTPUT_H
44
45#include <qtextstream.h>
46#include <qstack.h>
47
48QT_BEGIN_NAMESPACE
49
50class XmlOutput
51{
52public:
53 enum ConverstionType {
54 NoConversion, // No change
55 EscapeConversion, // Use '\"'
56 XMLConversion // Use &quot;
57 };
58 enum XMLFormat {
59 NoNewLine, // No new lines, unless added manually
60 NewLine // All properties & tags indented on new lines
61 };
62 enum XMLState {
63 Bare, // Not in tag or attribute
64 Tag, // <tagname attribute1="value"
65 Attribute // attribute2="value">
66 };
67 enum XMLType {
68 tNothing, // No XML output, and not state change
69 tRaw, // Raw text (no formating)
70 tDeclaration, // <?xml version="x.x" encoding="xxx"?>
71 tTag, // <tagname attribute1="value"
72 tTagValue, // <tagname>value</tagname>
73 tValueTag, // value</tagname>
74 tCloseTag, // Closes an open tag
75 tAttribute, // attribute2="value">
76 tAttributeTag, // attribute on the same line as a tag
77 tData, // Tag data (formating done)
78 tImport, // <import "type"="path" />
79 tComment, // <!-- Comment -->
80 tCDATA // <![CDATA[ ... ]]>
81 };
82
83 XmlOutput(QTextStream &file, ConverstionType type = XMLConversion);
84 ~XmlOutput();
85
86 // Settings
87 void setIndentString(const QString &indentString);
88 QString indentString();
89 void setIndentLevel(int level);
90 int indentLevel();
91 void setState(XMLState state);
92 void setFormat(XMLFormat newFormat);
93 XMLState state();
94
95
96 struct xml_output {
97 XMLType xo_type; // Type of struct instance
98 QString xo_text; // Tag/Attribute name/xml version
99 QString xo_value; // Value of attributes/xml encoding
100
101 xml_output(XMLType type, const QString &text, const QString &value)
102 : xo_type(type), xo_text(text), xo_value(value) {}
103 xml_output(const xml_output &xo)
104 : xo_type(xo.xo_type), xo_text(xo.xo_text), xo_value(xo.xo_value) {}
105 };
106
107 // Streams
108 XmlOutput& operator<<(const QString& o);
109 XmlOutput& operator<<(const xml_output& o);
110
111private:
112 void increaseIndent();
113 void decreaseIndent();
114 void updateIndent();
115
116 QString doConversion(const QString &text);
117
118 // Output functions
119 void newTag(const QString &tag);
120 void newTagOpen(const QString &tag);
121 void closeOpen();
122 void closeTag();
123 void closeTo(const QString &tag);
124 void closeAll();
125
126 void addDeclaration(const QString &version, const QString &encoding);
127 void addRaw(const QString &rawText);
128 void addAttribute(const QString &attribute, const QString &value);
129 void addAttributeTag(const QString &attribute, const QString &value);
130 void addData(const QString &data);
131
132 // Data
133 QTextStream &xmlFile;
134 QString indent;
135
136 QString currentIndent;
137 int currentLevel;
138 XMLState currentState;
139
140 XMLFormat format;
141 ConverstionType conversion;
142 QStack<QString> tagStack;
143};
144
145inline XmlOutput::xml_output noxml()
146{
147 return XmlOutput::xml_output(XmlOutput::tNothing, QString(), QString());
148}
149
150inline XmlOutput::xml_output raw(const QString &rawText)
151{
152 return XmlOutput::xml_output(XmlOutput::tRaw, rawText, QString());
153}
154
155inline XmlOutput::xml_output declaration(const QString &version = QString("1.0"),
156 const QString &encoding = QString())
157{
158 return XmlOutput::xml_output(XmlOutput::tDeclaration, version, encoding);
159}
160
161inline XmlOutput::xml_output decl(const QString &version = QString("1.0"),
162 const QString &encoding = QString())
163{
164 return declaration(version, encoding);
165}
166
167inline XmlOutput::xml_output tag(const QString &name)
168{
169 return XmlOutput::xml_output(XmlOutput::tTag, name, QString());
170}
171
172
173inline XmlOutput::xml_output valueTag(const QString &value)
174{
175 return XmlOutput::xml_output(XmlOutput::tValueTag, value, QString());
176}
177
178inline XmlOutput::xml_output tagValue(const QString &tagName, const QString &value)
179{
180 return XmlOutput::xml_output(XmlOutput::tTagValue, tagName, value);
181}
182
183inline XmlOutput::xml_output import(const QString &tagName, const QString &value)
184{
185 return XmlOutput::xml_output(XmlOutput::tImport, tagName, value);
186}
187
188inline XmlOutput::xml_output closetag()
189{
190 return XmlOutput::xml_output(XmlOutput::tCloseTag, QString(), QString());
191}
192
193inline XmlOutput::xml_output closetag(const QString &toTag)
194{
195 return XmlOutput::xml_output(XmlOutput::tCloseTag, toTag, QString());
196}
197
198inline XmlOutput::xml_output closeall()
199{
200 return XmlOutput::xml_output(XmlOutput::tCloseTag, QString(), QString("all"));
201}
202
203inline XmlOutput::xml_output attribute(const QString &name,
204 const QString &value)
205{
206 return XmlOutput::xml_output(XmlOutput::tAttribute, name, value);
207}
208
209inline XmlOutput::xml_output attributeTag(const QString &name,
210 const QString &value)
211{
212 return XmlOutput::xml_output(XmlOutput::tAttributeTag, name, value);
213}
214
215inline XmlOutput::xml_output attr(const QString &name,
216 const QString &value)
217{
218 return attribute(name, value);
219}
220
221inline XmlOutput::xml_output attrTag(const QString &name,
222 const QString &value)
223{
224 return attributeTag(name, value);
225}
226
227inline XmlOutput::xml_output data(const QString &text = QString())
228{
229 return XmlOutput::xml_output(XmlOutput::tData, text, QString());
230}
231
232inline XmlOutput::xml_output comment(const QString &text)
233{
234 return XmlOutput::xml_output(XmlOutput::tComment, text, QString());
235}
236
237inline XmlOutput::xml_output cdata(const QString &text)
238{
239 return XmlOutput::xml_output(XmlOutput::tCDATA, text, QString());
240}
241
242QT_END_NAMESPACE
243
244#endif // XMLOUTPUT_H
245

Warning: That file was not part of the compilation database. It may have many parsing errors.