Qt 4.8
qabstractitemview.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qabstractitemview.h"
43 
44 #ifndef QT_NO_ITEMVIEWS
45 #include <qpointer.h>
46 #include <qapplication.h>
47 #include <qclipboard.h>
48 #include <qpainter.h>
49 #include <qstyle.h>
50 #include <qdrag.h>
51 #include <qevent.h>
52 #include <qscrollbar.h>
53 #include <qwhatsthis.h>
54 #include <qtooltip.h>
55 #include <qdatetime.h>
56 #include <qlineedit.h>
57 #include <qspinbox.h>
58 #include <qstyleditemdelegate.h>
59 #include <private/qabstractitemview_p.h>
60 #include <private/qabstractitemmodel_p.h>
61 #ifndef QT_NO_ACCESSIBILITY
62 #include <qaccessible.h>
63 #include <qaccessible2.h>
64 #endif
65 #include <private/qsoftkeymanager_p.h>
66 
68 
70  : model(QAbstractItemModelPrivate::staticEmptyModel()),
71  itemDelegate(0),
72  selectionModel(0),
73  ctrlDragSelectionFlag(QItemSelectionModel::NoUpdate),
74  noSelectionOnMousePress(false),
75  selectionMode(QAbstractItemView::ExtendedSelection),
76  selectionBehavior(QAbstractItemView::SelectItems),
77  currentlyCommittingEditor(0),
78  pressedModifiers(Qt::NoModifier),
79  pressedPosition(QPoint(-1, -1)),
80  pressedAlreadySelected(false),
81  viewportEnteredNeeded(false),
82  state(QAbstractItemView::NoState),
83  stateBeforeAnimation(QAbstractItemView::NoState),
84  editTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed),
85  lastTrigger(QAbstractItemView::NoEditTriggers),
86  tabKeyNavigation(false),
87 #ifndef QT_NO_DRAGANDDROP
88  showDropIndicator(true),
89  dragEnabled(false),
90  dragDropMode(QAbstractItemView::NoDragDrop),
91  overwrite(false),
92  dropIndicatorPosition(QAbstractItemView::OnItem),
93  defaultDropAction(Qt::IgnoreAction),
94 #endif
95 #ifdef QT_SOFTKEYS_ENABLED
96  doneSoftKey(0),
97 #endif
98  autoScroll(true),
99  autoScrollMargin(16),
100  autoScrollCount(0),
101  shouldScrollToCurrentOnShow(false),
102  shouldClearStatusTip(false),
103  alternatingColors(false),
104  textElideMode(Qt::ElideRight),
105  verticalScrollMode(QAbstractItemView::ScrollPerItem),
106  horizontalScrollMode(QAbstractItemView::ScrollPerItem),
107  currentIndexSet(false),
108  wrapItemText(false),
109  delayedPendingLayout(true),
110  moveCursorUpdatedView(false)
111 {
113 }
114 
116 {
117 }
118 
120 {
122  q->setItemDelegate(new QStyledItemDelegate(q));
123 
124  vbar->setRange(0, 0);
125  hbar->setRange(0, 0);
126 
127  QObject::connect(vbar, SIGNAL(actionTriggered(int)),
128  q, SLOT(verticalScrollbarAction(int)));
129  QObject::connect(hbar, SIGNAL(actionTriggered(int)),
130  q, SLOT(horizontalScrollbarAction(int)));
131  QObject::connect(vbar, SIGNAL(valueChanged(int)),
132  q, SLOT(verticalScrollbarValueChanged(int)));
133  QObject::connect(hbar, SIGNAL(valueChanged(int)),
134  q, SLOT(horizontalScrollbarValueChanged(int)));
135 
137 
138  q->setAttribute(Qt::WA_InputMethodEnabled);
139 
140 #ifdef QT_SOFTKEYS_ENABLED
142 #endif
143 }
144 
146 {
148  if (hover == index)
149  return;
150 
152  q->update(hover); //update the old one
153  q->update(index); //update the new one
154  } else {
155  QRect oldHoverRect = q->visualRect(hover);
156  QRect newHoverRect = q->visualRect(index);
157  viewport->update(QRect(0, newHoverRect.y(), viewport->width(), newHoverRect.height()));
158  viewport->update(QRect(0, oldHoverRect.y(), viewport->width(), oldHoverRect.height()));
159  }
160  hover = index;
161 }
162 
164 {
165  //we take a persistent model index because the model might change by emitting signals
167  setHoverIndex(index);
168  if (viewportEnteredNeeded || enteredIndex != index) {
169  viewportEnteredNeeded = false;
170 
171  if (index.isValid()) {
172  emit q->entered(index);
173 #ifndef QT_NO_STATUSTIP
174  QString statustip = model->data(index, Qt::StatusTipRole).toString();
175  if (parent && (shouldClearStatusTip || !statustip.isEmpty())) {
176  QStatusTipEvent tip(statustip);
178  shouldClearStatusTip = !statustip.isEmpty();
179  }
180 #endif
181  } else {
182 #ifndef QT_NO_STATUSTIP
183  if (parent && shouldClearStatusTip) {
184  QString emptyString;
185  QStatusTipEvent tip( emptyString );
187  }
188 #endif
189  emit q->viewportEntered();
190  }
192  }
193 }
194 
195 
642 {
643  d_func()->init();
644 }
645 
650  : QAbstractScrollArea(dd, parent)
651 {
652  d_func()->init();
653 }
654 
659 {
661  // stop these timers here before ~QObject
662  d->delayedReset.stop();
663  d->updateTimer.stop();
664  d->delayedEditing.stop();
665  d->delayedAutoScroll.stop();
666  d->autoScrollTimer.stop();
667  d->delayedLayout.stop();
668  d->fetchMoreTimer.stop();
669 }
670 
692 {
694  if (model == d->model)
695  return;
696  if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
697  disconnect(d->model, SIGNAL(destroyed()),
698  this, SLOT(_q_modelDestroyed()));
701  disconnect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
702  this, SLOT(_q_headerDataChanged()));
703  disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
704  this, SLOT(rowsInserted(QModelIndex,int,int)));
706  this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));
707  disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
708  this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
709  disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
710  this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
711  disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
712  this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));
713  disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
714  this, SLOT(_q_columnsRemoved(QModelIndex,int,int)));
715  disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
716  this, SLOT(_q_columnsInserted(QModelIndex,int,int)));
717 
718  disconnect(d->model, SIGNAL(modelReset()), this, SLOT(reset()));
719  disconnect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged()));
720  }
721  d->model = (model ? model : QAbstractItemModelPrivate::staticEmptyModel());
722 
723  // These asserts do basic sanity checking of the model
724  Q_ASSERT_X(d->model->index(0,0) == d->model->index(0,0),
725  "QAbstractItemView::setModel",
726  "A model should return the exact same index "
727  "(including its internal id/pointer) when asked for it twice in a row.");
728  Q_ASSERT_X(!d->model->index(0,0).parent().isValid(),
729  "QAbstractItemView::setModel",
730  "The parent of a top level index should be invalid");
731 
733  connect(d->model, SIGNAL(destroyed()),
734  this, SLOT(_q_modelDestroyed()));
737  connect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
738  this, SLOT(_q_headerDataChanged()));
739  connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
740  this, SLOT(rowsInserted(QModelIndex,int,int)));
741  connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
742  this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
743  connect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
744  this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)));
745  connect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
746  this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
747  connect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
748  this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int)));
749  connect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
750  this, SLOT(_q_columnsRemoved(QModelIndex,int,int)));
751  connect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)),
752  this, SLOT(_q_columnsInserted(QModelIndex,int,int)));
753 
754  connect(d->model, SIGNAL(modelReset()), this, SLOT(reset()));
755  connect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged()));
756  }
757 
758  QItemSelectionModel *selection_model = new QItemSelectionModel(d->model, this);
759  connect(d->model, SIGNAL(destroyed()), selection_model, SLOT(deleteLater()));
760  setSelectionModel(selection_model);
761 
762  reset(); // kill editors, set new root and do layout
763 }
764 
769 {
770  Q_D(const QAbstractItemView);
771  return (d->model == QAbstractItemModelPrivate::staticEmptyModel() ? 0 : d->model);
772 }
773 
789 {
790  // ### if the given model is null, we should use the original selection model
791  Q_ASSERT(selectionModel);
793 
794  if (selectionModel->model() != d->model) {
795  qWarning("QAbstractItemView::setSelectionModel() failed: "
796  "Trying to set a selection model, which works on "
797  "a different model than the view.");
798  return;
799  }
800 
801  if (d->selectionModel) {
806  }
807 
808  d->selectionModel = selectionModel;
809 
810  if (d->selectionModel) {
815  }
816 }
817 
824 {
825  Q_D(const QAbstractItemView);
826  return d->selectionModel;
827 }
828 
845 {
847  if (delegate == d->itemDelegate)
848  return;
849 
850  if (d->itemDelegate) {
851  if (d->delegateRefCount(d->itemDelegate) == 1) {
854  disconnect(d->itemDelegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*)));
855  disconnect(d->itemDelegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout()));
856  }
857  }
858 
859  if (delegate) {
860  if (d->delegateRefCount(delegate) == 0) {
863  connect(delegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*)));
864  qRegisterMetaType<QModelIndex>("QModelIndex");
865  connect(delegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout()), Qt::QueuedConnection);
866  }
867  }
868  d->itemDelegate = delegate;
869  viewport()->update();
870 }
871 
879 {
880  return d_func()->itemDelegate;
881 }
882 
887 {
888  const QModelIndex current = currentIndex();
889  if (!current.isValid() || query != Qt::ImMicroFocus)
891  return visualRect(current);
892 }
893 
919 {
921  if (QAbstractItemDelegate *rowDelegate = d->rowDelegates.value(row, 0)) {
922  if (d->delegateRefCount(rowDelegate) == 1) {
925  disconnect(rowDelegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*)));
926  }
927  d->rowDelegates.remove(row);
928  }
929  if (delegate) {
930  if (d->delegateRefCount(delegate) == 0) {
933  connect(delegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*)));
934  }
935  d->rowDelegates.insert(row, delegate);
936  }
937  viewport()->update();
938 }
939 
953 {
954  Q_D(const QAbstractItemView);
955  return d->rowDelegates.value(row, 0);
956 }
957 
982 {
984  if (QAbstractItemDelegate *columnDelegate = d->columnDelegates.value(column, 0)) {
985  if (d->delegateRefCount(columnDelegate) == 1) {
988  disconnect(columnDelegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*)));
989  }
990  d->columnDelegates.remove(column);
991  }
992  if (delegate) {
993  if (d->delegateRefCount(delegate) == 0) {
996  connect(delegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*)));
997  }
998  d->columnDelegates.insert(column, delegate);
999  }
1000  viewport()->update();
1001 }
1002 
1016 {
1017  Q_D(const QAbstractItemView);
1018  return d->columnDelegates.value(column, 0);
1019 }
1020 
1026 {
1027  Q_D(const QAbstractItemView);
1028  return d->delegateForIndex(index);
1029 }
1030 
1045 {
1047  d->selectionMode = mode;
1048 }
1049 
1051 {
1052  Q_D(const QAbstractItemView);
1053  return d->selectionMode;
1054 }
1055 
1070 {
1072  d->selectionBehavior = behavior;
1073 }
1074 
1076 {
1077  Q_D(const QAbstractItemView);
1078  return d->selectionBehavior;
1079 }
1080 
1096 {
1098  if (d->selectionModel && (!index.isValid() || d->isIndexEnabled(index))) {
1099  QItemSelectionModel::SelectionFlags command = selectionCommand(index, 0);
1100  d->selectionModel->setCurrentIndex(index, command);
1101  d->currentIndexSet = true;
1102  if ((command & QItemSelectionModel::Current) == 0)
1103  d->pressedPosition = visualRect(currentIndex()).center() + d->offset();
1104  }
1105 }
1106 
1113 {
1114  Q_D(const QAbstractItemView);
1115  return d->selectionModel ? d->selectionModel->currentIndex() : QModelIndex();
1116 }
1117 
1118 
1129 {
1131  d->delayedReset.stop(); //make sure we stop the timer
1132  foreach (const QEditorInfo &info, d->indexEditorHash) {
1133  if (info.widget)
1134  d->releaseEditor(info.widget.data());
1135  }
1136  d->editorIndexHash.clear();
1137  d->indexEditorHash.clear();
1138  d->persistent.clear();
1139  d->currentIndexSet = false;
1140  setState(NoState);
1142  if (d->selectionModel)
1143  d->selectionModel->reset();
1144 #ifndef QT_NO_ACCESSIBILITY
1145 #ifdef Q_WS_X11
1146  if (QAccessible::isActive()) {
1149  }
1150 #endif
1151 #endif
1152 }
1153 
1160 {
1162  if (index.isValid() && index.model() != d->model) {
1163  qWarning("QAbstractItemView::setRootIndex failed : index must be from the currently set model");
1164  return;
1165  }
1166  d->root = index;
1167  d->doDelayedItemsLayout();
1168 }
1169 
1177 {
1178  return QModelIndex(d_func()->root);
1179 }
1180 
1189 {
1191  SelectionMode mode = d->selectionMode;
1192  if (mode == MultiSelection || mode == ExtendedSelection)
1194  |d->selectionBehaviorFlags());
1195  else if (mode != SingleSelection)
1196  d->selectAll(selectionCommand(d->model->index(0, 0, d->root)));
1197 }
1198 
1212 {
1214  if (!d->isIndexValid(index))
1215  qWarning("edit: index was invalid");
1216  if (!edit(index, AllEditTriggers, 0))
1217  qWarning("edit: editing failed");
1218 }
1219 
1226 {
1228  if (d->selectionModel)
1229  d->selectionModel->clearSelection();
1230 }
1231 
1242 {
1244  d->interruptDelayedItemsLayout();
1245  updateGeometries();
1246  d->viewport->update();
1247 }
1248 
1262 {
1264  d->editTriggers = actions;
1265 }
1266 
1267 QAbstractItemView::EditTriggers QAbstractItemView::editTriggers() const
1268 {
1269  Q_D(const QAbstractItemView);
1270  return d->editTriggers;
1271 }
1272 
1286 {
1288  if (mode == d->verticalScrollMode)
1289  return;
1290  QModelIndex topLeft = indexAt(QPoint(0, 0));
1291  d->verticalScrollMode = mode;
1292  updateGeometries(); // update the scroll bars
1294 }
1295 
1297 {
1298  Q_D(const QAbstractItemView);
1299  return d->verticalScrollMode;
1300 }
1301 
1315 {
1317  d->horizontalScrollMode = mode;
1318  updateGeometries(); // update the scroll bars
1319 }
1320 
1322 {
1323  Q_D(const QAbstractItemView);
1324  return d->horizontalScrollMode;
1325 }
1326 
1327 #ifndef QT_NO_DRAGANDDROP
1328 
1353 {
1355  d->overwrite = overwrite;
1356 }
1357 
1359 {
1360  Q_D(const QAbstractItemView);
1361  return d->overwrite;
1362 }
1363 #endif
1364 
1383 {
1385  d->autoScroll = enable;
1386 }
1387 
1389 {
1390  Q_D(const QAbstractItemView);
1391  return d->autoScroll;
1392 }
1393 
1406 {
1408  d->autoScrollMargin = margin;
1409 }
1410 
1412 {
1413  Q_D(const QAbstractItemView);
1414  return d->autoScrollMargin;
1415 }
1416 
1426 {
1428  d->tabKeyNavigation = enable;
1429 }
1430 
1432 {
1433  Q_D(const QAbstractItemView);
1434  return d->tabKeyNavigation;
1435 }
1436 
1437 #ifndef QT_NO_DRAGANDDROP
1438 
1449 {
1451  d->showDropIndicator = enable;
1452 }
1453 
1455 {
1456  Q_D(const QAbstractItemView);
1457  return d->showDropIndicator;
1458 }
1459 
1471 {
1473  d->dragEnabled = enable;
1474 }
1475 
1476 bool QAbstractItemView::dragEnabled() const
1477 {
1478  Q_D(const QAbstractItemView);
1479  return d->dragEnabled;
1480 }
1481 
1516 {
1518  d->dragDropMode = behavior;
1519  setDragEnabled(behavior == DragOnly || behavior == DragDrop || behavior == InternalMove);
1520  setAcceptDrops(behavior == DropOnly || behavior == DragDrop || behavior == InternalMove);
1521 }
1522 
1524 {
1525  Q_D(const QAbstractItemView);
1526  DragDropMode setBehavior = d->dragDropMode;
1527  if (!dragEnabled() && !acceptDrops())
1528  return NoDragDrop;
1529 
1530  if (dragEnabled() && !acceptDrops())
1531  return DragOnly;
1532 
1533  if (!dragEnabled() && acceptDrops())
1534  return DropOnly;
1535 
1536  if (dragEnabled() && acceptDrops()) {
1537  if (setBehavior == InternalMove)
1538  return setBehavior;
1539  else
1540  return DragDrop;
1541  }
1542 
1543  return NoDragDrop;
1544 }
1545 
1560 {
1562  d->defaultDropAction = dropAction;
1563 }
1564 
1566 {
1567  Q_D(const QAbstractItemView);
1568  return d->defaultDropAction;
1569 }
1570 
1571 #endif // QT_NO_DRAGANDDROP
1572 
1587 {
1589  d->alternatingColors = enable;
1590  if (isVisible())
1591  d->viewport->update();
1592 }
1593 
1595 {
1596  Q_D(const QAbstractItemView);
1597  return d->alternatingColors;
1598 }
1599 
1611 {
1613  if (size == d->iconSize)
1614  return;
1615  d->iconSize = size;
1616  d->doDelayedItemsLayout();
1617 }
1618 
1620 {
1621  Q_D(const QAbstractItemView);
1622  return d->iconSize;
1623 }
1624 
1636 {
1638  d->textElideMode = mode;
1639 }
1640 
1642 {
1643  return d_func()->textElideMode;
1644 }
1645 
1650 {
1652  if (d->tabKeyNavigation && isEnabled() && d->viewport->isEnabled()) {
1654  keyPressEvent(&event);
1655  if (event.isAccepted())
1656  return true;
1657  }
1659 }
1660 
1665 {
1667  switch (event->type()) {
1668  case QEvent::Paint:
1669  //we call this here because the scrollbars' visibility might be altered
1670  //so this can't be done in the paintEvent method
1671  d->executePostedLayout(); //make sure we set the layout properly
1672  break;
1673  case QEvent::Show:
1674  d->executePostedLayout(); //make sure we set the layout properly
1675  if (d->shouldScrollToCurrentOnShow) {
1676  d->shouldScrollToCurrentOnShow = false;
1677  const QModelIndex current = currentIndex();
1678  if (current.isValid() && (d->state == QAbstractItemView::EditingState || d->autoScroll))
1679  scrollTo(current);
1680  }
1681  break;
1682  case QEvent::LocaleChange:
1683  viewport()->update();
1684  break;
1687  updateGeometries();
1688  break;
1689  case QEvent::StyleChange:
1690  doItemsLayout();
1691  break;
1692  case QEvent::FocusOut:
1693  d->checkPersistentEditorFocus();
1694  break;
1695  case QEvent::FontChange:
1696  d->doDelayedItemsLayout(); // the size of the items will change
1697  break;
1698 #ifdef QT_SOFTKEYS_ENABLED
1701  break;
1702 #endif
1703  default:
1704  break;
1705  }
1706  return QAbstractScrollArea::event(event);
1707 }
1708 
1718 {
1720  switch (event->type()) {
1721  case QEvent::HoverMove:
1722  case QEvent::HoverEnter:
1723  d->setHoverIndex(indexAt(static_cast<QHoverEvent*>(event)->pos()));
1724  break;
1725  case QEvent::HoverLeave:
1726  d->setHoverIndex(QModelIndex());
1727  break;
1728  case QEvent::Enter:
1729  d->viewportEnteredNeeded = true;
1730  break;
1731  case QEvent::Leave:
1732  #ifndef QT_NO_STATUSTIP
1733  if (d->shouldClearStatusTip && d->parent) {
1734  QString empty;
1735  QStatusTipEvent tip(empty);
1736  QApplication::sendEvent(d->parent, &tip);
1737  d->shouldClearStatusTip = false;
1738  }
1739  #endif
1740  d->enteredIndex = QModelIndex();
1741  break;
1742  case QEvent::ToolTip:
1744  case QEvent::WhatsThis: {
1745  QHelpEvent *he = static_cast<QHelpEvent*>(event);
1746  const QModelIndex index = indexAt(he->pos());
1747  QStyleOptionViewItemV4 option = d->viewOptionsV4();
1748  option.rect = visualRect(index);
1749  option.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
1750  bool retval = false;
1751  // ### Qt 5: make this a normal function call to a virtual function
1752  QMetaObject::invokeMethod(d->delegateForIndex(index), "helpEvent",
1753  Q_RETURN_ARG(bool, retval),
1754  Q_ARG(QHelpEvent *, he),
1755  Q_ARG(QAbstractItemView *, this),
1756  Q_ARG(QStyleOptionViewItem, option),
1757  Q_ARG(QModelIndex, index));
1758  return retval;
1759  }
1760  case QEvent::FontChange:
1761  d->doDelayedItemsLayout(); // the size of the items will change
1762  break;
1765  d->viewport->update();
1766  break;
1767  default:
1768  break;
1769  }
1770  return QAbstractScrollArea::viewportEvent(event);
1771 }
1772 
1779 {
1781  d->delayedAutoScroll.stop(); //any interaction with the view cancel the auto scrolling
1782  QPoint pos = event->pos();
1784 
1785  if (!d->selectionModel
1786  || (d->state == EditingState && d->hasEditor(index)))
1787  return;
1788 
1789  d->pressedAlreadySelected = d->selectionModel->isSelected(index);
1790  d->pressedIndex = index;
1791  d->pressedModifiers = event->modifiers();
1792  QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
1793  d->noSelectionOnMousePress = command == QItemSelectionModel::NoUpdate || !index.isValid();
1794  QPoint offset = d->offset();
1795  if ((command & QItemSelectionModel::Current) == 0)
1796  d->pressedPosition = pos + offset;
1797  else if (!indexAt(d->pressedPosition - offset).isValid())
1798  d->pressedPosition = visualRect(currentIndex()).center() + offset;
1799 
1800  if (edit(index, NoEditTriggers, event))
1801  return;
1802 
1803  if (index.isValid() && d->isIndexEnabled(index)) {
1804  // we disable scrollTo for mouse press so the item doesn't change position
1805  // when the user is interacting with it (ie. clicking on it)
1806  bool autoScroll = d->autoScroll;
1807  d->autoScroll = false;
1808  d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
1809  d->autoScroll = autoScroll;
1810  QRect rect(d->pressedPosition - offset, pos);
1811  if (command.testFlag(QItemSelectionModel::Toggle)) {
1812  command &= ~QItemSelectionModel::Toggle;
1813  d->ctrlDragSelectionFlag = d->selectionModel->isSelected(index) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
1814  command |= d->ctrlDragSelectionFlag;
1815  }
1816  setSelection(rect, command);
1817 
1818  // signal handlers may change the model
1819  emit pressed(index);
1820  if (d->autoScroll) {
1821  //we delay the autoscrolling to filter out double click event
1822  //100 is to be sure that there won't be a double-click misinterpreted as a 2 single clicks
1823  d->delayedAutoScroll.start(QApplication::doubleClickInterval()+100, this);
1824  }
1825 
1826  } else {
1827  // Forces a finalize() even if mouse is pressed, but not on a item
1828  d->selectionModel->select(QModelIndex(), QItemSelectionModel::Select);
1829  }
1830 }
1831 
1838 {
1840  QPoint topLeft;
1841  QPoint bottomRight = event->pos();
1842 
1843  if (state() == ExpandingState || state() == CollapsingState)
1844  return;
1845 
1846 #ifndef QT_NO_DRAGANDDROP
1847  if (state() == DraggingState) {
1848  topLeft = d->pressedPosition - d->offset();
1849  if ((topLeft - bottomRight).manhattanLength() > QApplication::startDragDistance()) {
1850  d->pressedIndex = QModelIndex();
1851  startDrag(d->model->supportedDragActions());
1852  setState(NoState); // the startDrag will return when the dnd operation is done
1853  stopAutoScroll();
1854  }
1855  return;
1856  }
1857 #endif // QT_NO_DRAGANDDROP
1858 
1859  QPersistentModelIndex index = indexAt(bottomRight);
1860  QModelIndex buddy = d->model->buddy(d->pressedIndex);
1861  if ((state() == EditingState && d->hasEditor(buddy))
1862  || edit(index, NoEditTriggers, event))
1863  return;
1864 
1865  if (d->selectionMode != SingleSelection)
1866  topLeft = d->pressedPosition - d->offset();
1867  else
1868  topLeft = bottomRight;
1869 
1870  d->checkMouseMove(index);
1871 
1872 #ifndef QT_NO_DRAGANDDROP
1873  if (d->pressedIndex.isValid()
1874  && d->dragEnabled
1875  && (state() != DragSelectingState)
1876  && (event->buttons() != Qt::NoButton)
1877  && !d->selectedDraggableIndexes().isEmpty()) {
1879  return;
1880  }
1881 #endif
1882 
1883  if ((event->buttons() & Qt::LeftButton) && d->selectionAllowed(index) && d->selectionModel) {
1885  QItemSelectionModel::SelectionFlags command = selectionCommand(index, event);
1886  if (d->ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate && command.testFlag(QItemSelectionModel::Toggle)) {
1887  command &= ~QItemSelectionModel::Toggle;
1888  command |= d->ctrlDragSelectionFlag;
1889  }
1890 
1891  // Do the normalize ourselves, since QRect::normalized() is flawed
1892  QRect selectionRect = QRect(topLeft, bottomRight);
1893  setSelection(selectionRect, command);
1894 
1895  // set at the end because it might scroll the view
1896  if (index.isValid()
1897  && (index != d->selectionModel->currentIndex())
1898  && d->isIndexEnabled(index))
1899  d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
1900  }
1901 }
1902 
1911 {
1913 
1914  QPoint pos = event->pos();
1916 
1917  if (state() == EditingState) {
1918  if (d->isIndexValid(index)
1919  && d->isIndexEnabled(index)
1920  && d->sendDelegateEvent(index, event))
1921  update(index);
1922  return;
1923  }
1924 
1925  bool click = (index == d->pressedIndex && index.isValid());
1926  bool selectedClicked = click && (event->button() & Qt::LeftButton) && d->pressedAlreadySelected;
1927  EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers);
1928  bool edited = edit(index, trigger, event);
1929 
1930  d->ctrlDragSelectionFlag = QItemSelectionModel::NoUpdate;
1931 
1932  if (d->selectionModel && d->noSelectionOnMousePress) {
1933  d->noSelectionOnMousePress = false;
1934  d->selectionModel->select(index, selectionCommand(index, event));
1935  }
1936 
1937  setState(NoState);
1938 
1939  if (click) {
1940  emit clicked(index);
1941  if (edited)
1942  return;
1943  QStyleOptionViewItemV4 option = d->viewOptionsV4();
1944  if (d->pressedAlreadySelected)
1945  option.state |= QStyle::State_Selected;
1947  emit activated(index);
1948  }
1949 }
1950 
1957 {
1959 
1960  QModelIndex index = indexAt(event->pos());
1961  if (!index.isValid()
1962  || !d->isIndexEnabled(index)
1963  || (d->pressedIndex != index)) {
1965  event->pos(), event->button(),
1966  event->buttons(), event->modifiers());
1967  mousePressEvent(&me);
1968  return;
1969  }
1970  // signal handlers may change the model
1971  QPersistentModelIndex persistent = index;
1972  emit doubleClicked(persistent);
1973  if ((event->button() & Qt::LeftButton) && !edit(persistent, DoubleClicked, event)
1975  emit activated(persistent);
1976 }
1977 
1978 #ifndef QT_NO_DRAGANDDROP
1979 
1988 {
1989  if (dragDropMode() == InternalMove
1990  && (event->source() != this|| !(event->possibleActions() & Qt::MoveAction)))
1991  return;
1992 
1993  if (d_func()->canDecode(event)) {
1994  event->accept();
1996  } else {
1997  event->ignore();
1998  }
1999 }
2000 
2010 {
2012  if (dragDropMode() == InternalMove
2013  && (event->source() != this || !(event->possibleActions() & Qt::MoveAction)))
2014  return;
2015 
2016  // ignore by default
2017  event->ignore();
2018 
2019  QModelIndex index = indexAt(event->pos());
2020  d->hover = index;
2021  if (!d->droppingOnItself(event, index)
2022  && d->canDecode(event)) {
2023 
2024  if (index.isValid() && d->showDropIndicator) {
2025  QRect rect = visualRect(index);
2026  d->dropIndicatorPosition = d->position(event->pos(), rect, index);
2027  switch (d->dropIndicatorPosition) {
2028  case AboveItem:
2029  if (d->isIndexDropEnabled(index.parent())) {
2030  d->dropIndicatorRect = QRect(rect.left(), rect.top(), rect.width(), 0);
2031  event->accept();
2032  } else {
2033  d->dropIndicatorRect = QRect();
2034  }
2035  break;
2036  case BelowItem:
2037  if (d->isIndexDropEnabled(index.parent())) {
2038  d->dropIndicatorRect = QRect(rect.left(), rect.bottom(), rect.width(), 0);
2039  event->accept();
2040  } else {
2041  d->dropIndicatorRect = QRect();
2042  }
2043  break;
2044  case OnItem:
2045  if (d->isIndexDropEnabled(index)) {
2046  d->dropIndicatorRect = rect;
2047  event->accept();
2048  } else {
2049  d->dropIndicatorRect = QRect();
2050  }
2051  break;
2052  case OnViewport:
2053  d->dropIndicatorRect = QRect();
2054  if (d->isIndexDropEnabled(rootIndex())) {
2055  event->accept(); // allow dropping in empty areas
2056  }
2057  break;
2058  }
2059  } else {
2060  d->dropIndicatorRect = QRect();
2061  d->dropIndicatorPosition = OnViewport;
2062  if (d->isIndexDropEnabled(rootIndex())) {
2063  event->accept(); // allow dropping in empty areas
2064  }
2065  }
2066  d->viewport->update();
2067  } // can decode
2068 
2069  if (d->shouldAutoScroll(event->pos()))
2070  startAutoScroll();
2071 }
2072 
2082 {
2084  Qt::DropAction dropAction = event->dropAction();
2085  if (q->dragDropMode() == QAbstractItemView::InternalMove)
2086  dropAction = Qt::MoveAction;
2087  if (event->source() == q
2088  && event->possibleActions() & Qt::MoveAction
2089  && dropAction == Qt::MoveAction) {
2090  QModelIndexList selectedIndexes = q->selectedIndexes();
2091  QModelIndex child = index;
2092  while (child.isValid() && child != root) {
2093  if (selectedIndexes.contains(child))
2094  return true;
2095  child = child.parent();
2096  }
2097  }
2098  return false;
2099 }
2100 
2108 {
2110  stopAutoScroll();
2111  setState(NoState);
2112  d->hover = QModelIndex();
2113  d->viewport->update();
2114 }
2115 
2124 {
2126  if (dragDropMode() == InternalMove) {
2127  if (event->source() != this || !(event->possibleActions() & Qt::MoveAction))
2128  return;
2129  }
2130 
2132  int col = -1;
2133  int row = -1;
2134  if (d->dropOn(event, &row, &col, &index)) {
2135  if (d->model->dropMimeData(event->mimeData(),
2136  dragDropMode() == InternalMove ? Qt::MoveAction : event->dropAction(), row, col, index)) {
2137  if (dragDropMode() == InternalMove)
2138  event->setDropAction(Qt::MoveAction);
2139  event->accept();
2140  }
2141  }
2142  stopAutoScroll();
2143  setState(NoState);
2144  d->viewport->update();
2145 }
2146 
2158 bool QAbstractItemViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex)
2159 {
2161  if (event->isAccepted())
2162  return false;
2163 
2165  // rootIndex() (i.e. the viewport) might be a valid index
2166  if (viewport->rect().contains(event->pos())) {
2167  index = q->indexAt(event->pos());
2168  if (!index.isValid() || !q->visualRect(index).contains(event->pos()))
2169  index = root;
2170  }
2171 
2172  // If we are allowed to do the drop
2173  if (model->supportedDropActions() & event->dropAction()) {
2174  int row = -1;
2175  int col = -1;
2176  if (index != root) {
2177  dropIndicatorPosition = position(event->pos(), q->visualRect(index), index);
2178  switch (dropIndicatorPosition) {
2180  row = index.row();
2181  col = index.column();
2182  index = index.parent();
2183  break;
2185  row = index.row() + 1;
2186  col = index.column();
2187  index = index.parent();
2188  break;
2191  break;
2192  }
2193  } else {
2195  }
2196  *dropIndex = index;
2197  *dropRow = row;
2198  *dropCol = col;
2199  if (!droppingOnItself(event, index))
2200  return true;
2201  }
2202  return false;
2203 }
2204 
2207 {
2209  if (!overwrite) {
2210  const int margin = 2;
2211  if (pos.y() - rect.top() < margin) {
2213  } else if (rect.bottom() - pos.y() < margin) {
2215  } else if (rect.contains(pos, true)) {
2217  }
2218  } else {
2219  QRect touchingRect = rect;
2220  touchingRect.adjust(-1, -1, 1, 1);
2221  if (touchingRect.contains(pos, false)) {
2223  }
2224  }
2225 
2226  if (r == QAbstractItemView::OnItem && (!(model->flags(index) & Qt::ItemIsDropEnabled)))
2228 
2229  return r;
2230 }
2231 
2232 #endif // QT_NO_DRAGANDDROP
2233 
2241 {
2244 
2246  const bool currentIndexValid = currentIndex().isValid();
2247 
2248  if (model
2249  && !d->currentIndexSet
2250  && !currentIndexValid) {
2251  bool autoScroll = d->autoScroll;
2252  d->autoScroll = false;
2253  QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); // first visible index
2254  if (index.isValid() && d->isIndexEnabled(index) && event->reason() != Qt::MouseFocusReason)
2256  d->autoScroll = autoScroll;
2257  }
2258 
2259  if (model && currentIndexValid) {
2260  if (currentIndex().flags() != Qt::ItemIsEditable)
2262  else
2264  }
2265 
2266  if (!currentIndexValid)
2268 
2269  d->viewport->update();
2270 }
2271 
2279 {
2282  d->viewport->update();
2283 
2284 #ifdef QT_SOFTKEYS_ENABLED
2285  if(!hasEditFocus())
2286  removeAction(d->doneSoftKey);
2287 #endif
2288 }
2289 
2302 {
2304  d->delayedAutoScroll.stop(); //any interaction with the view cancel the auto scrolling
2305 
2306 #ifdef QT_KEYPAD_NAVIGATION
2307  switch (event->key()) {
2308  case Qt::Key_Select:
2309  if (QApplication::keypadNavigationEnabled()) {
2310  if (!hasEditFocus()) {
2311  setEditFocus(true);
2312 #ifdef QT_SOFTKEYS_ENABLED
2313  // If we can't keypad navigate to any direction, there is no sense to add
2314  // "Done" softkey, since it basically does nothing when there is
2315  // only one widget in screen
2316  if(QWidgetPrivate::canKeypadNavigate(Qt::Horizontal)
2317  || QWidgetPrivate::canKeypadNavigate(Qt::Vertical))
2318  addAction(d->doneSoftKey);
2319 #endif
2320  return;
2321  }
2322  }
2323  break;
2324  case Qt::Key_Back:
2325  if (QApplication::keypadNavigationEnabled() && hasEditFocus()) {
2326 #ifdef QT_SOFTKEYS_ENABLED
2327  removeAction(d->doneSoftKey);
2328 #endif
2329  setEditFocus(false);
2330  } else {
2331  event->ignore();
2332  }
2333  return;
2334  case Qt::Key_Down:
2335  case Qt::Key_Up:
2336  // Let's ignore vertical navigation events, only if there is no other widget
2337  // what can take the focus in vertical direction. This means widget can handle navigation events
2338  // even the widget don't have edit focus, and there is no other widget in requested direction.
2339  if(QApplication::keypadNavigationEnabled() && !hasEditFocus()
2340  && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
2341  event->ignore();
2342  return;
2343  }
2344  break;
2345  case Qt::Key_Left:
2346  case Qt::Key_Right:
2347  // Similar logic as in up and down events
2348  if(QApplication::keypadNavigationEnabled() && !hasEditFocus()
2349  && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this))) {
2350  event->ignore();
2351  return;
2352  }
2353  break;
2354  default:
2355  if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
2356  event->ignore();
2357  return;
2358  }
2359  }
2360 #endif
2361 
2362 #if !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT)
2363  if (event == QKeySequence::Copy) {
2364  QVariant variant;
2365  if (d->model)
2366  variant = d->model->data(currentIndex(), Qt::DisplayRole);
2367  if (variant.type() == QVariant::String)
2369  event->accept();
2370  }
2371 #endif
2372 
2373  QPersistentModelIndex newCurrent;
2374  d->moveCursorUpdatedView = false;
2375  switch (event->key()) {
2376  case Qt::Key_Down:
2377  newCurrent = moveCursor(MoveDown, event->modifiers());
2378  break;
2379  case Qt::Key_Up:
2380  newCurrent = moveCursor(MoveUp, event->modifiers());
2381  break;
2382  case Qt::Key_Left:
2383  newCurrent = moveCursor(MoveLeft, event->modifiers());
2384  break;
2385  case Qt::Key_Right:
2386  newCurrent = moveCursor(MoveRight, event->modifiers());
2387  break;
2388  case Qt::Key_Home:
2389  newCurrent = moveCursor(MoveHome, event->modifiers());
2390  break;
2391  case Qt::Key_End:
2392  newCurrent = moveCursor(MoveEnd, event->modifiers());
2393  break;
2394  case Qt::Key_PageUp:
2395  newCurrent = moveCursor(MovePageUp, event->modifiers());
2396  break;
2397  case Qt::Key_PageDown:
2398  newCurrent = moveCursor(MovePageDown, event->modifiers());
2399  break;
2400  case Qt::Key_Tab:
2401  if (d->tabKeyNavigation)
2402  newCurrent = moveCursor(MoveNext, event->modifiers());
2403  break;
2404  case Qt::Key_Backtab:
2405  if (d->tabKeyNavigation)
2406  newCurrent = moveCursor(MovePrevious, event->modifiers());
2407  break;
2408  }
2409 
2410  QPersistentModelIndex oldCurrent = currentIndex();
2411  if (newCurrent != oldCurrent && newCurrent.isValid() && d->isIndexEnabled(newCurrent)) {
2412  if (!hasFocus() && QApplication::focusWidget() == indexWidget(oldCurrent))
2413  setFocus();
2414  QItemSelectionModel::SelectionFlags command = selectionCommand(newCurrent, event);
2415  if (command != QItemSelectionModel::NoUpdate
2417  // note that we don't check if the new current index is enabled because moveCursor() makes sure it is
2418  if (command & QItemSelectionModel::Current) {
2419  d->selectionModel->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate);
2420  if (!indexAt(d->pressedPosition - d->offset()).isValid())
2421  d->pressedPosition = visualRect(oldCurrent).center() + d->offset();
2422  QRect rect(d->pressedPosition - d->offset(), visualRect(newCurrent).center());
2423  setSelection(rect, command);
2424  } else {
2425  d->selectionModel->setCurrentIndex(newCurrent, command);
2426  d->pressedPosition = visualRect(newCurrent).center() + d->offset();
2427  if (newCurrent.isValid()) {
2428  // We copy the same behaviour as for mousePressEvent().
2429  QRect rect(d->pressedPosition - d->offset(), QSize(1, 1));
2430  setSelection(rect, command);
2431  }
2432  }
2433  event->accept();
2434  return;
2435  }
2436  }
2437 
2438  switch (event->key()) {
2439  // ignored keys
2440  case Qt::Key_Down:
2441  case Qt::Key_Up:
2442 #ifdef QT_KEYPAD_NAVIGATION
2443  if (QApplication::keypadNavigationEnabled() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) {
2444  event->accept(); // don't change focus
2445  break;
2446  }
2447 #endif
2448  case Qt::Key_Left:
2449  case Qt::Key_Right:
2450 #ifdef QT_KEYPAD_NAVIGATION
2451  if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional
2452  && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal)
2453  || (QWidgetPrivate::inTabWidget(this) && d->model->columnCount(d->root) > 1))) {
2454  event->accept(); // don't change focus
2455  break;
2456  }
2457 #endif // QT_KEYPAD_NAVIGATION
2458  case Qt::Key_Home:
2459  case Qt::Key_End:
2460  case Qt::Key_PageUp:
2461  case Qt::Key_PageDown:
2462  case Qt::Key_Escape:
2463  case Qt::Key_Shift:
2464  case Qt::Key_Control:
2465  case Qt::Key_Delete:
2466  case Qt::Key_Backspace:
2467  event->ignore();
2468  break;
2469  case Qt::Key_Space:
2470  case Qt::Key_Select:
2471  if (!edit(currentIndex(), AnyKeyPressed, event) && d->selectionModel)
2472  d->selectionModel->select(currentIndex(), selectionCommand(currentIndex(), event));
2473 #ifdef QT_KEYPAD_NAVIGATION
2474  if ( event->key()==Qt::Key_Select ) {
2475  // Also do Key_Enter action.
2476  if (currentIndex().isValid()) {
2477  if (state() != EditingState)
2479  } else {
2480  event->ignore();
2481  }
2482  }
2483 #endif
2484  break;
2485 #ifdef Q_WS_MAC
2486  case Qt::Key_Enter:
2487  case Qt::Key_Return:
2488  // Propagate the enter if you couldn't edit the item and there are no
2489  // current editors (if there are editors, the event was most likely propagated from it).
2490  if (!edit(currentIndex(), EditKeyPressed, event) && d->editorIndexHash.isEmpty())
2491  event->ignore();
2492  break;
2493 #else
2494  case Qt::Key_F2:
2495  if (!edit(currentIndex(), EditKeyPressed, event))
2496  event->ignore();
2497  break;
2498  case Qt::Key_Enter:
2499  case Qt::Key_Return:
2500  // ### we can't open the editor on enter, becuse
2501  // some widgets will forward the enter event back
2502  // to the viewport, starting an endless loop
2503  if (state() != EditingState || hasFocus()) {
2504  if (currentIndex().isValid())
2506  event->ignore();
2507  }
2508  break;
2509 #endif
2510  case Qt::Key_A:
2511  if (event->modifiers() & Qt::ControlModifier) {
2512  selectAll();
2513  break;
2514  }
2515  default: {
2516 #ifdef Q_WS_MAC
2517  if (event->key() == Qt::Key_O && event->modifiers() & Qt::ControlModifier && currentIndex().isValid()) {
2519  break;
2520  }
2521 #endif
2522  bool modified = (event->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier));
2523  if (!event->text().isEmpty() && !modified && !edit(currentIndex(), AnyKeyPressed, event)) {
2524  keyboardSearch(event->text());
2525  event->accept();
2526  } else {
2527  event->ignore();
2528  }
2529  break; }
2530  }
2531  if (d->moveCursorUpdatedView)
2532  event->accept();
2533 }
2534 
2542 {
2544  updateGeometries();
2545 }
2546 
2554 {
2556  if (event->timerId() == d->fetchMoreTimer.timerId())
2557  d->fetchMore();
2558  else if (event->timerId() == d->delayedReset.timerId())
2559  reset();
2560  else if (event->timerId() == d->autoScrollTimer.timerId())
2561  doAutoScroll();
2562  else if (event->timerId() == d->updateTimer.timerId())
2563  d->updateDirtyRegion();
2564  else if (event->timerId() == d->delayedEditing.timerId()) {
2565  d->delayedEditing.stop();
2566  edit(currentIndex());
2567  } else if (event->timerId() == d->delayedLayout.timerId()) {
2568  d->delayedLayout.stop();
2569  if (isVisible()) {
2570  d->interruptDelayedItemsLayout();
2571  doItemsLayout();
2572  const QModelIndex current = currentIndex();
2573  if (current.isValid() && d->state == QAbstractItemView::EditingState)
2574  scrollTo(current);
2575  }
2576  } else if (event->timerId() == d->delayedAutoScroll.timerId()) {
2577  d->delayedAutoScroll.stop();
2578  //end of the timer: if the current item is still the same as the one when the mouse press occurred
2579  //we only get here if there was no double click
2580  if (d->pressedIndex.isValid() && d->pressedIndex == currentIndex())
2581  scrollTo(d->pressedIndex);
2582  }
2583 }
2584 
2589 {
2590  if (event->commitString().isEmpty() && event->preeditString().isEmpty()) {
2591  event->ignore();
2592  return;
2593  }
2594  if (!edit(currentIndex(), AnyKeyPressed, event)) {
2595  if (!event->commitString().isEmpty())
2596  keyboardSearch(event->commitString());
2597  event->ignore();
2598  }
2599 }
2600 
2601 #ifndef QT_NO_DRAGANDDROP
2602 
2632 {
2633  Q_D(const QAbstractItemView);
2634  return d->dropIndicatorPosition;
2635 }
2636 #endif
2637 
2646 {
2647  Q_D(const QAbstractItemView);
2648  QModelIndexList indexes;
2649  if (d->selectionModel) {
2650  indexes = d->selectionModel->selectedIndexes();
2652  while (it != indexes.end())
2653  if (isIndexHidden(*it))
2654  it = indexes.erase(it);
2655  else
2656  ++it;
2657  }
2658  return indexes;
2659 }
2660 
2675 {
2677 
2678  if (!d->isIndexValid(index))
2679  return false;
2680 
2681  if (QWidget *w = (d->persistent.isEmpty() ? static_cast<QWidget*>(0) : d->editorForIndex(index).widget.data())) {
2682  if (w->focusPolicy() == Qt::NoFocus)
2683  return false;
2684  w->setFocus();
2685  return true;
2686  }
2687 
2688  if (trigger == DoubleClicked) {
2689  d->delayedEditing.stop();
2690  d->delayedAutoScroll.stop();
2691  } else if (trigger == CurrentChanged) {
2692  d->delayedEditing.stop();
2693  }
2694 
2695  if (d->sendDelegateEvent(index, event)) {
2696  update(index);
2697  return true;
2698  }
2699 
2700  // save the previous trigger before updating
2701  EditTriggers lastTrigger = d->lastTrigger;
2702  d->lastTrigger = trigger;
2703 
2704  if (!d->shouldEdit(trigger, d->model->buddy(index)))
2705  return false;
2706 
2707  if (d->delayedEditing.isActive())
2708  return false;
2709 
2710  // we will receive a mouseButtonReleaseEvent after a
2711  // mouseDoubleClickEvent, so we need to check the previous trigger
2712  if (lastTrigger == DoubleClicked && trigger == SelectedClicked)
2713  return false;
2714 
2715  // we may get a double click event later
2716  if (trigger == SelectedClicked)
2717  d->delayedEditing.start(QApplication::doubleClickInterval(), this);
2718  else
2719  d->openEditor(index, d->shouldForwardEvent(trigger, event) ? event : 0);
2720 
2721  return true;
2722 }
2723 
2732 {
2734  d->updateEditorData(QModelIndex(), QModelIndex());
2735 }
2736 
2745 {
2747  if(d->editorIndexHash.isEmpty())
2748  return;
2749  QStyleOptionViewItemV4 option = d->viewOptionsV4();
2750  QEditorIndexHash::iterator it = d->editorIndexHash.begin();
2751  QWidgetList editorsToRelease;
2752  QWidgetList editorsToHide;
2753  while (it != d->editorIndexHash.end()) {
2754  QModelIndex index = it.value();
2755  QWidget *editor = it.key();
2756  if (index.isValid() && editor) {
2757  option.rect = visualRect(index);
2758  if (option.rect.isValid()) {
2759  editor->show();
2760  QAbstractItemDelegate *delegate = d->delegateForIndex(index);
2761  if (delegate)
2762  delegate->updateEditorGeometry(editor, option, index);
2763  } else {
2764  editorsToHide << editor;
2765  }
2766  ++it;
2767  } else {
2768  d->indexEditorHash.remove(it.value());
2769  it = d->editorIndexHash.erase(it);
2770  editorsToRelease << editor;
2771  }
2772  }
2773 
2774  //we hide and release the editor outside of the loop because it might change the focus and try
2775  //to change the editors hashes.
2776  for (int i = 0; i < editorsToHide.count(); ++i) {
2777  editorsToHide.at(i)->hide();
2778  }
2779  for (int i = 0; i < editorsToRelease.count(); ++i) {
2780  d->releaseEditor(editorsToRelease.at(i));
2781  }
2782 }
2783 
2793 {
2795  d_func()->fetchMoreTimer.start(0, this); //fetch more later
2796 }
2797 
2802 {
2804  if (verticalScrollBar()->maximum() == value && d->model->canFetchMore(d->root))
2805  d->model->fetchMore(d->root);
2806  QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos());
2807  if (viewport()->rect().contains(posInVp))
2808  d->checkMouseMove(posInVp);
2809 }
2810 
2815 {
2817  if (horizontalScrollBar()->maximum() == value && d->model->canFetchMore(d->root))
2818  d->model->fetchMore(d->root);
2819  QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos());
2820  if (viewport()->rect().contains(posInVp))
2821  d->checkMouseMove(posInVp);
2822 }
2823 
2828 {
2829  //do nothing
2830 }
2831 
2836 {
2837  //do nothing
2838 }
2839 
2850 {
2852 
2853  // Close the editor
2854  if (editor) {
2855  bool isPersistent = d->persistent.contains(editor);
2856  bool hadFocus = editor->hasFocus();
2857  QModelIndex index = d->indexForEditor(editor);
2858  if (!index.isValid())
2859  return; // the editor was not registered
2860 
2861  if (!isPersistent) {
2862  setState(NoState);
2863  QModelIndex index = d->indexForEditor(editor);
2864  editor->removeEventFilter(d->delegateForIndex(index));
2865  d->removeEditor(editor);
2866  }
2867  if (hadFocus)
2868  setFocus(); // this will send a focusLost event to the editor
2869  else
2870  d->checkPersistentEditorFocus();
2871 
2872  QPointer<QWidget> ed = editor;
2873  QApplication::sendPostedEvents(editor, 0);
2874  editor = ed;
2875 
2876  if (!isPersistent && editor)
2877  d->releaseEditor(editor);
2878  }
2879 
2880  // The EndEditHint part
2881  QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::ClearAndSelect
2882  | d->selectionBehaviorFlags();
2883  switch (hint) {
2886  if (index.isValid()) {
2887  QPersistentModelIndex persistent(index);
2888  d->selectionModel->setCurrentIndex(persistent, flags);
2889  // currentChanged signal would have already started editing
2890  if (index.flags() & Qt::ItemIsEditable
2892  edit(persistent);
2893  } break; }
2896  if (index.isValid()) {
2897  QPersistentModelIndex persistent(index);
2898  d->selectionModel->setCurrentIndex(persistent, flags);
2899  // currentChanged signal would have already started editing
2900  if (index.flags() & Qt::ItemIsEditable
2902  edit(persistent);
2903  } break; }
2905  d->model->submit();
2906  break;
2908  d->model->revert();
2909  break;
2910  default:
2911  break;
2912  }
2913 }
2914 
2921 {
2923  if (!editor || !d->itemDelegate || d->currentlyCommittingEditor)
2924  return;
2925  QModelIndex index = d->indexForEditor(editor);
2926  if (!index.isValid())
2927  return;
2928  d->currentlyCommittingEditor = editor;
2929  QAbstractItemDelegate *delegate = d->delegateForIndex(index);
2930  editor->removeEventFilter(delegate);
2931  delegate->setModelData(editor, d->model, index);
2932  editor->installEventFilter(delegate);
2933  d->currentlyCommittingEditor = 0;
2934 }
2935 
2942 {
2944  QWidget *w = qobject_cast<QWidget*>(editor);
2945  d->removeEditor(w);
2946  d->persistent.remove(w);
2947  if (state() == EditingState)
2948  setState(NoState);
2949 }
2950 
2967 {
2968  Q_UNUSED(steps)
2969  // do nothing
2970 }
2971 
2982 {
2983  return 1;
2984 }
2985 
3002 {
3003  Q_UNUSED(steps)
3004  // do nothing
3005 }
3006 
3017 {
3018  return 1;
3019 }
3020 
3030 {
3032  if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root))
3033  return;
3034 
3036  : d->model->index(0, 0, d->root);
3037  bool skipRow = false;
3038  bool keyboardTimeWasValid = d->keyboardInputTime.isValid();
3039  qint64 keyboardInputTimeElapsed = d->keyboardInputTime.restart();
3040  if (search.isEmpty() || !keyboardTimeWasValid
3041  || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) {
3042  d->keyboardInput = search;
3043  skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0)
3044  } else {
3045  d->keyboardInput += search;
3046  }
3047 
3048  // special case for searches with same key like 'aaaaa'
3049  bool sameKey = false;
3050  if (d->keyboardInput.length() > 1) {
3051  int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.length() - 1));
3052  sameKey = (c == d->keyboardInput.length());
3053  if (sameKey)
3054  skipRow = true;
3055  }
3056 
3057  // skip if we are searching for the same key or a new search started
3058  if (skipRow) {
3059  QModelIndex parent = start.parent();
3060  int newRow = (start.row() < d->model->rowCount(parent) - 1) ? start.row() + 1 : 0;
3061  start = d->model->index(newRow, start.column(), parent);
3062  }
3063 
3064  // search from start with wraparound
3065  const QString searchString = sameKey ? QString(d->keyboardInput.at(0)) : d->keyboardInput;
3066  QModelIndex current = start;
3068  QModelIndex firstMatch;
3069  QModelIndex startMatch;
3070  QModelIndexList previous;
3071  do {
3072  match = d->model->match(current, Qt::DisplayRole, searchString);
3073  if (match == previous)
3074  break;
3075  firstMatch = match.value(0);
3076  previous = match;
3077  if (firstMatch.isValid()) {
3078  if (d->isIndexEnabled(firstMatch)) {
3079  setCurrentIndex(firstMatch);
3080  break;
3081  }
3082  int row = firstMatch.row() + 1;
3083  if (row >= d->model->rowCount(firstMatch.parent()))
3084  row = 0;
3085  current = firstMatch.sibling(row, firstMatch.column());
3086 
3087  //avoid infinite loop if all the matching items are disabled.
3088  if (!startMatch.isValid())
3089  startMatch = firstMatch;
3090  else if (startMatch == firstMatch)
3091  break;
3092  }
3093  } while (current != start && firstMatch.isValid());
3094 }
3095 
3103 {
3104  Q_D(const QAbstractItemView);
3105  if (!d->isIndexValid(index) || !d->itemDelegate)
3106  return QSize();
3107  return d->delegateForIndex(index)->sizeHint(d->viewOptionsV4(), index);
3108 }
3109 
3127 {
3128  Q_D(const QAbstractItemView);
3129 
3130  if (row < 0 || row >= d->model->rowCount(d->root))
3131  return -1;
3132 
3133  ensurePolished();
3134 
3135  QStyleOptionViewItemV4 option = d->viewOptionsV4();
3136  int height = 0;
3137  int colCount = d->model->columnCount(d->root);
3139  for (int c = 0; c < colCount; ++c) {
3140  index = d->model->index(row, c, d->root);
3141  if (QWidget *editor = d->editorForIndex(index).widget.data())
3142  height = qMax(height, editor->height());
3143  int hint = d->delegateForIndex(index)->sizeHint(option, index).height();
3144  height = qMax(height, hint);
3145  }
3146  return height;
3147 }
3148 
3158 {
3159  Q_D(const QAbstractItemView);
3160 
3161  if (column < 0 || column >= d->model->columnCount(d->root))
3162  return -1;
3163 
3164  ensurePolished();
3165 
3166  QStyleOptionViewItemV4 option = d->viewOptionsV4();
3167  int width = 0;
3168  int rows = d->model->rowCount(d->root);
3170  for (int r = 0; r < rows; ++r) {
3171  index = d->model->index(r, column, d->root);
3172  if (QWidget *editor = d->editorForIndex(index).widget.data())
3173  width = qMax(width, editor->sizeHint().width());
3174  int hint = d->delegateForIndex(index)->sizeHint(option, index).width();
3175  width = qMax(width, hint);
3176  }
3177  return width;
3178 }
3179 
3187 {
3189  QStyleOptionViewItemV4 options = d->viewOptionsV4();
3190  options.rect = visualRect(index);
3191  options.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
3192 
3193  QWidget *editor = d->editor(index, options);
3194  if (editor) {
3195  editor->show();
3196  d->persistent.insert(editor);
3197  }
3198 }
3199 
3206 {
3208  if (QWidget *editor = d->editorForIndex(index).widget.data()) {
3209  if (index == selectionModel()->currentIndex())
3211  d->persistent.remove(editor);
3212  d->removeEditor(editor);
3213  d->releaseEditor(editor);
3214  }
3215 }
3216 
3247 {
3249  if (!d->isIndexValid(index))
3250  return;
3251  if (QWidget *oldWidget = indexWidget(index)) {
3252  d->persistent.remove(oldWidget);
3253  d->removeEditor(oldWidget);
3254  oldWidget->deleteLater();
3255  }
3256  if (widget) {
3257  widget->setParent(viewport());
3258  d->persistent.insert(widget);
3259  d->addEditor(index, widget, true);
3260  widget->show();
3261  dataChanged(index, index); // update the geometry
3262  if (!d->delayedPendingLayout)
3263  widget->setGeometry(visualRect(index));
3264  }
3265 }
3266 
3276 {
3277  Q_D(const QAbstractItemView);
3278  if (d->isIndexValid(index))
3279  if (QWidget *editor = d->editorForIndex(index).widget.data())
3280  return editor;
3281 
3282  return 0;
3283 }
3284 
3296 {
3297  verticalScrollBar()->setValue(verticalScrollBar()->minimum());
3298 }
3299 
3311 {
3313  if (d->delayedPendingLayout) {
3314  d->executePostedLayout();
3315  updateGeometries();
3316  }
3317  verticalScrollBar()->setValue(verticalScrollBar()->maximum());
3318 }
3319 
3330 {
3332  if (index.isValid()) {
3333  const QRect rect = visualRect(index);
3334  //this test is important for peformance reason
3335  //For example in dataChanged we simply update all the cells without checking
3336  //it can be a major bottleneck to update rects that aren't even part of the viewport
3337  if (d->viewport->rect().intersects(rect))
3338  d->viewport->update(rect);
3339  }
3340 }
3341 
3348 void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
3349 {
3350  // Single item changed
3352  if (topLeft == bottomRight && topLeft.isValid()) {
3353  const QEditorInfo &editorInfo = d->editorForIndex(topLeft);
3354  //we don't update the edit data if it is static
3355  if (!editorInfo.isStatic && editorInfo.widget) {
3356  QAbstractItemDelegate *delegate = d->delegateForIndex(topLeft);
3357  if (delegate) {
3358  delegate->setEditorData(editorInfo.widget.data(), topLeft);
3359  }
3360  }
3361  if (isVisible() && !d->delayedPendingLayout) {
3362  // otherwise the items will be update later anyway
3363  update(topLeft);
3364  }
3365  return;
3366  }
3367  d->updateEditorData(topLeft, bottomRight);
3368  if (!isVisible() || d->delayedPendingLayout)
3369  return; // no need to update
3370  d->viewport->update();
3371 }
3372 
3382 {
3383  if (!isVisible())
3384  d_func()->fetchMoreTimer.start(0, this); //fetch more later
3385  else
3387 }
3388 
3396 {
3398 
3400 
3401  // Ensure one selected item in single selection mode.
3402  QModelIndex current = currentIndex();
3403  if (d->selectionMode == SingleSelection
3404  && current.isValid()
3405  && current.row() >= start
3406  && current.row() <= end
3407  && current.parent() == parent) {
3408  int totalToRemove = end - start + 1;
3409  if (d->model->rowCount(parent) <= totalToRemove) { // no more children
3411  while (index != d->root && !d->isIndexEnabled(index))
3412  index = index.parent();
3413  if (index != d->root)
3414  setCurrentIndex(index);
3415  } else {
3416  int row = end + 1;
3417  QModelIndex next;
3418  do { // find the next visible and enabled item
3419  next = d->model->index(row++, current.column(), current.parent());
3420  } while (next.isValid() && (isIndexHidden(next) || !d->isIndexEnabled(next)));
3421  if (row > d->model->rowCount(parent)) {
3422  row = start - 1;
3423  do { // find the previous visible and enabled item
3424  next = d->model->index(row--, current.column(), current.parent());
3425  } while (next.isValid() && (isIndexHidden(next) || !d->isIndexEnabled(next)));
3426  }
3427  setCurrentIndex(next);
3428  }
3429  }
3430 
3431  // Remove all affected editors; this is more efficient than waiting for updateGeometries() to clean out editors for invalid indexes
3432  QEditorIndexHash::iterator i = d->editorIndexHash.begin();
3433  while (i != d->editorIndexHash.end()) {
3434  const QModelIndex index = i.value();
3435  if (index.row() >= start && index.row() <= end && d->model->parent(index) == parent) {
3436  QWidget *editor = i.key();
3437  QEditorInfo info = d->indexEditorHash.take(index);
3438  i = d->editorIndexHash.erase(i);
3439  if (info.widget)
3440  d->releaseEditor(editor);
3441  } else {
3442  ++i;
3443  }
3444  }
3445 }
3446 
3458 {
3459  Q_UNUSED(index)
3460  Q_UNUSED(start)
3461  Q_UNUSED(end)
3462 
3464  if (q->isVisible())
3465  q->updateEditorGeometries();
3466  q->setState(QAbstractItemView::NoState);
3467 #ifndef QT_NO_ACCESSIBILITY
3468 #ifdef Q_WS_X11
3469  if (QAccessible::isActive()) {
3472  }
3473 #endif
3474 #endif
3475 }
3476 
3488 {
3490 
3492 
3493  // Ensure one selected item in single selection mode.
3494  QModelIndex current = q->currentIndex();
3495  if (current.isValid()
3497  && current.column() >= start
3498  && current.column() <= end) {
3499  int totalToRemove = end - start + 1;
3500  if (model->columnCount(parent) < totalToRemove) { // no more columns
3502  while (index.isValid() && !isIndexEnabled(index))
3503  index = index.parent();
3504  if (index.isValid())
3505  q->setCurrentIndex(index);
3506  } else {
3507  int column = end;
3508  QModelIndex next;
3509  do { // find the next visible and enabled item
3510  next = model->index(current.row(), column++, current.parent());
3511  } while (next.isValid() && (q->isIndexHidden(next) || !isIndexEnabled(next)));
3512  q->setCurrentIndex(next);
3513  }
3514  }
3515 
3516  // Remove all affected editors; this is more efficient than waiting for updateGeometries() to clean out editors for invalid indexes
3517  QEditorIndexHash::iterator it = editorIndexHash.begin();
3518  while (it != editorIndexHash.end()) {
3519  QModelIndex index = it.value();
3520  if (index.column() <= start && index.column() >= end && model->parent(index) == parent) {
3521  QWidget *editor = it.key();
3522  QEditorInfo info = indexEditorHash.take(it.value());
3523  it = editorIndexHash.erase(it);
3524  if (info.widget)
3525  releaseEditor(editor);
3526  } else {
3527  ++it;
3528  }
3529  }
3530 
3531 }
3532 
3544 {
3545  Q_UNUSED(index)
3546  Q_UNUSED(start)
3547  Q_UNUSED(end)
3548 
3550  if (q->isVisible())
3551  q->updateEditorGeometries();
3552  q->setState(QAbstractItemView::NoState);
3553 #ifndef QT_NO_ACCESSIBILITY
3554 #ifdef Q_WS_X11
3555  if (QAccessible::isActive()) {
3558  }
3559 #endif
3560 #endif
3561 }
3562 
3563 
3573 {
3574  Q_UNUSED(index)
3575  Q_UNUSED(start)
3576  Q_UNUSED(end)
3577 
3578 #ifndef QT_NO_ACCESSIBILITY
3579 #ifdef Q_WS_X11
3581  if (QAccessible::isActive()) {
3584  }
3585 #endif
3586 #endif
3587 }
3588 
3598 {
3599  Q_UNUSED(index)
3600  Q_UNUSED(start)
3601  Q_UNUSED(end)
3602 
3604  if (q->isVisible())
3605  q->updateEditorGeometries();
3606 #ifndef QT_NO_ACCESSIBILITY
3607 #ifdef Q_WS_X11
3608  if (QAccessible::isActive()) {
3611  }
3612 #endif
3613 #endif
3614 }
3615 
3620 {
3622  doDelayedReset();
3623 }
3624 
3634 {
3635  doDelayedItemsLayout();
3636 #ifndef QT_NO_ACCESSIBILITY
3637 #ifdef Q_WS_X11
3639  if (QAccessible::isActive()) {
3642  }
3643 #endif
3644 #endif
3645 }
3646 
3655  const QItemSelection &deselected)
3656 {
3658  if (isVisible() && updatesEnabled()) {
3659  d->viewport->update(visualRegionForSelection(deselected) | visualRegionForSelection(selected));
3660  }
3661 }
3662 
3671 void QAbstractItemView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
3672 {
3674  Q_ASSERT(d->model);
3675 
3676  if (previous.isValid()) {
3677  QModelIndex buddy = d->model->buddy(previous);
3678  QWidget *editor = d->editorForIndex(buddy).widget.data();
3679  if (editor && !d->persistent.contains(editor)) {
3680  commitData(editor);
3681  if (current.row() != previous.row())
3683  else
3685  }
3686  if (isVisible()) {
3687  update(previous);
3688  }
3689  }
3690 
3691  if (current.isValid() && !d->autoScrollTimer.isActive()) {
3692  if (isVisible()) {
3693  if (d->autoScroll)
3694  scrollTo(current);
3695  update(current);
3696  edit(current, CurrentChanged, 0);
3697  if (current.row() == (d->model->rowCount(d->root) - 1))
3698  d->fetchMore();
3699  } else {
3700  d->shouldScrollToCurrentOnShow = d->autoScroll;
3701  }
3702  }
3703 }
3704 
3705 #ifndef QT_NO_DRAGANDDROP
3706 
3709 void QAbstractItemView::startDrag(Qt::DropActions supportedActions)
3710 {
3712  QModelIndexList indexes = d->selectedDraggableIndexes();
3713  if (indexes.count() > 0) {
3714  QMimeData *data = d->model->mimeData(indexes);
3715  if (!data)
3716  return;
3717  QRect rect;
3718  QPixmap pixmap = d->renderToPixmap(indexes, &rect);
3719  rect.adjust(horizontalOffset(), verticalOffset(), 0, 0);
3720  QDrag *drag = new QDrag(this);
3721  drag->setPixmap(pixmap);
3722  drag->setMimeData(data);
3723  drag->setHotSpot(d->pressedPosition - rect.topLeft());
3725  if (d->defaultDropAction != Qt::IgnoreAction && (supportedActions & d->defaultDropAction))
3726  defaultDropAction = d->defaultDropAction;
3727  else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)
3728  defaultDropAction = Qt::CopyAction;
3729  if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction)
3730  d->clearOrRemove();
3731  }
3732 }
3733 #endif // QT_NO_DRAGANDDROP
3734 
3740 {
3741  Q_D(const QAbstractItemView);
3742  QStyleOptionViewItem option;
3743  option.init(this);
3744  option.state &= ~QStyle::State_MouseOver;
3745  option.font = font();
3746 
3747 #ifndef Q_WS_MAC
3748  // On mac the focus appearance follows window activation
3749  // not widget activation
3750  if (!hasFocus())
3751  option.state &= ~QStyle::State_Active;
3752 #endif
3753 
3754  option.state &= ~QStyle::State_HasFocus;
3755  if (d->iconSize.isValid()) {
3756  option.decorationSize = d->iconSize;
3757  } else {
3758  int pm = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
3759  option.decorationSize = QSize(pm, pm);
3760  }
3764  option.textElideMode = d->textElideMode;
3765  option.rect = QRect();
3767  return option;
3768 }
3769 
3771 {
3772  Q_Q(const QAbstractItemView);
3773  QStyleOptionViewItemV4 option = q->viewOptions();
3774  if (wrapItemText)
3776  option.locale = q->locale();
3778  option.widget = q;
3779  return option;
3780 }
3781 
3788 {
3789  Q_D(const QAbstractItemView);
3790  return d->state;
3791 }
3792 
3799 {
3801  d->state = state;
3802 }
3803 
3814 {
3816  d->doDelayedItemsLayout();
3817 }
3818 
3826 {
3828  d->executePostedLayout();
3829 }
3830 
3845 {
3847  d->setDirtyRegion(region);
3848 }
3849 
3861 {
3863  d->scrollDirtyRegion(dx, dy);
3864 }
3865 
3876 {
3877  Q_D(const QAbstractItemView);
3878  return d->scrollDelayOffset;
3879 }
3880 
3885 {
3886  d_func()->startAutoScroll();
3887 }
3888 
3893 {
3894  d_func()->stopAutoScroll();
3895 }
3896 
3901 {
3902  // find how much we should scroll with
3904  int verticalStep = verticalScrollBar()->pageStep();
3905  int horizontalStep = horizontalScrollBar()->pageStep();
3906  if (d->autoScrollCount < qMax(verticalStep, horizontalStep))
3907  ++d->autoScrollCount;
3908 
3909  int margin = d->autoScrollMargin;
3910  int verticalValue = verticalScrollBar()->value();
3911  int horizontalValue = horizontalScrollBar()->value();
3912 
3913  QPoint pos = d->viewport->mapFromGlobal(QCursor::pos());
3914  QRect area = static_cast<QAbstractItemView*>(d->viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules
3915 
3916  // do the scrolling if we are in the scroll margins
3917  if (pos.y() - area.top() < margin)
3918  verticalScrollBar()->setValue(verticalValue - d->autoScrollCount);
3919  else if (area.bottom() - pos.y() < margin)
3920  verticalScrollBar()->setValue(verticalValue + d->autoScrollCount);
3921  if (pos.x() - area.left() < margin)
3922  horizontalScrollBar()->setValue(horizontalValue - d->autoScrollCount);
3923  else if (area.right() - pos.x() < margin)
3924  horizontalScrollBar()->setValue(horizontalValue + d->autoScrollCount);
3925  // if nothing changed, stop scrolling
3926  bool verticalUnchanged = (verticalValue == verticalScrollBar()->value());
3927  bool horizontalUnchanged = (horizontalValue == horizontalScrollBar()->value());
3928  if (verticalUnchanged && horizontalUnchanged) {
3929  stopAutoScroll();
3930  } else {
3931 #ifndef QT_NO_DRAGANDDROP
3932  d->dropIndicatorRect = QRect();
3933  d->dropIndicatorPosition = QAbstractItemView::OnViewport;
3934 #endif
3935  d->viewport->update();
3936  }
3937 }
3938 
3948 QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand(const QModelIndex &index,
3949  const QEvent *event) const
3950 {
3951  Q_D(const QAbstractItemView);
3952  switch (d->selectionMode) {
3953  case NoSelection: // Never update selection model
3955  case SingleSelection: // ClearAndSelect on valid index otherwise NoUpdate
3956  if (event && event->type() == QEvent::MouseButtonRelease)
3958  return QItemSelectionModel::ClearAndSelect|d->selectionBehaviorFlags();
3959  case MultiSelection:
3960  return d->multiSelectionCommand(index, event);
3961  case ExtendedSelection:
3962  return d->extendedSelectionCommand(index, event);
3963  case ContiguousSelection:
3964  return d->contiguousSelectionCommand(index, event);
3965  }
3967 }
3968 
3969 QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::multiSelectionCommand(
3970  const QModelIndex &index, const QEvent *event) const
3971 {
3972  Q_UNUSED(index)
3973 
3974  if (event) {
3975  switch (event->type()) {
3976  case QEvent::KeyPress:
3977  if (static_cast<const QKeyEvent*>(event)->key() == Qt::Key_Space
3978  || static_cast<const QKeyEvent*>(event)->key() == Qt::Key_Select)
3979  return QItemSelectionModel::Toggle|selectionBehaviorFlags();
3980  break;
3982  if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton)
3983  return QItemSelectionModel::Toggle|selectionBehaviorFlags(); // toggle
3984  break;
3986  if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton)
3987  return QItemSelectionModel::NoUpdate|selectionBehaviorFlags(); // finalize
3988  break;
3989  case QEvent::MouseMove:
3990  if (static_cast<const QMouseEvent*>(event)->buttons() & Qt::LeftButton)
3991  return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); // toggle drag select
3992  default:
3993  break;
3994  }
3996  }
3997 
3998  return QItemSelectionModel::Toggle|selectionBehaviorFlags();
3999 }
4000 
4001 QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::extendedSelectionCommand(
4002  const QModelIndex &index, const QEvent *event) const
4003 {
4004  Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
4005  if (event) {
4006  switch (event->type()) {
4007  case QEvent::MouseMove: {
4008  // Toggle on MouseMove
4009  modifiers = static_cast<const QMouseEvent*>(event)->modifiers();
4010  if (modifiers & Qt::ControlModifier)
4011  return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags();
4012  break;
4013  }
4014  case QEvent::MouseButtonPress: {
4015  modifiers = static_cast<const QMouseEvent*>(event)->modifiers();
4016  const Qt::MouseButton button = static_cast<const QMouseEvent*>(event)->button();
4017  const bool rightButtonPressed = button & Qt::RightButton;
4018  const bool shiftKeyPressed = modifiers & Qt::ShiftModifier;
4019  const bool controlKeyPressed = modifiers & Qt::ControlModifier;
4020  const bool indexIsSelected = selectionModel->isSelected(index);
4021  if ((shiftKeyPressed || controlKeyPressed) && rightButtonPressed)
4023  if (!shiftKeyPressed && !controlKeyPressed && indexIsSelected)
4025  if (!index.isValid() && !rightButtonPressed && !shiftKeyPressed && !controlKeyPressed)
4027  if (!index.isValid())
4029  break;
4030  }
4032  // ClearAndSelect on MouseButtonRelease if MouseButtonPress on selected item or empty area
4033  modifiers = static_cast<const QMouseEvent*>(event)->modifiers();
4034  const Qt::MouseButton button = static_cast<const QMouseEvent*>(event)->button();
4035  const bool rightButtonPressed = button & Qt::RightButton;
4036  const bool shiftKeyPressed = modifiers & Qt::ShiftModifier;
4037  const bool controlKeyPressed = modifiers & Qt::ControlModifier;
4038  if (((index == pressedIndex && selectionModel->isSelected(index))
4040  && !shiftKeyPressed && !controlKeyPressed && (!rightButtonPressed || !index.isValid()))
4041  return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags();
4043  }
4044  case QEvent::KeyPress: {
4045  // NoUpdate on Key movement and Ctrl
4046  modifiers = static_cast<const QKeyEvent*>(event)->modifiers();
4047  switch (static_cast<const QKeyEvent*>(event)->key()) {
4048  case Qt::Key_Backtab:
4049  modifiers = modifiers & ~Qt::ShiftModifier; // special case for backtab
4050  case Qt::Key_Down:
4051  case Qt::Key_Up:
4052  case Qt::Key_Left:
4053  case Qt::Key_Right:
4054  case Qt::Key_Home:
4055  case Qt::Key_End:
4056  case Qt::Key_PageUp:
4057  case Qt::Key_PageDown:
4058  case Qt::Key_Tab:
4059  if (modifiers & Qt::ControlModifier
4060 #ifdef QT_KEYPAD_NAVIGATION
4061  // Preserve historical tab order navigation behavior
4062  || QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
4063 #endif
4064  )
4066  break;
4067  case Qt::Key_Select:
4068  return QItemSelectionModel::Toggle|selectionBehaviorFlags();
4069  case Qt::Key_Space:// Toggle on Ctrl-Qt::Key_Space, Select on Space
4070  if (modifiers & Qt::ControlModifier)
4071  return QItemSelectionModel::Toggle|selectionBehaviorFlags();
4072  return QItemSelectionModel::Select|selectionBehaviorFlags();
4073  default:
4074  break;
4075  }
4076  }
4077  default:
4078  break;
4079  }
4080  }
4081 
4082  if (modifiers & Qt::ShiftModifier)
4083  return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags();
4084  if (modifiers & Qt::ControlModifier)
4085  return QItemSelectionModel::Toggle|selectionBehaviorFlags();
4087  //when drag-selecting we need to clear any previous selection and select the current one
4088  return QItemSelectionModel::Clear|QItemSelectionModel::SelectCurrent|selectionBehaviorFlags();
4089  }
4090 
4091  return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags();
4092 }
4093 
4094 QItemSelectionModel::SelectionFlags
4096  const QEvent *event) const
4097 {
4098  QItemSelectionModel::SelectionFlags flags = extendedSelectionCommand(index, event);
4102 
4103  switch (flags & Mask) {
4107  return flags;
4109  if (event &&
4110  (event->type() == QEvent::MouseButtonPress
4111  || event->type() == QEvent::MouseButtonRelease))
4112  return flags;
4113  return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags();
4114  default:
4115  return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags();
4116  }
4117 }
4118 
4120 {
4121  fetchMoreTimer.stop();
4122  if (!model->canFetchMore(root))
4123  return;
4124  int last = model->rowCount(root) - 1;
4125  if (last < 0) {
4126  model->fetchMore(root);
4127  return;
4128  }
4129 
4130  QModelIndex index = model->index(last, 0, root);
4131  QRect rect = q_func()->visualRect(index);
4132  if (viewport->rect().intersects(rect))
4133  model->fetchMore(root);
4134 }
4135 
4137  const QModelIndex &index) const
4138 {
4139  if (!index.isValid())
4140  return false;
4141  Qt::ItemFlags flags = model->flags(index);
4142  if (((flags & Qt::ItemIsEditable) == 0) || ((flags & Qt::ItemIsEnabled) == 0))
4143  return false;
4145  return false;
4146  if (hasEditor(index))
4147  return false;
4148  if (trigger == QAbstractItemView::AllEditTriggers) // force editing
4149  return true;
4151  && !selectionModel->isSelected(index))
4152  return false;
4153  return (trigger & editTriggers);
4154 }
4155 
4157  const QEvent *event) const
4158 {
4159  if (!event || (trigger & editTriggers) != QAbstractItemView::AnyKeyPressed)
4160  return false;
4161 
4162  switch (event->type()) {
4163  case QEvent::KeyPress:
4167  case QEvent::MouseMove:
4168  return true;
4169  default:
4170  break;
4171  };
4172 
4173  return false;
4174 }
4175 
4177 {
4178  if (!autoScroll)
4179  return false;
4180  QRect area = static_cast<QAbstractItemView*>(viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules
4181  return (pos.y() - area.top() < autoScrollMargin)
4182  || (area.bottom() - pos.y() < autoScrollMargin)
4183  || (pos.x() - area.left() < autoScrollMargin)
4184  || (area.right() - pos.x() < autoScrollMargin);
4185 }
4186 
4188 {
4189  if (!delayedPendingLayout) {
4190  delayedPendingLayout = true;
4191  delayedLayout.start(delay, q_func());
4192  }
4193 }
4194 
4196 {
4197  delayedLayout.stop();
4198  delayedPendingLayout = false;
4199 }
4200 
4201 
4202 
4204  const QStyleOptionViewItem &options)
4205 {
4207  QWidget *w = editorForIndex(index).widget.data();
4208  if (!w) {
4209  QAbstractItemDelegate *delegate = delegateForIndex(index);
4210  if (!delegate)
4211  return 0;
4212  w = delegate->createEditor(viewport, options, index);
4213  if (w) {
4214  w->installEventFilter(delegate);
4216  delegate->updateEditorGeometry(w, options, index);
4217  delegate->setEditorData(w, index);
4218  addEditor(index, w, false);
4219  if (w->parent() == viewport)
4220  QWidget::setTabOrder(q, w);
4221 
4222  // Special cases for some editors containing QLineEdit
4223  QWidget *focusWidget = w;
4224  while (QWidget *fp = focusWidget->focusProxy())
4225  focusWidget = fp;
4226 #ifndef QT_NO_LINEEDIT
4227  if (QLineEdit *le = qobject_cast<QLineEdit*>(focusWidget))
4228  le->selectAll();
4229 #endif
4230 #ifndef QT_NO_SPINBOX
4231  if (QSpinBox *sb = qobject_cast<QSpinBox*>(focusWidget))
4232  sb->selectAll();
4233  else if (QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox*>(focusWidget))
4234  dsb->selectAll();
4235 #endif
4236  }
4237  }
4238 
4239  return w;
4240 }
4241 
4243 {
4244  // we are counting on having relatively few editors
4245  const bool checkIndexes = tl.isValid() && br.isValid();
4246  const QModelIndex parent = tl.parent();
4247  QIndexEditorHash::const_iterator it = indexEditorHash.constBegin();
4248  for (; it != indexEditorHash.constEnd(); ++it) {
4249  QWidget *editor = it.value().widget.data();
4250  const QModelIndex index = it.key();
4251  if (it.value().isStatic || !editor || !index.isValid() ||
4252  (checkIndexes
4253  && (index.row() < tl.row() || index.row() > br.row()
4254  || index.column() < tl.column() || index.column() > br.column()
4255  || index.parent() != parent)))
4256  continue;
4257 
4258  QAbstractItemDelegate *delegate = delegateForIndex(index);
4259  if (delegate) {
4260  delegate->setEditorData(editor, index);
4261  }
4262  }
4263 }
4264 
4278 {
4279 #ifndef QT_NO_DRAGANDDROP
4280  const QItemSelection selection = selectionModel->selection();
4282 
4283  if (!overwrite) {
4284  for (; it != selection.constEnd(); ++it) {
4285  QModelIndex parent = (*it).parent();
4286  if ((*it).left() != 0)
4287  continue;
4288  if ((*it).right() != (model->columnCount(parent) - 1))
4289  continue;
4290  int count = (*it).bottom() - (*it).top() + 1;
4291  model->removeRows((*it).top(), count, parent);
4292  }
4293  } else {
4294  // we can't remove the rows so reset the items (i.e. the view is like a table)
4295  QModelIndexList list = selection.indexes();
4296  for (int i=0; i < list.size(); ++i) {
4297  QModelIndex index = list.at(i);
4298  QMap<int, QVariant> roles = model->itemData(index);
4299  for (QMap<int, QVariant>::Iterator it = roles.begin(); it != roles.end(); ++it)
4300  it.value() = QVariant();
4301  model->setItemData(index, roles);
4302  }
4303  }
4304 #endif
4305 }
4306 
4317 {
4320  if (persistent.contains(widget)) {
4321  //a persistent editor has gained the focus
4322  QModelIndex index = indexForEditor(widget);
4323  if (selectionModel->currentIndex() != index)
4324  q->setCurrentIndex(index);
4325  }
4326  }
4327 }
4328 
4329 
4331 {
4332  static QEditorInfo nullInfo;
4333 
4334  // do not try to search to avoid slow implicit cast from QModelIndex to QPersistentModelIndex
4335  if (indexEditorHash.isEmpty())
4336  return nullInfo;
4337 
4338  QIndexEditorHash::const_iterator it = indexEditorHash.find(index);
4339  if (it == indexEditorHash.end())
4340  return nullInfo;
4341 
4342  return it.value();
4343 }
4344 
4346 {
4347  // do not try to search to avoid slow implicit cast from QModelIndex to QPersistentModelIndex
4348  if (indexEditorHash.isEmpty())
4349  return QModelIndex();
4350 
4351  QEditorIndexHash::const_iterator it = editorIndexHash.find(editor);
4352  if (it == editorIndexHash.end())
4353  return QModelIndex();
4354 
4355  return it.value();
4356 }
4357 
4359 {
4360  QEditorIndexHash::iterator it = editorIndexHash.find(editor);
4361  if (it != editorIndexHash.end())
4362  {
4363  indexEditorHash.remove(it.value());
4364  editorIndexHash.erase(it);
4365  }
4366 }
4367 
4368 void QAbstractItemViewPrivate::addEditor(const QModelIndex &index, QWidget *editor, bool isStatic)
4369 {
4370  editorIndexHash.insert(editor, index);
4371  indexEditorHash.insert(index, QEditorInfo(editor, isStatic));
4372 }
4373 
4375 {
4376  Q_Q(const QAbstractItemView);
4377  QModelIndex buddy = model->buddy(index);
4378  QStyleOptionViewItemV4 options = viewOptionsV4();
4379  options.rect = q->visualRect(buddy);
4380  options.state |= (buddy == q->currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
4381  QAbstractItemDelegate *delegate = delegateForIndex(index);
4382  return (event && delegate && delegate->editorEvent(event, model, options, buddy));
4383 }
4384 
4386 {
4388 
4389  QModelIndex buddy = model->buddy(index);
4390  QStyleOptionViewItemV4 options = viewOptionsV4();
4391  options.rect = q->visualRect(buddy);
4392  options.state |= (buddy == q->currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
4393 
4394  QWidget *w = editor(buddy, options);
4395  if (!w)
4396  return false;
4397 
4398  q->setState(QAbstractItemView::EditingState);
4399  w->show();
4400  w->setFocus();
4401 
4402  if (event)
4404 
4405  return true;
4406 }
4407 
4408 /*
4409  \internal
4410 
4411  returns the pair QRect/QModelIndex that should be painted on the viewports's rect
4412 */
4413 
4415 {
4416  Q_ASSERT(r);
4417  Q_Q(const QAbstractItemView);
4418  QRect &rect = *r;
4419  const QRect viewportRect = viewport->rect();
4420  QItemViewPaintPairs ret;
4421  for (int i = 0; i < indexes.count(); ++i) {
4422  const QModelIndex &index = indexes.at(i);
4423  const QRect current = q->visualRect(index);
4424  if (current.intersects(viewportRect)) {
4425  ret += qMakePair(current, index);
4426  rect |= current;
4427  }
4428  }
4429  rect &= viewportRect;
4430  return ret;
4431 }
4432 
4434 {
4435  Q_ASSERT(r);
4436  QItemViewPaintPairs paintPairs = draggablePaintPairs(indexes, r);
4437  if (paintPairs.isEmpty())
4438  return QPixmap();
4439  QPixmap pixmap(r->size());
4440  pixmap.fill(Qt::transparent);
4441  QPainter painter(&pixmap);
4442  QStyleOptionViewItemV4 option = viewOptionsV4();
4443  option.state |= QStyle::State_Selected;
4444  for (int j = 0; j < paintPairs.count(); ++j) {
4445  option.rect = paintPairs.at(j).first.translated(-r->topLeft());
4446  const QModelIndex &current = paintPairs.at(j).second;
4447  adjustViewOptionsForIndex(&option, current);
4448  delegateForIndex(current)->paint(&painter, option, current);
4449  }
4450  return pixmap;
4451 }
4452 
4453 void QAbstractItemViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command)
4454 {
4455  if (!selectionModel)
4456  return;
4457 
4458  QItemSelection selection;
4459  QModelIndex tl = model->index(0, 0, root);
4460  QModelIndex br = model->index(model->rowCount(root) - 1,
4461  model->columnCount(root) - 1,
4462  root);
4463  selection.append(QItemSelectionRange(tl, br));
4464  selectionModel->select(selection, command);
4465 }
4466 
4468 {
4469  Q_Q(const QAbstractItemView);
4470  QModelIndexList indexes = q->selectedIndexes();
4471  for(int i = indexes.count() - 1 ; i >= 0; --i) {
4472  if (!isIndexDragEnabled(indexes.at(i)))
4473  indexes.removeAt(i);
4474  }
4475  return indexes;
4476 }
4477 
4478 
4480 
4481 #include "moc_qabstractitemview.cpp"
4482 
4483 #endif // QT_NO_ITEMVIEWS
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
SelectionMode
This enum indicates how the view responds to user selections:
QPoint pos() const
static int keyboardInputInterval()
QSize sizeHintForIndex(const QModelIndex &index) const
Returns the size hint for the item with the specified index or an invalid size for invalid indexes...
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QAbstractItemView(QWidget *parent=0)
Constructs an abstract item view with the given parent.
void setItemDelegateForRow(int row, QAbstractItemDelegate *delegate)
Sets the given item delegate used by this view and model for the given row.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
QPersistentModelIndex hover
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when rows are about to be removed.
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
The QAbstractItemDelegate class is used to display and edit data items from a model.
void openPersistentEditor(const QModelIndex &index)
Opens a persistent editor on the item at the given index.
void setSelectionMode(QAbstractItemView::SelectionMode mode)
static QAbstractItemModel * staticEmptyModel()
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition: qwidget.cpp:6863
The QItemSelectionModel class keeps track of a view&#39;s selected items.
virtual void _q_rowsRemoved(const QModelIndex &parent, int start, int end)
This slot is called when rows have been removed.
static QString standardSoftKeyText(StandardSoftKey standardKey)
void scrollToBottom()
Scrolls the view to the bottom.
QFont font
the font used for the item
Definition: qstyleoption.h:552
Qt::Alignment decorationAlignment
the alignment of the decoration for the item
Definition: qstyleoption.h:548
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
virtual QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setPixmap(const QPixmap &)
Sets pixmap as the pixmap used to represent the data in a drag and drop operation.
Definition: qdrag.cpp:166
void setDragDropOverwriteMode(bool overwrite)
virtual QMap< int, QVariant > itemData(const QModelIndex &index) const
Returns a map with values for all predefined roles in the model for the item at the given index...
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
The QDrag class provides support for MIME-based drag and drop data transfer.
Definition: qdrag.h:61
QSize size() const
void setMimeData(QMimeData *data)
Sets the data to be sent to the given MIME data.
Definition: qdrag.cpp:142
QPointer< QWidget > widget
void setDefaultDropAction(Qt::DropAction dropAction)
virtual QStyleOptionViewItem viewOptions() const
Returns a QStyleOptionViewItem structure populated with the view&#39;s palette, font, state...
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Updates the geometry of the editor for the item with the given index, according to the rectangle spec...
virtual void setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
ScrollMode horizontalScrollMode() const
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
bool acceptDrops() const
virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
Closes the given editor, and releases it.
void setAlternatingRowColors(bool enable)
bool autoScroll
whether autoscrolling in drag move events is enabled
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
void mouseMoveEvent(QMouseEvent *event)
This function is called with the given event when a mouse move event is sent to the widget...
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
#define it(className, varName)
virtual bool isIndexHidden(const QModelIndex &index) const =0
Returns true if the item referred to by the given index is hidden in the view, otherwise returns fals...
virtual QRect visualRect(const QModelIndex &index) const =0
Returns the rectangle on the viewport occupied by the item at index.
void mouseDoubleClickEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is double clicked inside the widget...
void setDirtyRegion(const QRegion &region)
Marks the given region as dirty and schedules it to be updated.
bool isVisible() const
Definition: qwidget.h:1005
void setAutoScrollMargin(int margin)
void clicked(const QModelIndex &index)
This signal is emitted when a mouse button is clicked.
QWeakPointer< QWidget > widget
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
void setIconSize(const QSize &size)
#define SLOT(a)
Definition: qobjectdefs.h:226
TextElideMode
Definition: qnamespace.h:263
void removeEventFilter(QObject *)
Removes an event filter object obj from this object.
Definition: qobject.cpp:2099
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setDropAction(Qt::DropAction action)
Sets the action to be performed on the data by the target.
Definition: qevent.cpp:2746
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
DragDropMode dragDropMode() const
Position decorationPosition
the position of the decoration for the item
Definition: qstyleoption.h:550
void setEditTriggers(EditTriggers triggers)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
The QItemSelectionRange class manages information about a range of selected items in a model...
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
void setIndexWidget(const QModelIndex &index, QWidget *widget)
Sets the given widget on the item at the given index, passing the ownership of the widget to the view...
virtual bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &roles)
Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole...
const QItemSelection selection() const
Returns the selection ranges stored in the selection model.
static bool match(const uchar *found, const char *target, uint len)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QAbstractItemView::SelectionBehavior selectionBehavior
virtual void verticalScrollbarValueChanged(int value)
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
void timerEvent(QTimerEvent *event)
This function is called with the given event when a timer event is sent to the widget.
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
virtual QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const
const QEditorInfo & editorForIndex(const QModelIndex &index) const
Qt::TextElideMode textElideMode
where ellipsis should be added for text that is too long to fit into an item
Definition: qstyleoption.h:549
QScrollBar * verticalScrollBar() const
Returns the vertical scroll bar.
void init(const QWidget *w)
Use initFrom(widget) instead.
bool shouldForwardEvent(QAbstractItemView::EditTrigger trigger, const QEvent *event) const
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
bool updatesEnabled() const
void checkPersistentEditorFocus()
When persistent aeditor gets/loses focus, we need to check and setcorrectly the current index...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
virtual Qt::DropActions supportedDropActions() const
Returns the drop actions supported by this model.
virtual void verticalScrollbarAction(int action)
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
virtual int sizeHintForColumn(int column) const
Returns the width size hint for the specified column or -1 if there is no model.
DropIndicatorPosition
This enum indicates the position of the drop indicator in relation to the index at the current mouse ...
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition: qwidget.cpp:9683
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Qt::DropAction exec(Qt::DropActions supportedActions=Qt::MoveAction)
Starts the drag and drop operation and returns a value indicating the requested drop action when it i...
Definition: qdrag.cpp:243
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
QAbstractItemDelegate * itemDelegate() const
Returns the item delegate used by this view and model.
bool hasFocus() const
Definition: qwidget.cpp:6583
T * qobject_cast(QObject *object)
Definition: qobject.h:375
virtual void doItemsLayout()
This function is intended to lay out the items in the view.
void setText(const QString &, Mode mode=Clipboard)
Copies text into the clipboard as plain text.
Definition: qclipboard.cpp:375
bool dragEnabled() const
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
Qt::DropAction defaultDropAction() const
DropIndicatorPosition dropIndicatorPosition() const
Returns the position of the drop indicator in relation to the closest item.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual void selectAll(QItemSelectionModel::SelectionFlags command)
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)=0
Returns a QModelIndex object pointing to the next object in the view, based on the given cursorAction...
bool tabKeyNavigation() const
void scheduleDelayedItemsLayout()
Schedules a layout of the items in the view to be executed when the event processing starts...
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Sets the data for the item at the given index in the model to the contents of the given editor...
int height() const
virtual void _q_layoutChanged()
This slot is called when the layout is changed.
void setNumberOptions(NumberOptions options)
Sets the options related to number conversions for this QLocale instance.
Definition: qlocale.cpp:786
The QStyledItemDelegate class provides display and editing facilities for data items from a model...
T * data() const
void addAction(QAction *action)
Appends the action action to this widget&#39;s list of actions.
Definition: qwidget.cpp:3317
bool focusNextPrevChild(bool next)
Reimplemented Function
virtual void editorDestroyed(QObject *editor)
This function is called when the given editor has been destroyed.
QWidget * focusProxy() const
Returns the focus proxy, or 0 if there is no focus proxy.
Definition: qwidget.cpp:6561
void dragMoveEvent(QDragMoveEvent *event)
This function is called continuously with the given event during a drag and drop operation over the w...
bool showDropIndicator() const
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
virtual void commitData(QWidget *editor)
Commit the data in the editor to the model.
QWidget * indexWidget(const QModelIndex &index) const
Returns the widget for the item at the given index.
QItemSelectionModel::SelectionFlags multiSelectionCommand(const QModelIndex &index, const QEvent *event) const
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setHoverIndex(const QPersistentModelIndex &index)
void setRange(int min, int max)
Sets the slider&#39;s minimum to min and its maximum to max.
void setAutoScroll(bool enable)
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QStyle * style() const
Definition: qwidget.cpp:2742
virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
When editing of an item starts, this function is called with the event that triggered the editing...
virtual void _q_columnsInserted(const QModelIndex &parent, int start, int end)
This slot is called when columns have been inserted.
virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index, const QEvent *event=0) const
Returns the SelectionFlags to be used when updating a selection with to include the index specified...
#define Q_Q(Class)
Definition: qglobal.h:2483
void removeEditor(QWidget *editor)
void setTabKeyNavigation(bool enable)
void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Sets the model item index to be the current item, and emits currentChanged().
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void dropEvent(QDropEvent *event)
This function is called with the given event when a drop event occurs over the widget.
QWidget * viewport() const
Returns the viewport widget.
virtual int verticalOffset() const =0
Returns the vertical offset of the view.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
virtual void columnsInserted(const QModelIndex &parent, int first, int last)=0
void checkMouseMove(const QPersistentModelIndex &index)
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the editor to be used for editing the data item with the given index.
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
void clearOrRemove()
In DND if something has been moved then this is called.
void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive resize events (passed in event)...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void doDelayedItemsLayout(int delay=0)
static QAction * createKeyedAction(StandardSoftKey standardKey, Qt::Key key, QWidget *actionWidget)
Creates a QAction and registers the &#39;triggered&#39; signal to send the given key event to actionWidget as...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
const QString & commitString() const
Returns the text that should get added to (or replace parts of) the text of the editor widget...
Definition: qevent.h:457
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
Reimplemented Function
int value() const
virtual void _q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when columns are about to be removed.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QPixmap renderToPixmap(const QModelIndexList &indexes, QRect *r) const
virtual void selectAll()
Selects all items in the view.
ViewItemFeatures features
a bitwise OR of the features that describe this view item
Definition: qstyleoption.h:577
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
bool isAccepted() const
Definition: qcoreevent.h:307
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
ScrollMode verticalScrollMode() const
void setDropIndicatorShown(bool enable)
virtual bool dropOn(QDropEvent *event, int *row, int *col, QModelIndex *index)
If the event hasn&#39;t already been accepted, determines the index to drop on.
friend class QPixmap
Definition: qwidget.h:748
QItemSelectionModel::SelectionFlags extendedSelectionCommand(const QModelIndex &index, const QEvent *event) const
~QAbstractItemView()
Destroys the view.
static QClipboard * clipboard()
Returns a pointer to the application global clipboard.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
virtual void rowsRemoved(const QModelIndex &parent, int first, int last)=0
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QItemSelectionModel * selectionModel() const
Returns the current selection model.
int verticalStepsPerItem() const
Returns the vertical scroll bar&#39;s steps per item.
virtual void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)=0
Scrolls the view if necessary to ensure that the item at index is visible.
void executeDelayedItemsLayout()
Executes the scheduled layouts without waiting for the event processing to begin. ...
bool isSelected(const QModelIndex &index) const
Returns true if the given model item index is selected.
int width() const
int autoScrollMargin() const
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
int row() const
Returns the row this model index refers to.
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
On models that support this, removes count rows starting with the given row under parent parent from ...
QWidgetData * data
Definition: qwidget.h:815
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
const char * styleHint(const QFontDef &request)
void setCurrentIndex(const QModelIndex &index)
Sets the current item to be the item at index.
Q_CORE_EXPORT void qWarning(const char *,...)
void setTextElideMode(Qt::TextElideMode mode)
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
bool showDecorationSelected
whether the decoration should be highlighted on selected items
Definition: qstyleoption.h:553
#define Q_RETURN_ARG(type, data)
Definition: qobjectdefs.h:247
virtual QModelIndex buddy(const QModelIndex &index) const
Returns a model index for the buddy of the item represented by index.
void setDragDropMode(DragDropMode behavior)
virtual void reset()
Reset the internal state of the view.
QModelIndex currentIndex() const
Returns the model index of the current item.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void invalidate()
Marks this QElapsedTimer object as invalid.
static void sendPostedEvents()
void keyPressEvent(QKeyEvent *event)
This function is called with the given event when a key event is sent to the widget.
bool alternatingRowColors() const
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
int horizontalStepsPerItem() const
Returns the horizontal scroll bar&#39;s steps per item.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
State
Describes the different states the view can be in.
virtual int horizontalOffset() const =0
Returns the horizontal offset of the view.
DropAction
Definition: qnamespace.h:1597
virtual bool canFetchMore(const QModelIndex &parent) const
Returns true if there is more data available for parent; otherwise returns false. ...
static int startDragDistance()
QModelIndex currentIndex() const
Returns the model item index for the current item, or an invalid index if there is no current item...
__int64 qint64
Definition: qglobal.h:942
void activated(const QModelIndex &index)
This signal is emitted when the item specified by index is activated by the user. ...
The State element defines configurations of objects and properties.
void show()
Shows the widget and its child widgets.
DragDropMode
Describes the various drag and drop events the view can act upon.
void setDragEnabled(bool enable)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
QAbstractItemView::SelectionBehavior selectionBehavior() const
void setVerticalStepsPerItem(int steps)
Sets the vertical scroll bar&#39;s steps per item to steps.
void focusInEvent(QFocusEvent *event)
This function is called with the given event when the widget obtains the focus.
bool shouldEdit(QAbstractItemView::EditTrigger trigger, const QModelIndex &index) const
Qt::MouseButton button() const
Returns the button that caused the event.
Definition: qevent.h:101
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QRect rect() const
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
bool isEnabled() const
Definition: qwidget.h:948
void scrollToTop()
Scrolls the view to the top.
#define QT_NO_DRAGANDDROP
Definition: qconfig-large.h:96
QAbstractItemView::SelectionMode selectionMode() const
The QAbstractItemModel class provides the abstract interface for item model classes.
Qt::ItemFlags flags() const
Returns the flags for the item referred to by the index.
static bool isActive()
Returns true if an accessibility implementation has been requested during the runtime of the applicat...
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
static QAccessibleInterface * queryAccessibleInterface(QObject *)
If a QAccessibleInterface implementation exists for the given object, this function returns a pointer...
virtual QModelIndex parent(const QModelIndex &child) const =0
Returns the parent of the model item with the given index.
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
virtual void fetchMore(const QModelIndex &parent)
Fetches any available data for the items with the parent specified by the parent index.
virtual bool viewportEvent(QEvent *)
The main event handler for the scrolling area (the viewport() widget).
InputMethodQuery
Definition: qnamespace.h:1541
void updateEditorData(const QModelIndex &topLeft, const QModelIndex &bottomRight)
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
Qt::TextElideMode textElideMode() const
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
virtual void modelReset()=0
The QAbstractItemView class provides the basic functionality for item view classes.
virtual void updateEditorData()
Updates the data shown in the open editor widgets in the view.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
void inputMethodEvent(QInputMethodEvent *event)
Reimplemented Function
The QItemSelection class manages information about selected items in a model.
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
void setAcceptDrops(bool on)
Definition: qwidget.cpp:3534
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
Qt::MouseButtons buttons() const
Returns the button state when the event was generated.
Definition: qevent.h:102
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)=0
Applies the selection flags to the items in or touched by the rectangle, rect.
void clearSelection()
Deselects all selected items.
The QMap::iterator class provides an STL-style non-const iterator for QMap and QMultiMap.
Definition: qmap.h:233
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
const QWidget * widget
Definition: qstyleoption.h:596
virtual void horizontalScrollbarValueChanged(int value)
The QDoubleSpinBox class provides a spin box widget that takes doubles.
Definition: qspinbox.h:126
void pressed(const QModelIndex &index)
This signal is emitted when a mouse button is pressed.
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
The QPersistentModelIndex class is used to locate data in a data model.
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
QString text() const
Returns the Unicode text that this key generated.
Definition: qevent.h:236
void setHorizontalScrollMode(ScrollMode mode)
virtual void columnsRemoved(const QModelIndex &parent, int first, int last)=0
void resizeEvent(QResizeEvent *event)
This function is called with the given event when a resize event is sent to the widget.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
The QStatusTipEvent class provides an event that is used to show messages in a status bar...
Definition: qevent.h:606
QPersistentModelIndex enteredIndex
void dragEnterEvent(QDragEnterEvent *event)
This function is called with the given event when a drag and drop operation enters the widget...
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
QAbstractItemDelegate * itemDelegateForRow(int row) const
Returns the item delegate used by this view and model for the given row, or 0 if no delegate has been...
QWidget * source() const
If the source of the drag operation is a widget in this application, this function returns that sourc...
Definition: qevent.cpp:2739
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool dragDropOverwriteMode() const
QModelIndex indexForEditor(QWidget *editor) const
Qt::Alignment displayAlignment
the alignment of the display value for the item
Definition: qstyleoption.h:547
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
virtual QModelIndexList selectedIndexes() const
This convenience function returns a list of all selected and non-hidden item indexes in the view...
void setVerticalScrollMode(ScrollMode mode)
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
bool sendDelegateEvent(const QModelIndex &index, QEvent *event) const
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can&#39;t.
Definition: qwidget.cpp:6836
The QModelIndex class is used to locate data in a data model.
QSize decorationSize
the size of the decoration for the item
Definition: qstyleoption.h:551
QScrollBar * horizontalScrollBar() const
Returns the horizontal scroll bar.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
Definition: qwidget.cpp:3407
QAccessibleTable2Interface * table2Interface()
Definition: qaccessible.h:432
QPoint dirtyRegionOffset() const
Returns the offset of the dirty regions in the view.
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
if(void) toggleToolbarShown
virtual void rowsInserted(const QModelIndex &parent, int first, int last)=0
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
const QAbstractItemModel * model() const
Returns the item model operated on by the selection model.
Definition: qnamespace.h:54
QWidget * editor(const QModelIndex &index, const QStyleOptionViewItem &options)
QStyleOptionViewItemV4 viewOptionsV4() const
The QSpinBox class provides a spin box widget.
Definition: qspinbox.h:56
void edit(const QModelIndex &index)
Starts editing the item corresponding to the given index if it is editable.
virtual void _q_columnsRemoved(const QModelIndex &parent, int start, int end)
This slot is called when columns have been removed.
bool openEditor(const QModelIndex &index, QEvent *event)
virtual void _q_rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows have been inserted.
State state() const
Returns the item view&#39;s state.
void focusOutEvent(QFocusEvent *event)
This function is called with the given event when the widget looses the focus.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
quint16 index
void mouseReleaseEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is released, after a mouse press eve...
QModelIndexList selectedDraggableIndexes() const
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
EndEditHint
This enum describes the different hints that the delegate can give to the model and view components t...
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This slot is called when items are changed in the model.
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QObject * parent
Definition: qobject.h:92
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const =0
Returns the region from the viewport of the items in the given selection.
EditTrigger
This enum describes actions which will initiate item editing.
virtual void updateGeometries()
Updates the geometry of the child widgets of the view.
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
bool event(QEvent *)
Reimplemented Function
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
const QFont & font() const
const QMimeData * mimeData() const
Returns the data that was dropped on the widget and its associated MIME type information.
Definition: qevent.h:498
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setHotSpot(const QPoint &hotspot)
Sets the position of the hot spot relative to the top-left corner of the pixmap used to the point spe...
Definition: qdrag.cpp:189
void setHorizontalStepsPerItem(int steps)
Sets the horizontal scroll bar&#39;s steps per item to steps.
void setItemDelegate(QAbstractItemDelegate *delegate)
Sets the item delegate for this view and its model to delegate.
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
QSize iconSize() const
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.
void doubleClicked(const QModelIndex &index)
This signal is emitted when a mouse button is double-clicked.
void closePersistentEditor(const QModelIndex &index)
Closes the persistent editor for the item at the given index.
const char * variant
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
void scrollDirtyRegion(int dx, int dy)
Prepares the view for scrolling by ({dx},{dy}) pixels by moving the dirty regions in the opposite dir...
virtual void horizontalScrollbarAction(int action)
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
Sets the contents of the given editor to the data for the item at the given index.
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
QItemSelectionModel::SelectionFlags contiguousSelectionCommand(const QModelIndex &index, const QEvent *event) const
static void setTabOrder(QWidget *, QWidget *)
Puts the second widget after the first widget in the focus order.
Definition: qwidget.cpp:6975
QModelIndex rootIndex() const
Returns the model index of the model&#39;s root item.
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Definition: qtestcase.cpp:2183
QAbstractItemModel * model() const
Returns the model that this view is presenting.
EditTriggers editTriggers() const
static const KeyPair *const end
void dragLeaveEvent(QDragLeaveEvent *event)
This function is called when the item being dragged leaves the view.
Orientation
Definition: qnamespace.h:174
bool event(QEvent *event)
Reimplemented Function
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
static int doubleClickInterval()
int pageStep() const
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QAbstractItemModel * model
void setState(State state)
Sets the item view&#39;s state to the given state.
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate)
Sets the given item delegate used by this view and model for the given column.
void mousePressEvent(QMouseEvent *event)
This function is called with the given event when a mouse button is pressed while the cursor is insid...
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
bool droppingOnItself(QDropEvent *event, const QModelIndex &index)
Return true if this is a move from ourself and index is a child of the selection that is being moved...
virtual int sizeHintForRow(int row) const
Returns the height size hint for the specified row or -1 if there is no model.
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
virtual void updateEditorGeometries()
Updates the geometry of the open editor widgets in the view.
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
bool viewportEvent(QEvent *event)
This function is used to handle tool tips, and What&#39;s This? mode, if the given event is a QEvent::Too...
const QPoint & pos() const
Returns the position where the drop was made.
Definition: qevent.h:486
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
bool shouldAutoScroll(const QPoint &pos) const
void addEditor(const QModelIndex &index, QWidget *editor, bool isStatic)
int column() const
Returns the column this model index refers to.
virtual void startDrag(Qt::DropActions supportedActions)
Starts a drag by calling drag->exec() using the given supportedActions.
static int area(const QSize &s)
Definition: qicon.cpp:155
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
bool isValid() const
Returns true if this persistent model index is valid; otherwise returns false.
virtual QModelIndex indexAt(const QPoint &point) const =0
Returns the model index of the item at the viewport coordinates point.
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
virtual void keyboardSearch(const QString &search)
Moves to and selects the item best matching the string search.
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586
MouseButton
Definition: qnamespace.h:150
QAbstractItemDelegate * itemDelegateForColumn(int column) const
Returns the item delegate used by this view and model for the given column.
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480
const QPoint & pos() const
Returns the mouse cursor position when the event was generated, relative to the widget to which the e...
Definition: qevent.h:597