1 <!DOCTYPE xsl:stylesheet [
4 <xsl:stylesheet version=
"1.0"
5 xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
6 xmlns:
xs=
"http://www.w3.org/2001/XMLSchema">
8 <xsl:output method=
"text"/>
10 <xsl:include href=
"generate_shared.xsl"/>
12 <!-- Implementation: constructor -->
14 <xsl:template name=
"ctor-init-attributes">
15 <xsl:param name=
"node"/>
16 <xsl:for-each select=
"$node/xs:attribute">
17 <xsl:variable name=
"camel-case-name">
18 <xsl:call-template name=
"camel-case">
19 <xsl:with-param name=
"text" select=
"@name"/>
22 <xsl:text> m_has_attr_
</xsl:text>
23 <xsl:value-of select=
"$camel-case-name"/>
24 <xsl:text> = false;
&endl;</xsl:text>
26 <xsl:when test=
"@type = 'xs:integer'">
27 <xsl:text> m_attr_
</xsl:text>
28 <xsl:value-of select=
"$camel-case-name"/>
29 <xsl:text> =
0;
&endl;</xsl:text>
31 <xsl:when test=
"@type = 'xs:double'">
32 <xsl:text> m_attr_
</xsl:text>
33 <xsl:value-of select=
"$camel-case-name"/>
34 <xsl:text> =
0.0;
&endl;</xsl:text>
36 <xsl:when test=
"@type = 'xs:float'">
37 <xsl:text> m_attr_
</xsl:text>
38 <xsl:value-of select=
"$camel-case-name"/>
39 <xsl:text> =
0.0;
&endl;</xsl:text>
41 <xsl:when test=
"@type = 'xs:boolean'">
42 <xsl:text> m_attr_
</xsl:text>
43 <xsl:value-of select=
"$camel-case-name"/>
44 <xsl:text> = false;
&endl;</xsl:text>
50 <xsl:template name=
"ctor-init-child-elements">
51 <xsl:param name=
"node"/>
52 <xsl:for-each select=
"$node/xs:element">
53 <xsl:variable name=
"array" select=
"@maxOccurs='unbounded'"/>
54 <xsl:if test=
"not($array)">
55 <xsl:variable name=
"cpp-type">
56 <xsl:call-template name=
"xs-type-to-cpp-type">
57 <xsl:with-param name=
"xs-type" select=
"@type"/>
58 <xsl:with-param name=
"array" select=
"$array"/>
61 <xsl:variable name=
"camel-case-name">
62 <xsl:call-template name=
"camel-case">
63 <xsl:with-param name=
"text" select=
"@name"/>
67 <xsl:when test=
"@type = 'xs:integer'">
68 <xsl:text> m_
</xsl:text>
69 <xsl:value-of select=
"$camel-case-name"/>
70 <xsl:text> =
0;
&endl;</xsl:text>
72 <xsl:when test=
"@type = 'xs:float'">
73 <xsl:text> m_
</xsl:text>
74 <xsl:value-of select=
"$camel-case-name"/>
75 <xsl:text> =
0.0;
&endl;</xsl:text>
77 <xsl:when test=
"@type = 'xs:boolean'">
78 <xsl:text> m_
</xsl:text>
79 <xsl:value-of select=
"$camel-case-name"/>
80 <xsl:text> = false;
&endl;</xsl:text>
82 <xsl:when test=
"@type = 'xs:string'"></xsl:when>
84 <xsl:text> m_
</xsl:text>
85 <xsl:value-of select=
"$camel-case-name"/>
86 <xsl:text> =
0;
&endl;</xsl:text>
93 <xsl:template name=
"ctor-init-members">
94 <xsl:param name=
"node"/>
96 <xsl:if test=
"boolean($node/xs:choice)">
97 <xsl:text> m_kind = Unknown;
&endl;&endl;</xsl:text>
100 <xsl:if test=
"not($node/xs:choice)">
101 <xsl:text> m_children =
0;
&endl;</xsl:text>
104 <xsl:call-template name=
"ctor-init-attributes">
105 <xsl:with-param name=
"node" select=
"."/>
108 <xsl:if test=
"$node[@mixed='true']">
109 <xsl:text> m_text = QLatin1String(
"");
&endl;</xsl:text>
112 <xsl:for-each select=
"$node//xs:sequence | $node//xs:choice | $node//xs:all">
113 <xsl:call-template name=
"ctor-init-child-elements">
114 <xsl:with-param name=
"node" select=
"."/>
119 <xsl:template name=
"ctor-impl">
120 <xsl:param name=
"node"/>
121 <xsl:variable name=
"name" select=
"concat('Dom', $node/@name)"/>
123 <xsl:value-of select=
"$name"/>
124 <xsl:text>::
</xsl:text>
125 <xsl:value-of select=
"$name"/>
126 <xsl:text>()
&endl;</xsl:text>
127 <xsl:text>{
&endl;</xsl:text>
128 <xsl:call-template name=
"ctor-init-members">
129 <xsl:with-param name=
"node" select=
"$node"/>
131 <xsl:text>}
&endl;&endl;</xsl:text>
134 <!-- Implementation: destructor -->
136 <xsl:template name=
"dtor-delete-members">
137 <xsl:param name=
"node"/>
139 <xsl:for-each select=
"$node/xs:element">
140 <xsl:variable name=
"camel-case-name">
141 <xsl:call-template name=
"camel-case">
142 <xsl:with-param name=
"text" select=
"@name"/>
145 <xsl:variable name=
"xs-type-cat">
146 <xsl:call-template name=
"xs-type-category">
147 <xsl:with-param name=
"xs-type" select=
"@type"/>
151 <xsl:when test=
"@maxOccurs='unbounded'">
152 <xsl:if test=
"$xs-type-cat = 'pointer'">
153 <xsl:text> qDeleteAll(m_
</xsl:text>
154 <xsl:value-of select=
"$camel-case-name"/>
155 <xsl:text>);
&endl;</xsl:text>
157 <xsl:text> m_
</xsl:text>
158 <xsl:value-of select=
"$camel-case-name"/>
159 <xsl:text>.clear();
&endl;</xsl:text>
162 <xsl:if test=
"$xs-type-cat = 'pointer'">
163 <xsl:text> delete m_
</xsl:text>
164 <xsl:value-of select=
"$camel-case-name"/>
165 <xsl:text>;
&endl;</xsl:text>
172 <xsl:template name=
"dtor-impl">
173 <xsl:param name=
"node"/>
174 <xsl:variable name=
"name" select=
"concat('Dom', $node/@name)"/>
176 <xsl:value-of select=
"$name"/>
177 <xsl:text>::~
</xsl:text>
178 <xsl:value-of select=
"$name"/>
179 <xsl:text>()
&endl;</xsl:text>
180 <xsl:text>{
&endl;</xsl:text>
182 <xsl:for-each select=
"$node//xs:sequence | $node//xs:choice | $node//xs:all">
183 <xsl:call-template name=
"dtor-delete-members">
184 <xsl:with-param name=
"node" select=
"."/>
188 <xsl:text>}
&endl;&endl;</xsl:text>
191 <!-- Implementation: clear() -->
193 <xsl:template name=
"clear-impl">
194 <xsl:param name=
"node"/>
195 <xsl:variable name=
"name" select=
"concat('Dom', $node/@name)"/>
197 <xsl:text>void
</xsl:text><xsl:value-of select=
"$name"/>
198 <xsl:text>::clear(bool clear_all)
&endl;</xsl:text>
199 <xsl:text>{
&endl;</xsl:text>
201 <xsl:for-each select=
"$node//xs:sequence | $node//xs:choice | $node//xs:all">
202 <xsl:call-template name=
"dtor-delete-members">
203 <xsl:with-param name=
"node" select=
"."/>
207 <xsl:text>&endl; if (clear_all) {
&endl;</xsl:text>
210 <xsl:when test=
"$node[@mixed='true']">
211 <xsl:text> m_text = QLatin1String(
"");
&endl;</xsl:text>
214 <xsl:text> m_text.clear();
&endl;</xsl:text>
218 <xsl:call-template name=
"ctor-init-attributes">
219 <xsl:with-param name=
"node" select=
"."/>
221 <xsl:text> }
&endl;&endl;</xsl:text>
223 <xsl:if test=
"boolean($node/xs:choice)">
224 <xsl:text> m_kind = Unknown;
&endl;&endl;</xsl:text>
227 <xsl:if test=
"not($node/xs:choice)">
228 <xsl:text> m_children =
0;
&endl;</xsl:text>
231 <xsl:for-each select=
"$node//xs:sequence | $node//xs:choice | $node//xs:all">
232 <xsl:call-template name=
"ctor-init-child-elements">
233 <xsl:with-param name=
"node" select=
"."/>
237 <xsl:text>}
&endl;&endl;</xsl:text>
241 <!-- Format a string constant as QString(QLatin1Char('X')) or QLatin1String("foo"), respectively -->
242 <xsl:template name=
"string-constant">
243 <xsl:param name=
"literal"/>
245 <xsl:when test=
"string-length($literal) < 2">
246 <xsl:text>QString(QLatin1Char('
</xsl:text>
247 <xsl:value-of select=
"$literal"/>
248 <xsl:text>'))
</xsl:text>
251 <xsl:text>QLatin1String(
"</xsl:text>
252 <xsl:value-of select="$literal
"/>
253 <xsl:text>")
</xsl:text>
258 <!-- Implementation: read(QXmlStreamReader) -->
260 <xsl:template name=
"read-impl-load-attributes">
261 <xsl:param name=
"node"/>
263 <xsl:if test=
"$node/xs:attribute">
264 <xsl:text>&endl;</xsl:text>
265 <xsl:text> foreach (const QXmlStreamAttribute
&attribute, reader.attributes()) {
&endl;</xsl:text>
266 <xsl:text> QStringRef name = attribute.name();
&endl;</xsl:text>
268 <xsl:for-each select=
"$node/xs:attribute">
269 <xsl:variable name=
"camel-case-name">
270 <xsl:call-template name=
"camel-case">
271 <xsl:with-param name=
"text" select=
"@name"/>
274 <xsl:variable name=
"cap-name">
275 <xsl:call-template name=
"cap-first-char">
276 <xsl:with-param name=
"text" select=
"$camel-case-name"/>
279 <xsl:variable name=
"qstring-func">
280 <xsl:call-template name=
"xs-type-from-qstring-func">
281 <xsl:with-param name=
"xs-type" select=
"@type"/>
282 <xsl:with-param name=
"val">
283 <xsl:text>attribute.value().toString()
</xsl:text>
288 <xsl:text> if (name ==
</xsl:text>
289 <xsl:call-template name=
"string-constant">
290 <xsl:with-param name=
"literal" select=
"@name"/>
292 <xsl:text>) {
&endl;</xsl:text>
293 <xsl:text> setAttribute
</xsl:text>
294 <xsl:value-of select=
"$cap-name"/>
295 <xsl:text>(
</xsl:text>
296 <xsl:value-of select=
"$qstring-func"/>
297 <xsl:text>);
&endl;</xsl:text>
298 <xsl:text> continue;
&endl;</xsl:text>
299 <xsl:text> }
&endl;</xsl:text>
302 <xsl:text> reader.raiseError(QLatin1String(
"Unexpected attribute ") + name.toString());
&endl;</xsl:text>
303 <xsl:text> }
&endl;</xsl:text>
307 <xsl:template name=
"read-impl-load-child-element">
308 <xsl:param name=
"node"/>
310 <xsl:for-each select=
"$node/xs:element">
311 <xsl:variable name=
"camel-case-name">
312 <xsl:call-template name=
"camel-case">
313 <xsl:with-param name=
"text" select=
"@name"/>
317 <xsl:variable name=
"cap-name">
318 <xsl:call-template name=
"cap-first-char">
319 <xsl:with-param name=
"text" select=
"$camel-case-name"/>
322 <xsl:variable name=
"xs-type-cat">
323 <xsl:call-template name=
"xs-type-category">
324 <xsl:with-param name=
"xs-type" select=
"@type"/>
327 <xsl:variable name=
"lower-name">
328 <xsl:call-template name=
"lower-text">
329 <xsl:with-param name=
"text" select=
"@name"/>
332 <xsl:variable name=
"array" select=
"@maxOccurs = 'unbounded'"/>
334 <xsl:text> if (tag ==
</xsl:text>
335 <xsl:call-template name=
"string-constant">
336 <xsl:with-param name=
"literal" select=
"$lower-name"/>
338 <xsl:text>) {
&endl;</xsl:text>
341 <xsl:when test=
"not($array) and $xs-type-cat = 'value'">
342 <xsl:variable name=
"qstring-func">
343 <xsl:call-template name=
"xs-type-from-qstring-func">
344 <xsl:with-param name=
"xs-type" select=
"@type"/>
345 <xsl:with-param name=
"val" select=
"'reader.readElementText()'"/>
349 <xsl:text> setElement
</xsl:text>
350 <xsl:value-of select=
"$cap-name"/>
351 <xsl:text>(
</xsl:text>
352 <xsl:value-of select=
"$qstring-func"/>
353 <xsl:text>);
&endl;</xsl:text>
355 <xsl:when test=
"@maxOccurs='unbounded' and $xs-type-cat = 'value'">
356 <xsl:variable name=
"qstring-func">
357 <xsl:call-template name=
"xs-type-from-qstring-func">
358 <xsl:with-param name=
"xs-type" select=
"@type"/>
359 <xsl:with-param name=
"val" select=
"'reader.readElementText()'"/>
363 <xsl:text> m_
</xsl:text>
364 <xsl:value-of select=
"$camel-case-name"/>
365 <xsl:text>.append(
</xsl:text>
366 <xsl:value-of select=
"$qstring-func"/>
367 <xsl:text>);
&endl;</xsl:text>
369 <xsl:when test=
"not(@maxOccurs='unbounded') and $xs-type-cat = 'pointer'">
370 <xsl:text> Dom
</xsl:text>
371 <xsl:value-of select=
"@type"/>
372 <xsl:text> *v = new Dom
</xsl:text>
373 <xsl:value-of select=
"@type"/>
374 <xsl:text>();
&endl;</xsl:text>
375 <xsl:text> v-
>read(reader);
&endl;</xsl:text>
376 <xsl:text> setElement
</xsl:text>
377 <xsl:value-of select=
"$cap-name"/>
378 <xsl:text>(v);
&endl;</xsl:text>
380 <xsl:when test=
"@maxOccurs='unbounded' and $xs-type-cat = 'pointer'">
381 <xsl:text> Dom
</xsl:text>
382 <xsl:value-of select=
"@type"/>
383 <xsl:text> *v = new Dom
</xsl:text>
384 <xsl:value-of select=
"@type"/>
385 <xsl:text>();
&endl;</xsl:text>
386 <xsl:text> v-
>read(reader);
&endl;</xsl:text>
387 <xsl:text> m_
</xsl:text>
388 <xsl:value-of select=
"$camel-case-name"/>
389 <xsl:text>.append(v);
&endl;</xsl:text>
392 <xsl:text> continue;
&endl;</xsl:text>
393 <xsl:text> }
&endl;</xsl:text>
397 <xsl:template name=
"read-impl">
398 <xsl:param name=
"node"/>
399 <xsl:variable name=
"name" select=
"concat('Dom', $node/@name)"/>
401 <xsl:text>void
</xsl:text>
402 <xsl:value-of select=
"$name"/>
403 <xsl:text>::read(QXmlStreamReader
&reader)
&endl;</xsl:text>
405 <xsl:text>{
&endl;</xsl:text>
407 <xsl:call-template name=
"read-impl-load-attributes">
408 <xsl:with-param name=
"node" select=
"$node"/>
411 <xsl:text>&endl;</xsl:text>
413 <xsl:text> for (bool finished = false; !finished
&& !reader.hasError();) {
&endl;</xsl:text>
414 <xsl:text> switch (reader.readNext()) {
&endl;</xsl:text>
415 <xsl:text> case QXmlStreamReader::StartElement : {
&endl;</xsl:text>
416 <xsl:text> const QString tag = reader.name().toString().toLower();
&endl;</xsl:text>
418 <xsl:for-each select=
"$node//xs:sequence | $node//xs:choice | $node//xs:all">
419 <xsl:call-template name=
"read-impl-load-child-element">
420 <xsl:with-param name=
"node" select=
"."/>
424 <xsl:text> reader.raiseError(QLatin1String(
"Unexpected element ") + tag);
&endl;</xsl:text>
425 <xsl:text> }
&endl;</xsl:text>
426 <xsl:text> break;
&endl;</xsl:text>
427 <xsl:text> case QXmlStreamReader::EndElement :
&endl;</xsl:text>
428 <xsl:text> finished = true;
&endl;</xsl:text>
429 <xsl:text> break;
&endl;</xsl:text>
430 <xsl:text> case QXmlStreamReader::Characters :
&endl;</xsl:text>
431 <xsl:text> if (!reader.isWhitespace())
&endl;</xsl:text>
432 <xsl:text> m_text.append(reader.text().toString());
&endl;</xsl:text>
433 <xsl:text> break;
&endl;</xsl:text>
434 <xsl:text> default :
&endl;</xsl:text>
435 <xsl:text> break;
&endl;</xsl:text>
437 <xsl:text> }
&endl;</xsl:text>
438 <xsl:text> }
&endl;</xsl:text>
439 <xsl:text>}
&endl;&endl;</xsl:text>
442 <!-- Implementation: read(QDomElement) -->
444 <xsl:template name=
"read-impl-qdom-load-attributes">
445 <xsl:param name=
"node"/>
447 <xsl:if test=
"$node/xs:attribute">
448 <xsl:text>&endl;</xsl:text>
450 <xsl:for-each select=
"$node/xs:attribute">
451 <xsl:variable name=
"camel-case-name">
452 <xsl:call-template name=
"camel-case">
453 <xsl:with-param name=
"text" select=
"@name"/>
456 <xsl:variable name=
"cap-name">
457 <xsl:call-template name=
"cap-first-char">
458 <xsl:with-param name=
"text" select=
"$camel-case-name"/>
461 <xsl:variable name=
"qstring-func">
462 <xsl:call-template name=
"xs-type-from-qstring-func">
463 <xsl:with-param name=
"xs-type" select=
"@type"/>
464 <xsl:with-param name=
"val">
465 <xsl:text>node.attribute(
</xsl:text>
466 <xsl:call-template name=
"string-constant">
467 <xsl:with-param name=
"literal" select=
"@name"/>
469 <xsl:text>)
</xsl:text>
474 <xsl:text> if (node.hasAttribute(
</xsl:text>
475 <xsl:call-template name=
"string-constant">
476 <xsl:with-param name=
"literal" select=
"@name"/>
478 <xsl:text>))
&endl;</xsl:text>
479 <xsl:text> setAttribute
</xsl:text>
480 <xsl:value-of select=
"$cap-name"/>
481 <xsl:text>(
</xsl:text>
482 <xsl:value-of select=
"$qstring-func"/>
483 <xsl:text>);
&endl;</xsl:text>
488 <xsl:template name=
"read-impl-qdom-load-child-element">
489 <xsl:param name=
"node"/>
491 <xsl:for-each select=
"$node/xs:element">
492 <xsl:variable name=
"camel-case-name">
493 <xsl:call-template name=
"camel-case">
494 <xsl:with-param name=
"text" select=
"@name"/>
497 <xsl:variable name=
"cap-name">
498 <xsl:call-template name=
"cap-first-char">
499 <xsl:with-param name=
"text" select=
"$camel-case-name"/>
502 <xsl:variable name=
"xs-type-cat">
503 <xsl:call-template name=
"xs-type-category">
504 <xsl:with-param name=
"xs-type" select=
"@type"/>
507 <xsl:variable name=
"lower-name">
508 <xsl:call-template name=
"lower-text">
509 <xsl:with-param name=
"text" select=
"@name"/>
512 <xsl:variable name=
"array" select=
"@maxOccurs = 'unbounded'"/>
514 <xsl:text> if (tag ==
</xsl:text>
515 <xsl:call-template name=
"string-constant">
516 <xsl:with-param name=
"literal" select=
"$lower-name"/>
518 <xsl:text>) {
&endl;</xsl:text>
521 <xsl:when test=
"not($array) and $xs-type-cat = 'value'">
522 <xsl:variable name=
"qstring-func">
523 <xsl:call-template name=
"xs-type-from-qstring-func">
524 <xsl:with-param name=
"xs-type" select=
"@type"/>
525 <xsl:with-param name=
"val" select=
"'e.text()'"/>
529 <xsl:text> setElement
</xsl:text>
530 <xsl:value-of select=
"$cap-name"/>
531 <xsl:text>(
</xsl:text>
532 <xsl:value-of select=
"$qstring-func"/>
533 <xsl:text>);
&endl;</xsl:text>
535 <xsl:when test=
"@maxOccurs='unbounded' and $xs-type-cat = 'value'">
536 <xsl:variable name=
"qstring-func">
537 <xsl:call-template name=
"xs-type-from-qstring-func">
538 <xsl:with-param name=
"xs-type" select=
"@type"/>
539 <xsl:with-param name=
"val" select=
"'e.text()'"/>
543 <xsl:text> m_
</xsl:text>
544 <xsl:value-of select=
"$camel-case-name"/>
545 <xsl:text>.append(
</xsl:text>
546 <xsl:value-of select=
"$qstring-func"/>
547 <xsl:text>);
&endl;</xsl:text>
549 <xsl:when test=
"not(@maxOccurs='unbounded') and $xs-type-cat = 'pointer'">
550 <xsl:text> Dom
</xsl:text>
551 <xsl:value-of select=
"@type"/>
552 <xsl:text> *v = new Dom
</xsl:text>
553 <xsl:value-of select=
"@type"/>
554 <xsl:text>();
&endl;</xsl:text>
555 <xsl:text> v-
>read(e);
&endl;</xsl:text>
556 <xsl:text> setElement
</xsl:text>
557 <xsl:value-of select=
"$cap-name"/>
558 <xsl:text>(v);
&endl;</xsl:text>
560 <xsl:when test=
"@maxOccurs='unbounded' and $xs-type-cat = 'pointer'">
561 <xsl:text> Dom
</xsl:text>
562 <xsl:value-of select=
"@type"/>
563 <xsl:text> *v = new Dom
</xsl:text>
564 <xsl:value-of select=
"@type"/>
565 <xsl:text>();
&endl;</xsl:text>
566 <xsl:text> v-
>read(e);
&endl;</xsl:text>
567 <xsl:text> m_
</xsl:text>
568 <xsl:value-of select=
"$camel-case-name"/>
569 <xsl:text>.append(v);
&endl;</xsl:text>
572 <xsl:text> continue;
&endl;</xsl:text>
573 <xsl:text> }
&endl;</xsl:text>
577 <xsl:template name=
"read-impl-qdom">
578 <xsl:param name=
"node"/>
579 <xsl:variable name=
"name" select=
"concat('Dom', $node/@name)"/>
581 <xsl:text>#ifdef QUILOADER_QDOM_READ
&endl;</xsl:text>
583 <xsl:text>void
</xsl:text>
584 <xsl:value-of select=
"$name"/>
585 <xsl:text>::read(const QDomElement
&node)
&endl;</xsl:text>
587 <xsl:text>{
</xsl:text>
589 <xsl:call-template name=
"read-impl-qdom-load-attributes">
590 <xsl:with-param name=
"node" select=
"$node"/>
593 <xsl:text>&endl;</xsl:text>
595 <xsl:text> for (QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling()) {
&endl;</xsl:text>
596 <xsl:text> if (!n.isElement())
&endl;</xsl:text>
597 <xsl:text> continue;
&endl;</xsl:text>
598 <xsl:text> QDomElement e = n.toElement();
&endl;</xsl:text>
599 <xsl:text> QString tag = e.tagName().toLower();
&endl;</xsl:text>
601 <xsl:for-each select=
"$node//xs:sequence | $node//xs:choice | $node//xs:all">
602 <xsl:call-template name=
"read-impl-qdom-load-child-element">
603 <xsl:with-param name=
"node" select=
"."/>
607 <xsl:text> }
&endl;</xsl:text>
610 <xsl:when test=
"$node[@mixed='true']">
611 <xsl:text> m_text = QLatin1String(
"");
&endl;</xsl:text>
614 <xsl:text> m_text.clear();
&endl;</xsl:text>
618 <xsl:text> for (QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling()) {
&endl;</xsl:text>
619 <xsl:text> if (child.isText())
&endl;</xsl:text>
620 <xsl:text> m_text.append(child.nodeValue());
&endl;</xsl:text>
621 <xsl:text> }
&endl;</xsl:text>
623 <xsl:text>}
&endl;</xsl:text>
624 <xsl:text>#endif
&endl;</xsl:text>
625 <xsl:text>&endl;</xsl:text>
627 <!-- Implementation: write() -->
629 <xsl:template name=
"write-impl-save-attributes">
630 <xsl:param name=
"node"/>
632 <xsl:for-each select=
"$node/xs:attribute">
633 <xsl:variable name=
"camel-case-name">
634 <xsl:call-template name=
"camel-case">
635 <xsl:with-param name=
"text" select=
"@name"/>
638 <xsl:variable name=
"cap-name">
639 <xsl:call-template name=
"cap-first-char">
640 <xsl:with-param name=
"text" select=
"$camel-case-name"/>
643 <xsl:variable name=
"lower-name">
644 <xsl:call-template name=
"lower-text">
645 <xsl:with-param name=
"text" select=
"@name"/>
649 <xsl:text> if (hasAttribute
</xsl:text>
650 <xsl:value-of select=
"$cap-name"/>
651 <xsl:text>())
&endl;</xsl:text>
652 <xsl:text> writer.writeAttribute(
</xsl:text>
653 <xsl:call-template name=
"string-constant">
654 <xsl:with-param name=
"literal" select=
"$lower-name"/>
657 <xsl:text>,
</xsl:text>
659 <xsl:call-template name=
"xs-type-to-qstring-func">
660 <xsl:with-param name=
"xs-type" select=
"@type"/>
661 <xsl:with-param name=
"val" select=
"concat('attribute', $cap-name, '()')"/>
664 <xsl:text>);
&endl;&endl;</xsl:text>
668 <xsl:template name=
"write-impl-save-choice-child-element">
669 <xsl:param name=
"node"/>
670 <xsl:variable name=
"have-kind" select=
"name($node) = 'xs:choice'"/>
672 <xsl:text> switch (kind()) {
&endl;</xsl:text>
674 <xsl:for-each select=
"$node/xs:element">
675 <xsl:variable name=
"camel-case-name">
676 <xsl:call-template name=
"camel-case">
677 <xsl:with-param name=
"text" select=
"@name"/>
680 <xsl:variable name=
"cap-name">
681 <xsl:call-template name=
"cap-first-char">
682 <xsl:with-param name=
"text" select=
"$camel-case-name"/>
685 <xsl:variable name=
"lower-name">
686 <xsl:call-template name=
"lower-text">
687 <xsl:with-param name=
"text" select=
"@name"/>
690 <xsl:variable name=
"xs-type-cat">
691 <xsl:call-template name=
"xs-type-category">
692 <xsl:with-param name=
"xs-type" select=
"@type"/>
696 <xsl:text> case
</xsl:text>
697 <xsl:value-of select=
"$cap-name"/>
698 <xsl:text>: {
&endl;</xsl:text>
700 <xsl:when test=
"$xs-type-cat = 'value'">
701 <xsl:variable name=
"qstring-func">
702 <xsl:call-template name=
"xs-type-to-qstring-func">
703 <xsl:with-param name=
"xs-type" select=
"@type"/>
704 <xsl:with-param name=
"val" select=
"concat('element', $cap-name, '()')"/>
708 <xsl:text> writer.writeTextElement(
</xsl:text>
709 <xsl:call-template name=
"string-constant">
710 <xsl:with-param name=
"literal" select=
"$camel-case-name"/>
712 <xsl:text>,
</xsl:text>
713 <xsl:value-of select=
"$qstring-func"/>
714 <xsl:text>);
&endl;</xsl:text>
716 <xsl:when test=
"$xs-type-cat = 'pointer'">
717 <xsl:variable name=
"cpp-return-type">
718 <xsl:call-template name=
"xs-type-to-cpp-return-type">
719 <xsl:with-param name=
"xs-type" select=
"@type"/>
723 <xsl:text> </xsl:text>
724 <xsl:value-of select=
"$cpp-return-type"/>
725 <xsl:text> v = element
</xsl:text>
726 <xsl:value-of select=
"$cap-name"/>
727 <xsl:text>();
&endl;</xsl:text>
728 <xsl:text> if (v !=
0) {
&endl;</xsl:text>
729 <xsl:text> v-
>write(writer,
</xsl:text>
730 <xsl:call-template name=
"string-constant">
731 <xsl:with-param name=
"literal" select=
"$lower-name"/>
733 <xsl:text>);
&endl;</xsl:text>
734 <xsl:text> }
&endl;</xsl:text>
737 <xsl:text> break;
&endl;</xsl:text>
738 <xsl:text> }
&endl;</xsl:text>
741 <xsl:text> default:
&endl;</xsl:text>
742 <xsl:text> break;
&endl;</xsl:text>
743 <xsl:text> }
&endl;</xsl:text>
746 <xsl:template name=
"write-impl-save-sequence-child-element">
747 <xsl:param name=
"node"/>
748 <xsl:variable name=
"name" select=
"concat('Dom', $node/@name)"/>
749 <xsl:for-each select=
"$node/xs:element">
750 <xsl:variable name=
"camel-case-name">
751 <xsl:call-template name=
"camel-case">
752 <xsl:with-param name=
"text" select=
"@name"/>
755 <xsl:variable name=
"cap-name">
756 <xsl:call-template name=
"cap-first-char">
757 <xsl:with-param name=
"text" select=
"$camel-case-name"/>
760 <xsl:variable name=
"lower-name">
761 <xsl:call-template name=
"lower-text">
762 <xsl:with-param name=
"text" select=
"@name"/>
765 <xsl:variable name=
"xs-type-cat">
766 <xsl:call-template name=
"xs-type-category">
767 <xsl:with-param name=
"xs-type" select=
"@type"/>
770 <xsl:variable name=
"cpp-return-type">
771 <xsl:call-template name=
"xs-type-to-cpp-return-type">
772 <xsl:with-param name=
"xs-type" select=
"@type"/>
777 <xsl:when test=
"@maxOccurs='unbounded'">
778 <xsl:text> for (int i =
0; i
< m_
</xsl:text>
779 <xsl:value-of select=
"$camel-case-name"/>
780 <xsl:text>.size(); ++i) {
&endl;</xsl:text>
781 <xsl:text> </xsl:text>
782 <xsl:value-of select=
"$cpp-return-type"/>
783 <xsl:text> v = m_
</xsl:text>
784 <xsl:value-of select=
"$camel-case-name"/>
785 <xsl:text>[i];
&endl;</xsl:text>
787 <xsl:when test=
"$xs-type-cat = 'pointer'">
788 <xsl:text> v-
>write(writer,
</xsl:text>
789 <xsl:call-template name=
"string-constant">
790 <xsl:with-param name=
"literal" select=
"$lower-name"/>
792 <xsl:text>);
&endl;</xsl:text>
795 <xsl:variable name=
"qstring-func">
796 <xsl:call-template name=
"xs-type-to-qstring-func">
797 <xsl:with-param name=
"xs-type" select=
"@type"/>
798 <xsl:with-param name=
"val" select=
"'v'"/>
802 <xsl:text> writer.writeTextElement(
</xsl:text>
803 <xsl:call-template name=
"string-constant">
804 <xsl:with-param name=
"literal" select=
"$lower-name"/>
806 <xsl:text>,
</xsl:text>
807 <xsl:value-of select=
"$qstring-func"/>
808 <xsl:text>);
&endl;</xsl:text>
811 <xsl:text> }
&endl;</xsl:text>
814 <xsl:text> if (m_children
& </xsl:text>
815 <xsl:value-of select=
"$cap-name"/>
816 <xsl:text>) {
&endl;</xsl:text>
818 <xsl:when test=
"$xs-type-cat = 'pointer'">
819 <xsl:text> m_
</xsl:text>
820 <xsl:value-of select=
"$camel-case-name"/>
821 <xsl:text>-
>write(writer,
</xsl:text>
822 <xsl:call-template name=
"string-constant">
823 <xsl:with-param name=
"literal" select=
"$lower-name"/>
825 <xsl:text>);
&endl;</xsl:text>
828 <xsl:variable name=
"qstring-func">
829 <xsl:call-template name=
"xs-type-to-qstring-func">
830 <xsl:with-param name=
"xs-type" select=
"@type"/>
831 <xsl:with-param name=
"val" select=
"concat('m_', $camel-case-name)"/>
834 <xsl:text> writer.writeTextElement(
</xsl:text>
835 <xsl:call-template name=
"string-constant">
836 <xsl:with-param name=
"literal" select=
"$lower-name"/>
838 <xsl:text>,
</xsl:text>
839 <xsl:value-of select=
"$qstring-func"/>
840 <xsl:text>);
&endl;</xsl:text>
843 <xsl:text> }
&endl;&endl;</xsl:text>
849 <xsl:template name=
"write-impl">
850 <xsl:param name=
"node"/>
851 <xsl:variable name=
"name" select=
"concat('Dom', $node/@name)"/>
852 <xsl:variable name=
"lower-name">
853 <xsl:call-template name=
"lower-text">
854 <xsl:with-param name=
"text" select=
"@name"/>
858 <xsl:text>void
</xsl:text>
859 <xsl:value-of select=
"$name"/>
860 <xsl:text>::write(QXmlStreamWriter
&writer, const QString
&tagName) const
&endl;</xsl:text>
861 <xsl:text>{
&endl;</xsl:text>
863 <xsl:text> writer.writeStartElement(tagName.isEmpty() ? QString::fromUtf8(
"</xsl:text>
864 <xsl:value-of select="$lower-name
"/>
865 <xsl:text>") : tagName.toLower());
&endl;&endl;</xsl:text>
867 <xsl:call-template name=
"write-impl-save-attributes">
868 <xsl:with-param name=
"node" select=
"$node"/>
871 <xsl:for-each select=
"$node//xs:choice">
872 <xsl:call-template name=
"write-impl-save-choice-child-element">
873 <xsl:with-param name=
"node" select=
"."/>
877 <xsl:for-each select=
"$node//xs:sequence | $node//xs:all">
878 <xsl:call-template name=
"write-impl-save-sequence-child-element">
879 <xsl:with-param name=
"node" select=
"."/>
883 <xsl:text> if (!m_text.isEmpty())
&endl;</xsl:text>
884 <xsl:text> writer.writeCharacters(m_text);
&endl;&endl;</xsl:text>
886 <xsl:text> writer.writeEndElement();
&endl;</xsl:text>
887 <xsl:text>}
&endl;&endl;</xsl:text>
890 <!-- Implementation: child element setters -->
892 <xsl:template name=
"child-setter-impl-helper">
893 <xsl:param name=
"node"/>
894 <xsl:param name=
"name"/>
895 <xsl:variable name=
"make-kind-enum" select=
"name($node)='xs:choice'"/>
896 <xsl:variable name=
"isChoice" select=
"name($node)='xs:choice'"/>
898 <xsl:for-each select=
"$node/xs:element">
899 <xsl:variable name=
"array" select=
"@maxOccurs = 'unbounded'"/>
900 <xsl:variable name=
"camel-case-name">
901 <xsl:call-template name=
"camel-case">
902 <xsl:with-param name=
"text" select=
"@name"/>
905 <xsl:variable name=
"cap-name">
906 <xsl:call-template name=
"cap-first-char">
907 <xsl:with-param name=
"text" select=
"$camel-case-name"/>
910 <xsl:variable name=
"return-cpp-type">
911 <xsl:call-template name=
"xs-type-to-cpp-return-type">
912 <xsl:with-param name=
"xs-type" select=
"@type"/>
913 <xsl:with-param name=
"array" select=
"$array"/>
916 <xsl:variable name=
"argument-cpp-type">
917 <xsl:call-template name=
"xs-type-to-cpp-argument-type">
918 <xsl:with-param name=
"xs-type" select=
"@type"/>
919 <xsl:with-param name=
"array" select=
"$array"/>
922 <xsl:variable name=
"xs-type-cat">
923 <xsl:call-template name=
"xs-type-category">
924 <xsl:with-param name=
"xs-type" select=
"@type"/>
925 <xsl:with-param name=
"array" select=
"$array"/>
929 <xsl:if test=
"$xs-type-cat = 'pointer'">
930 <xsl:value-of select=
"$return-cpp-type"/>
931 <xsl:text> </xsl:text>
932 <xsl:value-of select=
"$name"/>
933 <xsl:text>::takeElement
</xsl:text>
934 <xsl:value-of select=
"$cap-name"/>
935 <xsl:text>()
&endl;{
&endl;</xsl:text>
936 <xsl:text> </xsl:text>
937 <xsl:value-of select=
"$return-cpp-type"/>
938 <xsl:text> a = m_
</xsl:text>
939 <xsl:value-of select=
"$camel-case-name"/>
940 <xsl:text>;
&endl;</xsl:text>
941 <xsl:text> m_
</xsl:text>
942 <xsl:value-of select=
"$camel-case-name"/>
943 <xsl:text> =
0;
&endl;</xsl:text>
944 <xsl:if test=
"not($isChoice)">
945 <xsl:text> m_children ^=
</xsl:text>
946 <xsl:value-of select=
"$cap-name"/>
947 <xsl:text>;
&endl;</xsl:text>
949 <xsl:text> return a;
&endl;</xsl:text>
950 <xsl:text>}
&endl;&endl;</xsl:text>
953 <xsl:text>void
</xsl:text>
954 <xsl:value-of select=
"$name"/>
955 <xsl:text>::setElement
</xsl:text>
956 <xsl:value-of select=
"$cap-name"/>
957 <xsl:text>(
</xsl:text>
958 <xsl:value-of select=
"$argument-cpp-type"/>
959 <xsl:text> a)
&endl;</xsl:text>
960 <xsl:text>{
&endl;</xsl:text>
962 <xsl:when test=
"$make-kind-enum">
963 <xsl:text> clear(false);
&endl;</xsl:text>
964 <xsl:text> m_kind =
</xsl:text>
965 <xsl:value-of select=
"$cap-name"/>
966 <xsl:text>;
&endl;</xsl:text>
968 <xsl:when test=
"$xs-type-cat = 'pointer'">
969 <xsl:text> delete
</xsl:text>
970 <xsl:text>m_
</xsl:text>
971 <xsl:value-of select=
"$camel-case-name"/>
972 <xsl:text>;
&endl;</xsl:text>
975 <xsl:if test=
"not($isChoice)">
976 <xsl:text> m_children |=
</xsl:text>
977 <xsl:value-of select=
"$cap-name"/>
978 <xsl:text>;
&endl;</xsl:text>
980 <xsl:text> m_
</xsl:text>
981 <xsl:value-of select=
"$camel-case-name"/>
982 <xsl:text> = a;
&endl;</xsl:text>
983 <xsl:text>}
&endl;&endl;</xsl:text>
987 <xsl:template name=
"child-setter-impl">
988 <xsl:param name=
"node"/>
989 <xsl:variable name=
"name" select=
"concat('Dom', $node/@name)"/>
991 <xsl:for-each select=
"$node/xs:sequence | $node/xs:choice | $node/xs:all">
992 <xsl:call-template name=
"child-setter-impl-helper">
993 <xsl:with-param name=
"node" select=
"."/>
994 <xsl:with-param name=
"name" select=
"$name"/>
999 <xsl:template name=
"child-clear-impl">
1000 <xsl:param name=
"node"/>
1002 <xsl:variable name=
"name" select=
"concat('Dom', @name)"/>
1003 <xsl:for-each select=
"$node/xs:sequence | $node/xs:choice | $node/xs:all">
1004 <xsl:variable name=
"isChoice" select=
"name()='xs:choice'"/>
1005 <xsl:variable name=
"make-child-enum" select=
"boolean(xs:sequence) and not(@maxOccurs='unbounded')"/>
1007 <xsl:for-each select=
"xs:element">
1008 <xsl:if test=
"not($isChoice) and not(@maxOccurs='unbounded')">
1009 <xsl:variable name=
"camel-case-name">
1010 <xsl:call-template name=
"camel-case">
1011 <xsl:with-param name=
"text" select=
"@name"/>
1012 </xsl:call-template>
1014 <xsl:variable name=
"cap-name">
1015 <xsl:call-template name=
"cap-first-char">
1016 <xsl:with-param name=
"text" select=
"$camel-case-name"/>
1017 </xsl:call-template>
1019 <xsl:variable name=
"xs-type-cat">
1020 <xsl:call-template name=
"xs-type-category">
1021 <xsl:with-param name=
"xs-type" select=
"@type"/>
1022 <xsl:with-param name=
"array" select=
"@maxOccurs='unbounded'"/>
1023 </xsl:call-template>
1026 <xsl:text>void
</xsl:text>
1027 <xsl:value-of select=
"$name"/>
1028 <xsl:text>::clearElement
</xsl:text>
1029 <xsl:value-of select=
"$cap-name"/>
1030 <xsl:text>()
&endl;</xsl:text>
1031 <xsl:text>{
&endl;</xsl:text>
1032 <xsl:if test=
"$xs-type-cat = 'pointer'">
1033 <xsl:text> delete m_
</xsl:text>
1034 <xsl:value-of select=
"$camel-case-name"/>
1035 <xsl:text>;
&endl;</xsl:text>
1036 <xsl:text> m_
</xsl:text>
1037 <xsl:value-of select=
"$camel-case-name"/>
1038 <xsl:text> =
0;
&endl;</xsl:text>
1040 <xsl:text> m_children
&= ~
</xsl:text>
1041 <xsl:value-of select=
"$cap-name"/>
1042 <xsl:text>;
&endl;</xsl:text>
1043 <xsl:text>}
&endl;&endl;</xsl:text>
1050 <!-- Implementation -->
1052 <xsl:template name=
"class-implementation">
1053 <xsl:param name=
"node"/>
1055 <xsl:call-template name=
"clear-impl">
1056 <xsl:with-param name=
"node" select=
"$node"/>
1057 </xsl:call-template>
1059 <xsl:call-template name=
"ctor-impl">
1060 <xsl:with-param name=
"node" select=
"$node"/>
1061 </xsl:call-template>
1063 <xsl:call-template name=
"dtor-impl">
1064 <xsl:with-param name=
"node" select=
"$node"/>
1065 </xsl:call-template>
1067 <xsl:call-template name=
"read-impl">
1068 <xsl:with-param name=
"node" select=
"$node"/>
1069 </xsl:call-template>
1071 <xsl:call-template name=
"read-impl-qdom">
1072 <xsl:with-param name=
"node" select=
"$node"/>
1073 </xsl:call-template>
1075 <xsl:call-template name=
"write-impl">
1076 <xsl:with-param name=
"node" select=
"$node"/>
1077 </xsl:call-template>
1079 <xsl:call-template name=
"child-setter-impl">
1080 <xsl:with-param name=
"node" select=
"$node"/>
1081 </xsl:call-template>
1083 <xsl:call-template name=
"child-clear-impl">
1084 <xsl:with-param name=
"node" select=
"$node"/>
1085 </xsl:call-template>
1091 <xsl:template match=
"xs:schema">
1093 <xsl:text>/****************************************************************************
1095 ** Copyright (C)
2010 Nokia Corporation and/or its subsidiary(-ies).
1096 ** All rights reserved.
1097 ** Contact: Nokia Corporation (qt-info@nokia.com)
1099 ** This file is part of the tools applications of the Qt Toolkit.
1101 ** $QT_BEGIN_LICENSE:LGPL$
1102 ** No Commercial Usage
1103 ** This file contains pre-release code and may not be distributed.
1104 ** You may use this file in accordance with the terms and conditions
1105 ** contained in the Technology Preview License Agreement accompanying
1108 ** GNU Lesser General Public License Usage
1109 ** Alternatively, this file may be used under the terms of the GNU Lesser
1110 ** General Public License version
2.1 as published by the Free Software
1111 ** Foundation and appearing in the file LICENSE.LGPL included in the
1112 ** packaging of this file. Please review the following information to
1113 ** ensure the GNU Lesser General Public License version
2.1 requirements
1114 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-
2.1.html.
1116 ** In addition, as a special exception, Nokia gives you certain additional
1117 ** rights. These rights are described in the Nokia Qt LGPL Exception
1118 ** version
1.1, included in the file LGPL_EXCEPTION.txt in this package.
1120 ** If you have questions regarding the use of this file, please contact
1121 ** Nokia at qt-info@nokia.com.
1132 ****************************************************************************/
1134 <xsl:text>#include
"ui4_p.h"&endl;</xsl:text>
1135 <xsl:text>&endl;</xsl:text>
1136 <xsl:text>#ifdef QUILOADER_QDOM_READ
&endl;</xsl:text>
1137 <xsl:text>#include
<QtXml/QDomElement
>&endl;</xsl:text>
1138 <xsl:text>#endif
&endl;</xsl:text>
1139 <xsl:text>&endl;</xsl:text>
1140 <xsl:text>QT_BEGIN_NAMESPACE
&endl;</xsl:text>
1142 <xsl:text>#ifdef QFORMINTERNAL_NAMESPACE
&endl;</xsl:text>
1143 <xsl:text>using namespace QFormInternal;
&endl;</xsl:text>
1144 <xsl:text>#endif
&endl;</xsl:text>
1145 <xsl:text>&endl;</xsl:text>
1147 <xsl:text>/*******************************************************************************
&endl;</xsl:text>
1148 <xsl:text>** Implementations
&endl;</xsl:text>
1149 <xsl:text>*/
&endl;&endl;</xsl:text>
1151 <xsl:for-each select=
"xs:complexType">
1152 <xsl:call-template name=
"class-implementation">
1153 <xsl:with-param name=
"node" select=
"."/>
1154 </xsl:call-template>
1156 <xsl:text>QT_END_NAMESPACE
&endl;</xsl:text>
1158 <xsl:text>&endl;</xsl:text>