187 oldSelection = q->selectionModel()->selection();
188 oldCurrent = q->selectionModel()->currentIndex();
192 case QScroller::Dragging:
194 if (q->selectionModel()) {
195 q->selectionModel()->select(oldSelection, QItemSelectionModel::ClearAndSelect);
197 const bool wasAutoScroll = autoScroll;
199 q->selectionModel()->setCurrentIndex(oldCurrent, QItemSelectionModel::NoUpdate);
200 autoScroll = wasAutoScroll;
205 oldSelection = QItemSelection();
206 oldCurrent = QModelIndex();
214void QAbstractItemViewPrivate::delegateSizeHintChanged(
const QModelIndex &index)
216 Q_Q(QAbstractItemView);
218 if (!model->checkIndex(index))
219 qWarning(
"Delegate size hint changed for a model index that does not belong to this view");
221 QMetaObject::invokeMethod(q, &QAbstractItemView::doItemsLayout, Qt::QueuedConnection);
224void QAbstractItemViewPrivate::connectDelegate(QAbstractItemDelegate *delegate)
228 Q_Q(QAbstractItemView);
229 QObject::connect(delegate, &QAbstractItemDelegate::closeEditor,
230 q, &QAbstractItemView::closeEditor);
231 QObject::connect(delegate, &QAbstractItemDelegate::commitData,
232 q, &QAbstractItemView::commitData);
233 QObjectPrivate::connect(delegate, &QAbstractItemDelegate::sizeHintChanged,
234 this, &QAbstractItemViewPrivate::delegateSizeHintChanged);
237void QAbstractItemViewPrivate::disconnectDelegate(QAbstractItemDelegate *delegate)
241 Q_Q(QAbstractItemView);
242 QObject::disconnect(delegate, &QAbstractItemDelegate::closeEditor,
243 q, &QAbstractItemView::closeEditor);
244 QObject::disconnect(delegate, &QAbstractItemDelegate::commitData,
245 q, &QAbstractItemView::commitData);
246 QObjectPrivate::disconnect(delegate, &QAbstractItemDelegate::sizeHintChanged,
247 this, &QAbstractItemViewPrivate::delegateSizeHintChanged);
250void QAbstractItemViewPrivate::disconnectAll()
252 Q_Q(QAbstractItemView);
253 for (
const QMetaObject::Connection &connection : modelConnections)
254 QObject::disconnect(connection);
255 for (
const QMetaObject::Connection &connection : scrollbarConnections)
256 QObject::disconnect(connection);
257 disconnectDelegate(itemDelegate);
258 for (QAbstractItemDelegate *delegate : std::as_const(rowDelegates))
259 disconnectDelegate(delegate);
260 for (QAbstractItemDelegate *delegate : std::as_const(columnDelegates))
261 disconnectDelegate(delegate);
262 if (model && selectionModel) {
263 QObject::disconnect(model, &QAbstractItemModel::destroyed,
264 selectionModel, &QItemSelectionModel::deleteLater);
266 if (selectionModel) {
267 QObject::disconnect(selectionModel, &QItemSelectionModel::selectionChanged,
268 q, &QAbstractItemView::selectionChanged);
269 QObject::disconnect(selectionModel, &QItemSelectionModel::currentChanged,
270 q, &QAbstractItemView::currentChanged);
272 for (
const auto &info : std::as_const(indexEditorHash)) {
273 if (!info.isStatic && info.widget)
274 QObject::disconnect(info.widget, &QWidget::destroyed, q, &QAbstractItemView::editorDestroyed);
276#if QT_CONFIG(gestures) && QT_CONFIG(scroller)
277 QObject::disconnect(scollerConnection);
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
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
418
419
420
421
422
423
426
427
428
429
430
431
432
433
434
435
439
440
441
442
443
444
445
446
447
448
449
450
451
452
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
473
474
475
476
477
478
479
480
481
482
483
484
485
488
489
490
491
492
493
494
495
496
497
500
501
502
503
504
505
506
507
508
509
510
513
514
515
516
517
518
519
522
523
524
525
526
527
528
529
532
533
534
535
536
537
538
539
540
543
544
545
546
547
548
549
550
553
554
555
556
557
558
559
562
563
564
565
566
567
568
569
570
571
572
575
576
577
578
579
580
581
582
585
586
587
588
589
590
591
592
595
596
597
598
599
600
601
602
605
606
607
608
609
610
611
612
615
616
617
618
619
620
621
622
625
626
627
628
629
630
631
632
633
634
637
638
639
640
641
642
643
644
645
646
647
648
651
652
653
654
655
656
657
658
659
662
663
664QAbstractItemView::QAbstractItemView(QWidget *parent)
665 : QAbstractScrollArea(*(
new QAbstractItemViewPrivate), parent)
671
672
673QAbstractItemView::QAbstractItemView(QAbstractItemViewPrivate &dd, QWidget *parent)
674 : QAbstractScrollArea(dd, parent)
680
681
682QAbstractItemView::~QAbstractItemView()
684 Q_D(QAbstractItemView);
686 d->delayedReset.stop();
687 d->updateTimer.stop();
688 d->delayedEditing.stop();
689 d->delayedAutoScroll.stop();
690 d->autoScrollTimer.stop();
691 d->delayedLayout.stop();
692 d->fetchMoreTimer.stop();
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716void QAbstractItemView::setModel(QAbstractItemModel *model)
718 Q_D(QAbstractItemView);
719 if (model == d->model)
721 if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
722 for (
const QMetaObject::Connection &connection : d->modelConnections)
723 disconnect(connection);
725 d->model = (model ? model : QAbstractItemModelPrivate::staticEmptyModel());
727 if (d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
728 d->modelConnections = {
729 QObjectPrivate::connect(d->model, &QAbstractItemModel::destroyed,
730 d, &QAbstractItemViewPrivate::modelDestroyed),
731 QObject::connect(d->model, &QAbstractItemModel::dataChanged,
732 this, &QAbstractItemView::dataChanged),
733 QObjectPrivate::connect(d->model, &QAbstractItemModel::headerDataChanged,
734 d, &QAbstractItemViewPrivate::headerDataChanged),
735 QObject::connect(d->model, &QAbstractItemModel::rowsInserted,
736 this, &QAbstractItemView::rowsInserted),
737 QObjectPrivate::connect(d->model, &QAbstractItemModel::rowsInserted,
738 d, &QAbstractItemViewPrivate::rowsInserted),
739 QObject::connect(d->model, &QAbstractItemModel::rowsAboutToBeRemoved,
740 this, &QAbstractItemView::rowsAboutToBeRemoved),
741 QObjectPrivate::connect(d->model, &QAbstractItemModel::rowsRemoved,
742 d, &QAbstractItemViewPrivate::rowsRemoved),
743 QObjectPrivate::connect(d->model, &QAbstractItemModel::rowsMoved,
744 d, &QAbstractItemViewPrivate::rowsMoved),
745 QObjectPrivate::connect(d->model, &QAbstractItemModel::columnsAboutToBeRemoved,
746 d, &QAbstractItemViewPrivate::columnsAboutToBeRemoved),
747 QObjectPrivate::connect(d->model, &QAbstractItemModel::columnsRemoved,
748 d, &QAbstractItemViewPrivate::columnsRemoved),
749 QObjectPrivate::connect(d->model, &QAbstractItemModel::columnsInserted,
750 d, &QAbstractItemViewPrivate::columnsInserted),
751 QObjectPrivate::connect(d->model, &QAbstractItemModel::columnsMoved,
752 d, &QAbstractItemViewPrivate::columnsMoved),
753 QObject::connect(d->model, &QAbstractItemModel::modelReset,
754 this, &QAbstractItemView::reset),
755 QObjectPrivate::connect(d->model, &QAbstractItemModel::layoutChanged,
756 d, &QAbstractItemViewPrivate::layoutChanged),
760 QItemSelectionModel *selection_model =
new QItemSelectionModel(d->model,
this);
761 connect(d->model, &QAbstractItemModel::destroyed,
762 selection_model, &QItemSelectionModel::deleteLater);
763 setSelectionModel(selection_model);
769
770
771QAbstractItemModel *QAbstractItemView::model()
const
773 Q_D(
const QAbstractItemView);
774 return (d->model == QAbstractItemModelPrivate::staticEmptyModel() ?
nullptr : d->model);
778
779
780
781
782
783
784
785
786
787
788
789
790
791void QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel)
794 Q_ASSERT(selectionModel);
795 Q_D(QAbstractItemView);
797 if (Q_UNLIKELY(selectionModel->model() != d->model)) {
798 qWarning(
"QAbstractItemView::setSelectionModel() failed: "
799 "Trying to set a selection model, which works on "
800 "a different model than the view.");
804 QItemSelection oldSelection;
805 QModelIndex oldCurrentIndex;
807 if (d->selectionModel) {
808 if (d->selectionModel->model() == selectionModel->model()) {
809 oldSelection = d->selectionModel->selection();
810 oldCurrentIndex = d->selectionModel->currentIndex();
812 disconnect(d->selectionModel, &QItemSelectionModel::selectionChanged,
813 this, &QAbstractItemView::selectionChanged);
814 disconnect(d->selectionModel, &QItemSelectionModel::currentChanged,
815 this, &QAbstractItemView::currentChanged);
818 d->selectionModel = selectionModel;
820 if (d->selectionModel) {
821 connect(d->selectionModel, &QItemSelectionModel::selectionChanged,
822 this, &QAbstractItemView::selectionChanged);
823 connect(d->selectionModel, &QItemSelectionModel::currentChanged,
824 this, &QAbstractItemView::currentChanged);
826 selectionChanged(d->selectionModel->selection(), oldSelection);
827 currentChanged(d->selectionModel->currentIndex(), oldCurrentIndex);
832
833
834
835
836QItemSelectionModel* QAbstractItemView::selectionModel()
const
838 Q_D(
const QAbstractItemView);
839 return d->selectionModel;
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *delegate)
859 Q_D(QAbstractItemView);
860 if (delegate == d->itemDelegate)
863 if (d->itemDelegate) {
864 if (d->delegateRefCount(d->itemDelegate) == 1)
865 d->disconnectDelegate(d->itemDelegate);
869 if (d->delegateRefCount(delegate) == 0)
870 d->connectDelegate(delegate);
872 d->itemDelegate = delegate;
873 viewport()->update();
874 d->doDelayedItemsLayout();
878
879
880
881
882
883QAbstractItemDelegate *QAbstractItemView::itemDelegate()
const
885 return d_func()->itemDelegate;
889
890
891QVariant QAbstractItemView::inputMethodQuery(Qt::InputMethodQuery query)
const
893 Q_D(
const QAbstractItemView);
894 const QModelIndex current = currentIndex();
896 if (current.isValid()) {
897 if (QWidget *currentEditor;
898 d->waitForIMCommit && (currentEditor = d->editorForIndex(current).widget)) {
901 result = currentEditor->inputMethodQuery(query);
902 if (result.typeId() == QMetaType::QRect) {
903 const QRect editorRect = result.value<QRect>();
904 result = QRect(currentEditor->mapTo(
this, editorRect.topLeft()), editorRect.size());
906 }
else if (query == Qt::ImCursorRectangle) {
907 result = visualRect(current);
910 if (!result.isValid())
911 result = QAbstractScrollArea::inputMethodQuery(query);
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934void QAbstractItemView::setItemDelegateForRow(
int row, QAbstractItemDelegate *delegate)
936 Q_D(QAbstractItemView);
937 if (QAbstractItemDelegate *rowDelegate = d->rowDelegates.value(row,
nullptr)) {
938 if (d->delegateRefCount(rowDelegate) == 1)
939 d->disconnectDelegate(rowDelegate);
940 d->rowDelegates.remove(row);
943 if (d->delegateRefCount(delegate) == 0)
944 d->connectDelegate(delegate);
945 d->rowDelegates.insert(row, delegate);
947 viewport()->update();
948 d->doDelayedItemsLayout();
952
953
954
955
956
957
958QAbstractItemDelegate *QAbstractItemView::itemDelegateForRow(
int row)
const
960 Q_D(
const QAbstractItemView);
961 return d->rowDelegates.value(row,
nullptr);
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982void QAbstractItemView::setItemDelegateForColumn(
int column, QAbstractItemDelegate *delegate)
984 Q_D(QAbstractItemView);
985 if (QAbstractItemDelegate *columnDelegate = d->columnDelegates.value(column,
nullptr)) {
986 if (d->delegateRefCount(columnDelegate) == 1)
987 d->disconnectDelegate(columnDelegate);
988 d->columnDelegates.remove(column);
991 if (d->delegateRefCount(delegate) == 0)
992 d->connectDelegate(delegate);
993 d->columnDelegates.insert(column, delegate);
995 viewport()->update();
996 d->doDelayedItemsLayout();
1000
1001
1002
1003
1004
1005
1006QAbstractItemDelegate *QAbstractItemView::itemDelegateForColumn(
int column)
const
1008 Q_D(
const QAbstractItemView);
1009 return d->columnDelegates.value(column,
nullptr);
1013
1014
1015
1016
1017
1020
1021
1022
1023
1024
1025
1026
1027QAbstractItemDelegate *QAbstractItemView::itemDelegateForIndex(
const QModelIndex &index)
const
1029 Q_D(
const QAbstractItemView);
1030 return d->delegateForIndex(index);
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043void QAbstractItemView::setSelectionMode(SelectionMode mode)
1045 Q_D(QAbstractItemView);
1046 d->selectionMode = mode;
1049QAbstractItemView::SelectionMode QAbstractItemView::selectionMode()
const
1051 Q_D(
const QAbstractItemView);
1052 return d->selectionMode;
1056
1057
1058
1059
1060
1061
1062
1063
1065void QAbstractItemView::setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
1067 Q_D(QAbstractItemView);
1068 d->selectionBehavior = behavior;
1071QAbstractItemView::SelectionBehavior QAbstractItemView::selectionBehavior()
const
1073 Q_D(
const QAbstractItemView);
1074 return d->selectionBehavior;
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091void QAbstractItemView::setCurrentIndex(
const QModelIndex &index)
1093 Q_D(QAbstractItemView);
1094 if (d->selectionModel && (!index.isValid() || d->isIndexEnabled(index))) {
1095 QItemSelectionModel::SelectionFlags command = selectionCommand(index,
nullptr);
1096 d->selectionModel->setCurrentIndex(index, command);
1097 d->currentIndexSet =
true;
1102
1103
1104
1105
1106QModelIndex QAbstractItemView::currentIndex()
const
1108 Q_D(
const QAbstractItemView);
1109 return d->selectionModel ? d->selectionModel->currentIndex() : QModelIndex();
1114
1115
1116
1117
1118
1119
1120
1121
1122void QAbstractItemView::reset()
1124 Q_D(QAbstractItemView);
1125 d->delayedReset.stop();
1129 const auto copy = d->indexEditorHash;
1130 for (
const auto &[index, info] : copy.asKeyValueRange()) {
1132 d->releaseEditor(info.widget.data(), d->indexForEditor(info.widget.data()));
1134 d->editorIndexHash.clear();
1135 d->indexEditorHash.clear();
1136 d->persistent.clear();
1137 d->currentIndexSet =
false;
1139 setRootIndex(QModelIndex());
1140 if (d->selectionModel)
1141 d->selectionModel->reset();
1142#if QT_CONFIG(accessibility)
1143 if (QAccessible::isActive()) {
1144 QAccessibleTableModelChangeEvent accessibleEvent(
this, QAccessibleTableModelChangeEvent::ModelReset);
1145 QAccessible::updateAccessibility(&accessibleEvent);
1148 d->updateGeometry();
1152
1153
1154
1155
1156void QAbstractItemView::setRootIndex(
const QModelIndex &index)
1158 Q_D(QAbstractItemView);
1159 if (Q_UNLIKELY(index.isValid() && index.model() != d->model)) {
1160 qWarning(
"QAbstractItemView::setRootIndex failed : index must be from the currently set model");
1164#if QT_CONFIG(accessibility)
1165 if (QAccessible::isActive()) {
1166 QAccessibleTableModelChangeEvent accessibleEvent(
this, QAccessibleTableModelChangeEvent::ModelReset);
1167 QAccessible::updateAccessibility(&accessibleEvent);
1170 d->doDelayedItemsLayout();
1171 d->updateGeometry();
1175
1176
1177
1178
1179
1180QModelIndex QAbstractItemView::rootIndex()
const
1182 return QModelIndex(d_func()->root);
1186
1187
1188
1189
1190
1191
1192void QAbstractItemView::selectAll()
1194 Q_D(QAbstractItemView);
1195 const SelectionMode mode = d->selectionMode;
1197 case MultiSelection:
1198 case ExtendedSelection:
1199 d->selectAll(QItemSelectionModel::ClearAndSelect
1200 | d->selectionBehaviorFlags());
1203 case ContiguousSelection:
1204 if (d->model->hasChildren(d->root))
1205 d->selectAll(selectionCommand(d->model->index(0, 0, d->root)));
1207 case SingleSelection:
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224void QAbstractItemView::edit(
const QModelIndex &index)
1226 Q_D(QAbstractItemView);
1227 if (Q_UNLIKELY(!d->isIndexValid(index)))
1228 qWarning(
"edit: index was invalid");
1229 if (Q_UNLIKELY(!edit(index, AllEditTriggers,
nullptr)))
1230 qWarning(
"edit: editing failed");
1234
1235
1236
1237
1238void QAbstractItemView::clearSelection()
1240 Q_D(QAbstractItemView);
1241 if (d->selectionModel)
1242 d->selectionModel->clearSelection();
1246
1247
1248
1249
1250
1251void QAbstractItemView::doItemsLayout()
1253 Q_D(QAbstractItemView);
1254 d->interruptDelayedItemsLayout();
1256 d->viewport->update();
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274void QAbstractItemView::setEditTriggers(EditTriggers actions)
1276 Q_D(QAbstractItemView);
1277 d->editTriggers = actions;
1280QAbstractItemView::EditTriggers QAbstractItemView::editTriggers()
const
1282 Q_D(
const QAbstractItemView);
1283 return d->editTriggers;
1287
1288
1289
1290
1291
1292
1293
1295void QAbstractItemView::setVerticalScrollMode(ScrollMode mode)
1297 Q_D(QAbstractItemView);
1298 d->verticalScrollModeSet =
true;
1299 if (mode == d->verticalScrollMode)
1301 QModelIndex topLeft = indexAt(QPoint(0, 0));
1302 d->verticalScrollMode = mode;
1303 if (mode == ScrollPerItem)
1304 verticalScrollBar()->d_func()->itemviewChangeSingleStep(1);
1306 verticalScrollBar()->setSingleStep(-1);
1308 scrollTo(topLeft, QAbstractItemView::PositionAtTop);
1311QAbstractItemView::ScrollMode QAbstractItemView::verticalScrollMode()
const
1313 Q_D(
const QAbstractItemView);
1314 return d->verticalScrollMode;
1317void QAbstractItemView::resetVerticalScrollMode()
1319 auto sm =
static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode,
nullptr,
this,
nullptr));
1320 setVerticalScrollMode(sm);
1321 d_func()->verticalScrollModeSet =
false;
1325
1326
1327
1328
1329
1330
1331
1333void QAbstractItemView::setHorizontalScrollMode(ScrollMode mode)
1335 Q_D(QAbstractItemView);
1336 d->horizontalScrollModeSet =
true;
1337 if (mode == d->horizontalScrollMode)
1339 d->horizontalScrollMode = mode;
1340 if (mode == ScrollPerItem)
1341 horizontalScrollBar()->d_func()->itemviewChangeSingleStep(1);
1343 horizontalScrollBar()->setSingleStep(-1);
1347QAbstractItemView::ScrollMode QAbstractItemView::horizontalScrollMode()
const
1349 Q_D(
const QAbstractItemView);
1350 return d->horizontalScrollMode;
1353void QAbstractItemView::resetHorizontalScrollMode()
1355 auto sm =
static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode,
nullptr,
this,
nullptr));
1356 setHorizontalScrollMode(sm);
1357 d_func()->horizontalScrollModeSet =
false;
1360#if QT_CONFIG(draganddrop)
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381void QAbstractItemView::setDragDropOverwriteMode(
bool overwrite)
1383 Q_D(QAbstractItemView);
1384 d->overwrite = overwrite;
1387bool QAbstractItemView::dragDropOverwriteMode()
const
1389 Q_D(
const QAbstractItemView);
1390 return d->overwrite;
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1408void QAbstractItemView::setAutoScroll(
bool enable)
1410 Q_D(QAbstractItemView);
1411 d->autoScroll = enable;
1414bool QAbstractItemView::hasAutoScroll()
const
1416 Q_D(
const QAbstractItemView);
1417 return d->autoScroll;
1421
1422
1423
1424
1425
1426
1427void QAbstractItemView::setAutoScrollMargin(
int margin)
1429 Q_D(QAbstractItemView);
1430 d->autoScrollMargin = margin;
1433int QAbstractItemView::autoScrollMargin()
const
1435 Q_D(
const QAbstractItemView);
1436 return d->autoScrollMargin;
1440
1441
1442
1444void QAbstractItemView::setTabKeyNavigation(
bool enable)
1446 Q_D(QAbstractItemView);
1447 d->tabKeyNavigation = enable;
1450bool QAbstractItemView::tabKeyNavigation()
const
1452 Q_D(
const QAbstractItemView);
1453 return d->tabKeyNavigation;
1457
1458
1459
1460QSize QAbstractItemView::viewportSizeHint()
const
1462 return QAbstractScrollArea::viewportSizeHint();
1465#if QT_CONFIG(draganddrop)
1467
1468
1469
1470
1471
1473void QAbstractItemView::setDropIndicatorShown(
bool enable)
1475 Q_D(QAbstractItemView);
1476 d->showDropIndicator = enable;
1479bool QAbstractItemView::showDropIndicator()
const
1481 Q_D(
const QAbstractItemView);
1482 return d->showDropIndicator;
1486
1487
1488
1489
1490
1492void QAbstractItemView::setDragEnabled(
bool enable)
1494 Q_D(QAbstractItemView);
1495 d->dragEnabled = enable;
1498bool QAbstractItemView::dragEnabled()
const
1500 Q_D(
const QAbstractItemView);
1501 return d->dragEnabled;
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1524
1525
1526
1527
1528
1529void QAbstractItemView::setDragDropMode(DragDropMode behavior)
1531 Q_D(QAbstractItemView);
1532 d->dragDropMode = behavior;
1533 setDragEnabled(behavior == DragOnly || behavior == DragDrop || behavior == InternalMove);
1534 setAcceptDrops(behavior == DropOnly || behavior == DragDrop || behavior == InternalMove);
1537QAbstractItemView::DragDropMode QAbstractItemView::dragDropMode()
const
1539 Q_D(
const QAbstractItemView);
1540 DragDropMode setBehavior = d->dragDropMode;
1541 if (!dragEnabled() && !acceptDrops())
1544 if (dragEnabled() && !acceptDrops())
1547 if (!dragEnabled() && acceptDrops())
1550 if (dragEnabled() && acceptDrops()) {
1551 if (setBehavior == InternalMove)
1561
1562
1563
1564
1565
1566
1567
1568
1569void QAbstractItemView::setDefaultDropAction(Qt::DropAction dropAction)
1571 Q_D(QAbstractItemView);
1572 d->defaultDropAction = dropAction;
1575Qt::DropAction QAbstractItemView::defaultDropAction()
const
1577 Q_D(
const QAbstractItemView);
1578 return d->defaultDropAction;
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593void QAbstractItemView::setAlternatingRowColors(
bool enable)
1595 Q_D(QAbstractItemView);
1596 d->alternatingColors = enable;
1598 d->viewport->update();
1601bool QAbstractItemView::alternatingRowColors()
const
1603 Q_D(
const QAbstractItemView);
1604 return d->alternatingColors;
1608
1609
1610
1611
1612
1613
1614void QAbstractItemView::setIconSize(
const QSize &size)
1616 Q_D(QAbstractItemView);
1617 if (size == d->iconSize)
1620 d->doDelayedItemsLayout();
1621 emit iconSizeChanged(size);
1624QSize QAbstractItemView::iconSize()
const
1626 Q_D(
const QAbstractItemView);
1631
1632
1633
1634
1635
1636
1637void QAbstractItemView::setTextElideMode(Qt::TextElideMode mode)
1639 Q_D(QAbstractItemView);
1640 d->textElideMode = mode;
1643Qt::TextElideMode QAbstractItemView::textElideMode()
const
1645 return d_func()->textElideMode;
1649
1650
1651bool QAbstractItemView::focusNextPrevChild(
bool next)
1653 Q_D(QAbstractItemView);
1654 if (d->tabKeyNavigation && isVisible() && isEnabled() && d->viewport->isEnabled()) {
1655 QKeyEvent event(QEvent::KeyPress, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier);
1656 keyPressEvent(&event);
1657 if (event.isAccepted())
1660 return QAbstractScrollArea::focusNextPrevChild(next);
1664
1665
1666bool QAbstractItemView::event(QEvent *event)
1668 Q_D(QAbstractItemView);
1669 switch (event->type()) {
1673 d->executePostedLayout();
1676 d->executePostedLayout();
1677 if (d->shouldScrollToCurrentOnShow) {
1678 d->shouldScrollToCurrentOnShow =
false;
1679 const QModelIndex current = currentIndex();
1680 if (current.isValid() && (d->state == QAbstractItemView::EditingState || d->autoScroll))
1684 case QEvent::LocaleChange:
1685 viewport()->update();
1687 case QEvent::LayoutDirectionChange:
1688 case QEvent::ApplicationLayoutDirectionChange:
1691 case QEvent::StyleChange:
1693 if (!d->verticalScrollModeSet)
1694 resetVerticalScrollMode();
1695 if (!d->horizontalScrollModeSet)
1696 resetHorizontalScrollMode();
1698 case QEvent::FocusOut:
1699 d->checkPersistentEditorFocus();
1701 case QEvent::FontChange:
1702 d->doDelayedItemsLayout();
1707 return QAbstractScrollArea::event(event);
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721bool QAbstractItemView::viewportEvent(QEvent *event)
1723 Q_D(QAbstractItemView);
1724 switch (event->type()) {
1729 d->executePostedLayout();
1731 case QEvent::HoverMove:
1732 case QEvent::HoverEnter:
1733 d->setHoverIndex(indexAt(
static_cast<QHoverEvent*>(event)->position().toPoint()));
1735 case QEvent::HoverLeave:
1736 d->setHoverIndex(QModelIndex());
1739 d->viewportEnteredNeeded =
true;
1742 d->setHoverIndex(QModelIndex());
1743 #if QT_CONFIG(statustip)
1744 if (d->shouldClearStatusTip && d->parent) {
1746 QStatusTipEvent tip(empty);
1747 QCoreApplication::sendEvent(d->parent, &tip);
1748 d->shouldClearStatusTip =
false;
1751 d->enteredIndex = QModelIndex();
1753 case QEvent::ToolTip:
1754 case QEvent::QueryWhatsThis:
1755 case QEvent::WhatsThis: {
1756 QHelpEvent *he =
static_cast<QHelpEvent*>(event);
1757 const QModelIndex index = indexAt(he->pos());
1758 QStyleOptionViewItem option;
1759 initViewItemOption(&option);
1760 option.rect = visualRect(index);
1761 option.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
1763 QAbstractItemDelegate *delegate = itemDelegateForIndex(index);
1766 return delegate->helpEvent(he,
this, option, index);
1768 case QEvent::FontChange:
1769 d->doDelayedItemsLayout();
1771 case QEvent::WindowActivate:
1772 case QEvent::WindowDeactivate:
1773 d->viewport->update();
1775 case QEvent::ScrollPrepare:
1776 executeDelayedItemsLayout();
1777#if QT_CONFIG(gestures) && QT_CONFIG(scroller)
1778 d->scollerConnection = QObjectPrivate::connect(
1779 QScroller::scroller(d->viewport), &QScroller::stateChanged,
1780 d, &QAbstractItemViewPrivate::scrollerStateChanged,
1781 Qt::UniqueConnection);
1788 return QAbstractScrollArea::viewportEvent(event);
1792
1793
1794
1795
1796void QAbstractItemView::mousePressEvent(QMouseEvent *event)
1798 Q_D(QAbstractItemView);
1799 d->releaseFromDoubleClick =
false;
1800 d->delayedAutoScroll.stop();
1801 QPoint pos = event->position().toPoint();
1802 QPersistentModelIndex index = indexAt(pos);
1805 d->pressClosedEditor = d->pressClosedEditorWatcher.isActive() && d->lastEditedIndex == index;
1807 if (!d->selectionModel || (d->state == EditingState && d->hasEditor(index)))
1810 d->pressedAlreadySelected = d->selectionModel->isSelected(index);
1811 d->pressedIndex = index;
1812 d->pressedModifiers = event->modifiers();
1813 QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
1814 d->noSelectionOnMousePress = command == QItemSelectionModel::NoUpdate || !index.isValid();
1815 QPoint offset = d->offset();
1816 d->draggedPosition = pos;
1817 d->draggedPositionOffset = offset;
1819#if QT_CONFIG(draganddrop)
1822 d->pressedPosition = d->draggedPosition + d->draggedPositionOffset;
1825 if (!(command & QItemSelectionModel::Current)) {
1826 d->pressedPosition = pos + offset;
1827 d->currentSelectionStartIndex = index;
1829 else if (!d->currentSelectionStartIndex.isValid())
1830 d->currentSelectionStartIndex = currentIndex();
1832 if (edit(index, NoEditTriggers, event))
1835 if (index.isValid() && d->isIndexEnabled(index)) {
1838 bool autoScroll = d->autoScroll;
1839 d->autoScroll =
false;
1840 d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
1841 d->autoScroll = autoScroll;
1842 if (command.testFlag(QItemSelectionModel::Toggle)) {
1843 command &= ~QItemSelectionModel::Toggle;
1844 d->ctrlDragSelectionFlag = d->selectionModel->isSelected(index) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
1845 command |= d->ctrlDragSelectionFlag;
1848 if (!(command & QItemSelectionModel::Current)) {
1849 setSelection(QRect(pos, QSize(1, 1)), command);
1851 QRect rect(visualRect(d->currentSelectionStartIndex).center(), pos);
1852 setSelection(rect, command);
1856 emit pressed(index);
1857 if (d->autoScroll) {
1860 d->delayedAutoScroll.start(QApplication::doubleClickInterval()+100,
this);
1865 d->selectionModel->select(QModelIndex(), QItemSelectionModel::Select);
1870
1871
1872
1873
1874void QAbstractItemView::mouseMoveEvent(QMouseEvent *event)
1876 Q_D(QAbstractItemView);
1877 QPoint bottomRight = event->position().toPoint();
1879 d->draggedPosition = bottomRight;
1880 d->draggedPositionOffset = d->offset();
1882 if (state() == ExpandingState || state() == CollapsingState)
1885#if QT_CONFIG(draganddrop)
1886 if (state() == DraggingState) {
1887 d->maybeStartDrag(bottomRight);
1892 QPersistentModelIndex index = indexAt(bottomRight);
1893 QModelIndex buddy = d->model->buddy(d->pressedIndex);
1894 if ((state() == EditingState && d->hasEditor(buddy))
1895 || edit(index, NoEditTriggers, event))
1898 const QPoint topLeft =
1899 d->selectionMode != SingleSelection ? d->pressedPosition - d->offset() : bottomRight;
1901 d->checkMouseMove(index);
1903#if QT_CONFIG(draganddrop)
1904 if (d->pressedIndex.isValid()
1906 && (state() != DragSelectingState)
1907 && (event->buttons() != Qt::NoButton)
1908 && !d->selectedDraggableIndexes().isEmpty()) {
1909 setState(DraggingState);
1910 d->maybeStartDrag(bottomRight);
1915 if ((event->buttons() & Qt::LeftButton) && d->selectionAllowed(index) && d->selectionModel) {
1916 setState(DragSelectingState);
1917 QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
1918 if (d->ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate && command.testFlag(QItemSelectionModel::Toggle)) {
1919 command &= ~QItemSelectionModel::Toggle;
1920 command |= d->ctrlDragSelectionFlag;
1924 QRect selectionRect = QRect(topLeft, bottomRight);
1925 setSelection(selectionRect, command);
1928 if (index.isValid() && (index != d->selectionModel->currentIndex()) && d->isIndexEnabled(index))
1929 d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
1930 else if (d->shouldAutoScroll(event->pos()) && !d->autoScrollTimer.isActive())
1936
1937
1938
1939
1940
1941
1942void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event)
1944 Q_D(QAbstractItemView);
1945 const bool releaseFromDoubleClick = d->releaseFromDoubleClick;
1946 d->releaseFromDoubleClick =
false;
1948 QPoint pos = event->position().toPoint();
1949 QPersistentModelIndex index = indexAt(pos);
1951 if (state() == EditingState) {
1952 if (d->isIndexValid(index)
1953 && d->isIndexEnabled(index)
1954 && d->sendDelegateEvent(index, event))
1959 bool click = (index == d->pressedIndex && index.isValid() && !releaseFromDoubleClick);
1960 bool selectedClicked = click && d->pressedAlreadySelected
1961 && (event->button() == Qt::LeftButton)
1962 && (event->modifiers() == Qt::NoModifier);
1963 EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers);
1964 const bool edited = click && !d->pressClosedEditor ? edit(index, trigger, event) :
false;
1966 d->ctrlDragSelectionFlag = QItemSelectionModel::NoUpdate;
1968 if (d->selectionModel && d->noSelectionOnMousePress) {
1969 d->noSelectionOnMousePress =
false;
1970 if (!d->pressClosedEditor)
1971 d->selectionModel->select(index, selectionCommand(index, event));
1974 d->pressClosedEditor =
false;
1978 if (event->button() == Qt::LeftButton)
1979 emit clicked(index);
1982 QStyleOptionViewItem option;
1983 initViewItemOption(&option);
1984 if (d->pressedAlreadySelected)
1985 option.state |= QStyle::State_Selected;
1986 if ((d->model->flags(index) & Qt::ItemIsEnabled)
1987 && style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option,
this))
1988 emit activated(index);
1993
1994
1995
1996
1997void QAbstractItemView::mouseDoubleClickEvent(QMouseEvent *event)
1999 Q_D(QAbstractItemView);
2001 QModelIndex index = indexAt(event->position().toPoint());
2002 if (!index.isValid()
2003 || !d->isIndexEnabled(index)
2004 || (d->pressedIndex != index)) {
2005 QMouseEvent me(QEvent::MouseButtonPress,
2006 event->position(), event->scenePosition(), event->globalPosition(),
2007 event->button(), event->buttons(), event->modifiers(),
2008 event->source(), event->pointingDevice());
2009 mousePressEvent(&me);
2013 QPersistentModelIndex persistent = index;
2014 emit doubleClicked(persistent);
2015 if ((event->button() == Qt::LeftButton) && !edit(persistent, DoubleClicked, event)
2016 && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick,
nullptr,
this))
2017 emit activated(persistent);
2018 d->releaseFromDoubleClick =
true;
2021#if QT_CONFIG(draganddrop)
2024
2025
2026
2027
2028
2029
2030void QAbstractItemView::dragEnterEvent(QDragEnterEvent *event)
2032 if (dragDropMode() == InternalMove
2033 && (event->source() !=
this|| !(event->possibleActions() & Qt::MoveAction)))
2036 if (d_func()->canDrop(event)) {
2038 setState(DraggingState);
2045
2046
2047
2048
2049
2050
2051
2052void QAbstractItemView::dragMoveEvent(QDragMoveEvent *event)
2054 Q_D(QAbstractItemView);
2055 d->draggedPosition = event->position().toPoint();
2056 d->draggedPositionOffset = d->offset();
2057 if (dragDropMode() == InternalMove
2058 && (event->source() !=
this || !(event->possibleActions() & Qt::MoveAction)))
2064 QModelIndex index = indexAt(event->position().toPoint());
2066 if (!d->droppingOnItself(event, index)
2067 && d->canDrop(event)) {
2069 if (index.isValid() && d->showDropIndicator) {
2070 QRect rect = visualRect(index);
2071 d->dropIndicatorPosition = d->position(event->position().toPoint(), rect, index);
2072 if (d->selectionBehavior == QAbstractItemView::SelectRows
2073 && d->dropIndicatorPosition != OnViewport
2074 && (d->dropIndicatorPosition != OnItem || event->source() ==
this)) {
2075 if (index.column() > 0)
2076 rect = visualRect(index.siblingAtColumn(0));
2077 rect.setWidth(viewport()->width() - 1 - rect.x());
2079 switch (d->dropIndicatorPosition) {
2081 if (d->isIndexDropEnabled(index.parent())) {
2082 d->dropIndicatorRect = QRect(rect.left(), rect.top(), rect.width(), 0);
2083 event->acceptProposedAction();
2085 d->dropIndicatorRect = QRect();
2089 if (d->isIndexDropEnabled(index.parent())) {
2090 d->dropIndicatorRect = QRect(rect.left(), rect.bottom(), rect.width(), 0);
2091 event->acceptProposedAction();
2093 d->dropIndicatorRect = QRect();
2097 if (d->isIndexDropEnabled(index)) {
2098 d->dropIndicatorRect = rect;
2099 event->acceptProposedAction();
2101 d->dropIndicatorRect = QRect();
2105 d->dropIndicatorRect = QRect();
2106 if (d->isIndexDropEnabled(rootIndex())) {
2107 event->acceptProposedAction();
2112 d->dropIndicatorRect = QRect();
2113 d->dropIndicatorPosition = OnViewport;
2114 if (d->isIndexDropEnabled(rootIndex())) {
2115 event->acceptProposedAction();
2118 d->viewport->update();
2121 if (d->shouldAutoScroll(event->position().toPoint()))
2126
2127
2128
2129
2130bool QAbstractItemViewPrivate::droppingOnItself(QDropEvent *event,
const QModelIndex &index)
2132 Q_Q(QAbstractItemView);
2133 Qt::DropAction dropAction = event->dropAction();
2134 if (q->dragDropMode() == QAbstractItemView::InternalMove)
2135 dropAction = Qt::MoveAction;
2136 if (event->source() == q
2137 && event->possibleActions() & Qt::MoveAction
2138 && dropAction == Qt::MoveAction) {
2139 QModelIndexList selectedIndexes = q->selectedIndexes();
2140 QModelIndex child = index;
2141 while (child.isValid() && child != root) {
2142 if (selectedIndexes.contains(child))
2144 child = child.parent();
2151
2152
2153
2154
2155
2156void QAbstractItemView::dragLeaveEvent(QDragLeaveEvent *)
2158 Q_D(QAbstractItemView);
2161 d->hover = QModelIndex();
2162 d->viewport->update();
2166
2167
2168
2169
2170
2171
2172void QAbstractItemView::dropEvent(QDropEvent *event)
2174 Q_D(QAbstractItemView);
2175 if (dragDropMode() == InternalMove) {
2176 if (event->source() !=
this || !(event->possibleActions() & Qt::MoveAction))
2183 if (d->dropOn(event, &row, &col, &index)) {
2184 const Qt::DropAction action = dragDropMode() == InternalMove ? Qt::MoveAction : event->dropAction();
2185 if (d->model->dropMimeData(event->mimeData(), action, row, col, index)) {
2186 if (action != event->dropAction()) {
2187 event->setDropAction(action);
2190 event->acceptProposedAction();
2196 d->viewport->update();
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210bool QAbstractItemViewPrivate::dropOn(QDropEvent *event,
int *dropRow,
int *dropCol, QModelIndex *dropIndex)
2212 Q_Q(QAbstractItemView);
2213 if (event->isAccepted())
2218 if (viewport->rect().contains(event->position().toPoint())) {
2219 index = q->indexAt(event->position().toPoint());
2220 if (!index.isValid())
2225 if (model->supportedDropActions() & event->dropAction()) {
2228 if (index != root) {
2229 dropIndicatorPosition = position(event->position().toPoint(), q->visualRect(index), index);
2230 switch (dropIndicatorPosition) {
2231 case QAbstractItemView::AboveItem:
2233 col = index.column();
2234 index = index.parent();
2236 case QAbstractItemView::BelowItem:
2237 row = index.row() + 1;
2238 col = index.column();
2239 index = index.parent();
2241 case QAbstractItemView::OnItem:
2242 case QAbstractItemView::OnViewport:
2246 dropIndicatorPosition = QAbstractItemView::OnViewport;
2251 if (!droppingOnItself(event, index))
2257QAbstractItemView::DropIndicatorPosition
2258QAbstractItemViewPrivate::position(
const QPoint &pos,
const QRect &rect,
const QModelIndex &index)
const
2260 QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport;
2262 const int margin = qBound(2, qRound(qreal(rect.height()) / 5.5), 12);
2263 if (pos.y() - rect.top() < margin) {
2264 r = QAbstractItemView::AboveItem;
2265 }
else if (rect.bottom() - pos.y() < margin) {
2266 r = QAbstractItemView::BelowItem;
2267 }
else if (rect.contains(pos,
true)) {
2268 r = QAbstractItemView::OnItem;
2271 QRect touchingRect = rect;
2272 touchingRect.adjust(-1, -1, 1, 1);
2273 if (touchingRect.contains(pos,
false)) {
2274 r = QAbstractItemView::OnItem;
2278 if (r == QAbstractItemView::OnItem && (!(model->flags(index) & Qt::ItemIsDropEnabled)))
2279 r = pos.y() < rect.center().y() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem;
2287
2288
2289
2290
2291
2292void QAbstractItemView::focusInEvent(QFocusEvent *event)
2294 Q_D(QAbstractItemView);
2295 QAbstractScrollArea::focusInEvent(event);
2297 const QItemSelectionModel* model = selectionModel();
2298 bool currentIndexValid = currentIndex().isValid();
2301 && !d->currentIndexSet
2302 && !currentIndexValid) {
2303 bool autoScroll = d->autoScroll;
2304 d->autoScroll =
false;
2305 QModelIndex index = moveCursor(MoveNext, Qt::NoModifier);
2306 if (index.isValid() && d->isIndexEnabled(index) && event->reason() != Qt::MouseFocusReason) {
2307 selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
2308 currentIndexValid =
true;
2310 d->autoScroll = autoScroll;
2313 if (model && currentIndexValid)
2314 setAttribute(Qt::WA_InputMethodEnabled, (currentIndex().flags() & Qt::ItemIsEditable));
2315 else if (!currentIndexValid)
2316 setAttribute(Qt::WA_InputMethodEnabled,
false);
2318 d->viewport->update();
2322
2323
2324
2325
2326
2327void QAbstractItemView::focusOutEvent(QFocusEvent *event)
2329 Q_D(QAbstractItemView);
2330 QAbstractScrollArea::focusOutEvent(event);
2331 d->viewport->update();
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345void QAbstractItemView::keyPressEvent(QKeyEvent *event)
2347 Q_D(QAbstractItemView);
2348 d->delayedAutoScroll.stop();
2350#ifdef QT_KEYPAD_NAVIGATION
2351 switch (event->key()) {
2352 case Qt::Key_Select:
2353 if (QApplicationPrivate::keypadNavigationEnabled()) {
2354 if (!hasEditFocus()) {
2361 if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()) {
2362 setEditFocus(
false);
2372 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
2373 && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
2381 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
2382 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(
this))) {
2388 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
2395#if !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT)
2396 if (event == QKeySequence::Copy) {
2397 const QModelIndex index = currentIndex();
2398 if (index.isValid() && d->model) {
2399 const QVariant variant = d->model->data(index, Qt::DisplayRole);
2400 if (variant.canConvert<QString>())
2401 QGuiApplication::clipboard()->setText(variant.toString());
2407 QPersistentModelIndex newCurrent;
2408 d->moveCursorUpdatedView =
false;
2409 switch (event->key()) {
2411 newCurrent = moveCursor(MoveDown, event->modifiers());
2414 newCurrent = moveCursor(MoveUp, event->modifiers());
2417 newCurrent = moveCursor(MoveLeft, event->modifiers());
2420 newCurrent = moveCursor(MoveRight, event->modifiers());
2423 newCurrent = moveCursor(MoveHome, event->modifiers());
2426 newCurrent = moveCursor(MoveEnd, event->modifiers());
2428 case Qt::Key_PageUp:
2429 newCurrent = moveCursor(MovePageUp, event->modifiers());
2431 case Qt::Key_PageDown:
2432 newCurrent = moveCursor(MovePageDown, event->modifiers());
2435 if (d->tabKeyNavigation)
2436 newCurrent = moveCursor(MoveNext, event->modifiers());
2438 case Qt::Key_Backtab:
2439 if (d->tabKeyNavigation)
2440 newCurrent = moveCursor(MovePrevious, event->modifiers());
2444 QPersistentModelIndex oldCurrent = currentIndex();
2445 if (newCurrent != oldCurrent && newCurrent.isValid() && d->isIndexEnabled(newCurrent)) {
2446 if (!hasFocus() && QApplication::focusWidget() == indexWidget(oldCurrent))
2448 QItemSelectionModel::SelectionFlags command = selectionCommand(newCurrent, event);
2449 if (command != QItemSelectionModel::NoUpdate
2450 || style()->styleHint(QStyle::SH_ItemView_MovementWithoutUpdatingSelection,
nullptr,
this)) {
2452 if (command & QItemSelectionModel::Current) {
2453 d->selectionModel->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate);
2454 if (!d->currentSelectionStartIndex.isValid())
2455 d->currentSelectionStartIndex = oldCurrent;
2456 QRect rect(visualRect(d->currentSelectionStartIndex).center(), visualRect(newCurrent).center());
2457 setSelection(rect, command);
2459 d->selectionModel->setCurrentIndex(newCurrent, command);
2460 d->currentSelectionStartIndex = newCurrent;
2461 if (newCurrent.isValid()) {
2463 QRect rect(visualRect(newCurrent).center(), QSize(1, 1));
2464 setSelection(rect, command);
2472 switch (event->key()) {
2476#ifdef QT_KEYPAD_NAVIGATION
2477 if (QApplicationPrivate::keypadNavigationEnabled()
2478 && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
2485#ifdef QT_KEYPAD_NAVIGATION
2486 if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional
2487 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal)
2488 || (QWidgetPrivate::inTabWidget(
this) && d->model->columnCount(d->root) > 1))) {
2495 case Qt::Key_PageUp:
2496 case Qt::Key_PageDown:
2497 case Qt::Key_Escape:
2499 case Qt::Key_Control:
2500 case Qt::Key_Delete:
2501 case Qt::Key_Backspace:
2505 case Qt::Key_Select:
2506 if (!edit(currentIndex(), AnyKeyPressed, event)) {
2507 if (d->selectionModel)
2508 d->selectionModel->select(currentIndex(), selectionCommand(currentIndex(), event));
2509 if (event->key() == Qt::Key_Space) {
2510 keyboardSearch(event->text());
2514#ifdef QT_KEYPAD_NAVIGATION
2515 if ( event->key()==Qt::Key_Select ) {
2517 if (currentIndex().isValid()) {
2518 if (state() != EditingState)
2519 emit activated(currentIndex());
2528 case Qt::Key_Return:
2531 if (!edit(currentIndex(), EditKeyPressed, event) && d->editorIndexHash.isEmpty())
2536 if (!edit(currentIndex(), EditKeyPressed, event))
2540 case Qt::Key_Return:
2544 if (state() != EditingState || hasFocus()) {
2545 if (currentIndex().isValid())
2546 emit activated(currentIndex());
2552#ifndef QT_NO_SHORTCUT
2553 if (event == QKeySequence::SelectAll && selectionMode() != NoSelection) {
2559 if (event->key() == Qt::Key_O && event->modifiers() & Qt::ControlModifier && currentIndex().isValid()) {
2560 emit activated(currentIndex());
2564 bool modified = (event->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier));
2565 if (!event->text().isEmpty() && !modified && !edit(currentIndex(), AnyKeyPressed, event)) {
2566 keyboardSearch(event->text());
2573 if (d->moveCursorUpdatedView)
2578
2579
2580
2581
2582
2583void QAbstractItemView::resizeEvent(QResizeEvent *event)
2585 QAbstractScrollArea::resizeEvent(event);
2590
2591
2592
2593
2594
2595void QAbstractItemView::timerEvent(QTimerEvent *event)
2597 Q_D(QAbstractItemView);
2598 if (event->timerId() == d->fetchMoreTimer.timerId())
2600 else if (event->timerId() == d->delayedReset.timerId())
2602 else if (event->timerId() == d->autoScrollTimer.timerId())
2604 else if (event->timerId() == d->updateTimer.timerId())
2605 d->updateDirtyRegion();
2606 else if (event->timerId() == d->delayedEditing.timerId()) {
2607 d->delayedEditing.stop();
2608 edit(currentIndex());
2609 }
else if (event->timerId() == d->delayedLayout.timerId()) {
2610 d->delayedLayout.stop();
2612 d->interruptDelayedItemsLayout();
2614 const QModelIndex current = currentIndex();
2615 if (current.isValid() && d->state == QAbstractItemView::EditingState)
2618 }
else if (event->timerId() == d->delayedAutoScroll.timerId()) {
2619 d->delayedAutoScroll.stop();
2622 if (d->pressedIndex.isValid() && d->pressedIndex == currentIndex())
2623 scrollTo(d->pressedIndex);
2624 }
else if (event->timerId() == d->pressClosedEditorWatcher.timerId()) {
2625 d->pressClosedEditorWatcher.stop();
2630
2631
2632void QAbstractItemView::inputMethodEvent(QInputMethodEvent *event)
2634 Q_D(QAbstractItemView);
2641 bool forwardEventToEditor =
false;
2642 const bool commit = !event->commitString().isEmpty();
2643 const bool preediting = !event->preeditString().isEmpty();
2644 if (QWidget *currentEditor = d->editorForIndex(currentIndex()).widget) {
2645 if (d->waitForIMCommit) {
2646 if (commit || !preediting) {
2648 d->waitForIMCommit =
false;
2649 QApplication::sendEvent(currentEditor, event);
2651 QAbstractItemDelegate *delegate = itemDelegateForIndex(currentIndex());
2653 delegate->setEditorData(currentEditor, currentIndex());
2654 d->selectAllInEditor(currentEditor);
2656 if (currentEditor->focusPolicy() != Qt::NoFocus)
2657 currentEditor->setFocus();
2660 QApplication::sendEvent(currentEditor, event);
2664 }
else if (preediting) {
2666 d->waitForIMCommit =
true;
2668 forwardEventToEditor =
true;
2669 }
else if (!commit) {
2673 if (!edit(currentIndex(), AnyKeyPressed, event)) {
2674 d->waitForIMCommit =
false;
2676 keyboardSearch(event->commitString());
2678 }
else if (QWidget *currentEditor; forwardEventToEditor
2679 && (currentEditor = d->editorForIndex(currentIndex()).widget)) {
2680 QApplication::sendEvent(currentEditor, event);
2684#if QT_CONFIG(draganddrop)
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2704
2705
2706QAbstractItemView::DropIndicatorPosition QAbstractItemView::dropIndicatorPosition()
const
2708 Q_D(
const QAbstractItemView);
2709 return d->dropIndicatorPosition;
2714
2715
2716
2717
2718
2719
2720QModelIndexList QAbstractItemView::selectedIndexes()
const
2722 Q_D(
const QAbstractItemView);
2723 QModelIndexList indexes;
2724 if (d->selectionModel) {
2725 indexes = d->selectionModel->selectedIndexes();
2726 auto isHidden = [
this](
const QModelIndex &idx) {
2727 return isIndexHidden(idx);
2729 indexes.removeIf(isHidden);
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747bool QAbstractItemView::edit(
const QModelIndex &index, EditTrigger trigger, QEvent *event)
2749 Q_D(QAbstractItemView);
2751 if (!d->isIndexValid(index))
2754 if (QWidget *w = (d->persistent.isEmpty() ?
static_cast<QWidget*>(
nullptr) : d->editorForIndex(index).widget.data())) {
2755 if (w->focusPolicy() == Qt::NoFocus)
2757 if (!d->waitForIMCommit)
2764 if (trigger == DoubleClicked) {
2765 d->delayedEditing.stop();
2766 d->delayedAutoScroll.stop();
2767 }
else if (trigger == CurrentChanged) {
2768 d->delayedEditing.stop();
2772 QPersistentModelIndex safeIndex(index);
2774 if (d->sendDelegateEvent(index, event)) {
2779 if (!safeIndex.isValid()) {
2784 EditTriggers lastTrigger = d->lastTrigger;
2785 d->lastTrigger = trigger;
2787 if (!d->shouldEdit(trigger, d->model->buddy(safeIndex)))
2790 if (d->delayedEditing.isActive())
2795 if (lastTrigger == DoubleClicked && trigger == SelectedClicked)
2799 if (trigger == SelectedClicked)
2800 d->delayedEditing.start(QApplication::doubleClickInterval(),
this);
2802 d->openEditor(safeIndex, d->shouldForwardEvent(trigger, event) ? event :
nullptr);
2808
2809
2810
2811void QAbstractItemView::updateEditorData()
2813 Q_D(QAbstractItemView);
2814 d->updateEditorData(QModelIndex(), QModelIndex());
2818
2819
2820
2821void QAbstractItemView::updateEditorGeometries()
2823 Q_D(QAbstractItemView);
2824 if (d->editorIndexHash.isEmpty())
2826 if (d->delayedPendingLayout) {
2828 d->executePostedLayout();
2831 QStyleOptionViewItem option;
2832 initViewItemOption(&option);
2833 QEditorIndexHash::iterator it = d->editorIndexHash.begin();
2834 QWidgetList editorsToRelease;
2835 QWidgetList editorsToHide;
2836 while (it != d->editorIndexHash.end()) {
2837 QModelIndex index = it.value();
2838 QWidget *editor = it.key();
2839 if (index.isValid() && editor) {
2840 option.rect = visualRect(index);
2841 if (option.rect.isValid()) {
2843 QAbstractItemDelegate *delegate = itemDelegateForIndex(index);
2845 delegate->updateEditorGeometry(editor, option, index);
2847 editorsToHide << editor;
2851 d->indexEditorHash.remove(it.value());
2852 it = d->editorIndexHash.erase(it);
2853 editorsToRelease << editor;
2859 for (
int i = 0; i < editorsToHide.size(); ++i) {
2860 editorsToHide.at(i)->hide();
2862 for (
int i = 0; i < editorsToRelease.size(); ++i) {
2863 d->releaseEditor(editorsToRelease.at(i));
2868
2869
2870void QAbstractItemView::updateGeometries()
2872 Q_D(QAbstractItemView);
2873 updateEditorGeometries();
2874 d->fetchMoreTimer.start(0,
this);
2875 d->updateGeometry();
2879
2880
2881void QAbstractItemView::verticalScrollbarValueChanged(
int value)
2883 Q_D(QAbstractItemView);
2884 if (verticalScrollBar()->maximum() == value && d->model->canFetchMore(d->root))
2885 d->model->fetchMore(d->root);
2886 QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos());
2887 if (viewport()->rect().contains(posInVp))
2888 d->checkMouseMove(posInVp);
2892
2893
2894void QAbstractItemView::horizontalScrollbarValueChanged(
int value)
2896 Q_D(QAbstractItemView);
2897 if (horizontalScrollBar()->maximum() == value && d->model->canFetchMore(d->root))
2898 d->model->fetchMore(d->root);
2899 QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos());
2900 if (viewport()->rect().contains(posInVp))
2901 d->checkMouseMove(posInVp);
2905
2906
2907void QAbstractItemView::verticalScrollbarAction(
int)
2913
2914
2915void QAbstractItemView::horizontalScrollbarAction(
int)
2921
2922
2923
2924
2925
2926
2927
2929void QAbstractItemView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
2931 Q_D(QAbstractItemView);
2935 const bool isPersistent = d->persistent.contains(editor);
2936 const QModelIndex index = d->indexForEditor(editor);
2937 if (!index.isValid()) {
2938 if (!editor->isVisible()) {
2946 qWarning(
"QAbstractItemView::closeEditor called with an editor that does not belong to this view");
2950 const bool hadFocus = editor->hasFocus();
2954 d->pressClosedEditorWatcher.start(0,
this);
2955 d->lastEditedIndex = index;
2957 if (!isPersistent) {
2959 QModelIndex index = d->indexForEditor(editor);
2960 editor->removeEventFilter(itemDelegateForIndex(index));
2961 d->removeEditor(editor);
2964 if (focusPolicy() != Qt::NoFocus)
2967 editor->clearFocus();
2969 d->checkPersistentEditorFocus();
2972 QPointer<QWidget> ed = editor;
2973 QCoreApplication::sendPostedEvents(editor, 0);
2976 if (!isPersistent && editor)
2977 d->releaseEditor(editor, index);
2982 QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::NoUpdate;
2983 if (d->selectionMode != NoSelection)
2984 flags = QItemSelectionModel::ClearAndSelect | d->selectionBehaviorFlags();
2986 case QAbstractItemDelegate::EditNextItem: {
2987 QModelIndex index = moveCursor(MoveNext, Qt::NoModifier);
2988 if (index.isValid()) {
2989 QPersistentModelIndex persistent(index);
2990 d->selectionModel->setCurrentIndex(persistent, flags);
2992 if (index.flags() & Qt::ItemIsEditable
2993 && (!(editTriggers() & QAbstractItemView::CurrentChanged)))
2996 case QAbstractItemDelegate::EditPreviousItem: {
2997 QModelIndex index = moveCursor(MovePrevious, Qt::NoModifier);
2998 if (index.isValid()) {
2999 QPersistentModelIndex persistent(index);
3000 d->selectionModel->setCurrentIndex(persistent, flags);
3002 if (index.flags() & Qt::ItemIsEditable
3003 && (!(editTriggers() & QAbstractItemView::CurrentChanged)))
3006 case QAbstractItemDelegate::SubmitModelCache:
3009 case QAbstractItemDelegate::RevertModelCache:
3018
3019
3020
3021
3022void QAbstractItemView::commitData(QWidget *editor)
3024 Q_D(QAbstractItemView);
3025 if (!editor || !d->itemDelegate || d->currentlyCommittingEditor)
3027 QModelIndex index = d->indexForEditor(editor);
3028 if (!index.isValid()) {
3029 qWarning(
"QAbstractItemView::commitData called with an editor that does not belong to this view");
3032 d->currentlyCommittingEditor = editor;
3033 QAbstractItemDelegate *delegate = itemDelegateForIndex(index);
3034 editor->removeEventFilter(delegate);
3035 delegate->setModelData(editor, d->model, index);
3036 editor->installEventFilter(delegate);
3037 d->currentlyCommittingEditor =
nullptr;
3041
3042
3043
3044
3045void QAbstractItemView::editorDestroyed(QObject *editor)
3047 Q_D(QAbstractItemView);
3048 QWidget *w = qobject_cast<QWidget*>(editor);
3050 d->persistent.remove(w);
3051 if (state() == EditingState)
3058
3059
3060
3061
3062
3063
3064
3065void QAbstractItemView::keyboardSearch(
const QString &search)
3067 Q_D(QAbstractItemView);
3068 if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root))
3071 QModelIndex start = currentIndex().isValid() ? currentIndex()
3072 : d->model->index(0, 0, d->root);
3073 bool skipRow =
false;
3074 bool keyboardTimeWasValid = d->keyboardInputTime.isValid();
3075 qint64 keyboardInputTimeElapsed;
3076 if (keyboardTimeWasValid)
3077 keyboardInputTimeElapsed = d->keyboardInputTime.restart();
3079 d->keyboardInputTime.start();
3080 if (search.isEmpty() || !keyboardTimeWasValid
3081 || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) {
3082 d->keyboardInput = search;
3083 skipRow = currentIndex().isValid();
3085 d->keyboardInput += search;
3089 bool sameKey =
false;
3090 if (d->keyboardInput.size() > 1) {
3091 int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.size() - 1));
3092 sameKey = (c == d->keyboardInput.size());
3099 QModelIndex parent = start.parent();
3100 int newRow = (start.row() < d->model->rowCount(parent) - 1) ? start.row() + 1 : 0;
3101 start = d->model->index(newRow, start.column(), parent);
3105 QModelIndex current = start;
3106 QModelIndexList match;
3107 QModelIndex firstMatch;
3108 QModelIndex startMatch;
3109 QModelIndexList previous;
3111 match = d->model->match(current, Qt::DisplayRole, d->keyboardInput);
3112 if (match == previous)
3114 firstMatch = match.value(0);
3116 if (firstMatch.isValid()) {
3117 if (d->isIndexEnabled(firstMatch)) {
3118 setCurrentIndex(firstMatch);
3121 int row = firstMatch.row() + 1;
3122 if (row >= d->model->rowCount(firstMatch.parent()))
3124 current = firstMatch.sibling(row, firstMatch.column());
3127 if (!startMatch.isValid())
3128 startMatch = firstMatch;
3129 else if (startMatch == firstMatch)
3132 }
while (current != start && firstMatch.isValid());
3136
3137
3138
3139
3140
3141QSize QAbstractItemView::sizeHintForIndex(
const QModelIndex &index)
const
3143 Q_D(
const QAbstractItemView);
3144 if (!d->isIndexValid(index))
3146 const auto delegate = itemDelegateForIndex(index);
3147 QStyleOptionViewItem option;
3148 initViewItemOption(&option);
3149 return delegate ? delegate->sizeHint(option, index) : QSize();
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168int QAbstractItemView::sizeHintForRow(
int row)
const
3170 Q_D(
const QAbstractItemView);
3172 if (row < 0 || row >= d->model->rowCount(d->root))
3177 QStyleOptionViewItem option;
3178 initViewItemOption(&option);
3180 int colCount = d->model->columnCount(d->root);
3181 for (
int c = 0; c < colCount; ++c) {
3182 const QModelIndex index = d->model->index(row, c, d->root);
3183 if (QWidget *editor = d->editorForIndex(index).widget.data())
3184 height = qMax(height, editor->height());
3185 if (
const QAbstractItemDelegate *delegate = itemDelegateForIndex(index))
3186 height = qMax(height, delegate->sizeHint(option, index).height());
3192
3193
3194
3195
3196
3197
3198
3199int QAbstractItemView::sizeHintForColumn(
int column)
const
3201 Q_D(
const QAbstractItemView);
3203 if (column < 0 || column >= d->model->columnCount(d->root))
3208 QStyleOptionViewItem option;
3209 initViewItemOption(&option);
3211 int rows = d->model->rowCount(d->root);
3212 for (
int r = 0; r < rows; ++r) {
3213 const QModelIndex index = d->model->index(r, column, d->root);
3214 if (QWidget *editor = d->editorForIndex(index).widget.data())
3215 width = qMax(width, editor->sizeHint().width());
3216 if (
const QAbstractItemDelegate *delegate = itemDelegateForIndex(index))
3217 width = qMax(width, delegate->sizeHint(option, index).width());
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239int QAbstractItemView::updateThreshold()
const
3241 Q_D(
const QAbstractItemView);
3242 return d->updateThreshold;
3245void QAbstractItemView::setUpdateThreshold(
int threshold)
3247 Q_D(QAbstractItemView);
3248 if (d->updateThreshold == threshold)
3250 d->updateThreshold = threshold;
3254
3255
3256
3257
3258
3259void QAbstractItemView::openPersistentEditor(
const QModelIndex &index)
3261 Q_D(QAbstractItemView);
3262 QStyleOptionViewItem options;
3263 initViewItemOption(&options);
3264 options.rect = visualRect(index);
3265 options.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
3267 QWidget *editor = d->editor(index, options);
3270 d->persistent.insert(editor);
3275
3276
3277
3278
3279void QAbstractItemView::closePersistentEditor(
const QModelIndex &index)
3281 Q_D(QAbstractItemView);
3282 if (QWidget *editor = d->editorForIndex(index).widget.data()) {
3283 if (index == selectionModel()->currentIndex())
3284 closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
3285 d->persistent.remove(editor);
3286 d->removeEditor(editor);
3287 d->releaseEditor(editor, index);
3292
3293
3294
3295
3296
3297
3298bool QAbstractItemView::isPersistentEditorOpen(
const QModelIndex &index)
const
3300 Q_D(
const QAbstractItemView);
3301 return d->editorForIndex(index).widget;
4065void QAbstractItemView::doAutoScroll()
4068 Q_D(QAbstractItemView);
4069 QScrollBar *verticalScroll = verticalScrollBar();
4070 QScrollBar *horizontalScroll = horizontalScrollBar();
4074 QHeaderView *hv = qobject_cast<QHeaderView*>(
this);
4076 QAbstractScrollArea *parent = qobject_cast<QAbstractScrollArea*>(parentWidget());
4078 if (hv->orientation() == Qt::Horizontal) {
4079 if (!hv->horizontalScrollBar() || !hv->horizontalScrollBar()->isVisible())
4080 horizontalScroll = parent->horizontalScrollBar();
4082 if (!hv->verticalScrollBar() || !hv->verticalScrollBar()->isVisible())
4083 verticalScroll = parent->verticalScrollBar();
4088 const int verticalStep = verticalScroll->pageStep();
4089 const int horizontalStep = horizontalScroll->pageStep();
4090 if (d->autoScrollCount < qMax(verticalStep, horizontalStep))
4091 ++d->autoScrollCount;
4093 const int margin = d->autoScrollMargin;
4094 const int verticalValue = verticalScroll->value();
4095 const int horizontalValue = horizontalScroll->value();
4097 const QPoint pos = d->draggedPosition;
4099 const QRect area = QWidgetPrivate::get(d->viewport)->clipRect();
4102 if (pos.y() - area.top() < margin)
4103 verticalScroll->setValue(verticalValue - d->autoScrollCount);
4104 else if (area.bottom() - pos.y() < margin)
4105 verticalScroll->setValue(verticalValue + d->autoScrollCount);
4106 if (pos.x() - area.left() < margin)
4107 horizontalScroll->setValue(horizontalValue - d->autoScrollCount);
4108 else if (area.right() - pos.x() < margin)
4109 horizontalScroll->setValue(horizontalValue + d->autoScrollCount);
4111 const bool verticalUnchanged = (verticalValue == verticalScroll->value());
4112 const bool horizontalUnchanged = (horizontalValue == horizontalScroll->value());
4113 if (verticalUnchanged && horizontalUnchanged) {
4116#if QT_CONFIG(draganddrop)
4117 d->dropIndicatorRect = QRect();
4118 d->dropIndicatorPosition = QAbstractItemView::OnViewport;
4121 case QAbstractItemView::DragSelectingState: {
4124 const QPoint globalPos = d->viewport->mapToGlobal(pos);
4125 const QPoint windowPos = window()->mapFromGlobal(globalPos);
4126 QMouseEvent mm(QEvent::MouseMove, pos, windowPos, globalPos,
4127 Qt::NoButton, Qt::LeftButton, d->pressedModifiers,
4128 Qt::MouseEventSynthesizedByQt);
4129 QApplication::sendEvent(viewport(), &mm);
4132 case QAbstractItemView::DraggingState: {
4138 d->draggedPosition = pos;
4139 d->draggedPositionOffset = d->offset();
4145 d->viewport->update();
4249QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::extendedSelectionCommand(
4250 const QModelIndex &index,
const QEvent *event)
const
4252 Qt::KeyboardModifiers modifiers = event && event->isInputEvent()
4253 ?
static_cast<
const QInputEvent*>(event)->modifiers()
4254 : QGuiApplication::keyboardModifiers();
4256 switch (event->type()) {
4257 case QEvent::MouseMove: {
4259 if (modifiers & Qt::ControlModifier)
4260 return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags();
4263 case QEvent::MouseButtonPress: {
4264 const Qt::MouseButton button =
static_cast<
const QMouseEvent*>(event)->button();
4265 const bool rightButtonPressed = button & Qt::RightButton;
4266 const bool shiftKeyPressed = modifiers & Qt::ShiftModifier;
4267 const bool controlKeyPressed = modifiers & Qt::ControlModifier;
4268 const bool indexIsSelected = selectionModel->isSelected(index);
4269 if ((shiftKeyPressed || controlKeyPressed) && rightButtonPressed)
4270 return QItemSelectionModel::NoUpdate;
4271 if (!shiftKeyPressed && !controlKeyPressed && indexIsSelected)
4272 return QItemSelectionModel::NoUpdate;
4273 if (!index.isValid() && !rightButtonPressed && !shiftKeyPressed && !controlKeyPressed)
4274 return QItemSelectionModel::Clear;
4275 if (!index.isValid())
4276 return QItemSelectionModel::NoUpdate;
4278 if (controlKeyPressed && !rightButtonPressed && pressedAlreadySelected
4279#if QT_CONFIG(draganddrop)
4280 && dragEnabled && isIndexDragEnabled(index)
4283 return QItemSelectionModel::NoUpdate;
4287 case QEvent::MouseButtonRelease: {
4289 const Qt::MouseButton button =
static_cast<
const QMouseEvent*>(event)->button();
4290 const bool rightButtonPressed = button & Qt::RightButton;
4291 const bool shiftKeyPressed = modifiers & Qt::ShiftModifier;
4292 const bool controlKeyPressed = modifiers & Qt::ControlModifier;
4293 if (((index == pressedIndex && selectionModel->isSelected(index))
4294 || !index.isValid()) && state != QAbstractItemView::DragSelectingState
4295 && !shiftKeyPressed && !controlKeyPressed && (!rightButtonPressed || !index.isValid()))
4296 return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags();
4297 if (index == pressedIndex && controlKeyPressed && !rightButtonPressed
4298#if QT_CONFIG(draganddrop)
4299 && dragEnabled && isIndexDragEnabled(index)
4304 return QItemSelectionModel::NoUpdate;
4306 case QEvent::KeyPress: {
4308 switch (
static_cast<
const QKeyEvent*>(event)->key()) {
4309 case Qt::Key_Backtab:
4310 modifiers = modifiers & ~Qt::ShiftModifier;
4318 case Qt::Key_PageUp:
4319 case Qt::Key_PageDown:
4321 if (modifiers & Qt::ControlModifier
4322#ifdef QT_KEYPAD_NAVIGATION
4324 || QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
4327 return QItemSelectionModel::NoUpdate;
4329 case Qt::Key_Select:
4330 return QItemSelectionModel::Toggle|selectionBehaviorFlags();
4332 if (modifiers & Qt::ControlModifier)
4333 return QItemSelectionModel::Toggle|selectionBehaviorFlags();
4334 return QItemSelectionModel::Select|selectionBehaviorFlags();
4345 if (modifiers & Qt::ShiftModifier)
4346 return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags();
4347 if (modifiers & Qt::ControlModifier)
4348 return QItemSelectionModel::Toggle|selectionBehaviorFlags();
4349 if (state == QAbstractItemView::DragSelectingState) {
4351 return QItemSelectionModel::Clear|QItemSelectionModel::SelectCurrent|selectionBehaviorFlags();
4354 return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags();