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
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qmldom.h"
#include "qmldom_p.h"
#include "private/qmlcompiler_p.h"
#include "private/qmlengine_p.h"
#include <QtCore/QByteArray>
#include <QtCore/QDebug>
#include <QtCore/QString>
#include "qmlscriptparser_p.h"
QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(compilerDump, QML_COMPILER_DUMP)
QmlDomDocumentPrivate::QmlDomDocumentPrivate()
: root(0)
{
}
QmlDomDocumentPrivate::QmlDomDocumentPrivate(const QmlDomDocumentPrivate &other)
: QSharedData(other), root(0)
{
root = other.root;
if (root) root->addref();
}
QmlDomDocumentPrivate::~QmlDomDocumentPrivate()
{
if (root) root->release();
}
/*!
\class QmlDomDocument
\internal
\brief The QmlDomDocument class represents the root of a QML document
A QML document is a self-contained snippet of QML, usually contained in a
single file. Each document has a version number, accessible through
QmlDomDocument::version(), and a root object, accessible through
QmlDomDocument::rootObject().
The QmlDomDocument class allows the programmer to load a QML document, by
calling QmlDomDocument::load(), manipulate it and save it to textual form
by calling QmlDomDocument::save(). By using the QML DOM API, editors can
non-destructively modify a QML document even if they only understand a
subset of the total QML functionality.
The following example loads a QML file from disk, and prints out its root
object type and the properties assigned in the root object.
\code
QFile file(inputFileName);
file.open(QIODevice::ReadOnly);
QByteArray xmlData = file.readAll();
QDomDocument document;
document.load(xmlData);
QDomObject rootObject = document.rootObject();
qDebug() << rootObject.objectType();
foreach(QmlDomProperty property, rootObject.properties())
qDebug() << property.propertyName();
\endcode
*/
/*!
Construct an empty QmlDomDocument.
*/
QmlDomDocument::QmlDomDocument()
: d(new QmlDomDocumentPrivate)
{
}
/*!
Create a copy of \a other QmlDomDocument.
*/
QmlDomDocument::QmlDomDocument(const QmlDomDocument &other)
: d(other.d)
{
}
/*!
Destroy the QmlDomDocument
*/
QmlDomDocument::~QmlDomDocument()
{
}
/*!
Assign \a other to this QmlDomDocument.
*/
QmlDomDocument &QmlDomDocument::operator=(const QmlDomDocument &other)
{
d = other.d;
return *this;
}
/*!
Return the version number of the Qml document. Currently only version
1 exists.
*/
int QmlDomDocument::version() const
{
return 1;
}
/*!
Returns all import statements in qml.
*/
QList<QmlDomImport> QmlDomDocument::imports() const
{
return d->imports;
}
/*!
Loads a QmlDomDocument from \a data. \a data should be valid QML
data. On success, true is returned. If the \a data is malformed, false
is returned and QmlDomDocument::loadError() contains an error description.
\sa QmlDomDocument::save() QmlDomDocument::loadError()
*/
bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl &url)
{
Q_UNUSED(engine);
d->errors.clear();
d->imports.clear();
QmlCompiledData component;
QmlCompiler compiler;
QmlCompositeTypeData *td = ((QmlEnginePrivate *)QmlEnginePrivate::get(engine))->typeManager.getImmediate(data, url);
if(td->status == QmlCompositeTypeData::Error) {
d->errors = td->errors;
td->release();
return false;
} else if(td->status == QmlCompositeTypeData::Waiting) {
QmlError error;
error.setDescription(QLatin1String("QmlDomDocument supports local types only"));
d->errors << error;
td->release();
return false;
}
compiler.compile(engine, td, &component);
if (compiler.isError()) {
d->errors = compiler.errors();
td->release();
return false;
}
for (int i = 0; i < td->data.imports().size(); ++i) {
QmlScriptParser::Import parserImport = td->data.imports().at(i);
QmlDomImport domImport;
domImport.d->type = static_cast<QmlDomImportPrivate::Type>(parserImport.type);
domImport.d->uri = parserImport.uri;
domImport.d->qualifier = parserImport.qualifier;
domImport.d->version = parserImport.version;
d->imports += domImport;
}
if (td->data.tree()) {
if (compilerDump()) {
qWarning() << "-AST------------------------------------------------------------------------------";
td->data.tree()->dump();
qWarning() << "----------------------------------------------------------------------------------";
}
d->root = td->data.tree();
d->root->addref();
}
return true;
}
/*!
Returns the last load errors. The load errors will be reset after a
successful call to load().
\sa load()
*/
QList<QmlError> QmlDomDocument::errors() const
{
return d->errors;
}
/*!
Return a saved copy of the QmlDomDocument. The returned data will be valid
QML XML data.
\sa load()
*/
QByteArray QmlDomDocument::save() const
{
return QByteArray();
}
/*!
Returns the document's root object, or an invalid QmlDomObject if the
document has no root.
In the sample QML below, the root object will be the QFxItem type.
\qml
Item {
Text {
text: "Hello World"
}
}
\endqml
*/
QmlDomObject QmlDomDocument::rootObject() const
{
QmlDomObject rv;
rv.d->object = d->root;
if (rv.d->object) rv.d->object->addref();
return rv;
}
QmlDomPropertyPrivate::QmlDomPropertyPrivate()
: property(0)
{
}
QmlDomPropertyPrivate::QmlDomPropertyPrivate(const QmlDomPropertyPrivate &other)
: QSharedData(other), property(0)
{
property = other.property;
if (property) property->addref();
}
QmlDomPropertyPrivate::~QmlDomPropertyPrivate()
{
if (property) property->release();
}
QmlDomDynamicPropertyPrivate::QmlDomDynamicPropertyPrivate():
valid(false)
{
}
QmlDomDynamicPropertyPrivate::QmlDomDynamicPropertyPrivate(const QmlDomDynamicPropertyPrivate &other)
: QSharedData(other), valid(other.valid)
{
property = other.property;
if (valid && property.defaultValue) property.defaultValue->addref();
}
QmlDomDynamicPropertyPrivate::~QmlDomDynamicPropertyPrivate()
{
if (valid && property.defaultValue) property.defaultValue->release();
}
/*!
\class QmlDomProperty
\internal
\brief The QmlDomProperty class represents one property assignment in the
QML DOM tree
Properties in QML can be assigned QML \l {QmlDomValue}{values}.
\sa QmlDomObject
*/
/*!
Construct an invalid QmlDomProperty.
*/
QmlDomProperty::QmlDomProperty()
: d(new QmlDomPropertyPrivate)
{
}
/*!
Create a copy of \a other QmlDomProperty.
*/
QmlDomProperty::QmlDomProperty(const QmlDomProperty &other)
: d(other.d)
{
}
/*!
Destroy the QmlDomProperty.
*/
QmlDomProperty::~QmlDomProperty()
{
}
/*!
Assign \a other to this QmlDomProperty.
*/
QmlDomProperty &QmlDomProperty::operator=(const QmlDomProperty &other)
{
d = other.d;
return *this;
}
/*!
Return the name of this property.
\qml
Text {
x: 10
y: 10
font.bold: true
}
\endqml
As illustrated above, a property name can be a simple string, such as "x" or
"y", or a more complex "dot property", such as "font.bold". In both cases
the full name is returned ("x", "y" and "font.bold") by this method.
For dot properties, a split version of the name can be accessed by calling
QmlDomProperty::propertyNameParts().
\sa QmlDomProperty::propertyNameParts()
*/
QByteArray QmlDomProperty::propertyName() const
{
return d->propertyName;
}
/*!
Return the name of this property, split into multiple parts in the case
of dot properties.
\qml
Text {
x: 10
y: 10
font.bold: true
}
\endqml
For each of the properties shown above, this method would return ("x"),
("y") and ("font", "bold").
\sa QmlDomProperty::propertyName()
*/
QList<QByteArray> QmlDomProperty::propertyNameParts() const
{
if (d->propertyName.isEmpty()) return QList<QByteArray>();
else return d->propertyName.split('.');
}
/*!
Return true if this property is used as a default property in the QML
document.
\qml
<Text text="hello"/>
<Text>hello</Text>
\endqml
The above two examples return the same DOM tree, except that the second has
the default property flag set on the text property. Observe that whether
or not a property has isDefaultProperty set is determined by how the
property is used, and not only by whether the property is the types default
property.
*/
bool QmlDomProperty::isDefaultProperty() const
{
return d->property && d->property->isDefault;
}
/*!
Returns the QmlDomValue that is assigned to this property, or an invalid
QmlDomValue if no value is assigned.
*/
QmlDomValue QmlDomProperty::value() const
{
QmlDomValue rv;
if (d->property) {
rv.d->property = d->property;
rv.d->value = d->property->values.at(0);
rv.d->property->addref();
rv.d->value->addref();
}
return rv;
}
/*!
Sets the QmlDomValue that is assigned to this property to \a value.
*/
void QmlDomProperty::setValue(const QmlDomValue &value)
{
Q_UNUSED(value);
qWarning("QmlDomProperty::setValue(const QmlDomValue &): Not Implemented");
}
/*!
Returns the position in the input data where the property ID startd, or -1 if
the property is invalid.
*/
int QmlDomProperty::position() const
{
if (d && d->property) {
return d->property->location.range.offset;
} else
return -1;
}
/*!
Returns the length in the input data from where the property ID started upto
the end of it, or -1 if the property is invalid.
*/
int QmlDomProperty::length() const
{
if (d && d->property)
return d->property->location.range.length;
else
return -1;
}
/*!
Construct an invalid QmlDomDynamicProperty.
*/
QmlDomDynamicProperty::QmlDomDynamicProperty():
d(new QmlDomDynamicPropertyPrivate)
{
}
/*!
Create a copy of \a other QmlDomDynamicProperty.
*/
QmlDomDynamicProperty::QmlDomDynamicProperty(const QmlDomDynamicProperty &other):
d(other.d)
{
}
/*!
Destroy the QmlDomDynamicProperty.
*/
QmlDomDynamicProperty::~QmlDomDynamicProperty()
{
}
/*!
Assign \a other to this QmlDomDynamicProperty.
*/
QmlDomDynamicProperty &QmlDomDynamicProperty::operator=(const QmlDomDynamicProperty &other)
{
d = other.d;
return *this;
}
bool QmlDomDynamicProperty::isValid() const
{
return d && d->valid;
}
/*!
Return the name of this dynamic property.
\qml
Item {
property int count: 10;
}
\endqml
As illustrated above, a dynamic property name can have a name and a
default value ("10").
*/
QByteArray QmlDomDynamicProperty::propertyName() const
{
if (isValid())
return d->property.name;
else
return QByteArray();
}
int QmlDomDynamicProperty::propertyType() const
{
if (isValid()) {
switch (d->property.type) {
case QmlParser::Object::DynamicProperty::Bool:
return QMetaType::type("bool");
case QmlParser::Object::DynamicProperty::Color:
return QMetaType::type("QColor");
case QmlParser::Object::DynamicProperty::Date:
return QMetaType::type("QDateTime");
case QmlParser::Object::DynamicProperty::Int:
return QMetaType::type("int");
case QmlParser::Object::DynamicProperty::Real:
return QMetaType::type("double");
case QmlParser::Object::DynamicProperty::String:
return QMetaType::type("QString");
case QmlParser::Object::DynamicProperty::Url:
return QMetaType::type("QUrl");
case QmlParser::Object::DynamicProperty::Variant:
return QMetaType::type("QVariant");
default:
break;
}
}
return -1;
}
/*!
Return true if this property is used as a default property in the QML
document.
\qml
<Text text="hello"/>
<Text>hello</Text>
\endqml
The above two examples return the same DOM tree, except that the second has
the default property flag set on the text property. Observe that whether
or not a property has isDefaultProperty set is determined by how the
property is used, and not only by whether the property is the types default
property.
*/
bool QmlDomDynamicProperty::isDefaultProperty() const
{
if (isValid())
return d->property.isDefaultProperty;
else
return false;
}
/*!
Returns the default value as a QmlDomProperty.
*/
QmlDomProperty QmlDomDynamicProperty::defaultValue() const
{
QmlDomProperty rp;
if (isValid() && d->property.defaultValue) {
rp.d->property = d->property.defaultValue;
rp.d->property->addref();
}
return rp;
}
/*!
Returns the position in the input data where the property ID startd, or 0 if
the property is invalid.
*/
int QmlDomDynamicProperty::position() const
{
if (isValid()) {
return d->property.range.offset;
} else
return -1;
}
/*!
Returns the length in the input data from where the property ID started upto
the end of it, or 0 if the property is invalid.
*/
int QmlDomDynamicProperty::length() const
{
if (isValid())
return d->property.range.length;
else
return -1;
}
QmlDomObjectPrivate::QmlDomObjectPrivate()
: object(0), isVirtualComponent(false)
{
}
QmlDomObjectPrivate::QmlDomObjectPrivate(const QmlDomObjectPrivate &other)
: QSharedData(other), object(0), isVirtualComponent(false)
{
object = other.object;
if (object) object->addref();
isVirtualComponent = other.isVirtualComponent;
}
QmlDomObjectPrivate::~QmlDomObjectPrivate()
{
if (object) object->release();
}
QmlDomObjectPrivate::Properties
QmlDomObjectPrivate::properties() const
{
Properties rv;
for (QHash<QByteArray, QmlParser::Property *>::ConstIterator iter =
object->properties.begin();
iter != object->properties.end();
++iter) {
rv << properties(*iter);
}
return rv;
}
QmlDomObjectPrivate::Properties
QmlDomObjectPrivate::properties(QmlParser::Property *property) const
{
Properties rv;
if (property->value) {
for (QHash<QByteArray, QmlParser::Property *>::ConstIterator iter =
property->value->properties.begin();
iter != property->value->properties.end();
++iter) {
rv << properties(*iter);
}
QByteArray name(property->name + ".");
for (Properties::Iterator iter = rv.begin(); iter != rv.end(); ++iter)
iter->second.prepend(name);
} else {
rv << qMakePair(property, property->name);
}
return rv;
}
/*!
\class QmlDomObject
\internal
\brief The QmlDomObject class represents an object instantiation.
Each object instantiated in a QML file has a corresponding QmlDomObject
node in the QML DOM.
In addition to the type information that determines the object to
instantiate, QmlDomObject's also have a set of associated QmlDomProperty's.
Each QmlDomProperty represents a QML property assignment on the instantiated
object. For example,
\qml
QGraphicsWidget {
opacity: 0.5
size: "100x100"
}
\endqml
describes a single QmlDomObject - "QGraphicsWidget" - with two properties,
"opacity" and "size". Obviously QGraphicsWidget has many more properties than just
these two, but the QML DOM representation only contains those assigned
values (or bindings) in the QML file.
The DOM tree can be modified to include new property assignments by calling
QmlDomObject::addProperty(). Existing property assignments can be modified
through the QmlDomProperty::setValue() method, or removed entirely by
calling QmlDomObject::removeProperty().
*/
/*!
Construct an invalid QmlDomObject.
*/
QmlDomObject::QmlDomObject()
: d(new QmlDomObjectPrivate)
{
}
/*!
Construct a new QmlDomObject with the specified \a objectType.
*/
QmlDomObject::QmlDomObject(const QByteArray &objectType)
: d(new QmlDomObjectPrivate)
{
Q_UNUSED(objectType);
qWarning("QmlDomObject::QmlDomObject(const QByteArray &): Not implemented");
}
/*!
Create a copy of \a other QmlDomObject.
*/
QmlDomObject::QmlDomObject(const QmlDomObject &other)
: d(other.d)
{
}
/*!
Destroy the QmlDomObject.
*/
QmlDomObject::~QmlDomObject()
{
}
/*!
Assign \a other to this QmlDomObject.
*/
QmlDomObject &QmlDomObject::operator=(const QmlDomObject &other)
{
d = other.d;
return *this;
}
/*!
Returns true if this is a valid QmlDomObject, false otherwise.
*/
bool QmlDomObject::isValid() const
{
return d->object != 0;
}
/*!
Returns the type name of this object.
For example, the type of this object would be "QGraphicsWidget".
\qml
QGraphicsWidget { }
\endqml
*/
QByteArray QmlDomObject::objectType() const
{
if (d->object) return d->object->typeName;
else return QByteArray();
}
/*!
Returns the QML id assigned to this object, or an empty QByteArray if no id
has been assigned.
For example, the object id of this object would be "MyText".
\qml
Text { id: MyText }
\endqml
*/
QByteArray QmlDomObject::objectId() const
{
if (d->object) return d->object->id;
else return QByteArray();
}
/*!
Set the object \a id. If any other object within the DOM tree has the same
id, the other object's id will be cleared.
*/
void QmlDomObject::setObjectId(const QByteArray &id)
{
Q_UNUSED(id);
qWarning("QmlDomObject::setObjectId(const QByteArray &): Not implemented");
}
/*!
Returns the list of assigned properties on this object.
In the following example, "text" and "x" properties would be returned.
\qml
Text {
text: "Hello world!"
x: 100
}
\endqml
*/
QList<QmlDomProperty> QmlDomObject::properties() const
{
QList<QmlDomProperty> rv;
if (!d->object)
return rv;
QmlDomObjectPrivate::Properties properties = d->properties();
for (int ii = 0; ii < properties.count(); ++ii) {
QmlDomProperty domProperty;
domProperty.d->property = properties.at(ii).first;
domProperty.d->property->addref();
domProperty.d->propertyName = properties.at(ii).second;
rv << domProperty;
}
if (d->object->defaultProperty) {
QmlDomProperty domProperty;
domProperty.d->property = d->object->defaultProperty;
domProperty.d->property->addref();
domProperty.d->propertyName = d->object->defaultProperty->name;
rv << domProperty;
}
return rv;
}
/*!
Returns the object's \a name property if a value has been assigned to
it, or an invalid QmlDomProperty otherwise.
In the example below, \c {object.property("source")} would return a valid
QmlDomProperty, and \c {object.property("tile")} an invalid QmlDomProperty.
\qml
Image { source: "sample.jpg" }
\endqml
*/
QmlDomProperty QmlDomObject::property(const QByteArray &name) const
{
QList<QmlDomProperty> props = properties();
for (int ii = 0; ii < props.count(); ++ii)
if (props.at(ii).propertyName() == name)
return props.at(ii);
return QmlDomProperty();
}
/*!
Remove the property \a name from this object, if it exists. Otherwise does
nothing.
*/
void QmlDomObject::removeProperty(const QByteArray &name)
{
Q_UNUSED(name);
qWarning("QmlDomObject::removeProperty(const QByteArray &): Not implemented");
}
/*!
Adds the property \a name with the specified \a value to this object. If
a property by \a name already exists, it will be removed.
*/
void QmlDomObject::addProperty(const QByteArray &name, const QmlDomValue &value)
{
Q_UNUSED(name);
Q_UNUSED(value);
qWarning("QmlDomObject::addProperty(const QByteArray &, const QmlDomValue &): Not implemented");
}
QList<QmlDomDynamicProperty> QmlDomObject::dynamicProperties() const
{
QList<QmlDomDynamicProperty> properties;
for (int i = 0; i < d->object->dynamicProperties.size(); ++i) {
QmlDomDynamicProperty p;
p.d = new QmlDomDynamicPropertyPrivate;
p.d->property = d->object->dynamicProperties.at(i);
p.d->valid = true;
if (p.d->property.defaultValue)
p.d->property.defaultValue->addref();
properties.append(p);
}
return properties;
}
QmlDomDynamicProperty QmlDomObject::dynamicProperty(const QByteArray &name) const
{
QmlDomDynamicProperty p;
for (int i = 0; i < d->object->dynamicProperties.size(); ++i) {
if (d->object->dynamicProperties.at(i).name == name) {
p.d = new QmlDomDynamicPropertyPrivate;
p.d->property = d->object->dynamicProperties.at(i);
if (p.d->property.defaultValue) p.d->property.defaultValue->addref();
p.d->valid = true;
}
}
return p;
}
/*!
Returns true if this object is a custom type. Custom types are special
types that allow embeddeding non-QML data, such as SVG or HTML data,
directly into QML files.
\note Currently this method will always return false, and is a placekeeper
for future functionality.
\sa QmlDomObject::customTypeData()
*/
bool QmlDomObject::isCustomType() const
{
return false;
}
/*!
Sets the custom type \a data. If this type is not a custom type, this
method does nothing.
\sa QmlDomObject::isCustomType() QmlDomObject::customTypeData()
*/
void QmlDomObject::setCustomTypeData(const QByteArray &data)
{
Q_UNUSED(data);
qWarning("QmlDomObject::setCustomTypeData(const QByteArray &): Not implemented");
}
/*!
If this object represents a custom type, returns the data associated with
the custom type, otherwise returns an empty QByteArray().
QmlDomObject::isCustomType() can be used to check if this object represents
a custom type.
*/
QByteArray QmlDomObject::customTypeData() const
{
return QByteArray();
}
/*!
Returns true if this object is a sub-component object. Sub-component
objects can be converted into QmlDomComponent instances by calling
QmlDomObject::toComponent().
\sa QmlDomObject::toComponent()
*/
bool QmlDomObject::isComponent() const
{
return d->isVirtualComponent ||
(d->object && d->object->typeName == "Component");
}
/*!
Returns a QmlDomComponent for this object if it is a sub-component, or
an invalid QmlDomComponent if not. QmlDomObject::isComponent() can be used
to check if this object represents a sub-component.
\sa QmlDomObject::isComponent()
*/
QmlDomComponent QmlDomObject::toComponent() const
{
QmlDomComponent rv;
if (isComponent())
rv.d = d;
return rv;
}
/*!
Returns the position in the input data where the property assignment started
, or -1 if the property is invalid.
*/
int QmlDomObject::position() const
{
if (d && d->object)
return d->object->location.range.offset;
else
return -1;
}
/*!
Returns the length in the input data from where the property assignment star
ted upto the end of it, or -1 if the property is invalid.
*/
int QmlDomObject::length() const
{
if (d && d->object)
return d->object->location.range.length;
else
return -1;
}
// Returns the URL of the type, if it is an external type, or an empty URL if
// not
QUrl QmlDomObject::url() const
{
if (d && d->object)
return d->object->url;
else
return QUrl();
}
QmlDomBasicValuePrivate::QmlDomBasicValuePrivate()
: value(0)
{
}
QmlDomBasicValuePrivate::QmlDomBasicValuePrivate(const QmlDomBasicValuePrivate &other)
: QSharedData(other), value(0)
{
value = other.value;
if (value) value->addref();
}
QmlDomBasicValuePrivate::~QmlDomBasicValuePrivate()
{
if (value) value->release();
}
/*!
\class QmlDomValueLiteral
\internal
\brief The QmlDomValueLiteral class represents a literal value.
A literal value is a simple value, written inline with the QML. In the
example below, the "x", "y" and "color" properties are being assigned
literal values.
\qml
Rect {
x: 10
y: 10
color: "red"
}
\endqml
*/
/*!
Construct an empty QmlDomValueLiteral.
*/
QmlDomValueLiteral::QmlDomValueLiteral():
d(new QmlDomBasicValuePrivate)
{
}
/*!
Create a copy of \a other QmlDomValueLiteral.
*/
QmlDomValueLiteral::QmlDomValueLiteral(const QmlDomValueLiteral &other)
: d(other.d)
{
}
/*!
Destroy the QmlDomValueLiteral.
*/
QmlDomValueLiteral::~QmlDomValueLiteral()
{
}
/*!
Assign \a other to this QmlDomValueLiteral.
*/
QmlDomValueLiteral &QmlDomValueLiteral::operator=(const QmlDomValueLiteral &other)
{
d = other.d;
return *this;
}
/*!
Return the literal value.
In the example below, the literal value will be the string "10".
\qml
Rect { x: 10 }
\endqml
*/
QString QmlDomValueLiteral::literal() const
{
if (d->value) return d->value->primitive();
else return QString();
}
/*!
Sets the literal \a value.
*/
void QmlDomValueLiteral::setLiteral(const QString &value)
{
Q_UNUSED(value);
qWarning("QmlDomValueLiteral::setLiteral(const QString &): Not implemented");
}
/*!
\class QmlDomValueBinding
\internal
\brief The QmlDomValueBinding class represents a property binding.
A property binding is an ECMAScript expression assigned to a property. In
the example below, the "x" property is being assigned a property binding.
\qml
Rect { x: Other.x }
\endqml
*/
/*!
Construct an empty QmlDomValueBinding.
*/
QmlDomValueBinding::QmlDomValueBinding():
d(new QmlDomBasicValuePrivate)
{
}
/*!
Create a copy of \a other QmlDomValueBinding.
*/
QmlDomValueBinding::QmlDomValueBinding(const QmlDomValueBinding &other)
: d(other.d)
{
}
/*!
Destroy the QmlDomValueBinding.
*/
QmlDomValueBinding::~QmlDomValueBinding()
{
}
/*!
Assign \a other to this QmlDomValueBinding.
*/
QmlDomValueBinding &QmlDomValueBinding::operator=(const QmlDomValueBinding &other)
{
d = other.d;
return *this;
}
/*!
Return the binding expression.
In the example below, the string "Other.x" will be returned.
\qml
Rect { x: Other.x }
\endqml
*/
QString QmlDomValueBinding::binding() const
{
if (d->value)
return d->value->value.asScript();
else
return QString();
}
/*!
Sets the binding \a expression.
*/
void QmlDomValueBinding::setBinding(const QString &expression)
{
Q_UNUSED(expression);
qWarning("QmlDomValueBinding::setBinding(const QString &): Not implemented");
}
/*!
\class QmlDomValueValueSource
\internal
\brief The QmlDomValueValueSource class represents a value source assignment value.
In QML, value sources are special value generating types that may be
assigned to properties. Value sources inherit the QmlPropertyValueSource
class. In the example below, the "x" property is being assigned the
NumberAnimation value source.
\qml
Rect {
x: NumberAnimation {
from: 0
to: 100
repeat: true
running: true
}
}
\endqml
*/
/*!
Construct an empty QmlDomValueValueSource.
*/
QmlDomValueValueSource::QmlDomValueValueSource():
d(new QmlDomBasicValuePrivate)
{
}
/*!
Create a copy of \a other QmlDomValueValueSource.
*/
QmlDomValueValueSource::QmlDomValueValueSource(const QmlDomValueValueSource &other)
: d(other.d)
{
}
/*!
Destroy the QmlDomValueValueSource.
*/
QmlDomValueValueSource::~QmlDomValueValueSource()
{
}
/*!
Assign \a other to this QmlDomValueValueSource.
*/
QmlDomValueValueSource &QmlDomValueValueSource::operator=(const QmlDomValueValueSource &other)
{
d = other.d;
return *this;
}
/*!
Return the value source object.
In the example below, an object representing the NumberAnimation will be
returned.
\qml
Rect {
x: NumberAnimation {
from: 0
to: 100
repeat: true
running: true
}
}
\endqml
*/
QmlDomObject QmlDomValueValueSource::object() const
{
QmlDomObject rv;
if (d->value) {
rv.d->object = d->value->object;
rv.d->object->addref();
}
return rv;
}
/*!
Sets the value source \a object.
*/
void QmlDomValueValueSource::setObject(const QmlDomObject &object)
{
Q_UNUSED(object);
qWarning("QmlDomValueValueSource::setObject(const QmlDomObject &): Not implemented");
}
QmlDomValuePrivate::QmlDomValuePrivate()
: property(0), value(0)
{
}
QmlDomValuePrivate::QmlDomValuePrivate(const QmlDomValuePrivate &other)
: QSharedData(other), property(0), value(0)
{
property = other.property;
value = other.value;
if (property) property->addref();
if (value) value->addref();
}
QmlDomValuePrivate::~QmlDomValuePrivate()
{
if (property) property->release();
if (value) value->release();
}
/*!
\class QmlDomValue
\internal
\brief The QmlDomValue class represents a generic Qml value.
QmlDomValue's can be assigned to QML \l {QmlDomProperty}{properties}. In
QML, properties can be assigned various different values, including basic
literals, property bindings, property value sources, objects and lists of
values. The QmlDomValue class allows a programmer to determine the specific
value type being assigned and access more detailed information through a
corresponding value type class.
For example, in the following example,
\qml
Text {
text: "Hello World!"
y: Other.y
}
\endqml
The text property is being assigned a literal, and the y property a property
binding. To output the values assigned to the text and y properties in the
above example from C++,
\code
QmlDomDocument document;
QmlDomObject root = document.rootObject();
QmlDomProperty text = root.property("text");
if (text.value().isLiteral()) {
QmlDomValueLiteral literal = text.value().toLiteral();
qDebug() << literal.literal();
}
QmlDomProperty y = root.property("y");
if (y.value().isBinding()) {
QmlDomValueBinding binding = y.value().toBinding();
qDebug() << binding.binding();
}
\endcode
*/
/*!
Construct an invalid QmlDomValue.
*/
QmlDomValue::QmlDomValue()
: d(new QmlDomValuePrivate)
{
}
/*!
Create a copy of \a other QmlDomValue.
*/
QmlDomValue::QmlDomValue(const QmlDomValue &other)
: d(other.d)
{
}
/*!
Destroy the QmlDomValue
*/
QmlDomValue::~QmlDomValue()
{
}
/*!
Assign \a other to this QmlDomValue.
*/
QmlDomValue &QmlDomValue::operator=(const QmlDomValue &other)
{
d = other.d;
return *this;
}
/*!
\enum QmlDomValue::Type
The type of the QmlDomValue node.
\value Invalid The QmlDomValue is invalid.
\value Literal The QmlDomValue is a literal value assignment. Use QmlDomValue::toLiteral() to access the type instance.
\value PropertyBinding The QmlDomValue is a property binding. Use QmlDomValue::toBinding() to access the type instance.
\value ValueSource The QmlDomValue is a property value source. Use QmlDomValue::toValueSource() to access the type instance.
\value Object The QmlDomValue is an object assignment. Use QmlDomValue::toObject() to access the type instnace.
\value List The QmlDomValue is a list of other values. Use QmlDomValue::toList() to access the type instance.
*/
/*!
Returns the type of this QmlDomValue.
*/
QmlDomValue::Type QmlDomValue::type() const
{
if (d->property)
if (QmlMetaType::isList(d->property->type) ||
QmlMetaType::isQmlList(d->property->type) ||
(d->property && d->property->values.count() > 1))
return List;
QmlParser::Value *value = d->value;
if (!value && !d->property)
return Invalid;
switch(value->type) {
case QmlParser::Value::Unknown:
return Invalid;
case QmlParser::Value::Literal:
return Literal;
case QmlParser::Value::PropertyBinding:
return PropertyBinding;
case QmlParser::Value::ValueSource:
return ValueSource;
case QmlParser::Value::CreatedObject:
return Object;
case QmlParser::Value::SignalObject:
return Invalid;
case QmlParser::Value::SignalExpression:
return Literal;
case QmlParser::Value::Id:
return Literal;
}
return Invalid;
}
/*!
Returns true if this is an invalid value, otherwise false.
*/
bool QmlDomValue::isInvalid() const
{
return type() == Invalid;
}
/*!
Returns true if this is a literal value, otherwise false.
*/
bool QmlDomValue::isLiteral() const
{
return type() == Literal;
}
/*!
Returns true if this is a property binding value, otherwise false.
*/
bool QmlDomValue::isBinding() const
{
return type() == PropertyBinding;
}
/*!
Returns true if this is a value source value, otherwise false.
*/
bool QmlDomValue::isValueSource() const
{
return type() == ValueSource;
}
/*!
Returns true if this is an object value, otherwise false.
*/
bool QmlDomValue::isObject() const
{
return type() == Object;
}
/*!
Returns true if this is a list value, otherwise false.
*/
bool QmlDomValue::isList() const
{
return type() == List;
}
/*!
Returns a QmlDomValueLiteral if this value is a literal type, otherwise
returns an invalid QmlDomValueLiteral.
\sa QmlDomValue::type()
*/
QmlDomValueLiteral QmlDomValue::toLiteral() const
{
QmlDomValueLiteral rv;
if (type() == Literal) {
rv.d->value = d->value;
rv.d->value->addref();
}
return rv;
}
/*!
Returns a QmlDomValueBinding if this value is a property binding type,
otherwise returns an invalid QmlDomValueBinding.
\sa QmlDomValue::type()
*/
QmlDomValueBinding QmlDomValue::toBinding() const
{
QmlDomValueBinding rv;
if (type() == PropertyBinding) {
rv.d->value = d->value;
rv.d->value->addref();
}
return rv;
}
/*!
Returns a QmlDomValueValueSource if this value is a property value source
type, otherwise returns an invalid QmlDomValueValueSource.
\sa QmlDomValue::type()
*/
QmlDomValueValueSource QmlDomValue::toValueSource() const
{
QmlDomValueValueSource rv;
if (type() == ValueSource) {
rv.d->value = d->value;
rv.d->value->addref();
}
return rv;
}
/*!
Returns a QmlDomObject if this value is an object assignment type, otherwise
returns an invalid QmlDomObject.
\sa QmlDomValue::type()
*/
QmlDomObject QmlDomValue::toObject() const
{
QmlDomObject rv;
if (type() == Object) {
rv.d->object = d->value->object;
rv.d->object->addref();
}
return rv;
}
/*!
Returns a QmlDomList if this value is a list type, otherwise returns an
invalid QmlDomList.
\sa QmlDomValue::type()
*/
QmlDomList QmlDomValue::toList() const
{
QmlDomList rv;
if (type() == List) {
rv.d = d;
}
return rv;
}
/*!
Returns the position in the input data where the property value startd, or -1
if the value is invalid.
*/
int QmlDomValue::position() const
{
if (type() == Invalid)
return -1;
else
return d->value->location.range.offset;
}
/*!
Returns the length in the input data from where the property value started u
pto the end of it, or -1 if the value is invalid.
*/
int QmlDomValue::length() const
{
if (type() == Invalid)
return -1;
else
return d->value->location.range.length;
}
/*!
\class QmlDomList
\internal
\brief The QmlDomList class represents a list of values assigned to a QML property.
Lists of values can be assigned to properties. For example, the following
example assigns multiple objects to Item's "children" property
\qml
Item {
children: [
Text { },
Rect { }
]
}
\endqml
Lists can also be implicitly created by assigning multiple
\l {QmlDomValueValueSource}{value sources} or constants to a property.
\qml
Item {
x: 10
x: NumberAnimation {
running: false
from: 0
to: 100
}
}
\endqml
*/
/*!
Construct an empty QmlDomList.
*/
QmlDomList::QmlDomList()
{
}
/*!
Create a copy of \a other QmlDomList.
*/
QmlDomList::QmlDomList(const QmlDomList &other)
: d(other.d)
{
}
/*!
Destroy the QmlDomList.
*/
QmlDomList::~QmlDomList()
{
}
/*!
Assign \a other to this QmlDomList.
*/
QmlDomList &QmlDomList::operator=(const QmlDomList &other)
{
d = other.d;
return *this;
}
/*!
Returns the list of QmlDomValue's.
*/
QList<QmlDomValue> QmlDomList::values() const
{
QList<QmlDomValue> rv;
if (!d->property)
return rv;
for (int ii = 0; ii < d->property->values.count(); ++ii) {
QmlDomValue v;
v.d->value = d->property->values.at(ii);
v.d->value->addref();
rv << v;
}
return rv;
}
/*!
Set the list of QmlDomValue's to \a values.
*/
void QmlDomList::setValues(const QList<QmlDomValue> &values)
{
Q_UNUSED(values);
qWarning("QmlDomList::setValues(const QList<QmlDomValue> &): Not implemented");
}
/*!
Returns the position in the input data where the list started, or -1 if
the property is invalid.
*/
int QmlDomList::position() const
{
if (d && d->property) {
return d->property->listValueRange.offset;
} else
return -1;
}
/*!
Returns the length in the input data from where the list started upto
the end of it, or 0 if the property is invalid.
*/
int QmlDomList::length() const
{
if (d && d->property)
return d->property->listValueRange.length;
else
return -1;
}
/*!
Returns a list of positions of the commas in the QML file.
*/
QList<int> QmlDomList:: commaPositions() const
{
if (d && d->property)
return d->property->listCommaPositions;
else
return QList<int>();
}
/*!
\class QmlDomComponent
\internal
\brief The QmlDomComponent class represents sub-component within a QML document.
Sub-components are QmlComponents defined within a QML document. The
following example shows the definition of a sub-component with the id
"ListDelegate".
\qml
Item {
Component {
id: ListDelegate
Text {
text: modelData.text
}
}
}
\endqml
Like QmlDomDocument's, components contain a single root object.
*/
/*!
Construct an empty QmlDomComponent.
*/
QmlDomComponent::QmlDomComponent()
{
}
/*!
Create a copy of \a other QmlDomComponent.
*/
QmlDomComponent::QmlDomComponent(const QmlDomComponent &other)
: QmlDomObject(other)
{
}
/*!
Destroy the QmlDomComponent.
*/
QmlDomComponent::~QmlDomComponent()
{
}
/*!
Assign \a other to this QmlDomComponent.
*/
QmlDomComponent &QmlDomComponent::operator=(const QmlDomComponent &other)
{
static_cast<QmlDomObject &>(*this) = other;
return *this;
}
/*!
Returns the component's root object.
In the example below, the root object is the "Text" object.
\qml
Item {
Component {
id: ListDelegate
Text {
text: modelData.text
}
}
}
\endqml
*/
QmlDomObject QmlDomComponent::componentRoot() const
{
QmlDomObject rv;
if (d->isVirtualComponent) {
rv.d->object = d->object;
rv.d->object->addref();
} else if (d->object) {
QmlParser::Object *obj = 0;
if (d->object->defaultProperty &&
d->object->defaultProperty->values.count() == 1 &&
d->object->defaultProperty->values.at(0)->object)
obj = d->object->defaultProperty->values.at(0)->object;
if (obj) {
rv.d->object = obj;
rv.d->object->addref();
}
}
return rv;
}
/*!
Set the component's \a root object.
*/
void QmlDomComponent::setComponentRoot(const QmlDomObject &root)
{
Q_UNUSED(root);
qWarning("QmlDomComponent::setComponentRoot(const QmlDomObject &): Not implemented");
}
QmlDomImportPrivate::QmlDomImportPrivate()
: type(File)
{
}
QmlDomImportPrivate::QmlDomImportPrivate(const QmlDomImportPrivate &other)
: QSharedData(other)
{
}
QmlDomImportPrivate::~QmlDomImportPrivate()
{
}
/*!
\class QmlDomImport
\internal
\brief The QmlDomImport class represents an import statement.
*/
/*!
Construct an empty QmlDomImport.
*/
QmlDomImport::QmlDomImport()
: d(new QmlDomImportPrivate)
{
}
/*!
Create a copy of \a other QmlDomImport.
*/
QmlDomImport::QmlDomImport(const QmlDomImport &other)
: d(other.d)
{
}
/*!
Destroy the QmlDomImport.
*/
QmlDomImport::~QmlDomImport()
{
}
/*!
Assign \a other to this QmlDomImport.
*/
QmlDomImport &QmlDomImport::operator=(const QmlDomImport &other)
{
d = other.d;
return *this;
}
/*!
Returns the type of the import.
*/
QmlDomImport::Type QmlDomImport::type() const
{
return static_cast<QmlDomImport::Type>(d->type);
}
/*!
Returns the URI of the import (e.g. 'subdir' or 'com.nokia.Qt')
*/
QString QmlDomImport::uri() const
{
return d->uri;
}
/*!
Returns the version specified by the import. An empty string if no version was specified.
*/
QString QmlDomImport::version() const
{
return d->version;
}
/*!
Returns the (optional) qualifier string (the token following the 'as' keyword) of the import.
*/
QString QmlDomImport::qualifier() const
{
return d->qualifier;
}
QT_END_NAMESPACE
|