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
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef TESTTYPES_H
#define TESTTYPES_H
#include <QtCore/qobject.h>
#include <QtCore/qrect.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qjsonarray.h>
#include <QtGui/qtransform.h>
#include <QtGui/qcolor.h>
#include <QtGui/qvector2d.h>
#include <QtGui/qvector3d.h>
#include <QtGui/qvector4d.h>
#include <QtGui/qquaternion.h>
#include <QtQml/qqml.h>
#include <QtQml/qqmlcomponent.h>
#include <QtQml/qqmlparserstatus.h>
#include <QtQml/qqmlpropertyvaluesource.h>
#include <QtQml/qqmlscriptstring.h>
#include <QtQml/qqmlproperty.h>
#include <private/qqmlcomponentattached_p.h>
#include <private/qqmlcustomparser_p.h>
QVariant myCustomVariantTypeConverter(const QString &data);
class MyInterface
{
public:
MyInterface() : id(913) {}
int id;
};
QT_BEGIN_NAMESPACE
#define MyInterface_iid "org.qt-project.Qt.Test.MyInterface"
Q_DECLARE_INTERFACE(MyInterface, MyInterface_iid);
QT_END_NAMESPACE
QML_DECLARE_INTERFACE(MyInterface);
struct MyCustomVariantType
{
MyCustomVariantType() : a(0) {}
int a;
};
Q_DECLARE_METATYPE(MyCustomVariantType);
class Group : public QObject
{
Q_OBJECT
Q_PROPERTY(int value MEMBER value)
public:
Group(QObject *parent = nullptr) : QObject(parent) {}
int value = 0;
};
struct GroupGadget
{
Q_GADGET
Q_PROPERTY(int value MEMBER value)
public:
friend bool operator==(GroupGadget g1, GroupGadget g2) { return g1.value == g2.value; }
friend bool operator!=(GroupGadget g1, GroupGadget g2) { return !(g1 == g2); }
int value = 0;
};
struct FakeDynamicObject : public QObject
{
Q_OBJECT
Q_PROPERTY(QString value MEMBER value)
public:
FakeDynamicObject() {}
QString value;
};
QT_BEGIN_NAMESPACE
namespace QtPrivate {
// don't do this at home – we override the meta-object which QMetaType collects for
// FakeDynamicObject* properties
template<>
struct MetaObjectForType<FakeDynamicObject *, void>
{
static const QMetaObject *metaObjectFunction(const QMetaTypeInterface *);
};
}
QT_END_NAMESPACE
class UnexposedBase : public QObject
{
Q_OBJECT
Q_PROPERTY(Group *group MEMBER group)
Q_PROPERTY(GroupGadget groupGadget MEMBER groupGadget)
Q_PROPERTY(FakeDynamicObject *dynamic MEMBER dynamic)
public:
UnexposedBase(QObject *parent = nullptr) : QObject(parent)
{
group = new Group(this);
}
Group *group;
GroupGadget groupGadget;
FakeDynamicObject *dynamic = nullptr;
};
class DerivedFromUnexposedBase : public UnexposedBase
{
Q_OBJECT
QML_ELEMENT
};
class MyAttachedObject : public QObject
{
Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(int value2 READ value2 WRITE setValue2)
Q_PROPERTY(int length MEMBER length)
Q_PROPERTY(QString name MEMBER name)
public:
MyAttachedObject(QObject *parent) : QObject(parent), m_value(0), m_value2(0), name("attached") {}
int value() const { return m_value; }
void setValue(int v) { if (m_value != v) { m_value = v; emit valueChanged(); } }
int value2() const { return m_value2; }
void setValue2(int v) { m_value2 = v; }
signals:
void valueChanged();
private:
int m_value;
int m_value2;
int length = 10;
QString name;
};
class SomethingUnknown : public QObject {
Q_OBJECT
};
class SomethingKnown : public SomethingUnknown {
Q_OBJECT
};
class MyQmlObject : public QObject, public MyInterface
{
Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue FINAL)
Q_PROPERTY(QString readOnlyString READ readOnlyString)
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled)
Q_PROPERTY(QRect rect READ rect WRITE setRect)
Q_PROPERTY(QTransform transform READ transform WRITE setTransform) //assumed to be unsupported by QML
Q_PROPERTY(MyInterface *interfaceProperty READ interface WRITE setInterface)
Q_PROPERTY(int onLiteralSignal READ onLiteralSignal WRITE setOnLiteralSignal)
Q_PROPERTY(MyCustomVariantType customType READ customType WRITE setCustomType)
Q_PROPERTY(MyQmlObject *qmlobjectProperty READ qmlobject WRITE setQmlobject)
Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal)
Q_PROPERTY(int nonScriptable READ nonScriptable WRITE setNonScriptable SCRIPTABLE false)
Q_PROPERTY(QJSValue qjsvalue READ qjsvalue WRITE setQJSValue NOTIFY qjsvalueChanged)
Q_PROPERTY(SomethingUnknown* somethingUnknown READ somethingUnknown WRITE setSomethingUnknown NOTIFY somethingUnknownChanged)
Q_INTERFACES(MyInterface)
public:
MyQmlObject();
int value() const { return m_value; }
void setValue(int v) { m_value = v; }
QString readOnlyString() const { return QLatin1String(""); }
bool enabled() const { return false; }
void setEnabled(bool) {}
QRect rect() const { return QRect(); }
void setRect(const QRect&) {}
QTransform transform() const { return QTransform(); }
void setTransform(const QTransform &) {}
MyInterface *interface() const { return m_interface; }
void setInterface(MyInterface *iface) { m_interface = iface; }
static MyAttachedObject *qmlAttachedProperties(QObject *other) {
return new MyAttachedObject(other);
}
Q_CLASSINFO("DefaultMethod", "basicSlot()")
int onLiteralSignal() const { return m_value; }
void setOnLiteralSignal(int v) { m_value = v; }
MyQmlObject *qmlobject() const { return m_qmlobject; }
void setQmlobject(MyQmlObject *o) { m_qmlobject = o; }
MyCustomVariantType customType() const { return m_custom; }
void setCustomType(const MyCustomVariantType &v) { m_custom = v; }
int propertyWithNotify() const { return m_propertyWithNotify; }
void setPropertyWithNotify(int i) { m_propertyWithNotify = i; emit oddlyNamedNotifySignal(); }
int nonScriptable() const { return 0; }
void setNonScriptable(int) {}
QJSValue qjsvalue() const { return m_qjsvalue; }
void setQJSValue(const QJSValue &value) { m_qjsvalue = value; emit qjsvalueChanged(); }
int childAddedEventCount() const { return m_childAddedEventCount; }
SomethingUnknown* somethingUnknown() const { return nullptr; }
void setSomethingUnknown(SomethingUnknown* something) { Q_UNUSED(something); }
public slots:
void basicSlot() { qWarning("MyQmlObject::basicSlot"); }
void basicSlotWithArgs(int v) { qWarning("MyQmlObject::basicSlotWithArgs(%d)", v); }
void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; }
signals:
void basicSignal();
void basicParameterizedSignal(int parameter);
void oddlyNamedNotifySignal();
void signalWithDefaultArg(int parameter = 5);
void qjsvalueChanged();
void somethingUnknownChanged();
protected:
bool event(QEvent *event) override;
private:
friend class tst_qqmllanguage;
int m_value;
MyInterface *m_interface;
MyQmlObject *m_qmlobject;
MyCustomVariantType m_custom;
int m_propertyWithNotify;
QJSValue m_qjsvalue;
int m_childAddedEventCount;
};
QML_DECLARE_TYPE(MyQmlObject)
QML_DECLARE_TYPEINFO(MyQmlObject, QML_HAS_ATTACHED_PROPERTIES)
class MyQmlObjectWithAttachedCounter : public QObject
{
Q_OBJECT
public:
MyQmlObjectWithAttachedCounter(QObject *parent = nullptr) : QObject(parent) { }
static int attachedCount;
static MyAttachedObject *qmlAttachedProperties(QObject *other)
{
++MyQmlObjectWithAttachedCounter::attachedCount;
return new MyAttachedObject(other);
}
};
QML_DECLARE_TYPE(MyQmlObjectWithAttachedCounter)
QML_DECLARE_TYPEINFO(MyQmlObjectWithAttachedCounter, QML_HAS_ATTACHED_PROPERTIES)
class MyGroupedObject : public QObject
{
Q_OBJECT
Q_PROPERTY(QQmlScriptString script READ script WRITE setScript)
Q_PROPERTY(int value READ value WRITE setValue)
public:
QQmlScriptString script() const { return m_script; }
void setScript(const QQmlScriptString &s) { m_script = s; }
int value() const { return m_value; }
void setValue(int v) { m_value = v; }
private:
int m_value;
QQmlScriptString m_script;
};
class MyEnumContainer : public QObject
{
Q_OBJECT
Q_ENUMS(RelatedEnum)
public:
enum RelatedEnum { RelatedInvalid = -1, RelatedValue = 42 };
};
class MyTypeObject : public QObject
{
Q_OBJECT
Q_ENUMS(MyEnum)
Q_ENUMS(MyMirroredEnum)
Q_ENUMS(MyEnumContainer::RelatedEnum)
Q_FLAGS(MyFlags)
Q_PROPERTY(QString id READ id WRITE setId)
Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectPropertyChanged)
Q_PROPERTY(QQmlComponent *componentProperty READ componentProperty WRITE setComponentProperty)
Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty NOTIFY flagPropertyChanged)
Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty NOTIFY enumPropertyChanged)
Q_PROPERTY(MyEnum readOnlyEnumProperty READ readOnlyEnumProperty)
Q_PROPERTY(Qt::TextFormat qtEnumProperty READ qtEnumProperty WRITE setQtEnumProperty NOTIFY qtEnumPropertyChanged)
Q_PROPERTY(MyMirroredEnum mirroredEnumProperty READ mirroredEnumProperty WRITE setMirroredEnumProperty NOTIFY mirroredEnumPropertyChanged)
Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty)
Q_PROPERTY(MyScopedEnum scopedEnum READ scopedEnum WRITE setScopedEnum)
Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringPropertyChanged)
Q_PROPERTY(QByteArray byteArrayProperty READ byteArrayProperty WRITE setByteArrayProperty NOTIFY byteArrayPropertyChanged)
Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty NOTIFY uintPropertyChanged)
Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged)
Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty NOTIFY realPropertyChanged)
Q_PROPERTY(double doubleProperty READ doubleProperty WRITE setDoubleProperty NOTIFY doublePropertyChanged)
Q_PROPERTY(float floatProperty READ floatProperty WRITE setFloatProperty NOTIFY floatPropertyChanged)
Q_PROPERTY(qsizetype qsizetypeProperty READ qsizetypeProperty WRITE setQsizetypeProperty NOTIFY qsizetypePropertyChanged)
Q_PROPERTY(QColor colorProperty READ colorProperty WRITE setColorProperty NOTIFY colorPropertyChanged)
Q_PROPERTY(QDate dateProperty READ dateProperty WRITE setDateProperty NOTIFY datePropertyChanged)
Q_PROPERTY(QTime timeProperty READ timeProperty WRITE setTimeProperty NOTIFY timePropertyChanged)
Q_PROPERTY(QDateTime dateTimeProperty READ dateTimeProperty WRITE setDateTimeProperty NOTIFY dateTimePropertyChanged)
Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty NOTIFY pointPropertyChanged)
Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty NOTIFY pointFPropertyChanged)
Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty NOTIFY sizePropertyChanged)
Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty NOTIFY sizeFPropertyChanged)
Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged)
Q_PROPERTY(QRect rectProperty2 READ rectProperty2 WRITE setRectProperty2 )
Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty NOTIFY rectFPropertyChanged)
Q_PROPERTY(bool boolProperty READ boolProperty WRITE setBoolProperty NOTIFY boolPropertyChanged)
Q_PROPERTY(QVariant variantProperty READ variantProperty WRITE setVariantProperty NOTIFY variantPropertyChanged)
Q_PROPERTY(QVector2D vector2Property READ vector2Property WRITE setVector2Property NOTIFY vector2PropertyChanged)
Q_PROPERTY(QVector3D vectorProperty READ vectorProperty WRITE setVectorProperty NOTIFY vectorPropertyChanged)
Q_PROPERTY(QVector4D vector4Property READ vector4Property WRITE setVector4Property NOTIFY vector4PropertyChanged)
Q_PROPERTY(QQuaternion quaternionProperty READ quaternionProperty WRITE setQuaternionProperty NOTIFY quaternionPropertyChanged)
Q_PROPERTY(QUrl urlProperty READ urlProperty WRITE setUrlProperty NOTIFY urlPropertyChanged)
Q_PROPERTY(QQmlScriptString scriptProperty READ scriptProperty WRITE setScriptProperty)
Q_PROPERTY(MyGroupedObject *grouped READ grouped CONSTANT)
Q_PROPERTY(MyGroupedObject *nullGrouped READ nullGrouped CONSTANT)
Q_PROPERTY(MyTypeObject *selfGroupProperty READ selfGroupProperty)
public:
MyTypeObject()
: objectPropertyValue(0), componentPropertyValue(0) {}
QString idValue;
QString id() const {
return idValue;
}
void setId(const QString &v) {
idValue = v;
}
QObject *objectPropertyValue;
QObject *objectProperty() const {
return objectPropertyValue;
}
void setObjectProperty(QObject *v) {
objectPropertyValue = v;
emit objectPropertyChanged();
}
QQmlComponent *componentPropertyValue;
QQmlComponent *componentProperty() const {
return componentPropertyValue;
}
void setComponentProperty(QQmlComponent *v) {
componentPropertyValue = v;
}
enum MyFlag { FlagVal1 = 0x01, FlagVal2 = 0x02, FlagVal3 = 0x04 };
Q_DECLARE_FLAGS(MyFlags, MyFlag)
MyFlags flagPropertyValue;
MyFlags flagProperty() const {
return flagPropertyValue;
}
void setFlagProperty(MyFlags v) {
flagPropertyValue = v;
emit flagPropertyChanged();
}
enum MyEnum { EnumVal1, EnumVal2, lowercaseEnumVal };
MyEnum enumPropertyValue;
MyEnum enumProperty() const {
return enumPropertyValue;
}
void setEnumProperty(MyEnum v) {
enumPropertyValue = v;
emit enumPropertyChanged();
}
MyEnum readOnlyEnumProperty() const {
return EnumVal1;
}
Qt::TextFormat qtEnumPropertyValue;
Qt::TextFormat qtEnumProperty() const {
return qtEnumPropertyValue;
}
void setQtEnumProperty(Qt::TextFormat v) {
qtEnumPropertyValue = v;
emit qtEnumPropertyChanged();
}
enum MyMirroredEnum {
MirroredEnumVal1 = Qt::AlignLeft,
MirroredEnumVal2 = Qt::AlignRight,
MirroredEnumVal3 = Qt::AlignHCenter };
MyMirroredEnum mirroredEnumPropertyValue;
MyMirroredEnum mirroredEnumProperty() const {
return mirroredEnumPropertyValue;
}
void setMirroredEnumProperty(MyMirroredEnum v) {
mirroredEnumPropertyValue = v;
emit mirroredEnumPropertyChanged();
}
MyEnumContainer::RelatedEnum relatedEnumPropertyValue;
MyEnumContainer::RelatedEnum relatedEnumProperty() const {
return relatedEnumPropertyValue;
}
void setRelatedEnumProperty(MyEnumContainer::RelatedEnum v) {
relatedEnumPropertyValue = v;
}
enum class MyScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3 };
Q_ENUM(MyScopedEnum)
MyScopedEnum scopedEnumPropertyValue;
MyScopedEnum scopedEnum() const { return scopedEnumPropertyValue; }
void setScopedEnum(MyScopedEnum v) {
scopedEnumPropertyValue = v;
}
QString stringPropertyValue;
QString stringProperty() const {
return stringPropertyValue;
}
void setStringProperty(const QString &v) {
stringPropertyValue = v;
emit stringPropertyChanged();
}
QByteArray byteArrayPropertyValue;
QByteArray byteArrayProperty() const {
return byteArrayPropertyValue;
}
void setByteArrayProperty(const QByteArray &v) {
byteArrayPropertyValue = v;
emit byteArrayPropertyChanged();
}
uint uintPropertyValue;
uint uintProperty() const {
return uintPropertyValue;
}
void setUintProperty(const uint &v) {
uintPropertyValue = v;
emit uintPropertyChanged();
}
int intPropertyValue;
int intProperty() const {
return intPropertyValue;
}
void setIntProperty(const int &v) {
intPropertyValue = v;
emit intPropertyChanged();
}
qsizetype qsizetypePropertyValue;
qsizetype qsizetypeProperty() const {
return qsizetypePropertyValue;
}
void setQsizetypeProperty(const qsizetype &v) {
qsizetypePropertyValue = v;
emit qsizetypePropertyChanged();
}
qreal realPropertyValue;
qreal realProperty() const {
return realPropertyValue;
}
void setRealProperty(const qreal &v) {
realPropertyValue = v;
emit realPropertyChanged();
}
double doublePropertyValue;
double doubleProperty() const {
return doublePropertyValue;
}
void setDoubleProperty(const double &v) {
doublePropertyValue = v;
emit doublePropertyChanged();
}
float floatPropertyValue;
float floatProperty() const {
return floatPropertyValue;
}
void setFloatProperty(const float &v) {
floatPropertyValue = v;
emit floatPropertyChanged();
}
QColor colorPropertyValue;
QColor colorProperty() const {
return colorPropertyValue;
}
void setColorProperty(const QColor &v) {
colorPropertyValue = v;
emit colorPropertyChanged();
}
QDate datePropertyValue;
QDate dateProperty() const {
return datePropertyValue;
}
void setDateProperty(QDate v) {
datePropertyValue = v;
emit datePropertyChanged();
}
QTime timePropertyValue;
QTime timeProperty() const {
return timePropertyValue;
}
void setTimeProperty(QTime v) {
timePropertyValue = v;
emit timePropertyChanged();
}
QDateTime dateTimePropertyValue;
QDateTime dateTimeProperty() const {
return dateTimePropertyValue;
}
void setDateTimeProperty(const QDateTime &v) {
dateTimePropertyValue = v;
emit dateTimePropertyChanged();
}
QPoint pointPropertyValue;
QPoint pointProperty() const {
return pointPropertyValue;
}
void setPointProperty(const QPoint &v) {
pointPropertyValue = v;
emit pointPropertyChanged();
}
QPointF pointFPropertyValue;
QPointF pointFProperty() const {
return pointFPropertyValue;
}
void setPointFProperty(const QPointF &v) {
pointFPropertyValue = v;
emit pointFPropertyChanged();
}
QSize sizePropertyValue;
QSize sizeProperty() const {
return sizePropertyValue;
}
void setSizeProperty(const QSize &v) {
sizePropertyValue = v;
emit sizePropertyChanged();
}
QSizeF sizeFPropertyValue;
QSizeF sizeFProperty() const {
return sizeFPropertyValue;
}
void setSizeFProperty(const QSizeF &v) {
sizeFPropertyValue = v;
emit sizeFPropertyChanged();
}
QRect rectPropertyValue;
QRect rectProperty() const {
return rectPropertyValue;
}
void setRectProperty(const QRect &v) {
rectPropertyValue = v;
emit rectPropertyChanged();
}
QRect rectPropertyValue2;
QRect rectProperty2() const {
return rectPropertyValue2;
}
void setRectProperty2(const QRect &v) {
rectPropertyValue2 = v;
}
QRectF rectFPropertyValue;
QRectF rectFProperty() const {
return rectFPropertyValue;
}
void setRectFProperty(const QRectF &v) {
rectFPropertyValue = v;
emit rectFPropertyChanged();
}
bool boolPropertyValue;
bool boolProperty() const {
return boolPropertyValue;
}
void setBoolProperty(const bool &v) {
boolPropertyValue = v;
emit boolPropertyChanged();
}
QVariant variantPropertyValue;
QVariant variantProperty() const {
return variantPropertyValue;
}
void setVariantProperty(const QVariant &v) {
variantPropertyValue = v;
emit variantPropertyChanged();
}
QVector3D vectorPropertyValue;
QVector3D vectorProperty() const {
return vectorPropertyValue;
}
void setVectorProperty(const QVector3D &v) {
vectorPropertyValue = v;
emit vectorPropertyChanged();
}
QVector2D vector2PropertyValue;
QVector2D vector2Property() const {
return vector2PropertyValue;
}
void setVector2Property(const QVector2D &v) {
vector2PropertyValue = v;
emit vector2PropertyChanged();
}
QVector4D vector4PropertyValue;
QVector4D vector4Property() const {
return vector4PropertyValue;
}
void setVector4Property(const QVector4D &v) {
vector4PropertyValue = v;
emit vector4PropertyChanged();
}
QQuaternion quaternionPropertyValue;
QQuaternion quaternionProperty() const {
return quaternionPropertyValue;
}
void setQuaternionProperty(const QQuaternion &v) {
quaternionPropertyValue = v;
emit quaternionPropertyChanged();
}
QUrl urlPropertyValue;
QUrl urlProperty() const {
return urlPropertyValue;
}
void setUrlProperty(const QUrl &v) {
urlPropertyValue = v;
emit urlPropertyChanged();
}
QQmlScriptString scriptPropertyValue;
QQmlScriptString scriptProperty() const {
return scriptPropertyValue;
}
void setScriptProperty(const QQmlScriptString &v) {
scriptPropertyValue = v;
}
MyGroupedObject groupedValue;
MyGroupedObject *grouped() { return &groupedValue; }
MyGroupedObject *nullGrouped() { return 0; }
MyTypeObject *selfGroupProperty() { return this; }
void doAction() { emit action(); }
signals:
void action();
void objectPropertyChanged();
void flagPropertyChanged();
void enumPropertyChanged();
void qtEnumPropertyChanged();
void mirroredEnumPropertyChanged();
void stringPropertyChanged();
void byteArrayPropertyChanged();
void uintPropertyChanged();
void intPropertyChanged();
void qsizetypePropertyChanged();
void realPropertyChanged();
void doublePropertyChanged();
void floatPropertyChanged();
void colorPropertyChanged();
void datePropertyChanged();
void timePropertyChanged();
void dateTimePropertyChanged();
void pointPropertyChanged();
void pointFPropertyChanged();
void sizePropertyChanged();
void sizeFPropertyChanged();
void rectPropertyChanged();
void rectFPropertyChanged();
void boolPropertyChanged();
void variantPropertyChanged();
void vectorPropertyChanged();
void vector2PropertyChanged();
void vector4PropertyChanged();
void quaternionPropertyChanged();
void urlPropertyChanged();
};
Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags)
// FIXME: If no subclass is used for the singleton registration with qmlRegisterSingletonType(),
// the valueTypes() test will fail.
class MyTypeObjectSingleton : public MyTypeObject
{
Q_OBJECT
};
class MyContainer : public QObject
{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<QObject> children READ children)
Q_PROPERTY(QQmlListProperty<MyContainer> containerChildren READ containerChildren)
Q_PROPERTY(QQmlListProperty<MyInterface> qlistInterfaces READ qlistInterfaces)
Q_CLASSINFO("DefaultProperty", "children")
public:
MyContainer() {}
QQmlListProperty<QObject> children() { return QQmlListProperty<QObject>(this, &m_children); }
QQmlListProperty<MyContainer> containerChildren() { return QQmlListProperty<MyContainer>(this, &m_containerChildren); }
QList<QObject *> *getChildren() { return &m_children; }
QQmlListProperty<MyInterface> qlistInterfaces() { return QQmlListProperty<MyInterface>(this, &m_interfaces); }
QList<MyInterface *> *getQListInterfaces() { return &m_interfaces; }
QList<MyContainer*> m_containerChildren;
QList<QObject*> m_children;
QList<MyInterface *> m_interfaces;
};
class MyPropertyValueSource : public QObject, public QQmlPropertyValueSource
{
Q_OBJECT
Q_INTERFACES(QQmlPropertyValueSource)
public:
MyPropertyValueSource()
: QQmlPropertyValueSource() {}
QQmlProperty prop;
void setTarget(const QQmlProperty &p) override
{
prop = p;
}
};
class UnavailableType : public QObject
{
Q_OBJECT
public:
UnavailableType() {}
};
class MyReceiversTestObject : public QObject
{
Q_OBJECT
Q_PROPERTY(int prop READ prop NOTIFY propChanged)
public:
MyReceiversTestObject() {}
int prop() const { return 5; }
int mySignalCount() { return receivers(SIGNAL(mySignal())); }
int propChangedCount() { return receivers(SIGNAL(propChanged())); }
int myUnconnectedSignalCount() { return receivers(SIGNAL(myUnconnectedSignal())); }
signals:
void mySignal();
void propChanged();
void myUnconnectedSignal();
private:
friend class tst_qqmllanguage;
};
class MyDotPropertyObject : public QObject
{
Q_OBJECT
Q_PROPERTY(MyQmlObject *obj READ obj)
Q_PROPERTY(MyQmlObject *readWriteObj READ readWriteObj WRITE setReadWriteObj)
public:
MyDotPropertyObject() : m_rwobj(0), m_ownRWObj(false) {}
~MyDotPropertyObject()
{
if (m_ownRWObj)
delete m_rwobj;
}
MyQmlObject *obj() { return 0; }
MyQmlObject *readWriteObj()
{
if (!m_rwobj) {
m_rwobj = new MyQmlObject;
m_ownRWObj = true;
}
return m_rwobj;
}
void setReadWriteObj(MyQmlObject *obj)
{
if (m_ownRWObj) {
delete m_rwobj;
m_ownRWObj = false;
}
m_rwobj = obj;
}
private:
MyQmlObject *m_rwobj;
bool m_ownRWObj;
};
namespace MyStaticNamespace {
Q_NAMESPACE
QML_ELEMENT
enum MyNSEnum {
Key1 = 1,
Key2,
Key5 = 5
};
Q_ENUM_NS(MyNSEnum);
enum class MyOtherNSEnum {
OtherKey1 = 1,
OtherKey2
};
Q_ENUM_NS(MyOtherNSEnum);
class MyNamespacedType : public QObject
{
Q_OBJECT
Q_PROPERTY(MyStaticNamespace::MyNSEnum myEnum MEMBER m_myEnum)
QML_NAMED_ELEMENT(MyStaticNamespacedType)
MyStaticNamespace::MyNSEnum m_myEnum = MyNSEnum::Key1;
};
class MySecondNamespacedType : public QObject
{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<MyStaticNamespace::MyNamespacedType> list READ list)
QML_NAMED_ELEMENT(MyStaticSecondNamespacedType)
public:
QQmlListProperty<MyNamespacedType> list()
{
return QQmlListProperty<MyNamespacedType>(this, &m_list);
}
private:
QList<MyNamespacedType *> m_list;
};
}
namespace MyNamespace {
Q_NAMESPACE
enum MyNSEnum {
Key1 = 1,
Key2,
Key5 = 5
};
Q_ENUM_NS(MyNSEnum);
enum class MyOtherNSEnum {
OtherKey1 = 1,
OtherKey2
};
Q_ENUM_NS(MyOtherNSEnum);
class MyNamespacedType : public QObject
{
Q_OBJECT
Q_PROPERTY(MyNamespace::MyNSEnum myEnum MEMBER m_myEnum)
MyNamespace::MyNSEnum m_myEnum = MyNSEnum::Key1;
};
class MySecondNamespacedType : public QObject
{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<MyNamespace::MyNamespacedType> list READ list)
public:
QQmlListProperty<MyNamespacedType> list() { return QQmlListProperty<MyNamespacedType>(this, &m_list); }
private:
QList<MyNamespacedType *> m_list;
};
}
class MyCustomParserType : public QObject
{
Q_OBJECT
};
class MyCustomParserTypeParser : public QQmlCustomParser
{
public:
void verifyBindings(
const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &,
const QList<const QV4::CompiledData::Binding *> &) override {}
void applyBindings(
QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &,
const QList<const QV4::CompiledData::Binding *> &) override {}
};
class EnumSupportingCustomParser : public QQmlCustomParser
{
public:
void verifyBindings(
const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &,
const QList<const QV4::CompiledData::Binding *> &) override;
void applyBindings(
QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &,
const QList<const QV4::CompiledData::Binding *> &) override {}
};
class MyParserStatus : public QObject, public QQmlParserStatus
{
Q_INTERFACES(QQmlParserStatus)
Q_OBJECT
public:
MyParserStatus() : m_cbc(0), m_ccc(0) {}
int classBeginCount() const { return m_cbc; }
int componentCompleteCount() const { return m_ccc; }
void classBegin() override { m_cbc++; }
void componentComplete() override { m_ccc++; }
private:
int m_cbc;
int m_ccc;
};
class MyRevisionedBaseClassRegistered : public QObject
{
Q_OBJECT
Q_PROPERTY(qreal propA READ propA WRITE setPropA NOTIFY propAChanged)
Q_PROPERTY(qreal propB READ propB WRITE setPropB NOTIFY propBChanged REVISION 1)
public:
MyRevisionedBaseClassRegistered() : m_pa(1), m_pb(2) {}
qreal propA() const { return m_pa; }
void setPropA(qreal p) {
if (p != m_pa) {
m_pa = p;
emit propAChanged();
}
}
qreal propB() const { return m_pb; }
void setPropB(qreal p) {
if (p != m_pb) {
m_pb = p;
emit propBChanged();
}
}
Q_INVOKABLE void methodA() { }
Q_INVOKABLE Q_REVISION(1) void methodB() { }
signals:
void propAChanged();
void propBChanged();
void signalA();
Q_REVISION(1) void signalB();
protected:
qreal m_pa;
qreal m_pb;
};
class MyRevisionedIllegalOverload : public MyRevisionedBaseClassRegistered
{
Q_OBJECT
Q_PROPERTY(qreal propA READ propA WRITE setPropA REVISION 1);
};
class MyRevisionedLegalOverload : public MyRevisionedBaseClassRegistered
{
Q_OBJECT
Q_PROPERTY(qreal propB READ propB WRITE setPropB REVISION 1);
};
class MyRevisionedBaseClassUnregistered : public MyRevisionedBaseClassRegistered
{
Q_OBJECT
Q_PROPERTY(qreal propC READ propC WRITE setPropC NOTIFY propCChanged)
Q_PROPERTY(qreal propD READ propD WRITE setPropD NOTIFY propDChanged REVISION 1)
public:
MyRevisionedBaseClassUnregistered() : m_pc(1), m_pd(2) {}
qreal propC() const { return m_pc; }
void setPropC(qreal p) {
if (p != m_pc) {
m_pc = p;
emit propCChanged();
}
}
qreal propD() const { return m_pd; }
void setPropD(qreal p) {
if (p != m_pd) {
m_pd = p;
emit propDChanged();
}
}
Q_INVOKABLE void methodC() { }
Q_INVOKABLE Q_REVISION(1) void methodD() { }
signals:
void propCChanged();
void propDChanged();
void signalC();
Q_REVISION(1) void signalD();
protected:
qreal m_pc;
qreal m_pd;
};
class MyRevisionedClass : public MyRevisionedBaseClassUnregistered
{
Q_OBJECT
Q_PROPERTY(qreal prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed)
Q_PROPERTY(qreal prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed REVISION 1)
public:
MyRevisionedClass() : m_p1(1), m_p2(2) {}
qreal prop1() const { return m_p1; }
void setProp1(qreal p) {
if (p != m_p1) {
m_p1 = p;
emit prop1Changed();
}
}
qreal prop2() const { return m_p2; }
void setProp2(qreal p) {
if (p != m_p2) {
m_p2 = p;
emit prop2Changed();
}
}
Q_INVOKABLE void method1() { }
Q_INVOKABLE Q_REVISION(1) void method2() { }
signals:
void prop1Changed();
void prop2Changed();
void signal1();
Q_REVISION(1) void signal2();
protected:
qreal m_p1;
qreal m_p2;
};
class MyRevisionedSubclass : public MyRevisionedClass
{
Q_OBJECT
Q_PROPERTY(qreal prop3 READ prop3 WRITE setProp3 NOTIFY prop3Changed)
Q_PROPERTY(qreal prop4 READ prop4 WRITE setProp4 NOTIFY prop4Changed REVISION 1)
public:
MyRevisionedSubclass() : m_p3(3), m_p4(4) {}
qreal prop3() const { return m_p3; }
void setProp3(qreal p) {
if (p != m_p3) {
m_p3 = p;
emit prop3Changed();
}
}
qreal prop4() const { return m_p4; }
void setProp4(qreal p) {
if (p != m_p4) {
m_p4 = p;
emit prop4Changed();
}
}
Q_INVOKABLE void method3() { }
Q_INVOKABLE Q_REVISION(1) void method4() { }
signals:
void prop3Changed();
void prop4Changed();
void signal3();
Q_REVISION(1) void signal4();
protected:
qreal m_p3;
qreal m_p4;
};
class MySubclass : public MyRevisionedClass
{
Q_OBJECT
Q_PROPERTY(qreal prop5 READ prop5 WRITE setProp5 NOTIFY prop5Changed)
public:
MySubclass() : m_p5(5) {}
qreal prop5() const { return m_p5; }
void setProp5(qreal p) {
if (p != m_p5) {
m_p5 = p;
emit prop5Changed();
}
}
Q_INVOKABLE void method5() { }
signals:
void prop5Changed();
protected:
qreal m_p5;
};
class MyUncreateableBaseClass : public QObject
{
Q_OBJECT
Q_PROPERTY(bool prop1 READ prop1 WRITE setprop1)
Q_PROPERTY(bool prop2 READ prop2 WRITE setprop2 REVISION 1)
Q_PROPERTY(bool prop3 READ prop3 WRITE setprop3 REVISION 1)
public:
explicit MyUncreateableBaseClass(bool /* arg */, QObject *parent = nullptr)
: QObject(parent), _prop1(false), _prop2(false), _prop3(false)
{
}
bool _prop1;
bool prop1() const { return _prop1; }
void setprop1(bool p) { _prop1 = p; }
bool _prop2;
bool prop2() const { return _prop2; }
void setprop2(bool p) { _prop2 = p; }
bool _prop3;
bool prop3() const { return _prop3; }
void setprop3(bool p) { _prop3 = p; }
};
class MyCreateableDerivedClass : public MyUncreateableBaseClass
{
Q_OBJECT
Q_PROPERTY(bool prop2 READ prop2 WRITE setprop2 REVISION 1)
public:
MyCreateableDerivedClass(QObject *parent = nullptr)
: MyUncreateableBaseClass(true, parent)
{
}
};
class MyExtendedUncreateableBaseClass : public QObject
{
Q_OBJECT
Q_PROPERTY(bool prop1 READ prop1 WRITE setprop1)
Q_PROPERTY(bool prop2 READ prop2 WRITE setprop2 REVISION 1)
Q_PROPERTY(bool prop3 READ prop3 WRITE setprop3 REVISION 1)
public:
explicit MyExtendedUncreateableBaseClass(QObject *parent = nullptr)
: QObject(parent), _prop1(false), _prop2(false), _prop3(false)
{
}
bool _prop1;
bool prop1() const { return _prop1; }
void setprop1(bool p) { _prop1 = p; }
bool _prop2;
bool prop2() const { return _prop2; }
void setprop2(bool p) { _prop2 = p; }
bool _prop3;
bool prop3() const { return _prop3; }
void setprop3(bool p) { _prop3 = p; }
};
class MyExtendedUncreateableBaseClassExtension : public QObject
{
Q_OBJECT
Q_PROPERTY(bool prop4 READ prop4 WRITE setprop4)
public:
explicit MyExtendedUncreateableBaseClassExtension(QObject *parent = nullptr)
: QObject(parent), _prop4(false)
{
}
bool _prop4;
bool prop4() const { return _prop4; }
void setprop4(bool p) { _prop4 = p; }
};
class MyExtendedCreateableDerivedClass : public MyExtendedUncreateableBaseClass
{
Q_OBJECT
Q_PROPERTY(bool prop5 READ prop5 WRITE setprop5)
public:
MyExtendedCreateableDerivedClass(QObject *parent = nullptr)
: MyExtendedUncreateableBaseClass(parent), _prop5(false)
{
}
bool _prop5;
bool prop5() const { return _prop5; }
void setprop5(bool p) { _prop5 = p; }
};
class MyVersion2Class : public QObject
{
Q_OBJECT
};
class MyEnum1Class : public QObject
{
Q_OBJECT
Q_ENUMS(EnumA)
public:
MyEnum1Class() : value(A_Invalid) {}
enum EnumA
{
A_Invalid = -1,
A_11 = 11,
A_13 = 13
};
Q_INVOKABLE void setValue(EnumA v) { value = v; }
EnumA getValue() { return value; }
private:
EnumA value;
};
class MyEnum2Class : public QObject
{
Q_OBJECT
Q_ENUMS(EnumB)
Q_ENUMS(EnumE)
public:
MyEnum2Class() : valueA(MyEnum1Class::A_Invalid), valueB(B_Invalid), valueC(Qt::PlainText),
valueD(Qt::ElideLeft), valueE(E_Invalid), valueE2(E_Invalid) {}
enum EnumB
{
B_Invalid = -1,
B_29 = 29,
B_31 = 31,
B_37 = 37
};
enum EnumE
{
E_Invalid = -1,
E_14 = 14,
E_76 = 76
};
MyEnum1Class::EnumA getValueA() { return valueA; }
EnumB getValueB() { return valueB; }
Qt::TextFormat getValueC() { return valueC; }
Qt::TextElideMode getValueD() { return valueD; }
EnumE getValueE() { return valueE; }
EnumE getValueE2() { return valueE2; }
Q_INVOKABLE void setValueA(MyEnum1Class::EnumA v) { valueA = v; emit valueAChanged(v); }
Q_INVOKABLE void setValueB(EnumB v) { valueB = v; emit valueBChanged(v); }
Q_INVOKABLE void setValueC(Qt::TextFormat v) { valueC = v; emit valueCChanged(v); } //registered
Q_INVOKABLE void setValueD(Qt::TextElideMode v) { valueD = v; emit valueDChanged(v); } //unregistered
Q_INVOKABLE void setValueE(EnumE v) { valueE = v; emit valueEChanged(v); }
Q_INVOKABLE void setValueE2(MyEnum2Class::EnumE v) { valueE2 = v; emit valueE2Changed(v); }
signals:
void valueAChanged(MyEnum1Class::EnumA newValue);
void valueBChanged(MyEnum2Class::EnumB newValue);
void valueCChanged(Qt::TextFormat newValue);
void valueDChanged(Qt::TextElideMode newValue);
void valueEChanged(EnumE newValue);
void valueE2Changed(MyEnum2Class::EnumE newValue);
private:
MyEnum1Class::EnumA valueA;
EnumB valueB;
Qt::TextFormat valueC;
Qt::TextElideMode valueD;
EnumE valueE;
EnumE valueE2;
};
class MyEnumDerivedClass : public MyEnum2Class
{
Q_OBJECT
};
class MyCompositeBaseType : public QObject
{
Q_OBJECT
Q_ENUMS(CompositeEnum)
Q_ENUMS(ScopedCompositeEnum)
public:
enum CompositeEnum { EnumValue0, EnumValue42 = 42 };
enum class ScopedCompositeEnum : int { EnumValue15 = 15 };
static QObject *qmlAttachedProperties(QObject *parent) { return new QObject(parent); }
};
class MyArrayBufferTestClass : public QObject
{
Q_OBJECT
Q_PROPERTY(QByteArray byteArrayProperty READ byteArrayProperty WRITE setByteArrayProperty NOTIFY byteArrayPropertyChanged)
signals:
void byteArrayPropertyChanged();
void byteArraySignal(QByteArray arg);
public:
QByteArray byteArrayPropertyValue;
QByteArray byteArrayProperty() const {
return byteArrayPropertyValue;
}
void setByteArrayProperty(const QByteArray &v) {
byteArrayPropertyValue = v;
emit byteArrayPropertyChanged();
}
Q_INVOKABLE void emitByteArraySignal(char begin, char num) {
byteArraySignal(byteArrayMethod_CountUp(begin, num));
}
Q_INVOKABLE int byteArrayMethod_Sum(QByteArray arg) {
int sum = 0;
for (int i = 0; i < arg.size(); ++i) {
sum += arg[i];
}
return sum;
}
Q_INVOKABLE QByteArray byteArrayMethod_CountUp(char begin, int num) {
QByteArray ret;
for (int i = 0; i < num; ++i) {
ret.push_back(begin++);
}
return ret;
}
Q_INVOKABLE bool byteArrayMethod_Overloaded(QByteArray) {
return true;
}
Q_INVOKABLE bool byteArrayMethod_Overloaded(int) {
return false;
}
Q_INVOKABLE bool byteArrayMethod_Overloaded(QString) {
return false;
}
Q_INVOKABLE bool byteArrayMethod_Overloaded(QJSValue) {
return false;
}
Q_INVOKABLE bool byteArrayMethod_Overloaded(QVariant) {
return false;
}
};
class EnumPropsManyUnderlyingTypes : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
enum si8 : qint8 { ResolvedValue = 1};
enum ui8 : quint8 {};
enum si16 : qint16 {};
enum ui16 : quint16 {};
enum ui64 : qint64 {};
enum si64 : quint64 {};
Q_ENUM(si8)
Q_ENUM(ui8)
Q_ENUM(si16)
Q_ENUM(ui16)
Q_ENUM(si64)
Q_ENUM(ui64)
Q_PROPERTY(si8 si8prop MEMBER si8prop)
Q_PROPERTY(ui8 ui8prop MEMBER ui8prop)
Q_PROPERTY(si16 si16prop MEMBER si16prop)
Q_PROPERTY(ui16 ui16prop MEMBER ui16prop)
Q_PROPERTY(si64 si64prop MEMBER si64prop)
Q_PROPERTY(ui64 ui64prop MEMBER ui64prop)
si8 si8prop = si8(0);
ui8 ui8prop = ui8(0);
si16 si16prop = si16(0);
ui16 ui16prop = ui16(0);
si64 si64prop = si64(0);
ui64 ui64prop = ui64(0);
};
Q_DECLARE_METATYPE(MyEnum2Class::EnumB)
Q_DECLARE_METATYPE(MyEnum1Class::EnumA)
Q_DECLARE_METATYPE(Qt::TextFormat)
Q_DECLARE_METATYPE(MyCompositeBaseType::CompositeEnum)
QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered)
QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
QML_DECLARE_TYPE(MyRevisionedClass)
QML_DECLARE_TYPE(MyRevisionedSubclass)
QML_DECLARE_TYPE(MySubclass)
QML_DECLARE_TYPE(MyReceiversTestObject)
QML_DECLARE_TYPE(MyCompositeBaseType)
QML_DECLARE_TYPEINFO(MyCompositeBaseType, QML_HAS_ATTACHED_PROPERTIES)
class CustomBinding : public QObject, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QObject* target READ target WRITE setTarget)
public:
void classBegin() override {}
void componentComplete() override;
QObject *target() const { return m_target; }
void setTarget(QObject *newTarget) { m_target = newTarget; }
QPointer<QObject> m_target;
QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit;
QList<const QV4::CompiledData::Binding*> bindings;
QByteArray m_bindingData;
};
class CustomBindingParser : public QQmlCustomParser
{
void verifyBindings(
const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &,
const QList<const QV4::CompiledData::Binding *> &) override {}
void applyBindings(
QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &,
const QList<const QV4::CompiledData::Binding *> &) override;
};
class SimpleObjectWithCustomParser : public QObject
{
Q_OBJECT
Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty)
public:
SimpleObjectWithCustomParser()
: m_intProperty(0)
, m_customBindingsCount(0)
{}
int intProperty() const { return m_intProperty; }
void setIntProperty(int value) { m_intProperty = value; }
void setCustomBindingsCount(int count) { m_customBindingsCount = count; }
int customBindingsCount() const { return m_customBindingsCount; }
private:
int m_intProperty;
int m_customBindingsCount;
};
class SimpleObjectExtension : public QObject
{
Q_OBJECT
Q_PROPERTY(int extendedProperty READ extendedProperty WRITE setExtendedProperty NOTIFY extendedPropertyChanged)
public:
SimpleObjectExtension(QObject *parent = nullptr)
: QObject(parent)
, m_extendedProperty(1584)
{}
void setExtendedProperty(int extendedProperty) { m_extendedProperty = extendedProperty; emit extendedPropertyChanged(); }
int extendedProperty() const { return m_extendedProperty; }
signals:
void extendedPropertyChanged();
private:
int m_extendedProperty;
};
class SimpleObjectCustomParser : public QQmlCustomParser
{
void verifyBindings(
const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &,
const QList<const QV4::CompiledData::Binding *> &) override {}
void applyBindings(
QObject *, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &,
const QList<const QV4::CompiledData::Binding *> &) override;
};
class RootObjectInCreationTester : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject *subObject READ subObject WRITE setSubObject FINAL)
Q_CLASSINFO("DeferredPropertyNames", "subObject");
public:
RootObjectInCreationTester()
: obj(0)
{}
QObject *subObject() const { return obj; }
void setSubObject(QObject *o) { obj = o; }
private:
QObject *obj;
};
class LazyDeferredSubObject : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject *subObject READ subObject WRITE setSubObject NOTIFY subObjectChanged FINAL)
Q_CLASSINFO("DeferredPropertyNames", "subObject");
public:
LazyDeferredSubObject()
: obj(0)
{}
QObject *subObject() const { if (!obj) qmlExecuteDeferred(const_cast<LazyDeferredSubObject *>(this)); return obj; }
void setSubObject(QObject *o) { if (obj == o) return; obj = o; emit subObjectChanged(); }
signals:
void subObjectChanged();
private:
QObject *obj;
};
class DeferredProperties : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject *groupProperty MEMBER m_group)
Q_PROPERTY(QQmlListProperty<QObject> listProperty READ listProperty)
Q_CLASSINFO("DeferredPropertyNames", "groupProperty,listProperty")
Q_CLASSINFO("DefaultProperty", "listProperty")
public:
QQmlListProperty<QObject> listProperty() { return QQmlListProperty<QObject>(this, &m_list); }
private:
QObject *m_group = 0;
QObjectList m_list;
};
class ImmediateProperties : public QObject
{
Q_OBJECT
Q_CLASSINFO("ImmediatePropertyNames", "objectName")
};
namespace ScopedEnumsWithNameClash
{
Q_NAMESPACE
enum class ScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3, OtherScopedEnum };
Q_ENUM_NS(ScopedEnum)
enum class OtherScopedEnum : int { ScopedVal1 = 10, ScopedVal2 = 11, ScopedVal3 = 12 };
Q_ENUM_NS(OtherScopedEnum)
};
class ScopedEnumsWithResolvedNameClash
{
Q_GADGET
Q_ENUMS(ScopedEnum)
Q_ENUMS(OtherScopedEnum)
Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
public:
enum class ScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3, OtherScopedEnum };
enum class OtherScopedEnum : int { ScopedVal1, ScopedVal2, ScopedVal3 };
};
class AttachedType : public QObject
{
Q_OBJECT
QML_ANONYMOUS
Q_PROPERTY(
QString attachedName READ attachedName WRITE setAttachedName NOTIFY attachedNameChanged)
QString m_name;
public:
AttachedType(QObject *parent = nullptr) : QObject(parent) { }
QString attachedName() const { return m_name; }
void setAttachedName(const QString &name)
{
if (name != m_name) {
m_name = name;
Q_EMIT attachedNameChanged();
}
}
Q_SIGNALS:
void attachedNameChanged();
};
class Extension : public QObject
{
Q_OBJECT
Q_PROPERTY(int extension READ extension WRITE setExtension NOTIFY extensionChangedWithValue FINAL)
QML_ATTACHED(AttachedType)
public:
Extension(QObject *parent = nullptr) : QObject(parent) {}
int extension() const { return ext; }
void setExtension(int e) {
if (e != ext) {
ext = e;
emit extensionChanged();
emit extensionChangedWithValue(e);
}
}
Q_INVOKABLE int invokable() { return 123; }
static AttachedType *qmlAttachedProperties(QObject *object) { return new AttachedType(object); }
Q_SIGNALS:
void extensionChanged();
void extensionChangedWithValue(int value);
public slots:
int slot() { return 456; }
private:
int ext = 42;
};
class Extended : public QObject
{
Q_OBJECT
QML_EXTENDED(Extension)
QML_NAMED_ELEMENT(Extended)
Q_PROPERTY(int base READ base CONSTANT)
public:
int base() const { return 43; }
};
class Local : public QObject
{
Q_OBJECT
};
class Foreign
{
Q_GADGET
QML_FOREIGN(Local)
QML_NAMED_ELEMENT(Foreign)
};
class ForeignExtended
{
Q_GADGET
QML_FOREIGN(Local)
QML_NAMED_ELEMENT(ForeignExtended)
QML_EXTENDED(Extension)
};
class BareSingleton : public QObject
{
Q_OBJECT
QML_SINGLETON
QML_ELEMENT
QML_ADDED_IN_VERSION(1, 0)
public:
BareSingleton(QObject *parent = nullptr) : QObject(parent)
{
setObjectName("statically registered");
}
};
class UncreatableSingleton : public QObject
{
Q_OBJECT
QML_SINGLETON
QML_ELEMENT
QML_ADDED_IN_VERSION(1, 0)
public:
static UncreatableSingleton *instance();
private:
UncreatableSingleton() { setObjectName("uncreatable"); }
};
class UncreatableElementNoReason : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("")
};
namespace ExtensionNamespace {
Q_NAMESPACE
enum Foo {
Bar = 9,
Baz = 12
};
Q_ENUM_NS(Foo)
}
class ExtendedByNamespace : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED_NAMESPACE(ExtensionNamespace)
Q_PROPERTY(int own READ own CONSTANT)
public:
enum OwnEnum {
Moo = 16,
Maeh = 17
};
Q_ENUM(OwnEnum)
ExtendedByNamespace(QObject *parent = nullptr) : QObject(parent) {}
int own() const { return 93; }
};
class ExtendedByNamespaceInParent : public ExtendedByNamespace
{
Q_OBJECT
QML_ELEMENT
public:
ExtendedByNamespaceInParent(QObject *parent = nullptr) : ExtendedByNamespace(parent) { }
};
class ExtendedNamespaceByObject : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED_NAMESPACE(Extension)
Q_PROPERTY(QString dummy READ dummy CONSTANT)
Q_PROPERTY(int extension READ extension WRITE setExtension NOTIFY extensionChanged)
int m_ext = 0;
public:
ExtendedNamespaceByObject(QObject *parent = nullptr) : QObject(parent) {}
QString dummy() const { return QStringLiteral("dummy"); }
int extension() const { return m_ext; }
void setExtension(int e)
{
if (e != m_ext) {
m_ext = e;
Q_EMIT extensionChanged();
}
}
Q_SIGNALS:
void extensionChanged();
};
class FactorySingleton : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(int foo READ foo CONSTANT)
public:
static FactorySingleton *create(QQmlEngine *, QJSEngine *)
{
return new FactorySingleton;
}
int foo() const { return 314; }
private:
FactorySingleton() = default;
};
class ExtendedSingleton : public QObject {
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
QML_EXTENDED(Extension)
Q_PROPERTY(int foo READ foo CONSTANT)
public:
int foo() const { return 315; }
};
class NamespaceExtendedSingleton : public QObject {
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
QML_EXTENDED_NAMESPACE(ExtensionNamespace)
Q_PROPERTY(int foo READ foo CONSTANT)
public:
int foo() const { return 316; }
};
class ForeignSingleton : public QObject {
Q_OBJECT
Q_PROPERTY(int number READ number WRITE setnumber NOTIFY numberchanged)
public:
ForeignSingleton(QObject *parent = nullptr) : QObject(parent) {};
int number() { return m_number; }
void setnumber(int number) { m_number = number; }
static ForeignSingleton *obtain() { return new ForeignSingleton; }
signals:
void numberchanged();
private:
int m_number = 0;
};
class WrapperSingleton : public QObject {
Q_OBJECT
QML_NAMED_ELEMENT(ForeignSingleton)
QML_FOREIGN(ForeignSingleton)
QML_SINGLETON
public:
static ForeignSingleton* create(QQmlEngine *, QJSEngine *) {
ForeignSingleton *singleton = ForeignSingleton::obtain();
singleton->setnumber(42);
return singleton;
}
private:
WrapperSingleton() = default;
};
class ExtensionA : public QObject
{
Q_OBJECT
QML_ANONYMOUS
Q_PROPERTY(int a READ a CONSTANT)
Q_PROPERTY(int c READ c CONSTANT)
Q_PROPERTY(int d READ d CONSTANT)
Q_PROPERTY(int f READ f CONSTANT)
Q_PROPERTY(int g READ g CONSTANT)
public:
ExtensionA(QObject *parent = nullptr) : QObject(parent) {}
int a() const { return 'a'; }
int c() const { return 11; }
int d() const { return 21; }
int f() const { return 31; }
int g() const { return 41; }
};
class ExtensionB : public QObject
{
Q_OBJECT
QML_ANONYMOUS
Q_PROPERTY(int b READ b CONSTANT)
Q_PROPERTY(int c READ c CONSTANT)
Q_PROPERTY(int d READ d CONSTANT)
public:
ExtensionB(QObject *parent = nullptr) : QObject(parent) {}
int b() const { return 'b'; }
int c() const { return 12; }
int d() const { return 22; }
};
class IndirectExtensionB : public ExtensionB
{
Q_OBJECT
QML_ANONYMOUS
public:
IndirectExtensionB(QObject *parent = nullptr) : ExtensionB(parent) { }
};
class MultiExtensionParent : public QObject
{
Q_OBJECT
QML_ANONYMOUS
QML_EXTENDED(ExtensionA)
Q_PROPERTY(int p READ p CONSTANT)
Q_PROPERTY(int c READ c CONSTANT)
Q_PROPERTY(int f READ f CONSTANT)
public:
MultiExtensionParent(QObject *parent = nullptr) : QObject(parent) {}
int p() const { return 'p'; }
int c() const { return 13; }
int f() const { return 33; }
};
class MultiExtension : public MultiExtensionParent
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED(ExtensionB)
Q_PROPERTY(int e READ e CONSTANT)
Q_PROPERTY(int c READ c CONSTANT)
Q_PROPERTY(int g READ g CONSTANT)
public:
MultiExtension(QObject *parent = nullptr) : MultiExtensionParent(parent) {}
int e() const { return 'e'; }
int c() const { return 14; }
int g() const { return 44; }
};
class MultiExtensionIndirect : public MultiExtensionParent
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED(IndirectExtensionB)
Q_PROPERTY(int b READ b CONSTANT) // won't be able to use ExtensionB, so provide own property
Q_PROPERTY(int e READ e CONSTANT)
Q_PROPERTY(int c READ c CONSTANT)
Q_PROPERTY(int g READ g CONSTANT)
public:
MultiExtensionIndirect(QObject *parent = nullptr) : MultiExtensionParent(parent) { }
int b() const { return 77; }
int e() const { return 'e'; }
int c() const { return 'c'; }
int g() const { return 44; }
};
class ExtendedInParent : public MultiExtensionParent
{
Q_OBJECT
QML_ELEMENT
// properties from base type: p, c, f
// properties from base type's extension: a, c, d, f, g
Q_PROPERTY(int c READ c CONSTANT) // be evil: overwrite base type extension's property
public:
ExtendedInParent(QObject *parent = nullptr) : MultiExtensionParent(parent) { }
int c()
{
Q_UNREACHABLE_RETURN(1111);
}
};
class ExtendedByIndirect : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED(IndirectExtensionB)
// properties from extension's base type: b, c, d
public:
ExtendedByIndirect(QObject *parent = nullptr) : QObject(parent) { }
};
class ExtendedInParentByIndirect : public ExtendedByIndirect
{
Q_OBJECT
QML_ELEMENT
// properties from base type's extension's base type: b, c, d
public:
ExtendedInParentByIndirect(QObject *parent = nullptr) : ExtendedByIndirect(parent) { }
};
class MultiExtensionThreeExtensions : public MultiExtension
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED(Extension)
public:
MultiExtensionThreeExtensions(QObject *parent = nullptr) : MultiExtension(parent) { }
};
class MultiExtensionWithoutExtension : public MultiExtension
{
Q_OBJECT
QML_ANONYMOUS
public:
MultiExtensionWithoutExtension(QObject *parent = nullptr) : MultiExtension(parent) { }
};
class MultiExtensionWithExtensionInBaseBase : public MultiExtensionWithoutExtension
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED(Extension)
public:
MultiExtensionWithExtensionInBaseBase(QObject *parent = nullptr)
: MultiExtensionWithoutExtension(parent)
{
}
};
class RevisionedExtension : public QObject
{
Q_OBJECT
Q_PROPERTY(int extension READ extension WRITE setExtension REVISION(1, 0))
public:
RevisionedExtension(QObject *parent = nullptr) : QObject(parent) {}
int extension() const { return m_ext; }
void setExtension(int e) { m_ext = e; }
private:
int m_ext = 42;
};
class ExtendedWithRevisionOld : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED(RevisionedExtension)
QML_ADDED_IN_VERSION(0, 5)
public:
ExtendedWithRevisionOld(QObject *parent = nullptr) : QObject(parent) { }
};
class ExtendedWithRevisionNew : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED(RevisionedExtension)
QML_ADDED_IN_VERSION(1, 0)
public:
ExtendedWithRevisionNew(QObject *parent = nullptr) : QObject(parent) { }
};
class MyExtendedGroupedObject : public MyGroupedObject
{
Q_OBJECT
QML_ANONYMOUS
QML_EXTENDED(Extension)
Q_PROPERTY(int value2 READ value2 WRITE setValue2)
int m_value2 = 0;
public:
int value2() const { return m_value2; }
void setValue2(int v) { m_value2 = v; }
};
class ExtendedInGroup : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(MyExtendedGroupedObject *group READ group)
MyExtendedGroupedObject m_group;
public:
ExtendedInGroup(QObject *parent = nullptr) : QObject(parent) { }
MyExtendedGroupedObject *group() { return &m_group; }
};
class StringSignaler : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
StringSignaler(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void call() { emit signal(QJSValue("Hello world!")); }
signals:
void signal(QJSValue value);
};
class EnumList : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
enum Enum { Alpha, Beta, Gamma };
Q_ENUM(Enum)
Q_INVOKABLE QList<EnumList::Enum> list() const { return { Alpha, Beta, Gamma }; }
};
class ValueTypeWithEnum1
{
Q_GADGET
Q_PROPERTY(ValueTypeWithEnum1::Quality quality READ quality WRITE setQuality)
public:
enum Quality
{
VeryLowQuality,
LowQuality,
NormalQuality,
HighQuality,
VeryHighQuality
};
Q_ENUM(Quality)
Quality quality() const { return m_quality; }
void setQuality(Quality quality) { m_quality = quality; }
private:
Quality m_quality = HighQuality;
};
class ObjectTypeHoldingValueType1 : public QObject
{
Q_OBJECT
Q_PROPERTY(ValueTypeWithEnum1 vv READ vv WRITE setVv NOTIFY vvChanged)
Q_PROPERTY(ValueTypeWithEnum1::Quality q READ q CONSTANT)
public:
ValueTypeWithEnum1 vv() const
{
return m_vv;
}
void setVv(ValueTypeWithEnum1 vv)
{
if (m_vv.quality() == vv.quality())
return;
m_vv = vv;
emit vvChanged(m_vv);
}
ValueTypeWithEnum1::Quality q() const { return m_vv.quality(); }
signals:
void vvChanged(ValueTypeWithEnum1 vv);
private:
ValueTypeWithEnum1 m_vv;
};
struct ValueTypeWithEnumForeign1
{
Q_GADGET
QML_FOREIGN(ValueTypeWithEnum1)
QML_NAMED_ELEMENT(valueTypeWithEnum1)
};
namespace ValueTypeWithEnumForeignNamespace1
{
Q_NAMESPACE
QML_FOREIGN_NAMESPACE(ValueTypeWithEnum1)
QML_NAMED_ELEMENT(ValueTypeWithEnum1)
};
struct ObjectTypeHoldingValueTypeForeign1
{
Q_GADGET
QML_FOREIGN(ObjectTypeHoldingValueType1)
QML_NAMED_ELEMENT(ObjectTypeHoldingValueType1)
};
class ValueTypeWithEnum2
{
Q_GADGET
Q_PROPERTY(ValueTypeWithEnum2::Quality quality READ quality WRITE setQuality)
public:
enum Quality
{
VeryLowQuality,
LowQuality,
NormalQuality,
HighQuality,
VeryHighQuality
};
Q_ENUM(Quality)
Quality quality() const { return m_quality; }
void setQuality(Quality quality) { m_quality = quality; }
private:
Quality m_quality = HighQuality;
};
class ObjectTypeHoldingValueType2 : public QObject
{
Q_OBJECT
Q_PROPERTY(ValueTypeWithEnum2 vv READ vv WRITE setVv NOTIFY vvChanged)
Q_PROPERTY(ValueTypeWithEnum2::Quality q READ q CONSTANT)
Q_CLASSINFO("RegisterEnumsFromRelatedTypes", "false")
public:
ValueTypeWithEnum2 vv() const
{
return m_vv;
}
void setVv(ValueTypeWithEnum2 vv)
{
if (m_vv.quality() == vv.quality())
return;
m_vv = vv;
emit vvChanged(m_vv);
}
ValueTypeWithEnum2::Quality q() const { return m_vv.quality(); }
signals:
void vvChanged(ValueTypeWithEnum2 vv);
private:
ValueTypeWithEnum2 m_vv;
};
struct ValueTypeWithEnumForeign2
{
Q_GADGET
QML_FOREIGN(ValueTypeWithEnum2)
QML_NAMED_ELEMENT(valueTypeWithEnum2)
};
namespace ValueTypeWithEnumForeignNamespace2
{
Q_NAMESPACE
QML_FOREIGN_NAMESPACE(ValueTypeWithEnum2)
QML_NAMED_ELEMENT(ValueTypeWithEnum2)
};
struct ObjectTypeHoldingValueTypeForeign2
{
Q_GADGET
QML_FOREIGN(ObjectTypeHoldingValueType2)
QML_NAMED_ELEMENT(ObjectTypeHoldingValueType2)
};
struct Large {
Q_GADGET
QML_VALUE_TYPE(large)
Q_PROPERTY(uint a MEMBER a)
Q_PROPERTY(uint b MEMBER b)
Q_PROPERTY(uint c MEMBER c)
Q_PROPERTY(uint d MEMBER d)
Q_PROPERTY(uint e MEMBER e)
Q_PROPERTY(uint f MEMBER f)
public:
quint64 a;
quint64 b;
quint64 c;
quint64 d;
quint64 e;
quint64 f;
};
inline bool operator==(const Large &a, const Large &b)
{
return a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d && a.e == b.e && a.f == b.f;
}
inline bool operator!=(const Large &a, const Large &b) { return !(a == b); }
class Foo: public QObject {
Q_OBJECT
Q_PROPERTY(QVariantList fooProperty READ getList WRITE setList)
Q_PROPERTY(Large a MEMBER a BINDABLE aBindable)
Q_PROPERTY(Large b MEMBER b BINDABLE bBindable)
QML_ELEMENT
public:
QVariantList getList() const { return mFooProperty;}
void setList(QVariantList list) { mFooProperty = list;}
QBindable<Large> aBindable() { return QBindable<Large>(&a); }
QBindable<Large> bBindable() { return QBindable<Large>(&b); }
private:
QProperty<Large> a;
QProperty<Large> b;
QVariantList mFooProperty;
};
struct BaseValueType
{
Q_GADGET
Q_PROPERTY(int content READ content WRITE setContent)
QML_VALUE_TYPE(base)
public:
Q_INVOKABLE void increment() { ++m_content; }
Q_INVOKABLE QString report() const { return QString::number(m_content); }
int content() const { return m_content; }
void setContent(int content) { m_content = content; }
private:
int m_content = 27;
};
struct DerivedValueType : public BaseValueType
{
Q_GADGET
QML_VALUE_TYPE(derived)
public:
DerivedValueType() { increment(); }
Q_INVOKABLE int nothing() const { return m_nothing; }
private:
int m_nothing = 12;
};
class ItemAttached : public QObject
{
Q_OBJECT
Q_PROPERTY(QString attachedName READ attachedName WRITE setAttachedName NOTIFY attachedNameChanged)
QML_ELEMENT
QML_ATTACHED(ItemAttached)
public:
ItemAttached(QObject *parent = nullptr) : QObject(parent) {}
QString attachedName() const { return m_name; }
void setAttachedName(const QString &name)
{
if (name != m_name) {
m_name = name;
emit attachedNameChanged();
}
}
static ItemAttached *qmlAttachedProperties(QObject *object)
{
if (object->objectName() != QLatin1String("foo")) {
qWarning("Only foo can have ItemAttached!");
return nullptr;
}
return new ItemAttached(object);
}
signals:
void attachedNameChanged();
private:
QString m_name;
};
class BindableOnly : public QObject
{
Q_OBJECT
Q_PROPERTY(int score BINDABLE scoreBindable READ default WRITE default FINAL)
Q_PROPERTY(QByteArray data READ default WRITE default BINDABLE dataBindable FINAL)
QML_ELEMENT
public:
BindableOnly(QObject *parent = nullptr)
: QObject(parent)
, m_score(4)
{}
QBindable<int> scoreBindable() { return QBindable<int>(&m_score); }
QBindable<QByteArray> dataBindable() { return QBindable<QByteArray>(&m_data); }
private:
QProperty<int> m_score;
QProperty<QByteArray> m_data;
};
void registerTypes();
class AttachMe : public QObject
{
Q_OBJECT
Q_PROPERTY(bool abc READ abc WRITE setAbc NOTIFY abcChanged)
QML_ANONYMOUS
bool m_abc;
signals:
void abcChanged();
public:
AttachMe(QObject *parent) : QObject(parent) { }
bool abc() const { return m_abc; }
void setAbc(bool abc) { m_abc = abc; }
};
class AnotherAttachMe : public QObject
{
Q_OBJECT
Q_PROPERTY(QString anotherAbc READ anotherAbc WRITE setAnotherAbc NOTIFY anotherAbcChanged)
QML_ANONYMOUS
QString m_anotherAbc;
signals:
void anotherAbcChanged();
public:
AnotherAttachMe(QObject *parent) : QObject(parent) { }
QString anotherAbc() const { return m_anotherAbc; }
void setAnotherAbc(const QString &abc) { m_anotherAbc = abc; }
};
class OriginalQmlAttached : public QObject
{
Q_OBJECT
QML_ATTACHED(AttachMe)
QML_ELEMENT
public:
static AttachMe *qmlAttachedProperties(QObject *object) { return new AttachMe(object); }
};
class LeakingQmlAttached : public OriginalQmlAttached
{
Q_OBJECT
QML_ELEMENT
};
class DerivedQmlAttached : public OriginalQmlAttached
{
Q_OBJECT
QML_ELEMENT
QML_ATTACHED(AnotherAttachMe)
public:
static AnotherAttachMe *qmlAttachedProperties(QObject *object)
{
return new AnotherAttachMe(object);
}
};
class OriginalSingleton : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
private:
Q_PROPERTY(QString abc READ abc WRITE setAbc NOTIFY abcChanged)
QString m_abc;
signals:
void abcChanged(const QString &);
public:
Q_INVOKABLE int mm() { return 5; }
QString abc() const { return m_abc; }
void setAbc(const QString &abc)
{
m_abc = abc;
emit abcChanged(abc);
}
};
class LeakingSingleton : public OriginalSingleton
{
Q_OBJECT
QML_ELEMENT
};
class DerivedSingleton : public OriginalSingleton
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(QString anotherAbc READ anotherAbc WRITE setAnotherAbc NOTIFY anotherAbcChanged)
QString m_anotherAbc;
signals:
void anotherAbcChanged(const QString &);
public:
QString anotherAbc() const { return m_anotherAbc; }
void setAnotherAbc(const QString &abc)
{
m_anotherAbc = abc;
emit anotherAbcChanged(abc);
}
};
class Foreigner : public QObject
{
Q_OBJECT
private:
Q_PROPERTY(QString abc READ abc WRITE setAbc NOTIFY abcChanged)
QString m_abc;
signals:
void abcChanged(const QString &);
public:
QString abc() const { return m_abc; }
void setAbc(const QString &abc)
{
m_abc = abc;
emit abcChanged(abc);
}
};
class ForeignerForeign
{
Q_GADGET
QML_ELEMENT
QML_FOREIGN(Foreigner)
};
class LeakingForeignerForeign : public QObject, public ForeignerForeign
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QString anotherAbc READ anotherAbc WRITE setAnotherAbc NOTIFY anotherAbcChanged)
QString m_anotherAbc;
signals:
void anotherAbcChanged(const QString &);
public:
QString anotherAbc() const { return m_anotherAbc; }
void setAnotherAbc(const QString &abc)
{
m_anotherAbc = abc;
emit anotherAbcChanged(abc);
}
};
struct ForeignNamespace
{
Q_GADGET
public:
enum Abc { A, B, C, D };
Q_ENUM(Abc)
};
class ForeignNamespaceForeign
{
Q_GADGET
QML_ELEMENT
QML_FOREIGN_NAMESPACE(ForeignNamespace)
};
class LeakingForeignNamespaceForeign : public QObject, public ForeignNamespaceForeign
{
Q_OBJECT
QML_ELEMENT
public:
enum AnotherAbc { D, C, B, A };
Q_ENUM(AnotherAbc)
};
struct ValueTypeWithLength
{
Q_GADGET
QML_VALUE_TYPE(withLength)
QML_CONSTRUCTIBLE_VALUE
Q_PROPERTY(int length READ length CONSTANT)
public:
ValueTypeWithLength() = default;
Q_INVOKABLE ValueTypeWithLength(int length) : m_length(length) {}
Q_INVOKABLE QString toString() const { return QStringLiteral("no"); }
int length() const { return m_length; }
private:
int m_length = 19;
};
struct ValueTypeWithString
{
Q_GADGET
QML_VALUE_TYPE(withString)
QML_CONSTRUCTIBLE_VALUE
public:
Q_INVOKABLE ValueTypeWithString(const QString &v = QString()) : m_string(v) {}
QString toString() const { return m_string; }
private:
QString m_string;
};
class GetterObject : public QObject {
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
public:
explicit GetterObject(QObject *parent = nullptr) : QObject{parent} {}
// always returns a 0 as uint64_t
Q_INVOKABLE uint64_t getFalse() const { return 0; }
Q_INVOKABLE uint64_t getTrue() const { return 1; }
Q_INVOKABLE quint64 getQFalse() const { return 0; }
Q_INVOKABLE quint64 getQTrue() const { return 1; }
};
class EnumProviderSingleton : public QObject {
Q_OBJECT
public:
enum class Expected {
Value = 42
};
Q_ENUM(Expected)
EnumProviderSingleton(QObject* parent = nullptr) : QObject(parent) {}
};
class EnumProviderSingletonQml {
Q_GADGET
QML_FOREIGN(EnumProviderSingleton)
QML_NAMED_ELEMENT(EnumProviderSingleton)
QML_SINGLETON
public:
static EnumProviderSingleton* create(QQmlEngine*, QJSEngine*) {
return new EnumProviderSingleton();
}
private:
EnumProviderSingletonQml() = default;
};
namespace TypedEnums {
Q_NAMESPACE
QML_ELEMENT
enum E8S : qint8 {
E8SA = std::numeric_limits<qint8>::min(),
E8SB = -5,
E8SC = -1,
E8SD = 0,
E8SE = 1,
E8SF = 5,
E8SG = std::numeric_limits<qint8>::max(),
};
Q_ENUM_NS(E8S);
enum E8U : quint8 {
E8UA = 0,
E8UB = 1,
E8UC = 5,
E8UD = 1 << 7,
E8UE = std::numeric_limits<quint8>::max(),
};
Q_ENUM_NS(E8U);
enum E16S : qint16 {
E16SA = std::numeric_limits<qint16>::min(),
E16SB = -5,
E16SC = -1,
E16SD = 0,
E16SE = 1,
E16SF = 5,
E16SG = std::numeric_limits<qint16>::max(),
};
Q_ENUM_NS(E16S);
enum E16U : quint16 {
E16UA = 0,
E16UB = 1,
E16UC = 5,
E16UD = 1 << 15,
E16UE = std::numeric_limits<quint16>::max(),
};
Q_ENUM_NS(E16U);
enum E32S : qint32 {
E32SA = std::numeric_limits<qint32>::min(),
E32SB = -5,
E32SC = -1,
E32SD = 0,
E32SE = 1,
E32SF = 5,
E32SG = std::numeric_limits<qint32>::max(),
};
Q_ENUM_NS(E32S);
enum E32U : quint32 {
E32UA = 0,
E32UB = 1,
E32UC = 5,
E32UD = 1u << 31,
E32UE = std::numeric_limits<quint32>::max(),
};
Q_ENUM_NS(E32U);
enum E64S : qint64 {
E64SA = std::numeric_limits<qint64>::min(),
E64SB = -5,
E64SC = -1,
E64SD = 0,
E64SE = 1,
E64SF = 5,
E64SG = std::numeric_limits<qint64>::max(),
};
Q_ENUM_NS(E64S);
enum E64U : quint64 {
E64UA = 0,
E64UB = 1,
E64UC = 5,
E64UD = 1ull << 63,
E64UE = std::numeric_limits<quint64>::max(),
};
Q_ENUM_NS(E64U);
}
class GadgetWithEnums
{
Q_GADGET
QML_VALUE_TYPE(gadgetWithEnums)
Q_PROPERTY(TypedEnums::E8S e8s MEMBER m_e8s);
Q_PROPERTY(TypedEnums::E8U e8u MEMBER m_e8u);
Q_PROPERTY(TypedEnums::E16S e16s MEMBER m_e16s);
Q_PROPERTY(TypedEnums::E16U e16u MEMBER m_e16u);
Q_PROPERTY(TypedEnums::E32S e32s MEMBER m_e32s);
Q_PROPERTY(TypedEnums::E32U e32u MEMBER m_e32u);
Q_PROPERTY(TypedEnums::E64S e64s MEMBER m_e64s);
Q_PROPERTY(TypedEnums::E64U e64u MEMBER m_e64u);
public:
TypedEnums::E8S m_e8s = {};
TypedEnums::E8U m_e8u = {};
TypedEnums::E16S m_e16s = {};
TypedEnums::E16U m_e16u = {};
TypedEnums::E32S m_e32s = {};
TypedEnums::E32U m_e32u = {};
TypedEnums::E64S m_e64s = {};
TypedEnums::E64U m_e64u = {};
private:
friend bool operator==(const GadgetWithEnums &a, const GadgetWithEnums &b)
{
return a.m_e8s == b.m_e8s && a.m_e8u == b.m_e8u && a.m_e16s == b.m_e16s
&& a.m_e16u == b.m_e16u && a.m_e32s == b.m_e32s && a.m_e32u == b.m_e32u
&& a.m_e64s == b.m_e64s && a.m_e64u == b.m_e64u;
}
friend bool operator!=(const GadgetWithEnums &a, const GadgetWithEnums &b)
{
return !(a == b);
}
};
class ObjectWithEnums : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(TypedEnums::E8S e8s MEMBER m_e8s NOTIFY changed);
Q_PROPERTY(TypedEnums::E8U e8u MEMBER m_e8u NOTIFY changed);
Q_PROPERTY(TypedEnums::E16S e16s MEMBER m_e16s NOTIFY changed);
Q_PROPERTY(TypedEnums::E16U e16u MEMBER m_e16u NOTIFY changed);
Q_PROPERTY(TypedEnums::E32S e32s MEMBER m_e32s NOTIFY changed);
Q_PROPERTY(TypedEnums::E32U e32u MEMBER m_e32u NOTIFY changed);
Q_PROPERTY(TypedEnums::E64S e64s MEMBER m_e64s NOTIFY changed);
Q_PROPERTY(TypedEnums::E64U e64u MEMBER m_e64u NOTIFY changed);
Q_PROPERTY(GadgetWithEnums g MEMBER m_g NOTIFY changed);
public:
ObjectWithEnums(QObject *parent = nullptr) : QObject(parent) {}
TypedEnums::E8S m_e8s = {};
TypedEnums::E8U m_e8u = {};
TypedEnums::E16S m_e16s = {};
TypedEnums::E16U m_e16u = {};
TypedEnums::E32S m_e32s = {};
TypedEnums::E32U m_e32u = {};
TypedEnums::E64S m_e64s = {};
TypedEnums::E64U m_e64u = {};
GadgetWithEnums m_g;
Q_SIGNALS:
void changed();
};
struct UnregisteredValueBaseType
{
int foo = 12;
};
struct UnregisteredValueDerivedType: public UnregisteredValueBaseType
{
int bar = 13;
};
struct GadgetedValueBaseType
{
Q_GADGET
int foo = 12;
};
struct GadgetedValueDerivedType: public GadgetedValueBaseType
{
Q_GADGET
int bar = 13;
};
class UnregisteredValueTypeHandler: public QObject
{
Q_OBJECT
QML_ELEMENT
public:
int consumed = 0;
int gadgeted = 0;
public slots:
UnregisteredValueBaseType produce() { return UnregisteredValueBaseType(); }
UnregisteredValueDerivedType produceDerived() { return UnregisteredValueDerivedType(); }
void consume(UnregisteredValueBaseType) { ++consumed; }
GadgetedValueDerivedType produceGadgeted() { return GadgetedValueDerivedType(); }
void consume(GadgetedValueBaseType) { ++gadgeted; }
};
class Greeter : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
Greeter(QObject *parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void greet()
{
qDebug().noquote() << objectName() << "says hello";
}
Q_INVOKABLE void sum(int a, int b)
{
qDebug().noquote() << objectName() << QString("says %1 + %2 = %3").arg(a).arg(b).arg(a + b);
}
};
class Attachment : public QObject {
Q_OBJECT
public:
Attachment(QObject *parent = nullptr) : QObject(parent) {}
};
class AttachedInCtor : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_ATTACHED(Attachment)
public:
AttachedInCtor(QObject *parent = nullptr)
: QObject(parent)
{
attached = qmlAttachedPropertiesObject<AttachedInCtor>(this, true);
}
static Attachment *qmlAttachedProperties(QObject *object) {
return new Attachment(object);
}
QObject *attached = nullptr;
};
class BirthdayParty : public QObject
{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<QObject> guests READ guests)
Q_CLASSINFO("DefaultProperty", "guests")
QML_ELEMENT
public:
using QObject::QObject;
QQmlListProperty<QObject> guests() { return {this, &m_guests}; }
qsizetype guestCount() const { return m_guests.count(); }
QObject *guest(qsizetype i) const { return m_guests.at(i); }
private:
QList<QObject *> m_guests;
};
class ByteArrayReceiver : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
QList<QByteArray> byteArrays;
Q_INVOKABLE void byteArrayTest(const QByteArray &ba)
{
byteArrays.push_back(ba);
}
};
class CounterAttachedBaseType: public QObject
{
Q_OBJECT
QML_ANONYMOUS
Q_PROPERTY (int value READ value NOTIFY valueChanged)
public:
CounterAttachedBaseType(QObject *parent = nullptr) : QObject(parent) {}
int value() { return m_value; }
Q_SIGNAL void valueChanged();
protected:
int m_value = 98;
};
class CounterAttachedType: public CounterAttachedBaseType
{
Q_OBJECT
QML_ANONYMOUS
public:
CounterAttachedType(QObject *parent = nullptr) : CounterAttachedBaseType(parent) {}
Q_INVOKABLE void increase() {
++m_value;
Q_EMIT valueChanged();
}
};
class Counter : public QObject
{
Q_OBJECT
QML_ATTACHED(CounterAttachedBaseType)
QML_ELEMENT
public:
static CounterAttachedBaseType *qmlAttachedProperties(QObject *o)
{
return new CounterAttachedType(o);
}
};
class Singleton: public QObject
{
Q_OBJECT
Q_PROPERTY(EnumType enumProperty READ enumProperty CONSTANT)
Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
QML_ELEMENT
QML_SINGLETON
public:
explicit Singleton(QObject* parent = nullptr) : QObject(parent) {}
enum class EnumType {
EnumValue1,
EnumValue2
};
Q_ENUM(EnumType);
EnumType enumProperty() const {
return EnumType::EnumValue2;
}
};
class NonSingleton: public QObject
{
Q_OBJECT
Q_PROPERTY(EnumType enumProperty READ enumProperty CONSTANT)
Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
QML_ELEMENT
public:
explicit NonSingleton(QObject* parent = nullptr) : QObject(parent) {}
enum class EnumType {
EnumValue1,
EnumValue2
};
Q_ENUM(EnumType);
EnumType enumProperty() const {
return EnumType::EnumValue2;
}
};
class TypeWithQJsonArrayProperty : public QObject {
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QJsonArray jsonArray READ jsonArray WRITE setJsonArray NOTIFY jsonArrayChanged)
public:
TypeWithQJsonArrayProperty(QObject *parent = nullptr) : QObject(parent) {}
const QJsonArray& jsonArray() { return m_jsonArray; }
void setJsonArray(const QJsonArray& a) { m_jsonArray = a; }
signals:
void jsonArrayChanged();
private:
QJsonArray m_jsonArray;
};
class InvokableSingleton : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
public:
InvokableSingleton() = default;
Q_INVOKABLE InvokableSingleton(int a, QObject *parent) : QObject(parent), m_a(a) {}
int m_a = 0;
};
class InvokableExtension : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE InvokableExtension(QObject *parent = nullptr) : QObject(parent) {}
};
class InvokableExtended : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_EXTENDED(InvokableExtension)
public:
Q_INVOKABLE InvokableExtended() = default;
};
class InvokableUncreatable : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("no")
public:
Q_INVOKABLE InvokableUncreatable() = default;
};
class InvokableValueType
{
Q_GADGET
QML_VALUE_TYPE(vv)
public:
Q_INVOKABLE InvokableValueType() = default;
Q_INVOKABLE InvokableValueType(const QString &s) : m_s(s) {}
QString m_s;
};
class NestedVectors : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
NestedVectors(QObject *parent = nullptr) : QObject(parent)
{
std::vector<int> data;
data.push_back(1);
data.push_back(2);
data.push_back(3);
m_list.push_back(data);
data.clear();
data.push_back(4);
data.push_back(5);
m_list.push_back(data);
}
Q_INVOKABLE std::vector<std::vector<int>> getList()
{
return m_list;
}
Q_INVOKABLE void setList(std::vector<std::vector<int>> list)
{
m_list = list;
}
private:
std::vector<std::vector<int>> m_list;
};
class VariantAssociationProvider : public QObject {
Q_OBJECT
Q_PROPERTY(QVariantMap variantMap READ getMap WRITE setMap)
Q_PROPERTY(QVariantHash variantHash READ getHash WRITE setHash)
QML_ELEMENT
QVariantMap m_variantMap;
QVariantHash m_variantHash;
public:
VariantAssociationProvider(QObject* parent = nullptr) : QObject(parent)
{}
QVariantMap getMap() { return m_variantMap; }
void setMap(const QVariantMap& map) { m_variantMap = map; }
QVariantHash getHash() { return m_variantHash; }
void setHash(const QVariantHash& hash) { m_variantHash = hash; }
Q_INVOKABLE QVariantList getListOfMap() const {
return QVariantList{
QVariantMap{},
QVariantMap{ { "email", "Alice Smith"} }
};
}
Q_INVOKABLE QVariantList getListOfHash() const {
return QVariantList{
QVariantHash{},
QVariantHash{ { "email", "Alice Smith"} }
};
}
};
namespace YepNamespaceA {
class YepAttached : public QObject
{
Q_OBJECT
QML_ANONYMOUS
public:
YepAttached(QObject *parent) : QObject(parent) { }
Q_INVOKABLE QString s() const { return QStringLiteral("StaticTest Attached Type"); }
};
class Yep : public QObject
{
Q_OBJECT
QML_ATTACHED(YepAttached)
QML_ELEMENT
public:
static YepAttached *qmlAttachedProperties(QObject *object) { return new YepAttached(object); }
};
class YepSingleton : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
public:
Q_INVOKABLE QString s() const { return QStringLiteral("StaticTest Singleton"); }
};
class MyObject : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
Q_INVOKABLE QString s() const { return QStringLiteral("StaticTest"); }
};
} // namespace YepNamespaceA
class BindablePoint : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(QPointF point BINDABLE bindablePoint READ default WRITE default)
public:
BindablePoint(QObject *parent = nullptr) : QObject(parent), m_point(QPointF(101, 102)) {}
QBindable<QPointF> bindablePoint() { return QBindable<QPointF>(&m_point); }
private:
QProperty<QPointF> m_point;
};
class LargeRevisionBase : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(int c MEMBER m_c CONSTANT)
Q_PROPERTY(int d MEMBER m_d CONSTANT)
public:
int m_c = 11;
int m_d = 12;
};
class LargeRevision : public LargeRevisionBase
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(int a MEMBER m_a CONSTANT REVISION(1, 12))
Q_PROPERTY(int b MEMBER m_b CONSTANT REVISION(12, 12))
Q_PROPERTY(int c MEMBER m_c CONSTANT REVISION(1, 12))
Q_PROPERTY(int d MEMBER m_d CONSTANT REVISION(12, 12))
public:
int m_a = 13;
int m_b = 14;
int m_c = 15;
int m_d = 16;
};
#endif // TESTTYPES_H
|