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
1440Qt::ItemFlags QRangeModel::flags(
const QModelIndex &index)
const
1442 Q_D(
const QRangeModel);
1443 return d->impl->call<QRangeModelImplBase::Flags>(index);
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467QVariant QRangeModel::headerData(
int section, Qt::Orientation orientation,
int role)
const
1469 Q_D(
const QRangeModel);
1470 return d->impl->call<QRangeModelImplBase::HeaderData>(section, orientation, role);
1474
1475
1476bool QRangeModel::setHeaderData(
int section, Qt::Orientation orientation,
const QVariant &data,
1479 return QAbstractItemModel::setHeaderData(section, orientation, data, role);
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503QVariant QRangeModel::data(
const QModelIndex &index,
int role)
const
1505 Q_D(
const QRangeModel);
1506 return d->impl->call<QRangeModelImplBase::Data>(index, role);
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
1535bool QRangeModel::setData(
const QModelIndex &index,
const QVariant &data,
int role)
1538 return d->impl->call<QRangeModelImplBase::SetData>(index, data, role);
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559QMap<
int, QVariant> QRangeModel::itemData(
const QModelIndex &index)
const
1561 Q_D(
const QRangeModel);
1562 return d->impl->call<QRangeModelImplBase::ItemData>(index);
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
1591bool QRangeModel::setItemData(
const QModelIndex &index,
const QMap<
int, QVariant> &data)
1594 return d->impl->call<QRangeModelImplBase::SetItemData>(index, data);
1598
1599
1600
1601
1602
1603
1604
1605bool QRangeModel::clearItemData(
const QModelIndex &index)
1608 return d->impl->call<QRangeModelImplBase::ClearItemData>(index);
1612
1613
1614
1615
1616
1617
1618
1619
1620
1623
1624
1625
1626
1627
1628
1629
1630
1631bool QRangeModel::insertColumns(
int column,
int count,
const QModelIndex &parent)
1634 return d->impl->call<QRangeModelImplBase::InsertColumns>(column, count, parent);
1638
1639
1640
1641
1642
1643
1644
1645
1646bool QRangeModel::removeColumns(
int column,
int count,
const QModelIndex &parent)
1649 return d->impl->call<QRangeModelImplBase::RemoveColumns>(column, count, parent);
1653
1654
1655
1656
1657
1658
1659
1660
1661bool QRangeModel::moveColumns(
const QModelIndex &sourceParent,
int sourceColumn,
int count,
1662 const QModelIndex &destinationParent,
int destinationColumn)
1665 return d->impl->call<QRangeModelImplBase::MoveColumns>(
1666 sourceParent, sourceColumn, count,
1667 destinationParent, destinationColumn);
1671
1672
1673
1674
1675
1676
1677
1678
1679
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692bool QRangeModel::insertRows(
int row,
int count,
const QModelIndex &parent)
1695 return d->impl->call<QRangeModelImplBase::InsertRows>(row, count, parent);
1699
1700
1701
1702
1703
1704
1705
1706bool QRangeModel::removeRows(
int row,
int count,
const QModelIndex &parent)
1709 return d->impl->call<QRangeModelImplBase::RemoveRows>(row, count, parent);
1713
1714
1715
1716
1717
1718
1719
1720
1721bool QRangeModel::moveRows(
const QModelIndex &sourceParent,
int sourceRow,
int count,
1722 const QModelIndex &destinationParent,
int destinationRow)
1725 return d->impl->call<QRangeModelImplBase::MoveRows>(
1726 sourceParent, sourceRow, count,
1727 destinationParent, destinationRow);
1731
1732
1733bool QRangeModel::canFetchMore(
const QModelIndex &parent)
const
1735 return QAbstractItemModel::canFetchMore(parent);
1739
1740
1741void QRangeModel::fetchMore(
const QModelIndex &parent)
1743 QAbstractItemModel::fetchMore(parent);
1747
1748
1749bool QRangeModel::hasChildren(
const QModelIndex &parent)
const
1751 return QAbstractItemModel::hasChildren(parent);
1755
1756
1757QModelIndex QRangeModel::buddy(
const QModelIndex &index)
const
1759 return QAbstractItemModel::buddy(index);
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1787
1788
1789
1790
1791bool QRangeModel::canDropMimeData(
const QMimeData *data, Qt::DropAction action,
1792 int row,
int column,
const QModelIndex &parent)
const
1794 Q_D(
const QRangeModel);
1795 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
1796 return QAbstractItemModel::canDropMimeData(data, action, row, column, parent);
1797 return d->impl->call<QRangeModelImplBase::CanDropMimeData>(data, action, row, column, parent);
1801
1802
1803
1804
1805bool QRangeModel::dropMimeData(
const QMimeData *data, Qt::DropAction action,
1806 int row,
int column,
const QModelIndex &parent)
1810 if (action == Qt::IgnoreAction)
1814 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
1815 return QAbstractItemModel::dropMimeData(data, action, row, column, parent);
1816 if (d->impl->call<QRangeModelImplBase::DropMimeData>(data, action, row, column, parent))
1822 row = rowCount(parent);
1823#if !defined(QT_NO_DATASTREAM)
1824 const QString defaultFormat = QAbstractItemModel::mimeTypes().at(0);
1825 if (data->hasFormat(defaultFormat)) {
1826 QByteArray encoded = data->data(defaultFormat);
1827 QDataStream stream(&encoded, QDataStream::ReadOnly);
1828 return decodeData(row, column, parent, stream);
1834bool QRangeModelImplBase::dropDataOnItem(
const QMimeData *data,
const QModelIndex &index)
1836#if !defined(QT_NO_DATASTREAM)
1837 const QString defaultFormat = m_rangeModel->QAbstractItemModel::mimeTypes().at(0);
1838 if (data->hasFormat(defaultFormat)) {
1839 QByteArray encoded = data->data(defaultFormat);
1840 QDataStream stream(&encoded, QDataStream::ReadOnly);
1841 return m_rangeModel->d_func()->dropOnItem(index, stream);
1850bool QRangeModelPrivate::compareModelIndex(
const QModelIndex &left,
const QModelIndex &right)
1852 if (!left.isValid())
1853 return right.isValid();
1854 if (!right.isValid())
1856 const QModelIndex leftCol0 = left.column() ? left.siblingAtColumn(0) : left;
1857 const QModelIndex rightCol0 = right.column() ? right.siblingAtColumn(0) : right;
1858 const QModelIndex leftParent = leftCol0.parent();
1859 const QModelIndex rightParent = rightCol0.parent();
1860 if (leftParent == rightParent) {
1861 if (left.row() == right.row())
1862 return left.column() < right.column();
1863 return left.row() < right.row();
1866 if (leftCol0 == rightParent)
1868 if (rightCol0 == leftParent)
1872 auto makePath = [](
const QModelIndex &index) {
1874 Q_ASSERT(index.column() == 0);
1875 QVarLengthArray<
int, 32> path{index.row()};
1876 QModelIndex parent = index.parent();
1877 while (parent.isValid()) {
1878 path.append(parent.row());
1879 parent = parent.parent();
1881 std::reverse(path.begin(), path.end());
1884 const auto leftPath = makePath(leftCol0);
1885 const auto rightPath = makePath(rightCol0);
1886 return leftPath < rightPath;
1890
1891
1892
1893
1894QMimeData *QRangeModel::mimeData(
const QModelIndexList &indexes)
const
1896 Q_D(
const QRangeModel);
1897 if (indexes.isEmpty())
1900 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
1901 return QAbstractItemModel::mimeData(indexes);
1904 QModelIndexList groupedList = indexes;
1905 std::sort(groupedList.begin(), groupedList.end(), QRangeModelPrivate::compareModelIndex);
1906 QMimeData *data = d->impl->call<QRangeModelImplBase::MimeData>(groupedList);
1909 const QString defaultFormat = QAbstractItemModel::mimeTypes().at(0);
1910 if (!mimeTypes().contains(defaultFormat))
1913 std::unique_ptr<QMimeData> defaultMimeData(QAbstractItemModel::mimeData(indexes));
1915 return defaultMimeData.release();
1917 if (defaultMimeData) {
1918 const QStringList defaultTypes = defaultMimeData->formats();
1919 for (
const auto &defaultType : defaultTypes)
1920 data->setData(defaultType, defaultMimeData->data(defaultType));
1926
1927
1928
1929
1930QStringList QRangeModel::mimeTypes()
const
1932 Q_D(
const QRangeModel);
1933 if (!d->m_mimeTypes) {
1934 d->m_mimeTypes = d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0)
1935 ? QAbstractItemModel::mimeTypes()
1936 : d->impl->call<QRangeModelImplBase::MimeTypes>();
1938 return *d->m_mimeTypes;
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951QModelIndexList QRangeModel::match(
const QModelIndex &start,
int role,
const QVariant &value,
1952 int hits, Qt::MatchFlags flags)
const
1954 Q_D(
const QRangeModel);
1955 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
1956 return QAbstractItemModel::match(start, role, value, hits, flags);
1957 return d->impl->call<QRangeModelImplBase::Match>(start, role, value, hits, flags);
1961
1962
1963void QRangeModel::multiData(
const QModelIndex &index, QModelRoleDataSpan roleDataSpan)
const
1965 Q_D(
const QRangeModel);
1966 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 11, 0))
1967 return QAbstractItemModel::multiData(index, roleDataSpan);
1968 d->impl->call<QRangeModelImplBase::MultiData>(index, roleDataSpan);
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1989QHash<
int, QByteArray> QRangeModelImplBase::roleNamesForMetaObject(
const QAbstractItemModel &model,
1990 const QMetaObject &metaObject)
1992 const auto defaults = model.QAbstractItemModel::roleNames();
1993 QHash<
int, QByteArray> result = {{Qt::RangeModelDataRole,
"modelData"}};
1994 int offset = metaObject.propertyOffset();
1995 for (
int i = offset; i < metaObject.propertyCount(); ++i) {
1996 const auto name = metaObject.property(i).name();
1997 const int defaultRole = defaults.key(name, -1);
1998 if (defaultRole != -1) {
2000 result[defaultRole] = name;
2002 result[Qt::UserRole + i - offset] = name;
2008QHash<
int, QByteArray> QRangeModelImplBase::roleNamesForSimpleType()
2011 return QHash<
int, QByteArray>{
2012 {Qt::DisplayRole,
"display"},
2013 {Qt::EditRole,
"edit"},
2014 {Qt::RangeModelDataRole,
"modelData"},
2019
2020
2021
2022
2023
2024QHash<
int, QByteArray> QRangeModel::roleNames()
const
2026 Q_D(
const QRangeModel);
2027 if (d->m_roleNames.isEmpty())
2028 d->m_roleNames = d->impl->call<QRangeModelImplBase::RoleNames>();
2030 return d->m_roleNames;
2033void QRangeModel::setRoleNames(
const QHash<
int, QByteArray> &names)
2036 if (d->m_roleNames == names)
2039 d->impl->call<QRangeModelImplBase::InvalidateCaches>();
2040 if (d->m_autoConnectPolicy != AutoConnectPolicy::None)
2041 d->impl->call<QRangeModelImplBase::SetAutoConnectPolicy>();
2043 d->m_roleNames = names;
2045 Q_EMIT roleNamesChanged();
2048void QRangeModel::resetRoleNames()
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2106QRangeModel::AutoConnectPolicy QRangeModel::autoConnectPolicy()
const
2108 Q_D(
const QRangeModel);
2109 return d->m_autoConnectPolicy;
2112void QRangeModel::setAutoConnectPolicy(QRangeModel::AutoConnectPolicy policy)
2115 if (d->m_autoConnectPolicy == policy)
2118 d->m_autoConnectPolicy = policy;
2119 d->impl->call<QRangeModelImplBase::SetAutoConnectPolicy>();
2120 Q_EMIT autoConnectPolicyChanged(policy);
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140void QRangeModel::sort(
int column, Qt::SortOrder order)
2143 if (d->m_interfaceVersion < QT_VERSION_CHECK(6, 12, 0))
2144 return QAbstractItemModel::sort(column, order);
2146 d->impl->call<QRangeModelImplBase::Sort>(column, order);
2147 } QT_CATCH(
const std::bad_alloc &) {
2148 qCritical(
"QRangeModel::sort ran out of memory, sort likely incomplete.");
2153
2154
2155
2156
2157
2158
2159
2160
2161int QRangeModel::sortRole()
const
2163 Q_D(
const QRangeModel);
2164 return d->m_sortRole;
2167void QRangeModel::setSortRole(
int role)
2170 if (d->m_sortRole == role)
2172 d->m_sortRole = role;
2173 Q_EMIT sortRoleChanged(d->m_sortRole);
2176void QRangeModel::resetSortRole()
2178 setSortRole(Qt::DisplayRole);
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192QCollator QRangeModel::sortCollator()
const
2194 Q_D(
const QRangeModel);
2195 return d->m_sortCollator.value_or(QCollator(QLocale::C));
2198void QRangeModel::setSortCollator(
const QCollator &collator)
2201 if (sortCollator() == collator)
2203 d->m_sortCollator = collator;
2204 Q_EMIT sortCollatorChanged(*d->m_sortCollator);
2207void QRangeModel::resetSortCollator()
2210 if (!d->m_sortCollator)
2212 d->m_sortCollator = std::nullopt;
2213 Q_EMIT sortCollatorChanged(sortCollator());
2217
2218
2219QSize QRangeModel::span(
const QModelIndex &index)
const
2221 return QAbstractItemModel::span(index);
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237Qt::DropActions QRangeModel::supportedDragActions()
const
2239 Q_D(
const QRangeModel);
2240 return d->m_supportedDragActions;
2243void QRangeModel::setSupportedDragActions(Qt::DropActions actions)
2246 actions = d->impl->call<QRangeModelImplBase::AdjustSupportedDragActions>(actions);
2247 if (actions == d->m_supportedDragActions)
2249 d->m_supportedDragActions = actions;
2250 Q_EMIT supportedDragActionsChanged(d->m_supportedDragActions);
2253void QRangeModel::resetSupportedDragActions()
2255 setSupportedDragActions(Qt::CopyAction);
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270Qt::DropActions QRangeModel::supportedDropActions()
const
2272 Q_D(
const QRangeModel);
2273 return d->m_supportedDropActions;
2276void QRangeModel::setSupportedDropActions(Qt::DropActions actions)
2279 actions = d->impl->call<QRangeModelImplBase::AdjustSupportedDropActions>(actions);
2280 if (actions == d->m_supportedDropActions)
2282 d->m_supportedDropActions = actions;
2283 Q_EMIT supportedDropActionsChanged(d->m_supportedDropActions);
2286void QRangeModel::resetSupportedDropActions()
2288 setSupportedDropActions(Qt::CopyAction);
2292
2293
2294void QRangeModel::resetInternalData()
2296 QAbstractItemModel::resetInternalData();
2300
2301
2302bool QRangeModel::event(QEvent *event)
2304 return QAbstractItemModel::event(event);
2308
2309
2310bool QRangeModel::eventFilter(QObject *object, QEvent *event)
2312 return QAbstractItemModel::eventFilter(object, event);
2317#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)