6#include <QtCore/qcollator.h>
7#include <QtCore/qmimedata.h>
8#include <QtCore/qpoint.h>
9#include <QtCore/qsize.h>
11#include <QtCore/private/qabstractitemmodel_p.h>
17class QRangeModelPrivate : QAbstractItemModelPrivate
19 Q_DECLARE_PUBLIC(QRangeModel)
22 explicit QRangeModelPrivate(std::unique_ptr<QRangeModelImplBase, QRangeModelImplBase::Deleter> impl)
23 : impl(std::move(impl))
25 this->impl->call<QRangeModelImplBase::InterfaceVersion>(m_interfaceVersion);
26 if (m_interfaceVersion >= QT_VERSION_CHECK(6, 12, 0)) {
27 m_supportedDropActions =
this->impl->call<QRangeModelImplBase::AdjustSupportedDropActions>(
28 m_supportedDropActions
33 std::unique_ptr<QRangeModelImplBase, QRangeModelImplBase::Deleter> impl;
34 friend class QRangeModelImplBase;
36 static QRangeModelPrivate *get(QRangeModel *model) {
return model->d_func(); }
37 static const QRangeModelPrivate *get(
const QRangeModel *model) {
return model->d_func(); }
39 mutable QHash<
int, QByteArray> m_roleNames;
40 QRangeModel::AutoConnectPolicy m_autoConnectPolicy = QRangeModel::AutoConnectPolicy::None;
41 bool m_dataChangedDispatchBlocked =
false;
42 int m_interfaceVersion = -1;
43 int m_sortRole = Qt::DisplayRole;
44 std::optional<QCollator> m_sortCollator;
45 mutable std::optional<QStringList> m_mimeTypes;
46 Qt::DropActions m_supportedDragActions = Qt::CopyAction;
47 Qt::DropActions m_supportedDropActions = Qt::CopyAction;
49 static void emitDataChanged(
const QModelIndex &index,
int role)
51 const auto *model =
static_cast<
const QRangeModel *>(index.model());
52 if (!get(model)->m_dataChangedDispatchBlocked)
53 const_cast<QRangeModel *>(model)->dataChanged(index, index, {role});
56 static bool compareModelIndex(
const QModelIndex &left,
const QModelIndex &right);
70 Q_ASSERT(
std::holds_alternative<Data>(storage));
92 QMetaObject::Connection connection;
95 QPersistentModelIndex index;
103 Q_ASSERT(
std::holds_alternative<Data>(storage));
104 const auto &data =
std::get<Data>(storage);
105 if (!data.index.isValid()) {
106 if (!QObject::disconnect(connection))
107 qWarning() <<
"Failed to break connection for" << Qt::ItemDataRole(data.role);
109 QRangeModelPrivate::emitDataChanged(data.index, data.role);
123 void operator()() { QRangeModelPrivate::emitDataChanged(index, role); }
130QRangeModel::QRangeModel(QRangeModelImplBase *impl, QObject *parent)
131 : QAbstractItemModel(*
new QRangeModelPrivate({impl, {}}), parent)
135QRangeModelImplBase *QRangeModelImplBase::getImplementation(QRangeModel *model)
137 return model->d_func()->impl.get();
140const QRangeModelImplBase *QRangeModelImplBase::getImplementation(
const QRangeModel *model)
142 return model->d_func()->impl.get();
145QScopedValueRollback<
bool> QRangeModelImplBase::blockDataChangedDispatch()
147 return QScopedValueRollback(m_rangeModel->d_func()->m_dataChangedDispatchBlocked,
true);
150int QRangeModelImplBase::sortRole()
const
152 return m_rangeModel->sortRole();
155const QCollator *QRangeModelImplBase::sortCollator()
const
157 const QRangeModelPrivate *d = QRangeModelPrivate::get(m_rangeModel);
158 return d->m_sortCollator ? &d->m_sortCollator.value() :
nullptr;
161QVariant QRangeModelImplBase::convertMatchValue(
const QVariant &value, Qt::MatchFlags flags)
163 QVariant matchValue = value;
164 const Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive
165 ? Qt::CaseSensitive : Qt::CaseInsensitive;
166 switch ((flags & Qt::MatchTypeMask).toInt()) {
167#if QT_CONFIG(regularexpression)
168 case Qt::MatchRegularExpression:
169 case Qt::MatchWildcard:
170 if (value.metaType() != QMetaType::fromType<QRegularExpression>()) {
171 QRegularExpression rx;
172 if (flags & Qt::MatchWildcard) {
173 rx.setPattern(QRegularExpression::wildcardToRegularExpression(
174 value.toString(), QRegularExpression::NonPathWildcardConversion));
176 rx.setPattern(value.toString());
178 if (cs == Qt::CaseInsensitive)
179 rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
184 case Qt::MatchStartsWith:
185 case Qt::MatchEndsWith:
186 case Qt::MatchFixedString:
187 case Qt::MatchContains:
188 matchValue.convert(QMetaType::fromType<QString>());
196bool QRangeModelImplBase::matchValue(
const QString &itemData,
const QVariant &value,
197 Qt::MatchFlags flags)
200 const uint matchType = (flags & Qt::MatchTypeMask).toInt();
201 const Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive
202 ? Qt::CaseSensitive : Qt::CaseInsensitive;
204#if QT_CONFIG(regularexpression)
205 case Qt::MatchRegularExpression:
206 case Qt::MatchWildcard:
207 return itemData.contains(value.toRegularExpression());
209 case Qt::MatchStartsWith:
210 return itemData.startsWith(value.toString(), cs);
211 case Qt::MatchEndsWith:
212 return itemData.endsWith(value.toString(), cs);
213 case Qt::MatchFixedString:
214 return itemData.compare(value.toString(), cs) == 0;
215 case Qt::MatchContains:
216 return itemData.contains(value.toString(), cs);
223
224
225
226
227QHash<
int, QMetaProperty> QRangeModelImplBase::roleProperties(
const QAbstractItemModel &model,
228 const QMetaObject &metaObject)
230 const auto roles = model.roleNames();
231 QHash<
int, QMetaProperty> result;
232 for (
auto &&[role, roleName] : roles.asKeyValueRange()) {
233 if (role == Qt::RangeModelDataRole)
235 result[role] = metaObject.property(metaObject.indexOfProperty(roleName));
240QHash<
int, QMetaProperty> QRangeModelImplBase::columnProperties(
const QMetaObject &metaObject)
242 QHash<
int, QMetaProperty> result;
243 const int propertyOffset = metaObject.propertyOffset();
244 for (
int p = propertyOffset; p < metaObject.propertyCount(); ++p)
245 result[p - propertyOffset] = metaObject.property(p);
249QRangeModelDetails::AutoConnectContext::~AutoConnectContext() =
default;
251template <
auto Handler>
253 QRangeModelDetails::AutoConnectContext *context,
254 const QHash<
int, QMetaProperty> &properties)
259 auto connect = [item, context](
const QModelIndex &cell,
int role,
const QMetaProperty &property) {
260 if (property.hasNotifySignal()) {
261 if (!Handler(cell, item, context, role, property))
264 qWarning() <<
"Property" << property.name() <<
"for" << Qt::ItemDataRole(role)
265 <<
"at" << cell <<
"has no notify signal";
270 if (context->mapping == QRangeModelDetails::AutoConnectContext::AutoConnectMapping::Roles) {
271 for (
auto &&[role, property] : properties.asKeyValueRange())
272 connect(index, role, property);
274 for (
auto &&[column, property] : properties.asKeyValueRange())
275 connect(index.siblingAtColumn(column), Qt::DisplayRole, property);
280bool QRangeModelImplBase::connectProperty(
const QModelIndex &index,
const QObject *item,
281 QRangeModelDetails::AutoConnectContext *context,
282 int role,
const QMetaProperty &property)
286 PropertyChangedHandler handler{index, role};
287 auto connection = property.enclosingMetaObject()->connect(item, property.notifySignal(),
288 context, std::move(handler));
290 qWarning() <<
"Failed to connect to" << item << property.name();
298 handler = std::move(connection);
303bool QRangeModelImplBase::connectProperties(
const QModelIndex &index,
const QObject *item,
304 QRangeModelDetails::AutoConnectContext *context,
305 const QHash<
int, QMetaProperty> &properties)
307 return connectPropertiesHelper<QRangeModelImplBase::connectProperty>(index, item, context, properties);
310bool QRangeModelImplBase::connectPropertyConst(
const QModelIndex &index,
const QObject *item,
311 QRangeModelDetails::AutoConnectContext *context,
312 int role,
const QMetaProperty &property)
316 ConstPropertyChangedHandler handler{index, role};
317 if (!property.enclosingMetaObject()->connect(item, property.notifySignal(),
318 context, std::move(handler))) {
319 qWarning() <<
"Failed to connect to" << item << property.name();
326bool QRangeModelImplBase::connectPropertiesConst(
const QModelIndex &index,
const QObject *item,
327 QRangeModelDetails::AutoConnectContext *context,
328 const QHash<
int, QMetaProperty> &properties)
330 return connectPropertiesHelper<QRangeModelImplBase::connectPropertyConst>(index, item, context, properties);
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
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
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
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
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
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
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
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
1322
1323
1324
1325
1326
1327QRangeModel::~QRangeModel() =
default;
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339QModelIndex QRangeModel::index(
int row,
int column,
const QModelIndex &parent)
const
1341 Q_D(
const QRangeModel);
1342 return d->impl->call<QRangeModelImplBase::Index>(row, column, parent);
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357QModelIndex QRangeModel::parent(
const QModelIndex &child)
const
1359 Q_D(
const QRangeModel);
1360 return d->impl->call<QRangeModelImplBase::Parent>(child);
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374QModelIndex QRangeModel::sibling(
int row,
int column,
const QModelIndex &index)
const
1376 Q_D(
const QRangeModel);
1377 return d->impl->call<QRangeModelImplBase::Sibling>(row, column, index);
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393int QRangeModel::rowCount(
const QModelIndex &parent)
const
1395 Q_D(
const QRangeModel);
1396 return d->impl->call<QRangeModelImplBase::RowCount>(parent);
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412int QRangeModel::columnCount(
const QModelIndex &parent)
const
1414 Q_D(
const QRangeModel);
1415 return d->impl->call<QRangeModelImplBase::ColumnCount>(parent);
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
1445Qt::ItemFlags QRangeModel::flags(
const QModelIndex &index)
const
1447 Q_D(
const QRangeModel);
1448 return d->impl->call<QRangeModelImplBase::Flags>(index);
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
1480QVariant QRangeModel::headerData(
int section, Qt::Orientation orientation,
int role)
const
1482 Q_D(
const QRangeModel);
1483 return d->impl->call<QRangeModelImplBase::HeaderData>(section, orientation, role);
1487
1488
1489bool QRangeModel::setHeaderData(
int section, Qt::Orientation orientation,
const QVariant &data,
1492 return QAbstractItemModel::setHeaderData(section, orientation, data, role);
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516QVariant QRangeModel::data(
const QModelIndex &index,
int role)
const
1518 Q_D(
const QRangeModel);
1519 return d->impl->call<QRangeModelImplBase::Data>(index, role);
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
1548bool QRangeModel::setData(
const QModelIndex &index,
const QVariant &data,
int role)
1551 return d->impl->call<QRangeModelImplBase::SetData>(index, data, role);
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572QMap<
int, QVariant> QRangeModel::itemData(
const QModelIndex &index)
const
1574 Q_D(
const QRangeModel);
1575 return d->impl->call<QRangeModelImplBase::ItemData>(index);
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
1604bool QRangeModel::setItemData(
const QModelIndex &index,
const QMap<
int, QVariant> &data)
1607 return d->impl->call<QRangeModelImplBase::SetItemData>(index, data);
1611
1612
1613
1614
1615
1616
1617
1618bool QRangeModel::clearItemData(
const QModelIndex &index)
1621 return d->impl->call<QRangeModelImplBase::ClearItemData>(index);
1625
1626
1627
1628
1629
1630
1631
1632
1633
1636
1637
1638
1639
1640
1641
1642
1643
1644bool QRangeModel::insertColumns(
int column,
int count,
const QModelIndex &parent)
1647 return d->impl->call<QRangeModelImplBase::InsertColumns>(column, count, parent);
1651
1652
1653
1654
1655
1656
1657
1658
1659bool QRangeModel::removeColumns(
int column,
int count,
const QModelIndex &parent)
1662 return d->impl->call<QRangeModelImplBase::RemoveColumns>(column, count, parent);
1666
1667
1668
1669
1670
1671
1672
1673
1674bool QRangeModel::moveColumns(
const QModelIndex &sourceParent,
int sourceColumn,
int count,
1675 const QModelIndex &destinationParent,
int destinationColumn)
1678 return d->impl->call<QRangeModelImplBase::MoveColumns>(
1679 sourceParent, sourceColumn, count,
1680 destinationParent, destinationColumn);
1684
1685
1686
1687
1688
1689
1690
1691
1692
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705bool QRangeModel::insertRows(
int row,
int count,
const QModelIndex &parent)
1708 return d->impl->call<QRangeModelImplBase::InsertRows>(row, count, parent);
1712
1713
1714
1715
1716
1717
1718
1719bool QRangeModel::removeRows(
int row,
int count,
const QModelIndex &parent)
1722 return d->impl->call<QRangeModelImplBase::RemoveRows>(row, count, parent);
1726
1727
1728
1729
1730
1731
1732
1733
1734bool QRangeModel::moveRows(
const QModelIndex &sourceParent,
int sourceRow,
int count,
1735 const QModelIndex &destinationParent,
int destinationRow)
1738 return d->impl->call<QRangeModelImplBase::MoveRows>(
1739 sourceParent, sourceRow, count,
1740 destinationParent, destinationRow);
1744
1745
1746bool QRangeModel::canFetchMore(
const QModelIndex &parent)
const
1748 return QAbstractItemModel::canFetchMore(parent);
1752
1753
1754void QRangeModel::fetchMore(
const QModelIndex &parent)
1756 QAbstractItemModel::fetchMore(parent);
1760
1761
1762bool QRangeModel::hasChildren(
const QModelIndex &parent)
const
1764 return QAbstractItemModel::hasChildren(parent);
1768
1769
1770QModelIndex QRangeModel::buddy(
const QModelIndex &index)
const
1772 return QAbstractItemModel::buddy(index);
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
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
1827
1828
1829
1830
1831
1832
1833bool QRangeModel::canDropMimeData(
const QMimeData *data, Qt::DropAction action,
1834 int row,
int column,
const QModelIndex &parent)
const
1836 Q_D(
const QRangeModel);
1837 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
1838 return QAbstractItemModel::canDropMimeData(data, action, row, column, parent);
1839 return d->impl->call<QRangeModelImplBase::CanDropMimeData>(data, action, row, column, parent);
1843
1844
1845
1846
1847
1848
1849bool QRangeModel::dropMimeData(
const QMimeData *data, Qt::DropAction action,
1850 int row,
int column,
const QModelIndex &parent)
1854 if (action == Qt::IgnoreAction)
1858 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
1859 return QAbstractItemModel::dropMimeData(data, action, row, column, parent);
1860 if (d->impl->call<QRangeModelImplBase::DropMimeData>(data, action, row, column, parent))
1866 row = rowCount(parent);
1867#if !defined(QT_NO_DATASTREAM)
1868 const QString defaultFormat = QAbstractItemModel::mimeTypes().at(0);
1869 if (data->hasFormat(defaultFormat)) {
1870 QByteArray encoded = data->data(defaultFormat);
1871 QDataStream stream(&encoded, QDataStream::ReadOnly);
1872 return decodeData(row, column, parent, stream);
1878bool QRangeModelImplBase::dropDataOnItem(
const QMimeData *data,
const QModelIndex &index)
1880#if !defined(QT_NO_DATASTREAM)
1881 const QString defaultFormat = m_rangeModel->QAbstractItemModel::mimeTypes().at(0);
1882 if (data->hasFormat(defaultFormat)) {
1883 QByteArray encoded = data->data(defaultFormat);
1884 QDataStream stream(&encoded, QDataStream::ReadOnly);
1885 return m_rangeModel->d_func()->dropOnItem(index, stream);
1894bool QRangeModelPrivate::compareModelIndex(
const QModelIndex &left,
const QModelIndex &right)
1896 if (!left.isValid())
1897 return right.isValid();
1898 if (!right.isValid())
1900 const QModelIndex leftCol0 = left.column() ? left.siblingAtColumn(0) : left;
1901 const QModelIndex rightCol0 = right.column() ? right.siblingAtColumn(0) : right;
1902 const QModelIndex leftParent = leftCol0.parent();
1903 const QModelIndex rightParent = rightCol0.parent();
1904 if (leftParent == rightParent) {
1905 if (left.row() == right.row())
1906 return left.column() < right.column();
1907 return left.row() < right.row();
1910 if (leftCol0 == rightParent)
1912 if (rightCol0 == leftParent)
1916 auto makePath = [](
const QModelIndex &index) {
1918 Q_ASSERT(index.column() == 0);
1919 QVarLengthArray<
int, 32> path{index.row()};
1920 QModelIndex parent = index.parent();
1921 while (parent.isValid()) {
1922 path.append(parent.row());
1923 parent = parent.parent();
1925 std::reverse(path.begin(), path.end());
1928 const auto leftPath = makePath(leftCol0);
1929 const auto rightPath = makePath(rightCol0);
1930 return leftPath < rightPath;
1934
1935
1936
1937
1938
1939
1940QMimeData *QRangeModel::mimeData(
const QModelIndexList &indexes)
const
1942 Q_D(
const QRangeModel);
1943 if (indexes.isEmpty())
1946 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
1947 return QAbstractItemModel::mimeData(indexes);
1950 QModelIndexList groupedList = indexes;
1951 std::sort(groupedList.begin(), groupedList.end(), QRangeModelPrivate::compareModelIndex);
1952 QMimeData *data = d->impl->call<QRangeModelImplBase::MimeData>(groupedList);
1955 const QString defaultFormat = QAbstractItemModel::mimeTypes().at(0);
1956 if (!mimeTypes().contains(defaultFormat))
1959 std::unique_ptr<QMimeData> defaultMimeData(QAbstractItemModel::mimeData(indexes));
1961 return defaultMimeData.release();
1963 if (defaultMimeData) {
1964 const QStringList defaultTypes = defaultMimeData->formats();
1965 for (
const auto &defaultType : defaultTypes)
1966 data->setData(defaultType, defaultMimeData->data(defaultType));
1972
1973
1974
1975
1976
1977
1978QStringList QRangeModel::mimeTypes()
const
1980 Q_D(
const QRangeModel);
1981 if (!d->m_mimeTypes) {
1982 d->m_mimeTypes = d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0)
1983 ? QAbstractItemModel::mimeTypes()
1984 : d->impl->call<QRangeModelImplBase::MimeTypes>();
1986 return *d->m_mimeTypes;
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999QModelIndexList QRangeModel::match(
const QModelIndex &start,
int role,
const QVariant &value,
2000 int hits, Qt::MatchFlags flags)
const
2002 Q_D(
const QRangeModel);
2003 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
2004 return QAbstractItemModel::match(start, role, value, hits, flags);
2005 return d->impl->call<QRangeModelImplBase::Match>(start, role, value, hits, flags);
2009
2010
2011void QRangeModel::multiData(
const QModelIndex &index, QModelRoleDataSpan roleDataSpan)
const
2013 Q_D(
const QRangeModel);
2014 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 11, 0))
2015 return QAbstractItemModel::multiData(index, roleDataSpan);
2016 d->impl->call<QRangeModelImplBase::MultiData>(index, roleDataSpan);
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2037QHash<
int, QByteArray> QRangeModelImplBase::roleNamesForMetaObject(
const QAbstractItemModel &model,
2038 const QMetaObject &metaObject)
2040 const auto defaults = model.QAbstractItemModel::roleNames();
2041 QHash<
int, QByteArray> result = {{Qt::RangeModelDataRole,
"modelData"}};
2042 int offset = metaObject.propertyOffset();
2043 for (
int i = offset; i < metaObject.propertyCount(); ++i) {
2044 const auto name = metaObject.property(i).name();
2045 const int defaultRole = defaults.key(name, -1);
2046 if (defaultRole != -1) {
2048 result[defaultRole] = name;
2050 result[Qt::UserRole + i - offset] = name;
2056QHash<
int, QByteArray> QRangeModelImplBase::roleNamesForSimpleType()
2059 return QHash<
int, QByteArray>{
2060 {Qt::DisplayRole,
"display"},
2061 {Qt::EditRole,
"edit"},
2062 {Qt::RangeModelDataRole,
"modelData"},
2067
2068
2069
2070
2071
2072QHash<
int, QByteArray> QRangeModel::roleNames()
const
2074 Q_D(
const QRangeModel);
2075 if (d->m_roleNames.isEmpty())
2076 d->m_roleNames = d->impl->call<QRangeModelImplBase::RoleNames>();
2078 return d->m_roleNames;
2081void QRangeModel::setRoleNames(
const QHash<
int, QByteArray> &names)
2084 if (d->m_roleNames == names)
2087 d->impl->call<QRangeModelImplBase::InvalidateCaches>();
2088 if (d->m_autoConnectPolicy != AutoConnectPolicy::None)
2089 d->impl->call<QRangeModelImplBase::SetAutoConnectPolicy>();
2091 d->m_roleNames = names;
2093 Q_EMIT roleNamesChanged();
2096void QRangeModel::resetRoleNames()
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
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2154QRangeModel::AutoConnectPolicy QRangeModel::autoConnectPolicy()
const
2156 Q_D(
const QRangeModel);
2157 return d->m_autoConnectPolicy;
2160void QRangeModel::setAutoConnectPolicy(QRangeModel::AutoConnectPolicy policy)
2163 if (d->m_autoConnectPolicy == policy)
2166 d->m_autoConnectPolicy = policy;
2167 d->impl->call<QRangeModelImplBase::SetAutoConnectPolicy>();
2168 Q_EMIT autoConnectPolicyChanged(policy);
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188void QRangeModel::sort(
int column, Qt::SortOrder order)
2191 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
2192 return QAbstractItemModel::sort(column, order);
2194 d->impl->call<QRangeModelImplBase::Sort>(column, order);
2195 } QT_CATCH(
const std::bad_alloc &) {
2196 qCritical(
"QRangeModel::sort ran out of memory, sort likely incomplete.");
2201
2202
2203
2204
2205
2206
2207
2208
2209int QRangeModel::sortRole()
const
2211 Q_D(
const QRangeModel);
2212 return d->m_sortRole;
2215void QRangeModel::setSortRole(
int role)
2218 if (d->m_sortRole == role)
2220 d->m_sortRole = role;
2221 Q_EMIT sortRoleChanged(d->m_sortRole);
2224void QRangeModel::resetSortRole()
2226 setSortRole(Qt::DisplayRole);
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240QCollator QRangeModel::sortCollator()
const
2242 Q_D(
const QRangeModel);
2243 return d->m_sortCollator.value_or(QCollator(QLocale::C));
2246void QRangeModel::setSortCollator(
const QCollator &collator)
2249 if (sortCollator() == collator)
2251 d->m_sortCollator = collator;
2252 Q_EMIT sortCollatorChanged(*d->m_sortCollator);
2255void QRangeModel::resetSortCollator()
2258 if (!d->m_sortCollator)
2260 d->m_sortCollator = std::nullopt;
2261 Q_EMIT sortCollatorChanged(sortCollator());
2265
2266
2267QSize QRangeModel::span(
const QModelIndex &index)
const
2269 return QAbstractItemModel::span(index);
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285Qt::DropActions QRangeModel::supportedDragActions()
const
2287 Q_D(
const QRangeModel);
2288 return d->m_supportedDragActions;
2291void QRangeModel::setSupportedDragActions(Qt::DropActions actions)
2294 actions = d->impl->call<QRangeModelImplBase::AdjustSupportedDragActions>(actions);
2295 if (actions == d->m_supportedDragActions)
2297 d->m_supportedDragActions = actions;
2298 Q_EMIT supportedDragActionsChanged(d->m_supportedDragActions);
2301void QRangeModel::resetSupportedDragActions()
2303 setSupportedDragActions(Qt::CopyAction);
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318Qt::DropActions QRangeModel::supportedDropActions()
const
2320 Q_D(
const QRangeModel);
2321 return d->m_supportedDropActions;
2324void QRangeModel::setSupportedDropActions(Qt::DropActions actions)
2327 actions = d->impl->call<QRangeModelImplBase::AdjustSupportedDropActions>(actions);
2328 if (actions == d->m_supportedDropActions)
2330 d->m_supportedDropActions = actions;
2331 Q_EMIT supportedDropActionsChanged(d->m_supportedDropActions);
2334void QRangeModel::resetSupportedDropActions()
2336 setSupportedDropActions(Qt::CopyAction);
2340
2341
2342void QRangeModel::resetInternalData()
2344 QAbstractItemModel::resetInternalData();
2348
2349
2350bool QRangeModel::event(QEvent *event)
2352 return QAbstractItemModel::event(event);
2356
2357
2358bool QRangeModel::eventFilter(QObject *object, QEvent *event)
2360 return QAbstractItemModel::eventFilter(object, event);
2365#include "moc_qrangemodel.cpp"
static bool connectPropertiesHelper(const QModelIndex &index, const QObject *item, QRangeModelDetails::AutoConnectContext *context, const QHash< int, QMetaProperty > &properties)
~ConstPropertyChangedHandler()=default
ConstPropertyChangedHandler(ConstPropertyChangedHandler &&other) noexcept=default
ConstPropertyChangedHandler(const QModelIndex &index, int role)
PropertyChangedHandler & operator=(PropertyChangedHandler &&)=delete
PropertyChangedHandler(PropertyChangedHandler &&other) noexcept
PropertyChangedHandler(const PropertyChangedHandler &)=delete
PropertyChangedHandler & operator=(const PropertyChangedHandler &)=delete
~PropertyChangedHandler()=default
PropertyChangedHandler(const QPersistentModelIndex &index, int role)
PropertyChangedHandler & operator=(QMetaObject::Connection &&connection)