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
|
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:qsrc="http://qcad.org/namespaces/src"
xmlns:qc="http://qcad.org/namespaces/xsl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:func="http://exslt.org/functions"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:str="http://exslt.org/strings"
xmlns:com="http://exslt.org/common"
extension-element-prefixes="func date str">
<xsl:include href="shared.xsl"/>
<xsl:output method="text" />
<xsl:param name="mode" />
<xsl:param name="module" />
<xsl:param name="class_export">
<xsl:choose>
<xsl:when test="$module=''">
<xsl:text>QTJSAPI_EXPORT</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="qc:uppercase($module)"/>JSAPI_EXPORT
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
</xsl:param>
<!--
<xsl:param name="qobject">
<xsl:value-of select="boolean(/qsrc:unit/qsrc:class/qsrc:super_list/qsrc:super[@name='QObject'])" />
</xsl:param>
-->
<!--
<xsl:param name="class-name">
<xsl:value-of select="qsrc:unit/qsrc:class/@name" />
</xsl:param>
-->
<xsl:template match="text()" />
<xsl:template match="/">
// Auto generated
<!--
<xsl:choose>
<xsl:when test="$qobject='true'">
// Class inherited from QObject
</xsl:when>
<xsl:otherwise>
// Class not inherited from QObject
</xsl:otherwise>
</xsl:choose>
-->
<xsl:if test="$mode='h'">
#ifndef <xsl:value-of select="qc:include-guard(qsrc:unit/@filename)" />
#define <xsl:value-of select="qc:include-guard(qsrc:unit/@filename)" />
// include header:
//#include "header_h.h"
<xsl:choose>
<xsl:when test="$module!=''">
#include "RJSHelper.h"
#include "../RJSHelper_<xsl:value-of select="$module"/>.h"
</xsl:when>
<xsl:otherwise>
#include "../RJSHelper.h"
</xsl:otherwise>
</xsl:choose>
#include "RJSWrapperObj.h"
</xsl:if>
<xsl:if test="$mode='cpp'">
// include header:
//#include "<xsl:value-of select="qc:replace(qsrc:unit/@filename, '.h', 'wrapper.h')" />"
//#include "header_cpp.h"
</xsl:if>
<xsl:apply-templates />
<xsl:if test="$mode='h'">
#endif
</xsl:if>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="qsrc:unit">
<xsl:apply-templates select="qsrc:class_decl" />
<xsl:apply-templates select="qsrc:class" />
<xsl:apply-templates select="qsrc:namespace" />
</xsl:template>
<xsl:template match="qsrc:class_decl">
<xsl:if test="$mode='h'">
<xsl:choose>
<xsl:when test="starts-with(@name, 'Q')">
#include <<xsl:value-of select="@name" />>
</xsl:when>
<xsl:otherwise>
#include "<xsl:value-of select="@name" />.h"
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="qsrc:class|qsrc:namespace">
<!--
<xsl:variable name="base">
<xsl:choose>
<xsl:when test="$qobject='true'">
<xsl:text>RJSWrapper</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>RJSWrapperObj</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
-->
<xsl:if test="$mode='h'">
#include <QQmlEngine>
<xsl:choose>
<xsl:when test="$module=''">
#include "RJSType.h"
</xsl:when>
<xsl:otherwise>
#include "RJSType_<xsl:value-of select="$module"/>.h"
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="starts-with(@name, 'R')">
#include "<xsl:value-of select="@name" />.h"
</xsl:when>
<xsl:otherwise>
#include <<xsl:value-of select="@name" />>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:variable name="class-name">
<xsl:value-of select="@name" />
</xsl:variable>
<xsl:if test="$mode='h'">
<xsl:for-each select="document('tmp/xmlall.xml')/qsrc:unit/qsrc:class[@name=$class-name]/qsrc:downcasts/qsrc:class">
#include "<xsl:value-of select="@name" />.h"
</xsl:for-each>
</xsl:if>
<xsl:if test="$mode='cpp'">
#include "<xsl:value-of select="qc:lowercase(qc:replace(/qsrc:unit/@filename, '.h', '_wrapper.h'))" />"
</xsl:if>
<xsl:if test="$mode='h'">
<xsl:if test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name] or @inheritable='true'">
// wrapped object is <xsl:value-of select="@name"/>_Base class if new object is created:
#include "<xsl:value-of select="qc:lowercase(qc:replace(/qsrc:unit/@filename, '.h', '_base.h'))" />"
</xsl:if>
</xsl:if>
<xsl:if test="$mode='cpp'">
<xsl:if test="not(ancestor-or-self::qsrc:namespace)">
// list of registered base casters for this wrapper class:
QList<RJSBasecaster_<xsl:value-of select="@name" />*> <xsl:value-of select="@name" />_Wrapper::basecasters_<xsl:value-of select="@name" />;
</xsl:if>
</xsl:if>
<xsl:if test="$mode='h'">
<xsl:if test="not(ancestor-or-self::qsrc:namespace) and (qsrc:function[@static='true'] or qsrc:function/qsrc:variant[@static='true'])">
// singleton class wrapper for static functions:
class <xsl:value-of select="$class_export"/> <xsl:value-of select="@name" />_WrapperSingleton: public QObject {
Q_OBJECT
QML_INTERFACE
// constants:
<xsl:apply-templates select="qsrc:constant" />
// static properties:
<xsl:apply-templates select="qsrc:property[@static='true' and not(@read)]" mode="declaration" />
public:
//Q_INVOKABLE
<xsl:value-of select="@name" />_WrapperSingleton(RJSApi& h)
: QObject(),
handler(h)
<xsl:apply-templates select="qsrc:constant" mode="init" />
{}
<!--
// create / return single instance:
static <xsl:value-of select="@name" />_WrapperSingleton* getInstance(RJSApi& h) {
if (_singleInstance==nullptr) {
_singleInstance = new <xsl:value-of select="@name" />_WrapperSingleton(h);
}
return _singleInstance;
}
-->
<xsl:apply-templates select="qsrc:property[@static='true' and not(@read)]" mode="read-static-property"/>
// static functions:
<!--
<xsl:apply-templates select="qsrc:function[@static='true'] | qsrc:preproc" />
-->
<xsl:apply-templates select="qsrc:function | qsrc:preproc">
<xsl:with-param name="static" select="true()" />
</xsl:apply-templates>
private:
RJSApi& handler;
//static <xsl:value-of select="@name" />_WrapperSingleton* _singleInstance;
// constants:
<xsl:apply-templates select="qsrc:constant" mode="declare" />
};
</xsl:if>
</xsl:if>
<xsl:if test="not(ancestor-or-self::qsrc:namespace)">
// static functions implementation in singleton wrapper:
<xsl:if test="$mode='cpp'">
<!--
<xsl:apply-templates select="qsrc:function[@static='true'] | qsrc:preproc" />
-->
<xsl:apply-templates select="qsrc:function | qsrc:preproc">
<xsl:with-param name="static" select="true()" />
</xsl:apply-templates>
</xsl:if>
</xsl:if>
<xsl:if test="$mode='h'">
<!--
QObject base class needs to be fist in list:
-->
<!--
<xsl:choose>
<xsl:when test="$qobject='true'">
// QObject based class:
// inherit from class directly:
class <xsl:value-of select="@name" />_Wrapper : public <xsl:value-of select="@name" />, public <xsl:value-of select="$base" /> {
</xsl:when>
<xsl:otherwise>
// Wrapped class is not derrived from QObject,
// add QObject to wrapper and encapsulate object as member variable:
class <xsl:value-of select="@name" />_Wrapper : public <xsl:value-of select="$base" /> {
</xsl:otherwise>
</xsl:choose>
-->
// wrapper class for <xsl:value-of select="@name" />
class <xsl:value-of select="$class_export"/> <xsl:value-of select="@name" />_Wrapper : public RJSWrapperObj {
<!--
<xsl:if test="$base='RJSWrapper'">
-->
Q_OBJECT
QML_INTERFACE
<!--
</xsl:if>
-->
<!--
<xsl:if test="qsrc:constructor"
-->
<xsl:apply-templates select="qsrc:property[@read]" mode="declaration" />
<!--
</xsl:if>
-->
private:
// disable copy constructor:
<xsl:value-of select="@name" />_Wrapper(const <xsl:value-of select="@name" />_Wrapper&);
public:
// initialization of <xsl:value-of select="@name" />:
static void init(RJSApi& handler);
<xsl:variable name="classname">
<xsl:value-of select="@name" />
</xsl:variable>
<xsl:if test="not(ancestor-or-self::qsrc:namespace)">
static <xsl:value-of select="@name" />* castToBase(void* vp, /*RJSType ID*/ int t) {
<!--
switch (t) {
-->
<!-- cast to base class (only for Qt module), in other modules this is handled through hooks below -->
<xsl:if test="$module=''">
// check if pointer points to derrived type:
<xsl:for-each select="document('tmp/xmlall.xml')/qsrc:unit/qsrc:class/qsrc:super_list/qsrc:super[@name=$classname]">
if (t==RJSType_<xsl:value-of select="../../@name" />::getIdStatic()) {
return (<xsl:value-of select="$classname" />*)(<xsl:value-of select="../../@name" />*)vp;
}
<!--
case RJSType::<xsl:value-of select="../../@name" />_Type:
return (<xsl:value-of select="$classname" />*)(<xsl:value-of select="../../@name" />*)vp;
-->
</xsl:for-each>
</xsl:if>
<xsl:for-each select="document('tmp/xmlall.xml')/qsrc:unit/qsrc:class[@name=$classname]/qsrc:downcasts/qsrc:class">
if (t==RJSType_<xsl:value-of select="@type" />::getIdStatic()) {
return (<xsl:value-of select="$classname" />*)(<xsl:value-of select="@name" />*)vp;
}
<!--
case <xsl:value-of select="@type" />:
return (<xsl:value-of select="$classname" />*)(<xsl:value-of select="@name" />*)vp;
-->
</xsl:for-each>
// hook for modules to cast from other types to base <xsl:value-of select="@name" />:
for (int i=0; i<basecasters_<xsl:value-of select="@name" />.length(); i++) {
RJSBasecaster_<xsl:value-of select="@name" />* basecaster = basecasters_<xsl:value-of select="@name" />[i];
<xsl:value-of select="@name" />* ret = basecaster->castToBase(t, vp);
if (ret!=nullptr) {
return ret;
}
}
// object is a pointer to base class <xsl:value-of select="@name" />:
if (t==RJSType_<xsl:value-of select="@name" />::getIdStatic()) {
return (<xsl:value-of select="@name" />*)vp;
}
qWarning() << "<xsl:value-of select="@name" />_Wrapper::castToBase: type not found: " << RJSHelper::getTypeName(t);
return nullptr;
<!--
default:
return nullptr;
}
-->
}
static <xsl:value-of select="@name" />* getWrappedBase(RJSWrapper* wrapper) {
int t = wrapper->getWrappedType();
void* vp = wrapper->getWrappedVoid();
if (vp==nullptr) {
//qWarning() << "getWrapped_<xsl:value-of select="@name" />*: wrapper wraps NULL";
}
<xsl:value-of select="@name" />* ret = castToBase(vp, t);
if (ret==nullptr && vp!=nullptr) {
qWarning() << "<xsl:value-of select="@name" />*_Wrapper::getWrappedBase: extracted type " << t << "from wrapper is NULL";
}
return ret;
}
</xsl:if>
<xsl:if test="qsrc:enum">
// enums:
<xsl:apply-templates select="qsrc:enum" />
</xsl:if>
</xsl:if>
<xsl:if test="$mode='cpp'">
void <xsl:value-of select="@name" />_Wrapper::init(RJSApi& handler) {
<!--
<xsl:if test="$base='RJSWrapper'">
-->
//qmlRegisterType<<xsl:value-of select="@name" />_Wrapper>("org.qcad", 1, 0, "<xsl:value-of select="@name" />_Wrapper");
qmlRegisterInterface<<xsl:value-of select="@name" />_Wrapper>("<xsl:value-of select="@name" />_Wrapper", 1);
<!--
</xsl:if>
-->
QJSEngine* engine = handler.getEngine();
<xsl:choose>
<xsl:when test="not(ancestor-or-self::qsrc:namespace)">
// make type scriptable for JS files:
QJSValue global = engine->globalObject();
RJSType_<xsl:value-of select="@name" />* t = new RJSType_<xsl:value-of select="@name" />();
global.setProperty("RJSType_<xsl:value-of select="@name" />", engine->newQObject(t));
// initialize ID for this type:
RJSType_<xsl:value-of select="@name" />::getIdStatic();
<!--
QJSValue mot = engine->newQMetaObject(&RJSType_<xsl:value-of select="@name" />::staticMetaObject);
engine->globalObject().setProperty("RJSType_<xsl:value-of select="@name" />", mot);
-->
</xsl:when>
<xsl:otherwise>
// type is namespace, no scriptable type (RJSType_<xsl:value-of select="@name" />)
</xsl:otherwise>
</xsl:choose>
// wrapper:
QJSValue mo = engine->newQMetaObject(&<xsl:value-of select="@name" />_Wrapper::staticMetaObject);
engine->globalObject().setProperty("<xsl:value-of select="@name" />_Wrapper", mo);
<!--
<xsl:if test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name]">
-->
// JS base class:
//QJSValue mob = engine->newQMetaObject(&<xsl:value-of select="@name" />_BaseJs::staticMetaObject);
//engine->globalObject().setProperty("<xsl:value-of select="@name" />_BaseJs", mob);
<!--
</xsl:if>
-->
<xsl:if test="not(ancestor-or-self::qsrc:namespace) and (qsrc:function[@static='true'] or qsrc:function/qsrc:variant[@static='true'])">
// singleton wrapper:
QJSValue mos = engine->newQMetaObject(&<xsl:value-of select="@name" />_WrapperSingleton::staticMetaObject);
engine->globalObject().setProperty("<xsl:value-of select="@name" />_WrapperSingleton", mos);
// create instance of singleton wrapper for static functions:
<!--
<xsl:value-of select="@name" />_WrapperSingleton * s = <xsl:value-of select="@name" />_WrapperSingleton::getInstance(handler);
-->
<xsl:value-of select="@name" />_WrapperSingleton * s = new <xsl:value-of select="@name" />_WrapperSingleton(handler);
engine->globalObject().setProperty("<xsl:value-of select="@name" />_WrapperSingletonInstance", engine->newQObject(s));
QJSEngine::setObjectOwnership(s, QJSEngine::CppOwnership);
</xsl:if>
<!--
QString fileName = "<xsl:value-of select="qc:lowercase(ancestor::qsrc:unit/@filename)" />.js";
-->
QString fileName = ":generator/js/<xsl:value-of select="@name" />.js";
QFile scriptFile(fileName);
if (!scriptFile.open(QIODevice::ReadOnly)) {
qWarning() << "JS script wrapper file not found:" << fileName;
return;
}
QTextStream stream(&scriptFile);
QString contents = stream.readAll();
scriptFile.close();
qDebug() << "Evaluating file: " << fileName;
QJSValue result = engine->evaluate(contents, fileName);
if (result.isError()) {
qWarning()
<< "Uncaught exception at line"
<< result.property("lineNumber").toInt()
<< ":" << result.toString();
}
}
</xsl:if>
<xsl:if test="not(ancestor-or-self::qsrc:namespace)">
/*
// special constructor used as prototype:
<xsl:choose>
<xsl:when test="$mode='h'">
<!--
<xsl:if test="$qobject='false'">
-->
Q_INVOKABLE
<xsl:value-of select="@name" />_Wrapper(QJSEngine* e);
<!--
</xsl:if>
-->
</xsl:when>
<xsl:otherwise>
<!--
<xsl:if test="$qobject='false'">
-->
<xsl:value-of select="@name" />_Wrapper::<xsl:value-of select="@name" />_Wrapper(QJSEngine* e) : wrapped(nullptr), wrappedCreated(false) {
//setObjectName("<xsl:value-of select="@name" />_Wrapper");
setEngine(e);
// signal forwarding:
//initConnections();
}
<!--
</xsl:if>
-->
</xsl:otherwise>
</xsl:choose>
*/
<!--
<xsl:if test="qsrc:constructor">
-->
// special constructor to wrap existing object:
<xsl:choose>
<xsl:when test="$mode='h'">
<!--
<xsl:if test="$qobject='false'">
-->
//Q_INVOKABLE
<xsl:value-of select="@name" />_Wrapper(RJSApi& h, <xsl:value-of select="@name" />* o, bool wrappedCreated);
<!--
</xsl:if>
-->
</xsl:when>
<xsl:otherwise>
<!--
<xsl:if test="$qobject='false'">
-->
<xsl:value-of select="@name" />_Wrapper::<xsl:value-of select="@name" />_Wrapper(RJSApi& h, <xsl:value-of select="@name" />* o, bool wrappedCreated) : RJSWrapperObj(h), wrapped(o), wrappedCreated(wrappedCreated) {
//RDebug::incCounter(QString("<xsl:value-of select="@name" />_Wrapper_") + handler.getEngine()->objectName());
//RDebug::incCounter(QString("<xsl:value-of select="@name" />_Wrapper"));
//setObjectName("<xsl:value-of select="@name" />_Wrapper");
//setHandler(h);
// signal forwarding:
initConnections();
}
<!--
</xsl:if>
-->
</xsl:otherwise>
</xsl:choose>
<xsl:if test="@sharedpointer">
// special constructor to wrap existing object from shared pointer:
<xsl:choose>
<xsl:when test="$mode='h'">
//Q_INVOKABLE
<xsl:value-of select="@name" />_Wrapper(RJSApi& h, QSharedPointer<<xsl:value-of select="@name" />> o);
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name" />_Wrapper::<xsl:value-of select="@name" />_Wrapper(RJSApi& h, QSharedPointer<<xsl:value-of select="@name" />> o) : RJSWrapperObj(h), wrapped(nullptr), spWrapped(o), wrappedCreated(false) {
//RDebug::incCounter(QString("<xsl:value-of select="@name" />_Wrapper_") + handler.getEngine()->objectName());
//RDebug::incCounter(QString("<xsl:value-of select="@name" />_Wrapper"));
//setObjectName("<xsl:value-of select="@name" />_Wrapper");
//setHandler(h);
// signal forwarding:
initConnections();
}
</xsl:otherwise>
</xsl:choose>
</xsl:if>
// destructor:
<xsl:choose>
<xsl:when test="$mode='h'">
virtual ~<xsl:value-of select="@name" />_Wrapper();
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name" />_Wrapper::~<xsl:value-of select="@name" />_Wrapper() {
//RDebug::decCounter(QString("<xsl:value-of select="@name" />_Wrapper_") + handler.getEngine()->objectName());
//RDebug::decCounter(QString("<xsl:value-of select="@name" />_Wrapper"));
//qDebug() << "<xsl:value-of select="@name" />_Wrapper::~<xsl:value-of select="@name" />_Wrapper";
// tell script handler that this wrapper no longer exists:
handler.unregisterWrapper(*this);
<!--
<xsl:if test="$qobject='false'">
-->
if (wrappedCreated) {
<xsl:choose>
<xsl:when test="qc:is-non-copyable(@name)='true' or @nodestructor='true'">
// never delete wrapped object (non-copyable, CPP ownership or private destructor)
//qDebug() << "NOT deleting instance of <xsl:value-of select="@name" />";
</xsl:when>
<xsl:otherwise>
// delete wrapped object (copyable, JS ownership)
//qDebug() << "deleting instance of <xsl:value-of select="@name" />";
delete wrapped;
</xsl:otherwise>
</xsl:choose>
}
<!--
</xsl:if>
-->
}
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<!--
</xsl:if>
-->
<!--
<xsl:if test="not(ancestor-or-self::qsrc:namespace) and qsrc:constructor">
-->
<xsl:if test="not(ancestor-or-self::qsrc:namespace)">
// initialization of signal forwarding
<xsl:choose>
<xsl:when test="$mode='h'">
void initConnections();
</xsl:when>
<xsl:otherwise>
void <xsl:value-of select="@name" />_Wrapper::initConnections() {
//setObjectName("<xsl:value-of select="@name" />_Wrapper");
// tell script handler that this wrapper needs to be deleted if the engine is deleted:
handler.registerWrapper(*this);
<xsl:choose>
<xsl:when test="ancestor-or-self::qsrc:class/qsrc:super_list/qsrc:super[@name='QObject']">
// wrapped object is a QObject and not a wrapper for a null pointer:
// wrapper is managed by the QObject as child:
if (hasWrapped()) {
QJSEngine::setObjectOwnership(this, QJSEngine::CppOwnership);
}
</xsl:when>
<xsl:otherwise>
// wrapped object is not a QObject:
// wrapper is managed by script engine:
//QJSEngine::setObjectOwnership(this, QJSEngine::CppOwnership);
</xsl:otherwise>
</xsl:choose>
if (hasWrapped()) {
<xsl:choose>
<xsl:when test="ancestor-or-self::qsrc:class/qsrc:super_list/qsrc:super[@name='QObject']">
// set parent of wrapper to wrapped:
// wrapper can be looked up for object:
QVariant vThis = QVariant::fromValue(this);
getWrapped()->setProperty("__wrapper__", vThis);
// make sure wrapper is deleted when object is deleted:
// make sure wrapper stays alive as long as the wrapped stays alive::
QObject::setParent(getWrapped());
</xsl:when>
</xsl:choose>
// set up signal forwarding:
<xsl:apply-templates select="qsrc:function/qsrc:variant[@signal='true' and @access='public']" mode="signalconnections" />
<xsl:if test="ancestor-or-self::qsrc:class/qsrc:super_list/qsrc:super[@name='QObject']">
/*
connect(
getWrapped(),
SIGNAL(destroyed(QObject*)),
&handler,
SLOT(slotDestroyed(QObject*))
);
*/
</xsl:if>
}
}
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<!--
<xsl:choose>
<xsl:when test="$qobject='false'">
// constructors:
<xsl:apply-templates select="qsrc:constructor | qsrc:preproc" />
// non-static functions:
<xsl:apply-templates select="qsrc:function[not(@static)] | qsrc:preproc" />
< ! - - 20210702
<xsl:apply-templates select="qsrc:function[not(@static)] | qsrc:preproc" mode="public" />
- - >
</xsl:when>
<xsl:otherwise>
// constructors:
<xsl:apply-templates select="qsrc:constructor | qsrc:preproc" />
// public non-static functions:
< ! - -
<xsl:apply-templates select="qsrc:function/qsrc:variant[@access='public' and not(../@static)] | qsrc:preproc" />
- - >
<xsl:apply-templates select="qsrc:function[not(@static)] | qsrc:preproc" mode="public" />
</xsl:otherwise>
</xsl:choose>
-->
// constructors:
<!--
<xsl:if test="qsrc:constructor">
-->
<xsl:apply-templates select="qsrc:constructor | qsrc:preproc" />
// non-static functions:
<!--
<xsl:apply-templates select="qsrc:function[not(@static='true')] | qsrc:preproc" />
-->
<xsl:apply-templates select="qsrc:function | qsrc:preproc">
<xsl:with-param name="static" select="false()" />
</xsl:apply-templates>
<!--
<xsl:apply-templates select="qsrc:property" mode="setter_getter" />
-->
<xsl:if test="$mode='h'">
<xsl:if test="not(ancestor-or-self::qsrc:namespace)">
<xsl:apply-templates select="qsrc:property[@static='true' and @read]" mode="forward-static"/>
<!--
<xsl:if test="@shell='false'">
-->
<xsl:if test="qc:is-non-copyable(@name)='false' and ancestor-or-self::qsrc:class[@sharedpointer='true']">
/*
// get wrapped object as clone:
// used to create a QSharedPointer on the fly when needed for conversion:
public:
<xsl:value-of select="@name" />* getWrappedClone() {
<xsl:value-of select="@name" />* w = getWrapped();
if (w==nullptr) {
qWarning() << "<xsl:value-of select="$class-name" />::getWrappedClone: wrapped is NULL";
handler.trace();
return nullptr;
}
// return cloned object:
return new <xsl:value-of select="@name" />(*w);
}
*/
</xsl:if>
<!--
</xsl:if>
-->
<!--
<xsl:if test="qc:is-non-copyable(@name)='true' and not(@nodestructor='true')">
-->
<xsl:if test="not(@nodestructor='true')">
// destroy function for non-copyable objects:
Q_INVOKABLE void destr() {
if (wrapped!=nullptr) {
<!--
<xsl:choose>
<xsl:when test="not(@nodestructor)">
-->
delete wrapped;
<!--
</xsl:when>
<xsl:otherwise>
qWarning() << "trying to delete object without destructor";
</xsl:otherwise>
</xsl:choose>
-->
wrapped = nullptr;
}
<xsl:if test="ancestor-or-self::qsrc:class/@sharedpointer">
if (!spWrapped.isNull()) {
spWrapped = nullptr;
}
</xsl:if>
}
</xsl:if>
//public:
// set engine:
//Q_INVOKABLE void setHandler(RJSApi* h) {
// RJSWrapperObj::setHandler(h);
//}
</xsl:if>
</xsl:if>
<!--
</xsl:if>
-->
// member functions for static properties, forward to static function
// protected overwritten functions / events and their public invokable counterparts:
<!--
<xsl:if test="not(ancestor-or-self::qsrc:namespace) and qsrc:constructor">
-->
<xsl:if test="not(ancestor-or-self::qsrc:namespace)">
<xsl:if test="$mode='h'">
<!--
<xsl:if test="$qobject='false'">
-->
public:
// get type of wrapped object:
Q_INVOKABLE
virtual /*RJSType ID*/ int getWrappedType() const {
return RJSType_<xsl:value-of select="@name" />::getIdStatic();
}
// return true if wrapped object is owned by C++ (not deleted):
Q_INVOKABLE
virtual bool isCppOwnership() const {
<xsl:choose>
<xsl:when test="qc:is-non-copyable(@name)='true'">
return true;
</xsl:when>
<xsl:otherwise>
return false;
</xsl:otherwise>
</xsl:choose>
}
// get wrapped object:
<xsl:value-of select="@name" />* getWrapped() {
if (wrapped!=nullptr) {
return wrapped;
}
<xsl:if test="ancestor-or-self::qsrc:class/@sharedpointer">
else if (!spWrapped.isNull()) {
return spWrapped.data();
}
</xsl:if>
return nullptr;
}
// get wrapped object (const):
<xsl:value-of select="@name" />* getWrapped() const {
if (wrapped!=nullptr) {
return wrapped;
}
<xsl:if test="ancestor-or-self::qsrc:class/@sharedpointer">
else if (!spWrapped.isNull()) {
return spWrapped.data();
}
</xsl:if>
return nullptr;
}
// get wrapped object as void*:
virtual void* getWrappedVoid() {
if (wrapped!=nullptr) {
return wrapped;
}
<xsl:if test="ancestor-or-self::qsrc:class/@sharedpointer">
else if (!spWrapped.isNull()) {
return spWrapped.data();
}
</xsl:if>
return nullptr;
}
<xsl:if test="ancestor-or-self::qsrc:class/@sharedpointer">
// get wrapped object as QSharedPointer:
virtual QSharedPointer<<xsl:value-of select="@name" />> getWrappedSp() {
if (!spWrapped.isNull()) {
return spWrapped;
}
if (wrapped!=nullptr) {
qWarning() << "wrapper does not wrap a QSharedPointer<<xsl:value-of select="@name" />> but a regular pointer";
return QSharedPointer<<xsl:value-of select="@name" />>();
}
return QSharedPointer<<xsl:value-of select="@name" />>();
}
bool hasWrappedSp() const {
return !spWrapped.isNull() && spWrapped.data()!=nullptr;
}
</xsl:if>
<xsl:if test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name] or @inheritable='true'">
// get wrapped base object or nullptr:
<xsl:value-of select="$class-name" />_Base* getWrappedBase() {
<xsl:value-of select="$class-name" />* w = getWrapped();
return dynamic_cast<<xsl:value-of select="$class-name" />_Base*>(w);
}
<xsl:value-of select="$class-name" />_Base* getWrappedBase() const {
<xsl:value-of select="$class-name" />* w = getWrapped();
return dynamic_cast<<xsl:value-of select="$class-name" />_Base*>(w);
}
</xsl:if>
bool hasWrapped() const {
return wrapped!=nullptr
<xsl:if test="ancestor-or-self::qsrc:class/@sharedpointer">
|| (!spWrapped.isNull() && spWrapped.data()!=nullptr)
</xsl:if>
;
}
Q_INVOKABLE
bool isNullWrapper() const {
return !hasWrapped();
}
Q_INVOKABLE
unsigned long long int getAddress() const {
if (wrapped!=nullptr) {
return (unsigned long long int)wrapped;
}
<xsl:if test="ancestor-or-self::qsrc:class/@sharedpointer">
if (!spWrapped.isNull() && spWrapped.data()!=nullptr) {
return (unsigned long long int)spWrapped.data();
}
</xsl:if>
return (unsigned long long int)0;
}
<xsl:if test="ancestor-or-self::qsrc:class/@equalsfunction">
Q_INVOKABLE
bool equals(const QJSValue& other) const {
<xsl:value-of select="@name" /> otherObj = RJSHelper<xsl:value-of select="qc:get-helper-postfix(@name)"/>::js2cpp_<xsl:value-of select="@name" />(handler, other);
<xsl:value-of select="@name" />* thisObj = getWrapped();
if (thisObj==nullptr) {
return false;
}
return *thisObj==otherObj;
}
</xsl:if>
//public slots:
//void slotDestroyed(QObject* obj) {
// qDebug() << "destroying QObject:" << (long int)obj;
//}
<!--
<xsl:if test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name]">
-->
<xsl:if test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name] or @inheritable='true'">
//void setRecFlag(bool on) const {
// <xsl:value-of select="$class-name" />_Base* wb = getWrappedBase();
// if (wb) {
// wb->setRecFlag(on);
// }
//}
</xsl:if>
private:
// wrapped object:
<xsl:value-of select="@name" />* wrapped;
<xsl:if test="ancestor-or-self::qsrc:class/@sharedpointer">
// wrapped object as shared pointer:
QSharedPointer<<xsl:value-of select="@name" />> spWrapped;
</xsl:if>
bool wrappedCreated;
<!--
</xsl:if>
-->
</xsl:if>
</xsl:if>
<!--
<xsl:apply-templates select="qsrc:constructor" />
<xsl:apply-templates select="qsrc:function" />
-->
<!--
<xsl:if test="not(ancestor-or-self::qsrc:namespace) and (qsrc:function[@static='true'] or qsrc:function/qsrc:variant[@static='true'])">
<xsl:if test="$mode='cpp'">
<xsl:value-of select="@name" />_WrapperSingleton* <xsl:value-of select="@name" />_WrapperSingleton::_singleInstance = nullptr;
</xsl:if>
</xsl:if>
-->
<xsl:if test="$mode='h'">
<xsl:if test="not(ancestor-or-self::qsrc:namespace)">
private:
// list of registered base casters for this wrapper class:
static QList<RJSBasecaster_<xsl:value-of select="@name" />*> basecasters_<xsl:value-of select="@name" />;
public:
static void registerBasecaster_<xsl:value-of select="@name" />(RJSBasecaster_<xsl:value-of select="@name" />* bc) {
basecasters_<xsl:value-of select="@name" />.append(bc);
}
</xsl:if>
};
Q_DECLARE_METATYPE(<xsl:value-of select="@name" />_Wrapper*)
Q_DECLARE_INTERFACE(<xsl:value-of select="@name" />_Wrapper, "org.qcad.<xsl:value-of select="@name" />_Wrapper")
</xsl:if>
</xsl:template>
<xsl:template match="qsrc:preproc">
<xsl:text>
</xsl:text>
<xsl:value-of select="@plain" />
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="qsrc:constant" mode="declare">
<xsl:value-of select="@type" /><xsl:text> </xsl:text><xsl:value-of select="@name" />;
</xsl:template>
<xsl:template match="qsrc:constant" mode="init">
<xsl:if test="position() = 1">,</xsl:if>
<xsl:value-of select="@name" />(<xsl:value-of select="@value" />)
<xsl:if test="position() < last()">,</xsl:if>
</xsl:template>
<xsl:template match="qsrc:constant">
Q_PROPERTY(
<xsl:value-of select="@type" />
<xsl:text>
</xsl:text>
<xsl:value-of select="@name" />
MEMBER
<xsl:value-of select="@name" />
)
</xsl:template>
<xsl:template match="qsrc:constructor">
<!--
<xsl:variable name="class" >
<xsl:copy-of select="ancestor::qsrc:class[1]" />
<!- -
<xsl:value-of select="ancestor::qsrc:class/@name" />
- ->
</xsl:variable>
<xsl:variable name="sorted_variants">
<!- -
<xsl:for-each select="com:node-set($class)/qsrc:constructor/qsrc:variant">
- ->
<xsl:for-each select="qsrc:variant">
<xsl:sort select="count(qsrc:parameters/qsrc:parameter)" order="descending"/>
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:variable>
<!- -
<xsl:message>Function name: <xsl:copy-of select="com:node-set($sorted_variants)" /></xsl:message>
- ->
<xsl:for-each select="com:node-set($sorted_variants)">
// applying variant with <xsl:value-of select="count(qsrc:parameters/qsrc:parameter)" /> parameters for constructor
<xsl:apply-templates select="qsrc:variant">
<xsl:with-param name="class" select="com:node-set($class)" />
<xsl:with-param name="function" select="ancestor::qsrc:function[1]" />
</xsl:apply-templates>
</xsl:for-each>
-->
<xsl:apply-templates select="qsrc:variant[1] | qsrc:preproc">
<!--
<xsl:sort select="count(qsrc:parameters/qsrc:parameter)" order="descending" />
-->
<xsl:with-param name="constructor" select="true" />
</xsl:apply-templates>
</xsl:template>
<!--
<xsl:variable name="base">
<xsl:choose>
<xsl:when test="ancestor::qsrc:class/qsrc:super_list/qsrc:super[@name='QObject']">
<xsl:text>RJSWrapper</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>RJSWrapperObj</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$mode='h'">
<xsl:choose>
<xsl:when test="$base='RJSWrapperObj'">
// constructor
Q_INVOKABLE <xsl:value-of select="../@name" />_Wrapper(
<!- - constructor parameters - ->
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
) {
wrapped = new <xsl:value-of select="../@name" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
);
}
</xsl:when>
<xsl:otherwise>
// constructor
Q_INVOKABLE <xsl:value-of select="../@name" />_Wrapper(
<!- - constructor parameters - ->
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
) : <xsl:value-of select="../@name" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
) {
}
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
-->
<!--
Signal connections for signal forwarding from JS to C++ wrapper.
-->
<!--
<xsl:template match="qsrc:function" mode="signalconnections">
<xsl:apply-templates select="qsrc:variant" mode="signalconnections" />
</xsl:template>
-->
<xsl:template match="qsrc:variant" mode="signalconnections">
connect(
getWrapped(),
SIGNAL(<xsl:value-of select="../@name" />(<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="signalconnections"/>)),
this,
SLOT(<xsl:value-of select="../@name" />Emitter(<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="signalconnections"/>))
);
</xsl:template>
<xsl:template match="qsrc:parameter" mode="signalconnections">
<xsl:if test="@const='true'">const </xsl:if>
<xsl:value-of select="@type" /><xsl:value-of select="@modifier" />
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<!--
<xsl:template match="qsrc:function" mode="public">
// function <xsl:value-of select="@name" />
< ! - -
apply variant template in order of parameter count (most parameters first).
we only apply the template with the most paramters
- - >
<xsl:apply-templates select="qsrc:variant[@access='public'][1]">
< ! - -
<xsl:sort select="count(qsrc:parameters/qsrc:parameter)" order="descending" />
- - >
</xsl:apply-templates>
</xsl:template>
-->
<xsl:template match="qsrc:function">
<xsl:param name="static" />
<!--
<xsl:message><xsl:value-of select="@name"/></xsl:message>
-->
<!--
only apply for first variant (with most parameters)
the variant template will also implement the other variants
-->
<xsl:choose>
<xsl:when test="$static">
<xsl:if test="$mode='h' or not(@declare-only)">
<xsl:apply-templates select="qsrc:variant[@static='true' or ../@static='true'][1] | qsrc:preproc">
<xsl:with-param name="static" select="true()" />
</xsl:apply-templates>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$mode='h' or not(@declare-only)">
<xsl:apply-templates select="qsrc:variant[not(@static='true' or ../@static='true')][1] | qsrc:preproc">
<xsl:with-param name="static" select="false()" />
</xsl:apply-templates>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
<xsl:template match="qsrc:variant">
-->
<xsl:template match="qsrc:variant">
<xsl:param name="static" />
<!--
don't expose protected and overridable functions for abstract classes (no construtor):
-->
<xsl:if test="ancestor::qsrc:class/qsrc:constructor or not(@access='protected' or (@virtual='true' and @overridable='true'))">
<xsl:variable name="class-name">
<xsl:value-of select="ancestor::qsrc:class[1]/@name" />
</xsl:variable>
<xsl:variable name="wrapper-class-name">
<xsl:choose>
<xsl:when test="ancestor::qsrc:function/@static='true' or @static='true'">
<xsl:value-of select="concat($class-name, '_WrapperSingleton')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($class-name, '_Wrapper')" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="num-param">
<xsl:value-of select="@count" />
<!--
<xsl:value-of select="count(qsrc:parameters/qsrc:parameter)" />
-->
</xsl:variable>
<xsl:variable name="num-prev-param">
<xsl:choose>
<xsl:when test="preceding-sibling::*">
<xsl:value-of select="preceding-sibling::*[1]/@count" />
<!--
<xsl:value-of select="count(preceding-sibling::*[1]/qsrc:parameters/qsrc:parameter)" />
-->
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="-1" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!--
<xsl:param name="function" />
-->
<!--
Class: <xsl:value-of select="com:node-set($class)/@name" />
Function: <xsl:value-of select="com:node-set($function)/@name" />
Class: <xsl:value-of select="ancestor::qsrc:class[1]/@name" />
Function: <xsl:value-of select="../@name" />
// Class: <xsl:value-of select="com:node-set($class)/@name" />
// Function: <xsl:value-of select="$function" />
-->
// Class: <xsl:value-of select="$class-name" />
// Function: <xsl:value-of select="../@name" />
// Source: <xsl:value-of select="../@source" />
// Static: <xsl:value-of select="@static or ../@static" />
// Parameters: <xsl:value-of select="$num-param"/>
// preceding Parameters: <xsl:value-of select="$num-prev-param"/>
<xsl:text> </xsl:text>
<!--
only one function / constructor per parameter count:
-->
<xsl:if test="$num-param != $num-prev-param">
<!--
<xsl:if test="position()=1">
-->
<!--
<xsl:variable name="specifier">
<xsl:choose>
<xsl:when test="@virtual='true' and $mode='h'">
<xsl:value-of select="'virtual '" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
-->
<!--
<xsl:variable name="wrapped-return-type">
<xsl:value-of select="qc:get-wrapper-return-type(@return-type)" />
</xsl:variable>
-->
<!--
<xsl:if test="$mode='h'">
<xsl:choose>
<xsl:when test="@signal='true'">
Q_SIGNALS:
</xsl:when>
<xsl:otherwise>
public:
</xsl:otherwise>
</xsl:choose>
</xsl:if>
-->
<xsl:choose>
<!-- signal -->
<xsl:when test="@signal='true'">
<xsl:choose>
<xsl:when test="$mode='h'">
<!-- h -->
// signal forwarded from wrapped class:
signals:
void <xsl:value-of select="ancestor::qsrc:function/@name" />(
<!--
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
-->
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="qjsvalue_signal" />
);
// called when signal is emitted from wrapped class:
public slots:
void <xsl:value-of select="ancestor::qsrc:function/@name" />Emitter(
<!--
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="qjsvalue" />
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="towrapper" />
-->
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
);
</xsl:when>
<xsl:otherwise>
<!-- cpp -->
// signal emitter: called when signal is emitted from wrapped object:
void
<xsl:value-of select="$wrapper-class-name" />
<xsl:text>::</xsl:text>
<xsl:value-of select="ancestor::qsrc:function/@name" />Emitter(
<!--
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="qjsvalue" />
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="towrapper" />
-->
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
) {
// convert cpp parameters to js:
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="tojs" />
emit <xsl:value-of select="ancestor::qsrc:function/@name" />(
<!--
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="names" />
-->
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="qjsvaluenames_js" />
);
}
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- end signal -->
<!-- invokable function -->
<xsl:otherwise>
<xsl:choose>
<!-- h -->
<xsl:when test="$mode='h'">
public:
Q_INVOKABLE
<!--
<xsl:if test="$mode='h' and @static='true'">
static
</xsl:if>
-->
<!--
<xsl:value-of select="concat($specifier, $wrapped-return-type, ' ', @name)" />(
-->
<xsl:choose>
<xsl:when test="ancestor::qsrc:function">
<!-- function -->
QJSValue
<xsl:choose>
<xsl:when test="@access='protected'">
<!-- expose protected functions with Super to allow calling from JS: -->
// function is protected, this function can be called from JS implementation to call implementation of super class:
<xsl:value-of select="ancestor::qsrc:function/@name" />Super
</xsl:when>
<xsl:when test="@virtual='true' and @overridable='true'">
<!-- expose virtual functions with Super to allow calling from JS: -->
// function is public, virtual and overridable, this function can be called from JS implementation to call implementation of super class:
<xsl:value-of select="ancestor::qsrc:function/@name" />Super
</xsl:when>
<xsl:otherwise>
<!--
<xsl:value-of select="ancestor::qsrc:function/@name" />
-->
<xsl:choose>
<xsl:when test="ancestor::qsrc:function/@cppname">
// special function name for JS wrapper:
<xsl:value-of select="ancestor::qsrc:function/@cppname" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ancestor::qsrc:function/@name" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- constructor -->
<xsl:value-of select="$class-name" />_Wrapper
</xsl:otherwise>
</xsl:choose>
(
<!--
<xsl:value-of select="count(qsrc:parameters/qsrc:parameter)" />
-->
<!--
<xsl:for-each select="">
</xsl:for-each>
-->
<xsl:if test="ancestor::qsrc:constructor">
// RJSApi:
QObject* h
<xsl:if test="count(qsrc:parameters/qsrc:parameter)>0">
,
</xsl:if>
</xsl:if>
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="qjsvalue" />
<!--
// for overridable function, add parameter to call JS
// (true when called from <xsl:value-of select="$class-name" />.js:)
<xsl:if test="@virtual='true' and @overridable='true'">
<xsl:if test="count(qsrc:parameters/qsrc:parameter)>0">
<xsl:text>,</xsl:text>
</xsl:if>
bool callJs = false
</xsl:if>
-->
)
<xsl:if test="@const='true'">
const
</xsl:if>
;
</xsl:when>
<!-- cpp -->
<xsl:otherwise>
<xsl:if test="ancestor::qsrc:function">
QJSValue
</xsl:if>
<xsl:value-of select="$wrapper-class-name" />
<xsl:text>::</xsl:text>
<xsl:choose>
<xsl:when test="ancestor::qsrc:function">
<xsl:choose>
<xsl:when test="@access='protected'">
<!-- expose protected function with Super to allow calling from JS: -->
// function is protected, this function can be called from JS implementation to call implementation of super class:
<xsl:value-of select="ancestor::qsrc:function/@name" />Super
</xsl:when>
<xsl:when test="@virtual='true' and @overridable='true'">
<!-- expose virtual functions with Super to allow calling from JS: -->
// function is public, virtual and overridable, this function can be called from JS implementation to call implementation of super class:
<xsl:value-of select="ancestor::qsrc:function/@name" />Super
</xsl:when>
<xsl:otherwise>
<!--
<xsl:value-of select="ancestor::qsrc:function/@name" />
-->
<xsl:choose>
<xsl:when test="ancestor::qsrc:function/@cppname">
// special function name for JS wrapper:
<xsl:value-of select="ancestor::qsrc:function/@cppname" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ancestor::qsrc:function/@name" />
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$class-name" />_Wrapper
</xsl:otherwise>
</xsl:choose>
(
<xsl:if test="ancestor::qsrc:constructor">
// RJSApi:
QObject* h
<xsl:if test="count(qsrc:parameters/qsrc:parameter)>0">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:if>
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="qjsvalue" />
<!--
// for overridable function, add parameter to call JS
// (true when called from <xsl:value-of select="$class-name" />.js:)
<xsl:if test="@virtual='true' and @overridable='true'">
<xsl:if test="count(qsrc:parameters/qsrc:parameter)>0">
<xsl:text>,</xsl:text>
</xsl:if>
bool callJs
</xsl:if>
-->
)
<xsl:if test="ancestor::qsrc:constructor">
: RJSWrapperObj(*(RJSApi*)h)
</xsl:if>
<xsl:if test="@const='true'">
const
</xsl:if>
<!--
<xsl:if test="ancestor::qsrc:constructor">
<xsl:if test="$qobject='true'">
// calling base constructor:
: <xsl:value-of select="$class-name" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="tocppcontr" />
)
</xsl:if>
</xsl:if>
-->
{
<xsl:if test="ancestor::qsrc:constructor">
//RDebug::incCounter(QString("<xsl:value-of select="$class-name" />_Wrapper_") + handler.getEngine()->objectName());
//RDebug::incCounter(QString("<xsl:value-of select="$class-name" />_Wrapper"));
</xsl:if>
<!--
qDebug() << "<xsl:value-of select="$wrapper-class-name" />::<xsl:choose>
<xsl:when test="ancestor::qsrc:function"><xsl:value-of select="ancestor::qsrc:function/@name" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$class-name" />_Wrapper</xsl:otherwise>
</xsl:choose>";
-->
<!--
<xsl:variable name="count">
<xsl:value-of select="@count"/>
</xsl:variable>
-->
<!--
For each variant with any parameter count (from most parameters to least):
-->
<!--
<xsl:for-each select="ancestor::*/qsrc:variant[@count=$count]">
-->
<xsl:choose>
<xsl:when test="$static">
<xsl:apply-templates select="ancestor::*/qsrc:variant[@static='true' or ../@static='true']" mode="if" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="ancestor::*/qsrc:variant[not(@static='true' or ../@static='true')]" mode="if" />
</xsl:otherwise>
</xsl:choose>
<!--
<xsl:for-each select="ancestor::*/qsrc:variant[@static=$static or ../@static=$static]">
</xsl:for-each>
-->
<xsl:if test="ancestor::qsrc:function">
qWarning() << "no matching function variant found for <xsl:value-of select="ancestor::qsrc:function/@name" />";
handler.trace();
return QJSValue();
</xsl:if>
<xsl:if test="ancestor::qsrc:constructor">
<xsl:if test="count(qsrc:parameters/qsrc:parameter)>0">
// no constructor without arguments defined
// allow constructor for prototype objects without args:
if (
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="checkundef" />
) {
wrapped = nullptr;
wrappedCreated = false;
return;
}
</xsl:if>
qWarning() << "no matching constructor variant found for <xsl:value-of select="$class-name" />";
wrapped = nullptr;
wrappedCreated = false;
handler.trace();
</xsl:if>
}
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match="qsrc:variant" mode="if">
<xsl:variable name="class-name">
<xsl:value-of select="ancestor::qsrc:class[1]/@name" />
</xsl:variable>
<xsl:variable name="static">
<xsl:value-of select="@static" />
</xsl:variable>
<!-- 20220621: no protected methods
<xsl:if test="@access='protected'">
-->
<xsl:choose>
<xsl:when test="qsrc:parameters/qsrc:parameter">
// check parameter types:
if (
<xsl:for-each select="qsrc:parameters/qsrc:parameter">
<xsl:apply-templates select="." mode="checktype">
<xsl:with-param name="pos" select="position()"/>
<xsl:with-param name="last" select="position() = last()"/>
</xsl:apply-templates>
</xsl:for-each>
<xsl:if test="../qsrc:variant[@static=$static][1]">
<!--
<xsl:message>calling with params index: <xsl:value-of select="count(qsrc:parameters/qsrc:parameter) + 1"/>, total: <xsl:value-of select="../qsrc:variant[@static=$static][1]/@count"/></xsl:message>
-->
<xsl:call-template name="param-undefined-check">
<xsl:with-param name="index" select="count(qsrc:parameters/qsrc:parameter) + 1"/>
<xsl:with-param name="total" select="../qsrc:variant[@static=$static][1]/@count"/>
</xsl:call-template>
</xsl:if>
<!--
<xsl:variable name="count">
<xsl:value-of select-"@count"/>
</xsl:variable>
<xsl:for-each select="(//node())[(../qsrc:variant[1]/@count - $count) >= position()]">
a<xsl:value-of select="position() + $count"/>.isUndefined() &&
</xsl:for-each>
-->
) {
</xsl:when>
<xsl:otherwise>
{
</xsl:otherwise>
</xsl:choose>
<xsl:if test="qsrc:parameters/qsrc:parameter">
// prepare parameters:
</xsl:if>
<!--
<xsl:if test="$qobject='false' or ancestor::qsrc:function">
-->
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="tocpp" />
<!--
</xsl:if>
-->
<!--
<xsl:if test="@return-type!='void'">
// return value:
<xsl:choose>
<xsl:when test="qc:ends-with(@return-type, '&')">
<xsl:choose>
<xsl:when test="qc:is-non-copyable(@return-type)='false'">
// C++ function returns reference (non-copyable):
<xsl:value-of select="qc:replace(@return-type, '&', '*')" /> res = nullptr;
</xsl:when>
<xsl:otherwise>
// C++ function returns reference (copyable):
<xsl:value-of select="qc:replace(@return-type, '&', '')" />* res;
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@return-type" /> res;
</xsl:otherwise>
</xsl:choose>
</xsl:if>
-->
// call function:
<xsl:choose>
<xsl:when test="ancestor::qsrc:function">
<xsl:if test="not(../@static='true') and not(@static='true')">
if (!hasWrapped()) {
qWarning() << "wrapped is NULL";
handler.trace();
return QJSValue();
}
<!--
<xsl:if test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name]">
-->
<xsl:if test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name] or ancestor::qsrc:class[1]/@inheritable='true'">
//setRecFlag(true);
</xsl:if>
</xsl:if>
<!--
function or overridable function:
e.g.
int res = wrapped->fun(v1, v2);
or
int res = RClass::fun(v1, v2);
-->
<xsl:choose>
<!--
<xsl:when test="$qobject='true' or ../@static='true'">
-->
<xsl:when test="../@static='true' or @static='true'">
<!--
static function or function in class derrived from QObject:
call base class function
e.g. QCoreApplication::
-->
// static member function:
// call base class static function:
<!-- function name: -->
<xsl:variable name="functionname">
<xsl:choose>
<xsl:when test="../@call">
<xsl:value-of select="../@call" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../@name" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="@return-type!='void'">
<xsl:choose>
<xsl:when test="qc:ends-with(@return-type, '&')">
// return type is reference:
// use pointer instead 1:
<xsl:value-of select="qc:replace(@return-type, '&', '')" />* res =
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@return-type" /> res =
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="qc:ends-with(@return-type, '&')">
<xsl:text>&</xsl:text>
</xsl:if>
<!--
MyClass:: prefix when calling static members
@non-member can be used to disable this prefix (e.g. operator<):
-->
<xsl:choose>
<xsl:when test="not(../@non-member='true')">
// call static member function:
<xsl:choose>
<xsl:when test="../@source">
<xsl:value-of select="../@source" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ancestor::qsrc:class/@name" />
</xsl:otherwise>
</xsl:choose>
<xsl:text>::</xsl:text>
</xsl:when>
<xsl:otherwise>
// call non-member function:
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="$functionname" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="cppnames" />
);
</xsl:when>
<xsl:otherwise>
// non-static member function:
// call function of wrapped object:
<!-- function name: -->
<xsl:variable name="functionname">
<xsl:choose>
<xsl:when test="../@call">
<xsl:value-of select="../@call" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../@name" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="functionpostfix">
<xsl:choose>
<xsl:when test="@access='protected'">
<!-- protected member, exposed as public function -->
<xsl:text>Public</xsl:text>
</xsl:when>
<xsl:otherwise>
<!--
public member, overridable, not pure virtual
call base class implementation
or
call JS implementation
-->
<xsl:if test="@overridable='true' and not(@pure='true')">
<xsl:text>Sup</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="usebase">
<xsl:choose>
<xsl:when test="$functionpostfix!='' and (document('inheritable_class.xml')/inheritable-class/class[@name=$class-name] or ancestor::qsrc:class[1]/@inheritable='true')">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$usebase='true'">
// call function of <xsl:value-of select="ancestor::qsrc:class/@name" />_Base class as
// function has postfix inheritable class, overridable function):
<xsl:value-of select="ancestor::qsrc:class/@name" />_Base* wb = getWrappedBase();
if (wb==nullptr) {
qWarning() << "<xsl:value-of select="ancestor::qsrc:class/@name" />::<xsl:value-of select="$functionname" />: using base but wrapper is not of type of base class";
handler.trace();
return QJSValue();
}
<xsl:if test="@return-type!='void'">
<xsl:choose>
<xsl:when test="qc:ends-with(@return-type, '&')">
// return type is reference:
// use pointer instead 2:
<xsl:value-of select="qc:replace(@return-type, '&', '')" />* res;
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@return-type" /> res;
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<!--
<xsl:if test="qc:ends-with(@return-type, '&')">
&
</xsl:if>
-->
<xsl:choose>
<xsl:when test="$functionpostfix='Sup'">
// this is the wrapper that created the object
// call the base class implementation as this function was
// called from the JS implementation of the same function to call
// the base class implementation
if (wrappedCreated) {
<xsl:if test="@return-type!='void'">
<xsl:text>res =</xsl:text>
</xsl:if>
<xsl:if test="qc:ends-with(@return-type, '&')">
<xsl:text>&</xsl:text>
</xsl:if>
wb-><xsl:value-of select="$functionname" /><xsl:value-of select="$functionpostfix" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="cppnames" />
);
}
// this is a wrapper that was created for an existing object
// call the JS implementation as this function was
// called from another JS function
else {
<xsl:if test="@return-type!='void'">
<xsl:text>res =</xsl:text>
</xsl:if>
<xsl:if test="qc:ends-with(@return-type, '&')">
<xsl:text>&</xsl:text>
</xsl:if>
wb-><xsl:value-of select="$functionname" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="cppnames" />
);
}
</xsl:when>
<xsl:otherwise>
<xsl:if test="@return-type!='void'">
<xsl:text>res =</xsl:text>
</xsl:if>
wb-><xsl:value-of select="$functionname" /><xsl:value-of select="$functionpostfix" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="cppnames" />
);
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
// call function of C++ class:
<xsl:value-of select="ancestor::qsrc:class/@name" />* w = getWrapped();
<xsl:if test="@return-type!='void'">
<xsl:choose>
<xsl:when test="qc:ends-with(@return-type, '&')">
// return type is reference:
// use pointer instead 3:
<xsl:value-of select="qc:replace(@return-type, '&', '')" />* res =
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@return-type" /> res =
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<!--
<xsl:if test="qc:ends-with(@return-type, '&')">
&
</xsl:if>
-->
<xsl:if test="qc:ends-with(@return-type, '&')">
<xsl:text>&</xsl:text>
</xsl:if>
w-><xsl:value-of select="$functionname" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="cppnames" />
);
</xsl:otherwise>
</xsl:choose>
<xsl:if test="not(../@static='true') and not(@static='true')">
<xsl:if test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name] or ancestor::qsrc:class[1]/@inheritable='true'">
//setRecFlag(false);
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<!--
<xsl:value-of select="qc:get-wrapper-return-type(@return-type)" /> ret = new <xsl:value-of select="qc:get-wrapper-type(@return-type)" />(new <xsl:value-of select="@return-type" />(res));
return ret;
-->
<xsl:choose>
<xsl:when test="@return-type!='void'">
// return type: <xsl:value-of select="@return-type" />
return <xsl:value-of select="qc:type-to-function-cpp2js(@return-type)" />(
handler,
// non-copyable: <xsl:value-of select="qc:is-non-copyable(@return-type)='true'" />
<xsl:choose>
<xsl:when test="qc:ends-with(@return-type, '*') and qc:is-non-copyable(@return-type)='false'">
// return type is pointer, type is copyable:
// call pointer implementation of <xsl:value-of select="qc:type-to-function-cpp2js(@return-type)" />:
res
</xsl:when>
<xsl:when test="qc:ends-with(@return-type, '&') and qc:is-non-copyable(@return-type)='false'">
// return type is reference, type is copyable:
// convert pointer back to reference:
*res
</xsl:when>
<xsl:when test="qc:ends-with(@return-type, '&') and qc:is-non-copyable(@return-type)='true'">
// return type is reference, type is not copyable:
// convert using pointer:
res
</xsl:when>
<!--
<xsl:when test="qc:ends-with(@return-type, '&') and qc:is-non-copyable(@return-type)='false'">
// return type is reference, type is copyable:
*res
</xsl:when>
-->
<xsl:otherwise>
res
</xsl:otherwise>
</xsl:choose>
);
<!--
return cpp2js(engine, res);
-->
</xsl:when>
<xsl:otherwise>
return QJSValue();
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- constructor -->
// construct wrapper:
<xsl:choose>
<xsl:when test="document('inheritable_class.xml')/inheritable-class/class[@name=$class-name] or ancestor::qsrc:class[1]/@inheritable='true'">
wrapped = new <xsl:value-of select="$class-name" />_Base(
handler
<xsl:if test="qsrc:parameters/qsrc:parameter">
,
</xsl:if>
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="cppnames" />
);
wrappedCreated = true;
// set handler for wrapped base object:
//((<xsl:value-of select="$class-name" />_Base*)wrapped)->setHandler(handler);
// store self to call into JS:
((<xsl:value-of select="$class-name" />_Base*)wrapped)->self = handler.getSelf();
</xsl:when>
<xsl:otherwise>
wrapped = new <xsl:value-of select="$class-name" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="cppnames" />
);
wrappedCreated = true;
</xsl:otherwise>
</xsl:choose>
// signal forwarding:
// TODO
//connect(wrapped, SIGNAL(triggered(bool)), this, SLOT(triggeredEmitter(bool)));
initConnections();
return;
</xsl:otherwise>
</xsl:choose>
}
</xsl:template>
<xsl:template name="param-undefined-check">
<xsl:param name="index" />
<xsl:param name="total" />
<!--
<xsl:message>index:<xsl:value-of select="$index"/></xsl:message>
<xsl:message>total:<xsl:value-of select="$total"/></xsl:message>
-->
<xsl:if test="not($index > $total)">
<!--
<xsl:message>index not greater than total</xsl:message>
-->
<xsl:text>&&</xsl:text>
a<xsl:value-of select="$index"/>.isUndefined()
<xsl:if test="not($index >= $total)">
<xsl:call-template name="param-undefined-check">
<xsl:with-param name="index" select="$index + 1" />
<xsl:with-param name="total" select="$total" />
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match="qsrc:parameter" mode="checktype">
<xsl:param name="pos" />
<xsl:param name="last" />
<xsl:value-of select="qc:type-to-function-is(@type, @modifier)" />(handler, a<xsl:value-of select="$pos"/>
<!-- allow null / undefined if value has default value or is a pointer: -->
<xsl:if test="@default or @modifier='*'">
, true
</xsl:if>
)
<!--
(
<xsl:choose>
<xsl:when test="@type='QString'">
a<xsl:value-of select="$pos"/>.isString()
</xsl:when>
<xsl:when test="@type='QStringList'">
a<xsl:value-of select="$pos"/>.isArray()
</xsl:when>
<xsl:when test="contains(@type, 'QList')">
a<xsl:value-of select="$pos"/>.isArray()
</xsl:when>
<xsl:when test="@type='QAction'">
a<xsl:value-of select="$pos"/>.isObject()
</xsl:when>
<xsl:when test="@type='int'">
a<xsl:value-of select="$pos"/>.isNumber()
</xsl:when>
<xsl:when test="contains(@type, '::')">
a<xsl:value-of select="$pos"/>.isNumber()
</xsl:when>
<xsl:otherwise>
!a<xsl:value-of select="$pos"/>.isUndefined()
</xsl:otherwise>
</xsl:choose>
<xsl:if test="@default">
< ! - - value has default value, undefined is also acceptable - - >
|| a<xsl:value-of select="$pos"/>.isUndefined()
</xsl:if>
)
-->
<xsl:if test="not($last)"> && </xsl:if>
</xsl:template>
<xsl:template match="qsrc:function" mode="protected">
<xsl:apply-templates select="qsrc:variant" mode="protected" />
</xsl:template>
<xsl:template match="qsrc:function/qsrc:variant" mode="protected">
<xsl:variable name="specifier">
<xsl:choose>
<xsl:when test="@virtual='true' and $mode='h'">
<xsl:value-of select="'virtual '" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$mode='h'">
protected:
<xsl:value-of select="concat($specifier, @return-type, ' ', ../@name)" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
);
</xsl:if>
<xsl:if test="$mode='h'">
public:
// this can be called from JS to call the parent implementation (e.g. Parent.prototype.call(this, ...)):
Q_INVOKABLE <xsl:value-of select="concat($specifier, @return-type, ' ', ../@name)" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="towrapper" />
);
</xsl:if>
<xsl:if test="$mode='cpp'">
<xsl:value-of select="concat($specifier, @return-type, ' ', ancestor::qsrc:class/@name, '_Wrapper::', ../@name)" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="towrapper" />
) {
<xsl:choose>
<!-- inherited from QObject: call base class function -->
<xsl:when test="ancestor::qsrc:class/qsrc:super_list/qsrc:super[@name='QObject']">
//qDebug() << "calling: <xsl:value-of select="ancestor::qsrc:class/@name" />::<xsl:value-of select="../@name" />";
<xsl:value-of select="ancestor::qsrc:class/@name" />::<xsl:value-of select="../@name" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="towrappercall" />
);
</xsl:when>
<!-- not inherited from QObject: call wrapper function -->
<xsl:otherwise>
//qDebug() << "calling: wrapped-><xsl:value-of select="../@name" />";
getWrapped()-><xsl:value-of select="../@name" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="towrappercall" />
);
</xsl:otherwise>
</xsl:choose>
}
</xsl:if>
<xsl:if test="$mode='cpp'">
<!-- 20210702
// overwritable protected function:
// can be re-implemented in JS:
// calls JS function if implemented:
<xsl:value-of select="concat($specifier, @return-type, ' ', ancestor::qsrc:class/@name, '_Wrapper::', ../@name)" />(
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" />
) {
QJSValue self = getSelf();
QJSValue f = self.prototype().property("<xsl:value-of select="../@name" />");
if (f.isCallable()) {
qDebug() << "calling JS version of <xsl:value-of select="../@name" />";
qDebug() << " self: " << self.property("name").toString();
QJSValueList args;
<xsl:apply-templates select="qsrc:parameters/qsrc:parameter" mode="qjsvaluelist" />
< ! - -
<xsl:value-of select="parent::qsrc:class/@name" />_Wrapper* ew = new <xsl:value-of select="parent::qsrc:class/@name" />_Wrapper(event);
QJSValue v = engine->toScriptValue<<xsl:value-of select="parent::qsrc:class/@name" />_Wrapper*>(ew);
f.callWithInstance(self, QJSValueList() << v);
- - >
f.callWithInstance(self, args);
}
-->}
</xsl:if>
</xsl:template>
<!--
Used to fill args with QJSValues for each parameter.
-->
<!--
<xsl:template match="qsrc:parameter" mode="qjsvaluelist">
<xsl:value-of select="@type" />_Wrapper* ew = new <xsl:value-of select="@type" />_Wrapper(event);
QJSValue v = engine->toScriptValue<<xsl:value-of select="@type" />_Wrapper*>(ew);
args.append(v);
</xsl:template>
-->
<!--
Parameter as list of values with original C++ types.
e.g. bool myparam, int arg, ...
-->
<xsl:template match="qsrc:parameter">
<!-- e.g. const QWidget* -->
<xsl:if test="@const='true'">
<xsl:value-of select="'const'" />
<xsl:value-of select="' '" />
</xsl:if>
<xsl:value-of select="@type" />
<xsl:value-of select="@modifier" />
<xsl:value-of select="' '" />
<xsl:apply-templates select="." mode="paramname">
<xsl:with-param name="pos" select="position()" />
</xsl:apply-templates>
<!-- e.g. parent = nullptr -->
<xsl:if test="@name!=''">
<!-- default value for argument (header only) -->
<xsl:if test="$mode='h'">
<xsl:if test="@default!=''">
<xsl:value-of select="'='" />
<xsl:value-of select="@default" />
</xsl:if>
</xsl:if>
</xsl:if>
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<!--
Parameter name either from XML or a1, a2, ...
-->
<xsl:template match="qsrc:parameter" mode="paramname">
<xsl:param name="pos" />
<xsl:choose>
<xsl:when test="@name!=''">
<xsl:value-of select="@name" />
</xsl:when>
<xsl:otherwise>
<!--
<xsl:value-of select="concat('a', position())" />
-->
<xsl:value-of select="concat('a', $pos)" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Parameter as list of if conditions for undefined.
e.g. a1.isUndefined() && a2.isUndefined() ...
-->
<xsl:template match="qsrc:parameter" mode="checkundef">
<xsl:value-of select="concat('a', position())" />.isUndefined()
<xsl:if test="position() < last()"> && </xsl:if>
</xsl:template>
<!--
Parameter as list of QJSValue.
e.g. const QJSValue& a1, const QJSValue& a2, ...
-->
<xsl:template match="qsrc:parameter" mode="qjsvalue">
const QJSValue&
<!--
<xsl:choose>
<xsl:when test="@name!=''">
<xsl:value-of select="@name" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('a', position())" />
</xsl:otherwise>
</xsl:choose>
-->
<xsl:value-of select="concat('a', position())" />
<xsl:if test="$mode='h'">
<!--
<xsl:if test="@default!=''">
-->
<!-- always add default value to prevent segfault with wrong calls from JS: -->
= QJSValue()
<!--
</xsl:if>
-->
</xsl:if>
<!--
< ! - - e.g. const QWidget* - - >
<xsl:if test="@const='true'">
<xsl:value-of select="'const'" />
<xsl:value-of select="' '" />
</xsl:if>
<xsl:value-of select="@type" />
<xsl:value-of select="@modifier" />
<xsl:value-of select="' '" />
< ! - - e.g. parent = nullptr - - >
<xsl:choose>
<xsl:when test="@name!=''">
<xsl:value-of select="@name" />
< ! - - default value for argument (header only) - - >
<xsl:if test="$mode='h'">
<xsl:if test="@default!=''">
<xsl:value-of select="'='" />
<xsl:value-of select="@default" />
</xsl:if>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('a', position())" />
</xsl:otherwise>
</xsl:choose>
-->
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<!--
Parameter as list of QJSValue for signal declarations.
e.g. const QJSValue& a1, const QJSValue& a2, ...
-->
<xsl:template match="qsrc:parameter" mode="qjsvalue_signal">
const QJSValue&
<xsl:value-of select="concat('a', position())" />
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<!--
Parameter names as list.
e.g. a1, a2, a3, ...
-->
<xsl:template match="qsrc:parameter" mode="qjsvaluenames">
<xsl:value-of select="concat('a', position())" />
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<!--
Parameter names as list with postfix
e.g. a1_js,a2_js, a3_js, ...
-->
<xsl:template match="qsrc:parameter" mode="qjsvaluenames_js">
<xsl:value-of select="concat('a', position(), '_js')" />
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<xsl:template match="qsrc:parameter" mode="towrapper">
<!-- e.g. const QWidgetWrapper* -->
<xsl:if test="@const='true'">
<xsl:value-of select="'const'" />
<xsl:value-of select="' '" />
</xsl:if>
<xsl:choose>
<xsl:when test="starts-with(@type, 'Q')">
<xsl:value-of select="@type" />_Wrapper
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@type" />
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="@modifier" />
<xsl:value-of select="' '" />
<!-- parameter name or a1, a2, ... -->
<xsl:choose>
<xsl:when test="@name!=''">
<xsl:value-of select="@name" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('a', position())" />
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<xsl:template match="qsrc:parameter" mode="towrappercall">
<!-- parameter name or a1, a2, ... -->
<xsl:choose>
<xsl:when test="@name!=''">
<xsl:value-of select="@name" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('a', position())" />
</xsl:otherwise>
</xsl:choose>
<xsl:if test="starts-with(@type, 'Q')">
<xsl:text>->getWrapped()</xsl:text>
</xsl:if>
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<xsl:template match="qsrc:parameter" mode="names">
<xsl:choose>
<xsl:when test="@name!=''">
<xsl:value-of select="@name" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('a', position())" />
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<xsl:template match="qsrc:parameter" mode="cppnames">
<xsl:choose>
<xsl:when test="qc:is-non-copyable(@type)='true'">
<xsl:if test="@modifier='&'">
<xsl:text>*</xsl:text>
</xsl:if>
<xsl:value-of select="concat('a', position())" />_cpp
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('a', position())" />_cpp
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
<!--
Converts the parameter from QSValue to native type (int, RVector, ...).
-->
<xsl:template match="qsrc:parameter" mode="tocpp">
// convert js parameter to cpp: <xsl:value-of select="@name" /> (<xsl:value-of select="@type" />)
<xsl:text>
</xsl:text>
<xsl:variable name="type">
<xsl:value-of select="@type" />
</xsl:variable>
<xsl:variable name="name">
<!--
<xsl:choose>
<xsl:when test="@name!=''">
<xsl:value-of select="@name" />
</xsl:when>
<xsl:otherwise>
-->
<xsl:value-of select="concat('a', position())" />
<!--
</xsl:otherwise>
</xsl:choose>
-->
</xsl:variable>
<xsl:choose>
<xsl:when test="@type='char' and @modifier='*'">
// char pointer string:
QByteArray <xsl:value-of select="$name" />_ba = <xsl:value-of select="qc:type-to-function-js2cpp(@type, @modifier)" />(handler, <xsl:value-of select="$name" />).toLocal8Bit();
const char*<xsl:text> </xsl:text><xsl:value-of select="$name" />_cpp = <xsl:value-of select="$name" />_ba.constData();
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<!--
<xsl:when test="@type='QString'">
<xsl:value-of select="@type" />
</xsl:when>
-->
<xsl:when test="@modifier='*'">
// pointer:
<xsl:value-of select="@type" />*
</xsl:when>
<!--
<xsl:when test="@modifier='&' and qc:is-non-copyable(@type)">
<xsl:if test="@const='true'">
<xsl:text>const </xsl:text>
</xsl:if>
<xsl:value-of select="@type" />*
</xsl:when>
-->
<xsl:when test="qc:is-non-copyable(@type)='true'">
// non copyable:
<!--
<xsl:if test="@const='true'">
<xsl:text>const </xsl:text>
</xsl:if>
-->
<xsl:value-of select="@type" />*
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@type" />
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text><xsl:value-of select="$name" />_cpp;
<xsl:choose>
<xsl:when test="@default">
if (<xsl:value-of select="$name" />.isUndefined()) {
<xsl:value-of select="$name" />_cpp = <xsl:value-of select="@default" />;
}
else {
<xsl:value-of select="$name" />_cpp = <xsl:value-of select="qc:type-to-function-js2cpp(@type, @modifier)" />(handler, <xsl:value-of select="$name" />);
}
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$name" />_cpp = <xsl:value-of select="qc:type-to-function-js2cpp(@type, @modifier)" />(handler, <xsl:value-of select="$name" />);
</xsl:otherwise>
</xsl:choose>
<!--
<xsl:if test="qc:is-non-copyable(@type)='true' and @const='true'">
const_cast<<xsl:value-of select="@type" />*>(
</xsl:if>
-->
<!--
<xsl:if test="qc:is-non-copyable(@type)='true' and @const='true'">
)
</xsl:if>
-->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Converts the parameter from c++ to QJSValue.
-->
<xsl:template match="qsrc:parameter" mode="tojs">
// parameter: <xsl:value-of select="@name" /> (<xsl:value-of select="@type" />)
<xsl:text>
</xsl:text>
<xsl:variable name="name">
<xsl:value-of select="concat('a', position())" />
</xsl:variable>
QJSValue <xsl:value-of select="$name" />_js = <xsl:value-of select="qc:type-to-function-cpp2js(@type)" />(
handler,
<xsl:apply-templates select="." mode="paramname">
<xsl:with-param name="pos" select="position()" />
</xsl:apply-templates>
);
</xsl:template>
<!--
Converts the list of parameters from QSValue to native types for use in calling the base constructor:
RJSHelper::js2cpp_xy(engine, a1), ...
-->
<!--
<xsl:template match="qsrc:parameter" mode="tocppcontr">
<xsl:variable name="name">
<xsl:value-of select="concat('a', position())" />
</xsl:variable>
<xsl:value-of select="qc:type-to-function-js2cpp(@type, @modifier)" />(engine, <xsl:value-of select="$name" />)
<xsl:if test="position() < last()">, </xsl:if>
</xsl:template>
-->
<xsl:template match="qsrc:enum">
enum <xsl:value-of select="@name"/> {
<xsl:apply-templates />
};
Q_ENUM(<xsl:value-of select="@name"/>)
</xsl:template>
<xsl:template match="qsrc:enum/qsrc:key">
<xsl:value-of select="./text()"/> = <xsl:value-of select="(ancestor::qsrc:class|ancestor::qsrc:namespace)/@name"/>::<xsl:value-of select="./text()"/>
<xsl:if test="position() < last()">,</xsl:if>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="qsrc:property" mode="declaration">
Q_PROPERTY(
<!--
<xsl:value-of select="@type"/>
-->
QJSValue
<xsl:text> </xsl:text>
<xsl:value-of select="@name"/>
<xsl:choose>
<xsl:when test="@read">
<xsl:text> READ </xsl:text> <xsl:value-of select="@read"/>
</xsl:when>
<xsl:otherwise>
// auto generated read function for public static properties:
<xsl:text> READ </xsl:text> get<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="@write">
<xsl:text> WRITE </xsl:text> <xsl:value-of select="@write"/>
</xsl:if>
)
</xsl:template>
<xsl:template match="qsrc:property" mode="read-static-property">
// auto generated read function for public static property <xsl:value-of select="@name"/>:
Q_INVOKABLE QJSValue get<xsl:value-of select="@name"/>() {
return <xsl:value-of select="qc:type-to-function-cpp2js(@type)"/>(handler, <xsl:value-of select="(ancestor::qsrc:class|ancestor::qsrc:namespace)/@name"/>::<xsl:value-of select="@name"/>);
}
</xsl:template>
<xsl:template match="qsrc:property" mode="forward-static">
// read static property <xsl:value-of select="@name"/>:
Q_INVOKABLE QJSValue <xsl:value-of select="@read"/>() {
return handler.getEngine()->globalObject().property("<xsl:value-of select="(ancestor::qsrc:class|ancestor::qsrc:namespace)/@name"/>_WrapperSingleton").property("<xsl:value-of select="@read"/>").call();
<!--
return <xsl:value-of select="(ancestor::qsrc:class|ancestor::qsrc:namespace)/@name"/>_WrapperSingleton::getInstance(handler)-><xsl:value-of select="@read"/>();
-->
}
<xsl:if test="@write">
// write static property <xsl:value-of select="@name"/>:
Q_INVOKABLE QJSValue <xsl:value-of select="@write"/>(const QJSValue& arg) {
return handler.getEngine()->globalObject().property("<xsl:value-of select="(ancestor::qsrc:class|ancestor::qsrc:namespace)/@name"/>_WrapperSingleton").property("<xsl:value-of select="@write"/>").call(QJSValueList() << arg);
<!--
return <xsl:value-of select="(ancestor::qsrc:class|ancestor::qsrc:namespace)/@name"/>_WrapperSingleton::getInstance(handler)-><xsl:value-of select="@write"/>(arg);
-->
}
</xsl:if>
</xsl:template>
<!--
<xsl:template match="qsrc:property" mode="setter_getter">
<xsl:choose>
<xsl:when test="$mode='h'">
<xsl:if test="@read">
<xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@read"/>Property();
</xsl:if>
<xsl:if test="@write">
void <xsl:value-of select="@write"/>Property(const <xsl:value-of select="@type"/>& v);
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@read">
<xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="ancestor::qsrc:class/@name"/>_Wrapper::<xsl:value-of select="@read"/>Property() {
return getWrapped()-><xsl:value-of select="@read"/>();
}
</xsl:if>
<xsl:if test="@write">
void <xsl:value-of select="ancestor::qsrc:class/@name"/>_Wrapper::<xsl:value-of select="@write"/>Property(const <xsl:value-of select="@type"/>& v) {
return getWrapped()-><xsl:value-of select="@write"/>(v);
}
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
-->
<func:function name="qc:include-guard">
<xsl:param name="filename" />
<func:result>
<xsl:value-of select="concat(qc:uppercase(translate($filename, '.', '_')), '_WRAPPER')" />
</func:result>
</func:function>
<func:function name="qc:get-wrapper-return-type">
<xsl:param name="type" />
<func:result>
<xsl:choose>
<xsl:when test="$type='RVector'">
<xsl:value-of select="'RVectorWrapper*'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$type" />
</xsl:otherwise>
</xsl:choose>
</func:result>
</func:function>
<func:function name="qc:get-wrapper-type">
<xsl:param name="type" />
<func:result>
<xsl:choose>
<xsl:when test="$type='RVector'">
<xsl:value-of select="'RVectorWrapper'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$type" />
</xsl:otherwise>
</xsl:choose>
</func:result>
</func:function>
<!--
Return function to check for given type.
e.g. RJSHelper::is_bool
-->
<func:function name="qc:type-to-function-is">
<xsl:param name="type" />
<xsl:param name="modifier" />
<xsl:variable name="itemtype">
<xsl:value-of select="substring-before(substring-after($type, '<'), '>')" />
</xsl:variable>
<xsl:variable name="itemptr">
<xsl:value-of select="contains($itemtype, '*')" />
</xsl:variable>
<func:result>
<xsl:text>RJSHelper</xsl:text><xsl:value-of select="qc:get-helper-postfix($type)"/><xsl:text>::is_</xsl:text>
<xsl:value-of
select="qc:replace(
qc:replace(
qc:replace(
qc:replace(
qc:replace(
qc:replace(
qc:replace(
qc:replace(
$type, '>', ''
), '<', '_'
), '::', '_'
), ',', '_'
), 'const', ''
), '&', ''
), '*', ''
), ' ', ''
)" />
<xsl:if test="@modifier='*' or (qc:is-non-copyable(@type)='true' and @modifier='&') or $itemptr='true'">
<xsl:text>_ptr</xsl:text>
</xsl:if>
</func:result>
</func:function>
<func:function name="qc:strip-pointer">
<xsl:param name="type" />
<func:result>
<xsl:value-of select="qc:replace($type, '*', '')" />
</func:result>
</func:function>
</xsl:stylesheet>
|