summaryrefslogtreecommitdiffstats
path: root/tools/qdoc3/ditaxmlgenerator.cpp
blob: 3fb90d2f550cca7605666c7759d86f2c3be85122 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

/*
  ditaxmlgenerator.cpp
*/

#include "codemarker.h"
#include "codeparser.h"
#include "ditaxmlgenerator.h"
#include "node.h"
#include "separator.h"
#include "tree.h"
#include <ctype.h>
#include <qdebug.h>
#include <qlist.h>
#include <qiterator.h>
#include <qtextcodec.h>
#include <QUuid>

QT_BEGIN_NAMESPACE

#define COMMAND_VERSION                         Doc::alias("version")
int DitaXmlGenerator::id = 0;
bool DitaXmlGenerator::inApiDesc = false;
bool DitaXmlGenerator::inSection = false;
bool DitaXmlGenerator::inDetailedDescription = false;

#define cxxapi_d_xref                      	Doc::alias("cxxapi-d-xref")
#define cxxclass                           	Doc::alias("cxxclass")
#define cxxdefine                          	Doc::alias("cxxdefine")
#define cxxenumeration                     	Doc::alias("cxxenumeration")
#define cxxfile                            	Doc::alias("cxxfile")
#define cxxfunction                        	Doc::alias("cxxfunction")
#define cxxstruct                          	Doc::alias("cxxstruct")
#define cxxtypedef                         	Doc::alias("cxxtypedef")
#define cxxunion                           	Doc::alias("cxxunion")
#define cxxvariable                        	Doc::alias("cxxvariable")

#define CXXAPIMAP                          	Doc::alias("cxxAPIMap")
#define CXXCLASSREF                        	Doc::alias("cxxClassRef")
#define CXXDEFINEREF                       	Doc::alias("cxxDefineRef")
#define CXXENUMERATIONREF                  	Doc::alias("cxxEnumerationRef")
#define CXXFILEREF                         	Doc::alias("cxxFileRef")
#define CXXFUNCTIONREF                     	Doc::alias("cxxFunctionRef")
#define CXXSTRUCTREF                       	Doc::alias("cxxStructRef")
#define CXXTYPDEFREF                       	Doc::alias("cxxTypedefRef")
#define CXXUNIONREF                        	Doc::alias("cxxUnionRef")
#define CXXVARIABLEREF                     	Doc::alias("cxxVariableRef")

#define CXXCLASS                           	Doc::alias("cxxClass")
#define CXXCLASSABSTRACT                   	Doc::alias("cxxClassAbstract")
#define CXXCLASSACCESSSPECIFIER            	Doc::alias("cxxClassAccessSpecifier")
#define CXXCLASSAPIITEMLOCATION            	Doc::alias("cxxClassAPIItemLocation")
#define CXXCLASSBASECLASS                  	Doc::alias("cxxClassBaseClass")
#define CXXCLASSBASECLASSSTRUCT            	Doc::alias("cxxClassBaseStruct")
#define CXXCLASSBASEUNION                  	Doc::alias("cxxClassBaseUnion")
#define CXXCLASSDECLARATIONFILE            	Doc::alias("cxxClassDeclarationFile")
#define CXXCLASSDECLARATIONFILELINE        	Doc::alias("cxxClassDeclarationFileLine")
#define CXXCLASSDEFINITION                 	Doc::alias("cxxClassDefinition")
#define CXXCLASSDEFINITIONFILE             	Doc::alias("cxxClassDefinitionFile")
#define CXXCLASSDEFINITIONFILEEND          	Doc::alias("cxxClassDefinitionFileLineEnd")
#define CXXCLASSDEFINITIONFILESTART        	Doc::alias("cxxClassDefinitionFileLineStart")
#define CXXCLASSDERIVATION                 	Doc::alias("cxxClassDerivation")
#define CXXCLASSDERIVATIONACCESSSPECIFIER  	Doc::alias("cxxClassDerivationAccessSpecifier")
#define CXXCLASSDERIVATIONS                	Doc::alias("cxxClassDerivations")
#define CXXCLASSDERIVATIONVIRTUAL          	Doc::alias("cxxClassDerivationVirtual")
#define CXXCLASSDETAIL                     	Doc::alias("cxxClassDetail")
#define CXXCLASSENUMERATIONINHERITED       	Doc::alias("cxxClassEnumerationInherited")
#define CXXCLASSENUMERATORINHERITED        	Doc::alias("cxxClassEnumeratorInherited")
#define CXXCLASSFUNCTIONINHERITED          	Doc::alias("cxxClassFunctionInherited")
#define CXXCLASSINHERITS                   	Doc::alias("cxxClassInherits")
#define CXXCLASSINHERITSDETAIL             	Doc::alias("cxxClassInheritsDetail")
#define CXXCLASSNESTED                     	Doc::alias("cxxClassNested")
#define CXXCLASSNESTEDCLASS                	Doc::alias("cxxClassNestedClass")
#define CXXCLASSNESTEDDETAIL               	Doc::alias("cxxClassNestedDetail")
#define CXXCLASSNESTEDSTRUCT               	Doc::alias("cxxClassNestedStruct")
#define CXXCLASSNESTEDUNION                	Doc::alias("cxxClassNestedUnion")
#define CXXCLASSTEMPLATEPARAMETER          	Doc::alias("cxxClassTemplateParameter")
#define CXXCLASSTEMPLATEPARAMETERS         	Doc::alias("cxxClassTemplateParameters")
#define CXXCLASSTEMPLATEPARAMETERTYPE      	Doc::alias("cxxClassTemplateParameterType")
#define CXXCLASSVARIABLEINHERITED          	Doc::alias("cxxClassVariableInherited")

#define CXXDEFINE                          	Doc::alias("cxxDefine")
#define CXXDEFINEACCESSSPECIFIER           	Doc::alias("cxxDefineAccessSpecifier")
#define CXXDEFINEAPIITEMLOCATION           	Doc::alias("cxxDefineAPIItemLocation")
#define CXXDEFINEDECLARATIONFILE           	Doc::alias("cxxDefineDeclarationFile")
#define CXXDEFINEDECLARATIONFILELINE       	Doc::alias("cxxDefineDeclarationFileLine")
#define CXXDEFINEDEFINITION                	Doc::alias("cxxDefineDefinition")
#define CXXDEFINEDETAIL                    	Doc::alias("cxxDefineDetail")
#define CXXDEFINENAMELOOKUP                	Doc::alias("cxxDefineNameLookup")
#define CXXDEFINEPARAMETER                 	Doc::alias("cxxDefineParameter")
#define CXXDEFINEPARAMETERDECLARATIONNAME  	Doc::alias("cxxDefineParameterDeclarationName")
#define CXXDEFINEPARAMETERS                	Doc::alias("cxxDefineParameters")
#define CXXDEFINEPROTOTYPE                 	Doc::alias("cxxDefinePrototype")
#define CXXDEFINEREIMPLEMENTED             	Doc::alias("cxxDefineReimplemented")

#define CXXENUMERATION                     	Doc::alias("cxxEnumeration")
#define CXXENUMERATIONACCESSSPECIFIER      	Doc::alias("cxxEnumerationAccessSpecifier")
#define CXXENUMERATIONAPIITEMLOCATION      	Doc::alias("cxxEnumerationAPIItemLocation")
#define CXXENUMERATIONDECLARATIONFILE      	Doc::alias("cxxEnumerationDeclarationFile")
#define CXXENUMERATIONDECLARATIONFILELINE  	Doc::alias("cxxEnumerationDeclarationFileLine")
#define CXXENUMERATIONDEFINITION                Doc::alias("cxxEnumerationDefinition")
#define CXXENUMERATIONDEFINITIONFILE            Doc::alias("cxxEnumerationDefinitionFile")
#define CXXENUMERATIONDEFINITIONFILELINEEND     Doc::alias("cxxEnumerationDefinitionFileLineEnd")
#define CXXENUMERATIONDEFINITIONFILELINESTART   Doc::alias("cxxEnumerationDefinitionFileLineStart")
#define CXXENUMERATIONDETAIL                    Doc::alias("cxxEnumerationDetail")
#define CXXENUMERATIONNAMELOOKUP                Doc::alias("cxxEnumerationNameLookup")
#define CXXENUMERATIONPROTOTYPE                 Doc::alias("cxxEnumerationPrototype")
#define CXXENUMERATIONREIMPLEMENTED             Doc::alias("cxxEnumerationReimplemented")
#define CXXENUMERATIONSCOPEDNAME                Doc::alias("cxxEnumerationScopedName")
#define CXXENUMERATOR                           Doc::alias("cxxEnumerator")
#define CXXENUMERATORAPIITEMLOCATION            Doc::alias("cxxEnumeratorAPIItemLocation")
#define CXXENUMERATORDECLARATIONFILE            Doc::alias("cxxEnumeratorDeclarationFile")
#define CXXENUMERATORDECLARATIONFILELINE        Doc::alias("cxxEnumeratorDeclarationFileLine")
#define CXXENUMERATORINITIALISER                Doc::alias("cxxEnumeratorInitialiser")
#define CXXENUMERATORNAMELOOKUP                 Doc::alias("cxxEnumeratorNameLookup")
#define CXXENUMERATORPROTOTYPE                  Doc::alias("cxxEnumeratorPrototype")
#define CXXENUMERATORS                          Doc::alias("cxxEnumerators")
#define CXXENUMERATORSCOPEDNAME                 Doc::alias("cxxEnumeratorScopedName")

#define CXXFILE_INFO_TYPES                      Doc::alias("cxxFile-info-types")
#define CXXFILE_TYPES_DEFAULT                   Doc::alias("cxxFile-types-default")
#define CXXFILE                                 Doc::alias("cxxFile")
#define CXXFILEAPIITMELOCATION                  Doc::alias("cxxFileAPIItemLocation")
#define CXXFILEDECLARATIONFILE                  Doc::alias("cxxFileDeclarationFile")

#define CXXFUNCTION                             Doc::alias("cxxFunction")
#define CXXFUNCTIONACCESSSPECIFIER              Doc::alias("cxxFunctionAccessSpecifier")
#define CXXFUNCTIONAPIITEMLOCATION              Doc::alias("cxxFunctionAPIItemLocation")
#define CXXFUNCTIONCONST                        Doc::alias("cxxFunctionConst")
#define CXXFUNCTIONCONSTRUCTOR                  Doc::alias("cxxFunctionConstructor")
#define CXXFUNCTIONDECLARATIONFILE              Doc::alias("cxxFunctionDeclarationFile")
#define CXXFUNCTIONDECLARATIONFILELINE          Doc::alias("cxxFunctionDeclarationFileLine")
#define CXXFUNCTIONDECLAREDTYPE                 Doc::alias("cxxFunctionDeclaredType")
#define CXXFUNCTIONDEFINITION                   Doc::alias("cxxFunctionDefinition")
#define CXXFUNCTIONDEFINITIONFILE               Doc::alias("cxxFunctionDefinitionFile")
#define CXXFUNCTIONDEFINITIONFILELINEEND        Doc::alias("cxxFunctionDefinitionFileLineEnd")
#define CXXFUNCTIONDEFINITIONFILELINESTART      Doc::alias("cxxFunctionDefinitionFileLineStart")
#define CXXFUNCTIONDESTRUCTOR                   Doc::alias("cxxFunctionDestructor")
#define CXXFUNCTIONDETAIL                       Doc::alias("cxxFunctionDetail")
#define CXXFUNCTIONEXPLICIT                     Doc::alias("cxxFunctionExplicit")
#define CXXFUNCTIONINLINE                       Doc::alias("cxxFunctionInline")
#define CXXFUNCTIONNAMELOOKUP                   Doc::alias("cxxFunctionNameLookup")
#define CXXFUNCTIONPARAMETER                    Doc::alias("cxxFunctionParameter")
#define CXXFUNCTIONPARAMETERDECLARATIONNAME     Doc::alias("cxxFunctionParameterDeclarationName")
#define CXXFUNCTIONPARAMETERDECLAREDTYPE        Doc::alias("cxxFunctionParameterDeclaredType")
#define CXXFUNCTIONPARAMETERDEFAULTVALUE        Doc::alias("cxxFunctionParameterDefaultValue")
#define CXXFUNCTIONPARAMETERDEFINITIONNAME      Doc::alias("cxxFunctionParameterDefinitionName")
#define CXXFUNCTIONPARAMETERS                   Doc::alias("cxxFunctionParameters")
#define CXXFUNCTIONPROTOTYPE                    Doc::alias("cxxFunctionPrototype")
#define CXXFUNCTIONPUREVIRTUAL                  Doc::alias("cxxFunctionPureVirtual")
#define CXXFUNCTIONREIMPLEMENTED                Doc::alias("cxxFunctionReimplemented")
#define CXXFUNCTIONRETURNTYPE                   Doc::alias("cxxFunctionReturnType")
#define CXXFUNCTIONSCOPEDNAME                   Doc::alias("cxxFunctionScopedName")
#define CXXFUNCTIONSTORAGECLASSSPECIFIEREXTERN  Doc::alias("cxxFunctionStorageClassSpecifierExtern")
#define CXXFUNCTIONSTORAGECLASSSPECIFIERMUTABLE Doc::alias("cxxFunctionStorageClassSpecifierMutable")
#define CXXFUNCTIONSTORAGECLASSSPECIFIERSTATIC  Doc::alias("cxxFunctionStorageClassSpecifierStatic")
#define CXXFUNCTIONTEMPLATEPARAMETER            Doc::alias("cxxFunctionTemplateParameter")
#define CXXFUNCTIONTEMPLATEPARAMETERS           Doc::alias("cxxFunctionTemplateParameters")
#define CXXFUNCTIONTEMPLATEPARAMETERTYPE        Doc::alias("cxxFunctionTemplateParameterType")
#define CXXFUNCTIONVIRTUAL                      Doc::alias("cxxFunctionVirtual")
#define CXXFUNCTIONVOLATILE                     Doc::alias("cxxFunctionVolatile")

#define CXXSTRUCT                               Doc::alias("cxxStruct")
#define CXXSTRUCTABSTRACT                       Doc::alias("cxxStructAbstract")
#define CXXSTRUCTACCESSSPECIFIER                Doc::alias("cxxStructAccessSpecifier")
#define CXXSTRUCTAPIITEMLOCATION                Doc::alias("cxxStructAPIItemLocation")
#define CXXSTRUCTBASECLASS                      Doc::alias("cxxStructBaseClass")
#define CXXSTRUCTBASESTRUCT                     Doc::alias("cxxStructBaseStruct")
#define CXXSTRUCTBASEUNION                      Doc::alias("cxxStructBaseUnion")
#define CXXSTRUCTDECLARATIONFILE                Doc::alias("cxxStructDeclarationFile")
#define CXXSTRUCTDECLARATIONFILELINE            Doc::alias("cxxStructDeclarationFileLine")
#define CXXSTRUCTDEFINITION                     Doc::alias("cxxStructDefinition")
#define CXXSTRUCTDEFINITIONFILE                 Doc::alias("cxxStructDefinitionFile")
#define CXXSTRUCTDEFINITIONFILELINEEND          Doc::alias("cxxStructDefinitionFileLineEnd")
#define CXXSTRUCTDEFINITIONFILELINESTART        Doc::alias("cxxStructDefinitionFileLineStart")
#define CXXSTRUCTDERIVATION                     Doc::alias("cxxStructDerivation")
#define CXXSTRUCTDERIVATIONACCESSSPECIFIER      Doc::alias("cxxStructDerivationAccessSpecifier")
#define CXXSTRUCTDERIVATIONS                    Doc::alias("cxxStructDerivations")
#define CXXSTRUCTDERIVATIONVIRTUAL              Doc::alias("cxxStructDerivationVirtual")
#define CXXSTRUCTDETAIL                         Doc::alias("cxxStructDetail")
#define CXXSTRUCTENUMERATIONINHERITED           Doc::alias("cxxStructEnumerationInherited")
#define CXXSTRUCTENUMERATORINHERITED            Doc::alias("cxxStructEnumeratorInherited")
#define CXXSTRUCTFUNCTIONINHERITED              Doc::alias("cxxStructFunctionInherited")
#define CXXSTRUCTINHERITS                       Doc::alias("cxxStructInherits")
#define CXXSTRUCTINHERITSDETAIL                 Doc::alias("cxxStructInheritsDetail")
#define CXXSTRUCTNESTED                         Doc::alias("cxxStructNested")
#define CXXSTRUCTNESTEDCLASS                    Doc::alias("cxxStructNestedClass")
#define CXXSTRUCTNESTEDDETAIL                   Doc::alias("cxxStructNestedDetail")
#define CXXSTRUCTNESTEDSTRUCT                   Doc::alias("cxxStructNestedStruct")
#define CXXSTRUCTNESTEDUNION                    Doc::alias("cxxStructNestedUnion")
#define CXXSTRUCTTEMPLATEPARAMETER              Doc::alias("cxxStructTemplateParameter")
#define CXXSTRUCTTEMPLATEPARAMETERS             Doc::alias("cxxStructTemplateParameters")
#define CXXSTRUCTTEMPLATEPARAMETERTYPE          Doc::alias("cxxStructTemplateParameterType")
#define CXXSTRUCTVARIABLEINHERITED              Doc::alias("cxxStructVariableInherited")

#define CXXTYPEDEF                              Doc::alias("cxxTypedef")
#define CXXTYPEDEFACCESSSPECIFIER               Doc::alias("cxxTypedefAccessSpecifier")
#define CXXTYPEDEFAPIITEMLOCATION               Doc::alias("cxxTypedefAPIItemLocation")
#define CXXTYPEDEFDECLARATIONFILE               Doc::alias("cxxTypedefDeclarationFile")
#define CXXTYPEDEFDECLARATIONFILELINE           Doc::alias("cxxTypedefDeclarationFileLine")
#define CXXTYPEDEFDECLAREDTYPE                  Doc::alias("cxxTypedefDeclaredType")
#define CXXTYPEDEFDEFINITION                    Doc::alias("cxxTypedefDefinition")
#define CXXTYPEDEFDETAIL                        Doc::alias("cxxTypedefDetail")
#define CXXTYPEDEFNAMELOOKUP                    Doc::alias("cxxTypedefNameLookup")
#define CXXTYPEDEFPROTOTYPE                     Doc::alias("cxxTypedefPrototype")
#define CXXTYPEDEFREIMPLEMENTED                 Doc::alias("cxxTypedefReimplemented")
#define CXXTYPEDEFSCOPEDNAME                    Doc::alias("cxxTypedefScopedName")

#define CXXUNION                                Doc::alias("cxxUnion")
#define CXXUNIONABSTRACT                        Doc::alias("cxxUnionAbstract")
#define CXXUNIONACCESSSPECIFIER                 Doc::alias("cxxUnionAccessSpecifier")
#define CXXUNIONAPIITEMLOCATION                 Doc::alias("cxxUnionAPIItemLocation")
#define CXXUNIONDECLARATIONFILE                 Doc::alias("cxxUnionDeclarationFile")
#define CXXUNIONDECLARATIONFILELINE             Doc::alias("cxxUnionDeclarationFileLine")
#define CXXUNIONDEFINITION                      Doc::alias("cxxUnionDefinition")
#define CXXUNIONDEFINITIONFILE                  Doc::alias("cxxUnionDefinitionFile")
#define CXXUNIONDEFINITIONFILELINEEND           Doc::alias("cxxUnionDefinitionFileLineEnd")
#define CXXUNIONDEFINITIONFILELINESTART         Doc::alias("cxxUnionDefinitionFileLineStart")
#define CXXUNIONDETAIL                          Doc::alias("cxxUnionDetail")
#define CXXUNIONNESTED                          Doc::alias("cxxUnionNested")
#define CXXUNIONNESTEDCLASS                     Doc::alias("cxxUnionNestedClass")
#define CXXUNIONNESTEDDETAIL                    Doc::alias("cxxUnionNestedDetail")
#define CXXUNIONNESTEDSTRUCT                    Doc::alias("cxxUnionNestedStruct")
#define CXXUNIONNESTEDUNION                     Doc::alias("cxxUnionNestedUnion")
#define CXXUNIONTEMPLATEPARAMETER               Doc::alias("cxxUnionTemplateParameter")
#define CXXUNIONTEMPLATEPARAMETERS              Doc::alias("cxxUnionTemplateParameters")
#define CXXUNIONTEMPLATEPARAMETERTYPE           Doc::alias("cxxUnionTemplateParameterType")

#define CXXVARIABLE                             Doc::alias("cxxVariable")
#define CXXVARIABLEACCESSSPECIFIER              Doc::alias("cxxVariableAccessSpecifier")
#define CXXVARIABLEAPIITEMLOCATION              Doc::alias("cxxVariableAPIItemLocation")
#define CXXVARIABLECONST                        Doc::alias("cxxVariableConst")
#define CXXVARIABLEDECLARATIONFILE              Doc::alias("cxxVariableDeclarationFile")
#define CXXVARIABLEDECLARATIONFILELINE          Doc::alias("cxxVariableDeclarationFileLine")
#define CXXVARIABLEDECLAREDTYPE                 Doc::alias("cxxVariableDeclaredType")
#define CXXVARIABLEDEFINITION                   Doc::alias("cxxVariableDefinition")
#define CXXVARIABLEDETAIL                       Doc::alias("cxxVariableDetail")
#define CXXVARIABLENAMELOOKUP                   Doc::alias("cxxVariableNameLookup")
#define CXXVARIABLEPROTOTYPE                    Doc::alias("cxxVariablePrototype")
#define CXXVARIABLEREIMPLEMENTED                Doc::alias("cxxVariableReimplemented")
#define CXXVARIABLESCOPEDNAME                   Doc::alias("cxxVariableScopedName")
#define CXXVARIABLESTORAGECLASSSPECIFIEREXTERN  Doc::alias("cxxVariableStorageClassSpecifierExtern")
#define CXXVARIABLESTORAGECLASSSPECIFIERMUTABLE Doc::alias("cxxVariableStorageClassSpecifierMutable")
#define CXXVARIABLESTORAGECLASSSPECIFIERSTATIC  Doc::alias("cxxVariableStorageClassSpecifierStatic")
#define CXXVARIABLEVOLATILE                     Doc::alias("cxxVariableVolatile")

#define APIREF		                        Doc::alias("apiRef")
#define APINAME		                        Doc::alias("apiName")
#define APIDETAIL		                Doc::alias("apiDetail")
#define APISYNTAX		                Doc::alias("apiSyntax")
#define APISYNTAXTEXT				Doc::alias("apiSyntaxText")
#define APISYNTAXITEM				Doc::alias("apiSyntaxItem")
#define APIDEF		        		Doc::alias("apiDef")
#define APIQUALIFIER				Doc::alias("apiQualifier")
#define APIRELATION				Doc::alias("apiRelation")
#define APITYPE		        		Doc::alias("apiType")
#define APIARRAY		        	Doc::alias("apiArray")
#define APIDATA		        		Doc::alias("apiData")
#define APIDEFNOTE		        	Doc::alias("apiDefNote")
#define APIDEFITEM		        	Doc::alias("apiDefItem")
#define APIITEMNAME				Doc::alias("apiItemName")
#define APIDESC		        		Doc::alias("apiDesc")
#define APIIMPL		        		Doc::alias("apiImpl")

#define APIPACKAGE		        	Doc::alias("apiPackage")

#define APICLASSIFIER				Doc::alias("apiClassifier")
#define APICLASSIFIERDETAIL			Doc::alias("apiClassifierDetail")
#define APICLASSIFIERDEF			Doc::alias("apiClassifierDef")
#define APICLASSIFIERMEMBER			Doc::alias("apiClassifierMember")
#define APIOTHERCLASSIFIER			Doc::alias("apiOtherClassifier")
#define APIBASECLASSIFIER			Doc::alias("apiBaseClassifier")

#define APIOPERATION				Doc::alias("apiOperation")
#define APIOPERATIONDETAIL			Doc::alias("apiOperationDetail")
#define APIOPERATIONDEF				Doc::alias("apiOperationDef")
#define APIRETURN		        	Doc::alias("apiReturn")
#define APIPARAM		        	Doc::alias("apiParam")
#define APIEVENT		        	Doc::alias("apiEvent")
#define APIOPERATIONDEFITEM			Doc::alias("apiOperationDefItem")
#define APIOPERATIONCLASSIFIER			Doc::alias("apiOperationClassifier")
#define APICONSTRUCTORDEF			Doc::alias("apiConstructorDef")

#define APIVALUE		        	Doc::alias("apiValue")
#define APIVALUEDETAIL				Doc::alias("apiValueDetail")
#define APIVALUEDEF				Doc::alias("apiValueDef")
#define APIVALUEMEMBER				Doc::alias("apiValueMember")
#define APIVALUECLASSIFIER			Doc::alias("apiValueClassifier")

#define APIclassifier				Doc::alias("apiclassifier")
#define APIoperation				Doc::alias("apioperation")
#define APIpackage		        	Doc::alias("apipackage")
#define APIvalue		        	Doc::alias("apivalue")

#define APIMAP		        		Doc::alias("apiMap")
#define APIITEMREF		        	Doc::alias("apiItemRef")

#define SHORTDESC                               Doc::alias("shortdesc")

QString DitaXmlGenerator::sinceTitles[] =
    {
        "    New Namespaces",
        "    New Classes",
        "    New Member Functions",
        "    New Functions in Namespaces",
        "    New Global Functions",
        "    New Macros",
        "    New Enum Types",
        "    New Typedefs",
        "    New Properties",
        "    New Variables",
        "    New QML Elements",
        "    New Qml Properties",
        "    New Qml Signals",
        "    New Qml Methods",
        ""
    };

static bool showBrokenLinks = false;

/*!
  Appends an <xref> element to the current XML stream
  with the \a href attribute and the \a text.
 */
void DitaXmlGenerator::addLink(const QString& href,
                               const QStringRef& text)
{
    if (!href.isEmpty()) {
        xmlWriter().writeStartElement("xref");
        xmlWriter().writeAttribute("href", href);
        xmlWriter().writeCharacters(text.toString());
        xmlWriter().writeEndElement(); // </xref>
    }
    else {
        xmlWriter().writeCharacters(text.toString());
    }
}

/*!
  The default constructor.
 */
DitaXmlGenerator::DitaXmlGenerator()
    : inLink(false),
      inContents(false),
      inSectionHeading(false),
      inTableHeader(false),
      inTableBody(false),
      numTableRows(0),
      threeColumnEnumValueTable(true),
      offlineDocs(true),
      funcLeftParen("\\S(\\()"),
      myTree(0),
      slow(false),
      obsoleteLinks(false),
      noLinks(false),
      tableColumnCount(0)
{
    // nothing yet.
}

/*!
  The destructor has nothing to do.
 */
DitaXmlGenerator::~DitaXmlGenerator()
{
    GuidMaps::iterator i = guidMaps.begin();
    while (i != guidMaps.end()) {
        delete i.value();
        ++i;
    }
}

/*!
  A lot of internal structures are initialized.
 */
void DitaXmlGenerator::initializeGenerator(const Config &config)
{
    static const struct {
        const char *key;
        const char *tag;
    } defaults[] = {
        { ATOM_FORMATTING_BOLD, "b" },
        { ATOM_FORMATTING_INDEX, "<!--" },
        { ATOM_FORMATTING_ITALIC, "i" },
        { ATOM_FORMATTING_PARAMETER, "i" },
        { ATOM_FORMATTING_SUBSCRIPT, "sub" },
        { ATOM_FORMATTING_SUPERSCRIPT, "sup" },
        { ATOM_FORMATTING_TELETYPE, "tt", },
        { ATOM_FORMATTING_UNDERLINE, "u", },
        { 0, 0 }
    };

    Generator::initializeGenerator(config);
    obsoleteLinks = config.getBool(QLatin1String(CONFIG_OBSOLETELINKS));
    setImageFileExtensions(QStringList() << "png" << "jpg" << "jpeg" << "gif");
    int i = 0;
    while (defaults[i].key) {
        formattingLeftMap().insert(defaults[i].key, defaults[i].tag);
        i++;
    }

    style = config.getString(DitaXmlGenerator::format() +
                             Config::dot +
                             DITAXMLGENERATOR_STYLE);
    postHeader = config.getString(DitaXmlGenerator::format() +
                                  Config::dot +
                                  DITAXMLGENERATOR_POSTHEADER);
    postPostHeader = config.getString(DitaXmlGenerator::format() +
                                      Config::dot +
                                      DITAXMLGENERATOR_POSTPOSTHEADER);
    footer = config.getString(DitaXmlGenerator::format() +
                              Config::dot +
                              DITAXMLGENERATOR_FOOTER);
    address = config.getString(DitaXmlGenerator::format() +
                               Config::dot +
                               DITAXMLGENERATOR_ADDRESS);
    pleaseGenerateMacRef = config.getBool(DitaXmlGenerator::format() +
                                          Config::dot +
                                          DITAXMLGENERATOR_GENERATEMACREFS);

    project = config.getString(CONFIG_PROJECT);
    projectDescription = config.getString(CONFIG_DESCRIPTION);
    if (projectDescription.isEmpty() && !project.isEmpty())
        projectDescription = project + " Reference Documentation";

    projectUrl = config.getString(CONFIG_URL);

    outputEncoding = config.getString(CONFIG_OUTPUTENCODING);
    if (outputEncoding.isEmpty())
        outputEncoding = QLatin1String("ISO-8859-1");
    outputCodec = QTextCodec::codecForName(outputEncoding.toLocal8Bit());

    naturalLanguage = config.getString(CONFIG_NATURALLANGUAGE);
    if (naturalLanguage.isEmpty())
        naturalLanguage = QLatin1String("en");

    QSet<QString> editionNames = config.subVars(CONFIG_EDITION);
    QSet<QString>::ConstIterator edition = editionNames.begin();
    while (edition != editionNames.end()) {
        QString editionName = *edition;
        QStringList editionModules = config.getStringList(CONFIG_EDITION +
                                                          Config::dot +
                                                          editionName +
                                                          Config::dot +
                                                          "modules");
        QStringList editionGroups = config.getStringList(CONFIG_EDITION +
                                                         Config::dot +
                                                         editionName +
                                                         Config::dot +
                                                         "groups");

        if (!editionModules.isEmpty())
            editionModuleMap[editionName] = editionModules;
        if (!editionGroups.isEmpty())
            editionGroupMap[editionName] = editionGroups;

        ++edition;
    }

    slow = config.getBool(CONFIG_SLOW);

    stylesheets = config.getStringList(DitaXmlGenerator::format() +
                                       Config::dot +
                                       DITAXMLGENERATOR_STYLESHEETS);
    customHeadElements = config.getStringList(DitaXmlGenerator::format() +
                                              Config::dot +
                                              DITAXMLGENERATOR_CUSTOMHEADELEMENTS);
    codeIndent = config.getInt(CONFIG_CODEINDENT);

}

/*!
  All this does is call the same function in the base class.
 */
void DitaXmlGenerator::terminateGenerator()
{
    Generator::terminateGenerator();
}

/*!
  Returns "DITAXML".
 */
QString DitaXmlGenerator::format()
{
    return "DITAXML";
}

/*!
  Calls lookupGuid() to get a GUID for \a text, then writes
  it to the XML stream as an "id" attribute, and returns it.
 */
QString DitaXmlGenerator::writeGuidAttribute(QString text)
{
    QString guid = lookupGuid(outFileName(),text);
    xmlWriter().writeAttribute("id",guid);
    return guid;
}


/*!
  Write's the GUID for the \a node to the current XML stream
  as an "id" attribute. If the \a node doesn't yet have a GUID,
  one is generated.
 */
void DitaXmlGenerator::writeGuidAttribute(Node* node)
{
    xmlWriter().writeAttribute("id",node->guid());
}

/*!
  Looks up \a text in the GUID map. If it finds \a text,
  it returns the associated GUID. Otherwise it inserts
  \a text into the map with a new GUID, and it returns
  the new GUID.
 */
QString DitaXmlGenerator::lookupGuid(QString text)
{
    QMap<QString, QString>::const_iterator i = name2guidMap.find(text);
    if (i != name2guidMap.end())
        return i.value();
    QString guid = QUuid::createUuid().toString();
    name2guidMap.insert(text,guid);
    return guid;
}

/*!
  First, look up the GUID map for \a fileName. If there isn't
  a GUID map for \a fileName, create one and insert it into
  the map of GUID maps. Then look up \a text in that GUID map.
  If \a text is found, return the associated GUID. Otherwise,
  insert \a text into the GUID map with a new GUID, and return
  the new GUID.
 */
QString DitaXmlGenerator::lookupGuid(const QString& fileName, const QString& text)
{
    GuidMap* gm = lookupGuidMap(fileName);
    GuidMap::const_iterator i = gm->find(text);
    if (i != gm->end())
        return i.value();
    QString guid = QUuid::createUuid().toString();
    gm->insert(text,guid);
    return guid;
}

/*!
  Looks up \a fileName in the map of GUID maps. If it finds
  \a fileName, it returns a pointer to the associated GUID
  map. Otherwise it creates a new GUID map and inserts it
  into the map of GUID maps with \a fileName as its key.
 */
GuidMap* DitaXmlGenerator::lookupGuidMap(const QString& fileName)
{
    GuidMaps::const_iterator i = guidMaps.find(fileName);
    if (i != guidMaps.end())
        return i.value();
    GuidMap* gm = new GuidMap;
    guidMaps.insert(fileName,gm);
    return gm;
}

/*!
  This is where the DITA XML files are written.
  \note The file generation is done in the base class,
  PageGenerator::generateTree().
 */
void DitaXmlGenerator::generateTree(const Tree *tree, CodeMarker *marker)
{
    myTree = tree;
    nonCompatClasses.clear();
    mainClasses.clear();
    compatClasses.clear();
    obsoleteClasses.clear();
    moduleClassMap.clear();
    moduleNamespaceMap.clear();
    funcIndex.clear();
    legaleseTexts.clear();
    serviceClasses.clear();
    qmlClasses.clear();
    findAllClasses(tree->root());
    findAllFunctions(tree->root());
    findAllLegaleseTexts(tree->root());
    findAllNamespaces(tree->root());
    findAllSince(tree->root());

    PageGenerator::generateTree(tree, marker);
}

void DitaXmlGenerator::startText(const Node* /* relative */,
                                 CodeMarker* /* marker */)
{
    inLink = false;
    inContents = false;
    inSectionHeading = false;
    inTableHeader = false;
    numTableRows = 0;
    threeColumnEnumValueTable = true;
    link.clear();
    sectionNumber.clear();
}

static int countTableColumns(const Atom* t)
{
    int result = 0;
    if (t->type() == Atom::TableHeaderLeft) {
        while (t->type() == Atom::TableHeaderLeft) {
            int count = 0;
            t = t->next();
            while (t->type() != Atom::TableHeaderRight) {
                if (t->type() == Atom::TableItemLeft)
                    ++count;
                t = t->next();
            }
            if (count > result)
                result = count;
            t = t->next();
        }
    }
    else if (t->type() == Atom::TableRowLeft) {
        while (t->type() != Atom::TableRowRight) {
            if (t->type() == Atom::TableItemLeft)
                ++result;
            t = t->next();
        }
    }
    return result;
}

/*!
  Generate html from an instance of Atom.
 */
int DitaXmlGenerator::generateAtom(const Atom *atom,
                                   const Node *relative,
                                   CodeMarker *marker)
{
    int skipAhead = 0;
    QString hx;
    static bool in_para = false;
    QString guid, hc;

    switch (atom->type()) {
    case Atom::AbstractLeft:
        break;
    case Atom::AbstractRight:
        break;
    case Atom::AutoLink:
        if (!noLinks && !inLink && !inContents && !inSectionHeading) {
            const Node* node = 0;
            QString link = getLink(atom, relative, marker, &node);
            if (!link.isEmpty()) {
                beginLink(link, node, relative, marker);
                generateLink(atom, relative, marker);
                endLink();
            }
            else {
                xmlWriter().writeCharacters(protectEnc(atom->string()));
            }
        }
        else {
            xmlWriter().writeCharacters(protectEnc(atom->string()));
        }
        break;
    case Atom::BaseName:
        break;
    case Atom::BriefLeft:
        if (relative->type() == Node::Fake) {
            skipAhead = skipAtoms(atom, Atom::BriefRight);
            break;
        }
        if (inApiDesc || inSection)
            xmlWriter().writeStartElement("p");
        else {
            noLinks = true;
            xmlWriter().writeStartElement(SHORTDESC);
        }
        if (relative->type() == Node::Property ||
            relative->type() == Node::Variable) {
            QString str;
            atom = atom->next();
            while (atom != 0 && atom->type() != Atom::BriefRight) {
                if (atom->type() == Atom::String ||
                    atom->type() == Atom::AutoLink)
                    str += atom->string();
                skipAhead++;
                atom = atom->next();
            }
            str[0] = str[0].toLower();
            if (str.right(1) == ".")
                str.truncate(str.length() - 1);
            xmlWriter().writeCharacters("This ");
            if (relative->type() == Node::Property)
                xmlWriter().writeCharacters("property");
            else
                xmlWriter().writeCharacters("variable");
            QStringList words = str.split(" ");
            if (!(words.first() == "contains" || words.first() == "specifies"
                || words.first() == "describes" || words.first() == "defines"
                || words.first() == "holds" || words.first() == "determines"))
                xmlWriter().writeCharacters(" holds ");
            else
                xmlWriter().writeCharacters(" ");
            xmlWriter().writeCharacters(str + ".");
        }
        break;
    case Atom::BriefRight:
        if (relative->type() != Node::Fake) {
            xmlWriter().writeEndElement(); // </shortdesc> or </p>
            noLinks = false;
        }
        break;
    case Atom::C:
        xmlWriter().writeStartElement(formattingLeftMap()[ATOM_FORMATTING_TELETYPE]);
        if (inLink) {
            xmlWriter().writeCharacters(protectEnc(plainCode(atom->string())));
        }
        else {
            writeText(atom->string(), marker, relative);
        }
        xmlWriter().writeEndElement(); // sse writeStartElement() above
        break;
    case Atom::Code:
        {
            xmlWriter().writeStartElement("pre");
            xmlWriter().writeAttribute("outputclass","highlightedcode");
            QString chars = trimmedTrailing(atom->string()); 
            writeText(chars, marker, relative);
            xmlWriter().writeEndElement(); // </pre>
        }
	break;
    case Atom::Qml:
        xmlWriter().writeStartElement("pre");
        xmlWriter().writeAttribute("outputclass","highlightedcode");
        writeText(trimmedTrailing(atom->string()), marker, relative);
        xmlWriter().writeEndElement(); // </pre>
	break;
    case Atom::CodeNew:
        xmlWriter().writeStartElement("p");
        xmlWriter().writeCharacters("you can rewrite it as");
        xmlWriter().writeEndElement(); // </p>
        xmlWriter().writeStartElement("pre");
        xmlWriter().writeAttribute("outputclass","highlightedcode");
        writeText(trimmedTrailing(atom->string()), marker, relative);
        xmlWriter().writeEndElement(); // </pre>
        break;
    case Atom::CodeOld:
        xmlWriter().writeStartElement("p");
        xmlWriter().writeCharacters("For example, if you have code like");
        xmlWriter().writeEndElement(); // </p>
        // fallthrough
    case Atom::CodeBad:
        xmlWriter().writeStartElement("pre");
        xmlWriter().writeAttribute("outputclass","highlightedcode");
        xmlWriter().writeCharacters(trimmedTrailing(protectEnc(plainCode(atom->string()))));
        xmlWriter().writeEndElement(); // </pre>
	break;
    case Atom::FootnoteLeft:
        // ### For now
        if (in_para) {
            xmlWriter().writeEndElement(); // </p>
            in_para = false;
        }
        xmlWriter().writeCharacters("<!-- ");
        break;
    case Atom::FootnoteRight:
        // ### For now
        xmlWriter().writeCharacters("-->");
        break;
    case Atom::FormatElse:
    case Atom::FormatEndif:
    case Atom::FormatIf:
        break;
    case Atom::FormattingLeft:
        xmlWriter().writeStartElement(formattingLeftMap()[atom->string()]);
        if (atom->string() == ATOM_FORMATTING_PARAMETER) {
            if (atom->next() != 0 && atom->next()->type() == Atom::String) {
                QRegExp subscriptRegExp("([a-z]+)_([0-9n])");
                if (subscriptRegExp.exactMatch(atom->next()->string())) {
                    xmlWriter().writeCharacters(subscriptRegExp.cap(1));
                    xmlWriter().writeStartElement("sub");
                    xmlWriter().writeCharacters(subscriptRegExp.cap(2));
                    xmlWriter().writeEndElement(); // </sub>
                    skipAhead = 1;
                }
            }
        }
        break;
    case Atom::FormattingRight:
        if (atom->string() == ATOM_FORMATTING_LINK) {
            endLink();
        }
        else {
            xmlWriter().writeEndElement(); // ?
        }
        break;
    case Atom::AnnotatedList:
        {
            QList<Node*> values = myTree->groups().values(atom->string());
            NodeMap nodeMap;
            for (int i = 0; i < values.size(); ++i) {
                const Node* n = values.at(i);
                if ((n->status() != Node::Internal) && (n->access() != Node::Private)) {
                    nodeMap.insert(n->nameForLists(),n);
                }
            }
            generateAnnotatedList(relative, marker, nodeMap);
        }
        break;
    case Atom::GeneratedList:
        if (atom->string() == "annotatedclasses") {
            generateAnnotatedList(relative, marker, nonCompatClasses);
        }
        else if (atom->string() == "classes") {
            generateCompactList(relative, marker, nonCompatClasses, true);
        }
        else if (atom->string() == "qmlclasses") {
            generateCompactList(relative, marker, qmlClasses, true);
        }
        else if (atom->string().contains("classesbymodule")) {
            QString arg = atom->string().trimmed();
            QString moduleName = atom->string().mid(atom->string().indexOf(
                "classesbymodule") + 15).trimmed();
            if (moduleClassMap.contains(moduleName))
                generateAnnotatedList(relative, marker, moduleClassMap[moduleName]);
        }
        else if (atom->string().contains("classesbyedition")) {

            QString arg = atom->string().trimmed();
            QString editionName = atom->string().mid(atom->string().indexOf(
                "classesbyedition") + 16).trimmed();

            if (editionModuleMap.contains(editionName)) {

                // Add all classes in the modules listed for that edition.
                NodeMap editionClasses;
                foreach (const QString &moduleName, editionModuleMap[editionName]) {
                    if (moduleClassMap.contains(moduleName))
                        editionClasses.unite(moduleClassMap[moduleName]);
                }

                // Add additional groups and remove groups of classes that
                // should be excluded from the edition.

                QMultiMap <QString, Node *> groups = myTree->groups();
                foreach (const QString &groupName, editionGroupMap[editionName]) {
                    QList<Node *> groupClasses;
                    if (groupName.startsWith("-")) {
                        groupClasses = groups.values(groupName.mid(1));
                        foreach (const Node *node, groupClasses)
                            editionClasses.remove(node->name());
                    }
                    else {
                        groupClasses = groups.values(groupName);
                        foreach (const Node *node, groupClasses)
                            editionClasses.insert(node->name(), node);
                    }
                }
                generateAnnotatedList(relative, marker, editionClasses);
            }
        }
        else if (atom->string() == "classhierarchy") {
            generateClassHierarchy(relative, marker, nonCompatClasses);
        }
        else if (atom->string() == "compatclasses") {
            generateCompactList(relative, marker, compatClasses, false);
        }
        else if (atom->string() == "obsoleteclasses") {
            generateCompactList(relative, marker, obsoleteClasses, false);
        }
        else if (atom->string() == "functionindex") {
            generateFunctionIndex(relative, marker);
        }
        else if (atom->string() == "legalese") {
            generateLegaleseList(relative, marker);
        }
        else if (atom->string() == "mainclasses") {
            generateCompactList(relative, marker, mainClasses, true);
        }
        else if (atom->string() == "services") {
            generateCompactList(relative, marker, serviceClasses, false);
        }
        else if (atom->string() == "overviews") {
            generateOverviewList(relative, marker);
        }
        else if (atom->string() == "namespaces") {
            generateAnnotatedList(relative, marker, namespaceIndex);
        }
        else if (atom->string() == "related") {
            const FakeNode *fake = static_cast<const FakeNode *>(relative);
            if (fake && !fake->groupMembers().isEmpty()) {
                NodeMap groupMembersMap;
                foreach (const Node *node, fake->groupMembers()) {
                    if (node->type() == Node::Fake)
                        groupMembersMap[fullName(node, relative, marker)] = node;
                }
                generateAnnotatedList(fake, marker, groupMembersMap);
            }
        }
        break;
    case Atom::SinceList:
        {
            NewSinceMaps::const_iterator nsmap;
            nsmap = newSinceMaps.find(atom->string());
            NewClassMaps::const_iterator ncmap;
            ncmap = newClassMaps.find(atom->string());
            NewClassMaps::const_iterator nqcmap;
            nqcmap = newQmlClassMaps.find(atom->string());
            if ((nsmap != newSinceMaps.constEnd()) && !nsmap.value().isEmpty()) {
                QList<Section> sections;
                QList<Section>::ConstIterator s;
                for (int i=0; i<LastSinceType; ++i)
                    sections.append(Section(sinceTitle(i),QString(),QString(),QString()));

                NodeMultiMap::const_iterator n = nsmap.value().constBegin();
                while (n != nsmap.value().constEnd()) {
                    const Node* node = n.value();
                    switch (node->type()) {
                      case Node::Fake:
                          if (node->subType() == Node::QmlClass) {
                              sections[QmlClass].appendMember((Node*)node);
                          }
                          break;
                      case Node::Namespace:
                          sections[Namespace].appendMember((Node*)node);
                          break;
                      case Node::Class: 
                          sections[Class].appendMember((Node*)node);
                          break;
                      case Node::Enum: 
                          sections[Enum].appendMember((Node*)node);
                          break;
                      case Node::Typedef: 
                          sections[Typedef].appendMember((Node*)node);
                          break;
                      case Node::Function: {
                          const FunctionNode* fn = static_cast<const FunctionNode*>(node);
                          if (fn->isMacro())
                              sections[Macro].appendMember((Node*)node);
                          else {
                              Node* p = fn->parent();
                              if (p) {
                                  if (p->type() == Node::Class)
                                      sections[MemberFunction].appendMember((Node*)node);
                                  else if (p->type() == Node::Namespace) {
                                      if (p->name().isEmpty())
                                          sections[GlobalFunction].appendMember((Node*)node);
                                      else
                                          sections[NamespaceFunction].appendMember((Node*)node);
                                  }
                                  else
                                      sections[GlobalFunction].appendMember((Node*)node);
                              }
                              else
                                  sections[GlobalFunction].appendMember((Node*)node);
                          }
                          break;
                      }
                      case Node::Property:
                          sections[Property].appendMember((Node*)node);
                          break;
                      case Node::Variable: 
                          sections[Variable].appendMember((Node*)node);
                          break;
                      case Node::QmlProperty:
                          sections[QmlProperty].appendMember((Node*)node);
                          break;
                      case Node::QmlSignal:
                          sections[QmlSignal].appendMember((Node*)node);
                          break;
                      case Node::QmlMethod:
                          sections[QmlMethod].appendMember((Node*)node);
                          break;
                      default:
                          break;
                    }
                    ++n;
                }

                /*
                  First generate the table of contents.
                 */
                xmlWriter().writeStartElement("ul");
                s = sections.constBegin();
                while (s != sections.constEnd()) {
                    if (!(*s).members.isEmpty()) {
                        writeXrefListItem(QString("#" + Doc::canonicalTitle((*s).name)),
                                          (*s).name);
                    }
                    ++s;
                }
                xmlWriter().writeEndElement(); // </ul>

                int idx = 0;
                s = sections.constBegin();
                while (s != sections.constEnd()) {
                    if (!(*s).members.isEmpty()) {
                        xmlWriter().writeStartElement("p");
                        writeGuidAttribute(Doc::canonicalTitle((*s).name));
                        xmlWriter().writeAttribute("outputclass","h3");
                        xmlWriter().writeCharacters(protectEnc((*s).name));
                        xmlWriter().writeEndElement(); // </p>
                        if (idx == Class)
                            generateCompactList(0, marker, ncmap.value(), false, QString("Q"));
                        else if (idx == QmlClass)
                            generateCompactList(0, marker, nqcmap.value(), false, QString("Q"));
                        else if (idx == MemberFunction) {
                            ParentMaps parentmaps;
                            ParentMaps::iterator pmap;
                            NodeList::const_iterator i = s->members.constBegin();
                            while (i != s->members.constEnd()) {
                                Node* p = (*i)->parent();
                                pmap = parentmaps.find(p);
                                if (pmap == parentmaps.end())
                                    pmap = parentmaps.insert(p,NodeMultiMap());
                                pmap->insert((*i)->name(),(*i));
                                ++i;
                            }
                            pmap = parentmaps.begin();
                            while (pmap != parentmaps.end()) {
                                NodeList nlist = pmap->values();
                                xmlWriter().writeStartElement("p");
                                xmlWriter().writeCharacters("Class ");
                                xmlWriter().writeStartElement("xref");
                                xmlWriter().writeAttribute("href",linkForNode(pmap.key(), 0));
                                QStringList pieces = fullName(pmap.key(), 0, marker).split("::");
                                xmlWriter().writeCharacters(protectEnc(pieces.last()));
                                xmlWriter().writeEndElement(); // </xref>
                                xmlWriter().writeCharacters(":");
                                xmlWriter().writeEndElement(); // </p>

                                generateSection(nlist, 0, marker, CodeMarker::Summary);
                                xmlWriter().writeEmptyElement("br");
                                ++pmap;
                            }
                        }
                        else {
                            generateSection(s->members, 0, marker, CodeMarker::Summary);
                        }
                     }
                    ++idx;
                    ++s;
                }
            }
        }
        break;
    case Atom::Image:
    case Atom::InlineImage:
        {
            QString fileName = imageFileName(relative, atom->string());
            QString text;
            if (atom->next() != 0)
                text = atom->next()->string();
            if (fileName.isEmpty()) {
                xmlWriter().writeStartElement("font");
                xmlWriter().writeAttribute("color","red");
                xmlWriter().writeCharacters("[Missing image: ");
                xmlWriter().writeCharacters(protectEnc(atom->string()));
                xmlWriter().writeEndElement(); // </font>
            }
            else {
                xmlWriter().writeStartElement("fig");
                xmlWriter().writeStartElement("image");
                xmlWriter().writeAttribute("href",protectEnc(fileName));
                if (atom->type() == Atom::InlineImage)
                    xmlWriter().writeAttribute("placement","inline");
                else {
                    xmlWriter().writeAttribute("placement","break");
                    xmlWriter().writeAttribute("align","center");
                }
                if (!text.isEmpty()) {
                    xmlWriter().writeStartElement("alt");
                    xmlWriter().writeCharacters(protectEnc(text));
                    xmlWriter().writeEndElement(); // </alt>
                }
                xmlWriter().writeEndElement(); // </image>
                xmlWriter().writeEndElement(); // </fig>
            }
        }
        break;
    case Atom::ImageText:
        // nothing
        break;
    case Atom::LegaleseLeft:
        xmlWriter().writeStartElement("p");
        xmlWriter().writeAttribute("outputclass","legalese");
        break;
    case Atom::LegaleseRight:
        xmlWriter().writeEndElement(); // </p>
        break;
    case Atom::LineBreak:
        xmlWriter().writeEmptyElement("br");
        break;
    case Atom::Link:
        {
            const Node *node = 0;
            QString myLink = getLink(atom, relative, marker, &node);
            if (myLink.isEmpty()) {
                relative->doc().location().warning(tr("Can't link to '%1' in %2")
                        .arg(atom->string())
                        .arg(marker->plainFullName(relative)));
            }
#if 0            
            else
                qDebug() << "MYLINK:" << myLink << outFileName();;
#endif            
            beginLink(myLink, node, relative, marker);
            skipAhead = 1;
        }
        break;
    case Atom::GuidLink:
        {
#if 0            
            qDebug() << "GUID LINK:" << atom->string() << outFileName();
#endif            
            beginLink(atom->string(), 0, relative, marker);
            skipAhead = 1;
        }
        break;
    case Atom::LinkNode:
        {
            const Node* node = CodeMarker::nodeForString(atom->string());
            beginLink(linkForNode(node, relative), node, relative, marker);
            skipAhead = 1;
        }
        break;
    case Atom::ListLeft:
        if (in_para) {
            xmlWriter().writeEndElement(); // </p>
            in_para = false;
        }
        if (atom->string() == ATOM_LIST_BULLET) {
            xmlWriter().writeStartElement("ul");
        }
        else if (atom->string() == ATOM_LIST_TAG) {
            xmlWriter().writeStartElement("dl");
        }
        else if (atom->string() == ATOM_LIST_VALUE) {
            threeColumnEnumValueTable = isThreeColumnEnumValueTable(atom);
            if (threeColumnEnumValueTable) {
                xmlWriter().writeStartElement("simpletable");
                xmlWriter().writeAttribute("outputclass","valuelist");
                xmlWriter().writeStartElement("sthead");
                if (++numTableRows % 2 == 1)
                    xmlWriter().writeAttribute("outputclass","odd");
                else
                    xmlWriter().writeAttribute("outputclass","even");
                xmlWriter().writeStartElement("stentry");
                xmlWriter().writeCharacters("Constant");
                xmlWriter().writeEndElement(); // </stentry>
                xmlWriter().writeStartElement("stentry");
                xmlWriter().writeCharacters("Value");
                xmlWriter().writeEndElement(); // </stentry>
                xmlWriter().writeStartElement("stentry");
                xmlWriter().writeCharacters("Description");
                xmlWriter().writeEndElement(); // </stentry>
                xmlWriter().writeEndElement(); // </sthead>
            }
            else {
                xmlWriter().writeStartElement("simpletable");
                xmlWriter().writeAttribute("outputclass","valuelist");
                xmlWriter().writeStartElement("sthead");
                xmlWriter().writeStartElement("stentry");
                xmlWriter().writeCharacters("Constant");
                xmlWriter().writeEndElement(); // </stentry>
                xmlWriter().writeStartElement("stentry");
                xmlWriter().writeCharacters("Value");
                xmlWriter().writeEndElement(); // </stentry>
                xmlWriter().writeEndElement(); // </stentry>
            }
        }
        else {
            xmlWriter().writeStartElement("ol");
            if (atom->string() == ATOM_LIST_UPPERALPHA)
                xmlWriter().writeAttribute("outputclass","upperalpha");
            else if (atom->string() == ATOM_LIST_LOWERALPHA)
                xmlWriter().writeAttribute("outputclass","loweralpha");
            else if (atom->string() == ATOM_LIST_UPPERROMAN)
                xmlWriter().writeAttribute("outputclass","upperroman");
            else if (atom->string() == ATOM_LIST_LOWERROMAN)
                xmlWriter().writeAttribute("outputclass","lowerroman");
            else // (atom->string() == ATOM_LIST_NUMERIC)
                xmlWriter().writeAttribute("outputclass","numeric");
            if (atom->next() != 0 && atom->next()->string().toInt() != 1) {
                // I don't think this attribute is supported.
                xmlWriter().writeAttribute("start",atom->next()->string());
            }
        }
        break;
    case Atom::ListItemNumber:
        // nothing
        break;
    case Atom::ListTagLeft:
        if (atom->string() == ATOM_LIST_TAG) {
            xmlWriter().writeStartElement("dt");
        }
        else { // (atom->string() == ATOM_LIST_VALUE)
            xmlWriter().writeStartElement("strow");
            xmlWriter().writeStartElement("stentry");
            xmlWriter().writeAttribute("outputclass","topAlign");
            xmlWriter().writeStartElement("tt");
            xmlWriter().writeCharacters(protectEnc(plainCode(marker->markedUpEnumValue(atom->next()->string(),
                                                                                  relative))));
            xmlWriter().writeEndElement(); // </tt>
            xmlWriter().writeEndElement(); // </stentry>
            xmlWriter().writeStartElement("stentry");
            xmlWriter().writeAttribute("outputclass","topAlign");

            QString itemValue;
            if (relative->type() == Node::Enum) {
                const EnumNode *enume = static_cast<const EnumNode *>(relative);
                itemValue = enume->itemValue(atom->next()->string());
            }

            if (itemValue.isEmpty())
                xmlWriter().writeCharacters("?");
            else {
                xmlWriter().writeStartElement("tt");
                xmlWriter().writeCharacters(protectEnc(itemValue));
                xmlWriter().writeEndElement(); // </tt>
            }
            skipAhead = 1;
        }
        break;
    case Atom::ListTagRight:
        if (atom->string() == ATOM_LIST_TAG)
            xmlWriter().writeEndElement(); // </dt>
        break;
    case Atom::ListItemLeft:
        if (atom->string() == ATOM_LIST_TAG) {
            xmlWriter().writeStartElement("dd");
        }
        else if (atom->string() == ATOM_LIST_VALUE) {
            if (threeColumnEnumValueTable) {
                xmlWriter().writeEndElement(); // </stentry>
                xmlWriter().writeStartElement("stentry");
                xmlWriter().writeAttribute("outputclass","topAlign");
                if (matchAhead(atom, Atom::ListItemRight))
                    xmlWriter().writeCharacters("&nbsp;");
            }
        }
        else {
            xmlWriter().writeStartElement("li");
        }
        if (matchAhead(atom, Atom::ParaLeft))
            skipAhead = 1;
        break;
    case Atom::ListItemRight:
        if (atom->string() == ATOM_LIST_TAG) {
            xmlWriter().writeEndElement(); // </dd>
        }
        else if (atom->string() == ATOM_LIST_VALUE) {
            xmlWriter().writeEndElement(); // </stentry>
            xmlWriter().writeEndElement(); // </strow>
        }
        else {
            xmlWriter().writeEndElement(); // </li>
        }
        break;
    case Atom::ListRight:
        if (atom->string() == ATOM_LIST_BULLET) {
            xmlWriter().writeEndElement(); // </ul>
        }
        else if (atom->string() == ATOM_LIST_TAG) {
            xmlWriter().writeEndElement(); // </dl>
        }
        else if (atom->string() == ATOM_LIST_VALUE) {
            xmlWriter().writeEndElement(); // </simpletable>
        }
        else {
            xmlWriter().writeEndElement(); // </ol>
        }
        break;
    case Atom::Nop:
        // nothing
        break;
    case Atom::ParaLeft:
        xmlWriter().writeStartElement("p");
        in_para = true;
        break;
    case Atom::ParaRight:
        endLink();
        if (in_para) {
            xmlWriter().writeEndElement(); // </p>
            in_para = false;
        }
        break;
    case Atom::QuotationLeft:
        xmlWriter().writeStartElement("blockquote");
        break;
    case Atom::QuotationRight:
        xmlWriter().writeEndElement(); // </blockquote>
        break;
    case Atom::RawString:
        xmlWriter().writeCharacters(atom->string());
        break;
    case Atom::SectionLeft:
        if (inSection || inApiDesc) {
            inApiDesc = false;
            xmlWriter().writeEndElement(); // </section> or </apiDesc>
        }
        inSection = true;
        xmlWriter().writeStartElement("section");
        writeGuidAttribute(Doc::canonicalTitle(Text::sectionHeading(atom).toString()));
        xmlWriter().writeAttribute("outputclass","details");
        break;
    case Atom::SectionRight:
        if (inSection) {
            inSection = false;
            xmlWriter().writeEndElement(); // </section>
        }
        break;
    case Atom::SectionHeadingLeft:
        xmlWriter().writeStartElement("title");
        hx = "h" + QString::number(atom->string().toInt() + hOffset(relative));
        xmlWriter().writeAttribute("outputclass",hx);
        inSectionHeading = true;
        break;
    case Atom::SectionHeadingRight:
        xmlWriter().writeEndElement(); // </title> (see case Atom::SectionHeadingLeft)
        inSectionHeading = false;
        break;
    case Atom::SidebarLeft:
        // nothing
        break;
    case Atom::SidebarRight:
        // nothing
        break;
    case Atom::String:
        if (inLink && !inContents && !inSectionHeading) {
            generateLink(atom, relative, marker);
        }
        else {
            xmlWriter().writeCharacters(protectEnc(atom->string()));
        }
        break;
    case Atom::TableLeft:
        {
            if (in_para) {
                xmlWriter().writeEndElement(); // </p>
                in_para = false;
            }
            xmlWriter().writeStartElement("table");
            xmlWriter().writeAttribute("outputclass","generic");
            numTableRows = 0;
            if (tableColumnCount != 0) {
                qDebug() << "ERROR: Nested tables!";
                tableColumnCount = 0;
            }
            tableColumnCount = countTableColumns(atom->next());
            xmlWriter().writeStartElement("tgroup");
            xmlWriter().writeAttribute("cols",QString::number(tableColumnCount));
            inTableHeader = false;
            inTableBody = false;
        }
        break;
    case Atom::TableRight:
        xmlWriter().writeEndElement(); // </tbody>
        xmlWriter().writeEndElement(); // </tgroup>
        xmlWriter().writeEndElement(); // </table>
        inTableHeader = false;
        inTableBody = false;
        tableColumnCount = 0;
        break;
    case Atom::TableHeaderLeft:
        xmlWriter().writeStartElement("thead");
        xmlWriter().writeAttribute("valign","top");
        xmlWriter().writeStartElement("row");
        xmlWriter().writeAttribute("valign","top");
        inTableHeader = true;
        inTableBody = false;
        break;
    case Atom::TableHeaderRight:
        xmlWriter().writeEndElement(); // </row>
        if (matchAhead(atom, Atom::TableHeaderLeft)) {
            skipAhead = 1;
            xmlWriter().writeStartElement("row");
            xmlWriter().writeAttribute("valign","top");
        }
        else { 
            xmlWriter().writeEndElement(); // </thead>
            inTableHeader = false;
            inTableBody = true;
            xmlWriter().writeStartElement("tbody");
        }
        break;
    case Atom::TableRowLeft:
        if (!inTableHeader && !inTableBody) {
            inTableBody = true;
            xmlWriter().writeStartElement("tbody");
        }
        xmlWriter().writeStartElement("row");
        xmlWriter().writeAttribute("valign","top");
        if (++numTableRows % 2 == 1)
            xmlWriter().writeAttribute("outputclass","odd");
        else
            xmlWriter().writeAttribute("outputclass","even");
        break;
    case Atom::TableRowRight:
        xmlWriter().writeEndElement(); // </row>
        break;
    case Atom::TableItemLeft:
        {
            xmlWriter().writeStartElement("entry");
            QStringList spans = atom->string().split(",");
            if (spans.size() == 2) {
                if (inTableHeader ||
                    (spans[0].toInt() != 1) ||
                    (spans[1].toInt() != 1)) {
                    QString s = "span(" + spans[0] + "," + spans[1] + ")";
                    xmlWriter().writeAttribute("outputclass",s);
                }
                if (!inTableHeader)
                    xmlWriter().writeStartElement("p");
            }
            if (matchAhead(atom, Atom::ParaLeft))
                skipAhead = 1;
        }
        break;
    case Atom::TableItemRight:
        if (inTableHeader)
            xmlWriter().writeEndElement(); // </entry>
        else {
            xmlWriter().writeEndElement(); // </p>
            xmlWriter().writeEndElement(); // </entry>
        }
        if (matchAhead(atom, Atom::ParaLeft))
            skipAhead = 1;
        break;
    case Atom::TableOfContents:
        {
            int numColumns = 1;
            const Node* node = relative;

            Doc::SectioningUnit sectioningUnit = Doc::Section4;
            QStringList params = atom->string().split(",");
            QString columnText = params.at(0);
            QStringList pieces = columnText.split(" ", QString::SkipEmptyParts);
            if (pieces.size() >= 2) {
                columnText = pieces.at(0);
                pieces.pop_front();
                QString path = pieces.join(" ").trimmed();
                node = findNodeForTarget(path, relative, marker, atom);
            }

            if (params.size() == 2) {
                numColumns = qMax(columnText.toInt(), numColumns);
                sectioningUnit = (Doc::SectioningUnit)params.at(1).toInt();
            }

            if (node)
                generateTableOfContents(node,
                                        marker,
                                        sectioningUnit,
                                        numColumns,
                                        relative);
        }
        break;
    case Atom::Target:
        xmlWriter().writeStartElement("p");
        writeGuidAttribute(Doc::canonicalTitle(atom->string()));
        xmlWriter().writeAttribute("outputclass","target");
        xmlWriter().writeCharacters(protectEnc(atom->string()));
        xmlWriter().writeEndElement(); // </p>
        break;
    case Atom::UnhandledFormat:
        xmlWriter().writeStartElement("b");
        xmlWriter().writeAttribute("outputclass","redFont");
        xmlWriter().writeCharacters("&lt;Missing DITAXML&gt");
        xmlWriter().writeEndElement(); // </b>
        break;
    case Atom::UnknownCommand:
        xmlWriter().writeStartElement("b");
        xmlWriter().writeAttribute("outputclass","redFont code");
        xmlWriter().writeCharacters(protectEnc(atom->string()));
        xmlWriter().writeEndElement(); // </b>
        break;
    case Atom::QmlText:
    case Atom::EndQmlText:
        // don't do anything with these. They are just tags.
        break;
    default:
        //        unknownAtom(atom);
        break;
    }
    return skipAhead;
}

/*!
  Generate a <cxxClass> element (and all the stuff inside it)
  for the C++ class represented by \a innerNode. \a marker is
  for marking up the code. I don't know what that means exactly.
 */
void
DitaXmlGenerator::generateClassLikeNode(const InnerNode* inner, CodeMarker* marker)
{
    QList<Section>::ConstIterator s;

    const ClassNode* cn = 0;
    const NamespaceNode* namespasse = 0;

    QString title;
    QString rawTitle;
    QString fullTitle;
    if (inner->type() == Node::Namespace) {
        namespasse = const_cast<NamespaceNode*>(static_cast<const NamespaceNode*>(inner));
        rawTitle = marker->plainName(inner);
        fullTitle = marker->plainFullName(inner);
        title = rawTitle + " Namespace";
    }
    else if (inner->type() == Node::Class) {
        cn = const_cast<ClassNode*>(static_cast<const ClassNode*>(inner));
        rawTitle = marker->plainName(inner);
        fullTitle = marker->plainFullName(inner);
        title = rawTitle + " Class Reference";

        generateHeader(inner, fullTitle);
        generateBrief(inner, marker); // <shortdesc>

        // not included: <prolog>
    
        xmlWriter().writeStartElement(CXXCLASSDETAIL);
        xmlWriter().writeStartElement(CXXCLASSDEFINITION);
        xmlWriter().writeStartElement(CXXCLASSACCESSSPECIFIER);
        xmlWriter().writeAttribute("value",inner->accessString());
        xmlWriter().writeEndElement(); // <cxxClassAccessSpecifier>
        if (cn->isAbstract()) {
            xmlWriter().writeStartElement(CXXCLASSABSTRACT);
            xmlWriter().writeAttribute("name","abstract");
            xmlWriter().writeAttribute("value","abstract");
            xmlWriter().writeEndElement(); // </cxxClassAbstract>
        }
        writeDerivations(cn, marker); // <cxxClassDerivations>

        // not included: <cxxClassTemplateParameters>

        writeLocation(cn);
        xmlWriter().writeEndElement(); // <cxxClassDefinition>

        xmlWriter().writeStartElement(APIDESC);
        xmlWriter().writeAttribute("spectitle",title);
        Text brief = cn->doc().briefText();
        if (!brief.isEmpty()) {
            xmlWriter().writeStartElement("p");
            generateText(brief, cn, marker);
            xmlWriter().writeEndElement(); // </p>
        }
        generateIncludes(cn, marker);
        generateStatus(cn, marker);
        generateInherits(cn, marker);
        generateInheritedBy(cn, marker);
        generateThreadSafeness(cn, marker);
        generateSince(cn, marker);
        
        xmlWriter().writeStartElement("ul");
        
        QString membersLink = generateListOfAllMemberFile(inner, marker);
        if (!membersLink.isEmpty()) {
            writeXrefListItem(membersLink,"List of all members, including inherited members");
        }
        
        QString obsoleteLink = generateLowStatusMemberFile(inner,
                                                           marker,
                                                           CodeMarker::Obsolete);
        if (!obsoleteLink.isEmpty()) {
            writeXrefListItem(obsoleteLink,"Obsolete members");
        }

        QString compatLink = generateLowStatusMemberFile(inner,
                                                         marker,
                                                         CodeMarker::Compat);
        if (!compatLink.isEmpty()) {
            writeXrefListItem(compatLink,"Qt 3 support members");
        }

        xmlWriter().writeEndElement(); // </ul>
        xmlWriter().writeEndElement(); // </apiDesc>

        bool needOtherSection = false;
        QList<Section> summarySections;
        summarySections = marker->sections(inner, CodeMarker::Summary, CodeMarker::Okay);
        s = summarySections.begin();
        while (s != summarySections.end()) {
            if (s->members.isEmpty() && s->reimpMembers.isEmpty()) {
                if (!s->inherited.isEmpty())
                    needOtherSection = true;
            }
            else {
                QString attr;
                if (!s->members.isEmpty()) {
                    xmlWriter().writeStartElement("section");
                    attr = cleanRef((*s).name).toLower() + " redundant";
                    xmlWriter().writeAttribute("outputclass",attr);
                    xmlWriter().writeStartElement("title");
                    xmlWriter().writeAttribute("outputclass","h2");
                    xmlWriter().writeCharacters(protectEnc((*s).name));
                    xmlWriter().writeEndElement(); // </title>
                    generateSection(s->members, inner, marker, CodeMarker::Summary);
                    generateSectionInheritedList(*s, inner, marker);
                    xmlWriter().writeEndElement(); // </section>
                }
                if (!s->reimpMembers.isEmpty()) {
                    QString name = QString("Reimplemented ") + (*s).name;
                    attr = cleanRef(name).toLower() + " redundant";
                    xmlWriter().writeStartElement("section");
                    xmlWriter().writeAttribute("outputclass",attr);
                    xmlWriter().writeStartElement("title");
                    xmlWriter().writeAttribute("outputclass","h2");
                    xmlWriter().writeCharacters(protectEnc(name));
                    xmlWriter().writeEndElement(); // </title>
                    generateSection(s->reimpMembers, inner, marker, CodeMarker::Summary);
                    generateSectionInheritedList(*s, inner, marker);
                    xmlWriter().writeEndElement(); // </section>
                }
            }
            ++s;
        }
        if (needOtherSection) {
            xmlWriter().writeStartElement("section");
            xmlWriter().writeAttribute("outputclass","additional-inherited-members redundant");
            xmlWriter().writeStartElement("title");
            xmlWriter().writeAttribute("outputclass","h3");
            xmlWriter().writeCharacters("Additional Inherited Members");
            xmlWriter().writeEndElement(); // </title>
            s = summarySections.begin();
            while (s != summarySections.end()) {
                if (s->members.isEmpty())
                    generateSectionInheritedList(*s, inner, marker);
                ++s;
            }
            xmlWriter().writeEndElement(); // </section>
        }
        
        writeDetailedDescription(cn, marker, false, QString("Detailed Description"));

        // not included: <example> or <apiImpl>

        xmlWriter().writeEndElement(); // </cxxClassDetail>

        // not included: <related-links>
        // not included: <cxxClassNested>

        QList<Section> detailSections;
        detailSections = marker->sections(inner, CodeMarker::Detailed, CodeMarker::Okay);
        s = detailSections.begin();
        while (s != detailSections.end()) {
            if ((*s).name == "Member Function Documentation") {
                writeFunctions((*s),cn,marker);
            }
            else if ((*s).name == "Member Type Documentation") {
                writeEnumerations((*s),marker);
                writeTypedefs((*s),marker);
            }
            else if ((*s).name == "Member Variable Documentation") {
                writeDataMembers((*s),marker);
            }
            else if ((*s).name == "Property Documentation") {
                writeProperties((*s),marker);
            }
            else if ((*s).name == "Macro Documentation") {
                writeMacros((*s),marker);
            }
            ++s;
        }

        // not included: <cxxClassInherits>

        xmlWriter().writeEndElement(); // </cxxClass>
    }
}

/*!
  Write a paragraph for the \a target and a poaragraph for
  the \a header. Use the \a attribute for the \a header.
 */
void DitaXmlGenerator::writeTargetAndHeader(const QString& target,
                                            const QString& header,
                                            const QString& attribute)
{
    xmlWriter().writeStartElement("p");
    writeGuidAttribute(registerRef(target));
    xmlWriter().writeAttribute("outputclass","target");
    xmlWriter().writeCharacters(header);
    xmlWriter().writeEndElement(); // </p>
    xmlWriter().writeStartElement("p");
    xmlWriter().writeAttribute("outputclass",attribute);
    xmlWriter().writeCharacters(header);
    xmlWriter().writeEndElement(); // </p>
}

/*!
  Write a list item for a \a link with the given \a text.
 */
void DitaXmlGenerator::writeXrefListItem(const QString& link, const QString& text)
{
    xmlWriter().writeStartElement("li");
    xmlWriter().writeStartElement("xref");
    xmlWriter().writeAttribute("href",link);
    xmlWriter().writeCharacters(text);
    xmlWriter().writeEndElement(); // </xref>
    xmlWriter().writeEndElement(); // </li>
}

/*!
  Generate the html page for a qdoc file that doesn't map
  to an underlying c++ file.
 */
void DitaXmlGenerator::generateFakeNode(const FakeNode *fake, CodeMarker *marker)
{
    SubTitleSize subTitleSize = LargeSubTitle;
    QList<Section> sections;
    QList<Section>::const_iterator s;
    QString fullTitle = fake->fullTitle();
    QString htmlTitle = fullTitle;

    if (fake->subType() == Node::File && !fake->subTitle().isEmpty()) {
        subTitleSize = SmallSubTitle;
        htmlTitle += " (" + fake->subTitle() + ")";
    }
    else if (fake->subType() == Node::QmlBasicType) {
        fullTitle = "QML Basic Type: " + fullTitle;
        htmlTitle = fullTitle;
    }

    generateHeader(fake, fullTitle);
    
    generateBrief(fake, marker); // <shortdesc>
    if (fake->subType() == Node::Module) {
        generateStatus(fake, marker);
        if (moduleNamespaceMap.contains(fake->name())) {
            writeTargetAndHeader("namespaces","Namespaces","h2");
            generateAnnotatedList(fake, marker, moduleNamespaceMap[fake->name()]);
        }
        if (moduleClassMap.contains(fake->name())) {
            writeTargetAndHeader("classes","Classes","h2");
            generateAnnotatedList(fake, marker, moduleClassMap[fake->name()]);
        }
    }
    else if (fake->subType() == Node::HeaderFile) {
        generateStatus(fake, marker);
        xmlWriter().writeStartElement("ul");

        QString membersLink = generateListOfAllMemberFile(fake, marker);
        if (!membersLink.isEmpty()) {
            writeXrefListItem(membersLink,"List of all members, including inherited members");
        }

        QString obsoleteLink = generateLowStatusMemberFile(fake,
                                                           marker,
                                                           CodeMarker::Obsolete);
        if (!obsoleteLink.isEmpty()) {
            writeXrefListItem(obsoleteLink,"Obsolete members");
        }

        QString compatLink = generateLowStatusMemberFile(fake,
                                                         marker,
                                                         CodeMarker::Compat);
        if (!compatLink.isEmpty()) {
            writeXrefListItem(compatLink,"Qt 3 support members");
        }

        xmlWriter().writeEndElement(); // </ul>
    }
    else if (fake->subType() == Node::QmlClass) {
        const QmlClassNode* qml_cn = static_cast<const QmlClassNode*>(fake);
        const ClassNode* cn = qml_cn->classNode();
        generateQmlInherits(qml_cn, marker);
        generateQmlInstantiates(qml_cn, marker);
        generateBrief(qml_cn, marker);
        generateQmlInheritedBy(qml_cn, marker);
        sections = marker->qmlSections(qml_cn,CodeMarker::Summary,0);
        s = sections.begin();
        while (s != sections.end()) {
            xmlWriter().writeStartElement("section");
            QString attr = cleanRef((*s).name).toLower();
            xmlWriter().writeAttribute("outputclass",attr);
            xmlWriter().writeStartElement("title");
            xmlWriter().writeAttribute("outputclass","h2");
            xmlWriter().writeCharacters(protectEnc((*s).name));
            xmlWriter().writeEndElement(); // </title>
            generateQmlSummary(*s,fake,marker);
            xmlWriter().writeEndElement(); // </section>
            ++s;
        }
        
        writeDetailedDescription(fake, marker, false, QString("Detailed Description"));

        if (cn)
            generateQmlText(cn->doc().body(), cn, marker, fake->name());

        generateAlsoList(fake, marker);
        //out() << "<hr />\n";

        sections = marker->qmlSections(qml_cn,CodeMarker::Detailed,0);
        s = sections.begin();
        while (s != sections.end()) {
            if (!s->members.isEmpty()) {
                QString attr;
                xmlWriter().writeStartElement("section");
                attr = cleanRef((*s).name).toLower();
                xmlWriter().writeAttribute("outputclass",attr);
                xmlWriter().writeStartElement("title");
                xmlWriter().writeAttribute("outputclass","h2");
                xmlWriter().writeCharacters(protectEnc((*s).name));
                xmlWriter().writeEndElement(); // </title>
                NodeList::ConstIterator m = (*s).members.begin();
                while (m != (*s).members.end()) {
                    generateDetailedQmlMember(*m, fake, marker);
                    ++m;
                }
                xmlWriter().writeEndElement(); // </section>
            }
            ++s;
        }
        return;
    }

    if (!fake->doc().isEmpty()) {
        xmlWriter().writeStartElement("body");
        if (fake->subType() == Node::Module) {
            writeDetailedDescription(fake, marker, false, QString("Detailed Description"));
        }
        else
            writeDetailedDescription(fake, marker, false, QString());
        generateAlsoList(fake, marker);

        if (!fake->groupMembers().isEmpty()) {
            NodeMap groupMembersMap;
            foreach (const Node *node, fake->groupMembers()) {
                if (node->type() == Node::Class || node->type() == Node::Namespace)
                    groupMembersMap[node->name()] = node;
            }
            generateAnnotatedList(fake, marker, groupMembersMap);
        }

        xmlWriter().writeEndElement(); // </body>
    }
    xmlWriter().writeEndElement(); // </topic>
}

#if 0
zzz
    /*
      Generate the TOC for the new doc format.
      Don't generate a TOC for the home page.
    */
    if (fake->name() != QString("index.html"))
        generateTableOfContents(fake,marker,0);

    generateTitle(fullTitle,
                  Text() << fake->subTitle(),
                  subTitleSize,
                  fake,
                  marker);
    

#endif

#if 0
zzz
    sections = marker->sections(fake, CodeMarker::Summary, CodeMarker::Okay);
    s = sections.begin();
    while (s != sections.end()) {
        out() << "<a name=\"" << registerRef((*s).name) << "\"></a>\n";
        out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";
        generateSection(s->members, fake, marker, CodeMarker::Summary);
        generateSectionInheritedList(*s, relative, marker, name_alignment);
        ++s;
    }

    Text brief = fake->doc().briefText();
    if (fake->subType() == Node::Module && !brief.isEmpty()) {
        out() << "<a name=\"" << registerRef("details") << "\"></a>\n";
        out() << "<div class=\"descr\"/>\n"; // QTBUG-9504
        out() << "<h2>" << "Detailed Description" << "</h2>\n";
    }
    else
        out() << "<div class=\"descr\"/>\n"; // QTBUG-9504

    sections = marker->sections(fake, CodeMarker::Detailed, CodeMarker::Okay);
    s = sections.begin();
    while (s != sections.end()) {
        out() << "<hr />\n";
        out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";

        NodeList::ConstIterator m = (*s).members.begin();
        while (m != (*s).members.end()) {
            generateDetailedMember(*m, fake, marker);
            ++m;
        }
        ++s;
    }
#endif

/*!
  Returns "xml" for this subclass of class Generator.
 */
QString DitaXmlGenerator::fileExtension(const Node * /* node */) const
{
    return "xml";
}

/*!
  zzz
  Output breadcrumb list in the html file.
 */
void DitaXmlGenerator::generateBreadCrumbs(const QString& title,
                                           const Node *node,
                                           CodeMarker *marker)
{
    Text breadcrumb;
    if (node->type() == Node::Class) {
        const ClassNode* cn = static_cast<const ClassNode*>(node);
        QString name =  node->moduleName();
        out() << "              <li><xref href=\"modules.html\">All Modules</xref></li>";
        if (!name.isEmpty()) {
            out() << "              <li>";
            breadcrumb << Atom(Atom::AutoLink,name);
            generateText(breadcrumb, node, marker);
            out() << "</li>\n";
        }
        breadcrumb.clear();
        if (!cn->name().isEmpty()) {
            out() << "              <li>";
            breadcrumb << Atom(Atom::AutoLink,cn->name());
            generateText(breadcrumb, 0, marker);
            out() << "</li>\n";
        }
    }
    else if (node->type() == Node::Fake) {
        const FakeNode* fn = static_cast<const FakeNode*>(node);
        if (node->subType() == Node::Module) {
            out() << "              <li><xref href=\"modules.html\">All Modules</xref></li>";
            QString name =  node->name();
            if (!name.isEmpty()) {
                out() << "              <li>";
                breadcrumb << Atom(Atom::AutoLink,name);
                generateText(breadcrumb, 0, marker);
                out() << "</li>\n";
            }
        }
        else if (node->subType() == Node::Group) {
            if (fn->name() == QString("modules"))
                out() << "              <li><xref href=\"modules.html\">All Modules</xref></li>";
            else {
                out() << "              <li><xref href=\"" << fn->name() << "\">" << title
                      << "</xref></li>";
            }
        }
        else if (node->subType() == Node::Page) {
            if (fn->name() == QString("examples.html")) {
                out() << "              <li><xref href=\"all-examples.html\">Examples</xref></li>";
            }
            else if (fn->name().startsWith("examples-")) {
                out() << "              <li><xref href=\"all-examples.html\">Examples</xref></li>";
                out() << "              <li><xref href=\"" << fn->name() << "\">" << title
                      << "</xref></li>";
            }
            else if (fn->name() == QString("namespaces.html")) {
                out() << "              <li><xref href=\"namespaces.html\">All Namespaces</xref></li>";
            }
            else {
                out() << "              <li><xref href=\"" << fn->name() << "\">" << title
                      << "</xref></li>";
            }
        }
        else if (node->subType() == Node::QmlClass) {
            out() << "              <li><xref href=\"qdeclarativeelements.html\">QML Elements</xref></li>";
            out() << "              <li><xref href=\"" << fn->name() << "\">" << title
                  << "</xref></li>";
        }
        else if (node->subType() == Node::Example) {
            out() << "              <li><xref href=\"all-examples.html\">Examples</xref></li>";
            QStringList sl = fn->name().split('/');
            QString name = "examples-" + sl.at(0) + ".html";
            QString t = CodeParser::titleFromName(name);
            out() << "              <li><xref href=\"" << name << "\">"
                  << t << "</xref></li>";
            out() << "              <li><xref href=\"" << sl.at(0)
                  << "-" << sl.at(sl.size()-1) << ".html\">"
                  << title << "</xref></li>";
        }
    }
    else if (node->type() == Node::Namespace) {
        const NamespaceNode* nsn = static_cast<const NamespaceNode*>(node);
        out() << "              <li><xref href=\"namespaces.html\">All Namespaces</xref></li>";
        out() << "              <li><xref href=\"" << fileName(nsn) << "\">" << title
              << "</xref></li>";
    }
}

/*!
  Writes an XML file header to the current XML stream. This
  depends on which kind of DITA XML file is being generated,
  which is determined by the \a node type and subtype and the
  \a subpage flag. If the \subpage flag is true, a \c{<topic>}
  header is written, regardless of the type of \a node.
 */
void DitaXmlGenerator::generateHeader(const Node* node,
                                      const QString& name,
                                      bool subpage)
{
    if (!node)
        return;

    QString doctype;
    QString mainElement;
    QString nameElement;
    QString dtd;
    QString base;
    QString version;
    QString outputclass;

    if (node->type() == Node::Fake || subpage) {
        mainElement = "topic";
        nameElement = "title";
        dtd = "dtd/topic.dtd";
        doctype = "<!DOCTYPE " + mainElement +
            " PUBLIC \"-//OASIS//DTD DITA Topic//EN\" \"" + dtd + "\">";
        switch (node->subType()) {
        case Node::Page:
            outputclass = "page";
            break;
        case Node::Group:
            outputclass = "group";
            break;
        case Node::Example:
            outputclass = "example";
            break;
        case Node::HeaderFile:
            outputclass = "headerfile";
            break;
        case Node::File:
            outputclass = "file";
            break;
        case Node::Image:
            outputclass = "image";
            break;
        case Node::Module:
            outputclass = "module";
            break;
        case Node::ExternalPage:
            outputclass = "externalpage";
            break;
        case Node::QmlClass:
            outputclass = "QML-class";
            break;
        default:
            outputclass = "page";
        }
    }
    else if (node->type() == Node::Class) {
        mainElement = "cxxClass";
        nameElement = "apiName";
        dtd = "dtd/cxxClass.dtd";
        version = "0.6.0";
        doctype = "<!DOCTYPE " + mainElement +
            " PUBLIC \"-//NOKIA//DTD DITA C++ API Class Reference Type v" +
            version + "//EN\" \"" + dtd + "\">";
    }

    xmlWriter().writeDTD(doctype);
    xmlWriter().writeComment(node->doc().location().fileName());
    xmlWriter().writeStartElement(mainElement);
    xmlWriter().writeAttribute("id",node->guid());
    if (!outputclass.isEmpty())
        xmlWriter().writeAttribute("outputclass",outputclass);
    xmlWriter().writeStartElement(nameElement);
    xmlWriter().writeCharacters(name);
    xmlWriter().writeEndElement(); // <nameElement>
}

/*!
  Writes a \a title as a <p> element with an \c {outputclass}
  attribute of "h1 title".

  Also generates and writes a \a subTitle as a <p> element,
  if one is provided, but this probably doesn't work right.
 */
void DitaXmlGenerator::generateTitle(const QString& title,
                                     const Text& subTitle,
                                     SubTitleSize subTitleSize,
                                     const Node* relative,
                                     CodeMarker* marker)
{
    if (!title.isEmpty()) {
        xmlWriter().writeStartElement("p");
        xmlWriter().writeAttribute("outputclass", "h1 title");
        xmlWriter().writeCharacters(protectEnc(title));
        xmlWriter().writeEndElement(); // </p>
    }
    if (!subTitle.isEmpty()) {
        xmlWriter().writeStartElement("p");
        if (subTitleSize == SmallSubTitle) {
            xmlWriter().writeAttribute("outputclass", "small-subtitle");
        }
        else {
            xmlWriter().writeAttribute("outputclass", "subtitle");
        }
        generateText(subTitle, relative, marker);
        xmlWriter().writeEndElement(); // </p>
    }
}

/*!
  Outputs the \e brief command as a <shortdesc> element.
 */
void DitaXmlGenerator::generateBrief(const Node* node, CodeMarker* marker)
{
    Text brief = node->doc().briefText();
    if (!brief.isEmpty()) {
        noLinks = true;
        xmlWriter().writeStartElement(SHORTDESC);
        generateText(brief, node, marker);
        xmlWriter().writeEndElement(); // </shortdesc>
        noLinks = false;
    }
}

/*!
  Writes the \c {#include ...} required to include the class
  or namespace in a compilation.
 */
void DitaXmlGenerator::generateIncludes(const InnerNode* inner, CodeMarker* marker)
{
    if (!inner->includes().isEmpty()) {
        xmlWriter().writeStartElement("pre");
        xmlWriter().writeAttribute("outputclass","highlightedcode");
        writeText(marker->markedUpIncludes(inner->includes()), marker, inner);
        xmlWriter().writeEndElement(); // </pre>
    }
}

/*!
  zzz
  Generates a table of contents begining at \a node.
  Currently just returns without writing anything.
 */
void DitaXmlGenerator::generateTableOfContents(const Node* node,
                                               CodeMarker* marker,
                                               Doc::SectioningUnit sectioningUnit,
                                               int numColumns,
                                               const Node* relative)

{
    return;
    if (!node->doc().hasTableOfContents())
        return;
    QList<Atom *> toc = node->doc().tableOfContents();
    if (toc.isEmpty())
        return;

    QString nodeName = "";
    if (node != relative)
        nodeName = node->name();

    QStringList sectionNumber;
    int columnSize = 0;

    QString tdTag;
    if (numColumns > 1) {
        tdTag = "<td>"; /* width=\"" + QString::number((100 + numColumns - 1) / numColumns) + "%\">";*/
        out() << "<table class=\"toc\">\n<tr class=\"topAlign\">"
              << tdTag << "\n";
    }

    // disable nested links in table of contents
    inContents = true;
    inLink = true;

    for (int i = 0; i < toc.size(); ++i) {
        Atom *atom = toc.at(i);

        int nextLevel = atom->string().toInt();
        if (nextLevel > (int)sectioningUnit)
            continue;

        if (sectionNumber.size() < nextLevel) {
            do {
                out() << "<ul>";
                sectionNumber.append("1");
            } while (sectionNumber.size() < nextLevel);
        }
        else {
            while (sectionNumber.size() > nextLevel) {
                out() << "</ul>\n";
                sectionNumber.removeLast();
            }
            sectionNumber.last() = QString::number(sectionNumber.last().toInt() + 1);
        }
        int numAtoms;
        Text headingText = Text::sectionHeading(atom);

        if (sectionNumber.size() == 1 && columnSize > toc.size() / numColumns) {
            out() << "</ul></td>" << tdTag << "<ul>\n";
            columnSize = 0;
        }
        out() << "<li>";
        out() << "<xref href=\""
              << nodeName
              << "#"
              << Doc::canonicalTitle(headingText.toString())
              << "\">";
        generateAtomList(headingText.firstAtom(), node, marker, true, numAtoms);
        out() << "</xref></li>\n";

        ++columnSize;
    }
    while (!sectionNumber.isEmpty()) {
        out() << "</ul>\n";
        sectionNumber.removeLast();
    }

    if (numColumns > 1)
        out() << "</td></tr></table>\n";

    inContents = false;
    inLink = false;
}

/*!
  zzz
  Revised for the new doc format.
  Generates a table of contents begining at \a node.
 */
void DitaXmlGenerator::generateTableOfContents(const Node* node,
                                               CodeMarker* marker,
                                               QList<Section>* sections)
{
    QList<Atom*> toc;
    if (node->doc().hasTableOfContents()) 
        toc = node->doc().tableOfContents();
    if (toc.isEmpty() && !sections && (node->subType() != Node::Module))
        return;

    QStringList sectionNumber;
    int detailsBase = 0;

    // disable nested links in table of contents
    inContents = true;
    inLink = true;

    out() << "<div class=\"toc\">\n";
    out() << "<h3>Contents</h3>\n";
    sectionNumber.append("1");
    out() << "<ul>\n";

    if (node->subType() == Node::Module) {
        if (moduleNamespaceMap.contains(node->name())) {
            out() << "<li class=\"level"
                  << sectionNumber.size()
                  << "\"><xref href=\"#"
                  << registerRef("namespaces")
                  << "\">Namespaces</xref></li>\n";
        }
        if (moduleClassMap.contains(node->name())) {
            out() << "<li class=\"level"
                  << sectionNumber.size()
                  << "\"><xref href=\"#"
                  << registerRef("classes")
                  << "\">Classes</xref></li>\n";
        }
        out() << "<li class=\"level"
              << sectionNumber.size()
              << "\"><xref href=\"#"
              << registerRef("details")
              << "\">Detailed Description</xref></li>\n";
        for (int i = 0; i < toc.size(); ++i) {
            if (toc.at(i)->string().toInt() == 1) {
                detailsBase = 1;
                break;
            }
        }
    }
    else if (sections && (node->type() == Node::Class)) {
        QList<Section>::ConstIterator s = sections->begin();
        while (s != sections->end()) {
            if (!s->members.isEmpty() || !s->reimpMembers.isEmpty()) {
                out() << "<li class=\"level"
                      << sectionNumber.size()
                      << "\"><xref href=\"#"
                      << registerRef((*s).pluralMember)
                      << "\">" << (*s).name
                      << "</xref></li>\n";
            }
            ++s;
        }
        out() << "<li class=\"level"
              << sectionNumber.size()
              << "\"><xref href=\"#"
              << registerRef("details")
              << "\">Detailed Description</xref></li>\n";
        for (int i = 0; i < toc.size(); ++i) {
            if (toc.at(i)->string().toInt() == 1) {
                detailsBase = 1;
                break;
            }
        }
    }

    for (int i = 0; i < toc.size(); ++i) {
        Atom *atom = toc.at(i);
        int nextLevel = atom->string().toInt() + detailsBase;
        if (sectionNumber.size() < nextLevel) {
            do {
                sectionNumber.append("1");
            } while (sectionNumber.size() < nextLevel);
        }
        else {
            while (sectionNumber.size() > nextLevel) {
                sectionNumber.removeLast();
            }
            sectionNumber.last() = QString::number(sectionNumber.last().toInt() + 1);
        }
        int numAtoms;
        Text headingText = Text::sectionHeading(atom);
        QString s = headingText.toString();
        out() << "<li class=\"level"
              << sectionNumber.size()
              << "\">";
        out() << "<xref href=\""
              << "#"
              << Doc::canonicalTitle(s)
              << "\">";
        generateAtomList(headingText.firstAtom(), node, marker, true, numAtoms);
        out() << "</xref></li>\n";
    }
    while (!sectionNumber.isEmpty()) {
        sectionNumber.removeLast();
    }
    out() << "</ul>\n";
    out() << "</div>\n";
    inContents = false;
    inLink = false;
}

QString DitaXmlGenerator::generateListOfAllMemberFile(const InnerNode* inner,
                                                      CodeMarker* marker)
{
    QList<Section> sections;
    QList<Section>::ConstIterator s;

    sections = marker->sections(inner,
                                CodeMarker::SeparateList,
                                CodeMarker::Okay);
    if (sections.isEmpty())
        return QString();

    QString fileName = fileBase(inner) + "-members." + fileExtension(inner);
    beginSubPage(inner->location(), fileName);
    QString title = "List of All Members for " + inner->name();
    generateHeader(inner, title, true);
    xmlWriter().writeStartElement("body");
    xmlWriter().writeStartElement("section");
    if (!title.isEmpty()) {
        xmlWriter().writeStartElement("title");
        xmlWriter().writeAttribute("outputclass", "h1");
        xmlWriter().writeCharacters(protectEnc(title));
        xmlWriter().writeEndElement(); // </title>
    }
    xmlWriter().writeStartElement("p");
    xmlWriter().writeCharacters("This is the complete list of members for ");
    generateFullName(inner, 0, marker);
    xmlWriter().writeCharacters(", including inherited members.");
    xmlWriter().writeEndElement(); // </p>

    Section section = sections.first();
    generateSection(section.members, 0, marker, CodeMarker::SeparateList);
    xmlWriter().writeEndElement(); // </section>
    xmlWriter().writeEndElement(); // </body>
    endSubPage();
    return fileName;
}

QString DitaXmlGenerator::generateLowStatusMemberFile(const InnerNode* inner,
                                                      CodeMarker* marker,
                                                      CodeMarker::Status status)
{
    QList<Section> sections = marker->sections(inner,CodeMarker::Summary,status);
    QMutableListIterator<Section> j(sections);
    while (j.hasNext()) {
        if (j.next().members.size() == 0)
            j.remove();
    }
    if (sections.isEmpty())
        return QString();

    int i;
    QString title;
    QString fileName;

    if (status == CodeMarker::Compat) {
        title = "Qt 3 Support Members for " + inner->name();
        fileName = fileBase(inner) + "-qt3." + fileExtension(inner);
    }
    else {
        title = "Obsolete Members for " + inner->name();
        fileName = fileBase(inner) + "-obsolete." + fileExtension(inner);
    }
    beginSubPage(inner->location(), fileName);
    generateHeader(inner, title, true);
    xmlWriter().writeStartElement("body");
    xmlWriter().writeStartElement("section");
    if (!title.isEmpty()) {
        xmlWriter().writeStartElement("title");
        xmlWriter().writeAttribute("outputclass", "h1");
        xmlWriter().writeCharacters(protectEnc(title));
        xmlWriter().writeEndElement(); // </title>
    }

    xmlWriter().writeStartElement("p");
    if (status == CodeMarker::Compat) {
        xmlWriter().writeStartElement("b");
        xmlWriter().writeCharacters("The following class members are part of the ");
        xmlWriter().writeStartElement("xref");
        xmlWriter().writeAttribute("href","qt3support.html");
        xmlWriter().writeCharacters("Qt 3 support layer");
        xmlWriter().writeEndElement(); // </xref>
        xmlWriter().writeCharacters(". ");
        xmlWriter().writeEndElement(); // </b>
        xmlWriter().writeCharacters("They are provided to help you port old code to Qt 4. "
                                    "We advise against using them in new code.");
    }
    else {
        xmlWriter().writeStartElement("b");
        xmlWriter().writeCharacters("The following class members are obsolete. ");
        xmlWriter().writeEndElement(); // </b>
        xmlWriter().writeCharacters("They are provided to keep old source code working. "
                                    "We strongly advise against using them in new code.");
    }
    xmlWriter().writeEndElement(); // </p>
    xmlWriter().writeStartElement("p");
    xmlWriter().writeStartElement("ul");
    QString text = protectEnc(inner->name()) + " class reference";
    writeXrefListItem(linkForNode(inner,0),text);
    xmlWriter().writeEndElement(); // </ul>
    xmlWriter().writeEndElement(); // </p>
    xmlWriter().writeEndElement(); // </section>
    
    for (i = 0; i < sections.size(); ++i) {
        xmlWriter().writeStartElement("section");
        xmlWriter().writeStartElement("title");
        xmlWriter().writeAttribute("outputclass","h2");
        xmlWriter().writeCharacters(protectEnc(sections.at(i).name));
        xmlWriter().writeEndElement(); // </title>
        generateSection(sections.at(i).members, inner, marker, CodeMarker::Summary);
        generateSectionInheritedList(sections.at(i), inner, marker);
        xmlWriter().writeEndElement(); // </section>
    }

    sections = marker->sections(inner, CodeMarker::Detailed, status);
    for (i = 0; i < sections.size(); ++i) {
        xmlWriter().writeStartElement("section");
        xmlWriter().writeStartElement("title");
        xmlWriter().writeAttribute("outputclass","h2");
        xmlWriter().writeCharacters(protectEnc(sections.at(i).name));
        xmlWriter().writeEndElement(); // </title>

        NodeList::ConstIterator m = sections.at(i).members.begin();
        while (m != sections.at(i).members.end()) {
            if ((*m)->access() != Node::Private) {
                generateDetailedMember(*m, inner, marker);
            }
            ++m;
        }
        xmlWriter().writeEndElement(); // </section>
    }
    xmlWriter().writeEndElement(); // </body>
    xmlWriter().writeEndElement(); // </topic>
    endSubPage();
    return fileName;
}

/*!
  Write the XML for the class hierarchy to the current XML stream.
 */
void DitaXmlGenerator::generateClassHierarchy(const Node* relative,
                                              CodeMarker* marker,
                                              const QMap<QString,const Node*>& classMap)
{
    if (classMap.isEmpty())
        return;

    NodeMap topLevel;
    NodeMap::ConstIterator c = classMap.begin();
    while (c != classMap.end()) {
        const ClassNode* classe = static_cast<const ClassNode*>(*c);
        if (classe->baseClasses().isEmpty())
            topLevel.insert(classe->name(), classe);
        ++c;
    }

    QStack<NodeMap > stack;
    stack.push(topLevel);

    xmlWriter().writeStartElement("ul");
    while (!stack.isEmpty()) {
        if (stack.top().isEmpty()) {
            stack.pop();
            xmlWriter().writeEndElement(); // </ul>
        }
        else {
            const ClassNode *child =
                static_cast<const ClassNode *>(*stack.top().begin());
            xmlWriter().writeStartElement("li");
            generateFullName(child, relative, marker);
            xmlWriter().writeEndElement(); // </li>
            stack.top().erase(stack.top().begin());

            NodeMap newTop;
            foreach (const RelatedClass &d, child->derivedClasses()) {
                if (d.access != Node::Private)
                    newTop.insert(d.node->name(), d.node);
            }
            if (!newTop.isEmpty()) {
                stack.push(newTop);
                xmlWriter().writeStartElement("ul");
            }
        }
    }
}

/*!
  Write XML for the contents of the \a nodeMap to the current
  XML stream. 
 */
void DitaXmlGenerator::generateAnnotatedList(const Node* relative,
                                             CodeMarker* marker,
                                             const NodeMap& nodeMap)
{
    xmlWriter().writeStartElement("table");
    xmlWriter().writeAttribute("outputclass","annotated");
    xmlWriter().writeStartElement("tgroup");
    xmlWriter().writeAttribute("cols","2");
    xmlWriter().writeStartElement("tbody");

    int row = 0;
    foreach (const QString& name, nodeMap.keys()) {
        const Node* node = nodeMap[name];

        if (node->status() == Node::Obsolete)
            continue;

        xmlWriter().writeStartElement("row");
        if (++row % 2 == 1)
            xmlWriter().writeAttribute("outputclass","odd topAlign");
        else
            xmlWriter().writeAttribute("outputclass","even topAlign");
        xmlWriter().writeStartElement("entry");
        xmlWriter().writeStartElement("p");
        generateFullName(node, relative, marker);
        xmlWriter().writeEndElement(); // </p>
        xmlWriter().writeEndElement(); // <entry>

        if (!(node->type() == Node::Fake)) {
            Text brief = node->doc().trimmedBriefText(name);
            if (!brief.isEmpty()) {
                xmlWriter().writeStartElement("entry");
                xmlWriter().writeStartElement("p");
                generateText(brief, node, marker);
                xmlWriter().writeEndElement(); // </p>
                xmlWriter().writeEndElement(); // <entry>
            }
        }
        else {
            xmlWriter().writeStartElement("entry");
            xmlWriter().writeStartElement("p");
            xmlWriter().writeCharacters(protectEnc(node->doc().briefText().toString()));
            xmlWriter().writeEndElement(); // </p>
            xmlWriter().writeEndElement(); // <entry>
        }
        xmlWriter().writeEndElement(); // </row>
    }
    xmlWriter().writeEndElement(); // </tbody>
    xmlWriter().writeEndElement(); // </tgroup>
    xmlWriter().writeEndElement(); // </table>
}

/*!
  This function finds the common prefix of the names of all
  the classes in \a classMap and then generates a compact
  list of the class names alphabetized on the part of the
  name not including the common prefix. You can tell the
  function to use \a comonPrefix as the common prefix, but
  normally you let it figure it out itself by looking at
  the name of the first and last classes in \a classMap.
 */
void DitaXmlGenerator::generateCompactList(const Node* relative,
                                           CodeMarker* marker,
                                           const NodeMap& classMap,
                                           bool includeAlphabet,
                                           QString commonPrefix)
{
    const int NumParagraphs = 37; // '0' to '9', 'A' to 'Z', '_'

    if (classMap.isEmpty())
        return;

    /*
      If commonPrefix is not empty, then the caller knows what
      the common prefix is and has passed it in, so just use that
      one.
     */
    int commonPrefixLen = commonPrefix.length();
    if (commonPrefixLen == 0) {
        QString first;
        QString last;
        
        /*
          The caller didn't pass in a common prefix, so get the common
          prefix by looking at the class names of the first and last
          classes in the class map. Discard any namespace names and
          just use the bare class names. For Qt, the prefix is "Q".

          Note that the algorithm used here to derive the common prefix
          from the first and last classes in alphabetical order (QAccel
          and QXtWidget in Qt 2.1), fails if either class name does not
          begin with Q.
        */

        NodeMap::const_iterator iter = classMap.begin();
        while (iter != classMap.end()) {
            if (!iter.key().contains("::")) {
                first = iter.key();
                break;
            }
            ++iter;
        }

        if (first.isEmpty())
            first = classMap.begin().key();

        iter = classMap.end();
        while (iter != classMap.begin()) {
            --iter;
            if (!iter.key().contains("::")) {
                last = iter.key();
                break;
            }
        }

        if (last.isEmpty())
            last = classMap.begin().key();

        if (classMap.size() > 1) {
            while (commonPrefixLen < first.length() + 1 &&
                   commonPrefixLen < last.length() + 1 &&
                   first[commonPrefixLen] == last[commonPrefixLen])
                ++commonPrefixLen;
        }

        commonPrefix = first.left(commonPrefixLen);
    }

    /*
      Divide the data into 37 paragraphs: 0, ..., 9, A, ..., Z,
      underscore (_). QAccel will fall in paragraph 10 (A) and
      QXtWidget in paragraph 33 (X). This is the only place where we
      assume that NumParagraphs is 37. Each paragraph is a NodeMap.
    */
    NodeMap paragraph[NumParagraphs+1];
    QString paragraphName[NumParagraphs+1];
    QSet<char> usedParagraphNames;

    NodeMap::ConstIterator c = classMap.begin();
    while (c != classMap.end()) {
        QStringList pieces = c.key().split("::");
        QString key;
        int idx = commonPrefixLen;
        if (!pieces.last().startsWith(commonPrefix))
            idx = 0;
        if (pieces.size() == 1)
            key = pieces.last().mid(idx).toLower();
        else
            key = pieces.last().toLower();

        int paragraphNr = NumParagraphs - 1;

        if (key[0].digitValue() != -1) {
            paragraphNr = key[0].digitValue();
        }
        else if (key[0] >= QLatin1Char('a') && key[0] <= QLatin1Char('z')) {
            paragraphNr = 10 + key[0].unicode() - 'a';
        }

        paragraphName[paragraphNr] = key[0].toUpper();
        usedParagraphNames.insert(key[0].toLower().cell());
        paragraph[paragraphNr].insert(key, c.value());
        ++c;
    }

    /*
      Each paragraph j has a size: paragraph[j].count(). In the
      discussion, we will assume paragraphs 0 to 5 will have sizes
      3, 1, 4, 1, 5, 9.

      We now want to compute the paragraph offset. Paragraphs 0 to 6
      start at offsets 0, 3, 4, 8, 9, 14, 23.
    */
    int paragraphOffset[NumParagraphs + 1];     // 37 + 1
    paragraphOffset[0] = 0;
    for (int i=0; i<NumParagraphs; i++)         // i = 0..36
        paragraphOffset[i+1] = paragraphOffset[i] + paragraph[i].count();

    int curParNr = 0;
    int curParOffset = 0;

    /*
      Output the alphabet as a row of links.
     */
    if (includeAlphabet) {
        xmlWriter().writeStartElement("p");
        xmlWriter().writeAttribute("outputclass","centerAlign functionIndex");
        xmlWriter().writeStartElement("b");
        for (int i = 0; i < 26; i++) {
            QChar ch('a' + i);
            if (usedParagraphNames.contains(char('a' + i))) {
                xmlWriter().writeStartElement("xref");
                xmlWriter().writeAttribute("href",QString("#%1").arg(ch));
                xmlWriter().writeCharacters(QString(ch.toUpper()));
                xmlWriter().writeEndElement(); // </xref>
            }
        }
        xmlWriter().writeEndElement(); // </b>
        xmlWriter().writeEndElement(); // </p>
    }

    /*
      Output a <p> element to contain all the <dl> elements.
     */
    xmlWriter().writeStartElement("p");
    xmlWriter().writeAttribute("outputclass","compactlist flowListDiv");

    for (int i=0; i<classMap.count()-1; i++) {
        while ((curParNr < NumParagraphs) &&
               (curParOffset == paragraph[curParNr].count())) {
            ++curParNr;
            curParOffset = 0;
        }

        /*
          Starting a new paragraph means starting a new <dl>.
        */
        if (curParOffset == 0) {
            if (i > 0) {
                xmlWriter().writeEndElement(); // </dlentry>
                xmlWriter().writeEndElement(); // </dl>
            }
            xmlWriter().writeStartElement("dl");
            if (++numTableRows % 2 == 1)
                xmlWriter().writeAttribute("outputclass","flowList odd");
            else
                xmlWriter().writeAttribute("outputclass","flowList even");
            xmlWriter().writeStartElement("dlentry");
            xmlWriter().writeStartElement("dt");
            xmlWriter().writeAttribute("outputclass","alphaChar");
            if (includeAlphabet) {
                QChar c = paragraphName[curParNr][0].toLower();
                xmlWriter().writeStartElement("a");
                xmlWriter().writeAttribute("name",c);
            }
            xmlWriter().writeStartElement("b");
            xmlWriter().writeCharacters(paragraphName[curParNr]);
            xmlWriter().writeEndElement(); // </b>
            xmlWriter().writeEndElement(); // </dt>
        }

        /*
          Output a <dd> for the current offset in the current paragraph.
         */
        xmlWriter().writeStartElement("dd");
        if ((curParNr < NumParagraphs) &&
            !paragraphName[curParNr].isEmpty()) {
            NodeMap::Iterator it;
            it = paragraph[curParNr].begin();
            for (int i=0; i<curParOffset; i++)
                ++it;

            /*
              Previously, we used generateFullName() for this, but we
              require some special formatting.
            */
            xmlWriter().writeStartElement("xref");
            xmlWriter().writeAttribute("href",linkForNode(it.value(), relative));
            
            QStringList pieces;
            if (it.value()->subType() == Node::QmlClass)
                pieces << it.value()->name();
            else
                pieces = fullName(it.value(), relative, marker).split("::");
            xmlWriter().writeCharacters(protectEnc(pieces.last()));
            xmlWriter().writeEndElement(); // </xref>
            if (pieces.size() > 1) {
                xmlWriter().writeCharacters(" (");
                generateFullName(it.value()->parent(),relative,marker);
                xmlWriter().writeCharacters(")");
            }
        }
        xmlWriter().writeEndElement(); // </dd>
        curParOffset++;
    }
    xmlWriter().writeEndElement(); // </dlentry>
    xmlWriter().writeEndElement(); // </dl>
    xmlWriter().writeEndElement(); // </p>
}

/*!
  Write XML for a function index to the current XML stream.
 */
void DitaXmlGenerator::generateFunctionIndex(const Node* relative,
                                             CodeMarker* marker)
{
    xmlWriter().writeStartElement("p");
    xmlWriter().writeAttribute("outputclass","centerAlign functionIndex");
    xmlWriter().writeStartElement("b");
    for (int i = 0; i < 26; i++) {
        QChar ch('a' + i);
        xmlWriter().writeStartElement("xref");
        xmlWriter().writeAttribute("href",QString("#%1").arg(ch));
        xmlWriter().writeCharacters(QString(ch.toUpper()));
        xmlWriter().writeEndElement(); // </xref>
    }
    xmlWriter().writeEndElement(); // </b>
    xmlWriter().writeEndElement(); // </p>

    char nextLetter = 'a';
    char currentLetter;

    xmlWriter().writeStartElement("ul");
    QMap<QString, NodeMap >::ConstIterator f = funcIndex.begin();
    while (f != funcIndex.end()) {
        xmlWriter().writeStartElement("li");
        currentLetter = f.key()[0].unicode();
        while (islower(currentLetter) && currentLetter >= nextLetter) {
            xmlWriter().writeStartElement("p");
            writeGuidAttribute(QString(nextLetter));
            xmlWriter().writeAttribute("outputclass","target");
            xmlWriter().writeCharacters(QString(nextLetter));
            xmlWriter().writeEndElement(); // </p>
            nextLetter++;
        }
        xmlWriter().writeCharacters(protectEnc(f.key()));
        xmlWriter().writeCharacters(":");

        NodeMap::ConstIterator s = (*f).begin();
        while (s != (*f).end()) {
            generateFullName((*s)->parent(), relative, marker, *s);
            ++s;
        }
        xmlWriter().writeEndElement(); // </li>
        ++f;
    }
    xmlWriter().writeEndElement(); // </ul>
}

/*!
  Write the legalese texts as XML to the current XML stream.
 */
void DitaXmlGenerator::generateLegaleseList(const Node* relative,
                                            CodeMarker* marker)
{
    QMap<Text, const Node*>::ConstIterator it = legaleseTexts.begin();
    while (it != legaleseTexts.end()) {
        Text text = it.key();
        //out() << "<hr />\n";
        generateText(text, relative, marker);
        xmlWriter().writeStartElement("ul");
        do {
            xmlWriter().writeStartElement("li");
            generateFullName(it.value(), relative, marker);
            xmlWriter().writeEndElement(); // </li>
            ++it;
        } while (it != legaleseTexts.end() && it.key() == text);
        xmlWriter().writeEndElement(); //</ul>
    }
}

/*!
  Generate the text for the QML item described by \a node
  and write it to the current XML stream.
 */
void DitaXmlGenerator::generateQmlItem(const Node* node,
                                       const Node* relative,
                                       CodeMarker* marker,
                                       bool summary)
{ 
    QString marked = marker->markedUpQmlItem(node,summary);
    QRegExp tag("(<[^@>]*>)");
    if (marked.indexOf(tag) != -1) {
        QString tmp = protectEnc(marked.mid(tag.pos(1), tag.cap(1).length()));
        marked.replace(tag.pos(1), tag.cap(1).length(), tmp);
    }
    marked.replace(QRegExp("<@param>([a-z]+)_([1-9n])</@param>"),
                   "<i>\\1<sub>\\2</sub></i>");
    marked.replace("<@param>", "<i>");
    marked.replace("</@param>", "</i>");

    if (summary)
        marked.replace("@name>", "b>");

    marked.replace("<@extra>", "<tt>");
    marked.replace("</@extra>", "</tt>");

    if (summary) {
        marked.replace("<@type>", "");
        marked.replace("</@type>", "");
    }
    writeText(marked, marker, relative);
}

/*!
  Writher the XML for the overview list to the current XML stream.
 */
void DitaXmlGenerator::generateOverviewList(const Node* relative, CodeMarker* /* marker */)
{
    QMap<const FakeNode*, QMap<QString, FakeNode*> > fakeNodeMap;
    QMap<QString, const FakeNode*> groupTitlesMap;
    QMap<QString, FakeNode*> uncategorizedNodeMap;
    QRegExp singleDigit("\\b([0-9])\\b");

    const NodeList children = myTree->root()->childNodes();
    foreach (Node* child, children) {
        if (child->type() == Node::Fake && child != relative) {
            FakeNode* fakeNode = static_cast<FakeNode*>(child);

            // Check whether the page is part of a group or is the group
            // definition page.
            QString group;
            bool isGroupPage = false;
            if (fakeNode->doc().metaCommandsUsed().contains("group")) {
                group = fakeNode->doc().metaCommandArgs("group")[0];
                isGroupPage = true;
            }

            // there are too many examples; they would clutter the list
            if (fakeNode->subType() == Node::Example)
                continue;

            // not interested either in individual (Qt Designer etc.) manual chapters
            if (fakeNode->links().contains(Node::ContentsLink))
                continue;

            // Discard external nodes.
            if (fakeNode->subType() == Node::ExternalPage)
                continue;

            QString sortKey = fakeNode->fullTitle().toLower();
            if (sortKey.startsWith("the "))
                sortKey.remove(0, 4);
            sortKey.replace(singleDigit, "0\\1");

            if (!group.isEmpty()) {
                if (isGroupPage) {
                    // If we encounter a group definition page, we add all
                    // the pages in that group to the list for that group.
                    foreach (Node* member, fakeNode->groupMembers()) {
                        if (member->type() != Node::Fake)
                            continue;
                        FakeNode* page = static_cast<FakeNode*>(member);
                        if (page) {
                            QString sortKey = page->fullTitle().toLower();
                            if (sortKey.startsWith("the "))
                                sortKey.remove(0, 4);
                            sortKey.replace(singleDigit, "0\\1");
                            fakeNodeMap[const_cast<const FakeNode*>(fakeNode)].insert(sortKey, page);
                            groupTitlesMap[fakeNode->fullTitle()] = const_cast<const FakeNode*>(fakeNode);
                        }
                    }
                }
                else if (!isGroupPage) {
                    // If we encounter a page that belongs to a group then
                    // we add that page to the list for that group.
                    const FakeNode* groupNode =
                        static_cast<const FakeNode*>(myTree->root()->findNode(group, Node::Fake));
                    if (groupNode)
                        fakeNodeMap[groupNode].insert(sortKey, fakeNode);
                    //else
                    //    uncategorizedNodeMap.insert(sortKey, fakeNode);
                }// else
                //    uncategorizedNodeMap.insert(sortKey, fakeNode);
            }// else
            //    uncategorizedNodeMap.insert(sortKey, fakeNode);
        }
    }

    // We now list all the pages found that belong to groups.
    // If only certain pages were found for a group, but the definition page
    // for that group wasn't listed, the list of pages will be intentionally
    // incomplete. However, if the group definition page was listed, all the
    // pages in that group are listed for completeness.

    if (!fakeNodeMap.isEmpty()) {
        foreach (const QString& groupTitle, groupTitlesMap.keys()) {
            const FakeNode* groupNode = groupTitlesMap[groupTitle];
            xmlWriter().writeStartElement("p");
            xmlWriter().writeAttribute("outputclass","h3");
            xmlWriter().writeStartElement("xref");
            xmlWriter().writeAttribute("href",linkForNode(groupNode, relative));
            xmlWriter().writeCharacters(protectEnc(groupNode->fullTitle()));
            xmlWriter().writeEndElement(); // </xref>
            xmlWriter().writeEndElement(); // </p>
            if (fakeNodeMap[groupNode].count() == 0)
                continue;

            xmlWriter().writeStartElement("ul");
            foreach (const FakeNode* fakeNode, fakeNodeMap[groupNode]) {
                QString title = fakeNode->fullTitle();
                if (title.startsWith("The "))
                    title.remove(0, 4);
                xmlWriter().writeStartElement("li");
                xmlWriter().writeStartElement("xref");
                xmlWriter().writeAttribute("href",linkForNode(fakeNode, relative));
                xmlWriter().writeCharacters(protectEnc(title));
                xmlWriter().writeEndElement(); // </xref>
                xmlWriter().writeEndElement(); // </li>
            }
            xmlWriter().writeEndElement(); // </ul>
        }
    }

    if (!uncategorizedNodeMap.isEmpty()) {
        xmlWriter().writeStartElement("p");
        xmlWriter().writeAttribute("outputclass","h3");
        xmlWriter().writeCharacters("Miscellaneous");
        xmlWriter().writeEndElement(); // </p>
        xmlWriter().writeStartElement("ul");
        foreach (const FakeNode *fakeNode, uncategorizedNodeMap) {
            QString title = fakeNode->fullTitle();
            if (title.startsWith("The "))
                title.remove(0, 4);
            xmlWriter().writeStartElement("li");
            xmlWriter().writeStartElement("xref");
            xmlWriter().writeAttribute("href",linkForNode(fakeNode, relative));
            xmlWriter().writeCharacters(protectEnc(title));
            xmlWriter().writeEndElement(); // </xref>
            xmlWriter().writeEndElement(); // </li>
        }
        xmlWriter().writeEndElement(); // </ul>
    }
}

/*!
  Write the XML for a standard section of a page, e.g.
  "Public Functions" or "Protected Slots." The section
  is written too the current XML stream as a table.
 */
void DitaXmlGenerator::generateSection(const NodeList& nl,
                                       const Node* relative,
                                       CodeMarker* marker,
                                       CodeMarker::SynopsisStyle style)
{
    bool name_alignment = true;
    if (!nl.isEmpty()) {
        bool twoColumn = false;
        if (style == CodeMarker::SeparateList) {
            name_alignment = false;
            twoColumn = (nl.count() >= 16);
        }
        else if (nl.first()->type() == Node::Property) {
            twoColumn = (nl.count() >= 5);
            name_alignment = false;
        }
        if (name_alignment) {
            xmlWriter().writeStartElement("table");
            xmlWriter().writeAttribute("outputclass","alignedsummary");
            xmlWriter().writeStartElement("tgroup");
            xmlWriter().writeAttribute("cols","2");
            xmlWriter().writeStartElement("tbody");
        }
        else {
            if (twoColumn) {
                xmlWriter().writeStartElement("table");
                xmlWriter().writeAttribute("outputclass","propsummary");
                xmlWriter().writeStartElement("tgroup");
                xmlWriter().writeAttribute("cols","1");
                xmlWriter().writeStartElement("tbody");
                xmlWriter().writeStartElement("row");
                xmlWriter().writeStartElement("entry");
                xmlWriter().writeAttribute("outputclass","topAlign");
            }
            xmlWriter().writeStartElement("ul");
        }

        int i = 0;
        NodeList::ConstIterator m = nl.begin();
        while (m != nl.end()) {
            if ((*m)->access() == Node::Private) {
                ++m;
                continue;
            }

            if (name_alignment) {
                xmlWriter().writeStartElement("row");
                xmlWriter().writeStartElement("entry");
                xmlWriter().writeAttribute("outputclass","memItemLeft rightAlign topAlign");
            }
            else {
                if (twoColumn && i == (int) (nl.count() + 1) / 2) {
                    xmlWriter().writeEndElement(); // </ul>
                    xmlWriter().writeEndElement(); // </entry>
                    xmlWriter().writeStartElement("entry");
                    xmlWriter().writeAttribute("outputclass","topAlign");
                    xmlWriter().writeStartElement("ul");
                }
                xmlWriter().writeStartElement("li");
                xmlWriter().writeAttribute("outputclass","fn");
            }

            QString marked = getMarkedUpSynopsis(*m, relative, marker, style);
            writeText(marked, marker, relative, name_alignment);
            if (name_alignment) {
                xmlWriter().writeEndElement(); // </entry>
                xmlWriter().writeEndElement(); // </row>
            }
            else {
                xmlWriter().writeEndElement(); // </li>
            }
            i++;
            ++m;
        }
        if (name_alignment) {
            xmlWriter().writeEndElement(); // </tbody>
            xmlWriter().writeEndElement(); // </tgroup>
            xmlWriter().writeEndElement(); // </table>
        }
        else {
            xmlWriter().writeEndElement(); // </ul>
            if (twoColumn) {
                xmlWriter().writeEndElement(); // </entry>
                xmlWriter().writeEndElement(); // </row>
                xmlWriter().writeEndElement(); // </tbody>
                xmlWriter().writeEndElement(); // </tgroup>
                xmlWriter().writeEndElement(); // </table>
            }
        }
    }
}

/*!
  Writes the "inherited from" list to the current XML stream.
 */
void DitaXmlGenerator::generateSectionInheritedList(const Section& section,
                                                    const Node* relative,
                                                    CodeMarker* marker)
{
    if (section.inherited.isEmpty())
        return;
    xmlWriter().writeStartElement("ul");
    QList<QPair<ClassNode*,int> >::ConstIterator p = section.inherited.begin();
    while (p != section.inherited.end()) {
        xmlWriter().writeStartElement("li");
        xmlWriter().writeAttribute("outputclass","fn");
        QString text;
        text.setNum((*p).second);
        text += " ";
        if ((*p).second == 1)
            text += section.singularMember;
        else
            text += section.pluralMember;
        text += " inherited from ";
        xmlWriter().writeCharacters(text);
        xmlWriter().writeStartElement("xref");
        // zzz
        text = fileName((*p).first) + "#";
        text += DitaXmlGenerator::cleanRef(section.name.toLower());
        xmlWriter().writeAttribute("href",text);
        text = protectEnc(marker->plainFullName((*p).first, relative));
        xmlWriter().writeCharacters(text);
        xmlWriter().writeEndElement(); // </xref>
        xmlWriter().writeEndElement(); // </li>
        ++p;
    }
    xmlWriter().writeEndElement(); // </ul>
}

/*!
  Get the synopsis from the \a node using the \a relative
  node if needed, and mark up the synopsis using \a marker.
  Use the style to decide which kind of sysnopsis to build,
  normally \c Summary or \c Detailed. Return the marked up
  string.
 */
QString DitaXmlGenerator::getMarkedUpSynopsis(const Node* node,
                                              const Node* relative,
                                              CodeMarker* marker,
                                              CodeMarker::SynopsisStyle style)
{
    QString marked = marker->markedUpSynopsis(node, relative, style);
    QRegExp tag("(<[^@>]*>)");
    if (marked.indexOf(tag) != -1) {
        QString tmp = protectEnc(marked.mid(tag.pos(1), tag.cap(1).length()));
        marked.replace(tag.pos(1), tag.cap(1).length(), tmp);
    }
    marked.replace(QRegExp("<@param>([a-z]+)_([1-9n])</@param>"),
                   "<i>\\1<sub>\\2</sub></i>");
#if 0    
    marked.replace("<@param>","<i>");
    marked.replace("</@param>","</i>");
#endif
    if (style == CodeMarker::Summary) {
        marked.replace("<@name>","");   // was "<b>"
        marked.replace("</@name>","");  // was "</b>"
    }

    if (style == CodeMarker::SeparateList) {
        QRegExp extraRegExp("<@extra>.*</@extra>");
        extraRegExp.setMinimal(true);
        marked.replace(extraRegExp,"");
    }
#if 0    
    else {
        marked.replace("<@extra>","<tt>");
        marked.replace("</@extra>","</tt>");
    }
#endif    

    if (style != CodeMarker::Detailed) {
        marked.replace("<@type>","");
        marked.replace("</@type>","");
    }
    return marked;
}

/*!
  Renamed from highlightedCode() in the html generator. Writes
  the \a markedCode to the current XML stream.
 */
void DitaXmlGenerator::writeText(const QString& markedCode,
                                 CodeMarker* marker,
                                 const Node* relative,
                                 bool nameAlignment)
{
    QString src = markedCode;
    QString html;
    QStringRef arg;
    QStringRef par1;

    const QChar charLangle = '<';
    const QChar charAt = '@';

    /*
      First strip out all the extraneous markup. The table
      below contains the markup we want to keep. Everything
      else that begins with "<@" or "</@" is stripped out.
     */
    static const QString spanTags[] = {
        "<@link ",         "<@link ",
        "<@type>",         "<@type>",
        "<@headerfile>",   "<@headerfile>",
        "<@func>",         "<@func>",
        "<@param>",        "<@param>",
        "<@extra>",        "<@extra>",
        "</@link>",        "</@link>",
        "</@type>",        "</@type>",
        "</@headerfile>",  "</@headerfile>",
        "</@func>",        "</@func>",
        "</@param>",        "</@param>",
        "</@extra>",        "</@extra>"
    };
    for (int i = 0, n = src.size(); i < n;) {
        if (src.at(i) == charLangle) {
            bool handled = false;
            for (int k = 0; k != 12; ++k) {
                const QString & tag = spanTags[2 * k];
                if (tag == QStringRef(&src, i, tag.length())) {
                    html += spanTags[2 * k + 1];
                    i += tag.length();
                    handled = true;
                    break;
                }
            }
            if (!handled) {
                ++i;
                if (src.at(i) == charAt ||
                    (src.at(i) == QLatin1Char('/') && src.at(i + 1) == charAt)) {
                    // drop 'our' unknown tags (the ones still containing '@')
                    while (i < n && src.at(i) != QLatin1Char('>'))
                        ++i;
                    ++i;
                }
                else {
                    // retain all others
                    html += charLangle;
                }
            }
        }
        else {
            html += src.at(i);
            ++i;
        }
    }

    // replace all <@link> tags: "(<@link node=\"([^\"]+)\">).*(</@link>)"
    // replace all "(<@(type|headerfile|func)(?: +[^>]*)?>)(.*)(</@\\2>)" tags
    src = html;
    html = QString();
    static const QString markTags[] = {
        // 0       1         2           3       4        5
        "link", "type", "headerfile", "func", "param", "extra"
    };
    bool done = false;
    for (int i = 0, n = src.size(); i < n;) {
        if (src.at(i) == charLangle && src.at(i + 1) == charAt) {
            if (nameAlignment && !done) {
                if (!html.isEmpty()) {
                    xmlWriter().writeCharacters(html);
                    html.clear();
                }
                xmlWriter().writeEndElement(); // </<entry>
                xmlWriter().writeStartElement("entry");
                xmlWriter().writeAttribute("outputclass","memItemRight bottomAlign");
                done = true;
            }
            i += 2;
            bool handled = false;
            for (int k = 0; k != 6; ++k) {
                if (parseArg(src, markTags[k], &i, n, &arg, &par1)) {
                    const Node* n = 0;
                    if (k == 0) { // <@link>
                        if (!html.isEmpty()) {
                            xmlWriter().writeCharacters(html);
                            html.clear();
                        }
                        n = CodeMarker::nodeForString(par1.toString());
                        QString link = linkForNode(n, relative);
                        addLink(link, arg);
                    }
                    else if (k == 4) { // <@param>
                        if (!html.isEmpty()) {
                            xmlWriter().writeCharacters(html);
                            html.clear();
                        }
                        xmlWriter().writeStartElement("i");
                        xmlWriter().writeCharacters(arg.toString());
                        xmlWriter().writeEndElement(); // </i>
                    }
                    else if (k == 5) { // <@extra>
                        if (!html.isEmpty()) {
                            xmlWriter().writeCharacters(html);
                            html.clear();
                        }
                        xmlWriter().writeStartElement("tt");
                        xmlWriter().writeCharacters(arg.toString());
                        xmlWriter().writeEndElement(); // </tt>
                    }
                    else {
                        if (!html.isEmpty()) {
                            xmlWriter().writeCharacters(html);
                            html.clear();
                        }
                        par1 = QStringRef();
                        marker->resolveTarget(arg.toString(), myTree, relative);
                        QString link = linkForNode(n,relative);
                        addLink(link, arg);
                    }
                    handled = true;
                    break;
                }
            }
        }
        else {
            html += src.at(i++);
        }
    }

    if (!html.isEmpty()) {
        xmlWriter().writeCharacters(html);
    }
}

void DitaXmlGenerator::generateLink(const Atom* atom,
                                    const Node* /* relative */,
                                    CodeMarker* marker)
{
    static QRegExp camelCase("[A-Z][A-Z][a-z]|[a-z][A-Z0-9]|_");

    if (funcLeftParen.indexIn(atom->string()) != -1 && marker->recognizeLanguage("Cpp")) {
        // hack for C++: move () outside of link
        int k = funcLeftParen.pos(1);
        xmlWriter().writeCharacters(protectEnc(atom->string().left(k)));
        if (link.isEmpty()) {
            if (showBrokenLinks)
                xmlWriter().writeEndElement(); // </i>
        }
        else
            xmlWriter().writeEndElement(); // </xref>
        inLink = false;
        xmlWriter().writeCharacters(protectEnc(atom->string().mid(k)));
    }
    else if (marker->recognizeLanguage("Java")) {
	// hack for Java: remove () and use <tt> when appropriate
        bool func = atom->string().endsWith("()");
        bool tt = (func || atom->string().contains(camelCase));
        if (tt)
            xmlWriter().writeStartElement("tt");
        if (func)
            xmlWriter().writeCharacters(protectEnc(atom->string().left(atom->string().length() - 2)));
        else
            xmlWriter().writeCharacters(protectEnc(atom->string()));
        xmlWriter().writeEndElement(); // </tt>
    }
    else
        xmlWriter().writeCharacters(protectEnc(atom->string()));
}

QString DitaXmlGenerator::cleanRef(const QString& ref)
{
    QString clean;

    if (ref.isEmpty())
        return clean;

    clean.reserve(ref.size() + 20);
    const QChar c = ref[0];
    const uint u = c.unicode();

    if ((u >= 'a' && u <= 'z') ||
        (u >= 'A' && u <= 'Z') ||
        (u >= '0' && u <= '9')) {
        clean += c;
    }
    else if (u == '~') {
        clean += "dtor.";
    }
    else if (u == '_') {
        clean += "underscore.";
    }
    else {
        clean += "A";
    }

    for (int i = 1; i < (int) ref.length(); i++) {
        const QChar c = ref[i];
        const uint u = c.unicode();
        if ((u >= 'a' && u <= 'z') ||
            (u >= 'A' && u <= 'Z') ||
            (u >= '0' && u <= '9') || u == '-' ||
            u == '_' || u == ':' || u == '.') {
            clean += c;
        }
        else if (c.isSpace()) {
            clean += "-";
        }
        else if (u == '!') {
            clean += "-not";
        }
        else if (u == '&') {
            clean += "-and";
        }
        else if (u == '<') {
            clean += "-lt";
        }
        else if (u == '=') {
            clean += "-eq";
        }
        else if (u == '>') {
            clean += "-gt";
        }
        else if (u == '#') {
            clean += "#";
        }
        else {
            clean += "-";
            clean += QString::number((int)u, 16);
        }
    }
    return clean;
}

QString DitaXmlGenerator::registerRef(const QString& ref)
{
    QString clean = DitaXmlGenerator::cleanRef(ref);

    for (;;) {
        QString& prevRef = refMap[clean.toLower()];
        if (prevRef.isEmpty()) {
            prevRef = ref;
            break;
        }
        else if (prevRef == ref)
            break;
#if 0        
        else
            qDebug() << "PREVREF:" << prevRef;
#endif        
        clean += "x";
    }
    return clean;
}

/*!
  Calls protect() with the \a string. Returns the result.
 */
QString DitaXmlGenerator::protectEnc(const QString& string)
{
    return protect(string, outputEncoding);
}

QString DitaXmlGenerator::protect(const QString& string, const QString& outputEncoding)
{
#define APPEND(x) \
    if (xml.isEmpty()) { \
        xml = string; \
        xml.truncate(i); \
    } \
    xml += (x);

    QString xml;
    int n = string.length();

    for (int i = 0; i < n; ++i) {
        QChar ch = string.at(i);

        if (ch == QLatin1Char('&')) {
            APPEND("&amp;");
        }
        else if (ch == QLatin1Char('<')) {
            APPEND("&lt;");
        }
        else if (ch == QLatin1Char('>')) {
            APPEND("&gt;");
        }
        else if (ch == QLatin1Char('"')) {
            APPEND("&quot;");
        }
        else if ((outputEncoding == "ISO-8859-1" && ch.unicode() > 0x007F) ||
                 (ch == QLatin1Char('*') && i + 1 < n && string.at(i) == QLatin1Char('/')) ||
                 (ch == QLatin1Char('.') && i > 2 && string.at(i - 2) == QLatin1Char('.'))) {
            // we escape '*/' and the last dot in 'e.g.' and 'i.e.' for the Javadoc generator
            APPEND("&#x");
            xml += QString::number(ch.unicode(), 16);
            xml += QLatin1Char(';');
        }
        else {
            if (!xml.isEmpty())
                xml += ch;
        }
    }

    if (!xml.isEmpty())
        return xml;
    return string;

#undef APPEND
}

/*!
  Constructs a file name appropriate for the \a node
  and returns the file name.
 */
QString DitaXmlGenerator::fileBase(const Node* node) const
{
    QString result;
    result = PageGenerator::fileBase(node);
    if (!node->isInnerNode()) {
        switch (node->status()) {
        case Node::Compat:
            result += "-qt3";
            break;
        case Node::Obsolete:
            result += "-obsolete";
            break;
        default:
            ;
        }
    }
    return result;
}

QString DitaXmlGenerator::refForNode(const Node* node)
{
    const FunctionNode* func;
    const TypedefNode* tdn;
    QString ref;

    switch (node->type()) {
    case Node::Namespace:
    case Node::Class:
    default:
        break;
    case Node::Enum:
        ref = node->name() + "-enum";
        break;
    case Node::Typedef:
        tdn = static_cast<const TypedefNode *>(node);
        if (tdn->associatedEnum()) {
            return refForNode(tdn->associatedEnum());
        }
        else {
            ref = node->name() + "-typedef";
        }
        break;
    case Node::Function:
        func = static_cast<const FunctionNode *>(node);
        if (func->associatedProperty()) {
            return refForNode(func->associatedProperty());
        }
        else {
            ref = func->name();
            if (func->overloadNumber() != 1)
                ref += "-" + QString::number(func->overloadNumber());
        }
        break;
    case Node::Fake:
        if (node->subType() != Node::QmlPropertyGroup)
            break;
    case Node::QmlProperty:
    case Node::Property:
        ref = node->name() + "-prop";
        break;
    case Node::QmlSignal:
        ref = node->name() + "-signal";
        break;
    case Node::QmlMethod:
        ref = node->name() + "-method";
        break;
    case Node::Variable:
        ref = node->name() + "-var";
        break;
    case Node::Target:
        return protectEnc(node->name());
    }
    return registerRef(ref);
}

QString DitaXmlGenerator::guidForNode(const Node* node)
{
    switch (node->type()) {
    case Node::Namespace:
    case Node::Class:
    default:
        break;
    case Node::Enum:
        return node->guid();
    case Node::Typedef:
        {
            const TypedefNode* tdn = static_cast<const TypedefNode*>(node);
            if (tdn->associatedEnum()) 
                return guidForNode(tdn->associatedEnum());
        }
        return node->guid();
    case Node::Function:
        {
            const FunctionNode* fn = static_cast<const FunctionNode*>(node);
            if (fn->associatedProperty()) {
                return guidForNode(fn->associatedProperty());
            }
            else {
                QString ref = fn->name();
                if (fn->overloadNumber() != 1) {
                    ref += "-" + QString::number(fn->overloadNumber());
                    //qDebug() << "guidForNode() overloaded function:" << outFileName() << ref;
                }
            }
            return fn->guid();
        }
    case Node::Fake:
        if (node->subType() != Node::QmlPropertyGroup)
            break;
    case Node::QmlProperty:
    case Node::Property:
        return node->guid();
    case Node::QmlSignal:
        return node->guid();
    case Node::QmlMethod:
        return node->guid();
    case Node::Variable:
        return node->guid();
    case Node::Target:
        return node->guid();
    }
    return QString();
}

/*!
  Constructs a file name appropriate for the \a node and returns
  it. If the \a node is not a fake node, or if it is a fake node but
  it is neither an external page node nor an image node, call the
  PageGenerator::fileName() function.
 */
QString DitaXmlGenerator::fileName(const Node* node)
{
    if (node->type() == Node::Fake) {
        if (static_cast<const FakeNode*>(node)->subType() == Node::ExternalPage)
            return node->name();
        if (static_cast<const FakeNode*>(node)->subType() == Node::Image)
            return node->name();
    }
    return PageGenerator::fileName(node);
}

QString DitaXmlGenerator::linkForNode(const Node* node, const Node* relative)
{
    if (node == 0 || node == relative)
        return QString();
    if (!node->url().isEmpty())
        return node->url();
    if (fileBase(node).isEmpty())
        return QString();
    if (node->access() == Node::Private)
        return QString();

    QString fn = fileName(node);
    QString link = fn;

    if (!node->isInnerNode() || node->subType() == Node::QmlPropertyGroup) {
        QString guid = guidForNode(node);
        if (relative && fn == fileName(relative) && guid == guidForNode(relative)) {
            return QString();
        }
        link += "#";
        link += guid;
    }
    return link;
}

QString DitaXmlGenerator::refForAtom(Atom* atom, const Node* /* node */)
{
    if (atom->type() == Atom::SectionLeft)
        return Doc::canonicalTitle(Text::sectionHeading(atom).toString());
    if (atom->type() == Atom::Target)
        return Doc::canonicalTitle(atom->string());
    return QString();
}

void DitaXmlGenerator::generateFullName(const Node* apparentNode,
                                        const Node* relative,
                                        CodeMarker* marker,
                                        const Node* actualNode)
{
    if (actualNode == 0)
        actualNode = apparentNode;
    xmlWriter().writeStartElement("xref");
    xmlWriter().writeAttribute("href",linkForNode(actualNode, relative));
    if (true || relative == 0 || relative->status() != actualNode->status()) {
        switch (actualNode->status()) {
        case Node::Obsolete:
            xmlWriter().writeAttribute("outputclass","obsolete");
            break;
        case Node::Compat:
            xmlWriter().writeAttribute("outputclass","compat");
            break;
        default:
            break;
        }
    }
    xmlWriter().writeCharacters(protectEnc(fullName(apparentNode, relative, marker)));
    xmlWriter().writeEndElement(); // </xref>
}

void DitaXmlGenerator::generateDetailedMember(Node* node,
                                              const InnerNode* relative,
                                              CodeMarker* marker)
{
    QString marked;
    const EnumNode* en;

    if ((node->type() == Node::Enum) &&
        (en = static_cast<const EnumNode*>(node))->flagsType()) {
        xmlWriter().writeStartElement("p");
        writeGuidAttribute(node);
        xmlWriter().writeAttribute("outputclass","h3 flags");
        marked = getMarkedUpSynopsis(en, relative, marker, CodeMarker::Detailed);
        writeText(marked, marker, relative);
        xmlWriter().writeCharacters("\n");
        marked = getMarkedUpSynopsis(en->flagsType(),relative,marker,CodeMarker::Detailed);
        writeText(marked,marker,relative);
        xmlWriter().writeEndElement(); // </p>
    }
    else {
        xmlWriter().writeStartElement("p");
        writeGuidAttribute(node);
        xmlWriter().writeAttribute("outputclass","h3 fn");
        marked = getMarkedUpSynopsis(node, relative, marker, CodeMarker::Detailed);
        writeText(marked, marker, relative);
        xmlWriter().writeEndElement(); // </p>
    }

    generateStatus(node, marker);
    generateBody(node, marker);
    generateThreadSafeness(node, marker);
    generateSince(node, marker);

    if (node->type() == Node::Property) {
        const PropertyNode *property = static_cast<const PropertyNode *>(node);
        Section section;

        section.members += property->getters();
        section.members += property->setters();
        section.members += property->resetters();

        if (!section.members.isEmpty()) {
            xmlWriter().writeStartElement("p");
            xmlWriter().writeCharacters("<b>Access functions:</b>");
            xmlWriter().writeEndElement(); // </p>
            generateSection(section.members, node, marker, CodeMarker::Accessors);
        }

        Section notifiers;
        notifiers.members += property->notifiers();
        
        if (!notifiers.members.isEmpty()) {
            xmlWriter().writeStartElement("p");
            xmlWriter().writeCharacters("<b>Notifier signal:</b>");
            xmlWriter().writeEndElement(); // </p>
            generateSection(notifiers.members, node, marker, CodeMarker::Accessors);
        }
    }
    else if (node->type() == Node::Enum) {
        en = static_cast<const EnumNode *>(node);
        if (en->flagsType()) {
            xmlWriter().writeStartElement("p");
            QString text = "The " + protectEnc(en->flagsType()->name()) +
                " type is a typedef for " +
                "<xref href=\"qflags.html\">QFlags</xref>&lt;" +
                protectEnc(en->name()) +
                "&gt;. It stores an OR combination of " +
                protectEnc(en->name()) + " values.";
            xmlWriter().writeCharacters(text);
            xmlWriter().writeEndElement(); // </p>
        }
    }
    generateAlsoList(node, marker);
}

void DitaXmlGenerator::findAllClasses(const InnerNode* node)
{
    NodeList::const_iterator c = node->childNodes().constBegin();
    while (c != node->childNodes().constEnd()) {
        if ((*c)->access() != Node::Private && (*c)->url().isEmpty()) {
            if ((*c)->type() == Node::Class && !(*c)->doc().isEmpty()) {
                QString className = (*c)->name();
                if ((*c)->parent() &&
                    (*c)->parent()->type() == Node::Namespace &&
                    !(*c)->parent()->name().isEmpty())
                    className = (*c)->parent()->name()+"::"+className;

                if (!(static_cast<const ClassNode *>(*c))->hideFromMainList()) {
                    if ((*c)->status() == Node::Compat) {
                        compatClasses.insert(className, *c);
                    }
                    else if ((*c)->status() == Node::Obsolete) {
                        obsoleteClasses.insert(className, *c);
                    }
                    else {
                        nonCompatClasses.insert(className, *c);
                        if ((*c)->status() == Node::Main)
                            mainClasses.insert(className, *c);
                    }
                }

                QString moduleName = (*c)->moduleName();
                if (moduleName == "Qt3SupportLight") {
                    moduleClassMap[moduleName].insert((*c)->name(), *c);
                    moduleName = "Qt3Support";
                }
                if (!moduleName.isEmpty())
                    moduleClassMap[moduleName].insert((*c)->name(), *c);

                QString serviceName =
                    (static_cast<const ClassNode *>(*c))->serviceName();
                if (!serviceName.isEmpty())
                    serviceClasses.insert(serviceName, *c);
            }
            else if ((*c)->type() == Node::Fake &&
                     (*c)->subType() == Node::QmlClass &&
                     !(*c)->doc().isEmpty()) {
                QString qmlClassName = (*c)->name();
                qmlClasses.insert(qmlClassName,*c);
            }
            else if ((*c)->isInnerNode()) {
                findAllClasses(static_cast<InnerNode *>(*c));
            }
        }
        ++c;
    }
}

/*!
  For generating the "New Classes... in 4.x" section on the
  What's New in 4.x" page.
 */
void DitaXmlGenerator::findAllSince(const InnerNode* node)
{
    NodeList::const_iterator child = node->childNodes().constBegin();
    while (child != node->childNodes().constEnd()) {
        QString sinceVersion = (*child)->since();
        if (((*child)->access() != Node::Private) && !sinceVersion.isEmpty()) {
            NewSinceMaps::iterator nsmap = newSinceMaps.find(sinceVersion);
            if (nsmap == newSinceMaps.end())
                nsmap = newSinceMaps.insert(sinceVersion,NodeMultiMap());
            NewClassMaps::iterator ncmap = newClassMaps.find(sinceVersion);
            if (ncmap == newClassMaps.end())
                ncmap = newClassMaps.insert(sinceVersion,NodeMap());
            NewClassMaps::iterator nqcmap = newQmlClassMaps.find(sinceVersion);
            if (nqcmap == newQmlClassMaps.end())
                nqcmap = newQmlClassMaps.insert(sinceVersion,NodeMap());
 
            if ((*child)->type() == Node::Function) {
                FunctionNode *func = static_cast<FunctionNode *>(*child);
                if ((func->status() > Node::Obsolete) &&
                    (func->metaness() != FunctionNode::Ctor) &&
                    (func->metaness() != FunctionNode::Dtor)) {
                    nsmap.value().insert(func->name(),(*child));
                }
            }
            else if ((*child)->url().isEmpty()) {
                if ((*child)->type() == Node::Class && !(*child)->doc().isEmpty()) {
                    QString className = (*child)->name();
                    if ((*child)->parent() &&
                        (*child)->parent()->type() == Node::Namespace &&
                        !(*child)->parent()->name().isEmpty())
                        className = (*child)->parent()->name()+"::"+className;
                    nsmap.value().insert(className,(*child));
                    ncmap.value().insert(className,(*child));
                }
                else if ((*child)->subType() == Node::QmlClass) {
                    QString className = (*child)->name();
                    if ((*child)->parent() &&
                        (*child)->parent()->type() == Node::Namespace &&
                        !(*child)->parent()->name().isEmpty())
                        className = (*child)->parent()->name()+"::"+className;
                    nsmap.value().insert(className,(*child));
                    nqcmap.value().insert(className,(*child));
                }
            }
            else {
                QString name = (*child)->name();
                if ((*child)->parent() &&
                    (*child)->parent()->type() == Node::Namespace &&
                    !(*child)->parent()->name().isEmpty())
                    name = (*child)->parent()->name()+"::"+name;
                nsmap.value().insert(name,(*child));
            }
            if ((*child)->isInnerNode()) {
                findAllSince(static_cast<InnerNode *>(*child));
            }
        }
        ++child;
    }
}

void DitaXmlGenerator::findAllFunctions(const InnerNode* node)
{
    NodeList::ConstIterator c = node->childNodes().begin();
    while (c != node->childNodes().end()) {
        if ((*c)->access() != Node::Private) {
            if ((*c)->isInnerNode() && (*c)->url().isEmpty()) {
                findAllFunctions(static_cast<const InnerNode*>(*c));
            }
            else if ((*c)->type() == Node::Function) {
                const FunctionNode* func = static_cast<const FunctionNode*>(*c);
                if ((func->status() > Node::Obsolete) &&
                    (func->metaness() != FunctionNode::Ctor) &&
                    (func->metaness() != FunctionNode::Dtor)) {
                    funcIndex[(*c)->name()].insert(myTree->fullDocumentName((*c)->parent()), *c);
                }
            }
        }
        ++c;
    }
}

void DitaXmlGenerator::findAllLegaleseTexts(const InnerNode* node)
{
    NodeList::ConstIterator c = node->childNodes().begin();
    while (c != node->childNodes().end()) {
        if ((*c)->access() != Node::Private) {
            if (!(*c)->doc().legaleseText().isEmpty())
                legaleseTexts.insertMulti((*c)->doc().legaleseText(), *c);
            if ((*c)->isInnerNode())
                findAllLegaleseTexts(static_cast<const InnerNode *>(*c));
        }
        ++c;
    }
}

void DitaXmlGenerator::findAllNamespaces(const InnerNode* node)
{
    NodeList::ConstIterator c = node->childNodes().begin();
    while (c != node->childNodes().end()) {
        if ((*c)->access() != Node::Private) {
            if ((*c)->isInnerNode() && (*c)->url().isEmpty()) {
                findAllNamespaces(static_cast<const InnerNode *>(*c));
                if ((*c)->type() == Node::Namespace) {
                    const NamespaceNode *nspace = static_cast<const NamespaceNode *>(*c);
                    // Ensure that the namespace's name is not empty (the root
                    // namespace has no name).
                    if (!nspace->name().isEmpty()) {
                        namespaceIndex.insert(nspace->name(), *c);
                        QString moduleName = (*c)->moduleName();
                        if (moduleName == "Qt3SupportLight") {
                            moduleNamespaceMap[moduleName].insert((*c)->name(), *c);
                            moduleName = "Qt3Support";
                        }
                        if (!moduleName.isEmpty())
                            moduleNamespaceMap[moduleName].insert((*c)->name(), *c);
                    }
                }
            }
        }
        ++c;
    }
}

int DitaXmlGenerator::hOffset(const Node* node)
{
    switch (node->type()) {
    case Node::Namespace:
    case Node::Class:
        return 2;
    case Node::Fake:
        return 1;
    case Node::Enum:
    case Node::Typedef:
    case Node::Function:
    case Node::Property:
    default:
        return 3;
    }
}

bool DitaXmlGenerator::isThreeColumnEnumValueTable(const Atom* atom)
{
    while (atom != 0 && !(atom->type() == Atom::ListRight && atom->string() == ATOM_LIST_VALUE)) {
        if (atom->type() == Atom::ListItemLeft && !matchAhead(atom, Atom::ListItemRight))
            return true;
        atom = atom->next();
    }
    return false;
}

const Node* DitaXmlGenerator::findNodeForTarget(const QString& target,
                                                const Node* relative,
                                                CodeMarker* marker,
                                                const Atom* atom)
{
    const Node* node = 0;

    if (target.isEmpty()) {
        node = relative;
    }
    else if (target.endsWith(".html")) {
        node = myTree->root()->findNode(target, Node::Fake);
    }
    else if (marker) {
        node = marker->resolveTarget(target, myTree, relative);
        if (!node)
            node = myTree->findFakeNodeByTitle(target);
        if (!node && atom) {
            node = myTree->findUnambiguousTarget(target,
                *const_cast<Atom**>(&atom));
        }
    }

    if (!node)
        relative->doc().location().warning(tr("Cannot link to '%1'").arg(target));

    return node;
}

const QPair<QString,QString> DitaXmlGenerator::anchorForNode(const Node* node)
{
    QPair<QString,QString> anchorPair;
    anchorPair.first = PageGenerator::fileName(node);
    if (node->type() == Node::Fake) {
        const FakeNode *fakeNode = static_cast<const FakeNode*>(node);
        anchorPair.second = fakeNode->title();
    }

    return anchorPair;
}

QString DitaXmlGenerator::getLink(const Atom* atom,
                                  const Node* relative,
                                  CodeMarker* marker,
                                  const Node** node)
{
    QString link;
    *node = 0;
    inObsoleteLink = false;

    if (atom->string().contains(":") &&
        (atom->string().startsWith("file:")
         || atom->string().startsWith("http:")
         || atom->string().startsWith("https:")
         || atom->string().startsWith("ftp:")
         || atom->string().startsWith("mailto:"))) {
        
        link = atom->string();
    }
    else {
        QStringList path;
        if (atom->string().contains('#'))
            path = atom->string().split('#');
        else
            path.append(atom->string());

        Atom* targetAtom = 0;
        QString first = path.first().trimmed();

        if (first.isEmpty()) {
            *node = relative;
        }
        else if (first.endsWith(".html")) {
            *node = myTree->root()->findNode(first, Node::Fake);
        }
        else {
            *node = marker->resolveTarget(first, myTree, relative);
            if (!*node) {
                *node = myTree->findFakeNodeByTitle(first);
            }
            if (!*node) {
                *node = myTree->findUnambiguousTarget(first, targetAtom);
            }
        }

        if (*node) {
            if (!(*node)->url().isEmpty()) {
                return (*node)->url();
            }
            else {
                path.removeFirst();
            }
        }
        else {
            *node = relative;
        }

        if (*node && (*node)->status() == Node::Obsolete) {
            if (relative && (relative->parent() != *node) &&
                (relative->status() != Node::Obsolete)) {
                bool porting = false;
                if (relative->type() == Node::Fake) {
                    const FakeNode* fake = static_cast<const FakeNode*>(relative);
                    if (fake->title().startsWith("Porting"))
                        porting = true;
                }
                QString name = marker->plainFullName(relative);
                if (!porting && !name.startsWith("Q3")) {
                    if (obsoleteLinks) {
                        relative->doc().location().warning(tr("Link to obsolete item '%1' in %2")
                                                           .arg(atom->string())
                                                           .arg(name));
                    }
                    inObsoleteLink = true;
                }
            }
        }

        while (!path.isEmpty()) {
            targetAtom = myTree->findTarget(path.first(), *node);
            if (targetAtom == 0)
                break;
            path.removeFirst();
        }

        if (path.isEmpty()) {
            link = linkForNode(*node, relative);
            if (*node && (*node)->subType() == Node::Image)
                link = "images/used-in-examples/" + link;
            if (targetAtom)
                link += "#" + refForAtom(targetAtom, *node);
        }
    }
    return link;
}

void DitaXmlGenerator::generateIndex(const QString& fileBase,
                                     const QString& url,
                                     const QString& title)
{
    myTree->generateIndex(outputDir() + "/" + fileBase + ".index", url, title);
}

void DitaXmlGenerator::generateStatus(const Node* node, CodeMarker* marker)
{
    Text text;

    switch (node->status()) {
    case Node::Obsolete:
        if (node->isInnerNode())
	    Generator::generateStatus(node, marker);
        break;
    case Node::Compat:
        if (node->isInnerNode()) {
            text << Atom::ParaLeft
                 << Atom(Atom::FormattingLeft,ATOM_FORMATTING_BOLD)
                 << "This "
                 << typeString(node)
                 << " is part of the Qt 3 support library."
                 << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD)
                 << " It is provided to keep old source code working. "
                 << "We strongly advise against "
                 << "using it in new code. See ";

            const FakeNode *fakeNode = myTree->findFakeNodeByTitle("Porting To Qt 4");
            Atom *targetAtom = 0;
            if (fakeNode && node->type() == Node::Class) {
                QString oldName(node->name());
                targetAtom = myTree->findTarget(oldName.replace("3",""),fakeNode);
            }

            if (targetAtom) {
                QString fn = fileName(fakeNode);
                QString guid = lookupGuid(fn,refForAtom(targetAtom,fakeNode));
                text << Atom(Atom::GuidLink, fn + "#" + guid);
            }
            else
                text << Atom(Atom::Link, "Porting to Qt 4");

            text << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK)
                 << Atom(Atom::String, "Porting to Qt 4")
                 << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK)
                 << " for more information."
                 << Atom::ParaRight;
        }
        generateText(text, node, marker);
        break;
    default:
        Generator::generateStatus(node, marker);
    }
}

void DitaXmlGenerator::beginLink(const QString& link,
                                 const Node* node,
                                 const Node* relative,
                                 CodeMarker* marker)
{
    Q_UNUSED(marker)
    Q_UNUSED(relative)

    this->link = link;
    if (link.isEmpty()) {
        if (showBrokenLinks)
            xmlWriter().writeStartElement("i");
    }
    else if (node == 0 || (relative != 0 &&
                           node->status() == relative->status())) {
        xmlWriter().writeStartElement("xref");
        xmlWriter().writeAttribute("href",link);
    }
    else {
        switch (node->status()) {
        case Node::Obsolete:
            xmlWriter().writeStartElement("xref");
            xmlWriter().writeAttribute("href",link);
            xmlWriter().writeAttribute("outputclass","obsolete");
            break;
        case Node::Compat:
            xmlWriter().writeStartElement("xref");
            xmlWriter().writeAttribute("href",link);
            xmlWriter().writeAttribute("outputclass","compat");
            break;
        default:
            xmlWriter().writeStartElement("xref");
            xmlWriter().writeAttribute("href",link);
        }
    }
    inLink = true;
}

void DitaXmlGenerator::endLink()
{
    if (inLink) {
        if (link.isEmpty()) {
            if (showBrokenLinks)
                xmlWriter().writeEndElement(); // </i>
        }
        else {
            if (inObsoleteLink) {
                xmlWriter().writeStartElement("sup");
                xmlWriter().writeCharacters("(obsolete)");
                xmlWriter().writeEndElement(); // </sup>
            }
            xmlWriter().writeEndElement(); // </xref>
        }
    }
    inLink = false;
    inObsoleteLink = false;
}

/*!
  Generates the summary for the \a section. Only used for
  sections of QML element documentation.

  Currently handles only the QML property group.
 */
void DitaXmlGenerator::generateQmlSummary(const Section& section,
                                          const Node* relative,
                                          CodeMarker* marker)
{
    if (!section.members.isEmpty()) {
        xmlWriter().writeStartElement("ul");
        NodeList::ConstIterator m;
        m = section.members.begin();
        while (m != section.members.end()) {
            xmlWriter().writeStartElement("li");
            xmlWriter().writeAttribute("outputclass", "fn");
            generateQmlItem(*m,relative,marker,true);
            xmlWriter().writeEndElement(); // </li>
            ++m;
        }
        xmlWriter().writeEndElement(); // </ul>
    }
}

/*!
  zzz
  Outputs the html detailed documentation for a section
  on a QML element reference page.
 */
void DitaXmlGenerator::generateDetailedQmlMember(const Node* node,
                                                 const InnerNode* relative,
                                                 CodeMarker* marker)
{
    QString marked;
    QmlPropertyNode* qpn = 0;
    if (node->subType() == Node::QmlPropertyGroup) {
        const QmlPropGroupNode* qpgn = static_cast<const QmlPropGroupNode*>(node);
        NodeList::ConstIterator p = qpgn->childNodes().begin();
        xmlWriter().writeStartElement("ul");
        while (p != qpgn->childNodes().end()) {
            if ((*p)->type() == Node::QmlProperty) {
                qpn = static_cast<const QmlPropertyNode*>(*p);
                xmlWriter().writeStartElement("li");
                writeGuidAttribute(qpn);
                QString attr;
                if (!qpn->isWritable(myTree))
                    attr = "read-only";
                if (qpgn->isDefault()) {
                    if (!attr.isEmpty())
                        attr += " ";
                    attr += "default";
                }
                if (!attr.isEmpty())
                    xmlWriter().writeAttribute("outputclass",attr);
                generateQmlItem(qpn, relative, marker, false);
                xmlWriter().writeEndElement(); // </li>
            }
            ++p;
        }
        xmlWriter().writeEndElement(); // </ul>
    }
    else if (node->type() == Node::QmlSignal) {
        Node* n = const_cast<Node*>(node);
        xmlWriter().writeStartElement("ul");
        xmlWriter().writeStartElement("li");
        writeGuidAttribute(n);
        marked = getMarkedUpSynopsis(n, relative, marker, CodeMarker::Detailed);
        writeText(marked, marker, relative);
        xmlWriter().writeEndElement(); // </li>
        xmlWriter().writeEndElement(); // </ul>
    }
    else if (node->type() == Node::QmlMethod) {
        Node* n = const_cast<Node*>(node);
        xmlWriter().writeStartElement("ul");
        xmlWriter().writeStartElement("li");
        writeGuidAttribute(n);
        marked = getMarkedUpSynopsis(n, relative, marker, CodeMarker::Detailed);
        writeText(marked, marker, relative);
        xmlWriter().writeEndElement(); // </li>
        xmlWriter().writeEndElement(); // </ul>
    }
    generateStatus(node, marker);
    generateBody(node, marker);
    generateThreadSafeness(node, marker);
    generateSince(node, marker);
    generateAlsoList(node, marker);
}

/*!
  Output the "Inherits" line for the QML element,
  if there should be one.
 */
void DitaXmlGenerator::generateQmlInherits(const QmlClassNode* cn,
                                           CodeMarker* marker)
{
    if (cn && !cn->links().empty()) {
        if (cn->links().contains(Node::InheritsLink)) {
            QPair<QString,QString> linkPair;
            linkPair = cn->links()[Node::InheritsLink];
            QStringList strList(linkPair.first);
            const Node* n = myTree->findNode(strList,Node::Fake);
            if (n && n->subType() == Node::QmlClass) {
                const QmlClassNode* qcn = static_cast<const QmlClassNode*>(n);
                xmlWriter().writeStartElement("p");
                xmlWriter().writeAttribute("outputclass","centerAlign");
                Text text;
                text << "[Inherits ";
                text << Atom(Atom::LinkNode,CodeMarker::stringForNode(qcn));
                text << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK);
                text << Atom(Atom::String, linkPair.second);
                text << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK);
                text << "]";
                generateText(text, cn, marker);
                xmlWriter().writeEndElement(); // </p>
            }
        }
    }
}

/*!
  Output the "Inherit by" list for the QML element,
  if it is inherited by any other elements.
 */
void DitaXmlGenerator::generateQmlInheritedBy(const QmlClassNode* cn,
                                              CodeMarker* marker)
{
    if (cn) {
        NodeList subs;
        QmlClassNode::subclasses(cn->name(),subs);
        if (!subs.isEmpty()) {
            Text text;
            text << Atom::ParaLeft << "Inherited by ";
            appendSortedQmlNames(text,cn,subs,marker);
            text << Atom::ParaRight;
            generateText(text, cn, marker);
        }
    }
}

/*!
  Output the "[Xxx instantiates the C++ class QmlGraphicsXxx]"
  line for the QML element, if there should be one.

  If there is no class node, or if the class node status
  is set to Node::Internal, do nothing. 
 */
void DitaXmlGenerator::generateQmlInstantiates(const QmlClassNode* qcn,
                                               CodeMarker* marker)
{
    const ClassNode* cn = qcn->classNode();
    if (cn && (cn->status() != Node::Internal)) {
        xmlWriter().writeStartElement("p");
        xmlWriter().writeAttribute("outputclass","centerAlign");
        Text text;
        text << "[";
        text << Atom(Atom::LinkNode,CodeMarker::stringForNode(qcn));
        text << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK);
        text << Atom(Atom::String, qcn->name());
        text << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK);
        text << " instantiates the C++ class ";
        text << Atom(Atom::LinkNode,CodeMarker::stringForNode(cn));
        text << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK);
        text << Atom(Atom::String, cn->name());
        text << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK);
        text << "]";
        generateText(text, qcn, marker);
        xmlWriter().writeEndElement(); // </p>
    }
}

/*!
  Output the "[QmlGraphicsXxx is instantiated by QML element Xxx]"
  line for the class, if there should be one.

  If there is no QML element, or if the class node status
  is set to Node::Internal, do nothing. 
 */
void DitaXmlGenerator::generateInstantiatedBy(const ClassNode* cn,
                                           CodeMarker* marker)
{
    if (cn &&  cn->status() != Node::Internal && !cn->qmlElement().isEmpty()) {
        const Node* n = myTree->root()->findNode(cn->qmlElement(),Node::Fake);
        if (n && n->subType() == Node::QmlClass) {
            xmlWriter().writeStartElement("p");
            xmlWriter().writeAttribute("outputclass","centerAlign");
            Text text;
            text << "[";
            text << Atom(Atom::LinkNode,CodeMarker::stringForNode(cn));
            text << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK);
            text << Atom(Atom::String, cn->name());
            text << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK);
            text << " is instantiated by QML element ";
            text << Atom(Atom::LinkNode,CodeMarker::stringForNode(n));
            text << Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK);
            text << Atom(Atom::String, n->name());
            text << Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK);
            text << "]";
            generateText(text, cn, marker);
            xmlWriter().writeEndElement(); // </p>
        }
    }
}

/*!
  Return the full qualification of the node \a n, but without
  the name of \a n itself. e.g. A::B::C
 */
QString DitaXmlGenerator::fullQualification(const Node* n)
{
    QString fq;
    InnerNode* in = n->parent();
    while (in) {
        if ((in->type() == Node::Class) ||
            (in->type() == Node::Namespace)) {
            if (in->name().isEmpty())
                break;
            if (fq.isEmpty())
                fq = in->name();
            else
                fq = in->name() + "::" + fq;
        }
        else
            break;
        in = in->parent();
    }
    return fq;
}

/*!
  Outputs the <cxxClassDerivations> element.
  \code
	<cxxClassDerivations>
		<cxxClassDerivation>
			...
		</cxxClassDerivation>
		...
	</cxxClassDerivations>
  \endcode

  The <cxxClassDerivation> element is:

  \code
	<cxxClassDerivation>
		<cxxClassDerivationAccessSpecifier value="public"/>
		<cxxClassBaseClass href="class_base">Base</cxxClassBaseClass>
	</cxxClassDerivation>
  \endcode
 */
void DitaXmlGenerator::writeDerivations(const ClassNode* cn, CodeMarker* marker)
{
    QList<RelatedClass>::ConstIterator r;
    int index;

    if (!cn->baseClasses().isEmpty()) {
        xmlWriter().writeStartElement(CXXCLASSDERIVATIONS);
        r = cn->baseClasses().begin();
        index = 0;
        while (r != cn->baseClasses().end()) {
            xmlWriter().writeStartElement(CXXCLASSDERIVATION);
            xmlWriter().writeStartElement(CXXCLASSDERIVATIONACCESSSPECIFIER);
            xmlWriter().writeAttribute("value",(*r).accessString());
            xmlWriter().writeEndElement(); // </cxxClassDerivationAccessSpecifier>

            // not included: <cxxClassDerivationVirtual>

            xmlWriter().writeStartElement(CXXCLASSBASECLASS);
            xmlWriter().writeAttribute("href",(*r).node->ditaXmlHref());
            xmlWriter().writeCharacters(marker->plainFullName((*r).node));
            xmlWriter().writeEndElement(); // </cxxClassBaseClass>

            // not included: <ClassBaseStruct> or <cxxClassBaseUnion>

            xmlWriter().writeEndElement(); // </cxxClassDerivation>

            // not included: <cxxStructDerivation>

             ++r;
        }
        xmlWriter().writeEndElement(); // </cxxClassDerivations>
     }
}

/*!
  Writes a <cxxXXXAPIItemLocation> element, depending on the
  type of the node \a n, which can be a class, function, enum,
  typedef, or property.
 */
void DitaXmlGenerator::writeLocation(const Node* n)
{
    QString s1, s2, s3;
    if (n->type() == Node::Class) {
        s1 = CXXCLASSAPIITEMLOCATION;
        s2 = CXXCLASSDECLARATIONFILE;
        s3 = CXXCLASSDECLARATIONFILELINE;
    }
    else if (n->type() == Node::Function) {
        s1 = CXXFUNCTIONAPIITEMLOCATION;
        s2 = CXXFUNCTIONDECLARATIONFILE;
        s3 = CXXFUNCTIONDECLARATIONFILELINE;
    }
    else if (n->type() == Node::Enum) {
        s1 = CXXENUMERATIONAPIITEMLOCATION;
        s2 = CXXENUMERATIONDECLARATIONFILE;
        s3 = CXXENUMERATIONDECLARATIONFILELINE;
    }
    else if (n->type() == Node::Typedef) {
        s1 = CXXTYPEDEFAPIITEMLOCATION;
        s2 = CXXTYPEDEFDECLARATIONFILE;
        s3 = CXXTYPEDEFDECLARATIONFILELINE;
    }
    else if ((n->type() == Node::Property) ||
             (n->type() == Node::Variable)) {
        s1 = CXXVARIABLEAPIITEMLOCATION;
        s2 = CXXVARIABLEDECLARATIONFILE;
        s3 = CXXVARIABLEDECLARATIONFILELINE;
    }
    xmlWriter().writeStartElement(s1);
    xmlWriter().writeStartElement(s2);
    xmlWriter().writeAttribute("name","filePath");
    xmlWriter().writeAttribute("value",n->location().filePath());
    xmlWriter().writeEndElement(); // </cxx<s2>DeclarationFile>
    xmlWriter().writeStartElement(s3);
    xmlWriter().writeAttribute("name","lineNumber");
    QString lineNr;
    xmlWriter().writeAttribute("value",lineNr.setNum(n->location().lineNo()));
    xmlWriter().writeEndElement(); // </cxx<s3>DeclarationFileLine>

    // not included: <cxxXXXDefinitionFile>, <cxxXXXDefinitionFileSTart>,
    //               and <cxxXXXDefinitionFileEnd>

    xmlWriter().writeEndElement(); // </cxx<s1>ApiItemLocation>
}

/*!
  Write the <cxxFunction> elements.
 */
void DitaXmlGenerator::writeFunctions(const Section& s, 
                                      const ClassNode* cn, 
                                      CodeMarker* marker)
{
    NodeList::ConstIterator m = s.members.begin();
    while (m != s.members.end()) {
        if ((*m)->type() == Node::Function) {
            FunctionNode* fn = const_cast<FunctionNode*>(static_cast<const FunctionNode*>(*m));
            xmlWriter().writeStartElement(CXXFUNCTION);
            xmlWriter().writeAttribute("id",fn->guid());
            xmlWriter().writeStartElement(APINAME);
            if (fn->metaness() == FunctionNode::Signal)
                xmlWriter().writeAttribute("class","signal");
            else if (fn->metaness() == FunctionNode::Slot)
                xmlWriter().writeAttribute("class","slot");
            xmlWriter().writeCharacters(fn->name());
            xmlWriter().writeEndElement(); // </apiName>
            generateBrief(fn,marker);

            // not included: <prolog>

            xmlWriter().writeStartElement(CXXFUNCTIONDETAIL);
            xmlWriter().writeStartElement(CXXFUNCTIONDEFINITION);
            xmlWriter().writeStartElement(CXXFUNCTIONACCESSSPECIFIER);
            xmlWriter().writeAttribute("value",fn->accessString());
            xmlWriter().writeEndElement(); // <cxxFunctionAccessSpecifier>

            // not included: <cxxFunctionStorageClassSpecifierExtern>

            if (fn->isStatic()) {
                xmlWriter().writeStartElement(CXXFUNCTIONSTORAGECLASSSPECIFIERSTATIC);
                xmlWriter().writeAttribute("name","static");
                xmlWriter().writeAttribute("value","static");
                xmlWriter().writeEndElement(); // <cxxFunctionStorageClassSpecifierStatic>
            }

            // not included: <cxxFunctionStorageClassSpecifierMutable>,

            if (fn->isConst()) {
                xmlWriter().writeStartElement(CXXFUNCTIONCONST);
                xmlWriter().writeAttribute("name","const");
                xmlWriter().writeAttribute("value","const");
                xmlWriter().writeEndElement(); // <cxxFunctionConst>
            }
            
            // not included: <cxxFunctionExplicit>
            //               <cxxFunctionInline

            if (fn->virtualness() != FunctionNode::NonVirtual) {
                xmlWriter().writeStartElement(CXXFUNCTIONVIRTUAL);
                xmlWriter().writeAttribute("name","virtual");
                xmlWriter().writeAttribute("value","virtual");
                xmlWriter().writeEndElement(); // <cxxFunctionVirtual>
                if (fn->virtualness() == FunctionNode::PureVirtual) {
                    xmlWriter().writeStartElement(CXXFUNCTIONPUREVIRTUAL);
                    xmlWriter().writeAttribute("name","pure virtual");
                    xmlWriter().writeAttribute("value","pure virtual");
                    xmlWriter().writeEndElement(); // <cxxFunctionPureVirtual>
                }
            }
            
            if (fn->name() == cn->name()) {
                xmlWriter().writeStartElement(CXXFUNCTIONCONSTRUCTOR);
                xmlWriter().writeAttribute("name","constructor");
                xmlWriter().writeAttribute("value","constructor");
                xmlWriter().writeEndElement(); // <cxxFunctionConstructor>
            }
            else if (fn->name()[0] == QChar('~')) {
                xmlWriter().writeStartElement(CXXFUNCTIONDESTRUCTOR);
                xmlWriter().writeAttribute("name","destructor");
                xmlWriter().writeAttribute("value","destructor");
                xmlWriter().writeEndElement(); // <cxxFunctionDestructor>
            }
            else {
                xmlWriter().writeStartElement(CXXFUNCTIONDECLAREDTYPE);
                xmlWriter().writeCharacters(fn->returnType());
                xmlWriter().writeEndElement(); // <cxxFunctionDeclaredType>
            }

            // not included: <cxxFunctionReturnType>

            QString fq = fullQualification(fn);
            if (!fq.isEmpty()) {
                xmlWriter().writeStartElement(CXXFUNCTIONSCOPEDNAME);
                xmlWriter().writeCharacters(fq);
                xmlWriter().writeEndElement(); // <cxxFunctionScopedName>
            }
            xmlWriter().writeStartElement(CXXFUNCTIONPROTOTYPE);
            xmlWriter().writeCharacters(fn->signature(true));
            xmlWriter().writeEndElement(); // <cxxFunctionPrototype>

            QString fnl = fn->signature(false);
            int idx = fnl.indexOf(' ');
            if (idx < 0)
                idx = 0;
            else
                ++idx;
            fnl = fn->parent()->name() + "::" + fnl.mid(idx);
            xmlWriter().writeStartElement(CXXFUNCTIONNAMELOOKUP);
            xmlWriter().writeCharacters(fnl);
            xmlWriter().writeEndElement(); // <cxxFunctionNameLookup>

            if (fn->isReimp() && fn->reimplementedFrom() != 0) {
                FunctionNode* rfn = (FunctionNode*)fn->reimplementedFrom();
                xmlWriter().writeStartElement(CXXFUNCTIONREIMPLEMENTED);
                xmlWriter().writeAttribute("href",rfn->ditaXmlHref());
                xmlWriter().writeCharacters(marker->plainFullName(rfn));
                xmlWriter().writeEndElement(); // </cxxFunctionReimplemented>
            }
            writeParameters(fn);
            writeLocation(fn);
            xmlWriter().writeEndElement(); // <cxxFunctionDefinition>

            writeDetailedDescription(fn, marker, true, QString());
            // generateAlsoList(inner, marker);

            // not included: <example> or <apiImpl>

            xmlWriter().writeEndElement(); // </cxxFunctionDetail>
            xmlWriter().writeEndElement(); // </cxxFunction>

            if (fn->metaness() == FunctionNode::Ctor ||
                fn->metaness() == FunctionNode::Dtor ||
                fn->overloadNumber() != 1) {
            }
        }
        ++m;
    }
}

/*!
  This function writes the <cxxFunctionParameters> element.
 */
void DitaXmlGenerator::writeParameters(const FunctionNode* fn)
{
    const QList<Parameter>& parameters = fn->parameters();
    if (!parameters.isEmpty()) {
        xmlWriter().writeStartElement(CXXFUNCTIONPARAMETERS);
        QList<Parameter>::ConstIterator p = parameters.begin();
        while (p != parameters.end()) {
            xmlWriter().writeStartElement(CXXFUNCTIONPARAMETER);
            xmlWriter().writeStartElement(CXXFUNCTIONPARAMETERDECLAREDTYPE);
            xmlWriter().writeCharacters((*p).leftType());
            if (!(*p).rightType().isEmpty())
                xmlWriter().writeCharacters((*p).rightType());
            xmlWriter().writeEndElement(); // <cxxFunctionParameterDeclaredType>
            xmlWriter().writeStartElement(CXXFUNCTIONPARAMETERDECLARATIONNAME);
            xmlWriter().writeCharacters((*p).name());
            xmlWriter().writeEndElement(); // <cxxFunctionParameterDeclarationName>

            // not included: <cxxFunctionParameterDefinitionName>

            if (!(*p).defaultValue().isEmpty()) {
                xmlWriter().writeStartElement(CXXFUNCTIONPARAMETERDEFAULTVALUE);
                xmlWriter().writeCharacters((*p).defaultValue());
                xmlWriter().writeEndElement(); // <cxxFunctionParameterDefaultValue>
            }

            // not included: <apiDefNote>

            xmlWriter().writeEndElement(); // <cxxFunctionParameter>
            ++p;
        }
        xmlWriter().writeEndElement(); // <cxxFunctionParameters>
    }
}

/*!
  This function writes the enum types.
 */
void DitaXmlGenerator::writeEnumerations(const Section& s, 
                                         CodeMarker* marker)
{
    NodeList::ConstIterator m = s.members.begin();
    while (m != s.members.end()) {
        if ((*m)->type() == Node::Enum) {
            const EnumNode* en = static_cast<const EnumNode*>(*m);
            xmlWriter().writeStartElement(CXXENUMERATION);
            xmlWriter().writeAttribute("id",en->guid());
            xmlWriter().writeStartElement(APINAME);
            xmlWriter().writeCharacters(en->name());
            xmlWriter().writeEndElement(); // </apiName>
            generateBrief(en,marker);

            // not included <prolog>

            xmlWriter().writeStartElement(CXXENUMERATIONDETAIL);
            xmlWriter().writeStartElement(CXXENUMERATIONDEFINITION);
            xmlWriter().writeStartElement(CXXENUMERATIONACCESSSPECIFIER);
            xmlWriter().writeAttribute("value",en->accessString());
            xmlWriter().writeEndElement(); // <cxxEnumerationAccessSpecifier>

            QString fq = fullQualification(en);
            if (!fq.isEmpty()) {
                xmlWriter().writeStartElement(CXXENUMERATIONSCOPEDNAME);
                xmlWriter().writeCharacters(fq);
                xmlWriter().writeEndElement(); // <cxxEnumerationScopedName>
            }
            const QList<EnumItem>& items = en->items();
            if (!items.isEmpty()) {
                xmlWriter().writeStartElement(CXXENUMERATIONPROTOTYPE);
                xmlWriter().writeCharacters(en->name());
                xmlWriter().writeCharacters(" = { ");
                QList<EnumItem>::ConstIterator i = items.begin();
                while (i != items.end()) {
                    xmlWriter().writeCharacters((*i).name());
                    if (!(*i).value().isEmpty()) {
                        xmlWriter().writeCharacters(" = ");
                        xmlWriter().writeCharacters((*i).value());
                    }
                    ++i;
                    if (i != items.end())
                        xmlWriter().writeCharacters(", ");
                }
                xmlWriter().writeCharacters(" }");
                xmlWriter().writeEndElement(); // <cxxEnumerationPrototype>
            }

            xmlWriter().writeStartElement(CXXENUMERATIONNAMELOOKUP);
            xmlWriter().writeCharacters(en->parent()->name() + "::" + en->name());
            xmlWriter().writeEndElement(); // <cxxEnumerationNameLookup>

            // not included: <cxxEnumerationReimplemented>

            if (!items.isEmpty()) {
                xmlWriter().writeStartElement(CXXENUMERATORS);
                QList<EnumItem>::ConstIterator i = items.begin();
                while (i != items.end()) {
                    xmlWriter().writeStartElement(CXXENUMERATOR);
                    xmlWriter().writeStartElement(APINAME);
                    xmlWriter().writeCharacters((*i).name());
                    xmlWriter().writeEndElement(); // </apiName>

                    QString fq = fullQualification(en->parent());
                    if (!fq.isEmpty()) {
                        xmlWriter().writeStartElement(CXXENUMERATORSCOPEDNAME);
                        xmlWriter().writeCharacters(fq + "::" + (*i).name());
                        xmlWriter().writeEndElement(); // <cxxEnumeratorScopedName>
                    }
                    xmlWriter().writeStartElement(CXXENUMERATORPROTOTYPE);
                    xmlWriter().writeCharacters((*i).name());
                    xmlWriter().writeEndElement(); // <cxxEnumeratorPrototype>
                    xmlWriter().writeStartElement(CXXENUMERATORNAMELOOKUP);
                    xmlWriter().writeCharacters(en->parent()->name() + "::" + (*i).name());
                    xmlWriter().writeEndElement(); // <cxxEnumeratorNameLookup>

                    if (!(*i).value().isEmpty()) {
                        xmlWriter().writeStartElement(CXXENUMERATORINITIALISER);
                        xmlWriter().writeAttribute("value", (*i).value());
                        xmlWriter().writeEndElement(); // <cxxEnumeratorInitialiser>
                    }

                    // not included: <cxxEnumeratorAPIItemLocation>

                    if (!(*i).text().isEmpty()) {
                        xmlWriter().writeStartElement(APIDESC);
                        generateText((*i).text(), en, marker);
                        xmlWriter().writeEndElement(); // </apiDesc>
                    }
                    xmlWriter().writeEndElement(); // <cxxEnumerator>
                    ++i;
                }
                xmlWriter().writeEndElement(); // <cxxEnumerators>
            }
            
            writeLocation(en);
            xmlWriter().writeEndElement(); // <cxxEnumerationDefinition>

            writeDetailedDescription(en, marker, true, QString());

            // not included: <example> or <apiImpl>

            xmlWriter().writeEndElement(); // </cxxEnumerationDetail>

            // not included: <related-links>

            xmlWriter().writeEndElement(); // </cxxEnumeration>
        }
        ++m;
    }
}

/*!
  This function writes the output for the \typedef commands.
 */
void DitaXmlGenerator::writeTypedefs(const Section& s, 
                                     CodeMarker* marker)
{
    NodeList::ConstIterator m = s.members.begin();
    while (m != s.members.end()) {
        if ((*m)->type() == Node::Typedef) {
            const TypedefNode* tn = static_cast<const TypedefNode*>(*m);
            xmlWriter().writeStartElement(CXXTYPEDEF);
            xmlWriter().writeAttribute("id",tn->guid());
            xmlWriter().writeStartElement(APINAME);
            xmlWriter().writeCharacters(tn->name());
            xmlWriter().writeEndElement(); // </apiName>
            generateBrief(tn,marker);

            // not included: <prolog>

            xmlWriter().writeStartElement(CXXTYPEDEFDETAIL);
            xmlWriter().writeStartElement(CXXTYPEDEFDEFINITION);
            xmlWriter().writeStartElement(CXXTYPEDEFACCESSSPECIFIER);
            xmlWriter().writeAttribute("value",tn->accessString());
            xmlWriter().writeEndElement(); // <cxxTypedefAccessSpecifier>

            // not included: <cxxTypedefDeclaredType>

            QString fq = fullQualification(tn);
            if (!fq.isEmpty()) {
                xmlWriter().writeStartElement(CXXTYPEDEFSCOPEDNAME);
                xmlWriter().writeCharacters(fq);
                xmlWriter().writeEndElement(); // <cxxTypedefScopedName>
            }

            // not included: <cxxTypedefPrototype>

            xmlWriter().writeStartElement(CXXTYPEDEFNAMELOOKUP);
            xmlWriter().writeCharacters(tn->parent()->name() + "::" + tn->name());
            xmlWriter().writeEndElement(); // <cxxTypedefNameLookup>

            // not included: <cxxTypedefReimplemented>

            writeLocation(tn);
            xmlWriter().writeEndElement(); // <cxxTypedefDefinition>

            writeDetailedDescription(tn, marker, true, QString());

            // not included: <example> or <apiImpl>

            xmlWriter().writeEndElement(); // </cxxTypedefDetail>

            // not included: <related-links>

            xmlWriter().writeEndElement(); // </cxxTypedef>
        }
        ++m;
    }
}

/*!
  This function writes the output for the \property commands.
  This is the Q_PROPERTYs.
 */
void DitaXmlGenerator::writeProperties(const Section& s, 
                                       CodeMarker* marker)
{
    NodeList::ConstIterator m = s.members.begin();
    while (m != s.members.end()) {
        if ((*m)->type() == Node::Property) {
            const PropertyNode* pn = static_cast<const PropertyNode*>(*m);
            xmlWriter().writeStartElement(CXXVARIABLE);
            xmlWriter().writeAttribute("id",pn->guid());
            xmlWriter().writeStartElement(APINAME);
            xmlWriter().writeCharacters(pn->name());
            xmlWriter().writeEndElement(); // </apiName>
            generateBrief(pn,marker);

            // not included: <prolog>

            xmlWriter().writeStartElement(CXXVARIABLEDETAIL);
            xmlWriter().writeStartElement(CXXVARIABLEDEFINITION);
            xmlWriter().writeStartElement(CXXVARIABLEACCESSSPECIFIER);
            xmlWriter().writeAttribute("value",pn->accessString());
            xmlWriter().writeEndElement(); // <cxxVariableAccessSpecifier>

            // not included: <cxxVariableStorageClassSpecifierExtern>,
            //               <cxxVariableStorageClassSpecifierStatic>,
            //               <cxxVariableStorageClassSpecifierMutable>,
            //               <cxxVariableConst>, <cxxVariableVolatile>

            if (!pn->qualifiedDataType().isEmpty()) {
                xmlWriter().writeStartElement(CXXVARIABLEDECLAREDTYPE);
                xmlWriter().writeCharacters(pn->qualifiedDataType());
                xmlWriter().writeEndElement(); // <cxxVariableDeclaredType>
            }
            QString fq = fullQualification(pn);
            if (!fq.isEmpty()) {
                xmlWriter().writeStartElement(CXXVARIABLESCOPEDNAME);
                xmlWriter().writeCharacters(fq);
                xmlWriter().writeEndElement(); // <cxxVariableScopedName>
            }
            
            xmlWriter().writeStartElement(CXXVARIABLEPROTOTYPE);
            xmlWriter().writeCharacters("Q_PROPERTY(");
            xmlWriter().writeCharacters(pn->qualifiedDataType());
            xmlWriter().writeCharacters(" ");
            xmlWriter().writeCharacters(pn->name());
            writePropertyParameter("READ",pn->getters());
            writePropertyParameter("WRITE",pn->setters());
            writePropertyParameter("RESET",pn->resetters());
            writePropertyParameter("NOTIFY",pn->notifiers());
            if (pn->isDesignable() != pn->designableDefault()) {
                xmlWriter().writeCharacters(" DESIGNABLE ");
                if (!pn->runtimeDesignabilityFunction().isEmpty())
                    xmlWriter().writeCharacters(pn->runtimeDesignabilityFunction());
                else
                    xmlWriter().writeCharacters(pn->isDesignable() ? "true" : "false");
            }
            if (pn->isScriptable() != pn->scriptableDefault()) {
                xmlWriter().writeCharacters(" SCRIPTABLE ");
                if (!pn->runtimeScriptabilityFunction().isEmpty())
                    xmlWriter().writeCharacters(pn->runtimeScriptabilityFunction());
                else
                    xmlWriter().writeCharacters(pn->isScriptable() ? "true" : "false");
            }
            if (pn->isWritable() != pn->writableDefault()) {
                xmlWriter().writeCharacters(" STORED ");
                xmlWriter().writeCharacters(pn->isStored() ? "true" : "false");
            }
            if (pn->isUser() != pn->userDefault()) {
                xmlWriter().writeCharacters(" USER ");
                xmlWriter().writeCharacters(pn->isUser() ? "true" : "false");
            }
            if (pn->isConstant())
                xmlWriter().writeCharacters(" CONSTANT");
            if (pn->isFinal())
                xmlWriter().writeCharacters(" FINAL");
            xmlWriter().writeCharacters(")");
            xmlWriter().writeEndElement(); // <cxxVariablePrototype>

            xmlWriter().writeStartElement(CXXVARIABLENAMELOOKUP);
            xmlWriter().writeCharacters(pn->parent()->name() + "::" + pn->name());
            xmlWriter().writeEndElement(); // <cxxVariableNameLookup>

            if (pn->overriddenFrom() != 0) {
                PropertyNode* opn = (PropertyNode*)pn->overriddenFrom();
                xmlWriter().writeStartElement(CXXVARIABLEREIMPLEMENTED);
                xmlWriter().writeAttribute("href",opn->ditaXmlHref());
                xmlWriter().writeCharacters(marker->plainFullName(opn));
                xmlWriter().writeEndElement(); // </cxxVariableReimplemented>
            }

            writeLocation(pn);
            xmlWriter().writeEndElement(); // <cxxVariableDefinition>

            writeDetailedDescription(pn, marker, true, QString());
            
            // not included: <example> or <apiImpl>

            xmlWriter().writeEndElement(); // </cxxVariableDetail>

            // not included: <related-links>

            xmlWriter().writeEndElement(); // </cxxVariable>
        }
        ++m;
    }
}

/*!
  This function outputs the nodes resulting from \variable commands.
 */
void DitaXmlGenerator::writeDataMembers(const Section& s, 
                                        CodeMarker* marker)
{
    NodeList::ConstIterator m = s.members.begin();
    while (m != s.members.end()) {
        if ((*m)->type() == Node::Variable) {
            const VariableNode* vn = static_cast<const VariableNode*>(*m);
            xmlWriter().writeStartElement(CXXVARIABLE);
            xmlWriter().writeAttribute("id",vn->guid());
            xmlWriter().writeStartElement(APINAME);
            xmlWriter().writeCharacters(vn->name());
            xmlWriter().writeEndElement(); // </apiName>
            generateBrief(vn,marker);

            // not included: <prolog>

            xmlWriter().writeStartElement(CXXVARIABLEDETAIL);
            xmlWriter().writeStartElement(CXXVARIABLEDEFINITION);
            xmlWriter().writeStartElement(CXXVARIABLEACCESSSPECIFIER);
            xmlWriter().writeAttribute("value",vn->accessString());
            xmlWriter().writeEndElement(); // <cxxVariableAccessSpecifier>

            // not included: <cxxVAriableStorageClassSpecifierExtern>

            if (vn->isStatic()) {
                xmlWriter().writeStartElement(CXXVARIABLESTORAGECLASSSPECIFIERSTATIC);
                xmlWriter().writeAttribute("name","static");
                xmlWriter().writeAttribute("value","static");
                xmlWriter().writeEndElement(); // <cxxVariableStorageClassSpecifierStatic>
            }

            // not included: <cxxVAriableStorageClassSpecifierMutable>,
            //               <cxxVariableConst>, <cxxVariableVolatile>

            xmlWriter().writeStartElement(CXXVARIABLEDECLAREDTYPE);
            xmlWriter().writeCharacters(vn->leftType());
            if (!vn->rightType().isEmpty())
                xmlWriter().writeCharacters(vn->rightType());
            xmlWriter().writeEndElement(); // <cxxVariableDeclaredType>

            QString fq = fullQualification(vn);
            if (!fq.isEmpty()) {
                xmlWriter().writeStartElement(CXXVARIABLESCOPEDNAME);
                xmlWriter().writeCharacters(fq);
                xmlWriter().writeEndElement(); // <cxxVariableScopedName>
            }
            
            xmlWriter().writeStartElement(CXXVARIABLEPROTOTYPE);
            xmlWriter().writeCharacters(vn->leftType() + " ");
            //xmlWriter().writeCharacters(vn->parent()->name() + "::" + vn->name()); 
            xmlWriter().writeCharacters(vn->name()); 
            if (!vn->rightType().isEmpty())
                xmlWriter().writeCharacters(vn->rightType());
            xmlWriter().writeEndElement(); // <cxxVariablePrototype>

            xmlWriter().writeStartElement(CXXVARIABLENAMELOOKUP);
            xmlWriter().writeCharacters(vn->parent()->name() + "::" + vn->name());
            xmlWriter().writeEndElement(); // <cxxVariableNameLookup>

            // not included: <cxxVariableReimplemented>

            writeLocation(vn);
            xmlWriter().writeEndElement(); // <cxxVariableDefinition>

            writeDetailedDescription(vn, marker, true, QString());

            // not included: <example> or <apiImpl>

            xmlWriter().writeEndElement(); // </cxxVariableDetail>

            // not included: <related-links>

            xmlWriter().writeEndElement(); // </cxxVariable>
        }
        ++m;
    }
}

/*!
  This function writes a \macro as a <cxxDefine>.
 */
void DitaXmlGenerator::writeMacros(const Section& s, 
                                   CodeMarker* marker)
{
    NodeList::ConstIterator m = s.members.begin();
    while (m != s.members.end()) {
        if ((*m)->type() == Node::Function) {
            const FunctionNode* fn = static_cast<const FunctionNode*>(*m);
            if (fn->isMacro()) {
                xmlWriter().writeStartElement(CXXDEFINE);
                xmlWriter().writeAttribute("id",fn->guid());
                xmlWriter().writeStartElement(APINAME);
                xmlWriter().writeCharacters(fn->name());
                xmlWriter().writeEndElement(); // </apiName>
                generateBrief(fn,marker);

                // not included: <prolog>

                xmlWriter().writeStartElement(CXXDEFINEDETAIL);
                xmlWriter().writeStartElement(CXXDEFINEDEFINITION);
                xmlWriter().writeStartElement(CXXDEFINEACCESSSPECIFIER);
                xmlWriter().writeAttribute("value",fn->accessString());
                xmlWriter().writeEndElement(); // <cxxDefineAccessSpecifier>
            
                xmlWriter().writeStartElement(CXXDEFINEPROTOTYPE);
                xmlWriter().writeCharacters("#define ");
                xmlWriter().writeCharacters(fn->name());
                if (fn->metaness() == FunctionNode::MacroWithParams) {
                    QStringList params = fn->parameterNames();
                    if (!params.isEmpty()) {
                        xmlWriter().writeCharacters("(");
                        for (int i = 0; i < params.size(); ++i) {
                            if (params[i].isEmpty())
                                xmlWriter().writeCharacters("...");
                            else
                                xmlWriter().writeCharacters(params[i]);
                            if ((i+1) < params.size()) 
                                xmlWriter().writeCharacters(", ");
                        }
                        xmlWriter().writeCharacters(")");
                    }
                }
                xmlWriter().writeEndElement(); // <cxxDefinePrototype>

                xmlWriter().writeStartElement(CXXDEFINENAMELOOKUP);
                xmlWriter().writeCharacters(fn->name());
                xmlWriter().writeEndElement(); // <cxxDefineNameLookup>

                if (fn->reimplementedFrom() != 0) {
                    FunctionNode* rfn = (FunctionNode*)fn->reimplementedFrom();
                    xmlWriter().writeStartElement(CXXDEFINEREIMPLEMENTED);
                    xmlWriter().writeAttribute("href",rfn->ditaXmlHref());
                    xmlWriter().writeCharacters(marker->plainFullName(rfn));
                    xmlWriter().writeEndElement(); // </cxxDefineReimplemented>
                }

                if (fn->metaness() == FunctionNode::MacroWithParams) {
                    QStringList params = fn->parameterNames();
                    if (!params.isEmpty()) {
                        xmlWriter().writeStartElement(CXXDEFINEPARAMETERS);
                        for (int i = 0; i < params.size(); ++i) {
                            xmlWriter().writeStartElement(CXXDEFINEPARAMETER);
                            xmlWriter().writeStartElement(CXXDEFINEPARAMETERDECLARATIONNAME);
                            xmlWriter().writeCharacters(params[i]);
                            xmlWriter().writeEndElement(); // <cxxDefineParameterDeclarationName>

                            // not included: <apiDefNote>

                            xmlWriter().writeEndElement(); // <cxxDefineParameter>
                        }
                        xmlWriter().writeEndElement(); // <cxxDefineParameters>
                    }
                }

                writeLocation(fn);
                xmlWriter().writeEndElement(); // <cxxDefineDefinition>

                writeDetailedDescription(fn, marker, true, QString());

                // not included: <example> or <apiImpl>

                xmlWriter().writeEndElement(); // </cxxDefineDetail>

                // not included: <related-links>

                xmlWriter().writeEndElement(); // </cxxDefine>
            }
        }
        ++m;
    }
}

/*!
  This function writes one parameter of a Q_PROPERTY macro.
  The property is identified by \a tag ("READ" "WRIE" etc),
  and it is found in the 'a nlist.
 */
void DitaXmlGenerator::writePropertyParameter(const QString& tag, const NodeList& nlist)
{
    NodeList::const_iterator n = nlist.begin();
    while (n != nlist.end()) {
        xmlWriter().writeCharacters(" ");
        xmlWriter().writeCharacters(tag);
        xmlWriter().writeCharacters(" ");
        xmlWriter().writeCharacters((*n)->name());
        ++n;
    }
}

/*!
  Calls beginSubPage() in the base class to open the file.
  Then creates a new XML stream writer using the IO device
  from opened file and pushes the XML writer onto a stackj. 
  Creates the file named \a fileName in the output directory.
  Attaches a QTextStream to the created file, which is written
  to all over the place using out(). Finally, it sets some
  parameters in the XML writer and calls writeStartDocument().
 */
void DitaXmlGenerator::beginSubPage(const Location& location,
                                    const QString& fileName)
{
    PageGenerator::beginSubPage(location,fileName);
    QXmlStreamWriter* writer = new QXmlStreamWriter(out().device());
    xmlWriterStack.push(writer);
    writer->setAutoFormatting(true);
    writer->setAutoFormattingIndent(4);
    writer->writeStartDocument();
}

/*!
  Calls writeEndDocument() and then pops the XML stream writer
  off the stack and deletes it. Then it calls endSubPage() in
  the base class to close the device.
 */
void DitaXmlGenerator::endSubPage()
{
    xmlWriter().writeEndDocument();
    delete xmlWriterStack.pop();
    PageGenerator::endSubPage();
}

/*!
  Returns a reference to the XML stream writer currently in use.
  There is one XML stream writer open for each XML file being
  written, and they are kept on a stack. The one on top of the
  stack is the one being written to at the moment.
 */
QXmlStreamWriter& DitaXmlGenerator::xmlWriter()
{
    return *xmlWriterStack.top();
}

/*!
  Writes the \e {Detailed Description} section(s) for \a node to the
  current XML stream using the code \a marker. if the \a apiDesc flag
  is true, then the first section of the sequence of sections written
  will be an \c {apiDesc>} element with a \e {spectitle} attribute of
  \e {Detailed Description}. Otherwise, the first section will be a
  \c {<section>} element with a \c {<title>} element of \e {Detailed
  Description}. This function calls the Generator::generateBody()
  function to write the XML for the section list.
 */
void DitaXmlGenerator::writeDetailedDescription(const Node* node,
                                                CodeMarker* marker,
                                                bool apiDesc,
                                                const QString& title)
{
    if (!node->doc().isEmpty()) {
        inDetailedDescription = true;
        if (apiDesc) {
            inApiDesc = true;
            xmlWriter().writeStartElement(APIDESC);
            if (!title.isEmpty()) {
                writeGuidAttribute(title);
                xmlWriter().writeAttribute("spectitle",title);
            }
            else
                writeGuidAttribute("Detailed Description");
            xmlWriter().writeAttribute("outputclass","details");
        }
        else {
            inSection = true;
            xmlWriter().writeStartElement("section");
            if (!title.isEmpty()) {
                writeGuidAttribute(title);
                xmlWriter().writeAttribute("outputclass","details");
                xmlWriter().writeStartElement("title");
                xmlWriter().writeAttribute("outputclass","h2");
                xmlWriter().writeCharacters(title);
                xmlWriter().writeEndElement(); // </title>
            }
            else {
                writeGuidAttribute("Detailed Description");
                xmlWriter().writeAttribute("outputclass","details");
            }
        }
        generateBody(node, marker);
        if (inApiDesc) {
            xmlWriter().writeEndElement(); // </apiDesc>
            inApiDesc = false;
        }
        else if (inSection) {
            xmlWriter().writeEndElement(); // </section>
            inSection = false;
        }
    }
    inDetailedDescription = false;
}

QT_END_NAMESPACE

#ifdef TO_BE_INCLUDED_IN_API_DESC
zzzz
    Text subtitleText;
    if (rawTitle != fullTitle)
        subtitleText << "(" << Atom(Atom::AutoLink, fullTitle) << ")"
                     << Atom(Atom::LineBreak);

    QString shortVersion;
    shortVersion = project + " " + shortVersion + ": ";
    shortVersion = myTree->version();
    if (shortVersion.count(QChar('.')) == 2)
        shortVersion.truncate(shortVersion.lastIndexOf(QChar('.')));
    if (!shortVersion.isEmpty()) {
        if (project == "QSA")
            shortVersion = "QSA " + shortVersion + ": ";
        else
            shortVersion = "Qt " + shortVersion + ": ";
    }

    out() << "  <title>" << shortVersion << protectEnc(title) << "</title>\n";

#if 0    
    out() << QString(postHeader).replace("\\" + COMMAND_VERSION, myTree->version());
    generateBreadCrumbs(title,node,marker);
    out() << QString(postPostHeader).replace("\\" + COMMAND_VERSION, myTree->version());
#endif    
    
    sections = marker->sections(inner, CodeMarker::Summary, CodeMarker::Okay);
    generateTableOfContents(inner,marker,&sections);
    generateTitle(title, subtitleText, SmallSubTitle, inner, marker);

    if (cn && !cn->qmlElement().isEmpty()) {
        generateInstantiatedBy(cn,marker);
    }
    
    generateBrief(inner, marker);
    generateIncludes(inner, marker);
    generateStatus(inner, marker);
    if (cn) {
        generateInherits(cn, marker);
        generateInheritedBy(cn, marker);
    }
    generateThreadSafeness(inner, marker);
    generateSince(inner, marker);

    out() << "<ul>\n";

    QString membersLink = generateListOfAllMemberFile(inner, marker);
    if (!membersLink.isEmpty())
        out() << "<li><xref href=\"" << membersLink << "\">"
              << "List of all members, including inherited members</xref></li>\n";

    QString obsoleteLink = generateLowStatusMemberFile(inner,
                                                       marker,
                                                       CodeMarker::Obsolete);
    if (!obsoleteLink.isEmpty())
        out() << "<li><xref href=\"" << obsoleteLink << "\">"
              << "Obsolete members</xref></li>\n";

    QString compatLink = generateLowStatusMemberFile(inner,
                                                     marker,
                                                     CodeMarker::Compat);
    if (!compatLink.isEmpty())
        out() << "<li><xref href=\"" << compatLink << "\">"
              << "Qt 3 support members</xref></li>\n";

    out() << "</ul>\n";

    bool needOtherSection = false;

    /*
      sections is built above for the call to generateTableOfContents().
     */
    s = sections.begin();
    while (s != sections.end()) {
        if (s->members.isEmpty() && s->reimpMembers.isEmpty()) {
            if (!s->inherited.isEmpty())
                needOtherSection = true;
        }
        else {
            if (!s->members.isEmpty()) {
                out() << "<hr />\n";
                out() << "<a name=\""
                      << registerRef((*s).name.toLower())
                      << "\"></a>\n";
                out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";
                generateSection(s->members, inner, marker, CodeMarker::Summary);
            }
            if (!s->reimpMembers.isEmpty()) {
                QString name = QString("Reimplemented ") + (*s).name;
                out() << "<hr />\n";
                out() << "<a name=\""
                      << registerRef(name.toLower())
                      << "\"></a>\n";
                out() << "<h2>" << protectEnc(name) << "</h2>\n";
                generateSection(s->reimpMembers, inner, marker, CodeMarker::Summary);
            }
            generateSectionInheritedList(*s, inner, marker, true);
        }
        ++s;
    }

    if (needOtherSection) {
        out() << "<h3>Additional Inherited Members</h3>\n";
        s = sections.begin();
        while (s != sections.end()) {
            if (s->members.isEmpty())
                generateSectionInheritedList(*s, inner, marker);
            ++s;
        }
    }

    out() << "<a name=\"" << registerRef("details") << "\"></a>\n";

    if (!inner->doc().isEmpty()) {
        out() << "<hr />\n"
              << "<div class=\"descr\"/>\n" // QTBUG-9504
              << "<h2>" << "Detailed Description" << "</h2>\n";
        generateBody(inner, marker);
        out() << "</div>\n"; // QTBUG-9504
        generateAlsoList(inner, marker);
    }

    sections = marker->sections(inner, CodeMarker::Detailed, CodeMarker::Okay);
    s = sections.begin();
    while (s != sections.end()) {
        out() << "<hr />\n";
        if (!(*s).divClass.isEmpty())
            out() << "<div class=\"" << (*s).divClass << "\"/>\n"; // QTBUG-9504
        out() << "<h2>" << protectEnc((*s).name) << "</h2>\n";

        NodeList::ConstIterator m = (*s).members.begin();
        while (m != (*s).members.end()) {
            if ((*m)->access() != Node::Private) { // ### check necessary?
                if ((*m)->type() != Node::Class)
                    generateDetailedMember(*m, inner, marker);
                else {
                    out() << "<h3> class ";
                    generateFullName(*m, inner, marker);
                    out() << "</h3>";
                    generateBrief(*m, marker, inner);
                }

                QStringList names;
                names << (*m)->name();
                if ((*m)->type() == Node::Function) {
                    const FunctionNode *func = reinterpret_cast<const FunctionNode *>(*m);
                    if (func->metaness() == FunctionNode::Ctor ||
                        func->metaness() == FunctionNode::Dtor ||
                        func->overloadNumber() != 1)
                        names.clear();
                }
                else if ((*m)->type() == Node::Property) {
                    const PropertyNode *prop = reinterpret_cast<const PropertyNode *>(*m);
                    if (!prop->getters().isEmpty() &&
                        !names.contains(prop->getters().first()->name()))
                        names << prop->getters().first()->name();
                    if (!prop->setters().isEmpty())
                        names << prop->setters().first()->name();
                    if (!prop->resetters().isEmpty())
                        names << prop->resetters().first()->name();
                }
                else if ((*m)->type() == Node::Enum) {
                    const EnumNode *enume = reinterpret_cast<const EnumNode*>(*m);
                    if (enume->flagsType())
                        names << enume->flagsType()->name();

                    foreach (const QString &enumName,
                             enume->doc().enumItemNames().toSet() -
                             enume->doc().omitEnumItemNames().toSet())
                        names << plainCode(marker->markedUpEnumValue(enumName,
                                                                     enume));
                }
            }
            ++m;
        }
        if (!(*s).divClass.isEmpty())
            out() << "</div>\n"; // QTBUG-9504
        ++s;
    }
#endif // TO_BE_INCLUDED_IN_API_DESC