7#include <qscopedvaluerollback.h>
9#include <QtCore/qloggingcategory.h>
11#include <QtCore/qmetaobject.h>
17Q_STATIC_LOGGING_CATEGORY(lcQPropertyBinding,
"qt.qproperty.binding");
21void QPropertyBindingPrivatePtr::destroyAndFreeMemory()
23 QPropertyBindingPrivate::destroyAndFreeMemory(
static_cast<QPropertyBindingPrivate *>(d));
26void QPropertyBindingPrivatePtr::reset(QtPrivate::RefCounted *ptr)
noexcept
31 auto *old = std::exchange(d, ptr);
32 if (old && !old->deref())
33 QPropertyBindingPrivate::destroyAndFreeMemory(
static_cast<QPropertyBindingPrivate *>(d));
40 if (
auto *b = binding()) {
41 observer->prev = &b->firstObserver.ptr;
42 observer->next = b->firstObserver.ptr;
44 observer->next->prev = &observer->next;
45 b->firstObserver.ptr = observer;
47 auto &d = ptr->d_ref();
48 Q_ASSERT(!(d & QPropertyBindingData::BindingBit));
49 auto firstObserver =
reinterpret_cast<QPropertyObserver*>(d);
50 observer->prev =
reinterpret_cast<QPropertyObserver**>(&d);
51 observer->next = firstObserver;
53 observer->next->prev = &observer->next;
54 d =
reinterpret_cast<quintptr>(observer);
59
60
61
62
63
64
65
66
81
82
83
84
85
86
87
88
89 void addProperty(
const QPropertyBindingData *bindingData, QUntypedPropertyData *propertyData) {
90 if (bindingData->isNotificationDelayed())
93 while (data->used == size) {
99 auto *delayed = data->delayedProperties + data->used;
100 *delayed = QPropertyProxyBindingData { bindingData->d_ptr, bindingData, propertyData };
103 quintptr bindingBit = bindingData->d_ptr & QPropertyBindingData::BindingBit;
104 bindingData->d_ptr =
reinterpret_cast<quintptr>(delayed) | QPropertyBindingData::DelayedNotificationBit | bindingBit;
105 Q_ASSERT(bindingData->d_ptr > 3);
107 if (
auto observer =
reinterpret_cast<QPropertyObserver *>(delayed->d_ptr))
108 observer->prev =
reinterpret_cast<QPropertyObserver **>(&delayed->d_ptr);
113
114
115
116
117
118
119
120
121
122
123
124 void evaluateBindings(PendingBindingObserverList &bindingObservers, qsizetype index, QBindingStatus *status) {
125 auto *delayed = delayedProperties + index;
126 auto *bindingData = delayed->originalBindingData;
130 bindingData->d_ptr = delayed->d_ptr;
131 Q_ASSERT(!(bindingData->d_ptr & QPropertyBindingData::DelayedNotificationBit));
132 if (!bindingData->hasBinding()) {
133 if (
auto observer =
reinterpret_cast<QPropertyObserver *>(bindingData->d_ptr))
134 observer->prev =
reinterpret_cast<QPropertyObserver **>(&bindingData->d_ptr);
140 observer.evaluateBindings(bindingObservers, status);
144
145
146
147
148
149
150
151
153 auto *delayed = delayedProperties + index;
154 if (delayed->d_ptr & QPropertyBindingData::BindingBit)
156 if (!delayed->originalBindingData)
158 delayed->originalBindingData =
nullptr;
160 QPropertyObserverPointer observer {
reinterpret_cast<QPropertyObserver *>(delayed->d_ptr & ~QPropertyBindingData::DelayedNotificationBit) };
164 observer.notify(delayed->propertyData);
168Q_CONSTINIT
static thread_local QBindingStatus bindingStatus;
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
193 if (!groupUpdateData)
195 ++groupUpdateData
->ref;
199
200
201
202
203
204
205
206
207
208
209
212 auto status = &bindingStatus;
214 auto *data = groupUpdateData;
218 groupUpdateData =
nullptr;
220 PendingBindingObserverList bindingObservers;
224 for (qsizetype i = 0; i < data->used; ++i)
225 data->evaluateBindings(bindingObservers, i, status);
229 for (
const auto &bindingPtr: bindingObservers) {
230 auto *binding =
static_cast<QPropertyBindingPrivate *>(bindingPtr.get());
231 binding->notifyNonRecursive();
236 for (qsizetype i = 0; i < data->used; ++i)
238 delete std::exchange(data, data->next);
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
265
266
267
268
271
272
273
274
279static_assert(std::is_trivially_destructible_v<QPropertyBindingSourceLocation>);
282QPropertyBindingPrivate::~QPropertyBindingPrivate()
285 firstObserver.unlink();
287 vtable->destroy(
reinterpret_cast<std::byte *>(
this)
288 + QPropertyBindingPrivate::getSizeEnsuringAlignment());
291void QPropertyBindingPrivate::clearDependencyObservers() {
292 for (size_t i = 0; i < qMin(dependencyObserverCount, inlineDependencyObservers.size()); ++i) {
293 QPropertyObserverPointer p{&inlineDependencyObservers[i]};
297 heapObservers->clear();
298 dependencyObserverCount = 0;
301QPropertyObserverPointer QPropertyBindingPrivate::allocateDependencyObserver_slow()
303 ++dependencyObserverCount;
305 heapObservers.reset(
new std::vector<QPropertyObserver>());
306 return {&heapObservers->emplace_back()};
309void QPropertyBindingPrivate::unlinkAndDeref()
311 clearDependencyObservers();
312 propertyDataPtr =
nullptr;
314 destroyAndFreeMemory(
this);
317bool QPropertyBindingPrivate::evaluateRecursive(PendingBindingObserverList &bindingObservers, QBindingStatus *status)
320 status = &bindingStatus;
321 return evaluateRecursive_inline(bindingObservers, status);
324void QPropertyBindingPrivate::notifyNonRecursive(
const PendingBindingObserverList &bindingObservers)
326 notifyNonRecursive();
327 for (
auto &&bindingPtr: bindingObservers) {
328 auto *binding =
static_cast<QPropertyBindingPrivate *>(bindingPtr.get());
329 binding->notifyNonRecursive();
333QPropertyBindingPrivate::NotificationState QPropertyBindingPrivate::notifyNonRecursive()
337 pendingNotify =
false;
341 firstObserver.noSelfDependencies(
this);
342 firstObserver.notify(propertyDataPtr);
344 if (hasStaticObserver)
345 staticObserverCallback(propertyDataPtr);
351
352
353
354
355QUntypedPropertyBinding::QUntypedPropertyBinding() =
default;
358
359
360
361
362
365
366
367
368
369
370
371QUntypedPropertyBinding::QUntypedPropertyBinding(QMetaType metaType,
const BindingFunctionVTable *vtable,
void *function,
372 const QPropertyBindingSourceLocation &location)
374 std::byte *mem =
new std::byte[QPropertyBindingPrivate::getSizeEnsuringAlignment() + vtable->size]();
375 d =
new(mem) QPropertyBindingPrivate(metaType, vtable, std::move(location));
376 vtable->moveConstruct(mem + QPropertyBindingPrivate::getSizeEnsuringAlignment(), function);
380
381
382
383
384
385QUntypedPropertyBinding::QUntypedPropertyBinding(QUntypedPropertyBinding &&other)
386 : d(std::move(other.d))
391
392
393QUntypedPropertyBinding::QUntypedPropertyBinding(
const QUntypedPropertyBinding &other)
399
400
401QUntypedPropertyBinding &QUntypedPropertyBinding::operator=(
const QUntypedPropertyBinding &other)
408
409
410
411
412
413QUntypedPropertyBinding &QUntypedPropertyBinding::operator=(QUntypedPropertyBinding &&other)
415 d = std::move(other.d);
420
421
422QUntypedPropertyBinding::QUntypedPropertyBinding(QPropertyBindingPrivate *priv)
428
429
430QUntypedPropertyBinding::~QUntypedPropertyBinding()
435
436
437
438
439
440bool QUntypedPropertyBinding::isNull()
const
446
447
448
449
450QPropertyBindingError QUntypedPropertyBinding::error()
const
453 return QPropertyBindingError();
454 return static_cast<QPropertyBindingPrivate *>(d.get())->bindingError();
458
459
460
461QMetaType QUntypedPropertyBinding::valueMetaType()
const
465 return static_cast<QPropertyBindingPrivate *>(d.get())->valueMetaType();
468QPropertyBindingData::~QPropertyBindingData()
470 QPropertyBindingDataPointer d{
this};
471 if (isNotificationDelayed())
472 proxyData()->originalBindingData =
nullptr;
473 for (
auto observer = d.firstObserver(); observer;) {
474 auto next = observer.nextObserver();
478 if (
auto binding = d.binding())
479 binding->unlinkAndDeref();
482QUntypedPropertyBinding QPropertyBindingData::setBinding(
const QUntypedPropertyBinding &binding,
483 QUntypedPropertyData *propertyDataPtr,
484 QPropertyObserverCallback staticObserverCallback,
485 QtPrivate::QPropertyBindingWrapper guardCallback)
487 QPropertyBindingPrivatePtr oldBinding;
488 QPropertyBindingPrivatePtr newBinding = binding.d;
490 QPropertyBindingDataPointer d{
this};
491 QPropertyObserverPointer observer;
493 auto &data = d_ref();
494 if (
auto *existingBinding = d.binding()) {
495 if (existingBinding == newBinding.data())
496 return QUntypedPropertyBinding(
static_cast<QPropertyBindingPrivate *>(oldBinding.data()));
497 if (existingBinding->isUpdating()) {
498 existingBinding->setError({QPropertyBindingError::BindingLoop, QStringLiteral(
"Binding set during binding evaluation!")});
499 return QUntypedPropertyBinding(
static_cast<QPropertyBindingPrivate *>(oldBinding.data()));
501 oldBinding = QPropertyBindingPrivatePtr(existingBinding);
502 observer =
static_cast<QPropertyBindingPrivate *>(oldBinding.data())->takeObservers();
503 static_cast<QPropertyBindingPrivate *>(oldBinding.data())->unlinkAndDeref();
506 observer = d.firstObserver();
510 newBinding.data()->addRef();
511 data =
reinterpret_cast<quintptr>(newBinding.data());
513 auto newBindingRaw =
static_cast<QPropertyBindingPrivate *>(newBinding.data());
514 newBindingRaw->setProperty(propertyDataPtr);
516 newBindingRaw->prependObserver(observer);
517 newBindingRaw->setStaticObserver(staticObserverCallback, guardCallback);
519 PendingBindingObserverList bindingObservers;
520 newBindingRaw->evaluateRecursive(bindingObservers);
521 newBindingRaw->notifyNonRecursive(bindingObservers);
522 }
else if (observer) {
523 d.setObservers(observer.ptr);
529 static_cast<QPropertyBindingPrivate *>(oldBinding.data())->detachFromProperty();
531 return QUntypedPropertyBinding(
static_cast<QPropertyBindingPrivate *>(oldBinding.data()));
534QPropertyBindingData::QPropertyBindingData(QPropertyBindingData &&other) : d_ptr(std::exchange(other.d_ptr, 0))
536 QPropertyBindingDataPointer::fixupAfterMove(
this);
543 QBindingStatus *s = status;
546 currentState = &s->currentlyEvaluatingBinding;
549 binding->clearDependencyObservers();
561 currentlyEvaluatingBindingList = &bindingStatus.currentlyEvaluatingBinding;
566QPropertyBindingPrivate *QPropertyBindingPrivate::currentlyEvaluatingBinding()
568 auto currentState = bindingStatus.currentlyEvaluatingBinding ;
569 return currentState ? currentState->binding :
nullptr;
573void QPropertyBindingData::evaluateIfDirty(
const QUntypedPropertyData *)
const
577void QPropertyBindingData::removeBinding_helper()
579 QPropertyBindingDataPointer d{
this};
581 auto *existingBinding = d.binding();
582 Q_ASSERT(existingBinding);
583 if (existingBinding->isSticky()) {
587 auto observer = existingBinding->takeObservers();
590 d.setObservers(observer.ptr);
591 existingBinding->unlinkAndDeref();
594void QPropertyBindingData::registerWithCurrentlyEvaluatingBinding()
const
596 auto currentState = bindingStatus.currentlyEvaluatingBinding;
599 registerWithCurrentlyEvaluatingBinding_helper(currentState);
603void QPropertyBindingData::registerWithCurrentlyEvaluatingBinding_helper(BindingEvaluationState *currentState)
const
605 QPropertyBindingDataPointer d{
this};
607 if (currentState->alreadyCaptureProperties.contains(
this))
610 currentState->alreadyCaptureProperties.push_back(
this);
612 QPropertyObserverPointer dependencyObserver = currentState->binding->allocateDependencyObserver();
613 Q_ASSERT(QPropertyObserver::ObserverNotifiesBinding == 0);
614 dependencyObserver.setBindingToNotify_unsafe(currentState->binding);
615 d.addObserver(dependencyObserver.ptr);
618void QPropertyBindingData::notifyObservers(QUntypedPropertyData *propertyDataPtr)
const
620 notifyObservers(propertyDataPtr,
nullptr);
623void QPropertyBindingData::notifyObservers(QUntypedPropertyData *propertyDataPtr, QBindingStorage *storage)
const
625 if (isNotificationDelayed())
627 QPropertyBindingDataPointer d{
this};
629 PendingBindingObserverList bindingObservers;
630 if (QPropertyObserverPointer observer = d.firstObserver()) {
631 if (notifyObserver_helper(propertyDataPtr, storage, observer, bindingObservers) == Evaluated) {
633
634
635
636
637
638
640 d = QPropertyBindingDataPointer {storage->bindingData(propertyDataPtr)};
641 if (QPropertyObserverPointer observer = d.firstObserver())
642 observer.notify(propertyDataPtr);
643 for (
auto &&bindingPtr: bindingObservers) {
644 auto *binding =
static_cast<QPropertyBindingPrivate *>(bindingPtr.get());
645 binding->notifyNonRecursive();
651QPropertyBindingData::NotificationResult QPropertyBindingData::notifyObserver_helper
653 QUntypedPropertyData *propertyDataPtr, QBindingStorage *storage,
654 QPropertyObserverPointer observer,
655 PendingBindingObserverList &bindingObservers)
const
657#ifdef QT_HAS_FAST_CURRENT_THREAD_ID
658 QBindingStatus *status = storage ? storage->bindingStatus :
nullptr;
659 if (!status || status->threadId != QThread::currentThreadId())
660 status = &bindingStatus;
663 QBindingStatus *status = &bindingStatus;
665 if (QPropertyDelayedNotifications *delay = status->groupUpdateData) {
666 delay->addProperty(
this, propertyDataPtr);
670 observer.evaluateBindings(bindingObservers, status);
675QPropertyObserver::QPropertyObserver(ChangeHandler changeHandler)
677 QPropertyObserverPointer d{
this};
678 d.setChangeHandler(changeHandler);
681#if QT_DEPRECATED_SINCE(6
, 6
)
682QPropertyObserver::QPropertyObserver(QUntypedPropertyData *data)
684 QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
686 next.setTag(ObserverIsAlias);
692
693void QPropertyObserver::setSource(
const QPropertyBindingData &property)
695 QPropertyObserverPointer d{
this};
696 QPropertyBindingDataPointer propPrivate{&property};
697 d.observeProperty(propPrivate);
700QPropertyObserver::~QPropertyObserver()
702 QPropertyObserverPointer d{
this};
706QPropertyObserver::QPropertyObserver(QPropertyObserver &&other)
noexcept
708 binding = std::exchange(other.binding, {});
709 next = std::exchange(other.next, {});
710 prev = std::exchange(other.prev, {});
714 prev.setPointer(
this);
717QPropertyObserver &QPropertyObserver::operator=(QPropertyObserver &&other)
noexcept
722 QPropertyObserverPointer d{
this};
726 binding = std::exchange(other.binding, {});
727 next = std::exchange(other.next, {});
728 prev = std::exchange(other.prev, {});
732 prev.setPointer(
this);
738
739
740
741
745
746
747
748
749
750
754 Q_ASSERT(ptr->next.tag() != QPropertyObserver::ObserverIsPlaceholder);
755 ptr->changeHandler = changeHandler;
756 ptr->next.setTag(QPropertyObserver::ObserverNotifiesChangeHandler);
760
761
762
765 Q_ASSERT(ptr->next.tag() == QPropertyObserver::ObserverNotifiesBinding);
766 ptr->binding = binding;
770
771
772
773
774
777
778
779
780
785 auto observer =
const_cast<QPropertyObserver*>(ptr);
788 if (QPropertyObserver::ObserverTag(observer->next.tag()) == QPropertyObserver::ObserverNotifiesBinding)
789 if (observer->binding == binding) {
790 qCritical(
"Property depends on itself!");
794 observer = observer->next.data();
803 auto observer =
const_cast<QPropertyObserver*>(ptr);
806 QPropertyObserver *next = observer->next.data();
808 if (QPropertyObserver::ObserverTag(observer->next.tag()) == QPropertyObserver::ObserverNotifiesBinding) {
809 auto bindingToEvaluate = observer->binding;
810 QPropertyObserverNodeProtector protector(observer);
812 QPropertyBindingPrivatePtr currentBinding(observer->binding);
813 const bool evalStatus = bindingToEvaluate->evaluateRecursive_inline(bindingObservers, status);
815 bindingObservers.push_back(std::move(currentBinding));
816 next = protector.next();
827 property.addObserver(
ptr);
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
873
874
875
876
877QPropertyBindingError::QPropertyBindingError()
882
883
884
885QPropertyBindingError::QPropertyBindingError(Type type,
const QString &description)
887 if (type != NoError) {
888 d =
new QPropertyBindingErrorPrivate;
890 d->description = description;
895
896
897QPropertyBindingError::QPropertyBindingError(
const QPropertyBindingError &other)
903
904
905QPropertyBindingError &QPropertyBindingError::operator=(
const QPropertyBindingError &other)
912
913
914
915QPropertyBindingError::QPropertyBindingError(QPropertyBindingError &&other)
916 : d(std::move(other.d))
921
922
923
924QPropertyBindingError &QPropertyBindingError::operator=(QPropertyBindingError &&other)
926 d = std::move(other.d);
931
932
933QPropertyBindingError::~QPropertyBindingError()
938
939
940
941
942QPropertyBindingError::Type QPropertyBindingError::type()
const
945 return QPropertyBindingError::NoError;
950
951
952
953QString QPropertyBindingError::description()
const
957 return d->description;
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
980
981
982
983
984
985
986
989
990
991
992
993
996
997
998
999
1000
1001
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1020
1021
1022
1023
1024
1027
1028
1029
1030
1031
1032
1033
1034
1037
1038
1039
1040
1041
1044
1045
1046
1047
1048
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1063
1064
1065
1066
1069
1070
1071
1072
1073
1076
1077
1078
1079
1080
1081
1082
1083
1086
1087
1088
1089
1090
1091
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1106
1107
1108
1109
1110
1111
1112
1115
1116
1117
1118
1119
1120
1121
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1136
1137
1138
1139
1142
1143
1144
1145
1146
1147
1148
1149
1150
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
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
1205
1206
1207
1208
1209
1212
1213
1214
1215
1216
1219
1220
1221
1222
1223
1224
1225
1226
1229
1230
1231
1232
1233
1234
1235
1236
1240
1241
1242
1243
1244
1245
1246
1247
1250
1251
1252
1253
1254
1257
1258
1259
1260
1261
1262
1263
1266
1267
1268
1269
1270
1271
1272
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1301
1302
1303
1304
1307
1308
1309
1310
1313
1314
1315
1316
1319
1320
1321
1322
1323
1326
1327
1328
1329
1330
1331
1332
1335
1336
1337
1338
1339
1340
1341
1344
1345
1346
1347
1350
1351
1352
1353
1354
1357
1358
1359
1360
1361
1362
1365
1366
1367
1368
1369
1372
1373
1374
1375
1376
1377
1378
1379
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1409
1410
1411
1412
1413
1414
1417
1418
1419
1420
1421
1422
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1477
1478
1479
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
1545
1546
1547
1548
1549
1550
1551
1552
1553
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
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
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1643
1644
1645
1646
1647
1648
1649
1650
1651
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
1701
1702
1703
1704
1705
1706
1707
1708
1709
1713
1714
1715
1718
1719
1720
1721
1724
1725
1726
1727
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1754
1755
1756
1757
1758
1759
1760
1761
1764
1765
1766
1767
1770
1771
1772
1773
1774
1777
1778
1779
1780
1781
1782
1783
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1844
1845
1846
1847
1851
1852
1853
1854
1855
1856
1859
1860
1861
1862
1863
1864
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1918
1919
1920
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
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
1996
1997
1998
1999
2002
2003
2004
2005
2008
2009
2010
2011
2012
2015
2016
2017
2018
2019
2022
2023
2024
2025
2026
2029
2030
2031
2032
2033
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2080
2081
2082
2083
2084
2087
2088
2089
2090
2091
2092
2095
2096
2097
2098
2099
2100
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2154
2155
2156
2157
2158
2159
2178 static_assert(
alignof(
Pair) ==
alignof(
void *));
2179 static_assert(
alignof(
size_t) ==
alignof(
void *));
2186 return reinterpret_cast<
Pair *>(dd + 1);
2190 Q_ASSERT(!
d || newSize >
d->size);
2191 size_t allocSize =
sizeof(QBindingStorageData) + newSize*
sizeof(Pair);
2192 void *nd = malloc(allocSize);
2193 memset(nd, 0, allocSize);
2195 newData->size = newSize;
2200 newData->used =
d->used;
2202 for (size_t i = 0; i <
d->size; ++i, ++p) {
2205 Q_ASSERT(newData->size && (newData->size & (newData->size - 1)) == 0);
2206 size_t index = qHash(p->data) & (newData->size - 1);
2207 while (pp[index].data) {
2209 if (index == newData->size)
2212 new (pp + index)
Pair{p->data, QPropertyBindingData(
std::move(p->bindingData))};
2225 Q_ASSERT(
d->size && (
d->size & (
d->size - 1)) == 0);
2226 size_t index = qHash(data) & (d->size - 1);
2228 while (p[index].data) {
2229 if (p[index].data == data)
2230 return &p[index].bindingData;
2232 if (index ==
d->size)
2244 else if (d->used*2 >= d->size)
2245 reallocate(d->size*2);
2246 Q_ASSERT(
d->size && (
d->size & (
d->size - 1)) == 0);
2247 size_t index = qHash(data) & (d->size - 1);
2249 while (p[index].data) {
2250 if (p[index].data == data)
2251 return &p[index].bindingData;
2253 if (index ==
d->size)
2259 new (p + index)
Pair{data, QPropertyBindingData()};
2260 return &p[index].bindingData;
2268 for (size_t i = 0; i <
d->size; ++i) {
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2289QBindingStorage::QBindingStorage()
2291 bindingStatus = &QT_PREPEND_NAMESPACE(bindingStatus);
2292 Q_ASSERT(bindingStatus);
2295QBindingStorage::~QBindingStorage()
2297 QBindingStoragePrivate(d).destroy();
2300void QBindingStorage::reinitAfterThreadMove()
2302 bindingStatus = &QT_PREPEND_NAMESPACE(bindingStatus);
2303 Q_ASSERT(bindingStatus);
2306void QBindingStorage::clear()
2308 QBindingStoragePrivate(d).destroy();
2310 bindingStatus =
nullptr;
2313void QBindingStorage::registerDependency_helper(
const QUntypedPropertyData *data)
const
2315 Q_ASSERT(bindingStatus);
2318 QtPrivate::BindingEvaluationState *currentBinding;
2319#ifdef QT_HAS_FAST_CURRENT_THREAD_ID
2320 const bool threadMatches = (QThread::currentThreadId() == bindingStatus->threadId);
2321 if (Q_LIKELY(threadMatches))
2322 currentBinding = bindingStatus->currentlyEvaluatingBinding;
2324 currentBinding = QT_PREPEND_NAMESPACE(bindingStatus).currentlyEvaluatingBinding;
2326 currentBinding = QT_PREPEND_NAMESPACE(bindingStatus).currentlyEvaluatingBinding;
2328 QUntypedPropertyData *dd =
const_cast<QUntypedPropertyData *>(data);
2329 if (!currentBinding)
2331 auto storage = QBindingStoragePrivate(d).get(dd,
true);
2334 storage->registerWithCurrentlyEvaluatingBinding(currentBinding);
2338QPropertyBindingData *QBindingStorage::bindingData_helper(
const QUntypedPropertyData *data)
const
2340 return QBindingStoragePrivate(d).get(data);
2343const QBindingStatus *QBindingStorage::status(QtPrivate::QBindingStatusAccessToken)
const
2345 return bindingStatus;
2348QPropertyBindingData *QBindingStorage::bindingData_helper(QUntypedPropertyData *data,
bool create)
2350 return QBindingStoragePrivate(d).get(data, create);
2357void initBindingStatusThreadId()
2359 bindingStatus.threadId = QThread::currentThreadId();
2364 auto ret = bindingStatus.currentlyEvaluatingBinding;
2365 bindingStatus.currentlyEvaluatingBinding =
nullptr;
2375
2376
2377
2378
2379
2380
2381
2384 return bindingStatus.currentlyEvaluatingBinding !=
nullptr;
2390 if (
const auto current = bindingStatus.currentCompatProperty)
2391 return current->property == property;
2400 case QtPrivate::BindableWarnings::NonBindableInterface:
2401 qCWarning(lcQPropertyBinding).noquote() << prefix.toString()
2402 <<
"The QBindable does not allow interaction with the binding.";
2404 case QtPrivate::BindableWarnings::ReadOnlyInterface:
2405 qCWarning(lcQPropertyBinding).noquote() << prefix.toString()
2406 <<
"The QBindable is read-only.";
2409 case QtPrivate::BindableWarnings::InvalidInterface:
2410 qCWarning(lcQPropertyBinding).noquote() << prefix.toString()
2411 <<
"The QBindable is invalid.";
2418 qCWarning(lcQPropertyBinding) <<
"setBinding: Could not set binding as the property expects it to be of type"
2420 <<
"but got" << expected.name() <<
"instead.";
2426
2427
2428
2432void getter(
const QUntypedPropertyData *d,
void *value)
2435 adaptor->bindingData().registerWithCurrentlyEvaluatingBinding();
2436 auto mt = adaptor->metaProperty().metaType();
2438 mt.construct(value, adaptor->metaProperty().read(adaptor->object()).data());
2441void setter(QUntypedPropertyData *d,
const void *value)
2444 adaptor->bindingData().removeBinding();
2445 adaptor->metaProperty().write(adaptor->object(),
2446 QVariant(adaptor->metaProperty().metaType(), value));
2452 return QUntypedPropertyBinding(adaptor->bindingData().binding());
2456 QtPrivate::QPropertyBindingFunction binding, QUntypedPropertyData *temp,
2460 type.destruct(value);
2461 type.construct(value, adaptor->metaProperty().read(adaptor->object()).data());
2462 if (binding.vtable->call(type, temp, binding.functor)) {
2463 adaptor->metaProperty().write(adaptor->object(), QVariant(type, value));
2470 QPropertyBindingWrapper wrapper)
2473 return adaptor->bindingData().setBinding(binding, d,
nullptr, wrapper);
2476void setObserver(
const QUntypedPropertyData *d, QPropertyObserver *observer)
2483 : QSlotObjectBase(&impl), obj(o), metaProperty_(p)
2487#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2501 if (!self->bindingData_.hasBinding())
2502 self->bindingData_.notifyObservers(self);
2522 if (!metaProperty.isValid()) {
2523 qCWarning(lcQPropertyBinding) <<
"QUntypedBindable: Property is not valid";
2527 if (metaProperty.isBindable()) {
2528 *
this = metaProperty.bindable(obj);
2532 if (!metaProperty.hasNotifySignal()) {
2533 qCWarning(lcQPropertyBinding)
2534 <<
"QUntypedBindable: Property" << metaProperty.name() <<
"has no notify signal";
2538 auto metatype =
iface->metaType();
2539 if (metaProperty.metaType() != metatype) {
2540 qCWarning(lcQPropertyBinding) <<
"QUntypedBindable: Property" << metaProperty.name()
2541 <<
"of type" << metaProperty.metaType().name()
2542 <<
"does not match requested type" << metatype.name();
2547 if (obj->metaObject()->property(metaProperty.propertyIndex()).name() != metaProperty.name()) {
2548 qCWarning(lcQPropertyBinding) <<
"QUntypedBindable: Property" << metaProperty.name()
2549 <<
"does not belong to this object";
2554 auto adaptor = QObjectPrivate::get(obj)->getPropertyAdaptorSlotObject(metaProperty);
2559 auto c = QObjectPrivate::connect(obj, metaProperty.notifySignalIndex(), obj, adaptor,
2560 Qt::DirectConnection);
2571 [=]() -> QMetaProperty {
2574 auto propertyIndex = obj->metaObject()->indexOfProperty(property);
2575 if (propertyIndex < 0) {
2576 qCWarning(lcQPropertyBinding)
2577 <<
"QUntypedBindable: No property named" << property;
2580 return obj->metaObject()->property(propertyIndex);
const QtPrivate::QBindableInterface * iface
Combined button and popup list for selecting options.
void printMetaTypeMismatch(QMetaType actual, QMetaType expected)
void printUnsuitableBindableWarning(QAnyStringView prefix, BindableWarnings::Reason reason)
void setter(QUntypedPropertyData *d, const void *value)
void getter(const QUntypedPropertyData *d, void *value)
bool bindingWrapper(QMetaType type, QUntypedPropertyData *d, QtPrivate::QPropertyBindingFunction binding, QUntypedPropertyData *temp, void *value)
QUntypedPropertyBinding getBinding(const QUntypedPropertyData *d)
QUntypedPropertyBinding setBinding(QUntypedPropertyData *d, const QUntypedPropertyBinding &binding, QPropertyBindingWrapper wrapper)
void setObserver(const QUntypedPropertyData *d, QPropertyObserver *observer)
Q_CORE_EXPORT bool isAnyBindingEvaluating()
Q_CORE_EXPORT void restoreBindingStatus(BindingEvaluationState *status)
QBindingStatus * getBindingStatus(QtPrivate::QBindingStatusAccessToken)
Q_CORE_EXPORT bool isPropertyInBindingWrapper(const QUntypedPropertyData *property)
Q_CORE_EXPORT void beginPropertyUpdateGroup()
Q_CORE_EXPORT void endPropertyUpdateGroup()
QPropertyBindingData bindingData
QUntypedPropertyData * data
static Pair * pairs(QBindingStorageData *dd)
QBindingStoragePrivate(QBindingStorageData *&_d)
void reallocate(size_t newSize)
QPropertyBindingData * get(QUntypedPropertyData *data, bool create)
QPropertyBindingData * get(const QUntypedPropertyData *data)
QPropertyObserverPointer firstObserver() const
QPropertyProxyBindingData delayedProperties[size]
void notify(qsizetype index)
static constexpr auto PageSize
void addProperty(const QPropertyBindingData *bindingData, QUntypedPropertyData *propertyData)
static constexpr qsizetype size
void evaluateBindings(PendingBindingObserverList &bindingObservers, qsizetype index, QBindingStatus *status)
QPropertyDelayedNotifications * next
void observeProperty(QPropertyBindingDataPointer property)
void setChangeHandler(QPropertyObserver::ChangeHandler changeHandler)
BindingEvaluationState(QPropertyBindingPrivate *binding, QBindingStatus *status)
BindingEvaluationState * previousState
BindingEvaluationState ** currentState
QtPrivate::BindingEvaluationState ** currentlyEvaluatingBindingList
CompatPropertySafePoint * previousState
CompatPropertySafePoint ** currentState
QtPrivate::BindingEvaluationState * bindingState