QtBase  v6.3.1
xmloutput.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the qmake application of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #ifndef XMLOUTPUT_H
30 #define XMLOUTPUT_H
31 
32 #include <qtextstream.h>
33 #include <qstack.h>
34 
36 
37 class XmlOutput
38 {
39 public:
41  NoConversion, // No change
42  EscapeConversion, // Use '\"'
43  XMLConversion // Use &quot;
44  };
45  enum XMLFormat {
46  NoNewLine, // No new lines, unless added manually
47  NewLine // All properties & tags indented on new lines
48  };
49  enum XMLState {
50  Bare, // Not in tag or attribute
51  Tag, // <tagname attribute1="value"
52  Attribute // attribute2="value">
53  };
54  enum XMLType {
55  tNothing, // No XML output, and not state change
56  tRaw, // Raw text (no formating)
57  tDeclaration, // <?xml version="x.x" encoding="xxx"?>
58  tTag, // <tagname attribute1="value"
59  tTagValue, // <tagname>value</tagname>
60  tValueTag, // value</tagname>
61  tCloseTag, // Closes an open tag
62  tAttribute, // attribute2="value">
63  tAttributeTag, // attribute on the same line as a tag
64  tData, // Tag data (formating done)
65  tImport, // <import "type"="path" />
66  tComment, // <!-- Comment -->
67  tCDATA // <![CDATA[ ... ]]>
68  };
69 
71  ~XmlOutput();
72 
73  // Settings
76  void setIndentLevel(int level);
77  int indentLevel();
78  void setState(XMLState state);
79  void setFormat(XMLFormat newFormat);
80  XMLState state();
81 
82 
83  struct xml_output {
84  XMLType xo_type; // Type of struct instance
85  QString xo_text; // Tag/Attribute name/xml version
86  QString xo_value; // Value of attributes/xml encoding
87 
91  : xo_type(xo.xo_type), xo_text(xo.xo_text), xo_value(xo.xo_value) {}
92  };
93 
94  // Streams
95  XmlOutput& operator<<(const QString& o);
96  XmlOutput& operator<<(const xml_output& o);
97 
98 private:
99  void increaseIndent();
100  void decreaseIndent();
101  void updateIndent();
102 
103  QString doConversion(const QString &text);
104 
105  // Output functions
106  void newTag(const QString &tag);
107  void newTagOpen(const QString &tag);
108  void closeOpen();
109  void closeTag();
110  void closeTo(const QString &tag);
111  void closeAll();
112 
113  void addDeclaration(const QString &version, const QString &encoding);
114  void addRaw(const QString &rawText);
115  void addAttribute(const QString &attribute, const QString &value);
116  void addAttributeTag(const QString &attribute, const QString &value);
117  void addData(const QString &data);
118 
119  // Data
120  QTextStream &xmlFile;
121  QString indent;
122 
123  QString currentIndent;
124  int currentLevel;
125  XMLState currentState;
126 
128  ConverstionType conversion;
129  QStack<QString> tagStack;
130 };
131 
133 {
135 }
136 
137 inline XmlOutput::xml_output raw(const QString &rawText)
138 {
139  return XmlOutput::xml_output(XmlOutput::tRaw, rawText, QString());
140 }
141 
143  const QString &encoding = QString())
144 {
146 }
147 
149  const QString &encoding = QString())
150 {
151  return declaration(version, encoding);
152 }
153 
155 {
157 }
158 
159 
161 {
163 }
164 
165 inline XmlOutput::xml_output tagValue(const QString &tagName, const QString &value)
166 {
168 }
169 
170 inline XmlOutput::xml_output import(const QString &tagName, const QString &value)
171 {
173 }
174 
176 {
178 }
179 
181 {
183 }
184 
186 {
188 }
189 
191  const QString &value)
192 {
194 }
195 
197  const QString &value)
198 {
200 }
201 
203  const QString &value)
204 {
205  return attribute(name, value);
206 }
207 
209  const QString &value)
210 {
211  return attributeTag(name, value);
212 }
213 
215 {
217 }
218 
220 {
222 }
223 
225 {
227 }
228 
230 
231 #endif // XMLOUTPUT_H
#define value
[5]
char * data()
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:62
@ Attribute
Definition: xmloutput.h:52
XMLState state()
Definition: xmloutput.cpp:76
@ tTagValue
Definition: xmloutput.h:59
@ tCloseTag
Definition: xmloutput.h:61
@ tComment
Definition: xmloutput.h:66
@ tAttribute
Definition: xmloutput.h:62
@ tDeclaration
Definition: xmloutput.h:57
@ tAttributeTag
Definition: xmloutput.h:63
@ tNothing
Definition: xmloutput.h:55
@ tValueTag
Definition: xmloutput.h:60
void setState(XMLState state)
Definition: xmloutput.cpp:66
@ NoNewLine
Definition: xmloutput.h:46
void setFormat(XMLFormat newFormat)
Definition: xmloutput.cpp:71
QString indentString()
Definition: xmloutput.cpp:51
void setIndentLevel(int level)
Definition: xmloutput.cpp:56
XmlOutput & operator<<(const QString &o)
Definition: xmloutput.cpp:153
int indentLevel()
Definition: xmloutput.cpp:61
void setIndentString(const QString &indentString)
Definition: xmloutput.cpp:46
XmlOutput(QTextStream &file, ConverstionType type=XMLConversion)
Definition: xmloutput.cpp:33
ConverstionType
Definition: xmloutput.h:40
@ XMLConversion
Definition: xmloutput.h:43
@ EscapeConversion
Definition: xmloutput.h:42
@ NoConversion
Definition: xmloutput.h:41
QString text
[meta data]
int const char * version
Definition: zlib.h:814
#define QString()
Definition: parse-defines.h:51
EGLOutputLayerEXT EGLint EGLAttrib value
EGLOutputLayerEXT EGLint attribute
@ text
GLenum type
Definition: qopengl.h:270
GLenum GLuint GLint level
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
GLint GLsizei GLsizei GLenum format
QFile file
[0]
xml_output(const xml_output &xo)
Definition: xmloutput.h:90
xml_output(XMLType type, const QString &text, const QString &value)
Definition: xmloutput.h:88
XmlOutput::xml_output closeall()
Definition: xmloutput.h:185
XmlOutput::xml_output attribute(const QString &name, const QString &value)
Definition: xmloutput.h:190
XmlOutput::xml_output declaration(const QString &version=QString("1.0"), const QString &encoding=QString())
Definition: xmloutput.h:142
XmlOutput::xml_output cdata(const QString &text)
Definition: xmloutput.h:224
XmlOutput::xml_output tag(const QString &name)
Definition: xmloutput.h:154
XmlOutput::xml_output closetag()
Definition: xmloutput.h:175
XmlOutput::xml_output noxml()
Definition: xmloutput.h:132
XmlOutput::xml_output raw(const QString &rawText)
Definition: xmloutput.h:137
XmlOutput::xml_output attributeTag(const QString &name, const QString &value)
Definition: xmloutput.h:196
XmlOutput::xml_output tagValue(const QString &tagName, const QString &value)
Definition: xmloutput.h:165
XmlOutput::xml_output decl(const QString &version=QString("1.0"), const QString &encoding=QString())
Definition: xmloutput.h:148
XmlOutput::xml_output attrTag(const QString &name, const QString &value)
Definition: xmloutput.h:208
XmlOutput::xml_output comment(const QString &text)
Definition: xmloutput.h:219
XmlOutput::xml_output attr(const QString &name, const QString &value)
Definition: xmloutput.h:202
XmlOutput::xml_output valueTag(const QString &value)
Definition: xmloutput.h:160