| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qabstractitemview.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | #include "qabstractitemview.h" | - | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | #ifndef QT_NO_ITEMVIEWS | - | ||||||||||||||||||||||||
| 43 | #include <qpointer.h> | - | ||||||||||||||||||||||||
| 44 | #include <qapplication.h> | - | ||||||||||||||||||||||||
| 45 | #include <qclipboard.h> | - | ||||||||||||||||||||||||
| 46 | #include <qpainter.h> | - | ||||||||||||||||||||||||
| 47 | #include <qstyle.h> | - | ||||||||||||||||||||||||
| 48 | #include <qdrag.h> | - | ||||||||||||||||||||||||
| 49 | #include <qevent.h> | - | ||||||||||||||||||||||||
| 50 | #include <qscrollbar.h> | - | ||||||||||||||||||||||||
| 51 | #include <qwhatsthis.h> | - | ||||||||||||||||||||||||
| 52 | #include <qtooltip.h> | - | ||||||||||||||||||||||||
| 53 | #include <qdatetime.h> | - | ||||||||||||||||||||||||
| 54 | #include <qlineedit.h> | - | ||||||||||||||||||||||||
| 55 | #include <qspinbox.h> | - | ||||||||||||||||||||||||
| 56 | #include <qtreeview.h> | - | ||||||||||||||||||||||||
| 57 | #include <qtableview.h> | - | ||||||||||||||||||||||||
| 58 | #include <qheaderview.h> | - | ||||||||||||||||||||||||
| 59 | #include <qstyleditemdelegate.h> | - | ||||||||||||||||||||||||
| 60 | #include <private/qabstractitemview_p.h> | - | ||||||||||||||||||||||||
| 61 | #include <private/qabstractitemmodel_p.h> | - | ||||||||||||||||||||||||
| 62 | #include <private/qguiapplication_p.h> | - | ||||||||||||||||||||||||
| 63 | #include <private/qscrollbar_p.h> | - | ||||||||||||||||||||||||
| 64 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 65 | #include <qaccessible.h> | - | ||||||||||||||||||||||||
| 66 | #endif | - | ||||||||||||||||||||||||
| 67 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||
| 68 | # include <qscroller.h> | - | ||||||||||||||||||||||||
| 69 | #endif | - | ||||||||||||||||||||||||
| 70 | - | |||||||||||||||||||||||||
| 71 | #include <algorithm> | - | ||||||||||||||||||||||||
| 72 | - | |||||||||||||||||||||||||
| 73 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | QAbstractItemViewPrivate::QAbstractItemViewPrivate() | - | ||||||||||||||||||||||||
| 76 | : model(QAbstractItemModelPrivate::staticEmptyModel()), | - | ||||||||||||||||||||||||
| 77 | itemDelegate(0), | - | ||||||||||||||||||||||||
| 78 | selectionModel(0), | - | ||||||||||||||||||||||||
| 79 | ctrlDragSelectionFlag(QItemSelectionModel::NoUpdate), | - | ||||||||||||||||||||||||
| 80 | noSelectionOnMousePress(false), | - | ||||||||||||||||||||||||
| 81 | selectionMode(QAbstractItemView::ExtendedSelection), | - | ||||||||||||||||||||||||
| 82 | selectionBehavior(QAbstractItemView::SelectItems), | - | ||||||||||||||||||||||||
| 83 | currentlyCommittingEditor(0), | - | ||||||||||||||||||||||||
| 84 | pressedModifiers(Qt::NoModifier), | - | ||||||||||||||||||||||||
| 85 | pressedPosition(QPoint(-1, -1)), | - | ||||||||||||||||||||||||
| 86 | pressedAlreadySelected(false), | - | ||||||||||||||||||||||||
| 87 | viewportEnteredNeeded(false), | - | ||||||||||||||||||||||||
| 88 | state(QAbstractItemView::NoState), | - | ||||||||||||||||||||||||
| 89 | stateBeforeAnimation(QAbstractItemView::NoState), | - | ||||||||||||||||||||||||
| 90 | editTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed), | - | ||||||||||||||||||||||||
| 91 | lastTrigger(QAbstractItemView::NoEditTriggers), | - | ||||||||||||||||||||||||
| 92 | tabKeyNavigation(false), | - | ||||||||||||||||||||||||
| 93 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 94 | showDropIndicator(true), | - | ||||||||||||||||||||||||
| 95 | dragEnabled(false), | - | ||||||||||||||||||||||||
| 96 | dragDropMode(QAbstractItemView::NoDragDrop), | - | ||||||||||||||||||||||||
| 97 | overwrite(false), | - | ||||||||||||||||||||||||
| 98 | dropIndicatorPosition(QAbstractItemView::OnItem), | - | ||||||||||||||||||||||||
| 99 | defaultDropAction(Qt::IgnoreAction), | - | ||||||||||||||||||||||||
| 100 | #endif | - | ||||||||||||||||||||||||
| 101 | autoScroll(true), | - | ||||||||||||||||||||||||
| 102 | autoScrollMargin(16), | - | ||||||||||||||||||||||||
| 103 | autoScrollCount(0), | - | ||||||||||||||||||||||||
| 104 | shouldScrollToCurrentOnShow(false), | - | ||||||||||||||||||||||||
| 105 | shouldClearStatusTip(false), | - | ||||||||||||||||||||||||
| 106 | alternatingColors(false), | - | ||||||||||||||||||||||||
| 107 | textElideMode(Qt::ElideRight), | - | ||||||||||||||||||||||||
| 108 | verticalScrollMode(QAbstractItemView::ScrollPerItem), | - | ||||||||||||||||||||||||
| 109 | horizontalScrollMode(QAbstractItemView::ScrollPerItem), | - | ||||||||||||||||||||||||
| 110 | currentIndexSet(false), | - | ||||||||||||||||||||||||
| 111 | wrapItemText(false), | - | ||||||||||||||||||||||||
| 112 | delayedPendingLayout(true), | - | ||||||||||||||||||||||||
| 113 | moveCursorUpdatedView(false), | - | ||||||||||||||||||||||||
| 114 | verticalScrollModeSet(false), | - | ||||||||||||||||||||||||
| 115 | horizontalScrollModeSet(false) | - | ||||||||||||||||||||||||
| 116 | { | - | ||||||||||||||||||||||||
| 117 | keyboardInputTime.invalidate(); | - | ||||||||||||||||||||||||
| 118 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||
| 120 | QAbstractItemViewPrivate::~QAbstractItemViewPrivate() | - | ||||||||||||||||||||||||
| 121 | { | - | ||||||||||||||||||||||||
| 122 | } | - | ||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||
| 124 | void QAbstractItemViewPrivate::init() | - | ||||||||||||||||||||||||
| 125 | { | - | ||||||||||||||||||||||||
| 126 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 127 | q->setItemDelegate(new QStyledItemDelegate(q)); | - | ||||||||||||||||||||||||
| 128 | - | |||||||||||||||||||||||||
| 129 | vbar->setRange(0, 0); | - | ||||||||||||||||||||||||
| 130 | hbar->setRange(0, 0); | - | ||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||
| 132 | QObject::connect(vbar, SIGNAL(actionTriggered(int)), | - | ||||||||||||||||||||||||
| 133 | q, SLOT(verticalScrollbarAction(int))); | - | ||||||||||||||||||||||||
| 134 | QObject::connect(hbar, SIGNAL(actionTriggered(int)), | - | ||||||||||||||||||||||||
| 135 | q, SLOT(horizontalScrollbarAction(int))); | - | ||||||||||||||||||||||||
| 136 | QObject::connect(vbar, SIGNAL(valueChanged(int)), | - | ||||||||||||||||||||||||
| 137 | q, SLOT(verticalScrollbarValueChanged(int))); | - | ||||||||||||||||||||||||
| 138 | QObject::connect(hbar, SIGNAL(valueChanged(int)), | - | ||||||||||||||||||||||||
| 139 | q, SLOT(horizontalScrollbarValueChanged(int))); | - | ||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||
| 141 | viewport->setBackgroundRole(QPalette::Base); | - | ||||||||||||||||||||||||
| 142 | - | |||||||||||||||||||||||||
| 143 | q->setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||
| 145 | verticalScrollMode = static_cast<QAbstractItemView::ScrollMode>(q->style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, q, 0)); | - | ||||||||||||||||||||||||
| 146 | horizontalScrollMode = static_cast<QAbstractItemView::ScrollMode>(q->style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, q, 0)); | - | ||||||||||||||||||||||||
| 147 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | void QAbstractItemViewPrivate::setHoverIndex(const QPersistentModelIndex &index) | - | ||||||||||||||||||||||||
| 150 | { | - | ||||||||||||||||||||||||
| 151 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 152 | if (hover == index)
| 0 | ||||||||||||||||||||||||
| 153 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||
| 155 | if (selectionBehavior != QAbstractItemView::SelectRows) {
| 0 | ||||||||||||||||||||||||
| 156 | q->update(hover); //update the old one | - | ||||||||||||||||||||||||
| 157 | q->update(index); //update the new one | - | ||||||||||||||||||||||||
| 158 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 159 | QRect oldHoverRect = q->visualRect(hover); | - | ||||||||||||||||||||||||
| 160 | QRect newHoverRect = q->visualRect(index); | - | ||||||||||||||||||||||||
| 161 | viewport->update(QRect(0, newHoverRect.y(), viewport->width(), newHoverRect.height())); | - | ||||||||||||||||||||||||
| 162 | viewport->update(QRect(0, oldHoverRect.y(), viewport->width(), oldHoverRect.height())); | - | ||||||||||||||||||||||||
| 163 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 164 | hover = index; | - | ||||||||||||||||||||||||
| 165 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||
| 167 | void QAbstractItemViewPrivate::checkMouseMove(const QPersistentModelIndex &index) | - | ||||||||||||||||||||||||
| 168 | { | - | ||||||||||||||||||||||||
| 169 | //we take a persistent model index because the model might change by emitting signals | - | ||||||||||||||||||||||||
| 170 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 171 | setHoverIndex(index); | - | ||||||||||||||||||||||||
| 172 | if (viewportEnteredNeeded || enteredIndex != index) {
| 0 | ||||||||||||||||||||||||
| 173 | viewportEnteredNeeded = false; | - | ||||||||||||||||||||||||
| 174 | - | |||||||||||||||||||||||||
| 175 | if (index.isValid()) {
| 0 | ||||||||||||||||||||||||
| 176 | emit q->entered(index); | - | ||||||||||||||||||||||||
| 177 | #ifndef QT_NO_STATUSTIP | - | ||||||||||||||||||||||||
| 178 | QString statustip = model->data(index, Qt::StatusTipRole).toString(); | - | ||||||||||||||||||||||||
| 179 | if (parent && (shouldClearStatusTip || !statustip.isEmpty())) {
| 0 | ||||||||||||||||||||||||
| 180 | QStatusTipEvent tip(statustip); | - | ||||||||||||||||||||||||
| 181 | QApplication::sendEvent(parent, &tip); | - | ||||||||||||||||||||||||
| 182 | shouldClearStatusTip = !statustip.isEmpty(); | - | ||||||||||||||||||||||||
| 183 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 184 | #endif | - | ||||||||||||||||||||||||
| 185 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 186 | #ifndef QT_NO_STATUSTIP | - | ||||||||||||||||||||||||
| 187 | if (parent && shouldClearStatusTip) {
| 0 | ||||||||||||||||||||||||
| 188 | QString emptyString; | - | ||||||||||||||||||||||||
| 189 | QStatusTipEvent tip( emptyString ); | - | ||||||||||||||||||||||||
| 190 | QApplication::sendEvent(parent, &tip); | - | ||||||||||||||||||||||||
| 191 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 192 | #endif | - | ||||||||||||||||||||||||
| 193 | emit q->viewportEntered(); | - | ||||||||||||||||||||||||
| 194 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 195 | enteredIndex = index; | - | ||||||||||||||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 197 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||
| 199 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | // stores and restores the selection and current item when flicking | - | ||||||||||||||||||||||||
| 202 | void QAbstractItemViewPrivate::_q_scrollerStateChanged() | - | ||||||||||||||||||||||||
| 203 | { | - | ||||||||||||||||||||||||
| 204 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||
| 206 | if (QScroller *scroller = QScroller::scroller(viewport)) {
| 0 | ||||||||||||||||||||||||
| 207 | switch (scroller->state()) { | - | ||||||||||||||||||||||||
| 208 | case QScroller::Pressed: never executed: case QScroller::Pressed: | 0 | ||||||||||||||||||||||||
| 209 | // store the current selection in case we start scrolling | - | ||||||||||||||||||||||||
| 210 | if (q->selectionModel()) {
| 0 | ||||||||||||||||||||||||
| 211 | oldSelection = q->selectionModel()->selection(); | - | ||||||||||||||||||||||||
| 212 | oldCurrent = q->selectionModel()->currentIndex(); | - | ||||||||||||||||||||||||
| 213 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 214 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||
| 216 | case QScroller::Dragging: never executed: case QScroller::Dragging: | 0 | ||||||||||||||||||||||||
| 217 | // restore the old selection if we really start scrolling | - | ||||||||||||||||||||||||
| 218 | if (q->selectionModel()) {
| 0 | ||||||||||||||||||||||||
| 219 | q->selectionModel()->select(oldSelection, QItemSelectionModel::ClearAndSelect); | - | ||||||||||||||||||||||||
| 220 | q->selectionModel()->setCurrentIndex(oldCurrent, QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||||||||
| 221 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 222 | // fall through | - | ||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | default: code before this statement never executed: default:never executed: default: | 0 | ||||||||||||||||||||||||
| 225 | oldSelection = QItemSelection(); | - | ||||||||||||||||||||||||
| 226 | oldCurrent = QModelIndex(); | - | ||||||||||||||||||||||||
| 227 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 228 | } | - | ||||||||||||||||||||||||
| 229 | } | - | ||||||||||||||||||||||||
| 230 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 231 | - | |||||||||||||||||||||||||
| 232 | #endif // QT_NO_GESTURES | - | ||||||||||||||||||||||||
| 233 | - | |||||||||||||||||||||||||
| 234 | /*! | - | ||||||||||||||||||||||||
| 235 | \class QAbstractItemView | - | ||||||||||||||||||||||||
| 236 | - | |||||||||||||||||||||||||
| 237 | \brief The QAbstractItemView class provides the basic functionality for | - | ||||||||||||||||||||||||
| 238 | item view classes. | - | ||||||||||||||||||||||||
| 239 | - | |||||||||||||||||||||||||
| 240 | \ingroup model-view | - | ||||||||||||||||||||||||
| 241 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
| 242 | - | |||||||||||||||||||||||||
| 243 | QAbstractItemView class is the base class for every standard view | - | ||||||||||||||||||||||||
| 244 | that uses a QAbstractItemModel. QAbstractItemView is an abstract | - | ||||||||||||||||||||||||
| 245 | class and cannot itself be instantiated. It provides a standard | - | ||||||||||||||||||||||||
| 246 | interface for interoperating with models through the signals and | - | ||||||||||||||||||||||||
| 247 | slots mechanism, enabling subclasses to be kept up-to-date with | - | ||||||||||||||||||||||||
| 248 | changes to their models. This class provides standard support for | - | ||||||||||||||||||||||||
| 249 | keyboard and mouse navigation, viewport scrolling, item editing, | - | ||||||||||||||||||||||||
| 250 | and selections. The keyboard navigation implements this | - | ||||||||||||||||||||||||
| 251 | functionality: | - | ||||||||||||||||||||||||
| 252 | - | |||||||||||||||||||||||||
| 253 | \table | - | ||||||||||||||||||||||||
| 254 | \header | - | ||||||||||||||||||||||||
| 255 | \li Keys | - | ||||||||||||||||||||||||
| 256 | \li Functionality | - | ||||||||||||||||||||||||
| 257 | \row | - | ||||||||||||||||||||||||
| 258 | \li Arrow keys | - | ||||||||||||||||||||||||
| 259 | \li Changes the current item and selects it. | - | ||||||||||||||||||||||||
| 260 | \row | - | ||||||||||||||||||||||||
| 261 | \li Ctrl+Arrow keys | - | ||||||||||||||||||||||||
| 262 | \li Changes the current item but does not select it. | - | ||||||||||||||||||||||||
| 263 | \row | - | ||||||||||||||||||||||||
| 264 | \li Shift+Arrow keys | - | ||||||||||||||||||||||||
| 265 | \li Changes the current item and selects it. The previously | - | ||||||||||||||||||||||||
| 266 | selected item(s) is not deselected. | - | ||||||||||||||||||||||||
| 267 | \row | - | ||||||||||||||||||||||||
| 268 | \li Ctr+Space | - | ||||||||||||||||||||||||
| 269 | \li Toggles selection of the current item. | - | ||||||||||||||||||||||||
| 270 | \row | - | ||||||||||||||||||||||||
| 271 | \li Tab/Backtab | - | ||||||||||||||||||||||||
| 272 | \li Changes the current item to the next/previous item. | - | ||||||||||||||||||||||||
| 273 | \row | - | ||||||||||||||||||||||||
| 274 | \li Home/End | - | ||||||||||||||||||||||||
| 275 | \li Selects the first/last item in the model. | - | ||||||||||||||||||||||||
| 276 | \row | - | ||||||||||||||||||||||||
| 277 | \li Page up/Page down | - | ||||||||||||||||||||||||
| 278 | \li Scrolls the rows shown up/down by the number of | - | ||||||||||||||||||||||||
| 279 | visible rows in the view. | - | ||||||||||||||||||||||||
| 280 | \row | - | ||||||||||||||||||||||||
| 281 | \li Ctrl+A | - | ||||||||||||||||||||||||
| 282 | \li Selects all items in the model. | - | ||||||||||||||||||||||||
| 283 | \endtable | - | ||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||
| 285 | Note that the above table assumes that the | - | ||||||||||||||||||||||||
| 286 | \l{selectionMode}{selection mode} allows the operations. For | - | ||||||||||||||||||||||||
| 287 | instance, you cannot select items if the selection mode is | - | ||||||||||||||||||||||||
| 288 | QAbstractItemView::NoSelection. | - | ||||||||||||||||||||||||
| 289 | - | |||||||||||||||||||||||||
| 290 | The QAbstractItemView class is one of the \l{Model/View Classes} | - | ||||||||||||||||||||||||
| 291 | and is part of Qt's \l{Model/View Programming}{model/view framework}. | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | The view classes that inherit QAbstractItemView only need | - | ||||||||||||||||||||||||
| 294 | to implement their own view-specific functionality, such as | - | ||||||||||||||||||||||||
| 295 | drawing items, returning the geometry of items, finding items, | - | ||||||||||||||||||||||||
| 296 | etc. | - | ||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||
| 298 | QAbstractItemView provides common slots such as edit() and | - | ||||||||||||||||||||||||
| 299 | setCurrentIndex(). Many protected slots are also provided, including | - | ||||||||||||||||||||||||
| 300 | dataChanged(), rowsInserted(), rowsAboutToBeRemoved(), selectionChanged(), | - | ||||||||||||||||||||||||
| 301 | and currentChanged(). | - | ||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||
| 303 | The root item is returned by rootIndex(), and the current item by | - | ||||||||||||||||||||||||
| 304 | currentIndex(). To make sure that an item is visible use | - | ||||||||||||||||||||||||
| 305 | scrollTo(). | - | ||||||||||||||||||||||||
| 306 | - | |||||||||||||||||||||||||
| 307 | Some of QAbstractItemView's functions are concerned with | - | ||||||||||||||||||||||||
| 308 | scrolling, for example setHorizontalScrollMode() and | - | ||||||||||||||||||||||||
| 309 | setVerticalScrollMode(). To set the range of the scroll bars, you | - | ||||||||||||||||||||||||
| 310 | can, for example, reimplement the view's resizeEvent() function: | - | ||||||||||||||||||||||||
| 311 | - | |||||||||||||||||||||||||
| 312 | \snippet code/src_gui_itemviews_qabstractitemview.cpp 0 | - | ||||||||||||||||||||||||
| 313 | - | |||||||||||||||||||||||||
| 314 | Note that the range is not updated until the widget is shown. | - | ||||||||||||||||||||||||
| 315 | - | |||||||||||||||||||||||||
| 316 | Several other functions are concerned with selection control; for | - | ||||||||||||||||||||||||
| 317 | example setSelectionMode(), and setSelectionBehavior(). This class | - | ||||||||||||||||||||||||
| 318 | provides a default selection model to work with | - | ||||||||||||||||||||||||
| 319 | (selectionModel()), but this can be replaced by using | - | ||||||||||||||||||||||||
| 320 | setSelectionModel() with an instance of QItemSelectionModel. | - | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | For complete control over the display and editing of items you can | - | ||||||||||||||||||||||||
| 323 | specify a delegate with setItemDelegate(). | - | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | QAbstractItemView provides a lot of protected functions. Some are | - | ||||||||||||||||||||||||
| 326 | concerned with editing, for example, edit(), and commitData(), | - | ||||||||||||||||||||||||
| 327 | whilst others are keyboard and mouse event handlers. | - | ||||||||||||||||||||||||
| 328 | - | |||||||||||||||||||||||||
| 329 | \note If you inherit QAbstractItemView and intend to update the contents | - | ||||||||||||||||||||||||
| 330 | of the viewport, you should use viewport->update() instead of | - | ||||||||||||||||||||||||
| 331 | \l{QWidget::update()}{update()} as all painting operations take place on the | - | ||||||||||||||||||||||||
| 332 | viewport. | - | ||||||||||||||||||||||||
| 333 | - | |||||||||||||||||||||||||
| 334 | \sa {View Classes}, {Model/View Programming}, QAbstractItemModel, {Chart Example} | - | ||||||||||||||||||||||||
| 335 | */ | - | ||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | /*! | - | ||||||||||||||||||||||||
| 338 | \enum QAbstractItemView::SelectionMode | - | ||||||||||||||||||||||||
| 339 | - | |||||||||||||||||||||||||
| 340 | This enum indicates how the view responds to user selections: | - | ||||||||||||||||||||||||
| 341 | - | |||||||||||||||||||||||||
| 342 | \value SingleSelection When the user selects an item, any already-selected | - | ||||||||||||||||||||||||
| 343 | item becomes unselected, and the user cannot unselect the selected item by | - | ||||||||||||||||||||||||
| 344 | clicking on it. | - | ||||||||||||||||||||||||
| 345 | - | |||||||||||||||||||||||||
| 346 | \value ContiguousSelection When the user selects an item in the usual way, | - | ||||||||||||||||||||||||
| 347 | the selection is cleared and the new item selected. However, if the user | - | ||||||||||||||||||||||||
| 348 | presses the Shift key while clicking on an item, all items between the | - | ||||||||||||||||||||||||
| 349 | current item and the clicked item are selected or unselected, depending on | - | ||||||||||||||||||||||||
| 350 | the state of the clicked item. | - | ||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||
| 352 | \value ExtendedSelection When the user selects an item in the usual way, | - | ||||||||||||||||||||||||
| 353 | the selection is cleared and the new item selected. However, if the user | - | ||||||||||||||||||||||||
| 354 | presses the Ctrl key when clicking on an item, the clicked item gets | - | ||||||||||||||||||||||||
| 355 | toggled and all other items are left untouched. If the user presses the | - | ||||||||||||||||||||||||
| 356 | Shift key while clicking on an item, all items between the current item | - | ||||||||||||||||||||||||
| 357 | and the clicked item are selected or unselected, depending on the state of | - | ||||||||||||||||||||||||
| 358 | the clicked item. Multiple items can be selected by dragging the mouse over | - | ||||||||||||||||||||||||
| 359 | them. | - | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | \value MultiSelection When the user selects an item in the usual way, the | - | ||||||||||||||||||||||||
| 362 | selection status of that item is toggled and the other items are left | - | ||||||||||||||||||||||||
| 363 | alone. Multiple items can be toggled by dragging the mouse over them. | - | ||||||||||||||||||||||||
| 364 | - | |||||||||||||||||||||||||
| 365 | \value NoSelection Items cannot be selected. | - | ||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||
| 367 | The most commonly used modes are SingleSelection and ExtendedSelection. | - | ||||||||||||||||||||||||
| 368 | */ | - | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | /*! | - | ||||||||||||||||||||||||
| 371 | \enum QAbstractItemView::SelectionBehavior | - | ||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||
| 373 | \value SelectItems Selecting single items. | - | ||||||||||||||||||||||||
| 374 | \value SelectRows Selecting only rows. | - | ||||||||||||||||||||||||
| 375 | \value SelectColumns Selecting only columns. | - | ||||||||||||||||||||||||
| 376 | */ | - | ||||||||||||||||||||||||
| 377 | - | |||||||||||||||||||||||||
| 378 | /*! | - | ||||||||||||||||||||||||
| 379 | \enum QAbstractItemView::ScrollHint | - | ||||||||||||||||||||||||
| 380 | - | |||||||||||||||||||||||||
| 381 | \value EnsureVisible Scroll to ensure that the item is visible. | - | ||||||||||||||||||||||||
| 382 | \value PositionAtTop Scroll to position the item at the top of the | - | ||||||||||||||||||||||||
| 383 | viewport. | - | ||||||||||||||||||||||||
| 384 | \value PositionAtBottom Scroll to position the item at the bottom of the | - | ||||||||||||||||||||||||
| 385 | viewport. | - | ||||||||||||||||||||||||
| 386 | \value PositionAtCenter Scroll to position the item at the center of the | - | ||||||||||||||||||||||||
| 387 | viewport. | - | ||||||||||||||||||||||||
| 388 | */ | - | ||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||
| 390 | - | |||||||||||||||||||||||||
| 391 | /*! | - | ||||||||||||||||||||||||
| 392 | \enum QAbstractItemView::EditTrigger | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | This enum describes actions which will initiate item editing. | - | ||||||||||||||||||||||||
| 395 | - | |||||||||||||||||||||||||
| 396 | \value NoEditTriggers No editing possible. | - | ||||||||||||||||||||||||
| 397 | \value CurrentChanged Editing start whenever current item changes. | - | ||||||||||||||||||||||||
| 398 | \value DoubleClicked Editing starts when an item is double clicked. | - | ||||||||||||||||||||||||
| 399 | \value SelectedClicked Editing starts when clicking on an already selected | - | ||||||||||||||||||||||||
| 400 | item. | - | ||||||||||||||||||||||||
| 401 | \value EditKeyPressed Editing starts when the platform edit key has been | - | ||||||||||||||||||||||||
| 402 | pressed over an item. | - | ||||||||||||||||||||||||
| 403 | \value AnyKeyPressed Editing starts when any key is pressed over an item. | - | ||||||||||||||||||||||||
| 404 | \value AllEditTriggers Editing starts for all above actions. | - | ||||||||||||||||||||||||
| 405 | */ | - | ||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||
| 407 | /*! | - | ||||||||||||||||||||||||
| 408 | \enum QAbstractItemView::CursorAction | - | ||||||||||||||||||||||||
| 409 | - | |||||||||||||||||||||||||
| 410 | This enum describes the different ways to navigate between items, | - | ||||||||||||||||||||||||
| 411 | \sa moveCursor() | - | ||||||||||||||||||||||||
| 412 | - | |||||||||||||||||||||||||
| 413 | \value MoveUp Move to the item above the current item. | - | ||||||||||||||||||||||||
| 414 | \value MoveDown Move to the item below the current item. | - | ||||||||||||||||||||||||
| 415 | \value MoveLeft Move to the item left of the current item. | - | ||||||||||||||||||||||||
| 416 | \value MoveRight Move to the item right of the current item. | - | ||||||||||||||||||||||||
| 417 | \value MoveHome Move to the top-left corner item. | - | ||||||||||||||||||||||||
| 418 | \value MoveEnd Move to the bottom-right corner item. | - | ||||||||||||||||||||||||
| 419 | \value MovePageUp Move one page up above the current item. | - | ||||||||||||||||||||||||
| 420 | \value MovePageDown Move one page down below the current item. | - | ||||||||||||||||||||||||
| 421 | \value MoveNext Move to the item after the current item. | - | ||||||||||||||||||||||||
| 422 | \value MovePrevious Move to the item before the current item. | - | ||||||||||||||||||||||||
| 423 | */ | - | ||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||
| 425 | /*! | - | ||||||||||||||||||||||||
| 426 | \enum QAbstractItemView::State | - | ||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||
| 428 | Describes the different states the view can be in. This is usually | - | ||||||||||||||||||||||||
| 429 | only interesting when reimplementing your own view. | - | ||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||
| 431 | \value NoState The is the default state. | - | ||||||||||||||||||||||||
| 432 | \value DraggingState The user is dragging items. | - | ||||||||||||||||||||||||
| 433 | \value DragSelectingState The user is selecting items. | - | ||||||||||||||||||||||||
| 434 | \value EditingState The user is editing an item in a widget editor. | - | ||||||||||||||||||||||||
| 435 | \value ExpandingState The user is opening a branch of items. | - | ||||||||||||||||||||||||
| 436 | \value CollapsingState The user is closing a branch of items. | - | ||||||||||||||||||||||||
| 437 | \value AnimatingState The item view is performing an animation. | - | ||||||||||||||||||||||||
| 438 | */ | - | ||||||||||||||||||||||||
| 439 | - | |||||||||||||||||||||||||
| 440 | /*! | - | ||||||||||||||||||||||||
| 441 | \since 4.2 | - | ||||||||||||||||||||||||
| 442 | \enum QAbstractItemView::ScrollMode | - | ||||||||||||||||||||||||
| 443 | - | |||||||||||||||||||||||||
| 444 | Describes how the scrollbar should behave. When setting the scroll mode | - | ||||||||||||||||||||||||
| 445 | to ScrollPerPixel the single step size will adjust automatically unless | - | ||||||||||||||||||||||||
| 446 | it was set explicitly using \l{QAbstractSlider::}{setSingleStep()}. | - | ||||||||||||||||||||||||
| 447 | The automatic adjustment can be restored by setting the single step size to -1. | - | ||||||||||||||||||||||||
| 448 | - | |||||||||||||||||||||||||
| 449 | \value ScrollPerItem The view will scroll the contents one item at a time. | - | ||||||||||||||||||||||||
| 450 | \value ScrollPerPixel The view will scroll the contents one pixel at a time. | - | ||||||||||||||||||||||||
| 451 | */ | - | ||||||||||||||||||||||||
| 452 | - | |||||||||||||||||||||||||
| 453 | /*! | - | ||||||||||||||||||||||||
| 454 | \fn QRect QAbstractItemView::visualRect(const QModelIndex &index) const = 0 | - | ||||||||||||||||||||||||
| 455 | Returns the rectangle on the viewport occupied by the item at \a index. | - | ||||||||||||||||||||||||
| 456 | - | |||||||||||||||||||||||||
| 457 | If your item is displayed in several areas then visualRect should return | - | ||||||||||||||||||||||||
| 458 | the primary area that contains index and not the complete area that index | - | ||||||||||||||||||||||||
| 459 | might encompasses, touch or cause drawing. | - | ||||||||||||||||||||||||
| 460 | - | |||||||||||||||||||||||||
| 461 | In the base class this is a pure virtual function. | - | ||||||||||||||||||||||||
| 462 | - | |||||||||||||||||||||||||
| 463 | \sa indexAt(), visualRegionForSelection() | - | ||||||||||||||||||||||||
| 464 | */ | - | ||||||||||||||||||||||||
| 465 | - | |||||||||||||||||||||||||
| 466 | /*! | - | ||||||||||||||||||||||||
| 467 | \fn void QAbstractItemView::scrollTo(const QModelIndex &index, ScrollHint hint) = 0 | - | ||||||||||||||||||||||||
| 468 | - | |||||||||||||||||||||||||
| 469 | Scrolls the view if necessary to ensure that the item at \a index | - | ||||||||||||||||||||||||
| 470 | is visible. The view will try to position the item according to the given \a hint. | - | ||||||||||||||||||||||||
| 471 | - | |||||||||||||||||||||||||
| 472 | In the base class this is a pure virtual function. | - | ||||||||||||||||||||||||
| 473 | */ | - | ||||||||||||||||||||||||
| 474 | - | |||||||||||||||||||||||||
| 475 | /*! | - | ||||||||||||||||||||||||
| 476 | \fn QModelIndex QAbstractItemView::indexAt(const QPoint &point) const = 0 | - | ||||||||||||||||||||||||
| 477 | - | |||||||||||||||||||||||||
| 478 | Returns the model index of the item at the viewport coordinates \a point. | - | ||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | In the base class this is a pure virtual function. | - | ||||||||||||||||||||||||
| 481 | - | |||||||||||||||||||||||||
| 482 | \sa visualRect() | - | ||||||||||||||||||||||||
| 483 | */ | - | ||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||
| 485 | /*! | - | ||||||||||||||||||||||||
| 486 | \fn void QAbstractItemView::activated(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 487 | - | |||||||||||||||||||||||||
| 488 | This signal is emitted when the item specified by \a index is | - | ||||||||||||||||||||||||
| 489 | activated by the user. How to activate items depends on the | - | ||||||||||||||||||||||||
| 490 | platform; e.g., by single- or double-clicking the item, or by | - | ||||||||||||||||||||||||
| 491 | pressing the Return or Enter key when the item is current. | - | ||||||||||||||||||||||||
| 492 | - | |||||||||||||||||||||||||
| 493 | \sa clicked(), doubleClicked(), entered(), pressed() | - | ||||||||||||||||||||||||
| 494 | */ | - | ||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||
| 496 | /*! | - | ||||||||||||||||||||||||
| 497 | \fn void QAbstractItemView::entered(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 498 | - | |||||||||||||||||||||||||
| 499 | This signal is emitted when the mouse cursor enters the item | - | ||||||||||||||||||||||||
| 500 | specified by \a index. | - | ||||||||||||||||||||||||
| 501 | Mouse tracking needs to be enabled for this feature to work. | - | ||||||||||||||||||||||||
| 502 | - | |||||||||||||||||||||||||
| 503 | \sa viewportEntered(), activated(), clicked(), doubleClicked(), pressed() | - | ||||||||||||||||||||||||
| 504 | */ | - | ||||||||||||||||||||||||
| 505 | - | |||||||||||||||||||||||||
| 506 | /*! | - | ||||||||||||||||||||||||
| 507 | \fn void QAbstractItemView::viewportEntered() | - | ||||||||||||||||||||||||
| 508 | - | |||||||||||||||||||||||||
| 509 | This signal is emitted when the mouse cursor enters the viewport. | - | ||||||||||||||||||||||||
| 510 | Mouse tracking needs to be enabled for this feature to work. | - | ||||||||||||||||||||||||
| 511 | - | |||||||||||||||||||||||||
| 512 | \sa entered() | - | ||||||||||||||||||||||||
| 513 | */ | - | ||||||||||||||||||||||||
| 514 | - | |||||||||||||||||||||||||
| 515 | /*! | - | ||||||||||||||||||||||||
| 516 | \fn void QAbstractItemView::pressed(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 517 | - | |||||||||||||||||||||||||
| 518 | This signal is emitted when a mouse button is pressed. The item | - | ||||||||||||||||||||||||
| 519 | the mouse was pressed on is specified by \a index. The signal is | - | ||||||||||||||||||||||||
| 520 | only emitted when the index is valid. | - | ||||||||||||||||||||||||
| 521 | - | |||||||||||||||||||||||||
| 522 | Use the QApplication::mouseButtons() function to get the state | - | ||||||||||||||||||||||||
| 523 | of the mouse buttons. | - | ||||||||||||||||||||||||
| 524 | - | |||||||||||||||||||||||||
| 525 | \sa activated(), clicked(), doubleClicked(), entered() | - | ||||||||||||||||||||||||
| 526 | */ | - | ||||||||||||||||||||||||
| 527 | - | |||||||||||||||||||||||||
| 528 | /*! | - | ||||||||||||||||||||||||
| 529 | \fn void QAbstractItemView::clicked(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 530 | - | |||||||||||||||||||||||||
| 531 | This signal is emitted when a mouse button is left-clicked. The item | - | ||||||||||||||||||||||||
| 532 | the mouse was clicked on is specified by \a index. The signal is | - | ||||||||||||||||||||||||
| 533 | only emitted when the index is valid. | - | ||||||||||||||||||||||||
| 534 | - | |||||||||||||||||||||||||
| 535 | \sa activated(), doubleClicked(), entered(), pressed() | - | ||||||||||||||||||||||||
| 536 | */ | - | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | /*! | - | ||||||||||||||||||||||||
| 539 | \fn void QAbstractItemView::doubleClicked(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 540 | - | |||||||||||||||||||||||||
| 541 | This signal is emitted when a mouse button is double-clicked. The | - | ||||||||||||||||||||||||
| 542 | item the mouse was double-clicked on is specified by \a index. | - | ||||||||||||||||||||||||
| 543 | The signal is only emitted when the index is valid. | - | ||||||||||||||||||||||||
| 544 | - | |||||||||||||||||||||||||
| 545 | \sa clicked(), activated() | - | ||||||||||||||||||||||||
| 546 | */ | - | ||||||||||||||||||||||||
| 547 | - | |||||||||||||||||||||||||
| 548 | /*! | - | ||||||||||||||||||||||||
| 549 | \fn QModelIndex QAbstractItemView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) = 0 | - | ||||||||||||||||||||||||
| 550 | - | |||||||||||||||||||||||||
| 551 | Returns a QModelIndex object pointing to the next object in the view, | - | ||||||||||||||||||||||||
| 552 | based on the given \a cursorAction and keyboard modifiers specified | - | ||||||||||||||||||||||||
| 553 | by \a modifiers. | - | ||||||||||||||||||||||||
| 554 | - | |||||||||||||||||||||||||
| 555 | In the base class this is a pure virtual function. | - | ||||||||||||||||||||||||
| 556 | */ | - | ||||||||||||||||||||||||
| 557 | - | |||||||||||||||||||||||||
| 558 | /*! | - | ||||||||||||||||||||||||
| 559 | \fn int QAbstractItemView::horizontalOffset() const = 0 | - | ||||||||||||||||||||||||
| 560 | - | |||||||||||||||||||||||||
| 561 | Returns the horizontal offset of the view. | - | ||||||||||||||||||||||||
| 562 | - | |||||||||||||||||||||||||
| 563 | In the base class this is a pure virtual function. | - | ||||||||||||||||||||||||
| 564 | - | |||||||||||||||||||||||||
| 565 | \sa verticalOffset() | - | ||||||||||||||||||||||||
| 566 | */ | - | ||||||||||||||||||||||||
| 567 | - | |||||||||||||||||||||||||
| 568 | /*! | - | ||||||||||||||||||||||||
| 569 | \fn int QAbstractItemView::verticalOffset() const = 0 | - | ||||||||||||||||||||||||
| 570 | - | |||||||||||||||||||||||||
| 571 | Returns the vertical offset of the view. | - | ||||||||||||||||||||||||
| 572 | - | |||||||||||||||||||||||||
| 573 | In the base class this is a pure virtual function. | - | ||||||||||||||||||||||||
| 574 | - | |||||||||||||||||||||||||
| 575 | \sa horizontalOffset() | - | ||||||||||||||||||||||||
| 576 | */ | - | ||||||||||||||||||||||||
| 577 | - | |||||||||||||||||||||||||
| 578 | /*! | - | ||||||||||||||||||||||||
| 579 | \fn bool QAbstractItemView::isIndexHidden(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 580 | - | |||||||||||||||||||||||||
| 581 | Returns \c true if the item referred to by the given \a index is hidden in the view, | - | ||||||||||||||||||||||||
| 582 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 583 | - | |||||||||||||||||||||||||
| 584 | Hiding is a view specific feature. For example in TableView a column can be marked | - | ||||||||||||||||||||||||
| 585 | as hidden or a row in the TreeView. | - | ||||||||||||||||||||||||
| 586 | - | |||||||||||||||||||||||||
| 587 | In the base class this is a pure virtual function. | - | ||||||||||||||||||||||||
| 588 | */ | - | ||||||||||||||||||||||||
| 589 | - | |||||||||||||||||||||||||
| 590 | /*! | - | ||||||||||||||||||||||||
| 591 | \fn void QAbstractItemView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) | - | ||||||||||||||||||||||||
| 592 | - | |||||||||||||||||||||||||
| 593 | Applies the selection \a flags to the items in or touched by the | - | ||||||||||||||||||||||||
| 594 | rectangle, \a rect. | - | ||||||||||||||||||||||||
| 595 | - | |||||||||||||||||||||||||
| 596 | When implementing your own itemview setSelection should call | - | ||||||||||||||||||||||||
| 597 | selectionModel()->select(selection, flags) where selection | - | ||||||||||||||||||||||||
| 598 | is either an empty QModelIndex or a QItemSelection that contains | - | ||||||||||||||||||||||||
| 599 | all items that are contained in \a rect. | - | ||||||||||||||||||||||||
| 600 | - | |||||||||||||||||||||||||
| 601 | \sa selectionCommand(), selectedIndexes() | - | ||||||||||||||||||||||||
| 602 | */ | - | ||||||||||||||||||||||||
| 603 | - | |||||||||||||||||||||||||
| 604 | /*! | - | ||||||||||||||||||||||||
| 605 | \fn QRegion QAbstractItemView::visualRegionForSelection(const QItemSelection &selection) const = 0 | - | ||||||||||||||||||||||||
| 606 | - | |||||||||||||||||||||||||
| 607 | Returns the region from the viewport of the items in the given | - | ||||||||||||||||||||||||
| 608 | \a selection. | - | ||||||||||||||||||||||||
| 609 | - | |||||||||||||||||||||||||
| 610 | In the base class this is a pure virtual function. | - | ||||||||||||||||||||||||
| 611 | - | |||||||||||||||||||||||||
| 612 | \sa visualRect(), selectedIndexes() | - | ||||||||||||||||||||||||
| 613 | */ | - | ||||||||||||||||||||||||
| 614 | - | |||||||||||||||||||||||||
| 615 | /*! | - | ||||||||||||||||||||||||
| 616 | Constructs an abstract item view with the given \a parent. | - | ||||||||||||||||||||||||
| 617 | */ | - | ||||||||||||||||||||||||
| 618 | QAbstractItemView::QAbstractItemView(QWidget *parent) | - | ||||||||||||||||||||||||
| 619 | : QAbstractScrollArea(*(new QAbstractItemViewPrivate), parent) | - | ||||||||||||||||||||||||
| 620 | { | - | ||||||||||||||||||||||||
| 621 | d_func()->init(); | - | ||||||||||||||||||||||||
| 622 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 623 | - | |||||||||||||||||||||||||
| 624 | /*! | - | ||||||||||||||||||||||||
| 625 | \internal | - | ||||||||||||||||||||||||
| 626 | */ | - | ||||||||||||||||||||||||
| 627 | QAbstractItemView::QAbstractItemView(QAbstractItemViewPrivate &dd, QWidget *parent) | - | ||||||||||||||||||||||||
| 628 | : QAbstractScrollArea(dd, parent) | - | ||||||||||||||||||||||||
| 629 | { | - | ||||||||||||||||||||||||
| 630 | d_func()->init(); | - | ||||||||||||||||||||||||
| 631 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 632 | - | |||||||||||||||||||||||||
| 633 | /*! | - | ||||||||||||||||||||||||
| 634 | Destroys the view. | - | ||||||||||||||||||||||||
| 635 | */ | - | ||||||||||||||||||||||||
| 636 | QAbstractItemView::~QAbstractItemView() | - | ||||||||||||||||||||||||
| 637 | { | - | ||||||||||||||||||||||||
| 638 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 639 | // stop these timers here before ~QObject | - | ||||||||||||||||||||||||
| 640 | d->delayedReset.stop(); | - | ||||||||||||||||||||||||
| 641 | d->updateTimer.stop(); | - | ||||||||||||||||||||||||
| 642 | d->delayedEditing.stop(); | - | ||||||||||||||||||||||||
| 643 | d->delayedAutoScroll.stop(); | - | ||||||||||||||||||||||||
| 644 | d->autoScrollTimer.stop(); | - | ||||||||||||||||||||||||
| 645 | d->delayedLayout.stop(); | - | ||||||||||||||||||||||||
| 646 | d->fetchMoreTimer.stop(); | - | ||||||||||||||||||||||||
| 647 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 648 | - | |||||||||||||||||||||||||
| 649 | /*! | - | ||||||||||||||||||||||||
| 650 | Sets the \a model for the view to present. | - | ||||||||||||||||||||||||
| 651 | - | |||||||||||||||||||||||||
| 652 | This function will create and set a new selection model, replacing any | - | ||||||||||||||||||||||||
| 653 | model that was previously set with setSelectionModel(). However, the old | - | ||||||||||||||||||||||||
| 654 | selection model will not be deleted as it may be shared between several | - | ||||||||||||||||||||||||
| 655 | views. We recommend that you delete the old selection model if it is no | - | ||||||||||||||||||||||||
| 656 | longer required. This is done with the following code: | - | ||||||||||||||||||||||||
| 657 | - | |||||||||||||||||||||||||
| 658 | \snippet code/src_gui_itemviews_qabstractitemview.cpp 2 | - | ||||||||||||||||||||||||
| 659 | - | |||||||||||||||||||||||||
| 660 | If both the old model and the old selection model do not have parents, or | - | ||||||||||||||||||||||||
| 661 | if their parents are long-lived objects, it may be preferable to call their | - | ||||||||||||||||||||||||
| 662 | deleteLater() functions to explicitly delete them. | - | ||||||||||||||||||||||||
| 663 | - | |||||||||||||||||||||||||
| 664 | The view \e{does not} take ownership of the model unless it is the model's | - | ||||||||||||||||||||||||
| 665 | parent object because the model may be shared between many different views. | - | ||||||||||||||||||||||||
| 666 | - | |||||||||||||||||||||||||
| 667 | \sa selectionModel(), setSelectionModel() | - | ||||||||||||||||||||||||
| 668 | */ | - | ||||||||||||||||||||||||
| 669 | void QAbstractItemView::setModel(QAbstractItemModel *model) | - | ||||||||||||||||||||||||
| 670 | { | - | ||||||||||||||||||||||||
| 671 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 672 | if (model == d->model)
| 0 | ||||||||||||||||||||||||
| 673 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 674 | if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
| 0 | ||||||||||||||||||||||||
| 675 | disconnect(d->model, SIGNAL(destroyed()), | - | ||||||||||||||||||||||||
| 676 | this, SLOT(_q_modelDestroyed())); | - | ||||||||||||||||||||||||
| 677 | disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), | - | ||||||||||||||||||||||||
| 678 | this, SLOT(dataChanged(QModelIndex,QModelIndex,QVector<int>))); | - | ||||||||||||||||||||||||
| 679 | disconnect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), | - | ||||||||||||||||||||||||
| 680 | this, SLOT(_q_headerDataChanged())); | - | ||||||||||||||||||||||||
| 681 | disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 682 | this, SLOT(rowsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 683 | disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 684 | this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 685 | disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 686 | this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 687 | disconnect(d->model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||||||||
| 688 | this, SLOT(_q_rowsMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||||||||
| 689 | disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 690 | this, SLOT(_q_rowsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 691 | disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 692 | this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 693 | disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 694 | this, SLOT(_q_columnsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 695 | disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 696 | this, SLOT(_q_columnsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 697 | disconnect(d->model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||||||||
| 698 | this, SLOT(_q_columnsMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||||||||
| 699 | - | |||||||||||||||||||||||||
| 700 | disconnect(d->model, SIGNAL(modelReset()), this, SLOT(reset())); | - | ||||||||||||||||||||||||
| 701 | disconnect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged())); | - | ||||||||||||||||||||||||
| 702 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 703 | d->model = (model ? model : QAbstractItemModelPrivate::staticEmptyModel());
| 0 | ||||||||||||||||||||||||
| 704 | - | |||||||||||||||||||||||||
| 705 | // These asserts do basic sanity checking of the model | - | ||||||||||||||||||||||||
| 706 | Q_ASSERT_X(d->model->index(0,0) == d->model->index(0,0), | - | ||||||||||||||||||||||||
| 707 | "QAbstractItemView::setModel", | - | ||||||||||||||||||||||||
| 708 | "A model should return the exact same index " | - | ||||||||||||||||||||||||
| 709 | "(including its internal id/pointer) when asked for it twice in a row."); | - | ||||||||||||||||||||||||
| 710 | Q_ASSERT_X(!d->model->index(0,0).parent().isValid(), | - | ||||||||||||||||||||||||
| 711 | "QAbstractItemView::setModel", | - | ||||||||||||||||||||||||
| 712 | "The parent of a top level index should be invalid"); | - | ||||||||||||||||||||||||
| 713 | - | |||||||||||||||||||||||||
| 714 | if (d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
| 0 | ||||||||||||||||||||||||
| 715 | connect(d->model, SIGNAL(destroyed()), | - | ||||||||||||||||||||||||
| 716 | this, SLOT(_q_modelDestroyed())); | - | ||||||||||||||||||||||||
| 717 | connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), | - | ||||||||||||||||||||||||
| 718 | this, SLOT(dataChanged(QModelIndex,QModelIndex,QVector<int>))); | - | ||||||||||||||||||||||||
| 719 | connect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), | - | ||||||||||||||||||||||||
| 720 | this, SLOT(_q_headerDataChanged())); | - | ||||||||||||||||||||||||
| 721 | connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 722 | this, SLOT(rowsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 723 | connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 724 | this, SLOT(_q_rowsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 725 | connect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 726 | this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 727 | connect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 728 | this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 729 | connect(d->model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||||||||
| 730 | this, SLOT(_q_rowsMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||||||||
| 731 | connect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 732 | this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 733 | connect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 734 | this, SLOT(_q_columnsRemoved(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 735 | connect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)), | - | ||||||||||||||||||||||||
| 736 | this, SLOT(_q_columnsInserted(QModelIndex,int,int))); | - | ||||||||||||||||||||||||
| 737 | connect(d->model, SIGNAL(columnsMoved(QModelIndex,int,int,QModelIndex,int)), | - | ||||||||||||||||||||||||
| 738 | this, SLOT(_q_columnsMoved(QModelIndex,int,int,QModelIndex,int))); | - | ||||||||||||||||||||||||
| 739 | - | |||||||||||||||||||||||||
| 740 | connect(d->model, SIGNAL(modelReset()), this, SLOT(reset())); | - | ||||||||||||||||||||||||
| 741 | connect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged())); | - | ||||||||||||||||||||||||
| 742 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 743 | - | |||||||||||||||||||||||||
| 744 | QItemSelectionModel *selection_model = new QItemSelectionModel(d->model, this); | - | ||||||||||||||||||||||||
| 745 | connect(d->model, SIGNAL(destroyed()), selection_model, SLOT(deleteLater())); | - | ||||||||||||||||||||||||
| 746 | setSelectionModel(selection_model); | - | ||||||||||||||||||||||||
| 747 | - | |||||||||||||||||||||||||
| 748 | reset(); // kill editors, set new root and do layout | - | ||||||||||||||||||||||||
| 749 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 750 | - | |||||||||||||||||||||||||
| 751 | /*! | - | ||||||||||||||||||||||||
| 752 | Returns the model that this view is presenting. | - | ||||||||||||||||||||||||
| 753 | */ | - | ||||||||||||||||||||||||
| 754 | QAbstractItemModel *QAbstractItemView::model() const | - | ||||||||||||||||||||||||
| 755 | { | - | ||||||||||||||||||||||||
| 756 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 757 | return (d->model == QAbstractItemModelPrivate::staticEmptyModel() ? 0 : d->model); never executed: return (d->model == QAbstractItemModelPrivate::staticEmptyModel() ? 0 : d->model); | 0 | ||||||||||||||||||||||||
| 758 | } | - | ||||||||||||||||||||||||
| 759 | - | |||||||||||||||||||||||||
| 760 | /*! | - | ||||||||||||||||||||||||
| 761 | Sets the current selection model to the given \a selectionModel. | - | ||||||||||||||||||||||||
| 762 | - | |||||||||||||||||||||||||
| 763 | Note that, if you call setModel() after this function, the given \a selectionModel | - | ||||||||||||||||||||||||
| 764 | will be replaced by one created by the view. | - | ||||||||||||||||||||||||
| 765 | - | |||||||||||||||||||||||||
| 766 | \note It is up to the application to delete the old selection model if it is no | - | ||||||||||||||||||||||||
| 767 | longer needed; i.e., if it is not being used by other views. This will happen | - | ||||||||||||||||||||||||
| 768 | automatically when its parent object is deleted. However, if it does not have a | - | ||||||||||||||||||||||||
| 769 | parent, or if the parent is a long-lived object, it may be preferable to call its | - | ||||||||||||||||||||||||
| 770 | deleteLater() function to explicitly delete it. | - | ||||||||||||||||||||||||
| 771 | - | |||||||||||||||||||||||||
| 772 | \sa selectionModel(), setModel(), clearSelection() | - | ||||||||||||||||||||||||
| 773 | */ | - | ||||||||||||||||||||||||
| 774 | void QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel) | - | ||||||||||||||||||||||||
| 775 | { | - | ||||||||||||||||||||||||
| 776 | // ### if the given model is null, we should use the original selection model | - | ||||||||||||||||||||||||
| 777 | Q_ASSERT(selectionModel); | - | ||||||||||||||||||||||||
| 778 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 779 | - | |||||||||||||||||||||||||
| 780 | if (Q_UNLIKELY(selectionModel->model() != d->model)) {
| 0 | ||||||||||||||||||||||||
| 781 | qWarning("QAbstractItemView::setSelectionModel() failed: " | - | ||||||||||||||||||||||||
| 782 | "Trying to set a selection model, which works on " | - | ||||||||||||||||||||||||
| 783 | "a different model than the view."); | - | ||||||||||||||||||||||||
| 784 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 785 | } | - | ||||||||||||||||||||||||
| 786 | - | |||||||||||||||||||||||||
| 787 | QItemSelection oldSelection; | - | ||||||||||||||||||||||||
| 788 | QModelIndex oldCurrentIndex; | - | ||||||||||||||||||||||||
| 789 | - | |||||||||||||||||||||||||
| 790 | if (d->selectionModel) {
| 0 | ||||||||||||||||||||||||
| 791 | if (d->selectionModel->model() == selectionModel->model()) {
| 0 | ||||||||||||||||||||||||
| 792 | oldSelection = d->selectionModel->selection(); | - | ||||||||||||||||||||||||
| 793 | oldCurrentIndex = d->selectionModel->currentIndex(); | - | ||||||||||||||||||||||||
| 794 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 795 | - | |||||||||||||||||||||||||
| 796 | disconnect(d->selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | - | ||||||||||||||||||||||||
| 797 | this, SLOT(selectionChanged(QItemSelection,QItemSelection))); | - | ||||||||||||||||||||||||
| 798 | disconnect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||||||||
| 799 | this, SLOT(currentChanged(QModelIndex,QModelIndex))); | - | ||||||||||||||||||||||||
| 800 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 801 | - | |||||||||||||||||||||||||
| 802 | d->selectionModel = selectionModel; | - | ||||||||||||||||||||||||
| 803 | - | |||||||||||||||||||||||||
| 804 | if (d->selectionModel) {
| 0 | ||||||||||||||||||||||||
| 805 | connect(d->selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | - | ||||||||||||||||||||||||
| 806 | this, SLOT(selectionChanged(QItemSelection,QItemSelection))); | - | ||||||||||||||||||||||||
| 807 | connect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), | - | ||||||||||||||||||||||||
| 808 | this, SLOT(currentChanged(QModelIndex,QModelIndex))); | - | ||||||||||||||||||||||||
| 809 | - | |||||||||||||||||||||||||
| 810 | selectionChanged(d->selectionModel->selection(), oldSelection); | - | ||||||||||||||||||||||||
| 811 | currentChanged(d->selectionModel->currentIndex(), oldCurrentIndex); | - | ||||||||||||||||||||||||
| 812 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 813 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 814 | - | |||||||||||||||||||||||||
| 815 | /*! | - | ||||||||||||||||||||||||
| 816 | Returns the current selection model. | - | ||||||||||||||||||||||||
| 817 | - | |||||||||||||||||||||||||
| 818 | \sa setSelectionModel(), selectedIndexes() | - | ||||||||||||||||||||||||
| 819 | */ | - | ||||||||||||||||||||||||
| 820 | QItemSelectionModel* QAbstractItemView::selectionModel() const | - | ||||||||||||||||||||||||
| 821 | { | - | ||||||||||||||||||||||||
| 822 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 823 | return d->selectionModel; never executed: return d->selectionModel; | 0 | ||||||||||||||||||||||||
| 824 | } | - | ||||||||||||||||||||||||
| 825 | - | |||||||||||||||||||||||||
| 826 | /*! | - | ||||||||||||||||||||||||
| 827 | Sets the item delegate for this view and its model to \a delegate. | - | ||||||||||||||||||||||||
| 828 | This is useful if you want complete control over the editing and | - | ||||||||||||||||||||||||
| 829 | display of items. | - | ||||||||||||||||||||||||
| 830 | - | |||||||||||||||||||||||||
| 831 | Any existing delegate will be removed, but not deleted. QAbstractItemView | - | ||||||||||||||||||||||||
| 832 | does not take ownership of \a delegate. | - | ||||||||||||||||||||||||
| 833 | - | |||||||||||||||||||||||||
| 834 | \warning You should not share the same instance of a delegate between views. | - | ||||||||||||||||||||||||
| 835 | Doing so can cause incorrect or unintuitive editing behavior since each | - | ||||||||||||||||||||||||
| 836 | view connected to a given delegate may receive the \l{QAbstractItemDelegate::}{closeEditor()} | - | ||||||||||||||||||||||||
| 837 | signal, and attempt to access, modify or close an editor that has already been closed. | - | ||||||||||||||||||||||||
| 838 | - | |||||||||||||||||||||||||
| 839 | \sa itemDelegate() | - | ||||||||||||||||||||||||
| 840 | */ | - | ||||||||||||||||||||||||
| 841 | void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *delegate) | - | ||||||||||||||||||||||||
| 842 | { | - | ||||||||||||||||||||||||
| 843 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 844 | if (delegate == d->itemDelegate)
| 0 | ||||||||||||||||||||||||
| 845 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 846 | - | |||||||||||||||||||||||||
| 847 | if (d->itemDelegate) {
| 0 | ||||||||||||||||||||||||
| 848 | if (d->delegateRefCount(d->itemDelegate) == 1) {
| 0 | ||||||||||||||||||||||||
| 849 | disconnect(d->itemDelegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), | - | ||||||||||||||||||||||||
| 850 | this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); | - | ||||||||||||||||||||||||
| 851 | disconnect(d->itemDelegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); | - | ||||||||||||||||||||||||
| 852 | disconnect(d->itemDelegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout())); | - | ||||||||||||||||||||||||
| 853 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 854 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 855 | - | |||||||||||||||||||||||||
| 856 | if (delegate) {
| 0 | ||||||||||||||||||||||||
| 857 | if (d->delegateRefCount(delegate) == 0) {
| 0 | ||||||||||||||||||||||||
| 858 | connect(delegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), | - | ||||||||||||||||||||||||
| 859 | this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); | - | ||||||||||||||||||||||||
| 860 | connect(delegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); | - | ||||||||||||||||||||||||
| 861 | connect(delegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout()), Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 862 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 863 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 864 | d->itemDelegate = delegate; | - | ||||||||||||||||||||||||
| 865 | viewport()->update(); | - | ||||||||||||||||||||||||
| 866 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 867 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 868 | - | |||||||||||||||||||||||||
| 869 | /*! | - | ||||||||||||||||||||||||
| 870 | Returns the item delegate used by this view and model. This is | - | ||||||||||||||||||||||||
| 871 | either one set with setItemDelegate(), or the default one. | - | ||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||
| 873 | \sa setItemDelegate() | - | ||||||||||||||||||||||||
| 874 | */ | - | ||||||||||||||||||||||||
| 875 | QAbstractItemDelegate *QAbstractItemView::itemDelegate() const | - | ||||||||||||||||||||||||
| 876 | { | - | ||||||||||||||||||||||||
| 877 | return d_func()->itemDelegate; never executed: return d_func()->itemDelegate; | 0 | ||||||||||||||||||||||||
| 878 | } | - | ||||||||||||||||||||||||
| 879 | - | |||||||||||||||||||||||||
| 880 | /*! | - | ||||||||||||||||||||||||
| 881 | \reimp | - | ||||||||||||||||||||||||
| 882 | */ | - | ||||||||||||||||||||||||
| 883 | QVariant QAbstractItemView::inputMethodQuery(Qt::InputMethodQuery query) const | - | ||||||||||||||||||||||||
| 884 | { | - | ||||||||||||||||||||||||
| 885 | const QModelIndex current = currentIndex(); | - | ||||||||||||||||||||||||
| 886 | if (!current.isValid() || query != Qt::ImCursorRectangle)
| 0 | ||||||||||||||||||||||||
| 887 | return QAbstractScrollArea::inputMethodQuery(query); never executed: return QAbstractScrollArea::inputMethodQuery(query); | 0 | ||||||||||||||||||||||||
| 888 | return visualRect(current); never executed: return visualRect(current); | 0 | ||||||||||||||||||||||||
| 889 | } | - | ||||||||||||||||||||||||
| 890 | - | |||||||||||||||||||||||||
| 891 | /*! | - | ||||||||||||||||||||||||
| 892 | \since 4.2 | - | ||||||||||||||||||||||||
| 893 | - | |||||||||||||||||||||||||
| 894 | Sets the given item \a delegate used by this view and model for the given | - | ||||||||||||||||||||||||
| 895 | \a row. All items on \a row will be drawn and managed by \a delegate | - | ||||||||||||||||||||||||
| 896 | instead of using the default delegate (i.e., itemDelegate()). | - | ||||||||||||||||||||||||
| 897 | - | |||||||||||||||||||||||||
| 898 | Any existing row delegate for \a row will be removed, but not | - | ||||||||||||||||||||||||
| 899 | deleted. QAbstractItemView does not take ownership of \a delegate. | - | ||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||
| 901 | \note If a delegate has been assigned to both a row and a column, the row | - | ||||||||||||||||||||||||
| 902 | delegate (i.e., this delegate) will take precedence and manage the | - | ||||||||||||||||||||||||
| 903 | intersecting cell index. | - | ||||||||||||||||||||||||
| 904 | - | |||||||||||||||||||||||||
| 905 | \warning You should not share the same instance of a delegate between views. | - | ||||||||||||||||||||||||
| 906 | Doing so can cause incorrect or unintuitive editing behavior since each | - | ||||||||||||||||||||||||
| 907 | view connected to a given delegate may receive the \l{QAbstractItemDelegate::}{closeEditor()} | - | ||||||||||||||||||||||||
| 908 | signal, and attempt to access, modify or close an editor that has already been closed. | - | ||||||||||||||||||||||||
| 909 | - | |||||||||||||||||||||||||
| 910 | \sa itemDelegateForRow(), setItemDelegateForColumn(), itemDelegate() | - | ||||||||||||||||||||||||
| 911 | */ | - | ||||||||||||||||||||||||
| 912 | void QAbstractItemView::setItemDelegateForRow(int row, QAbstractItemDelegate *delegate) | - | ||||||||||||||||||||||||
| 913 | { | - | ||||||||||||||||||||||||
| 914 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 915 | if (QAbstractItemDelegate *rowDelegate = d->rowDelegates.value(row, 0)) {
| 0 | ||||||||||||||||||||||||
| 916 | if (d->delegateRefCount(rowDelegate) == 1) {
| 0 | ||||||||||||||||||||||||
| 917 | disconnect(rowDelegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), | - | ||||||||||||||||||||||||
| 918 | this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); | - | ||||||||||||||||||||||||
| 919 | disconnect(rowDelegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); | - | ||||||||||||||||||||||||
| 920 | disconnect(rowDelegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout())); | - | ||||||||||||||||||||||||
| 921 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 922 | d->rowDelegates.remove(row); | - | ||||||||||||||||||||||||
| 923 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 924 | if (delegate) {
| 0 | ||||||||||||||||||||||||
| 925 | if (d->delegateRefCount(delegate) == 0) {
| 0 | ||||||||||||||||||||||||
| 926 | connect(delegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), | - | ||||||||||||||||||||||||
| 927 | this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); | - | ||||||||||||||||||||||||
| 928 | connect(delegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); | - | ||||||||||||||||||||||||
| 929 | connect(delegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout()), Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 930 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 931 | d->rowDelegates.insert(row, delegate); | - | ||||||||||||||||||||||||
| 932 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 933 | viewport()->update(); | - | ||||||||||||||||||||||||
| 934 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 935 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 936 | - | |||||||||||||||||||||||||
| 937 | /*! | - | ||||||||||||||||||||||||
| 938 | \since 4.2 | - | ||||||||||||||||||||||||
| 939 | - | |||||||||||||||||||||||||
| 940 | Returns the item delegate used by this view and model for the given \a row, | - | ||||||||||||||||||||||||
| 941 | or 0 if no delegate has been assigned. You can call itemDelegate() to get a | - | ||||||||||||||||||||||||
| 942 | pointer to the current delegate for a given index. | - | ||||||||||||||||||||||||
| 943 | - | |||||||||||||||||||||||||
| 944 | \sa setItemDelegateForRow(), itemDelegateForColumn(), setItemDelegate() | - | ||||||||||||||||||||||||
| 945 | */ | - | ||||||||||||||||||||||||
| 946 | QAbstractItemDelegate *QAbstractItemView::itemDelegateForRow(int row) const | - | ||||||||||||||||||||||||
| 947 | { | - | ||||||||||||||||||||||||
| 948 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 949 | return d->rowDelegates.value(row, 0); never executed: return d->rowDelegates.value(row, 0); | 0 | ||||||||||||||||||||||||
| 950 | } | - | ||||||||||||||||||||||||
| 951 | - | |||||||||||||||||||||||||
| 952 | /*! | - | ||||||||||||||||||||||||
| 953 | \since 4.2 | - | ||||||||||||||||||||||||
| 954 | - | |||||||||||||||||||||||||
| 955 | Sets the given item \a delegate used by this view and model for the given | - | ||||||||||||||||||||||||
| 956 | \a column. All items on \a column will be drawn and managed by \a delegate | - | ||||||||||||||||||||||||
| 957 | instead of using the default delegate (i.e., itemDelegate()). | - | ||||||||||||||||||||||||
| 958 | - | |||||||||||||||||||||||||
| 959 | Any existing column delegate for \a column will be removed, but not | - | ||||||||||||||||||||||||
| 960 | deleted. QAbstractItemView does not take ownership of \a delegate. | - | ||||||||||||||||||||||||
| 961 | - | |||||||||||||||||||||||||
| 962 | \note If a delegate has been assigned to both a row and a column, the row | - | ||||||||||||||||||||||||
| 963 | delegate will take precedence and manage the intersecting cell index. | - | ||||||||||||||||||||||||
| 964 | - | |||||||||||||||||||||||||
| 965 | \warning You should not share the same instance of a delegate between views. | - | ||||||||||||||||||||||||
| 966 | Doing so can cause incorrect or unintuitive editing behavior since each | - | ||||||||||||||||||||||||
| 967 | view connected to a given delegate may receive the \l{QAbstractItemDelegate::}{closeEditor()} | - | ||||||||||||||||||||||||
| 968 | signal, and attempt to access, modify or close an editor that has already been closed. | - | ||||||||||||||||||||||||
| 969 | - | |||||||||||||||||||||||||
| 970 | \sa itemDelegateForColumn(), setItemDelegateForRow(), itemDelegate() | - | ||||||||||||||||||||||||
| 971 | */ | - | ||||||||||||||||||||||||
| 972 | void QAbstractItemView::setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate) | - | ||||||||||||||||||||||||
| 973 | { | - | ||||||||||||||||||||||||
| 974 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 975 | if (QAbstractItemDelegate *columnDelegate = d->columnDelegates.value(column, 0)) {
| 0 | ||||||||||||||||||||||||
| 976 | if (d->delegateRefCount(columnDelegate) == 1) {
| 0 | ||||||||||||||||||||||||
| 977 | disconnect(columnDelegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), | - | ||||||||||||||||||||||||
| 978 | this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); | - | ||||||||||||||||||||||||
| 979 | disconnect(columnDelegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); | - | ||||||||||||||||||||||||
| 980 | disconnect(columnDelegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout())); | - | ||||||||||||||||||||||||
| 981 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 982 | d->columnDelegates.remove(column); | - | ||||||||||||||||||||||||
| 983 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 984 | if (delegate) {
| 0 | ||||||||||||||||||||||||
| 985 | if (d->delegateRefCount(delegate) == 0) {
| 0 | ||||||||||||||||||||||||
| 986 | connect(delegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), | - | ||||||||||||||||||||||||
| 987 | this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); | - | ||||||||||||||||||||||||
| 988 | connect(delegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); | - | ||||||||||||||||||||||||
| 989 | connect(delegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout()), Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 990 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 991 | d->columnDelegates.insert(column, delegate); | - | ||||||||||||||||||||||||
| 992 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 993 | viewport()->update(); | - | ||||||||||||||||||||||||
| 994 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 995 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 996 | - | |||||||||||||||||||||||||
| 997 | /*! | - | ||||||||||||||||||||||||
| 998 | \since 4.2 | - | ||||||||||||||||||||||||
| 999 | - | |||||||||||||||||||||||||
| 1000 | Returns the item delegate used by this view and model for the given \a | - | ||||||||||||||||||||||||
| 1001 | column. You can call itemDelegate() to get a pointer to the current delegate | - | ||||||||||||||||||||||||
| 1002 | for a given index. | - | ||||||||||||||||||||||||
| 1003 | - | |||||||||||||||||||||||||
| 1004 | \sa setItemDelegateForColumn(), itemDelegateForRow(), itemDelegate() | - | ||||||||||||||||||||||||
| 1005 | */ | - | ||||||||||||||||||||||||
| 1006 | QAbstractItemDelegate *QAbstractItemView::itemDelegateForColumn(int column) const | - | ||||||||||||||||||||||||
| 1007 | { | - | ||||||||||||||||||||||||
| 1008 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1009 | return d->columnDelegates.value(column, 0); never executed: return d->columnDelegates.value(column, 0); | 0 | ||||||||||||||||||||||||
| 1010 | } | - | ||||||||||||||||||||||||
| 1011 | - | |||||||||||||||||||||||||
| 1012 | /*! | - | ||||||||||||||||||||||||
| 1013 | Returns the item delegate used by this view and model for | - | ||||||||||||||||||||||||
| 1014 | the given \a index. | - | ||||||||||||||||||||||||
| 1015 | */ | - | ||||||||||||||||||||||||
| 1016 | QAbstractItemDelegate *QAbstractItemView::itemDelegate(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 1017 | { | - | ||||||||||||||||||||||||
| 1018 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1019 | return d->delegateForIndex(index); never executed: return d->delegateForIndex(index); | 0 | ||||||||||||||||||||||||
| 1020 | } | - | ||||||||||||||||||||||||
| 1021 | - | |||||||||||||||||||||||||
| 1022 | /*! | - | ||||||||||||||||||||||||
| 1023 | \property QAbstractItemView::selectionMode | - | ||||||||||||||||||||||||
| 1024 | \brief which selection mode the view operates in | - | ||||||||||||||||||||||||
| 1025 | - | |||||||||||||||||||||||||
| 1026 | This property controls whether the user can select one or many items | - | ||||||||||||||||||||||||
| 1027 | and, in many-item selections, whether the selection must be a | - | ||||||||||||||||||||||||
| 1028 | continuous range of items. | - | ||||||||||||||||||||||||
| 1029 | - | |||||||||||||||||||||||||
| 1030 | \sa SelectionMode, SelectionBehavior | - | ||||||||||||||||||||||||
| 1031 | */ | - | ||||||||||||||||||||||||
| 1032 | void QAbstractItemView::setSelectionMode(SelectionMode mode) | - | ||||||||||||||||||||||||
| 1033 | { | - | ||||||||||||||||||||||||
| 1034 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1035 | d->selectionMode = mode; | - | ||||||||||||||||||||||||
| 1036 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1037 | - | |||||||||||||||||||||||||
| 1038 | QAbstractItemView::SelectionMode QAbstractItemView::selectionMode() const | - | ||||||||||||||||||||||||
| 1039 | { | - | ||||||||||||||||||||||||
| 1040 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1041 | return d->selectionMode; never executed: return d->selectionMode; | 0 | ||||||||||||||||||||||||
| 1042 | } | - | ||||||||||||||||||||||||
| 1043 | - | |||||||||||||||||||||||||
| 1044 | /*! | - | ||||||||||||||||||||||||
| 1045 | \property QAbstractItemView::selectionBehavior | - | ||||||||||||||||||||||||
| 1046 | \brief which selection behavior the view uses | - | ||||||||||||||||||||||||
| 1047 | - | |||||||||||||||||||||||||
| 1048 | This property holds whether selections are done | - | ||||||||||||||||||||||||
| 1049 | in terms of single items, rows or columns. | - | ||||||||||||||||||||||||
| 1050 | - | |||||||||||||||||||||||||
| 1051 | \sa SelectionMode, SelectionBehavior | - | ||||||||||||||||||||||||
| 1052 | */ | - | ||||||||||||||||||||||||
| 1053 | - | |||||||||||||||||||||||||
| 1054 | void QAbstractItemView::setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior) | - | ||||||||||||||||||||||||
| 1055 | { | - | ||||||||||||||||||||||||
| 1056 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1057 | d->selectionBehavior = behavior; | - | ||||||||||||||||||||||||
| 1058 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1059 | - | |||||||||||||||||||||||||
| 1060 | QAbstractItemView::SelectionBehavior QAbstractItemView::selectionBehavior() const | - | ||||||||||||||||||||||||
| 1061 | { | - | ||||||||||||||||||||||||
| 1062 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1063 | return d->selectionBehavior; never executed: return d->selectionBehavior; | 0 | ||||||||||||||||||||||||
| 1064 | } | - | ||||||||||||||||||||||||
| 1065 | - | |||||||||||||||||||||||||
| 1066 | /*! | - | ||||||||||||||||||||||||
| 1067 | Sets the current item to be the item at \a index. | - | ||||||||||||||||||||||||
| 1068 | - | |||||||||||||||||||||||||
| 1069 | Unless the current selection mode is | - | ||||||||||||||||||||||||
| 1070 | \l{QAbstractItemView::}{NoSelection}, the item is also selected. | - | ||||||||||||||||||||||||
| 1071 | Note that this function also updates the starting position for any | - | ||||||||||||||||||||||||
| 1072 | new selections the user performs. | - | ||||||||||||||||||||||||
| 1073 | - | |||||||||||||||||||||||||
| 1074 | To set an item as the current item without selecting it, call | - | ||||||||||||||||||||||||
| 1075 | - | |||||||||||||||||||||||||
| 1076 | \c{selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);} | - | ||||||||||||||||||||||||
| 1077 | - | |||||||||||||||||||||||||
| 1078 | \sa currentIndex(), currentChanged(), selectionMode | - | ||||||||||||||||||||||||
| 1079 | */ | - | ||||||||||||||||||||||||
| 1080 | void QAbstractItemView::setCurrentIndex(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 1081 | { | - | ||||||||||||||||||||||||
| 1082 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1083 | if (d->selectionModel && (!index.isValid() || d->isIndexEnabled(index))) {
| 0 | ||||||||||||||||||||||||
| 1084 | QItemSelectionModel::SelectionFlags command = selectionCommand(index, 0); | - | ||||||||||||||||||||||||
| 1085 | d->selectionModel->setCurrentIndex(index, command); | - | ||||||||||||||||||||||||
| 1086 | d->currentIndexSet = true; | - | ||||||||||||||||||||||||
| 1087 | if ((command & QItemSelectionModel::Current) == 0)
| 0 | ||||||||||||||||||||||||
| 1088 | d->currentSelectionStartIndex = index; never executed: d->currentSelectionStartIndex = index; | 0 | ||||||||||||||||||||||||
| 1089 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1090 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1091 | - | |||||||||||||||||||||||||
| 1092 | /*! | - | ||||||||||||||||||||||||
| 1093 | Returns the model index of the current item. | - | ||||||||||||||||||||||||
| 1094 | - | |||||||||||||||||||||||||
| 1095 | \sa setCurrentIndex() | - | ||||||||||||||||||||||||
| 1096 | */ | - | ||||||||||||||||||||||||
| 1097 | QModelIndex QAbstractItemView::currentIndex() const | - | ||||||||||||||||||||||||
| 1098 | { | - | ||||||||||||||||||||||||
| 1099 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1100 | return d->selectionModel ? d->selectionModel->currentIndex() : QModelIndex(); never executed: return d->selectionModel ? d->selectionModel->currentIndex() : QModelIndex(); | 0 | ||||||||||||||||||||||||
| 1101 | } | - | ||||||||||||||||||||||||
| 1102 | - | |||||||||||||||||||||||||
| 1103 | - | |||||||||||||||||||||||||
| 1104 | /*! | - | ||||||||||||||||||||||||
| 1105 | Reset the internal state of the view. | - | ||||||||||||||||||||||||
| 1106 | - | |||||||||||||||||||||||||
| 1107 | \warning This function will reset open editors, scroll bar positions, | - | ||||||||||||||||||||||||
| 1108 | selections, etc. Existing changes will not be committed. If you would like | - | ||||||||||||||||||||||||
| 1109 | to save your changes when resetting the view, you can reimplement this | - | ||||||||||||||||||||||||
| 1110 | function, commit your changes, and then call the superclass' | - | ||||||||||||||||||||||||
| 1111 | implementation. | - | ||||||||||||||||||||||||
| 1112 | */ | - | ||||||||||||||||||||||||
| 1113 | void QAbstractItemView::reset() | - | ||||||||||||||||||||||||
| 1114 | { | - | ||||||||||||||||||||||||
| 1115 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1116 | d->delayedReset.stop(); //make sure we stop the timer | - | ||||||||||||||||||||||||
| 1117 | foreach (const QEditorInfo &info, d->indexEditorHash) { | - | ||||||||||||||||||||||||
| 1118 | if (info.widget)
| 0 | ||||||||||||||||||||||||
| 1119 | d->releaseEditor(info.widget.data(), d->indexForEditor(info.widget.data())); never executed: d->releaseEditor(info.widget.data(), d->indexForEditor(info.widget.data())); | 0 | ||||||||||||||||||||||||
| 1120 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1121 | d->editorIndexHash.clear(); | - | ||||||||||||||||||||||||
| 1122 | d->indexEditorHash.clear(); | - | ||||||||||||||||||||||||
| 1123 | d->persistent.clear(); | - | ||||||||||||||||||||||||
| 1124 | d->currentIndexSet = false; | - | ||||||||||||||||||||||||
| 1125 | setState(NoState); | - | ||||||||||||||||||||||||
| 1126 | setRootIndex(QModelIndex()); | - | ||||||||||||||||||||||||
| 1127 | if (d->selectionModel)
| 0 | ||||||||||||||||||||||||
| 1128 | d->selectionModel->reset(); never executed: d->selectionModel->reset(); | 0 | ||||||||||||||||||||||||
| 1129 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 1130 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
| 1131 | QAccessibleTableModelChangeEvent accessibleEvent(this, QAccessibleTableModelChangeEvent::ModelReset); | - | ||||||||||||||||||||||||
| 1132 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||||||||
| 1133 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1134 | #endif | - | ||||||||||||||||||||||||
| 1135 | d->updateGeometry(); | - | ||||||||||||||||||||||||
| 1136 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1137 | - | |||||||||||||||||||||||||
| 1138 | /*! | - | ||||||||||||||||||||||||
| 1139 | Sets the root item to the item at the given \a index. | - | ||||||||||||||||||||||||
| 1140 | - | |||||||||||||||||||||||||
| 1141 | \sa rootIndex() | - | ||||||||||||||||||||||||
| 1142 | */ | - | ||||||||||||||||||||||||
| 1143 | void QAbstractItemView::setRootIndex(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 1144 | { | - | ||||||||||||||||||||||||
| 1145 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1146 | if (Q_UNLIKELY(index.isValid() && index.model() != d->model)) {
| 0 | ||||||||||||||||||||||||
| 1147 | qWarning("QAbstractItemView::setRootIndex failed : index must be from the currently set model"); | - | ||||||||||||||||||||||||
| 1148 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1149 | } | - | ||||||||||||||||||||||||
| 1150 | d->root = index; | - | ||||||||||||||||||||||||
| 1151 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 1152 | d->updateGeometry(); | - | ||||||||||||||||||||||||
| 1153 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1154 | - | |||||||||||||||||||||||||
| 1155 | /*! | - | ||||||||||||||||||||||||
| 1156 | Returns the model index of the model's root item. The root item is | - | ||||||||||||||||||||||||
| 1157 | the parent item to the view's toplevel items. The root can be invalid. | - | ||||||||||||||||||||||||
| 1158 | - | |||||||||||||||||||||||||
| 1159 | \sa setRootIndex() | - | ||||||||||||||||||||||||
| 1160 | */ | - | ||||||||||||||||||||||||
| 1161 | QModelIndex QAbstractItemView::rootIndex() const | - | ||||||||||||||||||||||||
| 1162 | { | - | ||||||||||||||||||||||||
| 1163 | return QModelIndex(d_func()->root); never executed: return QModelIndex(d_func()->root); | 0 | ||||||||||||||||||||||||
| 1164 | } | - | ||||||||||||||||||||||||
| 1165 | - | |||||||||||||||||||||||||
| 1166 | /*! | - | ||||||||||||||||||||||||
| 1167 | Selects all items in the view. | - | ||||||||||||||||||||||||
| 1168 | This function will use the selection behavior | - | ||||||||||||||||||||||||
| 1169 | set on the view when selecting. | - | ||||||||||||||||||||||||
| 1170 | - | |||||||||||||||||||||||||
| 1171 | \sa setSelection(), selectedIndexes(), clearSelection() | - | ||||||||||||||||||||||||
| 1172 | */ | - | ||||||||||||||||||||||||
| 1173 | void QAbstractItemView::selectAll() | - | ||||||||||||||||||||||||
| 1174 | { | - | ||||||||||||||||||||||||
| 1175 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1176 | SelectionMode mode = d->selectionMode; | - | ||||||||||||||||||||||||
| 1177 | if (mode == MultiSelection || mode == ExtendedSelection)
| 0 | ||||||||||||||||||||||||
| 1178 | d->selectAll(QItemSelectionModel::ClearAndSelect never executed: d->selectAll(QItemSelectionModel::ClearAndSelect |d->selectionBehaviorFlags()); | 0 | ||||||||||||||||||||||||
| 1179 | |d->selectionBehaviorFlags()); never executed: d->selectAll(QItemSelectionModel::ClearAndSelect |d->selectionBehaviorFlags()); | 0 | ||||||||||||||||||||||||
| 1180 | else if (mode != SingleSelection)
| 0 | ||||||||||||||||||||||||
| 1181 | d->selectAll(selectionCommand(d->model->index(0, 0, d->root))); never executed: d->selectAll(selectionCommand(d->model->index(0, 0, d->root))); | 0 | ||||||||||||||||||||||||
| 1182 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1183 | - | |||||||||||||||||||||||||
| 1184 | /*! | - | ||||||||||||||||||||||||
| 1185 | Starts editing the item corresponding to the given \a index if it is | - | ||||||||||||||||||||||||
| 1186 | editable. | - | ||||||||||||||||||||||||
| 1187 | - | |||||||||||||||||||||||||
| 1188 | Note that this function does not change the current index. Since the current | - | ||||||||||||||||||||||||
| 1189 | index defines the next and previous items to edit, users may find that | - | ||||||||||||||||||||||||
| 1190 | keyboard navigation does not work as expected. To provide consistent navigation | - | ||||||||||||||||||||||||
| 1191 | behavior, call setCurrentIndex() before this function with the same model | - | ||||||||||||||||||||||||
| 1192 | index. | - | ||||||||||||||||||||||||
| 1193 | - | |||||||||||||||||||||||||
| 1194 | \sa QModelIndex::flags() | - | ||||||||||||||||||||||||
| 1195 | */ | - | ||||||||||||||||||||||||
| 1196 | void QAbstractItemView::edit(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 1197 | { | - | ||||||||||||||||||||||||
| 1198 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1199 | if (Q_UNLIKELY(!d->isIndexValid(index)))
| 0 | ||||||||||||||||||||||||
| 1200 | qWarning("edit: index was invalid"); never executed: QMessageLogger(__FILE__, 1200, __PRETTY_FUNCTION__).warning("edit: index was invalid"); | 0 | ||||||||||||||||||||||||
| 1201 | if (Q_UNLIKELY(!edit(index, AllEditTriggers, 0)))
| 0 | ||||||||||||||||||||||||
| 1202 | qWarning("edit: editing failed"); never executed: QMessageLogger(__FILE__, 1202, __PRETTY_FUNCTION__).warning("edit: editing failed"); | 0 | ||||||||||||||||||||||||
| 1203 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1204 | - | |||||||||||||||||||||||||
| 1205 | /*! | - | ||||||||||||||||||||||||
| 1206 | Deselects all selected items. The current index will not be changed. | - | ||||||||||||||||||||||||
| 1207 | - | |||||||||||||||||||||||||
| 1208 | \sa setSelection(), selectAll() | - | ||||||||||||||||||||||||
| 1209 | */ | - | ||||||||||||||||||||||||
| 1210 | void QAbstractItemView::clearSelection() | - | ||||||||||||||||||||||||
| 1211 | { | - | ||||||||||||||||||||||||
| 1212 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1213 | if (d->selectionModel)
| 0 | ||||||||||||||||||||||||
| 1214 | d->selectionModel->clearSelection(); never executed: d->selectionModel->clearSelection(); | 0 | ||||||||||||||||||||||||
| 1215 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1216 | - | |||||||||||||||||||||||||
| 1217 | /*! | - | ||||||||||||||||||||||||
| 1218 | \internal | - | ||||||||||||||||||||||||
| 1219 | - | |||||||||||||||||||||||||
| 1220 | This function is intended to lay out the items in the view. | - | ||||||||||||||||||||||||
| 1221 | The default implementation just calls updateGeometries() and updates the viewport. | - | ||||||||||||||||||||||||
| 1222 | */ | - | ||||||||||||||||||||||||
| 1223 | void QAbstractItemView::doItemsLayout() | - | ||||||||||||||||||||||||
| 1224 | { | - | ||||||||||||||||||||||||
| 1225 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1226 | d->interruptDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 1227 | updateGeometries(); | - | ||||||||||||||||||||||||
| 1228 | d->viewport->update(); | - | ||||||||||||||||||||||||
| 1229 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1230 | - | |||||||||||||||||||||||||
| 1231 | /*! | - | ||||||||||||||||||||||||
| 1232 | \property QAbstractItemView::editTriggers | - | ||||||||||||||||||||||||
| 1233 | \brief which actions will initiate item editing | - | ||||||||||||||||||||||||
| 1234 | - | |||||||||||||||||||||||||
| 1235 | This property is a selection of flags defined by | - | ||||||||||||||||||||||||
| 1236 | \l{EditTrigger}, combined using the OR | - | ||||||||||||||||||||||||
| 1237 | operator. The view will only initiate the editing of an item if the | - | ||||||||||||||||||||||||
| 1238 | action performed is set in this property. | - | ||||||||||||||||||||||||
| 1239 | */ | - | ||||||||||||||||||||||||
| 1240 | void QAbstractItemView::setEditTriggers(EditTriggers actions) | - | ||||||||||||||||||||||||
| 1241 | { | - | ||||||||||||||||||||||||
| 1242 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1243 | d->editTriggers = actions; | - | ||||||||||||||||||||||||
| 1244 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1245 | - | |||||||||||||||||||||||||
| 1246 | QAbstractItemView::EditTriggers QAbstractItemView::editTriggers() const | - | ||||||||||||||||||||||||
| 1247 | { | - | ||||||||||||||||||||||||
| 1248 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1249 | return d->editTriggers; never executed: return d->editTriggers; | 0 | ||||||||||||||||||||||||
| 1250 | } | - | ||||||||||||||||||||||||
| 1251 | - | |||||||||||||||||||||||||
| 1252 | /*! | - | ||||||||||||||||||||||||
| 1253 | \since 4.2 | - | ||||||||||||||||||||||||
| 1254 | \property QAbstractItemView::verticalScrollMode | - | ||||||||||||||||||||||||
| 1255 | \brief how the view scrolls its contents in the vertical direction | - | ||||||||||||||||||||||||
| 1256 | - | |||||||||||||||||||||||||
| 1257 | This property controls how the view scroll its contents vertically. | - | ||||||||||||||||||||||||
| 1258 | Scrolling can be done either per pixel or per item. Its default value | - | ||||||||||||||||||||||||
| 1259 | comes from the style via the QStyle::SH_ItemView_ScrollMode style hint. | - | ||||||||||||||||||||||||
| 1260 | */ | - | ||||||||||||||||||||||||
| 1261 | - | |||||||||||||||||||||||||
| 1262 | void QAbstractItemView::setVerticalScrollMode(ScrollMode mode) | - | ||||||||||||||||||||||||
| 1263 | { | - | ||||||||||||||||||||||||
| 1264 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1265 | d->verticalScrollModeSet = true; | - | ||||||||||||||||||||||||
| 1266 | if (mode == d->verticalScrollMode)
| 0 | ||||||||||||||||||||||||
| 1267 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1268 | QModelIndex topLeft = indexAt(QPoint(0, 0)); | - | ||||||||||||||||||||||||
| 1269 | d->verticalScrollMode = mode; | - | ||||||||||||||||||||||||
| 1270 | if (mode == ScrollPerItem)
| 0 | ||||||||||||||||||||||||
| 1271 | verticalScrollBar()->d_func()->itemviewChangeSingleStep(1); // setSingleStep(-1) => step with 1 never executed: verticalScrollBar()->d_func()->itemviewChangeSingleStep(1); | 0 | ||||||||||||||||||||||||
| 1272 | else | - | ||||||||||||||||||||||||
| 1273 | verticalScrollBar()->setSingleStep(-1); // Ensure that the view can update single step never executed: verticalScrollBar()->setSingleStep(-1); | 0 | ||||||||||||||||||||||||
| 1274 | updateGeometries(); // update the scroll bars | - | ||||||||||||||||||||||||
| 1275 | scrollTo(topLeft, QAbstractItemView::PositionAtTop); | - | ||||||||||||||||||||||||
| 1276 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1277 | - | |||||||||||||||||||||||||
| 1278 | QAbstractItemView::ScrollMode QAbstractItemView::verticalScrollMode() const | - | ||||||||||||||||||||||||
| 1279 | { | - | ||||||||||||||||||||||||
| 1280 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1281 | return d->verticalScrollMode; never executed: return d->verticalScrollMode; | 0 | ||||||||||||||||||||||||
| 1282 | } | - | ||||||||||||||||||||||||
| 1283 | - | |||||||||||||||||||||||||
| 1284 | void QAbstractItemView::resetVerticalScrollMode() | - | ||||||||||||||||||||||||
| 1285 | { | - | ||||||||||||||||||||||||
| 1286 | auto sm = static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, this, 0)); | - | ||||||||||||||||||||||||
| 1287 | setVerticalScrollMode(sm); | - | ||||||||||||||||||||||||
| 1288 | d_func()->verticalScrollModeSet = false; | - | ||||||||||||||||||||||||
| 1289 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1290 | - | |||||||||||||||||||||||||
| 1291 | /*! | - | ||||||||||||||||||||||||
| 1292 | \since 4.2 | - | ||||||||||||||||||||||||
| 1293 | \property QAbstractItemView::horizontalScrollMode | - | ||||||||||||||||||||||||
| 1294 | \brief how the view scrolls its contents in the horizontal direction | - | ||||||||||||||||||||||||
| 1295 | - | |||||||||||||||||||||||||
| 1296 | This property controls how the view scroll its contents horizontally. | - | ||||||||||||||||||||||||
| 1297 | Scrolling can be done either per pixel or per item. Its default value | - | ||||||||||||||||||||||||
| 1298 | comes from the style via the QStyle::SH_ItemView_ScrollMode style hint. | - | ||||||||||||||||||||||||
| 1299 | */ | - | ||||||||||||||||||||||||
| 1300 | - | |||||||||||||||||||||||||
| 1301 | void QAbstractItemView::setHorizontalScrollMode(ScrollMode mode) | - | ||||||||||||||||||||||||
| 1302 | { | - | ||||||||||||||||||||||||
| 1303 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1304 | d->horizontalScrollModeSet = true; | - | ||||||||||||||||||||||||
| 1305 | if (mode == d->horizontalScrollMode)
| 0 | ||||||||||||||||||||||||
| 1306 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1307 | d->horizontalScrollMode = mode; | - | ||||||||||||||||||||||||
| 1308 | if (mode == ScrollPerItem)
| 0 | ||||||||||||||||||||||||
| 1309 | horizontalScrollBar()->d_func()->itemviewChangeSingleStep(1); // setSingleStep(-1) => step with 1 never executed: horizontalScrollBar()->d_func()->itemviewChangeSingleStep(1); | 0 | ||||||||||||||||||||||||
| 1310 | else | - | ||||||||||||||||||||||||
| 1311 | horizontalScrollBar()->setSingleStep(-1); // Ensure that the view can update single step never executed: horizontalScrollBar()->setSingleStep(-1); | 0 | ||||||||||||||||||||||||
| 1312 | updateGeometries(); // update the scroll bars | - | ||||||||||||||||||||||||
| 1313 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1314 | - | |||||||||||||||||||||||||
| 1315 | QAbstractItemView::ScrollMode QAbstractItemView::horizontalScrollMode() const | - | ||||||||||||||||||||||||
| 1316 | { | - | ||||||||||||||||||||||||
| 1317 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1318 | return d->horizontalScrollMode; never executed: return d->horizontalScrollMode; | 0 | ||||||||||||||||||||||||
| 1319 | } | - | ||||||||||||||||||||||||
| 1320 | - | |||||||||||||||||||||||||
| 1321 | void QAbstractItemView::resetHorizontalScrollMode() | - | ||||||||||||||||||||||||
| 1322 | { | - | ||||||||||||||||||||||||
| 1323 | auto sm = static_cast<ScrollMode>(style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, this, 0)); | - | ||||||||||||||||||||||||
| 1324 | setHorizontalScrollMode(sm); | - | ||||||||||||||||||||||||
| 1325 | d_func()->horizontalScrollModeSet = false; | - | ||||||||||||||||||||||||
| 1326 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1327 | - | |||||||||||||||||||||||||
| 1328 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 1329 | /*! | - | ||||||||||||||||||||||||
| 1330 | \since 4.2 | - | ||||||||||||||||||||||||
| 1331 | \property QAbstractItemView::dragDropOverwriteMode | - | ||||||||||||||||||||||||
| 1332 | \brief the view's drag and drop behavior | - | ||||||||||||||||||||||||
| 1333 | - | |||||||||||||||||||||||||
| 1334 | If its value is \c true, the selected data will overwrite the | - | ||||||||||||||||||||||||
| 1335 | existing item data when dropped, while moving the data will clear | - | ||||||||||||||||||||||||
| 1336 | the item. If its value is \c false, the selected data will be | - | ||||||||||||||||||||||||
| 1337 | inserted as a new item when the data is dropped. When the data is | - | ||||||||||||||||||||||||
| 1338 | moved, the item is removed as well. | - | ||||||||||||||||||||||||
| 1339 | - | |||||||||||||||||||||||||
| 1340 | The default value is \c false, as in the QListView and QTreeView | - | ||||||||||||||||||||||||
| 1341 | subclasses. In the QTableView subclass, on the other hand, the | - | ||||||||||||||||||||||||
| 1342 | property has been set to \c true. | - | ||||||||||||||||||||||||
| 1343 | - | |||||||||||||||||||||||||
| 1344 | Note: This is not intended to prevent overwriting of items. | - | ||||||||||||||||||||||||
| 1345 | The model's implementation of flags() should do that by not | - | ||||||||||||||||||||||||
| 1346 | returning Qt::ItemIsDropEnabled. | - | ||||||||||||||||||||||||
| 1347 | - | |||||||||||||||||||||||||
| 1348 | \sa dragDropMode | - | ||||||||||||||||||||||||
| 1349 | */ | - | ||||||||||||||||||||||||
| 1350 | void QAbstractItemView::setDragDropOverwriteMode(bool overwrite) | - | ||||||||||||||||||||||||
| 1351 | { | - | ||||||||||||||||||||||||
| 1352 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1353 | d->overwrite = overwrite; | - | ||||||||||||||||||||||||
| 1354 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1355 | - | |||||||||||||||||||||||||
| 1356 | bool QAbstractItemView::dragDropOverwriteMode() const | - | ||||||||||||||||||||||||
| 1357 | { | - | ||||||||||||||||||||||||
| 1358 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1359 | return d->overwrite; never executed: return d->overwrite; | 0 | ||||||||||||||||||||||||
| 1360 | } | - | ||||||||||||||||||||||||
| 1361 | #endif | - | ||||||||||||||||||||||||
| 1362 | - | |||||||||||||||||||||||||
| 1363 | /*! | - | ||||||||||||||||||||||||
| 1364 | \property QAbstractItemView::autoScroll | - | ||||||||||||||||||||||||
| 1365 | \brief whether autoscrolling in drag move events is enabled | - | ||||||||||||||||||||||||
| 1366 | - | |||||||||||||||||||||||||
| 1367 | If this property is set to true (the default), the | - | ||||||||||||||||||||||||
| 1368 | QAbstractItemView automatically scrolls the contents of the view | - | ||||||||||||||||||||||||
| 1369 | if the user drags within 16 pixels of the viewport edge. If the current | - | ||||||||||||||||||||||||
| 1370 | item changes, then the view will scroll automatically to ensure that the | - | ||||||||||||||||||||||||
| 1371 | current item is fully visible. | - | ||||||||||||||||||||||||
| 1372 | - | |||||||||||||||||||||||||
| 1373 | This property only works if the viewport accepts drops. Autoscroll is | - | ||||||||||||||||||||||||
| 1374 | switched off by setting this property to false. | - | ||||||||||||||||||||||||
| 1375 | */ | - | ||||||||||||||||||||||||
| 1376 | - | |||||||||||||||||||||||||
| 1377 | void QAbstractItemView::setAutoScroll(bool enable) | - | ||||||||||||||||||||||||
| 1378 | { | - | ||||||||||||||||||||||||
| 1379 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1380 | d->autoScroll = enable; | - | ||||||||||||||||||||||||
| 1381 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1382 | - | |||||||||||||||||||||||||
| 1383 | bool QAbstractItemView::hasAutoScroll() const | - | ||||||||||||||||||||||||
| 1384 | { | - | ||||||||||||||||||||||||
| 1385 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1386 | return d->autoScroll; never executed: return d->autoScroll; | 0 | ||||||||||||||||||||||||
| 1387 | } | - | ||||||||||||||||||||||||
| 1388 | - | |||||||||||||||||||||||||
| 1389 | /*! | - | ||||||||||||||||||||||||
| 1390 | \since 4.4 | - | ||||||||||||||||||||||||
| 1391 | \property QAbstractItemView::autoScrollMargin | - | ||||||||||||||||||||||||
| 1392 | \brief the size of the area when auto scrolling is triggered | - | ||||||||||||||||||||||||
| 1393 | - | |||||||||||||||||||||||||
| 1394 | This property controls the size of the area at the edge of the viewport that | - | ||||||||||||||||||||||||
| 1395 | triggers autoscrolling. The default value is 16 pixels. | - | ||||||||||||||||||||||||
| 1396 | */ | - | ||||||||||||||||||||||||
| 1397 | void QAbstractItemView::setAutoScrollMargin(int margin) | - | ||||||||||||||||||||||||
| 1398 | { | - | ||||||||||||||||||||||||
| 1399 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1400 | d->autoScrollMargin = margin; | - | ||||||||||||||||||||||||
| 1401 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1402 | - | |||||||||||||||||||||||||
| 1403 | int QAbstractItemView::autoScrollMargin() const | - | ||||||||||||||||||||||||
| 1404 | { | - | ||||||||||||||||||||||||
| 1405 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1406 | return d->autoScrollMargin; never executed: return d->autoScrollMargin; | 0 | ||||||||||||||||||||||||
| 1407 | } | - | ||||||||||||||||||||||||
| 1408 | - | |||||||||||||||||||||||||
| 1409 | /*! | - | ||||||||||||||||||||||||
| 1410 | \property QAbstractItemView::tabKeyNavigation | - | ||||||||||||||||||||||||
| 1411 | \brief whether item navigation with tab and backtab is enabled. | - | ||||||||||||||||||||||||
| 1412 | */ | - | ||||||||||||||||||||||||
| 1413 | - | |||||||||||||||||||||||||
| 1414 | void QAbstractItemView::setTabKeyNavigation(bool enable) | - | ||||||||||||||||||||||||
| 1415 | { | - | ||||||||||||||||||||||||
| 1416 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1417 | d->tabKeyNavigation = enable; | - | ||||||||||||||||||||||||
| 1418 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1419 | - | |||||||||||||||||||||||||
| 1420 | bool QAbstractItemView::tabKeyNavigation() const | - | ||||||||||||||||||||||||
| 1421 | { | - | ||||||||||||||||||||||||
| 1422 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1423 | return d->tabKeyNavigation; never executed: return d->tabKeyNavigation; | 0 | ||||||||||||||||||||||||
| 1424 | } | - | ||||||||||||||||||||||||
| 1425 | - | |||||||||||||||||||||||||
| 1426 | /*! | - | ||||||||||||||||||||||||
| 1427 | \since 5.2 | - | ||||||||||||||||||||||||
| 1428 | \reimp | - | ||||||||||||||||||||||||
| 1429 | */ | - | ||||||||||||||||||||||||
| 1430 | QSize QAbstractItemView::viewportSizeHint() const | - | ||||||||||||||||||||||||
| 1431 | { | - | ||||||||||||||||||||||||
| 1432 | return QAbstractScrollArea::viewportSizeHint(); never executed: return QAbstractScrollArea::viewportSizeHint(); | 0 | ||||||||||||||||||||||||
| 1433 | } | - | ||||||||||||||||||||||||
| 1434 | - | |||||||||||||||||||||||||
| 1435 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 1436 | /*! | - | ||||||||||||||||||||||||
| 1437 | \property QAbstractItemView::showDropIndicator | - | ||||||||||||||||||||||||
| 1438 | \brief whether the drop indicator is shown when dragging items and dropping. | - | ||||||||||||||||||||||||
| 1439 | - | |||||||||||||||||||||||||
| 1440 | \sa dragEnabled, DragDropMode, dragDropOverwriteMode, acceptDrops | - | ||||||||||||||||||||||||
| 1441 | */ | - | ||||||||||||||||||||||||
| 1442 | - | |||||||||||||||||||||||||
| 1443 | void QAbstractItemView::setDropIndicatorShown(bool enable) | - | ||||||||||||||||||||||||
| 1444 | { | - | ||||||||||||||||||||||||
| 1445 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1446 | d->showDropIndicator = enable; | - | ||||||||||||||||||||||||
| 1447 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1448 | - | |||||||||||||||||||||||||
| 1449 | bool QAbstractItemView::showDropIndicator() const | - | ||||||||||||||||||||||||
| 1450 | { | - | ||||||||||||||||||||||||
| 1451 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1452 | return d->showDropIndicator; never executed: return d->showDropIndicator; | 0 | ||||||||||||||||||||||||
| 1453 | } | - | ||||||||||||||||||||||||
| 1454 | - | |||||||||||||||||||||||||
| 1455 | /*! | - | ||||||||||||||||||||||||
| 1456 | \property QAbstractItemView::dragEnabled | - | ||||||||||||||||||||||||
| 1457 | \brief whether the view supports dragging of its own items | - | ||||||||||||||||||||||||
| 1458 | - | |||||||||||||||||||||||||
| 1459 | \sa showDropIndicator, DragDropMode, dragDropOverwriteMode, acceptDrops | - | ||||||||||||||||||||||||
| 1460 | */ | - | ||||||||||||||||||||||||
| 1461 | - | |||||||||||||||||||||||||
| 1462 | void QAbstractItemView::setDragEnabled(bool enable) | - | ||||||||||||||||||||||||
| 1463 | { | - | ||||||||||||||||||||||||
| 1464 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1465 | d->dragEnabled = enable; | - | ||||||||||||||||||||||||
| 1466 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1467 | - | |||||||||||||||||||||||||
| 1468 | bool QAbstractItemView::dragEnabled() const | - | ||||||||||||||||||||||||
| 1469 | { | - | ||||||||||||||||||||||||
| 1470 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1471 | return d->dragEnabled; never executed: return d->dragEnabled; | 0 | ||||||||||||||||||||||||
| 1472 | } | - | ||||||||||||||||||||||||
| 1473 | - | |||||||||||||||||||||||||
| 1474 | /*! | - | ||||||||||||||||||||||||
| 1475 | \since 4.2 | - | ||||||||||||||||||||||||
| 1476 | \enum QAbstractItemView::DragDropMode | - | ||||||||||||||||||||||||
| 1477 | - | |||||||||||||||||||||||||
| 1478 | Describes the various drag and drop events the view can act upon. | - | ||||||||||||||||||||||||
| 1479 | By default the view does not support dragging or dropping (\c | - | ||||||||||||||||||||||||
| 1480 | NoDragDrop). | - | ||||||||||||||||||||||||
| 1481 | - | |||||||||||||||||||||||||
| 1482 | \value NoDragDrop Does not support dragging or dropping. | - | ||||||||||||||||||||||||
| 1483 | \value DragOnly The view supports dragging of its own items | - | ||||||||||||||||||||||||
| 1484 | \value DropOnly The view accepts drops | - | ||||||||||||||||||||||||
| 1485 | \value DragDrop The view supports both dragging and dropping | - | ||||||||||||||||||||||||
| 1486 | \value InternalMove The view accepts move (\b{not copy}) operations only | - | ||||||||||||||||||||||||
| 1487 | from itself. | - | ||||||||||||||||||||||||
| 1488 | - | |||||||||||||||||||||||||
| 1489 | Note that the model used needs to provide support for drag and drop operations. | - | ||||||||||||||||||||||||
| 1490 | - | |||||||||||||||||||||||||
| 1491 | \sa setDragDropMode(), {Using drag and drop with item views} | - | ||||||||||||||||||||||||
| 1492 | */ | - | ||||||||||||||||||||||||
| 1493 | - | |||||||||||||||||||||||||
| 1494 | /*! | - | ||||||||||||||||||||||||
| 1495 | \property QAbstractItemView::dragDropMode | - | ||||||||||||||||||||||||
| 1496 | \brief the drag and drop event the view will act upon | - | ||||||||||||||||||||||||
| 1497 | - | |||||||||||||||||||||||||
| 1498 | \since 4.2 | - | ||||||||||||||||||||||||
| 1499 | \sa showDropIndicator, dragDropOverwriteMode | - | ||||||||||||||||||||||||
| 1500 | */ | - | ||||||||||||||||||||||||
| 1501 | void QAbstractItemView::setDragDropMode(DragDropMode behavior) | - | ||||||||||||||||||||||||
| 1502 | { | - | ||||||||||||||||||||||||
| 1503 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1504 | d->dragDropMode = behavior; | - | ||||||||||||||||||||||||
| 1505 | setDragEnabled(behavior == DragOnly || behavior == DragDrop || behavior == InternalMove); | - | ||||||||||||||||||||||||
| 1506 | setAcceptDrops(behavior == DropOnly || behavior == DragDrop || behavior == InternalMove); | - | ||||||||||||||||||||||||
| 1507 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1508 | - | |||||||||||||||||||||||||
| 1509 | QAbstractItemView::DragDropMode QAbstractItemView::dragDropMode() const | - | ||||||||||||||||||||||||
| 1510 | { | - | ||||||||||||||||||||||||
| 1511 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1512 | DragDropMode setBehavior = d->dragDropMode; | - | ||||||||||||||||||||||||
| 1513 | if (!dragEnabled() && !acceptDrops())
| 0 | ||||||||||||||||||||||||
| 1514 | return NoDragDrop; never executed: return NoDragDrop; | 0 | ||||||||||||||||||||||||
| 1515 | - | |||||||||||||||||||||||||
| 1516 | if (dragEnabled() && !acceptDrops())
| 0 | ||||||||||||||||||||||||
| 1517 | return DragOnly; never executed: return DragOnly; | 0 | ||||||||||||||||||||||||
| 1518 | - | |||||||||||||||||||||||||
| 1519 | if (!dragEnabled() && acceptDrops())
| 0 | ||||||||||||||||||||||||
| 1520 | return DropOnly; never executed: return DropOnly; | 0 | ||||||||||||||||||||||||
| 1521 | - | |||||||||||||||||||||||||
| 1522 | if (dragEnabled() && acceptDrops()) {
| 0 | ||||||||||||||||||||||||
| 1523 | if (setBehavior == InternalMove)
| 0 | ||||||||||||||||||||||||
| 1524 | return setBehavior; never executed: return setBehavior; | 0 | ||||||||||||||||||||||||
| 1525 | else | - | ||||||||||||||||||||||||
| 1526 | return DragDrop; never executed: return DragDrop; | 0 | ||||||||||||||||||||||||
| 1527 | } | - | ||||||||||||||||||||||||
| 1528 | - | |||||||||||||||||||||||||
| 1529 | return NoDragDrop; never executed: return NoDragDrop; | 0 | ||||||||||||||||||||||||
| 1530 | } | - | ||||||||||||||||||||||||
| 1531 | - | |||||||||||||||||||||||||
| 1532 | /*! | - | ||||||||||||||||||||||||
| 1533 | \property QAbstractItemView::defaultDropAction | - | ||||||||||||||||||||||||
| 1534 | \brief the drop action that will be used by default in QAbstractItemView::drag() | - | ||||||||||||||||||||||||
| 1535 | - | |||||||||||||||||||||||||
| 1536 | If the property is not set, the drop action is CopyAction when the supported | - | ||||||||||||||||||||||||
| 1537 | actions support CopyAction. | - | ||||||||||||||||||||||||
| 1538 | - | |||||||||||||||||||||||||
| 1539 | \since 4.6 | - | ||||||||||||||||||||||||
| 1540 | \sa showDropIndicator, dragDropOverwriteMode | - | ||||||||||||||||||||||||
| 1541 | */ | - | ||||||||||||||||||||||||
| 1542 | void QAbstractItemView::setDefaultDropAction(Qt::DropAction dropAction) | - | ||||||||||||||||||||||||
| 1543 | { | - | ||||||||||||||||||||||||
| 1544 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1545 | d->defaultDropAction = dropAction; | - | ||||||||||||||||||||||||
| 1546 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1547 | - | |||||||||||||||||||||||||
| 1548 | Qt::DropAction QAbstractItemView::defaultDropAction() const | - | ||||||||||||||||||||||||
| 1549 | { | - | ||||||||||||||||||||||||
| 1550 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1551 | return d->defaultDropAction; never executed: return d->defaultDropAction; | 0 | ||||||||||||||||||||||||
| 1552 | } | - | ||||||||||||||||||||||||
| 1553 | - | |||||||||||||||||||||||||
| 1554 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 1555 | - | |||||||||||||||||||||||||
| 1556 | /*! | - | ||||||||||||||||||||||||
| 1557 | \property QAbstractItemView::alternatingRowColors | - | ||||||||||||||||||||||||
| 1558 | \brief whether to draw the background using alternating colors | - | ||||||||||||||||||||||||
| 1559 | - | |||||||||||||||||||||||||
| 1560 | If this property is \c true, the item background will be drawn using | - | ||||||||||||||||||||||||
| 1561 | QPalette::Base and QPalette::AlternateBase; otherwise the background | - | ||||||||||||||||||||||||
| 1562 | will be drawn using the QPalette::Base color. | - | ||||||||||||||||||||||||
| 1563 | - | |||||||||||||||||||||||||
| 1564 | By default, this property is \c false. | - | ||||||||||||||||||||||||
| 1565 | */ | - | ||||||||||||||||||||||||
| 1566 | void QAbstractItemView::setAlternatingRowColors(bool enable) | - | ||||||||||||||||||||||||
| 1567 | { | - | ||||||||||||||||||||||||
| 1568 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1569 | d->alternatingColors = enable; | - | ||||||||||||||||||||||||
| 1570 | if (isVisible())
| 0 | ||||||||||||||||||||||||
| 1571 | d->viewport->update(); never executed: d->viewport->update(); | 0 | ||||||||||||||||||||||||
| 1572 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1573 | - | |||||||||||||||||||||||||
| 1574 | bool QAbstractItemView::alternatingRowColors() const | - | ||||||||||||||||||||||||
| 1575 | { | - | ||||||||||||||||||||||||
| 1576 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1577 | return d->alternatingColors; never executed: return d->alternatingColors; | 0 | ||||||||||||||||||||||||
| 1578 | } | - | ||||||||||||||||||||||||
| 1579 | - | |||||||||||||||||||||||||
| 1580 | /*! | - | ||||||||||||||||||||||||
| 1581 | \property QAbstractItemView::iconSize | - | ||||||||||||||||||||||||
| 1582 | \brief the size of items' icons | - | ||||||||||||||||||||||||
| 1583 | - | |||||||||||||||||||||||||
| 1584 | Setting this property when the view is visible will cause the | - | ||||||||||||||||||||||||
| 1585 | items to be laid out again. | - | ||||||||||||||||||||||||
| 1586 | */ | - | ||||||||||||||||||||||||
| 1587 | void QAbstractItemView::setIconSize(const QSize &size) | - | ||||||||||||||||||||||||
| 1588 | { | - | ||||||||||||||||||||||||
| 1589 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1590 | if (size == d->iconSize)
| 0 | ||||||||||||||||||||||||
| 1591 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1592 | d->iconSize = size; | - | ||||||||||||||||||||||||
| 1593 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 1594 | emit iconSizeChanged(size); | - | ||||||||||||||||||||||||
| 1595 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1596 | - | |||||||||||||||||||||||||
| 1597 | QSize QAbstractItemView::iconSize() const | - | ||||||||||||||||||||||||
| 1598 | { | - | ||||||||||||||||||||||||
| 1599 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 1600 | return d->iconSize; never executed: return d->iconSize; | 0 | ||||||||||||||||||||||||
| 1601 | } | - | ||||||||||||||||||||||||
| 1602 | - | |||||||||||||||||||||||||
| 1603 | /*! | - | ||||||||||||||||||||||||
| 1604 | \property QAbstractItemView::textElideMode | - | ||||||||||||||||||||||||
| 1605 | - | |||||||||||||||||||||||||
| 1606 | \brief the position of the "..." in elided text. | - | ||||||||||||||||||||||||
| 1607 | - | |||||||||||||||||||||||||
| 1608 | The default value for all item views is Qt::ElideRight. | - | ||||||||||||||||||||||||
| 1609 | */ | - | ||||||||||||||||||||||||
| 1610 | void QAbstractItemView::setTextElideMode(Qt::TextElideMode mode) | - | ||||||||||||||||||||||||
| 1611 | { | - | ||||||||||||||||||||||||
| 1612 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1613 | d->textElideMode = mode; | - | ||||||||||||||||||||||||
| 1614 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1615 | - | |||||||||||||||||||||||||
| 1616 | Qt::TextElideMode QAbstractItemView::textElideMode() const | - | ||||||||||||||||||||||||
| 1617 | { | - | ||||||||||||||||||||||||
| 1618 | return d_func()->textElideMode; never executed: return d_func()->textElideMode; | 0 | ||||||||||||||||||||||||
| 1619 | } | - | ||||||||||||||||||||||||
| 1620 | - | |||||||||||||||||||||||||
| 1621 | /*! | - | ||||||||||||||||||||||||
| 1622 | \reimp | - | ||||||||||||||||||||||||
| 1623 | */ | - | ||||||||||||||||||||||||
| 1624 | bool QAbstractItemView::focusNextPrevChild(bool next) | - | ||||||||||||||||||||||||
| 1625 | { | - | ||||||||||||||||||||||||
| 1626 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1627 | if (d->tabKeyNavigation && isEnabled() && d->viewport->isEnabled()) {
| 0 | ||||||||||||||||||||||||
| 1628 | QKeyEvent event(QEvent::KeyPress, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier); | - | ||||||||||||||||||||||||
| 1629 | keyPressEvent(&event); | - | ||||||||||||||||||||||||
| 1630 | if (event.isAccepted())
| 0 | ||||||||||||||||||||||||
| 1631 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1632 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1633 | return QAbstractScrollArea::focusNextPrevChild(next); never executed: return QAbstractScrollArea::focusNextPrevChild(next); | 0 | ||||||||||||||||||||||||
| 1634 | } | - | ||||||||||||||||||||||||
| 1635 | - | |||||||||||||||||||||||||
| 1636 | /*! | - | ||||||||||||||||||||||||
| 1637 | \reimp | - | ||||||||||||||||||||||||
| 1638 | */ | - | ||||||||||||||||||||||||
| 1639 | bool QAbstractItemView::event(QEvent *event) | - | ||||||||||||||||||||||||
| 1640 | { | - | ||||||||||||||||||||||||
| 1641 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1642 | switch (event->type()) { | - | ||||||||||||||||||||||||
| 1643 | case QEvent::Paint: never executed: case QEvent::Paint: | 0 | ||||||||||||||||||||||||
| 1644 | //we call this here because the scrollbars' visibility might be altered | - | ||||||||||||||||||||||||
| 1645 | //so this can't be done in the paintEvent method | - | ||||||||||||||||||||||||
| 1646 | d->executePostedLayout(); //make sure we set the layout properly | - | ||||||||||||||||||||||||
| 1647 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1648 | case QEvent::Show: never executed: case QEvent::Show: | 0 | ||||||||||||||||||||||||
| 1649 | d->executePostedLayout(); //make sure we set the layout properly | - | ||||||||||||||||||||||||
| 1650 | if (d->shouldScrollToCurrentOnShow) {
| 0 | ||||||||||||||||||||||||
| 1651 | d->shouldScrollToCurrentOnShow = false; | - | ||||||||||||||||||||||||
| 1652 | const QModelIndex current = currentIndex(); | - | ||||||||||||||||||||||||
| 1653 | if (current.isValid() && (d->state == QAbstractItemView::EditingState || d->autoScroll))
| 0 | ||||||||||||||||||||||||
| 1654 | scrollTo(current); never executed: scrollTo(current); | 0 | ||||||||||||||||||||||||
| 1655 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1656 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1657 | case QEvent::LocaleChange: never executed: case QEvent::LocaleChange: | 0 | ||||||||||||||||||||||||
| 1658 | viewport()->update(); | - | ||||||||||||||||||||||||
| 1659 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1660 | case QEvent::LayoutDirectionChange: never executed: case QEvent::LayoutDirectionChange: | 0 | ||||||||||||||||||||||||
| 1661 | case QEvent::ApplicationLayoutDirectionChange: never executed: case QEvent::ApplicationLayoutDirectionChange: | 0 | ||||||||||||||||||||||||
| 1662 | updateGeometries(); | - | ||||||||||||||||||||||||
| 1663 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1664 | case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||||||||||||||
| 1665 | doItemsLayout(); | - | ||||||||||||||||||||||||
| 1666 | if (!d->verticalScrollModeSet)
| 0 | ||||||||||||||||||||||||
| 1667 | resetVerticalScrollMode(); never executed: resetVerticalScrollMode(); | 0 | ||||||||||||||||||||||||
| 1668 | if (!d->horizontalScrollModeSet)
| 0 | ||||||||||||||||||||||||
| 1669 | resetHorizontalScrollMode(); never executed: resetHorizontalScrollMode(); | 0 | ||||||||||||||||||||||||
| 1670 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1671 | case QEvent::FocusOut: never executed: case QEvent::FocusOut: | 0 | ||||||||||||||||||||||||
| 1672 | d->checkPersistentEditorFocus(); | - | ||||||||||||||||||||||||
| 1673 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1674 | case QEvent::FontChange: never executed: case QEvent::FontChange: | 0 | ||||||||||||||||||||||||
| 1675 | d->doDelayedItemsLayout(); // the size of the items will change | - | ||||||||||||||||||||||||
| 1676 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1677 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1678 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1679 | } | - | ||||||||||||||||||||||||
| 1680 | return QAbstractScrollArea::event(event); never executed: return QAbstractScrollArea::event(event); | 0 | ||||||||||||||||||||||||
| 1681 | } | - | ||||||||||||||||||||||||
| 1682 | - | |||||||||||||||||||||||||
| 1683 | /*! | - | ||||||||||||||||||||||||
| 1684 | \fn bool QAbstractItemView::viewportEvent(QEvent *event) | - | ||||||||||||||||||||||||
| 1685 | - | |||||||||||||||||||||||||
| 1686 | This function is used to handle tool tips, and What's | - | ||||||||||||||||||||||||
| 1687 | This? mode, if the given \a event is a QEvent::ToolTip,or a | - | ||||||||||||||||||||||||
| 1688 | QEvent::WhatsThis. It passes all other | - | ||||||||||||||||||||||||
| 1689 | events on to its base class viewportEvent() handler. | - | ||||||||||||||||||||||||
| 1690 | */ | - | ||||||||||||||||||||||||
| 1691 | bool QAbstractItemView::viewportEvent(QEvent *event) | - | ||||||||||||||||||||||||
| 1692 | { | - | ||||||||||||||||||||||||
| 1693 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1694 | switch (event->type()) { | - | ||||||||||||||||||||||||
| 1695 | case QEvent::HoverMove: never executed: case QEvent::HoverMove: | 0 | ||||||||||||||||||||||||
| 1696 | case QEvent::HoverEnter: never executed: case QEvent::HoverEnter: | 0 | ||||||||||||||||||||||||
| 1697 | d->setHoverIndex(indexAt(static_cast<QHoverEvent*>(event)->pos())); | - | ||||||||||||||||||||||||
| 1698 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1699 | case QEvent::HoverLeave: never executed: case QEvent::HoverLeave: | 0 | ||||||||||||||||||||||||
| 1700 | d->setHoverIndex(QModelIndex()); | - | ||||||||||||||||||||||||
| 1701 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1702 | case QEvent::Enter: never executed: case QEvent::Enter: | 0 | ||||||||||||||||||||||||
| 1703 | d->viewportEnteredNeeded = true; | - | ||||||||||||||||||||||||
| 1704 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1705 | case QEvent::Leave: never executed: case QEvent::Leave: | 0 | ||||||||||||||||||||||||
| 1706 | #ifndef QT_NO_STATUSTIP | - | ||||||||||||||||||||||||
| 1707 | if (d->shouldClearStatusTip && d->parent) {
| 0 | ||||||||||||||||||||||||
| 1708 | QString empty; | - | ||||||||||||||||||||||||
| 1709 | QStatusTipEvent tip(empty); | - | ||||||||||||||||||||||||
| 1710 | QApplication::sendEvent(d->parent, &tip); | - | ||||||||||||||||||||||||
| 1711 | d->shouldClearStatusTip = false; | - | ||||||||||||||||||||||||
| 1712 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1713 | #endif | - | ||||||||||||||||||||||||
| 1714 | d->enteredIndex = QModelIndex(); | - | ||||||||||||||||||||||||
| 1715 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1716 | case QEvent::ToolTip: never executed: case QEvent::ToolTip: | 0 | ||||||||||||||||||||||||
| 1717 | case QEvent::QueryWhatsThis: never executed: case QEvent::QueryWhatsThis: | 0 | ||||||||||||||||||||||||
| 1718 | case QEvent::WhatsThis: { never executed: case QEvent::WhatsThis: | 0 | ||||||||||||||||||||||||
| 1719 | QHelpEvent *he = static_cast<QHelpEvent*>(event); | - | ||||||||||||||||||||||||
| 1720 | const QModelIndex index = indexAt(he->pos()); | - | ||||||||||||||||||||||||
| 1721 | QStyleOptionViewItem option = d->viewOptionsV1(); | - | ||||||||||||||||||||||||
| 1722 | option.rect = visualRect(index); | - | ||||||||||||||||||||||||
| 1723 | option.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
| 0 | ||||||||||||||||||||||||
| 1724 | - | |||||||||||||||||||||||||
| 1725 | QAbstractItemDelegate *delegate = d->delegateForIndex(index); | - | ||||||||||||||||||||||||
| 1726 | if (!delegate)
| 0 | ||||||||||||||||||||||||
| 1727 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1728 | return delegate->helpEvent(he, this, option, index); never executed: return delegate->helpEvent(he, this, option, index); | 0 | ||||||||||||||||||||||||
| 1729 | } | - | ||||||||||||||||||||||||
| 1730 | case QEvent::FontChange: never executed: case QEvent::FontChange: | 0 | ||||||||||||||||||||||||
| 1731 | d->doDelayedItemsLayout(); // the size of the items will change | - | ||||||||||||||||||||||||
| 1732 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1733 | case QEvent::WindowActivate: never executed: case QEvent::WindowActivate: | 0 | ||||||||||||||||||||||||
| 1734 | case QEvent::WindowDeactivate: never executed: case QEvent::WindowDeactivate: | 0 | ||||||||||||||||||||||||
| 1735 | d->viewport->update(); | - | ||||||||||||||||||||||||
| 1736 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1737 | case QEvent::ScrollPrepare: never executed: case QEvent::ScrollPrepare: | 0 | ||||||||||||||||||||||||
| 1738 | executeDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 1739 | #ifndef QT_NO_GESTURES | - | ||||||||||||||||||||||||
| 1740 | connect(QScroller::scroller(d->viewport), SIGNAL(stateChanged(QScroller::State)), this, SLOT(_q_scrollerStateChanged()), Qt::UniqueConnection); | - | ||||||||||||||||||||||||
| 1741 | #endif | - | ||||||||||||||||||||||||
| 1742 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1743 | - | |||||||||||||||||||||||||
| 1744 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1745 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1746 | } | - | ||||||||||||||||||||||||
| 1747 | return QAbstractScrollArea::viewportEvent(event); never executed: return QAbstractScrollArea::viewportEvent(event); | 0 | ||||||||||||||||||||||||
| 1748 | } | - | ||||||||||||||||||||||||
| 1749 | - | |||||||||||||||||||||||||
| 1750 | /*! | - | ||||||||||||||||||||||||
| 1751 | This function is called with the given \a event when a mouse button is pressed | - | ||||||||||||||||||||||||
| 1752 | while the cursor is inside the widget. If a valid item is pressed on it is made | - | ||||||||||||||||||||||||
| 1753 | into the current item. This function emits the pressed() signal. | - | ||||||||||||||||||||||||
| 1754 | */ | - | ||||||||||||||||||||||||
| 1755 | void QAbstractItemView::mousePressEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 1756 | { | - | ||||||||||||||||||||||||
| 1757 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1758 | d->delayedAutoScroll.stop(); //any interaction with the view cancel the auto scrolling | - | ||||||||||||||||||||||||
| 1759 | QPoint pos = event->pos(); | - | ||||||||||||||||||||||||
| 1760 | QPersistentModelIndex index = indexAt(pos); | - | ||||||||||||||||||||||||
| 1761 | - | |||||||||||||||||||||||||
| 1762 | if (!d->selectionModel
| 0 | ||||||||||||||||||||||||
| 1763 | || (d->state == EditingState && d->hasEditor(index)))
| 0 | ||||||||||||||||||||||||
| 1764 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1765 | - | |||||||||||||||||||||||||
| 1766 | d->pressedAlreadySelected = d->selectionModel->isSelected(index); | - | ||||||||||||||||||||||||
| 1767 | d->pressedIndex = index; | - | ||||||||||||||||||||||||
| 1768 | d->pressedModifiers = event->modifiers(); | - | ||||||||||||||||||||||||
| 1769 | QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); | - | ||||||||||||||||||||||||
| 1770 | d->noSelectionOnMousePress = command == QItemSelectionModel::NoUpdate || !index.isValid();
| 0 | ||||||||||||||||||||||||
| 1771 | QPoint offset = d->offset(); | - | ||||||||||||||||||||||||
| 1772 | if ((command & QItemSelectionModel::Current) == 0) {
| 0 | ||||||||||||||||||||||||
| 1773 | d->pressedPosition = pos + offset; | - | ||||||||||||||||||||||||
| 1774 | d->currentSelectionStartIndex = index; | - | ||||||||||||||||||||||||
| 1775 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1776 | else if (!d->currentSelectionStartIndex.isValid())
| 0 | ||||||||||||||||||||||||
| 1777 | d->currentSelectionStartIndex = currentIndex(); never executed: d->currentSelectionStartIndex = currentIndex(); | 0 | ||||||||||||||||||||||||
| 1778 | - | |||||||||||||||||||||||||
| 1779 | if (edit(index, NoEditTriggers, event))
| 0 | ||||||||||||||||||||||||
| 1780 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1781 | - | |||||||||||||||||||||||||
| 1782 | if (index.isValid() && d->isIndexEnabled(index)) {
| 0 | ||||||||||||||||||||||||
| 1783 | // we disable scrollTo for mouse press so the item doesn't change position | - | ||||||||||||||||||||||||
| 1784 | // when the user is interacting with it (ie. clicking on it) | - | ||||||||||||||||||||||||
| 1785 | bool autoScroll = d->autoScroll; | - | ||||||||||||||||||||||||
| 1786 | d->autoScroll = false; | - | ||||||||||||||||||||||||
| 1787 | d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||||||||
| 1788 | d->autoScroll = autoScroll; | - | ||||||||||||||||||||||||
| 1789 | if (command.testFlag(QItemSelectionModel::Toggle)) {
| 0 | ||||||||||||||||||||||||
| 1790 | command &= ~QItemSelectionModel::Toggle; | - | ||||||||||||||||||||||||
| 1791 | d->ctrlDragSelectionFlag = d->selectionModel->isSelected(index) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
| 0 | ||||||||||||||||||||||||
| 1792 | command |= d->ctrlDragSelectionFlag; | - | ||||||||||||||||||||||||
| 1793 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1794 | - | |||||||||||||||||||||||||
| 1795 | if ((command & QItemSelectionModel::Current) == 0) {
| 0 | ||||||||||||||||||||||||
| 1796 | setSelection(QRect(pos, QSize(1, 1)), command); | - | ||||||||||||||||||||||||
| 1797 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1798 | QRect rect(visualRect(d->currentSelectionStartIndex).center(), pos); | - | ||||||||||||||||||||||||
| 1799 | setSelection(rect, command); | - | ||||||||||||||||||||||||
| 1800 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1801 | - | |||||||||||||||||||||||||
| 1802 | // signal handlers may change the model | - | ||||||||||||||||||||||||
| 1803 | emit pressed(index); | - | ||||||||||||||||||||||||
| 1804 | if (d->autoScroll) {
| 0 | ||||||||||||||||||||||||
| 1805 | //we delay the autoscrolling to filter out double click event | - | ||||||||||||||||||||||||
| 1806 | //100 is to be sure that there won't be a double-click misinterpreted as a 2 single clicks | - | ||||||||||||||||||||||||
| 1807 | d->delayedAutoScroll.start(QApplication::doubleClickInterval()+100, this); | - | ||||||||||||||||||||||||
| 1808 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1809 | - | |||||||||||||||||||||||||
| 1810 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1811 | // Forces a finalize() even if mouse is pressed, but not on a item | - | ||||||||||||||||||||||||
| 1812 | d->selectionModel->select(QModelIndex(), QItemSelectionModel::Select); | - | ||||||||||||||||||||||||
| 1813 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1814 | } | - | ||||||||||||||||||||||||
| 1815 | - | |||||||||||||||||||||||||
| 1816 | /*! | - | ||||||||||||||||||||||||
| 1817 | This function is called with the given \a event when a mouse move event is | - | ||||||||||||||||||||||||
| 1818 | sent to the widget. If a selection is in progress and new items are moved | - | ||||||||||||||||||||||||
| 1819 | over the selection is extended; if a drag is in progress it is continued. | - | ||||||||||||||||||||||||
| 1820 | */ | - | ||||||||||||||||||||||||
| 1821 | void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 1822 | { | - | ||||||||||||||||||||||||
| 1823 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1824 | QPoint topLeft; | - | ||||||||||||||||||||||||
| 1825 | QPoint bottomRight = event->pos(); | - | ||||||||||||||||||||||||
| 1826 | - | |||||||||||||||||||||||||
| 1827 | if (state() == ExpandingState || state() == CollapsingState)
| 0 | ||||||||||||||||||||||||
| 1828 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1829 | - | |||||||||||||||||||||||||
| 1830 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 1831 | if (state() == DraggingState) {
| 0 | ||||||||||||||||||||||||
| 1832 | topLeft = d->pressedPosition - d->offset(); | - | ||||||||||||||||||||||||
| 1833 | if ((topLeft - bottomRight).manhattanLength() > QApplication::startDragDistance()) {
| 0 | ||||||||||||||||||||||||
| 1834 | d->pressedIndex = QModelIndex(); | - | ||||||||||||||||||||||||
| 1835 | startDrag(d->model->supportedDragActions()); | - | ||||||||||||||||||||||||
| 1836 | setState(NoState); // the startDrag will return when the dnd operation is done | - | ||||||||||||||||||||||||
| 1837 | stopAutoScroll(); | - | ||||||||||||||||||||||||
| 1838 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1839 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1840 | } | - | ||||||||||||||||||||||||
| 1841 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 1842 | - | |||||||||||||||||||||||||
| 1843 | QPersistentModelIndex index = indexAt(bottomRight); | - | ||||||||||||||||||||||||
| 1844 | QModelIndex buddy = d->model->buddy(d->pressedIndex); | - | ||||||||||||||||||||||||
| 1845 | if ((state() == EditingState && d->hasEditor(buddy))
| 0 | ||||||||||||||||||||||||
| 1846 | || edit(index, NoEditTriggers, event))
| 0 | ||||||||||||||||||||||||
| 1847 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1848 | - | |||||||||||||||||||||||||
| 1849 | if (d->selectionMode != SingleSelection)
| 0 | ||||||||||||||||||||||||
| 1850 | topLeft = d->pressedPosition - d->offset(); never executed: topLeft = d->pressedPosition - d->offset(); | 0 | ||||||||||||||||||||||||
| 1851 | else | - | ||||||||||||||||||||||||
| 1852 | topLeft = bottomRight; never executed: topLeft = bottomRight; | 0 | ||||||||||||||||||||||||
| 1853 | - | |||||||||||||||||||||||||
| 1854 | d->checkMouseMove(index); | - | ||||||||||||||||||||||||
| 1855 | - | |||||||||||||||||||||||||
| 1856 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 1857 | if (d->pressedIndex.isValid()
| 0 | ||||||||||||||||||||||||
| 1858 | && d->dragEnabled
| 0 | ||||||||||||||||||||||||
| 1859 | && (state() != DragSelectingState)
| 0 | ||||||||||||||||||||||||
| 1860 | && (event->buttons() != Qt::NoButton)
| 0 | ||||||||||||||||||||||||
| 1861 | && !d->selectedDraggableIndexes().isEmpty()) {
| 0 | ||||||||||||||||||||||||
| 1862 | setState(DraggingState); | - | ||||||||||||||||||||||||
| 1863 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1864 | } | - | ||||||||||||||||||||||||
| 1865 | #endif | - | ||||||||||||||||||||||||
| 1866 | - | |||||||||||||||||||||||||
| 1867 | if ((event->buttons() & Qt::LeftButton) && d->selectionAllowed(index) && d->selectionModel) {
| 0 | ||||||||||||||||||||||||
| 1868 | setState(DragSelectingState); | - | ||||||||||||||||||||||||
| 1869 | QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); | - | ||||||||||||||||||||||||
| 1870 | if (d->ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate && command.testFlag(QItemSelectionModel::Toggle)) {
| 0 | ||||||||||||||||||||||||
| 1871 | command &= ~QItemSelectionModel::Toggle; | - | ||||||||||||||||||||||||
| 1872 | command |= d->ctrlDragSelectionFlag; | - | ||||||||||||||||||||||||
| 1873 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1874 | - | |||||||||||||||||||||||||
| 1875 | // Do the normalize ourselves, since QRect::normalized() is flawed | - | ||||||||||||||||||||||||
| 1876 | QRect selectionRect = QRect(topLeft, bottomRight); | - | ||||||||||||||||||||||||
| 1877 | setSelection(selectionRect, command); | - | ||||||||||||||||||||||||
| 1878 | - | |||||||||||||||||||||||||
| 1879 | // set at the end because it might scroll the view | - | ||||||||||||||||||||||||
| 1880 | if (index.isValid()
| 0 | ||||||||||||||||||||||||
| 1881 | && (index != d->selectionModel->currentIndex())
| 0 | ||||||||||||||||||||||||
| 1882 | && d->isIndexEnabled(index))
| 0 | ||||||||||||||||||||||||
| 1883 | d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); never executed: d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); | 0 | ||||||||||||||||||||||||
| 1884 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1885 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1886 | - | |||||||||||||||||||||||||
| 1887 | /*! | - | ||||||||||||||||||||||||
| 1888 | This function is called with the given \a event when a mouse button is released, | - | ||||||||||||||||||||||||
| 1889 | after a mouse press event on the widget. If a user presses the mouse inside your | - | ||||||||||||||||||||||||
| 1890 | widget and then drags the mouse to another location before releasing the mouse button, | - | ||||||||||||||||||||||||
| 1891 | your widget receives the release event. The function will emit the clicked() signal if an | - | ||||||||||||||||||||||||
| 1892 | item was being pressed. | - | ||||||||||||||||||||||||
| 1893 | */ | - | ||||||||||||||||||||||||
| 1894 | void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 1895 | { | - | ||||||||||||||||||||||||
| 1896 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1897 | - | |||||||||||||||||||||||||
| 1898 | QPoint pos = event->pos(); | - | ||||||||||||||||||||||||
| 1899 | QPersistentModelIndex index = indexAt(pos); | - | ||||||||||||||||||||||||
| 1900 | - | |||||||||||||||||||||||||
| 1901 | if (state() == EditingState) {
| 0 | ||||||||||||||||||||||||
| 1902 | if (d->isIndexValid(index)
| 0 | ||||||||||||||||||||||||
| 1903 | && d->isIndexEnabled(index)
| 0 | ||||||||||||||||||||||||
| 1904 | && d->sendDelegateEvent(index, event))
| 0 | ||||||||||||||||||||||||
| 1905 | update(index); never executed: update(index); | 0 | ||||||||||||||||||||||||
| 1906 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1907 | } | - | ||||||||||||||||||||||||
| 1908 | - | |||||||||||||||||||||||||
| 1909 | bool click = (index == d->pressedIndex && index.isValid());
| 0 | ||||||||||||||||||||||||
| 1910 | bool selectedClicked = click && (event->button() == Qt::LeftButton) && d->pressedAlreadySelected;
| 0 | ||||||||||||||||||||||||
| 1911 | EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers);
| 0 | ||||||||||||||||||||||||
| 1912 | bool edited = edit(index, trigger, event); | - | ||||||||||||||||||||||||
| 1913 | - | |||||||||||||||||||||||||
| 1914 | d->ctrlDragSelectionFlag = QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||||||||
| 1915 | - | |||||||||||||||||||||||||
| 1916 | if (d->selectionModel && d->noSelectionOnMousePress) {
| 0 | ||||||||||||||||||||||||
| 1917 | d->noSelectionOnMousePress = false; | - | ||||||||||||||||||||||||
| 1918 | d->selectionModel->select(index, selectionCommand(index, event)); | - | ||||||||||||||||||||||||
| 1919 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1920 | - | |||||||||||||||||||||||||
| 1921 | setState(NoState); | - | ||||||||||||||||||||||||
| 1922 | - | |||||||||||||||||||||||||
| 1923 | if (click) {
| 0 | ||||||||||||||||||||||||
| 1924 | if (event->button() == Qt::LeftButton)
| 0 | ||||||||||||||||||||||||
| 1925 | emit clicked(index); never executed: clicked(index); | 0 | ||||||||||||||||||||||||
| 1926 | if (edited)
| 0 | ||||||||||||||||||||||||
| 1927 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1928 | QStyleOptionViewItem option = d->viewOptionsV1(); | - | ||||||||||||||||||||||||
| 1929 | if (d->pressedAlreadySelected)
| 0 | ||||||||||||||||||||||||
| 1930 | option.state |= QStyle::State_Selected; never executed: option.state |= QStyle::State_Selected; | 0 | ||||||||||||||||||||||||
| 1931 | if ((model()->flags(index) & Qt::ItemIsEnabled)
| 0 | ||||||||||||||||||||||||
| 1932 | && style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this))
| 0 | ||||||||||||||||||||||||
| 1933 | emit activated(index); never executed: activated(index); | 0 | ||||||||||||||||||||||||
| 1934 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1935 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1936 | - | |||||||||||||||||||||||||
| 1937 | /*! | - | ||||||||||||||||||||||||
| 1938 | This function is called with the given \a event when a mouse button is | - | ||||||||||||||||||||||||
| 1939 | double clicked inside the widget. If the double-click is on a valid item it | - | ||||||||||||||||||||||||
| 1940 | emits the doubleClicked() signal and calls edit() on the item. | - | ||||||||||||||||||||||||
| 1941 | */ | - | ||||||||||||||||||||||||
| 1942 | void QAbstractItemView::mouseDoubleClickEvent(QMouseEvent *event) | - | ||||||||||||||||||||||||
| 1943 | { | - | ||||||||||||||||||||||||
| 1944 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1945 | - | |||||||||||||||||||||||||
| 1946 | QModelIndex index = indexAt(event->pos()); | - | ||||||||||||||||||||||||
| 1947 | if (!index.isValid()
| 0 | ||||||||||||||||||||||||
| 1948 | || !d->isIndexEnabled(index)
| 0 | ||||||||||||||||||||||||
| 1949 | || (d->pressedIndex != index)) {
| 0 | ||||||||||||||||||||||||
| 1950 | QMouseEvent me(QEvent::MouseButtonPress, | - | ||||||||||||||||||||||||
| 1951 | event->localPos(), event->windowPos(), event->screenPos(), | - | ||||||||||||||||||||||||
| 1952 | event->button(), event->buttons(), event->modifiers(), event->source()); | - | ||||||||||||||||||||||||
| 1953 | mousePressEvent(&me); | - | ||||||||||||||||||||||||
| 1954 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1955 | } | - | ||||||||||||||||||||||||
| 1956 | // signal handlers may change the model | - | ||||||||||||||||||||||||
| 1957 | QPersistentModelIndex persistent = index; | - | ||||||||||||||||||||||||
| 1958 | emit doubleClicked(persistent); | - | ||||||||||||||||||||||||
| 1959 | if ((event->button() == Qt::LeftButton) && !edit(persistent, DoubleClicked, event)
| 0 | ||||||||||||||||||||||||
| 1960 | && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this))
| 0 | ||||||||||||||||||||||||
| 1961 | emit activated(persistent); never executed: activated(persistent); | 0 | ||||||||||||||||||||||||
| 1962 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1963 | - | |||||||||||||||||||||||||
| 1964 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 1965 | - | |||||||||||||||||||||||||
| 1966 | /*! | - | ||||||||||||||||||||||||
| 1967 | This function is called with the given \a event when a drag and drop operation enters | - | ||||||||||||||||||||||||
| 1968 | the widget. If the drag is over a valid dropping place (e.g. over an item that | - | ||||||||||||||||||||||||
| 1969 | accepts drops), the event is accepted; otherwise it is ignored. | - | ||||||||||||||||||||||||
| 1970 | - | |||||||||||||||||||||||||
| 1971 | \sa dropEvent(), startDrag() | - | ||||||||||||||||||||||||
| 1972 | */ | - | ||||||||||||||||||||||||
| 1973 | void QAbstractItemView::dragEnterEvent(QDragEnterEvent *event) | - | ||||||||||||||||||||||||
| 1974 | { | - | ||||||||||||||||||||||||
| 1975 | if (dragDropMode() == InternalMove
| 0 | ||||||||||||||||||||||||
| 1976 | && (event->source() != this|| !(event->possibleActions() & Qt::MoveAction)))
| 0 | ||||||||||||||||||||||||
| 1977 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1978 | - | |||||||||||||||||||||||||
| 1979 | if (d_func()->canDrop(event)) {
| 0 | ||||||||||||||||||||||||
| 1980 | event->accept(); | - | ||||||||||||||||||||||||
| 1981 | setState(DraggingState); | - | ||||||||||||||||||||||||
| 1982 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1983 | event->ignore(); | - | ||||||||||||||||||||||||
| 1984 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1985 | } | - | ||||||||||||||||||||||||
| 1986 | - | |||||||||||||||||||||||||
| 1987 | /*! | - | ||||||||||||||||||||||||
| 1988 | This function is called continuously with the given \a event during a drag and | - | ||||||||||||||||||||||||
| 1989 | drop operation over the widget. It can cause the view to scroll if, for example, | - | ||||||||||||||||||||||||
| 1990 | the user drags a selection to view's right or bottom edge. In this case, the | - | ||||||||||||||||||||||||
| 1991 | event will be accepted; otherwise it will be ignored. | - | ||||||||||||||||||||||||
| 1992 | - | |||||||||||||||||||||||||
| 1993 | \sa dropEvent(), startDrag() | - | ||||||||||||||||||||||||
| 1994 | */ | - | ||||||||||||||||||||||||
| 1995 | void QAbstractItemView::dragMoveEvent(QDragMoveEvent *event) | - | ||||||||||||||||||||||||
| 1996 | { | - | ||||||||||||||||||||||||
| 1997 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 1998 | if (dragDropMode() == InternalMove
| 0 | ||||||||||||||||||||||||
| 1999 | && (event->source() != this || !(event->possibleActions() & Qt::MoveAction)))
| 0 | ||||||||||||||||||||||||
| 2000 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2001 | - | |||||||||||||||||||||||||
| 2002 | // ignore by default | - | ||||||||||||||||||||||||
| 2003 | event->ignore(); | - | ||||||||||||||||||||||||
| 2004 | - | |||||||||||||||||||||||||
| 2005 | QModelIndex index = indexAt(event->pos()); | - | ||||||||||||||||||||||||
| 2006 | d->hover = index; | - | ||||||||||||||||||||||||
| 2007 | if (!d->droppingOnItself(event, index)
| 0 | ||||||||||||||||||||||||
| 2008 | && d->canDrop(event)) {
| 0 | ||||||||||||||||||||||||
| 2009 | - | |||||||||||||||||||||||||
| 2010 | if (index.isValid() && d->showDropIndicator) {
| 0 | ||||||||||||||||||||||||
| 2011 | QRect rect = visualRect(index); | - | ||||||||||||||||||||||||
| 2012 | d->dropIndicatorPosition = d->position(event->pos(), rect, index); | - | ||||||||||||||||||||||||
| 2013 | switch (d->dropIndicatorPosition) { | - | ||||||||||||||||||||||||
| 2014 | case AboveItem: never executed: case AboveItem: | 0 | ||||||||||||||||||||||||
| 2015 | if (d->isIndexDropEnabled(index.parent())) {
| 0 | ||||||||||||||||||||||||
| 2016 | d->dropIndicatorRect = QRect(rect.left(), rect.top(), rect.width(), 0); | - | ||||||||||||||||||||||||
| 2017 | event->acceptProposedAction(); | - | ||||||||||||||||||||||||
| 2018 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2019 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
| 2020 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2021 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2022 | case BelowItem: never executed: case BelowItem: | 0 | ||||||||||||||||||||||||
| 2023 | if (d->isIndexDropEnabled(index.parent())) {
| 0 | ||||||||||||||||||||||||
| 2024 | d->dropIndicatorRect = QRect(rect.left(), rect.bottom(), rect.width(), 0); | - | ||||||||||||||||||||||||
| 2025 | event->acceptProposedAction(); | - | ||||||||||||||||||||||||
| 2026 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2027 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
| 2028 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2029 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2030 | case OnItem: never executed: case OnItem: | 0 | ||||||||||||||||||||||||
| 2031 | if (d->isIndexDropEnabled(index)) {
| 0 | ||||||||||||||||||||||||
| 2032 | d->dropIndicatorRect = rect; | - | ||||||||||||||||||||||||
| 2033 | event->acceptProposedAction(); | - | ||||||||||||||||||||||||
| 2034 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2035 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
| 2036 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2037 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2038 | case OnViewport: never executed: case OnViewport: | 0 | ||||||||||||||||||||||||
| 2039 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
| 2040 | if (d->isIndexDropEnabled(rootIndex())) {
| 0 | ||||||||||||||||||||||||
| 2041 | event->acceptProposedAction(); // allow dropping in empty areas | - | ||||||||||||||||||||||||
| 2042 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2043 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2044 | } | - | ||||||||||||||||||||||||
| 2045 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2046 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
| 2047 | d->dropIndicatorPosition = OnViewport; | - | ||||||||||||||||||||||||
| 2048 | if (d->isIndexDropEnabled(rootIndex())) {
| 0 | ||||||||||||||||||||||||
| 2049 | event->acceptProposedAction(); // allow dropping in empty areas | - | ||||||||||||||||||||||||
| 2050 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2051 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2052 | d->viewport->update(); | - | ||||||||||||||||||||||||
| 2053 | } // can drop never executed: end of block | 0 | ||||||||||||||||||||||||
| 2054 | - | |||||||||||||||||||||||||
| 2055 | if (d->shouldAutoScroll(event->pos()))
| 0 | ||||||||||||||||||||||||
| 2056 | startAutoScroll(); never executed: startAutoScroll(); | 0 | ||||||||||||||||||||||||
| 2057 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2058 | - | |||||||||||||||||||||||||
| 2059 | /*! | - | ||||||||||||||||||||||||
| 2060 | \internal | - | ||||||||||||||||||||||||
| 2061 | Return true if this is a move from ourself and \a index is a child of the selection that | - | ||||||||||||||||||||||||
| 2062 | is being moved. | - | ||||||||||||||||||||||||
| 2063 | */ | - | ||||||||||||||||||||||||
| 2064 | bool QAbstractItemViewPrivate::droppingOnItself(QDropEvent *event, const QModelIndex &index) | - | ||||||||||||||||||||||||
| 2065 | { | - | ||||||||||||||||||||||||
| 2066 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2067 | Qt::DropAction dropAction = event->dropAction(); | - | ||||||||||||||||||||||||
| 2068 | if (q->dragDropMode() == QAbstractItemView::InternalMove)
| 0 | ||||||||||||||||||||||||
| 2069 | dropAction = Qt::MoveAction; never executed: dropAction = Qt::MoveAction; | 0 | ||||||||||||||||||||||||
| 2070 | if (event->source() == q
| 0 | ||||||||||||||||||||||||
| 2071 | && event->possibleActions() & Qt::MoveAction
| 0 | ||||||||||||||||||||||||
| 2072 | && dropAction == Qt::MoveAction) {
| 0 | ||||||||||||||||||||||||
| 2073 | QModelIndexList selectedIndexes = q->selectedIndexes(); | - | ||||||||||||||||||||||||
| 2074 | QModelIndex child = index; | - | ||||||||||||||||||||||||
| 2075 | while (child.isValid() && child != root) {
| 0 | ||||||||||||||||||||||||
| 2076 | if (selectedIndexes.contains(child))
| 0 | ||||||||||||||||||||||||
| 2077 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 2078 | child = child.parent(); | - | ||||||||||||||||||||||||
| 2079 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2080 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2081 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2082 | } | - | ||||||||||||||||||||||||
| 2083 | - | |||||||||||||||||||||||||
| 2084 | /*! | - | ||||||||||||||||||||||||
| 2085 | \fn void QAbstractItemView::dragLeaveEvent(QDragLeaveEvent *event) | - | ||||||||||||||||||||||||
| 2086 | - | |||||||||||||||||||||||||
| 2087 | This function is called when the item being dragged leaves the view. | - | ||||||||||||||||||||||||
| 2088 | The \a event describes the state of the drag and drop operation. | - | ||||||||||||||||||||||||
| 2089 | */ | - | ||||||||||||||||||||||||
| 2090 | void QAbstractItemView::dragLeaveEvent(QDragLeaveEvent *) | - | ||||||||||||||||||||||||
| 2091 | { | - | ||||||||||||||||||||||||
| 2092 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2093 | stopAutoScroll(); | - | ||||||||||||||||||||||||
| 2094 | setState(NoState); | - | ||||||||||||||||||||||||
| 2095 | d->hover = QModelIndex(); | - | ||||||||||||||||||||||||
| 2096 | d->viewport->update(); | - | ||||||||||||||||||||||||
| 2097 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2098 | - | |||||||||||||||||||||||||
| 2099 | /*! | - | ||||||||||||||||||||||||
| 2100 | This function is called with the given \a event when a drop event occurs over | - | ||||||||||||||||||||||||
| 2101 | the widget. If the model accepts the even position the drop event is accepted; | - | ||||||||||||||||||||||||
| 2102 | otherwise it is ignored. | - | ||||||||||||||||||||||||
| 2103 | - | |||||||||||||||||||||||||
| 2104 | \sa startDrag() | - | ||||||||||||||||||||||||
| 2105 | */ | - | ||||||||||||||||||||||||
| 2106 | void QAbstractItemView::dropEvent(QDropEvent *event) | - | ||||||||||||||||||||||||
| 2107 | { | - | ||||||||||||||||||||||||
| 2108 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2109 | if (dragDropMode() == InternalMove) {
| 0 | ||||||||||||||||||||||||
| 2110 | if (event->source() != this || !(event->possibleActions() & Qt::MoveAction))
| 0 | ||||||||||||||||||||||||
| 2111 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2112 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2113 | - | |||||||||||||||||||||||||
| 2114 | QModelIndex index; | - | ||||||||||||||||||||||||
| 2115 | int col = -1; | - | ||||||||||||||||||||||||
| 2116 | int row = -1; | - | ||||||||||||||||||||||||
| 2117 | if (d->dropOn(event, &row, &col, &index)) {
| 0 | ||||||||||||||||||||||||
| 2118 | const Qt::DropAction action = dragDropMode() == InternalMove ? Qt::MoveAction : event->dropAction();
| 0 | ||||||||||||||||||||||||
| 2119 | if (d->model->dropMimeData(event->mimeData(), action, row, col, index)) {
| 0 | ||||||||||||||||||||||||
| 2120 | if (action != event->dropAction()) {
| 0 | ||||||||||||||||||||||||
| 2121 | event->setDropAction(action); | - | ||||||||||||||||||||||||
| 2122 | event->accept(); | - | ||||||||||||||||||||||||
| 2123 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2124 | event->acceptProposedAction(); | - | ||||||||||||||||||||||||
| 2125 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2126 | } | - | ||||||||||||||||||||||||
| 2127 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2128 | stopAutoScroll(); | - | ||||||||||||||||||||||||
| 2129 | setState(NoState); | - | ||||||||||||||||||||||||
| 2130 | d->viewport->update(); | - | ||||||||||||||||||||||||
| 2131 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2132 | - | |||||||||||||||||||||||||
| 2133 | /*! | - | ||||||||||||||||||||||||
| 2134 | If the event hasn't already been accepted, determines the index to drop on. | - | ||||||||||||||||||||||||
| 2135 | - | |||||||||||||||||||||||||
| 2136 | if (row == -1 && col == -1) | - | ||||||||||||||||||||||||
| 2137 | // append to this drop index | - | ||||||||||||||||||||||||
| 2138 | else | - | ||||||||||||||||||||||||
| 2139 | // place at row, col in drop index | - | ||||||||||||||||||||||||
| 2140 | - | |||||||||||||||||||||||||
| 2141 | If it returns \c true a drop can be done, and dropRow, dropCol and dropIndex reflects the position of the drop. | - | ||||||||||||||||||||||||
| 2142 | \internal | - | ||||||||||||||||||||||||
| 2143 | */ | - | ||||||||||||||||||||||||
| 2144 | bool QAbstractItemViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex) | - | ||||||||||||||||||||||||
| 2145 | { | - | ||||||||||||||||||||||||
| 2146 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2147 | if (event->isAccepted())
| 0 | ||||||||||||||||||||||||
| 2148 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2149 | - | |||||||||||||||||||||||||
| 2150 | QModelIndex index; | - | ||||||||||||||||||||||||
| 2151 | // rootIndex() (i.e. the viewport) might be a valid index | - | ||||||||||||||||||||||||
| 2152 | if (viewport->rect().contains(event->pos())) {
| 0 | ||||||||||||||||||||||||
| 2153 | index = q->indexAt(event->pos()); | - | ||||||||||||||||||||||||
| 2154 | if (!index.isValid() || !q->visualRect(index).contains(event->pos()))
| 0 | ||||||||||||||||||||||||
| 2155 | index = root; never executed: index = root; | 0 | ||||||||||||||||||||||||
| 2156 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2157 | - | |||||||||||||||||||||||||
| 2158 | // If we are allowed to do the drop | - | ||||||||||||||||||||||||
| 2159 | if (model->supportedDropActions() & event->dropAction()) {
| 0 | ||||||||||||||||||||||||
| 2160 | int row = -1; | - | ||||||||||||||||||||||||
| 2161 | int col = -1; | - | ||||||||||||||||||||||||
| 2162 | if (index != root) {
| 0 | ||||||||||||||||||||||||
| 2163 | dropIndicatorPosition = position(event->pos(), q->visualRect(index), index); | - | ||||||||||||||||||||||||
| 2164 | switch (dropIndicatorPosition) { | - | ||||||||||||||||||||||||
| 2165 | case QAbstractItemView::AboveItem: never executed: case QAbstractItemView::AboveItem: | 0 | ||||||||||||||||||||||||
| 2166 | row = index.row(); | - | ||||||||||||||||||||||||
| 2167 | col = index.column(); | - | ||||||||||||||||||||||||
| 2168 | index = index.parent(); | - | ||||||||||||||||||||||||
| 2169 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2170 | case QAbstractItemView::BelowItem: never executed: case QAbstractItemView::BelowItem: | 0 | ||||||||||||||||||||||||
| 2171 | row = index.row() + 1; | - | ||||||||||||||||||||||||
| 2172 | col = index.column(); | - | ||||||||||||||||||||||||
| 2173 | index = index.parent(); | - | ||||||||||||||||||||||||
| 2174 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2175 | case QAbstractItemView::OnItem: never executed: case QAbstractItemView::OnItem: | 0 | ||||||||||||||||||||||||
| 2176 | case QAbstractItemView::OnViewport: never executed: case QAbstractItemView::OnViewport: | 0 | ||||||||||||||||||||||||
| 2177 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2178 | } | - | ||||||||||||||||||||||||
| 2179 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2180 | dropIndicatorPosition = QAbstractItemView::OnViewport; | - | ||||||||||||||||||||||||
| 2181 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2182 | *dropIndex = index; | - | ||||||||||||||||||||||||
| 2183 | *dropRow = row; | - | ||||||||||||||||||||||||
| 2184 | *dropCol = col; | - | ||||||||||||||||||||||||
| 2185 | if (!droppingOnItself(event, index))
| 0 | ||||||||||||||||||||||||
| 2186 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 2187 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2188 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2189 | } | - | ||||||||||||||||||||||||
| 2190 | - | |||||||||||||||||||||||||
| 2191 | QAbstractItemView::DropIndicatorPosition | - | ||||||||||||||||||||||||
| 2192 | QAbstractItemViewPrivate::position(const QPoint &pos, const QRect &rect, const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 2193 | { | - | ||||||||||||||||||||||||
| 2194 | QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport; | - | ||||||||||||||||||||||||
| 2195 | if (!overwrite) {
| 0 | ||||||||||||||||||||||||
| 2196 | const int margin = 2; | - | ||||||||||||||||||||||||
| 2197 | if (pos.y() - rect.top() < margin) {
| 0 | ||||||||||||||||||||||||
| 2198 | r = QAbstractItemView::AboveItem; | - | ||||||||||||||||||||||||
| 2199 | } else if (rect.bottom() - pos.y() < margin) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 2200 | r = QAbstractItemView::BelowItem; | - | ||||||||||||||||||||||||
| 2201 | } else if (rect.contains(pos, true)) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 2202 | r = QAbstractItemView::OnItem; | - | ||||||||||||||||||||||||
| 2203 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2204 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2205 | QRect touchingRect = rect; | - | ||||||||||||||||||||||||
| 2206 | touchingRect.adjust(-1, -1, 1, 1); | - | ||||||||||||||||||||||||
| 2207 | if (touchingRect.contains(pos, false)) {
| 0 | ||||||||||||||||||||||||
| 2208 | r = QAbstractItemView::OnItem; | - | ||||||||||||||||||||||||
| 2209 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2210 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2211 | - | |||||||||||||||||||||||||
| 2212 | if (r == QAbstractItemView::OnItem && (!(model->flags(index) & Qt::ItemIsDropEnabled)))
| 0 | ||||||||||||||||||||||||
| 2213 | r = pos.y() < rect.center().y() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem; never executed: r = pos.y() < rect.center().y() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem;
| 0 | ||||||||||||||||||||||||
| 2214 | - | |||||||||||||||||||||||||
| 2215 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||
| 2216 | } | - | ||||||||||||||||||||||||
| 2217 | - | |||||||||||||||||||||||||
| 2218 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 2219 | - | |||||||||||||||||||||||||
| 2220 | /*! | - | ||||||||||||||||||||||||
| 2221 | This function is called with the given \a event when the widget obtains the focus. | - | ||||||||||||||||||||||||
| 2222 | By default, the event is ignored. | - | ||||||||||||||||||||||||
| 2223 | - | |||||||||||||||||||||||||
| 2224 | \sa setFocus(), focusOutEvent() | - | ||||||||||||||||||||||||
| 2225 | */ | - | ||||||||||||||||||||||||
| 2226 | void QAbstractItemView::focusInEvent(QFocusEvent *event) | - | ||||||||||||||||||||||||
| 2227 | { | - | ||||||||||||||||||||||||
| 2228 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2229 | QAbstractScrollArea::focusInEvent(event); | - | ||||||||||||||||||||||||
| 2230 | - | |||||||||||||||||||||||||
| 2231 | const QItemSelectionModel* model = selectionModel(); | - | ||||||||||||||||||||||||
| 2232 | const bool currentIndexValid = currentIndex().isValid(); | - | ||||||||||||||||||||||||
| 2233 | - | |||||||||||||||||||||||||
| 2234 | if (model
| 0 | ||||||||||||||||||||||||
| 2235 | && !d->currentIndexSet
| 0 | ||||||||||||||||||||||||
| 2236 | && !currentIndexValid) {
| 0 | ||||||||||||||||||||||||
| 2237 | bool autoScroll = d->autoScroll; | - | ||||||||||||||||||||||||
| 2238 | d->autoScroll = false; | - | ||||||||||||||||||||||||
| 2239 | QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); // first visible index | - | ||||||||||||||||||||||||
| 2240 | if (index.isValid() && d->isIndexEnabled(index) && event->reason() != Qt::MouseFocusReason)
| 0 | ||||||||||||||||||||||||
| 2241 | selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); never executed: selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); | 0 | ||||||||||||||||||||||||
| 2242 | d->autoScroll = autoScroll; | - | ||||||||||||||||||||||||
| 2243 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2244 | - | |||||||||||||||||||||||||
| 2245 | if (model && currentIndexValid) {
| 0 | ||||||||||||||||||||||||
| 2246 | if (currentIndex().flags() != Qt::ItemIsEditable)
| 0 | ||||||||||||||||||||||||
| 2247 | setAttribute(Qt::WA_InputMethodEnabled, false); never executed: setAttribute(Qt::WA_InputMethodEnabled, false); | 0 | ||||||||||||||||||||||||
| 2248 | else | - | ||||||||||||||||||||||||
| 2249 | setAttribute(Qt::WA_InputMethodEnabled); never executed: setAttribute(Qt::WA_InputMethodEnabled); | 0 | ||||||||||||||||||||||||
| 2250 | } | - | ||||||||||||||||||||||||
| 2251 | - | |||||||||||||||||||||||||
| 2252 | if (!currentIndexValid)
| 0 | ||||||||||||||||||||||||
| 2253 | setAttribute(Qt::WA_InputMethodEnabled, false); never executed: setAttribute(Qt::WA_InputMethodEnabled, false); | 0 | ||||||||||||||||||||||||
| 2254 | - | |||||||||||||||||||||||||
| 2255 | d->viewport->update(); | - | ||||||||||||||||||||||||
| 2256 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2257 | - | |||||||||||||||||||||||||
| 2258 | /*! | - | ||||||||||||||||||||||||
| 2259 | This function is called with the given \a event when the widget | - | ||||||||||||||||||||||||
| 2260 | looses the focus. By default, the event is ignored. | - | ||||||||||||||||||||||||
| 2261 | - | |||||||||||||||||||||||||
| 2262 | \sa clearFocus(), focusInEvent() | - | ||||||||||||||||||||||||
| 2263 | */ | - | ||||||||||||||||||||||||
| 2264 | void QAbstractItemView::focusOutEvent(QFocusEvent *event) | - | ||||||||||||||||||||||||
| 2265 | { | - | ||||||||||||||||||||||||
| 2266 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2267 | QAbstractScrollArea::focusOutEvent(event); | - | ||||||||||||||||||||||||
| 2268 | d->viewport->update(); | - | ||||||||||||||||||||||||
| 2269 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2270 | - | |||||||||||||||||||||||||
| 2271 | /*! | - | ||||||||||||||||||||||||
| 2272 | This function is called with the given \a event when a key event is sent to | - | ||||||||||||||||||||||||
| 2273 | the widget. The default implementation handles basic cursor movement, e.g. Up, | - | ||||||||||||||||||||||||
| 2274 | Down, Left, Right, Home, PageUp, and PageDown; the activated() signal is | - | ||||||||||||||||||||||||
| 2275 | emitted if the current index is valid and the activation key is pressed | - | ||||||||||||||||||||||||
| 2276 | (e.g. Enter or Return, depending on the platform). | - | ||||||||||||||||||||||||
| 2277 | This function is where editing is initiated by key press, e.g. if F2 is | - | ||||||||||||||||||||||||
| 2278 | pressed. | - | ||||||||||||||||||||||||
| 2279 | - | |||||||||||||||||||||||||
| 2280 | \sa edit(), moveCursor(), keyboardSearch(), tabKeyNavigation | - | ||||||||||||||||||||||||
| 2281 | */ | - | ||||||||||||||||||||||||
| 2282 | void QAbstractItemView::keyPressEvent(QKeyEvent *event) | - | ||||||||||||||||||||||||
| 2283 | { | - | ||||||||||||||||||||||||
| 2284 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2285 | d->delayedAutoScroll.stop(); //any interaction with the view cancel the auto scrolling | - | ||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||
| 2287 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 2288 | switch (event->key()) { | - | ||||||||||||||||||||||||
| 2289 | case Qt::Key_Select: | - | ||||||||||||||||||||||||
| 2290 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
| 2291 | if (!hasEditFocus()) { | - | ||||||||||||||||||||||||
| 2292 | setEditFocus(true); | - | ||||||||||||||||||||||||
| 2293 | return; | - | ||||||||||||||||||||||||
| 2294 | } | - | ||||||||||||||||||||||||
| 2295 | } | - | ||||||||||||||||||||||||
| 2296 | break; | - | ||||||||||||||||||||||||
| 2297 | case Qt::Key_Back: | - | ||||||||||||||||||||||||
| 2298 | if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { | - | ||||||||||||||||||||||||
| 2299 | setEditFocus(false); | - | ||||||||||||||||||||||||
| 2300 | } else { | - | ||||||||||||||||||||||||
| 2301 | event->ignore(); | - | ||||||||||||||||||||||||
| 2302 | } | - | ||||||||||||||||||||||||
| 2303 | return; | - | ||||||||||||||||||||||||
| 2304 | case Qt::Key_Down: | - | ||||||||||||||||||||||||
| 2305 | case Qt::Key_Up: | - | ||||||||||||||||||||||||
| 2306 | // Let's ignore vertical navigation events, only if there is no other widget | - | ||||||||||||||||||||||||
| 2307 | // what can take the focus in vertical direction. This means widget can handle navigation events | - | ||||||||||||||||||||||||
| 2308 | // even the widget don't have edit focus, and there is no other widget in requested direction. | - | ||||||||||||||||||||||||
| 2309 | if(QApplication::keypadNavigationEnabled() && !hasEditFocus() | - | ||||||||||||||||||||||||
| 2310 | && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) { | - | ||||||||||||||||||||||||
| 2311 | event->ignore(); | - | ||||||||||||||||||||||||
| 2312 | return; | - | ||||||||||||||||||||||||
| 2313 | } | - | ||||||||||||||||||||||||
| 2314 | break; | - | ||||||||||||||||||||||||
| 2315 | case Qt::Key_Left: | - | ||||||||||||||||||||||||
| 2316 | case Qt::Key_Right: | - | ||||||||||||||||||||||||
| 2317 | // Similar logic as in up and down events | - | ||||||||||||||||||||||||
| 2318 | if(QApplication::keypadNavigationEnabled() && !hasEditFocus() | - | ||||||||||||||||||||||||
| 2319 | && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this))) { | - | ||||||||||||||||||||||||
| 2320 | event->ignore(); | - | ||||||||||||||||||||||||
| 2321 | return; | - | ||||||||||||||||||||||||
| 2322 | } | - | ||||||||||||||||||||||||
| 2323 | break; | - | ||||||||||||||||||||||||
| 2324 | default: | - | ||||||||||||||||||||||||
| 2325 | if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { | - | ||||||||||||||||||||||||
| 2326 | event->ignore(); | - | ||||||||||||||||||||||||
| 2327 | return; | - | ||||||||||||||||||||||||
| 2328 | } | - | ||||||||||||||||||||||||
| 2329 | } | - | ||||||||||||||||||||||||
| 2330 | #endif | - | ||||||||||||||||||||||||
| 2331 | - | |||||||||||||||||||||||||
| 2332 | #if !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT) | - | ||||||||||||||||||||||||
| 2333 | if (event == QKeySequence::Copy) {
| 0 | ||||||||||||||||||||||||
| 2334 | QVariant variant; | - | ||||||||||||||||||||||||
| 2335 | if (d->model)
| 0 | ||||||||||||||||||||||||
| 2336 | variant = d->model->data(currentIndex(), Qt::DisplayRole); never executed: variant = d->model->data(currentIndex(), Qt::DisplayRole); | 0 | ||||||||||||||||||||||||
| 2337 | if (variant.type() == QVariant::String)
| 0 | ||||||||||||||||||||||||
| 2338 | QApplication::clipboard()->setText(variant.toString()); never executed: QApplication::clipboard()->setText(variant.toString()); | 0 | ||||||||||||||||||||||||
| 2339 | event->accept(); | - | ||||||||||||||||||||||||
| 2340 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2341 | #endif | - | ||||||||||||||||||||||||
| 2342 | - | |||||||||||||||||||||||||
| 2343 | QPersistentModelIndex newCurrent; | - | ||||||||||||||||||||||||
| 2344 | d->moveCursorUpdatedView = false; | - | ||||||||||||||||||||||||
| 2345 | switch (event->key()) { | - | ||||||||||||||||||||||||
| 2346 | case Qt::Key_Down: never executed: case Qt::Key_Down: | 0 | ||||||||||||||||||||||||
| 2347 | newCurrent = moveCursor(MoveDown, event->modifiers()); | - | ||||||||||||||||||||||||
| 2348 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2349 | case Qt::Key_Up: never executed: case Qt::Key_Up: | 0 | ||||||||||||||||||||||||
| 2350 | newCurrent = moveCursor(MoveUp, event->modifiers()); | - | ||||||||||||||||||||||||
| 2351 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2352 | case Qt::Key_Left: never executed: case Qt::Key_Left: | 0 | ||||||||||||||||||||||||
| 2353 | newCurrent = moveCursor(MoveLeft, event->modifiers()); | - | ||||||||||||||||||||||||
| 2354 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2355 | case Qt::Key_Right: never executed: case Qt::Key_Right: | 0 | ||||||||||||||||||||||||
| 2356 | newCurrent = moveCursor(MoveRight, event->modifiers()); | - | ||||||||||||||||||||||||
| 2357 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2358 | case Qt::Key_Home: never executed: case Qt::Key_Home: | 0 | ||||||||||||||||||||||||
| 2359 | newCurrent = moveCursor(MoveHome, event->modifiers()); | - | ||||||||||||||||||||||||
| 2360 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2361 | case Qt::Key_End: never executed: case Qt::Key_End: | 0 | ||||||||||||||||||||||||
| 2362 | newCurrent = moveCursor(MoveEnd, event->modifiers()); | - | ||||||||||||||||||||||||
| 2363 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2364 | case Qt::Key_PageUp: never executed: case Qt::Key_PageUp: | 0 | ||||||||||||||||||||||||
| 2365 | newCurrent = moveCursor(MovePageUp, event->modifiers()); | - | ||||||||||||||||||||||||
| 2366 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2367 | case Qt::Key_PageDown: never executed: case Qt::Key_PageDown: | 0 | ||||||||||||||||||||||||
| 2368 | newCurrent = moveCursor(MovePageDown, event->modifiers()); | - | ||||||||||||||||||||||||
| 2369 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2370 | case Qt::Key_Tab: never executed: case Qt::Key_Tab: | 0 | ||||||||||||||||||||||||
| 2371 | if (d->tabKeyNavigation)
| 0 | ||||||||||||||||||||||||
| 2372 | newCurrent = moveCursor(MoveNext, event->modifiers()); never executed: newCurrent = moveCursor(MoveNext, event->modifiers()); | 0 | ||||||||||||||||||||||||
| 2373 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2374 | case Qt::Key_Backtab: never executed: case Qt::Key_Backtab: | 0 | ||||||||||||||||||||||||
| 2375 | if (d->tabKeyNavigation)
| 0 | ||||||||||||||||||||||||
| 2376 | newCurrent = moveCursor(MovePrevious, event->modifiers()); never executed: newCurrent = moveCursor(MovePrevious, event->modifiers()); | 0 | ||||||||||||||||||||||||
| 2377 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2378 | } | - | ||||||||||||||||||||||||
| 2379 | - | |||||||||||||||||||||||||
| 2380 | QPersistentModelIndex oldCurrent = currentIndex(); | - | ||||||||||||||||||||||||
| 2381 | if (newCurrent != oldCurrent && newCurrent.isValid() && d->isIndexEnabled(newCurrent)) {
| 0 | ||||||||||||||||||||||||
| 2382 | if (!hasFocus() && QApplication::focusWidget() == indexWidget(oldCurrent))
| 0 | ||||||||||||||||||||||||
| 2383 | setFocus(); never executed: setFocus(); | 0 | ||||||||||||||||||||||||
| 2384 | QItemSelectionModel::SelectionFlags command = selectionCommand(newCurrent, event); | - | ||||||||||||||||||||||||
| 2385 | if (command != QItemSelectionModel::NoUpdate
| 0 | ||||||||||||||||||||||||
| 2386 | || style()->styleHint(QStyle::SH_ItemView_MovementWithoutUpdatingSelection, 0, this)) {
| 0 | ||||||||||||||||||||||||
| 2387 | // note that we don't check if the new current index is enabled because moveCursor() makes sure it is | - | ||||||||||||||||||||||||
| 2388 | if (command & QItemSelectionModel::Current) {
| 0 | ||||||||||||||||||||||||
| 2389 | d->selectionModel->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||||||||
| 2390 | if (!d->currentSelectionStartIndex.isValid())
| 0 | ||||||||||||||||||||||||
| 2391 | d->currentSelectionStartIndex = oldCurrent; never executed: d->currentSelectionStartIndex = oldCurrent; | 0 | ||||||||||||||||||||||||
| 2392 | QRect rect(visualRect(d->currentSelectionStartIndex).center(), visualRect(newCurrent).center()); | - | ||||||||||||||||||||||||
| 2393 | setSelection(rect, command); | - | ||||||||||||||||||||||||
| 2394 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2395 | d->selectionModel->setCurrentIndex(newCurrent, command); | - | ||||||||||||||||||||||||
| 2396 | d->currentSelectionStartIndex = newCurrent; | - | ||||||||||||||||||||||||
| 2397 | if (newCurrent.isValid()) {
| 0 | ||||||||||||||||||||||||
| 2398 | // We copy the same behaviour as for mousePressEvent(). | - | ||||||||||||||||||||||||
| 2399 | QRect rect(visualRect(newCurrent).center(), QSize(1, 1)); | - | ||||||||||||||||||||||||
| 2400 | setSelection(rect, command); | - | ||||||||||||||||||||||||
| 2401 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2402 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2403 | event->accept(); | - | ||||||||||||||||||||||||
| 2404 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2405 | } | - | ||||||||||||||||||||||||
| 2406 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2407 | - | |||||||||||||||||||||||||
| 2408 | switch (event->key()) { | - | ||||||||||||||||||||||||
| 2409 | // ignored keys | - | ||||||||||||||||||||||||
| 2410 | case Qt::Key_Down: never executed: case Qt::Key_Down: | 0 | ||||||||||||||||||||||||
| 2411 | case Qt::Key_Up: never executed: case Qt::Key_Up: | 0 | ||||||||||||||||||||||||
| 2412 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 2413 | if (QApplication::keypadNavigationEnabled() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) { | - | ||||||||||||||||||||||||
| 2414 | event->accept(); // don't change focus | - | ||||||||||||||||||||||||
| 2415 | break; | - | ||||||||||||||||||||||||
| 2416 | } | - | ||||||||||||||||||||||||
| 2417 | #endif | - | ||||||||||||||||||||||||
| 2418 | case Qt::Key_Left: never executed: case Qt::Key_Left: | 0 | ||||||||||||||||||||||||
| 2419 | case Qt::Key_Right: never executed: case Qt::Key_Right: | 0 | ||||||||||||||||||||||||
| 2420 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 2421 | if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional | - | ||||||||||||||||||||||||
| 2422 | && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) | - | ||||||||||||||||||||||||
| 2423 | || (QWidgetPrivate::inTabWidget(this) && d->model->columnCount(d->root) > 1))) { | - | ||||||||||||||||||||||||
| 2424 | event->accept(); // don't change focus | - | ||||||||||||||||||||||||
| 2425 | break; | - | ||||||||||||||||||||||||
| 2426 | } | - | ||||||||||||||||||||||||
| 2427 | #endif // QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 2428 | case Qt::Key_Home: never executed: case Qt::Key_Home: | 0 | ||||||||||||||||||||||||
| 2429 | case Qt::Key_End: never executed: case Qt::Key_End: | 0 | ||||||||||||||||||||||||
| 2430 | case Qt::Key_PageUp: never executed: case Qt::Key_PageUp: | 0 | ||||||||||||||||||||||||
| 2431 | case Qt::Key_PageDown: never executed: case Qt::Key_PageDown: | 0 | ||||||||||||||||||||||||
| 2432 | case Qt::Key_Escape: never executed: case Qt::Key_Escape: | 0 | ||||||||||||||||||||||||
| 2433 | case Qt::Key_Shift: never executed: case Qt::Key_Shift: | 0 | ||||||||||||||||||||||||
| 2434 | case Qt::Key_Control: never executed: case Qt::Key_Control: | 0 | ||||||||||||||||||||||||
| 2435 | case Qt::Key_Delete: never executed: case Qt::Key_Delete: | 0 | ||||||||||||||||||||||||
| 2436 | case Qt::Key_Backspace: never executed: case Qt::Key_Backspace: | 0 | ||||||||||||||||||||||||
| 2437 | event->ignore(); | - | ||||||||||||||||||||||||
| 2438 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2439 | case Qt::Key_Space: never executed: case Qt::Key_Space: | 0 | ||||||||||||||||||||||||
| 2440 | case Qt::Key_Select: never executed: case Qt::Key_Select: | 0 | ||||||||||||||||||||||||
| 2441 | if (!edit(currentIndex(), AnyKeyPressed, event) && d->selectionModel)
| 0 | ||||||||||||||||||||||||
| 2442 | d->selectionModel->select(currentIndex(), selectionCommand(currentIndex(), event)); never executed: d->selectionModel->select(currentIndex(), selectionCommand(currentIndex(), event)); | 0 | ||||||||||||||||||||||||
| 2443 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 2444 | if ( event->key()==Qt::Key_Select ) { | - | ||||||||||||||||||||||||
| 2445 | // Also do Key_Enter action. | - | ||||||||||||||||||||||||
| 2446 | if (currentIndex().isValid()) { | - | ||||||||||||||||||||||||
| 2447 | if (state() != EditingState) | - | ||||||||||||||||||||||||
| 2448 | emit activated(currentIndex()); | - | ||||||||||||||||||||||||
| 2449 | } else { | - | ||||||||||||||||||||||||
| 2450 | event->ignore(); | - | ||||||||||||||||||||||||
| 2451 | } | - | ||||||||||||||||||||||||
| 2452 | } | - | ||||||||||||||||||||||||
| 2453 | #endif | - | ||||||||||||||||||||||||
| 2454 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2455 | #ifdef Q_OS_OSX | - | ||||||||||||||||||||||||
| 2456 | case Qt::Key_Enter: | - | ||||||||||||||||||||||||
| 2457 | case Qt::Key_Return: | - | ||||||||||||||||||||||||
| 2458 | // Propagate the enter if you couldn't edit the item and there are no | - | ||||||||||||||||||||||||
| 2459 | // current editors (if there are editors, the event was most likely propagated from it). | - | ||||||||||||||||||||||||
| 2460 | if (!edit(currentIndex(), EditKeyPressed, event) && d->editorIndexHash.isEmpty()) | - | ||||||||||||||||||||||||
| 2461 | event->ignore(); | - | ||||||||||||||||||||||||
| 2462 | break; | - | ||||||||||||||||||||||||
| 2463 | #else | - | ||||||||||||||||||||||||
| 2464 | case Qt::Key_F2: never executed: case Qt::Key_F2: | 0 | ||||||||||||||||||||||||
| 2465 | if (!edit(currentIndex(), EditKeyPressed, event))
| 0 | ||||||||||||||||||||||||
| 2466 | event->ignore(); never executed: event->ignore(); | 0 | ||||||||||||||||||||||||
| 2467 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2468 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 | ||||||||||||||||||||||||
| 2469 | case Qt::Key_Return: never executed: case Qt::Key_Return: | 0 | ||||||||||||||||||||||||
| 2470 | // ### we can't open the editor on enter, becuse | - | ||||||||||||||||||||||||
| 2471 | // some widgets will forward the enter event back | - | ||||||||||||||||||||||||
| 2472 | // to the viewport, starting an endless loop | - | ||||||||||||||||||||||||
| 2473 | if (state() != EditingState || hasFocus()) {
| 0 | ||||||||||||||||||||||||
| 2474 | if (currentIndex().isValid())
| 0 | ||||||||||||||||||||||||
| 2475 | emit activated(currentIndex()); never executed: activated(currentIndex()); | 0 | ||||||||||||||||||||||||
| 2476 | event->ignore(); | - | ||||||||||||||||||||||||
| 2477 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2478 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2479 | #endif | - | ||||||||||||||||||||||||
| 2480 | default: { never executed: default: | 0 | ||||||||||||||||||||||||
| 2481 | if (event == QKeySequence::SelectAll && selectionMode() != NoSelection) {
| 0 | ||||||||||||||||||||||||
| 2482 | selectAll(); | - | ||||||||||||||||||||||||
| 2483 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2484 | } | - | ||||||||||||||||||||||||
| 2485 | #ifdef Q_OS_OSX | - | ||||||||||||||||||||||||
| 2486 | if (event->key() == Qt::Key_O && event->modifiers() & Qt::ControlModifier && currentIndex().isValid()) { | - | ||||||||||||||||||||||||
| 2487 | emit activated(currentIndex()); | - | ||||||||||||||||||||||||
| 2488 | break; | - | ||||||||||||||||||||||||
| 2489 | } | - | ||||||||||||||||||||||||
| 2490 | #endif | - | ||||||||||||||||||||||||
| 2491 | bool modified = (event->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)); | - | ||||||||||||||||||||||||
| 2492 | if (!event->text().isEmpty() && !modified && !edit(currentIndex(), AnyKeyPressed, event)) {
| 0 | ||||||||||||||||||||||||
| 2493 | keyboardSearch(event->text()); | - | ||||||||||||||||||||||||
| 2494 | event->accept(); | - | ||||||||||||||||||||||||
| 2495 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2496 | event->ignore(); | - | ||||||||||||||||||||||||
| 2497 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2498 | break; } never executed: break; | 0 | ||||||||||||||||||||||||
| 2499 | } | - | ||||||||||||||||||||||||
| 2500 | if (d->moveCursorUpdatedView)
| 0 | ||||||||||||||||||||||||
| 2501 | event->accept(); never executed: event->accept(); | 0 | ||||||||||||||||||||||||
| 2502 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2503 | - | |||||||||||||||||||||||||
| 2504 | /*! | - | ||||||||||||||||||||||||
| 2505 | This function is called with the given \a event when a resize event is sent to | - | ||||||||||||||||||||||||
| 2506 | the widget. | - | ||||||||||||||||||||||||
| 2507 | - | |||||||||||||||||||||||||
| 2508 | \sa QWidget::resizeEvent() | - | ||||||||||||||||||||||||
| 2509 | */ | - | ||||||||||||||||||||||||
| 2510 | void QAbstractItemView::resizeEvent(QResizeEvent *event) | - | ||||||||||||||||||||||||
| 2511 | { | - | ||||||||||||||||||||||||
| 2512 | QAbstractScrollArea::resizeEvent(event); | - | ||||||||||||||||||||||||
| 2513 | updateGeometries(); | - | ||||||||||||||||||||||||
| 2514 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2515 | - | |||||||||||||||||||||||||
| 2516 | /*! | - | ||||||||||||||||||||||||
| 2517 | This function is called with the given \a event when a timer event is sent | - | ||||||||||||||||||||||||
| 2518 | to the widget. | - | ||||||||||||||||||||||||
| 2519 | - | |||||||||||||||||||||||||
| 2520 | \sa QObject::timerEvent() | - | ||||||||||||||||||||||||
| 2521 | */ | - | ||||||||||||||||||||||||
| 2522 | void QAbstractItemView::timerEvent(QTimerEvent *event) | - | ||||||||||||||||||||||||
| 2523 | { | - | ||||||||||||||||||||||||
| 2524 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2525 | if (event->timerId() == d->fetchMoreTimer.timerId())
| 0 | ||||||||||||||||||||||||
| 2526 | d->fetchMore(); never executed: d->fetchMore(); | 0 | ||||||||||||||||||||||||
| 2527 | else if (event->timerId() == d->delayedReset.timerId())
| 0 | ||||||||||||||||||||||||
| 2528 | reset(); never executed: reset(); | 0 | ||||||||||||||||||||||||
| 2529 | else if (event->timerId() == d->autoScrollTimer.timerId())
| 0 | ||||||||||||||||||||||||
| 2530 | doAutoScroll(); never executed: doAutoScroll(); | 0 | ||||||||||||||||||||||||
| 2531 | else if (event->timerId() == d->updateTimer.timerId())
| 0 | ||||||||||||||||||||||||
| 2532 | d->updateDirtyRegion(); never executed: d->updateDirtyRegion(); | 0 | ||||||||||||||||||||||||
| 2533 | else if (event->timerId() == d->delayedEditing.timerId()) {
| 0 | ||||||||||||||||||||||||
| 2534 | d->delayedEditing.stop(); | - | ||||||||||||||||||||||||
| 2535 | edit(currentIndex()); | - | ||||||||||||||||||||||||
| 2536 | } else if (event->timerId() == d->delayedLayout.timerId()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 2537 | d->delayedLayout.stop(); | - | ||||||||||||||||||||||||
| 2538 | if (isVisible()) {
| 0 | ||||||||||||||||||||||||
| 2539 | d->interruptDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 2540 | doItemsLayout(); | - | ||||||||||||||||||||||||
| 2541 | const QModelIndex current = currentIndex(); | - | ||||||||||||||||||||||||
| 2542 | if (current.isValid() && d->state == QAbstractItemView::EditingState)
| 0 | ||||||||||||||||||||||||
| 2543 | scrollTo(current); never executed: scrollTo(current); | 0 | ||||||||||||||||||||||||
| 2544 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2545 | } else if (event->timerId() == d->delayedAutoScroll.timerId()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 2546 | d->delayedAutoScroll.stop(); | - | ||||||||||||||||||||||||
| 2547 | //end of the timer: if the current item is still the same as the one when the mouse press occurred | - | ||||||||||||||||||||||||
| 2548 | //we only get here if there was no double click | - | ||||||||||||||||||||||||
| 2549 | if (d->pressedIndex.isValid() && d->pressedIndex == currentIndex())
| 0 | ||||||||||||||||||||||||
| 2550 | scrollTo(d->pressedIndex); never executed: scrollTo(d->pressedIndex); | 0 | ||||||||||||||||||||||||
| 2551 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2552 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2553 | - | |||||||||||||||||||||||||
| 2554 | /*! | - | ||||||||||||||||||||||||
| 2555 | \reimp | - | ||||||||||||||||||||||||
| 2556 | */ | - | ||||||||||||||||||||||||
| 2557 | void QAbstractItemView::inputMethodEvent(QInputMethodEvent *event) | - | ||||||||||||||||||||||||
| 2558 | { | - | ||||||||||||||||||||||||
| 2559 | if (event->commitString().isEmpty() && event->preeditString().isEmpty()) {
| 0 | ||||||||||||||||||||||||
| 2560 | event->ignore(); | - | ||||||||||||||||||||||||
| 2561 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2562 | } | - | ||||||||||||||||||||||||
| 2563 | if (!edit(currentIndex(), AnyKeyPressed, event)) {
| 0 | ||||||||||||||||||||||||
| 2564 | if (!event->commitString().isEmpty())
| 0 | ||||||||||||||||||||||||
| 2565 | keyboardSearch(event->commitString()); never executed: keyboardSearch(event->commitString()); | 0 | ||||||||||||||||||||||||
| 2566 | event->ignore(); | - | ||||||||||||||||||||||||
| 2567 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2568 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2569 | - | |||||||||||||||||||||||||
| 2570 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 2571 | /*! | - | ||||||||||||||||||||||||
| 2572 | \enum QAbstractItemView::DropIndicatorPosition | - | ||||||||||||||||||||||||
| 2573 | - | |||||||||||||||||||||||||
| 2574 | This enum indicates the position of the drop indicator in | - | ||||||||||||||||||||||||
| 2575 | relation to the index at the current mouse position: | - | ||||||||||||||||||||||||
| 2576 | - | |||||||||||||||||||||||||
| 2577 | \value OnItem The item will be dropped on the index. | - | ||||||||||||||||||||||||
| 2578 | - | |||||||||||||||||||||||||
| 2579 | \value AboveItem The item will be dropped above the index. | - | ||||||||||||||||||||||||
| 2580 | - | |||||||||||||||||||||||||
| 2581 | \value BelowItem The item will be dropped below the index. | - | ||||||||||||||||||||||||
| 2582 | - | |||||||||||||||||||||||||
| 2583 | \value OnViewport The item will be dropped onto a region of the viewport with | - | ||||||||||||||||||||||||
| 2584 | no items. The way each view handles items dropped onto the viewport depends on | - | ||||||||||||||||||||||||
| 2585 | the behavior of the underlying model in use. | - | ||||||||||||||||||||||||
| 2586 | */ | - | ||||||||||||||||||||||||
| 2587 | - | |||||||||||||||||||||||||
| 2588 | - | |||||||||||||||||||||||||
| 2589 | /*! | - | ||||||||||||||||||||||||
| 2590 | \since 4.1 | - | ||||||||||||||||||||||||
| 2591 | - | |||||||||||||||||||||||||
| 2592 | Returns the position of the drop indicator in relation to the closest item. | - | ||||||||||||||||||||||||
| 2593 | */ | - | ||||||||||||||||||||||||
| 2594 | QAbstractItemView::DropIndicatorPosition QAbstractItemView::dropIndicatorPosition() const | - | ||||||||||||||||||||||||
| 2595 | { | - | ||||||||||||||||||||||||
| 2596 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 2597 | return d->dropIndicatorPosition; never executed: return d->dropIndicatorPosition; | 0 | ||||||||||||||||||||||||
| 2598 | } | - | ||||||||||||||||||||||||
| 2599 | #endif | - | ||||||||||||||||||||||||
| 2600 | - | |||||||||||||||||||||||||
| 2601 | /*! | - | ||||||||||||||||||||||||
| 2602 | This convenience function returns a list of all selected and | - | ||||||||||||||||||||||||
| 2603 | non-hidden item indexes in the view. The list contains no | - | ||||||||||||||||||||||||
| 2604 | duplicates, and is not sorted. | - | ||||||||||||||||||||||||
| 2605 | - | |||||||||||||||||||||||||
| 2606 | \sa QItemSelectionModel::selectedIndexes() | - | ||||||||||||||||||||||||
| 2607 | */ | - | ||||||||||||||||||||||||
| 2608 | QModelIndexList QAbstractItemView::selectedIndexes() const | - | ||||||||||||||||||||||||
| 2609 | { | - | ||||||||||||||||||||||||
| 2610 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 2611 | QModelIndexList indexes; | - | ||||||||||||||||||||||||
| 2612 | if (d->selectionModel) {
| 0 | ||||||||||||||||||||||||
| 2613 | indexes = d->selectionModel->selectedIndexes(); | - | ||||||||||||||||||||||||
| 2614 | auto isHidden = [this](const QModelIndex &idx) { | - | ||||||||||||||||||||||||
| 2615 | return isIndexHidden(idx); never executed: return isIndexHidden(idx); | 0 | ||||||||||||||||||||||||
| 2616 | }; | - | ||||||||||||||||||||||||
| 2617 | const auto end = indexes.end(); | - | ||||||||||||||||||||||||
| 2618 | indexes.erase(std::remove_if(indexes.begin(), end, isHidden), end); | - | ||||||||||||||||||||||||
| 2619 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2620 | return indexes; never executed: return indexes; | 0 | ||||||||||||||||||||||||
| 2621 | } | - | ||||||||||||||||||||||||
| 2622 | - | |||||||||||||||||||||||||
| 2623 | /*! | - | ||||||||||||||||||||||||
| 2624 | Starts editing the item at \a index, creating an editor if | - | ||||||||||||||||||||||||
| 2625 | necessary, and returns \c true if the view's \l{State} is now | - | ||||||||||||||||||||||||
| 2626 | EditingState; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 2627 | - | |||||||||||||||||||||||||
| 2628 | The action that caused the editing process is described by | - | ||||||||||||||||||||||||
| 2629 | \a trigger, and the associated event is specified by \a event. | - | ||||||||||||||||||||||||
| 2630 | - | |||||||||||||||||||||||||
| 2631 | Editing can be forced by specifying the \a trigger to be | - | ||||||||||||||||||||||||
| 2632 | QAbstractItemView::AllEditTriggers. | - | ||||||||||||||||||||||||
| 2633 | - | |||||||||||||||||||||||||
| 2634 | \sa closeEditor() | - | ||||||||||||||||||||||||
| 2635 | */ | - | ||||||||||||||||||||||||
| 2636 | bool QAbstractItemView::edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) | - | ||||||||||||||||||||||||
| 2637 | { | - | ||||||||||||||||||||||||
| 2638 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2639 | - | |||||||||||||||||||||||||
| 2640 | if (!d->isIndexValid(index))
| 0 | ||||||||||||||||||||||||
| 2641 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2642 | - | |||||||||||||||||||||||||
| 2643 | if (QWidget *w = (d->persistent.isEmpty() ? static_cast<QWidget*>(0) : d->editorForIndex(index).widget.data())) {
| 0 | ||||||||||||||||||||||||
| 2644 | if (w->focusPolicy() == Qt::NoFocus)
| 0 | ||||||||||||||||||||||||
| 2645 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2646 | w->setFocus(); | - | ||||||||||||||||||||||||
| 2647 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 2648 | } | - | ||||||||||||||||||||||||
| 2649 | - | |||||||||||||||||||||||||
| 2650 | if (trigger == DoubleClicked) {
| 0 | ||||||||||||||||||||||||
| 2651 | d->delayedEditing.stop(); | - | ||||||||||||||||||||||||
| 2652 | d->delayedAutoScroll.stop(); | - | ||||||||||||||||||||||||
| 2653 | } else if (trigger == CurrentChanged) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 2654 | d->delayedEditing.stop(); | - | ||||||||||||||||||||||||
| 2655 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2656 | - | |||||||||||||||||||||||||
| 2657 | if (d->sendDelegateEvent(index, event)) {
| 0 | ||||||||||||||||||||||||
| 2658 | update(index); | - | ||||||||||||||||||||||||
| 2659 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 2660 | } | - | ||||||||||||||||||||||||
| 2661 | - | |||||||||||||||||||||||||
| 2662 | // save the previous trigger before updating | - | ||||||||||||||||||||||||
| 2663 | EditTriggers lastTrigger = d->lastTrigger; | - | ||||||||||||||||||||||||
| 2664 | d->lastTrigger = trigger; | - | ||||||||||||||||||||||||
| 2665 | - | |||||||||||||||||||||||||
| 2666 | if (!d->shouldEdit(trigger, d->model->buddy(index)))
| 0 | ||||||||||||||||||||||||
| 2667 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2668 | - | |||||||||||||||||||||||||
| 2669 | if (d->delayedEditing.isActive())
| 0 | ||||||||||||||||||||||||
| 2670 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2671 | - | |||||||||||||||||||||||||
| 2672 | // we will receive a mouseButtonReleaseEvent after a | - | ||||||||||||||||||||||||
| 2673 | // mouseDoubleClickEvent, so we need to check the previous trigger | - | ||||||||||||||||||||||||
| 2674 | if (lastTrigger == DoubleClicked && trigger == SelectedClicked)
| 0 | ||||||||||||||||||||||||
| 2675 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2676 | - | |||||||||||||||||||||||||
| 2677 | // we may get a double click event later | - | ||||||||||||||||||||||||
| 2678 | if (trigger == SelectedClicked)
| 0 | ||||||||||||||||||||||||
| 2679 | d->delayedEditing.start(QApplication::doubleClickInterval(), this); never executed: d->delayedEditing.start(QApplication::doubleClickInterval(), this); | 0 | ||||||||||||||||||||||||
| 2680 | else | - | ||||||||||||||||||||||||
| 2681 | d->openEditor(index, d->shouldForwardEvent(trigger, event) ? event : 0); never executed: d->openEditor(index, d->shouldForwardEvent(trigger, event) ? event : 0); | 0 | ||||||||||||||||||||||||
| 2682 | - | |||||||||||||||||||||||||
| 2683 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 2684 | } | - | ||||||||||||||||||||||||
| 2685 | - | |||||||||||||||||||||||||
| 2686 | /*! | - | ||||||||||||||||||||||||
| 2687 | \internal | - | ||||||||||||||||||||||||
| 2688 | Updates the data shown in the open editor widgets in the view. | - | ||||||||||||||||||||||||
| 2689 | */ | - | ||||||||||||||||||||||||
| 2690 | void QAbstractItemView::updateEditorData() | - | ||||||||||||||||||||||||
| 2691 | { | - | ||||||||||||||||||||||||
| 2692 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2693 | d->updateEditorData(QModelIndex(), QModelIndex()); | - | ||||||||||||||||||||||||
| 2694 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2695 | - | |||||||||||||||||||||||||
| 2696 | /*! | - | ||||||||||||||||||||||||
| 2697 | \internal | - | ||||||||||||||||||||||||
| 2698 | Updates the geometry of the open editor widgets in the view. | - | ||||||||||||||||||||||||
| 2699 | */ | - | ||||||||||||||||||||||||
| 2700 | void QAbstractItemView::updateEditorGeometries() | - | ||||||||||||||||||||||||
| 2701 | { | - | ||||||||||||||||||||||||
| 2702 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2703 | if(d->editorIndexHash.isEmpty())
| 0 | ||||||||||||||||||||||||
| 2704 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2705 | if (d->delayedPendingLayout) {
| 0 | ||||||||||||||||||||||||
| 2706 | // doItemsLayout() will end up calling this function again | - | ||||||||||||||||||||||||
| 2707 | d->executePostedLayout(); | - | ||||||||||||||||||||||||
| 2708 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2709 | } | - | ||||||||||||||||||||||||
| 2710 | QStyleOptionViewItem option = d->viewOptionsV1(); | - | ||||||||||||||||||||||||
| 2711 | QEditorIndexHash::iterator it = d->editorIndexHash.begin(); | - | ||||||||||||||||||||||||
| 2712 | QWidgetList editorsToRelease; | - | ||||||||||||||||||||||||
| 2713 | QWidgetList editorsToHide; | - | ||||||||||||||||||||||||
| 2714 | while (it != d->editorIndexHash.end()) {
| 0 | ||||||||||||||||||||||||
| 2715 | QModelIndex index = it.value(); | - | ||||||||||||||||||||||||
| 2716 | QWidget *editor = it.key(); | - | ||||||||||||||||||||||||
| 2717 | if (index.isValid() && editor) {
| 0 | ||||||||||||||||||||||||
| 2718 | option.rect = visualRect(index); | - | ||||||||||||||||||||||||
| 2719 | if (option.rect.isValid()) {
| 0 | ||||||||||||||||||||||||
| 2720 | editor->show(); | - | ||||||||||||||||||||||||
| 2721 | QAbstractItemDelegate *delegate = d->delegateForIndex(index); | - | ||||||||||||||||||||||||
| 2722 | if (delegate)
| 0 | ||||||||||||||||||||||||
| 2723 | delegate->updateEditorGeometry(editor, option, index); never executed: delegate->updateEditorGeometry(editor, option, index); | 0 | ||||||||||||||||||||||||
| 2724 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2725 | editorsToHide << editor; | - | ||||||||||||||||||||||||
| 2726 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2727 | ++it; | - | ||||||||||||||||||||||||
| 2728 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2729 | d->indexEditorHash.remove(it.value()); | - | ||||||||||||||||||||||||
| 2730 | it = d->editorIndexHash.erase(it); | - | ||||||||||||||||||||||||
| 2731 | editorsToRelease << editor; | - | ||||||||||||||||||||||||
| 2732 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2733 | } | - | ||||||||||||||||||||||||
| 2734 | - | |||||||||||||||||||||||||
| 2735 | //we hide and release the editor outside of the loop because it might change the focus and try | - | ||||||||||||||||||||||||
| 2736 | //to change the editors hashes. | - | ||||||||||||||||||||||||
| 2737 | for (int i = 0; i < editorsToHide.count(); ++i) {
| 0 | ||||||||||||||||||||||||
| 2738 | editorsToHide.at(i)->hide(); | - | ||||||||||||||||||||||||
| 2739 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2740 | for (int i = 0; i < editorsToRelease.count(); ++i) {
| 0 | ||||||||||||||||||||||||
| 2741 | d->releaseEditor(editorsToRelease.at(i)); | - | ||||||||||||||||||||||||
| 2742 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2743 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2744 | - | |||||||||||||||||||||||||
| 2745 | /*! | - | ||||||||||||||||||||||||
| 2746 | \since 4.4 | - | ||||||||||||||||||||||||
| 2747 | - | |||||||||||||||||||||||||
| 2748 | Updates the geometry of the child widgets of the view. | - | ||||||||||||||||||||||||
| 2749 | */ | - | ||||||||||||||||||||||||
| 2750 | void QAbstractItemView::updateGeometries() | - | ||||||||||||||||||||||||
| 2751 | { | - | ||||||||||||||||||||||||
| 2752 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2753 | updateEditorGeometries(); | - | ||||||||||||||||||||||||
| 2754 | d->fetchMoreTimer.start(0, this); //fetch more later | - | ||||||||||||||||||||||||
| 2755 | d->updateGeometry(); | - | ||||||||||||||||||||||||
| 2756 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2757 | - | |||||||||||||||||||||||||
| 2758 | /*! | - | ||||||||||||||||||||||||
| 2759 | \internal | - | ||||||||||||||||||||||||
| 2760 | */ | - | ||||||||||||||||||||||||
| 2761 | void QAbstractItemView::verticalScrollbarValueChanged(int value) | - | ||||||||||||||||||||||||
| 2762 | { | - | ||||||||||||||||||||||||
| 2763 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2764 | if (verticalScrollBar()->maximum() == value && d->model->canFetchMore(d->root))
| 0 | ||||||||||||||||||||||||
| 2765 | d->model->fetchMore(d->root); never executed: d->model->fetchMore(d->root); | 0 | ||||||||||||||||||||||||
| 2766 | QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos()); | - | ||||||||||||||||||||||||
| 2767 | if (viewport()->rect().contains(posInVp))
| 0 | ||||||||||||||||||||||||
| 2768 | d->checkMouseMove(posInVp); never executed: d->checkMouseMove(posInVp); | 0 | ||||||||||||||||||||||||
| 2769 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2770 | - | |||||||||||||||||||||||||
| 2771 | /*! | - | ||||||||||||||||||||||||
| 2772 | \internal | - | ||||||||||||||||||||||||
| 2773 | */ | - | ||||||||||||||||||||||||
| 2774 | void QAbstractItemView::horizontalScrollbarValueChanged(int value) | - | ||||||||||||||||||||||||
| 2775 | { | - | ||||||||||||||||||||||||
| 2776 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2777 | if (horizontalScrollBar()->maximum() == value && d->model->canFetchMore(d->root))
| 0 | ||||||||||||||||||||||||
| 2778 | d->model->fetchMore(d->root); never executed: d->model->fetchMore(d->root); | 0 | ||||||||||||||||||||||||
| 2779 | QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos()); | - | ||||||||||||||||||||||||
| 2780 | if (viewport()->rect().contains(posInVp))
| 0 | ||||||||||||||||||||||||
| 2781 | d->checkMouseMove(posInVp); never executed: d->checkMouseMove(posInVp); | 0 | ||||||||||||||||||||||||
| 2782 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2783 | - | |||||||||||||||||||||||||
| 2784 | /*! | - | ||||||||||||||||||||||||
| 2785 | \internal | - | ||||||||||||||||||||||||
| 2786 | */ | - | ||||||||||||||||||||||||
| 2787 | void QAbstractItemView::verticalScrollbarAction(int) | - | ||||||||||||||||||||||||
| 2788 | { | - | ||||||||||||||||||||||||
| 2789 | //do nothing | - | ||||||||||||||||||||||||
| 2790 | } | - | ||||||||||||||||||||||||
| 2791 | - | |||||||||||||||||||||||||
| 2792 | /*! | - | ||||||||||||||||||||||||
| 2793 | \internal | - | ||||||||||||||||||||||||
| 2794 | */ | - | ||||||||||||||||||||||||
| 2795 | void QAbstractItemView::horizontalScrollbarAction(int) | - | ||||||||||||||||||||||||
| 2796 | { | - | ||||||||||||||||||||||||
| 2797 | //do nothing | - | ||||||||||||||||||||||||
| 2798 | } | - | ||||||||||||||||||||||||
| 2799 | - | |||||||||||||||||||||||||
| 2800 | /*! | - | ||||||||||||||||||||||||
| 2801 | Closes the given \a editor, and releases it. The \a hint is | - | ||||||||||||||||||||||||
| 2802 | used to specify how the view should respond to the end of the editing | - | ||||||||||||||||||||||||
| 2803 | operation. For example, the hint may indicate that the next item in | - | ||||||||||||||||||||||||
| 2804 | the view should be opened for editing. | - | ||||||||||||||||||||||||
| 2805 | - | |||||||||||||||||||||||||
| 2806 | \sa edit(), commitData() | - | ||||||||||||||||||||||||
| 2807 | */ | - | ||||||||||||||||||||||||
| 2808 | - | |||||||||||||||||||||||||
| 2809 | void QAbstractItemView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint) | - | ||||||||||||||||||||||||
| 2810 | { | - | ||||||||||||||||||||||||
| 2811 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2812 | - | |||||||||||||||||||||||||
| 2813 | // Close the editor | - | ||||||||||||||||||||||||
| 2814 | if (editor) {
| 0 | ||||||||||||||||||||||||
| 2815 | bool isPersistent = d->persistent.contains(editor); | - | ||||||||||||||||||||||||
| 2816 | bool hadFocus = editor->hasFocus(); | - | ||||||||||||||||||||||||
| 2817 | QModelIndex index = d->indexForEditor(editor); | - | ||||||||||||||||||||||||
| 2818 | if (!index.isValid())
| 0 | ||||||||||||||||||||||||
| 2819 | return; // the editor was not registered never executed: return; | 0 | ||||||||||||||||||||||||
| 2820 | - | |||||||||||||||||||||||||
| 2821 | if (!isPersistent) {
| 0 | ||||||||||||||||||||||||
| 2822 | setState(NoState); | - | ||||||||||||||||||||||||
| 2823 | QModelIndex index = d->indexForEditor(editor); | - | ||||||||||||||||||||||||
| 2824 | editor->removeEventFilter(d->delegateForIndex(index)); | - | ||||||||||||||||||||||||
| 2825 | d->removeEditor(editor); | - | ||||||||||||||||||||||||
| 2826 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2827 | if (hadFocus) {
| 0 | ||||||||||||||||||||||||
| 2828 | if (focusPolicy() != Qt::NoFocus)
| 0 | ||||||||||||||||||||||||
| 2829 | setFocus(); // this will send a focusLost event to the editor never executed: setFocus(); | 0 | ||||||||||||||||||||||||
| 2830 | else | - | ||||||||||||||||||||||||
| 2831 | editor->clearFocus(); never executed: editor->clearFocus(); | 0 | ||||||||||||||||||||||||
| 2832 | } else { | - | ||||||||||||||||||||||||
| 2833 | d->checkPersistentEditorFocus(); | - | ||||||||||||||||||||||||
| 2834 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2835 | - | |||||||||||||||||||||||||
| 2836 | QPointer<QWidget> ed = editor; | - | ||||||||||||||||||||||||
| 2837 | QApplication::sendPostedEvents(editor, 0); | - | ||||||||||||||||||||||||
| 2838 | editor = ed; | - | ||||||||||||||||||||||||
| 2839 | - | |||||||||||||||||||||||||
| 2840 | if (!isPersistent && editor)
| 0 | ||||||||||||||||||||||||
| 2841 | d->releaseEditor(editor, index); never executed: d->releaseEditor(editor, index); | 0 | ||||||||||||||||||||||||
| 2842 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2843 | - | |||||||||||||||||||||||||
| 2844 | // The EndEditHint part | - | ||||||||||||||||||||||||
| 2845 | QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||||||||
| 2846 | if (d->selectionMode != NoSelection)
| 0 | ||||||||||||||||||||||||
| 2847 | flags = QItemSelectionModel::ClearAndSelect | d->selectionBehaviorFlags(); never executed: flags = QItemSelectionModel::ClearAndSelect | d->selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 2848 | switch (hint) { | - | ||||||||||||||||||||||||
| 2849 | case QAbstractItemDelegate::EditNextItem: { never executed: case QAbstractItemDelegate::EditNextItem: | 0 | ||||||||||||||||||||||||
| 2850 | QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); | - | ||||||||||||||||||||||||
| 2851 | if (index.isValid()) {
| 0 | ||||||||||||||||||||||||
| 2852 | QPersistentModelIndex persistent(index); | - | ||||||||||||||||||||||||
| 2853 | d->selectionModel->setCurrentIndex(persistent, flags); | - | ||||||||||||||||||||||||
| 2854 | // currentChanged signal would have already started editing | - | ||||||||||||||||||||||||
| 2855 | if (index.flags() & Qt::ItemIsEditable
| 0 | ||||||||||||||||||||||||
| 2856 | && (!(editTriggers() & QAbstractItemView::CurrentChanged)))
| 0 | ||||||||||||||||||||||||
| 2857 | edit(persistent); never executed: edit(persistent); | 0 | ||||||||||||||||||||||||
| 2858 | } break; } never executed: end of blocknever executed: break; | 0 | ||||||||||||||||||||||||
| 2859 | case QAbstractItemDelegate::EditPreviousItem: { never executed: case QAbstractItemDelegate::EditPreviousItem: | 0 | ||||||||||||||||||||||||
| 2860 | QModelIndex index = moveCursor(MovePrevious, Qt::NoModifier); | - | ||||||||||||||||||||||||
| 2861 | if (index.isValid()) {
| 0 | ||||||||||||||||||||||||
| 2862 | QPersistentModelIndex persistent(index); | - | ||||||||||||||||||||||||
| 2863 | d->selectionModel->setCurrentIndex(persistent, flags); | - | ||||||||||||||||||||||||
| 2864 | // currentChanged signal would have already started editing | - | ||||||||||||||||||||||||
| 2865 | if (index.flags() & Qt::ItemIsEditable
| 0 | ||||||||||||||||||||||||
| 2866 | && (!(editTriggers() & QAbstractItemView::CurrentChanged)))
| 0 | ||||||||||||||||||||||||
| 2867 | edit(persistent); never executed: edit(persistent); | 0 | ||||||||||||||||||||||||
| 2868 | } break; } never executed: end of blocknever executed: break; | 0 | ||||||||||||||||||||||||
| 2869 | case QAbstractItemDelegate::SubmitModelCache: never executed: case QAbstractItemDelegate::SubmitModelCache: | 0 | ||||||||||||||||||||||||
| 2870 | d->model->submit(); | - | ||||||||||||||||||||||||
| 2871 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2872 | case QAbstractItemDelegate::RevertModelCache: never executed: case QAbstractItemDelegate::RevertModelCache: | 0 | ||||||||||||||||||||||||
| 2873 | d->model->revert(); | - | ||||||||||||||||||||||||
| 2874 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2875 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 2876 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2877 | } | - | ||||||||||||||||||||||||
| 2878 | } | - | ||||||||||||||||||||||||
| 2879 | - | |||||||||||||||||||||||||
| 2880 | /*! | - | ||||||||||||||||||||||||
| 2881 | Commit the data in the \a editor to the model. | - | ||||||||||||||||||||||||
| 2882 | - | |||||||||||||||||||||||||
| 2883 | \sa closeEditor() | - | ||||||||||||||||||||||||
| 2884 | */ | - | ||||||||||||||||||||||||
| 2885 | void QAbstractItemView::commitData(QWidget *editor) | - | ||||||||||||||||||||||||
| 2886 | { | - | ||||||||||||||||||||||||
| 2887 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2888 | if (!editor || !d->itemDelegate || d->currentlyCommittingEditor)
| 0 | ||||||||||||||||||||||||
| 2889 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2890 | QModelIndex index = d->indexForEditor(editor); | - | ||||||||||||||||||||||||
| 2891 | if (!index.isValid())
| 0 | ||||||||||||||||||||||||
| 2892 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2893 | d->currentlyCommittingEditor = editor; | - | ||||||||||||||||||||||||
| 2894 | QAbstractItemDelegate *delegate = d->delegateForIndex(index); | - | ||||||||||||||||||||||||
| 2895 | editor->removeEventFilter(delegate); | - | ||||||||||||||||||||||||
| 2896 | delegate->setModelData(editor, d->model, index); | - | ||||||||||||||||||||||||
| 2897 | editor->installEventFilter(delegate); | - | ||||||||||||||||||||||||
| 2898 | d->currentlyCommittingEditor = 0; | - | ||||||||||||||||||||||||
| 2899 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2900 | - | |||||||||||||||||||||||||
| 2901 | /*! | - | ||||||||||||||||||||||||
| 2902 | This function is called when the given \a editor has been destroyed. | - | ||||||||||||||||||||||||
| 2903 | - | |||||||||||||||||||||||||
| 2904 | \sa closeEditor() | - | ||||||||||||||||||||||||
| 2905 | */ | - | ||||||||||||||||||||||||
| 2906 | void QAbstractItemView::editorDestroyed(QObject *editor) | - | ||||||||||||||||||||||||
| 2907 | { | - | ||||||||||||||||||||||||
| 2908 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2909 | QWidget *w = qobject_cast<QWidget*>(editor); | - | ||||||||||||||||||||||||
| 2910 | d->removeEditor(w); | - | ||||||||||||||||||||||||
| 2911 | d->persistent.remove(w); | - | ||||||||||||||||||||||||
| 2912 | if (state() == EditingState)
| 0 | ||||||||||||||||||||||||
| 2913 | setState(NoState); never executed: setState(NoState); | 0 | ||||||||||||||||||||||||
| 2914 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2915 | - | |||||||||||||||||||||||||
| 2916 | /*! | - | ||||||||||||||||||||||||
| 2917 | \obsolete | - | ||||||||||||||||||||||||
| 2918 | Sets the horizontal scroll bar's steps per item to \a steps. | - | ||||||||||||||||||||||||
| 2919 | - | |||||||||||||||||||||||||
| 2920 | This is the number of steps used by the horizontal scroll bar to | - | ||||||||||||||||||||||||
| 2921 | represent the width of an item. | - | ||||||||||||||||||||||||
| 2922 | - | |||||||||||||||||||||||||
| 2923 | Note that if the view has a horizontal header, the item steps | - | ||||||||||||||||||||||||
| 2924 | will be ignored and the header section size will be used instead. | - | ||||||||||||||||||||||||
| 2925 | - | |||||||||||||||||||||||||
| 2926 | \sa horizontalStepsPerItem(), setVerticalStepsPerItem() | - | ||||||||||||||||||||||||
| 2927 | */ | - | ||||||||||||||||||||||||
| 2928 | void QAbstractItemView::setHorizontalStepsPerItem(int steps) | - | ||||||||||||||||||||||||
| 2929 | { | - | ||||||||||||||||||||||||
| 2930 | Q_UNUSED(steps) | - | ||||||||||||||||||||||||
| 2931 | // do nothing | - | ||||||||||||||||||||||||
| 2932 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2933 | - | |||||||||||||||||||||||||
| 2934 | /*! | - | ||||||||||||||||||||||||
| 2935 | \obsolete | - | ||||||||||||||||||||||||
| 2936 | Returns the horizontal scroll bar's steps per item. | - | ||||||||||||||||||||||||
| 2937 | - | |||||||||||||||||||||||||
| 2938 | \sa setHorizontalStepsPerItem(), verticalStepsPerItem() | - | ||||||||||||||||||||||||
| 2939 | */ | - | ||||||||||||||||||||||||
| 2940 | int QAbstractItemView::horizontalStepsPerItem() const | - | ||||||||||||||||||||||||
| 2941 | { | - | ||||||||||||||||||||||||
| 2942 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
| 2943 | } | - | ||||||||||||||||||||||||
| 2944 | - | |||||||||||||||||||||||||
| 2945 | /*! | - | ||||||||||||||||||||||||
| 2946 | \obsolete | - | ||||||||||||||||||||||||
| 2947 | Sets the vertical scroll bar's steps per item to \a steps. | - | ||||||||||||||||||||||||
| 2948 | - | |||||||||||||||||||||||||
| 2949 | This is the number of steps used by the vertical scroll bar to | - | ||||||||||||||||||||||||
| 2950 | represent the height of an item. | - | ||||||||||||||||||||||||
| 2951 | - | |||||||||||||||||||||||||
| 2952 | Note that if the view has a vertical header, the item steps | - | ||||||||||||||||||||||||
| 2953 | will be ignored and the header section size will be used instead. | - | ||||||||||||||||||||||||
| 2954 | - | |||||||||||||||||||||||||
| 2955 | \sa verticalStepsPerItem(), setHorizontalStepsPerItem() | - | ||||||||||||||||||||||||
| 2956 | */ | - | ||||||||||||||||||||||||
| 2957 | void QAbstractItemView::setVerticalStepsPerItem(int steps) | - | ||||||||||||||||||||||||
| 2958 | { | - | ||||||||||||||||||||||||
| 2959 | Q_UNUSED(steps) | - | ||||||||||||||||||||||||
| 2960 | // do nothing | - | ||||||||||||||||||||||||
| 2961 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2962 | - | |||||||||||||||||||||||||
| 2963 | /*! | - | ||||||||||||||||||||||||
| 2964 | \obsolete | - | ||||||||||||||||||||||||
| 2965 | Returns the vertical scroll bar's steps per item. | - | ||||||||||||||||||||||||
| 2966 | - | |||||||||||||||||||||||||
| 2967 | \sa setVerticalStepsPerItem(), horizontalStepsPerItem() | - | ||||||||||||||||||||||||
| 2968 | */ | - | ||||||||||||||||||||||||
| 2969 | int QAbstractItemView::verticalStepsPerItem() const | - | ||||||||||||||||||||||||
| 2970 | { | - | ||||||||||||||||||||||||
| 2971 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
| 2972 | } | - | ||||||||||||||||||||||||
| 2973 | - | |||||||||||||||||||||||||
| 2974 | /*! | - | ||||||||||||||||||||||||
| 2975 | Moves to and selects the item best matching the string \a search. | - | ||||||||||||||||||||||||
| 2976 | If no item is found nothing happens. | - | ||||||||||||||||||||||||
| 2977 | - | |||||||||||||||||||||||||
| 2978 | In the default implementation, the search is reset if \a search is empty, or | - | ||||||||||||||||||||||||
| 2979 | the time interval since the last search has exceeded | - | ||||||||||||||||||||||||
| 2980 | QApplication::keyboardInputInterval(). | - | ||||||||||||||||||||||||
| 2981 | */ | - | ||||||||||||||||||||||||
| 2982 | void QAbstractItemView::keyboardSearch(const QString &search) | - | ||||||||||||||||||||||||
| 2983 | { | - | ||||||||||||||||||||||||
| 2984 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 2985 | if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root))
| 0 | ||||||||||||||||||||||||
| 2986 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2987 | - | |||||||||||||||||||||||||
| 2988 | QModelIndex start = currentIndex().isValid() ? currentIndex()
| 0 | ||||||||||||||||||||||||
| 2989 | : d->model->index(0, 0, d->root); | - | ||||||||||||||||||||||||
| 2990 | bool skipRow = false; | - | ||||||||||||||||||||||||
| 2991 | bool keyboardTimeWasValid = d->keyboardInputTime.isValid(); | - | ||||||||||||||||||||||||
| 2992 | qint64 keyboardInputTimeElapsed; | - | ||||||||||||||||||||||||
| 2993 | if (keyboardTimeWasValid)
| 0 | ||||||||||||||||||||||||
| 2994 | keyboardInputTimeElapsed = d->keyboardInputTime.restart(); never executed: keyboardInputTimeElapsed = d->keyboardInputTime.restart(); | 0 | ||||||||||||||||||||||||
| 2995 | else | - | ||||||||||||||||||||||||
| 2996 | d->keyboardInputTime.start(); never executed: d->keyboardInputTime.start(); | 0 | ||||||||||||||||||||||||
| 2997 | if (search.isEmpty() || !keyboardTimeWasValid
| 0 | ||||||||||||||||||||||||
| 2998 | || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) {
| 0 | ||||||||||||||||||||||||
| 2999 | d->keyboardInput = search; | - | ||||||||||||||||||||||||
| 3000 | skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0) | - | ||||||||||||||||||||||||
| 3001 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3002 | d->keyboardInput += search; | - | ||||||||||||||||||||||||
| 3003 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3004 | - | |||||||||||||||||||||||||
| 3005 | // special case for searches with same key like 'aaaaa' | - | ||||||||||||||||||||||||
| 3006 | bool sameKey = false; | - | ||||||||||||||||||||||||
| 3007 | if (d->keyboardInput.length() > 1) {
| 0 | ||||||||||||||||||||||||
| 3008 | int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.length() - 1)); | - | ||||||||||||||||||||||||
| 3009 | sameKey = (c == d->keyboardInput.length()); | - | ||||||||||||||||||||||||
| 3010 | if (sameKey)
| 0 | ||||||||||||||||||||||||
| 3011 | skipRow = true; never executed: skipRow = true; | 0 | ||||||||||||||||||||||||
| 3012 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3013 | - | |||||||||||||||||||||||||
| 3014 | // skip if we are searching for the same key or a new search started | - | ||||||||||||||||||||||||
| 3015 | if (skipRow) {
| 0 | ||||||||||||||||||||||||
| 3016 | QModelIndex parent = start.parent(); | - | ||||||||||||||||||||||||
| 3017 | int newRow = (start.row() < d->model->rowCount(parent) - 1) ? start.row() + 1 : 0;
| 0 | ||||||||||||||||||||||||
| 3018 | start = d->model->index(newRow, start.column(), parent); | - | ||||||||||||||||||||||||
| 3019 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3020 | - | |||||||||||||||||||||||||
| 3021 | // search from start with wraparound | - | ||||||||||||||||||||||||
| 3022 | QModelIndex current = start; | - | ||||||||||||||||||||||||
| 3023 | QModelIndexList match; | - | ||||||||||||||||||||||||
| 3024 | QModelIndex firstMatch; | - | ||||||||||||||||||||||||
| 3025 | QModelIndex startMatch; | - | ||||||||||||||||||||||||
| 3026 | QModelIndexList previous; | - | ||||||||||||||||||||||||
| 3027 | do { | - | ||||||||||||||||||||||||
| 3028 | match = d->model->match(current, Qt::DisplayRole, d->keyboardInput); | - | ||||||||||||||||||||||||
| 3029 | if (match == previous)
| 0 | ||||||||||||||||||||||||
| 3030 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 3031 | firstMatch = match.value(0); | - | ||||||||||||||||||||||||
| 3032 | previous = match; | - | ||||||||||||||||||||||||
| 3033 | if (firstMatch.isValid()) {
| 0 | ||||||||||||||||||||||||
| 3034 | if (d->isIndexEnabled(firstMatch)) {
| 0 | ||||||||||||||||||||||||
| 3035 | setCurrentIndex(firstMatch); | - | ||||||||||||||||||||||||
| 3036 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 3037 | } | - | ||||||||||||||||||||||||
| 3038 | int row = firstMatch.row() + 1; | - | ||||||||||||||||||||||||
| 3039 | if (row >= d->model->rowCount(firstMatch.parent()))
| 0 | ||||||||||||||||||||||||
| 3040 | row = 0; never executed: row = 0; | 0 | ||||||||||||||||||||||||
| 3041 | current = firstMatch.sibling(row, firstMatch.column()); | - | ||||||||||||||||||||||||
| 3042 | - | |||||||||||||||||||||||||
| 3043 | //avoid infinite loop if all the matching items are disabled. | - | ||||||||||||||||||||||||
| 3044 | if (!startMatch.isValid())
| 0 | ||||||||||||||||||||||||
| 3045 | startMatch = firstMatch; never executed: startMatch = firstMatch; | 0 | ||||||||||||||||||||||||
| 3046 | else if (startMatch == firstMatch)
| 0 | ||||||||||||||||||||||||
| 3047 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 3048 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3049 | } while (current != start && firstMatch.isValid()); never executed: end of block
| 0 | ||||||||||||||||||||||||
| 3050 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3051 | - | |||||||||||||||||||||||||
| 3052 | /*! | - | ||||||||||||||||||||||||
| 3053 | Returns the size hint for the item with the specified \a index or | - | ||||||||||||||||||||||||
| 3054 | an invalid size for invalid indexes. | - | ||||||||||||||||||||||||
| 3055 | - | |||||||||||||||||||||||||
| 3056 | \sa sizeHintForRow(), sizeHintForColumn() | - | ||||||||||||||||||||||||
| 3057 | */ | - | ||||||||||||||||||||||||
| 3058 | QSize QAbstractItemView::sizeHintForIndex(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 3059 | { | - | ||||||||||||||||||||||||
| 3060 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 3061 | if (!d->isIndexValid(index) || !d->itemDelegate)
| 0 | ||||||||||||||||||||||||
| 3062 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||||||||
| 3063 | return d->delegateForIndex(index)->sizeHint(d->viewOptionsV1(), index); never executed: return d->delegateForIndex(index)->sizeHint(d->viewOptionsV1(), index); | 0 | ||||||||||||||||||||||||
| 3064 | } | - | ||||||||||||||||||||||||
| 3065 | - | |||||||||||||||||||||||||
| 3066 | /*! | - | ||||||||||||||||||||||||
| 3067 | Returns the height size hint for the specified \a row or -1 if | - | ||||||||||||||||||||||||
| 3068 | there is no model. | - | ||||||||||||||||||||||||
| 3069 | - | |||||||||||||||||||||||||
| 3070 | The returned height is calculated using the size hints of the | - | ||||||||||||||||||||||||
| 3071 | given \a row's items, i.e. the returned value is the maximum | - | ||||||||||||||||||||||||
| 3072 | height among the items. Note that to control the height of a row, | - | ||||||||||||||||||||||||
| 3073 | you must reimplement the QAbstractItemDelegate::sizeHint() | - | ||||||||||||||||||||||||
| 3074 | function. | - | ||||||||||||||||||||||||
| 3075 | - | |||||||||||||||||||||||||
| 3076 | This function is used in views with a vertical header to find the | - | ||||||||||||||||||||||||
| 3077 | size hint for a header section based on the contents of the given | - | ||||||||||||||||||||||||
| 3078 | \a row. | - | ||||||||||||||||||||||||
| 3079 | - | |||||||||||||||||||||||||
| 3080 | \sa sizeHintForColumn() | - | ||||||||||||||||||||||||
| 3081 | */ | - | ||||||||||||||||||||||||
| 3082 | int QAbstractItemView::sizeHintForRow(int row) const | - | ||||||||||||||||||||||||
| 3083 | { | - | ||||||||||||||||||||||||
| 3084 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 3085 | - | |||||||||||||||||||||||||
| 3086 | if (row < 0 || row >= d->model->rowCount(d->root))
| 0 | ||||||||||||||||||||||||
| 3087 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
| 3088 | - | |||||||||||||||||||||||||
| 3089 | ensurePolished(); | - | ||||||||||||||||||||||||
| 3090 | - | |||||||||||||||||||||||||
| 3091 | QStyleOptionViewItem option = d->viewOptionsV1(); | - | ||||||||||||||||||||||||
| 3092 | int height = 0; | - | ||||||||||||||||||||||||
| 3093 | int colCount = d->model->columnCount(d->root); | - | ||||||||||||||||||||||||
| 3094 | for (int c = 0; c < colCount; ++c) {
| 0 | ||||||||||||||||||||||||
| 3095 | const QModelIndex index = d->model->index(row, c, d->root); | - | ||||||||||||||||||||||||
| 3096 | if (QWidget *editor = d->editorForIndex(index).widget.data())
| 0 | ||||||||||||||||||||||||
| 3097 | height = qMax(height, editor->height()); never executed: height = qMax(height, editor->height()); | 0 | ||||||||||||||||||||||||
| 3098 | if (const QAbstractItemDelegate *delegate = d->delegateForIndex(index))
| 0 | ||||||||||||||||||||||||
| 3099 | height = qMax(height, delegate->sizeHint(option, index).height()); never executed: height = qMax(height, delegate->sizeHint(option, index).height()); | 0 | ||||||||||||||||||||||||
| 3100 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3101 | return height; never executed: return height; | 0 | ||||||||||||||||||||||||
| 3102 | } | - | ||||||||||||||||||||||||
| 3103 | - | |||||||||||||||||||||||||
| 3104 | /*! | - | ||||||||||||||||||||||||
| 3105 | Returns the width size hint for the specified \a column or -1 if there is no model. | - | ||||||||||||||||||||||||
| 3106 | - | |||||||||||||||||||||||||
| 3107 | This function is used in views with a horizontal header to find the size hint for | - | ||||||||||||||||||||||||
| 3108 | a header section based on the contents of the given \a column. | - | ||||||||||||||||||||||||
| 3109 | - | |||||||||||||||||||||||||
| 3110 | \sa sizeHintForRow() | - | ||||||||||||||||||||||||
| 3111 | */ | - | ||||||||||||||||||||||||
| 3112 | int QAbstractItemView::sizeHintForColumn(int column) const | - | ||||||||||||||||||||||||
| 3113 | { | - | ||||||||||||||||||||||||
| 3114 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 3115 | - | |||||||||||||||||||||||||
| 3116 | if (column < 0 || column >= d->model->columnCount(d->root))
| 0 | ||||||||||||||||||||||||
| 3117 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
| 3118 | - | |||||||||||||||||||||||||
| 3119 | ensurePolished(); | - | ||||||||||||||||||||||||
| 3120 | - | |||||||||||||||||||||||||
| 3121 | QStyleOptionViewItem option = d->viewOptionsV1(); | - | ||||||||||||||||||||||||
| 3122 | int width = 0; | - | ||||||||||||||||||||||||
| 3123 | int rows = d->model->rowCount(d->root); | - | ||||||||||||||||||||||||
| 3124 | for (int r = 0; r < rows; ++r) {
| 0 | ||||||||||||||||||||||||
| 3125 | const QModelIndex index = d->model->index(r, column, d->root); | - | ||||||||||||||||||||||||
| 3126 | if (QWidget *editor = d->editorForIndex(index).widget.data())
| 0 | ||||||||||||||||||||||||
| 3127 | width = qMax(width, editor->sizeHint().width()); never executed: width = qMax(width, editor->sizeHint().width()); | 0 | ||||||||||||||||||||||||
| 3128 | if (const QAbstractItemDelegate *delegate = d->delegateForIndex(index))
| 0 | ||||||||||||||||||||||||
| 3129 | width = qMax(width, delegate->sizeHint(option, index).width()); never executed: width = qMax(width, delegate->sizeHint(option, index).width()); | 0 | ||||||||||||||||||||||||
| 3130 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3131 | return width; never executed: return width; | 0 | ||||||||||||||||||||||||
| 3132 | } | - | ||||||||||||||||||||||||
| 3133 | - | |||||||||||||||||||||||||
| 3134 | /*! | - | ||||||||||||||||||||||||
| 3135 | Opens a persistent editor on the item at the given \a index. | - | ||||||||||||||||||||||||
| 3136 | If no editor exists, the delegate will create a new editor. | - | ||||||||||||||||||||||||
| 3137 | - | |||||||||||||||||||||||||
| 3138 | \sa closePersistentEditor() | - | ||||||||||||||||||||||||
| 3139 | */ | - | ||||||||||||||||||||||||
| 3140 | void QAbstractItemView::openPersistentEditor(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 3141 | { | - | ||||||||||||||||||||||||
| 3142 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3143 | QStyleOptionViewItem options = d->viewOptionsV1(); | - | ||||||||||||||||||||||||
| 3144 | options.rect = visualRect(index); | - | ||||||||||||||||||||||||
| 3145 | options.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
| 0 | ||||||||||||||||||||||||
| 3146 | - | |||||||||||||||||||||||||
| 3147 | QWidget *editor = d->editor(index, options); | - | ||||||||||||||||||||||||
| 3148 | if (editor) {
| 0 | ||||||||||||||||||||||||
| 3149 | editor->show(); | - | ||||||||||||||||||||||||
| 3150 | d->persistent.insert(editor); | - | ||||||||||||||||||||||||
| 3151 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3152 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3153 | - | |||||||||||||||||||||||||
| 3154 | /*! | - | ||||||||||||||||||||||||
| 3155 | Closes the persistent editor for the item at the given \a index. | - | ||||||||||||||||||||||||
| 3156 | - | |||||||||||||||||||||||||
| 3157 | \sa openPersistentEditor() | - | ||||||||||||||||||||||||
| 3158 | */ | - | ||||||||||||||||||||||||
| 3159 | void QAbstractItemView::closePersistentEditor(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 3160 | { | - | ||||||||||||||||||||||||
| 3161 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3162 | if (QWidget *editor = d->editorForIndex(index).widget.data()) {
| 0 | ||||||||||||||||||||||||
| 3163 | if (index == selectionModel()->currentIndex())
| 0 | ||||||||||||||||||||||||
| 3164 | closeEditor(editor, QAbstractItemDelegate::RevertModelCache); never executed: closeEditor(editor, QAbstractItemDelegate::RevertModelCache); | 0 | ||||||||||||||||||||||||
| 3165 | d->persistent.remove(editor); | - | ||||||||||||||||||||||||
| 3166 | d->removeEditor(editor); | - | ||||||||||||||||||||||||
| 3167 | d->releaseEditor(editor, index); | - | ||||||||||||||||||||||||
| 3168 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3169 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3170 | - | |||||||||||||||||||||||||
| 3171 | /*! | - | ||||||||||||||||||||||||
| 3172 | \since 4.1 | - | ||||||||||||||||||||||||
| 3173 | - | |||||||||||||||||||||||||
| 3174 | Sets the given \a widget on the item at the given \a index, passing the | - | ||||||||||||||||||||||||
| 3175 | ownership of the widget to the viewport. | - | ||||||||||||||||||||||||
| 3176 | - | |||||||||||||||||||||||||
| 3177 | If \a index is invalid (e.g., if you pass the root index), this function | - | ||||||||||||||||||||||||
| 3178 | will do nothing. | - | ||||||||||||||||||||||||
| 3179 | - | |||||||||||||||||||||||||
| 3180 | The given \a widget's \l{QWidget}{autoFillBackground} property must be set | - | ||||||||||||||||||||||||
| 3181 | to true, otherwise the widget's background will be transparent, showing | - | ||||||||||||||||||||||||
| 3182 | both the model data and the item at the given \a index. | - | ||||||||||||||||||||||||
| 3183 | - | |||||||||||||||||||||||||
| 3184 | If index widget A is replaced with index widget B, index widget A will be | - | ||||||||||||||||||||||||
| 3185 | deleted. For example, in the code snippet below, the QLineEdit object will | - | ||||||||||||||||||||||||
| 3186 | be deleted. | - | ||||||||||||||||||||||||
| 3187 | - | |||||||||||||||||||||||||
| 3188 | \snippet code/src_gui_itemviews_qabstractitemview.cpp 1 | - | ||||||||||||||||||||||||
| 3189 | - | |||||||||||||||||||||||||
| 3190 | This function should only be used to display static content within the | - | ||||||||||||||||||||||||
| 3191 | visible area corresponding to an item of data. If you want to display | - | ||||||||||||||||||||||||
| 3192 | custom dynamic content or implement a custom editor widget, subclass | - | ||||||||||||||||||||||||
| 3193 | QItemDelegate instead. | - | ||||||||||||||||||||||||
| 3194 | - | |||||||||||||||||||||||||
| 3195 | \sa {Delegate Classes} | - | ||||||||||||||||||||||||
| 3196 | */ | - | ||||||||||||||||||||||||
| 3197 | void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget) | - | ||||||||||||||||||||||||
| 3198 | { | - | ||||||||||||||||||||||||
| 3199 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3200 | if (!d->isIndexValid(index))
| 0 | ||||||||||||||||||||||||
| 3201 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 3202 | if (indexWidget(index) == widget)
| 0 | ||||||||||||||||||||||||
| 3203 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 3204 | if (QWidget *oldWidget = indexWidget(index)) {
| 0 | ||||||||||||||||||||||||
| 3205 | d->persistent.remove(oldWidget); | - | ||||||||||||||||||||||||
| 3206 | d->removeEditor(oldWidget); | - | ||||||||||||||||||||||||
| 3207 | oldWidget->deleteLater(); | - | ||||||||||||||||||||||||
| 3208 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3209 | if (widget) {
| 0 | ||||||||||||||||||||||||
| 3210 | widget->setParent(viewport()); | - | ||||||||||||||||||||||||
| 3211 | d->persistent.insert(widget); | - | ||||||||||||||||||||||||
| 3212 | d->addEditor(index, widget, true); | - | ||||||||||||||||||||||||
| 3213 | widget->show(); | - | ||||||||||||||||||||||||
| 3214 | dataChanged(index, index); // update the geometry | - | ||||||||||||||||||||||||
| 3215 | if (!d->delayedPendingLayout)
| 0 | ||||||||||||||||||||||||
| 3216 | widget->setGeometry(visualRect(index)); never executed: widget->setGeometry(visualRect(index)); | 0 | ||||||||||||||||||||||||
| 3217 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3218 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3219 | - | |||||||||||||||||||||||||
| 3220 | /*! | - | ||||||||||||||||||||||||
| 3221 | \since 4.1 | - | ||||||||||||||||||||||||
| 3222 | - | |||||||||||||||||||||||||
| 3223 | Returns the widget for the item at the given \a index. | - | ||||||||||||||||||||||||
| 3224 | */ | - | ||||||||||||||||||||||||
| 3225 | QWidget* QAbstractItemView::indexWidget(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 3226 | { | - | ||||||||||||||||||||||||
| 3227 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 3228 | if (d->isIndexValid(index))
| 0 | ||||||||||||||||||||||||
| 3229 | if (QWidget *editor = d->editorForIndex(index).widget.data())
| 0 | ||||||||||||||||||||||||
| 3230 | return editor; never executed: return editor; | 0 | ||||||||||||||||||||||||
| 3231 | - | |||||||||||||||||||||||||
| 3232 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 3233 | } | - | ||||||||||||||||||||||||
| 3234 | - | |||||||||||||||||||||||||
| 3235 | /*! | - | ||||||||||||||||||||||||
| 3236 | \since 4.1 | - | ||||||||||||||||||||||||
| 3237 | - | |||||||||||||||||||||||||
| 3238 | Scrolls the view to the top. | - | ||||||||||||||||||||||||
| 3239 | - | |||||||||||||||||||||||||
| 3240 | \sa scrollTo(), scrollToBottom() | - | ||||||||||||||||||||||||
| 3241 | */ | - | ||||||||||||||||||||||||
| 3242 | void QAbstractItemView::scrollToTop() | - | ||||||||||||||||||||||||
| 3243 | { | - | ||||||||||||||||||||||||
| 3244 | verticalScrollBar()->setValue(verticalScrollBar()->minimum()); | - | ||||||||||||||||||||||||
| 3245 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3246 | - | |||||||||||||||||||||||||
| 3247 | /*! | - | ||||||||||||||||||||||||
| 3248 | \since 4.1 | - | ||||||||||||||||||||||||
| 3249 | - | |||||||||||||||||||||||||
| 3250 | Scrolls the view to the bottom. | - | ||||||||||||||||||||||||
| 3251 | - | |||||||||||||||||||||||||
| 3252 | \sa scrollTo(), scrollToTop() | - | ||||||||||||||||||||||||
| 3253 | */ | - | ||||||||||||||||||||||||
| 3254 | void QAbstractItemView::scrollToBottom() | - | ||||||||||||||||||||||||
| 3255 | { | - | ||||||||||||||||||||||||
| 3256 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3257 | if (d->delayedPendingLayout) {
| 0 | ||||||||||||||||||||||||
| 3258 | d->executePostedLayout(); | - | ||||||||||||||||||||||||
| 3259 | updateGeometries(); | - | ||||||||||||||||||||||||
| 3260 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3261 | verticalScrollBar()->setValue(verticalScrollBar()->maximum()); | - | ||||||||||||||||||||||||
| 3262 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3263 | - | |||||||||||||||||||||||||
| 3264 | /*! | - | ||||||||||||||||||||||||
| 3265 | \since 4.3 | - | ||||||||||||||||||||||||
| 3266 | - | |||||||||||||||||||||||||
| 3267 | Updates the area occupied by the given \a index. | - | ||||||||||||||||||||||||
| 3268 | - | |||||||||||||||||||||||||
| 3269 | */ | - | ||||||||||||||||||||||||
| 3270 | void QAbstractItemView::update(const QModelIndex &index) | - | ||||||||||||||||||||||||
| 3271 | { | - | ||||||||||||||||||||||||
| 3272 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3273 | if (index.isValid()) {
| 0 | ||||||||||||||||||||||||
| 3274 | const QRect rect = visualRect(index); | - | ||||||||||||||||||||||||
| 3275 | //this test is important for peformance reason | - | ||||||||||||||||||||||||
| 3276 | //For example in dataChanged we simply update all the cells without checking | - | ||||||||||||||||||||||||
| 3277 | //it can be a major bottleneck to update rects that aren't even part of the viewport | - | ||||||||||||||||||||||||
| 3278 | if (d->viewport->rect().intersects(rect))
| 0 | ||||||||||||||||||||||||
| 3279 | d->viewport->update(rect); never executed: d->viewport->update(rect); | 0 | ||||||||||||||||||||||||
| 3280 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3281 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3282 | - | |||||||||||||||||||||||||
| 3283 | /*! | - | ||||||||||||||||||||||||
| 3284 | This slot is called when items with the given \a roles are changed in the | - | ||||||||||||||||||||||||
| 3285 | model. The changed items are those from \a topLeft to \a bottomRight | - | ||||||||||||||||||||||||
| 3286 | inclusive. If just one item is changed \a topLeft == \a bottomRight. | - | ||||||||||||||||||||||||
| 3287 | - | |||||||||||||||||||||||||
| 3288 | The \a roles which have been changed can either be an empty container (meaning everything | - | ||||||||||||||||||||||||
| 3289 | has changed), or a non-empty container with the subset of roles which have changed. | - | ||||||||||||||||||||||||
| 3290 | */ | - | ||||||||||||||||||||||||
| 3291 | void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) | - | ||||||||||||||||||||||||
| 3292 | { | - | ||||||||||||||||||||||||
| 3293 | Q_UNUSED(roles); | - | ||||||||||||||||||||||||
| 3294 | // Single item changed | - | ||||||||||||||||||||||||
| 3295 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3296 | if (topLeft == bottomRight && topLeft.isValid()) {
| 0 | ||||||||||||||||||||||||
| 3297 | const QEditorInfo &editorInfo = d->editorForIndex(topLeft); | - | ||||||||||||||||||||||||
| 3298 | //we don't update the edit data if it is static | - | ||||||||||||||||||||||||
| 3299 | if (!editorInfo.isStatic && editorInfo.widget) {
| 0 | ||||||||||||||||||||||||
| 3300 | QAbstractItemDelegate *delegate = d->delegateForIndex(topLeft); | - | ||||||||||||||||||||||||
| 3301 | if (delegate) {
| 0 | ||||||||||||||||||||||||
| 3302 | delegate->setEditorData(editorInfo.widget.data(), topLeft); | - | ||||||||||||||||||||||||
| 3303 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3304 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3305 | if (isVisible() && !d->delayedPendingLayout) {
| 0 | ||||||||||||||||||||||||
| 3306 | // otherwise the items will be update later anyway | - | ||||||||||||||||||||||||
| 3307 | update(topLeft); | - | ||||||||||||||||||||||||
| 3308 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3309 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3310 | d->updateEditorData(topLeft, bottomRight); | - | ||||||||||||||||||||||||
| 3311 | if (isVisible() && !d->delayedPendingLayout)
| 0 | ||||||||||||||||||||||||
| 3312 | d->viewport->update(); never executed: d->viewport->update(); | 0 | ||||||||||||||||||||||||
| 3313 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3314 | - | |||||||||||||||||||||||||
| 3315 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 3316 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
| 3317 | QAccessibleTableModelChangeEvent accessibleEvent(this, QAccessibleTableModelChangeEvent::DataChanged); | - | ||||||||||||||||||||||||
| 3318 | accessibleEvent.setFirstRow(topLeft.row()); | - | ||||||||||||||||||||||||
| 3319 | accessibleEvent.setFirstColumn(topLeft.column()); | - | ||||||||||||||||||||||||
| 3320 | accessibleEvent.setLastRow(bottomRight.row()); | - | ||||||||||||||||||||||||
| 3321 | accessibleEvent.setLastColumn(bottomRight.column()); | - | ||||||||||||||||||||||||
| 3322 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||||||||
| 3323 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3324 | #endif | - | ||||||||||||||||||||||||
| 3325 | d->updateGeometry(); | - | ||||||||||||||||||||||||
| 3326 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3327 | - | |||||||||||||||||||||||||
| 3328 | /*! | - | ||||||||||||||||||||||||
| 3329 | This slot is called when rows are inserted. The new rows are those | - | ||||||||||||||||||||||||
| 3330 | under the given \a parent from \a start to \a end inclusive. The | - | ||||||||||||||||||||||||
| 3331 | base class implementation calls fetchMore() on the model to check | - | ||||||||||||||||||||||||
| 3332 | for more data. | - | ||||||||||||||||||||||||
| 3333 | - | |||||||||||||||||||||||||
| 3334 | \sa rowsAboutToBeRemoved() | - | ||||||||||||||||||||||||
| 3335 | */ | - | ||||||||||||||||||||||||
| 3336 | void QAbstractItemView::rowsInserted(const QModelIndex &, int, int) | - | ||||||||||||||||||||||||
| 3337 | { | - | ||||||||||||||||||||||||
| 3338 | if (!isVisible())
| 0 | ||||||||||||||||||||||||
| 3339 | d_func()->fetchMoreTimer.start(0, this); //fetch more later never executed: d_func()->fetchMoreTimer.start(0, this); | 0 | ||||||||||||||||||||||||
| 3340 | else | - | ||||||||||||||||||||||||
| 3341 | updateEditorGeometries(); never executed: updateEditorGeometries(); | 0 | ||||||||||||||||||||||||
| 3342 | } | - | ||||||||||||||||||||||||
| 3343 | - | |||||||||||||||||||||||||
| 3344 | /*! | - | ||||||||||||||||||||||||
| 3345 | This slot is called when rows are about to be removed. The deleted rows are | - | ||||||||||||||||||||||||
| 3346 | those under the given \a parent from \a start to \a end inclusive. | - | ||||||||||||||||||||||||
| 3347 | - | |||||||||||||||||||||||||
| 3348 | \sa rowsInserted() | - | ||||||||||||||||||||||||
| 3349 | */ | - | ||||||||||||||||||||||||
| 3350 | void QAbstractItemView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) | - | ||||||||||||||||||||||||
| 3351 | { | - | ||||||||||||||||||||||||
| 3352 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3353 | - | |||||||||||||||||||||||||
| 3354 | setState(CollapsingState); | - | ||||||||||||||||||||||||
| 3355 | - | |||||||||||||||||||||||||
| 3356 | // Ensure one selected item in single selection mode. | - | ||||||||||||||||||||||||
| 3357 | QModelIndex current = currentIndex(); | - | ||||||||||||||||||||||||
| 3358 | if (d->selectionMode == SingleSelection
| 0 | ||||||||||||||||||||||||
| 3359 | && current.isValid()
| 0 | ||||||||||||||||||||||||
| 3360 | && current.row() >= start
| 0 | ||||||||||||||||||||||||
| 3361 | && current.row() <= end
| 0 | ||||||||||||||||||||||||
| 3362 | && current.parent() == parent) {
| 0 | ||||||||||||||||||||||||
| 3363 | int totalToRemove = end - start + 1; | - | ||||||||||||||||||||||||
| 3364 | if (d->model->rowCount(parent) <= totalToRemove) { // no more children
| 0 | ||||||||||||||||||||||||
| 3365 | QModelIndex index = parent; | - | ||||||||||||||||||||||||
| 3366 | while (index != d->root && !d->isIndexEnabled(index))
| 0 | ||||||||||||||||||||||||
| 3367 | index = index.parent(); never executed: index = index.parent(); | 0 | ||||||||||||||||||||||||
| 3368 | if (index != d->root)
| 0 | ||||||||||||||||||||||||
| 3369 | setCurrentIndex(index); never executed: setCurrentIndex(index); | 0 | ||||||||||||||||||||||||
| 3370 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3371 | int row = end + 1; | - | ||||||||||||||||||||||||
| 3372 | QModelIndex next; | - | ||||||||||||||||||||||||
| 3373 | do { // find the next visible and enabled item | - | ||||||||||||||||||||||||
| 3374 | next = d->model->index(row++, current.column(), current.parent()); | - | ||||||||||||||||||||||||
| 3375 | } while (next.isValid() && (isIndexHidden(next) || !d->isIndexEnabled(next))); never executed: end of block
| 0 | ||||||||||||||||||||||||
| 3376 | if (row > d->model->rowCount(parent)) {
| 0 | ||||||||||||||||||||||||
| 3377 | row = start - 1; | - | ||||||||||||||||||||||||
| 3378 | do { // find the previous visible and enabled item | - | ||||||||||||||||||||||||
| 3379 | next = d->model->index(row--, current.column(), current.parent()); | - | ||||||||||||||||||||||||
| 3380 | } while (next.isValid() && (isIndexHidden(next) || !d->isIndexEnabled(next))); never executed: end of block
| 0 | ||||||||||||||||||||||||
| 3381 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3382 | setCurrentIndex(next); | - | ||||||||||||||||||||||||
| 3383 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3384 | } | - | ||||||||||||||||||||||||
| 3385 | - | |||||||||||||||||||||||||
| 3386 | // Remove all affected editors; this is more efficient than waiting for updateGeometries() to clean out editors for invalid indexes | - | ||||||||||||||||||||||||
| 3387 | QEditorIndexHash::iterator i = d->editorIndexHash.begin(); | - | ||||||||||||||||||||||||
| 3388 | while (i != d->editorIndexHash.end()) {
| 0 | ||||||||||||||||||||||||
| 3389 | const QModelIndex index = i.value(); | - | ||||||||||||||||||||||||
| 3390 | if (index.row() >= start && index.row() <= end && d->model->parent(index) == parent) {
| 0 | ||||||||||||||||||||||||
| 3391 | QWidget *editor = i.key(); | - | ||||||||||||||||||||||||
| 3392 | QEditorInfo info = d->indexEditorHash.take(index); | - | ||||||||||||||||||||||||
| 3393 | i = d->editorIndexHash.erase(i); | - | ||||||||||||||||||||||||
| 3394 | if (info.widget)
| 0 | ||||||||||||||||||||||||
| 3395 | d->releaseEditor(editor, index); never executed: d->releaseEditor(editor, index); | 0 | ||||||||||||||||||||||||
| 3396 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3397 | ++i; | - | ||||||||||||||||||||||||
| 3398 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3399 | } | - | ||||||||||||||||||||||||
| 3400 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3401 | - | |||||||||||||||||||||||||
| 3402 | /*! | - | ||||||||||||||||||||||||
| 3403 | \internal | - | ||||||||||||||||||||||||
| 3404 | - | |||||||||||||||||||||||||
| 3405 | This slot is called when rows have been removed. The deleted | - | ||||||||||||||||||||||||
| 3406 | rows are those under the given \a parent from \a start to \a end | - | ||||||||||||||||||||||||
| 3407 | inclusive. | - | ||||||||||||||||||||||||
| 3408 | */ | - | ||||||||||||||||||||||||
| 3409 | void QAbstractItemViewPrivate::_q_rowsRemoved(const QModelIndex &index, int start, int end) | - | ||||||||||||||||||||||||
| 3410 | { | - | ||||||||||||||||||||||||
| 3411 | Q_UNUSED(index) | - | ||||||||||||||||||||||||
| 3412 | Q_UNUSED(start) | - | ||||||||||||||||||||||||
| 3413 | Q_UNUSED(end) | - | ||||||||||||||||||||||||
| 3414 | - | |||||||||||||||||||||||||
| 3415 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3416 | if (q->isVisible())
| 0 | ||||||||||||||||||||||||
| 3417 | q->updateEditorGeometries(); never executed: q->updateEditorGeometries(); | 0 | ||||||||||||||||||||||||
| 3418 | q->setState(QAbstractItemView::NoState); | - | ||||||||||||||||||||||||
| 3419 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 3420 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
| 3421 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::RowsRemoved); | - | ||||||||||||||||||||||||
| 3422 | accessibleEvent.setFirstRow(start); | - | ||||||||||||||||||||||||
| 3423 | accessibleEvent.setLastRow(end); | - | ||||||||||||||||||||||||
| 3424 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||||||||
| 3425 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3426 | #endif | - | ||||||||||||||||||||||||
| 3427 | updateGeometry(); | - | ||||||||||||||||||||||||
| 3428 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3429 | - | |||||||||||||||||||||||||
| 3430 | /*! | - | ||||||||||||||||||||||||
| 3431 | \internal | - | ||||||||||||||||||||||||
| 3432 | - | |||||||||||||||||||||||||
| 3433 | This slot is called when columns are about to be removed. The deleted | - | ||||||||||||||||||||||||
| 3434 | columns are those under the given \a parent from \a start to \a end | - | ||||||||||||||||||||||||
| 3435 | inclusive. | - | ||||||||||||||||||||||||
| 3436 | */ | - | ||||||||||||||||||||||||
| 3437 | void QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) | - | ||||||||||||||||||||||||
| 3438 | { | - | ||||||||||||||||||||||||
| 3439 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3440 | - | |||||||||||||||||||||||||
| 3441 | q->setState(QAbstractItemView::CollapsingState); | - | ||||||||||||||||||||||||
| 3442 | - | |||||||||||||||||||||||||
| 3443 | // Ensure one selected item in single selection mode. | - | ||||||||||||||||||||||||
| 3444 | QModelIndex current = q->currentIndex(); | - | ||||||||||||||||||||||||
| 3445 | if (current.isValid()
| 0 | ||||||||||||||||||||||||
| 3446 | && selectionMode == QAbstractItemView::SingleSelection
| 0 | ||||||||||||||||||||||||
| 3447 | && current.column() >= start
| 0 | ||||||||||||||||||||||||
| 3448 | && current.column() <= end) {
| 0 | ||||||||||||||||||||||||
| 3449 | int totalToRemove = end - start + 1; | - | ||||||||||||||||||||||||
| 3450 | if (model->columnCount(parent) < totalToRemove) { // no more columns
| 0 | ||||||||||||||||||||||||
| 3451 | QModelIndex index = parent; | - | ||||||||||||||||||||||||
| 3452 | while (index.isValid() && !isIndexEnabled(index))
| 0 | ||||||||||||||||||||||||
| 3453 | index = index.parent(); never executed: index = index.parent(); | 0 | ||||||||||||||||||||||||
| 3454 | if (index.isValid())
| 0 | ||||||||||||||||||||||||
| 3455 | q->setCurrentIndex(index); never executed: q->setCurrentIndex(index); | 0 | ||||||||||||||||||||||||
| 3456 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3457 | int column = end; | - | ||||||||||||||||||||||||
| 3458 | QModelIndex next; | - | ||||||||||||||||||||||||
| 3459 | do { // find the next visible and enabled item | - | ||||||||||||||||||||||||
| 3460 | next = model->index(current.row(), column++, current.parent()); | - | ||||||||||||||||||||||||
| 3461 | } while (next.isValid() && (q->isIndexHidden(next) || !isIndexEnabled(next))); never executed: end of block
| 0 | ||||||||||||||||||||||||
| 3462 | q->setCurrentIndex(next); | - | ||||||||||||||||||||||||
| 3463 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3464 | } | - | ||||||||||||||||||||||||
| 3465 | - | |||||||||||||||||||||||||
| 3466 | // Remove all affected editors; this is more efficient than waiting for updateGeometries() to clean out editors for invalid indexes | - | ||||||||||||||||||||||||
| 3467 | QEditorIndexHash::iterator it = editorIndexHash.begin(); | - | ||||||||||||||||||||||||
| 3468 | while (it != editorIndexHash.end()) {
| 0 | ||||||||||||||||||||||||
| 3469 | QModelIndex index = it.value(); | - | ||||||||||||||||||||||||
| 3470 | if (index.column() <= start && index.column() >= end && model->parent(index) == parent) {
| 0 | ||||||||||||||||||||||||
| 3471 | QWidget *editor = it.key(); | - | ||||||||||||||||||||||||
| 3472 | QEditorInfo info = indexEditorHash.take(it.value()); | - | ||||||||||||||||||||||||
| 3473 | it = editorIndexHash.erase(it); | - | ||||||||||||||||||||||||
| 3474 | if (info.widget)
| 0 | ||||||||||||||||||||||||
| 3475 | releaseEditor(editor, index); never executed: releaseEditor(editor, index); | 0 | ||||||||||||||||||||||||
| 3476 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3477 | ++it; | - | ||||||||||||||||||||||||
| 3478 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3479 | } | - | ||||||||||||||||||||||||
| 3480 | - | |||||||||||||||||||||||||
| 3481 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3482 | - | |||||||||||||||||||||||||
| 3483 | /*! | - | ||||||||||||||||||||||||
| 3484 | \internal | - | ||||||||||||||||||||||||
| 3485 | - | |||||||||||||||||||||||||
| 3486 | This slot is called when columns have been removed. The deleted | - | ||||||||||||||||||||||||
| 3487 | rows are those under the given \a parent from \a start to \a end | - | ||||||||||||||||||||||||
| 3488 | inclusive. | - | ||||||||||||||||||||||||
| 3489 | */ | - | ||||||||||||||||||||||||
| 3490 | void QAbstractItemViewPrivate::_q_columnsRemoved(const QModelIndex &index, int start, int end) | - | ||||||||||||||||||||||||
| 3491 | { | - | ||||||||||||||||||||||||
| 3492 | Q_UNUSED(index) | - | ||||||||||||||||||||||||
| 3493 | Q_UNUSED(start) | - | ||||||||||||||||||||||||
| 3494 | Q_UNUSED(end) | - | ||||||||||||||||||||||||
| 3495 | - | |||||||||||||||||||||||||
| 3496 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3497 | if (q->isVisible())
| 0 | ||||||||||||||||||||||||
| 3498 | q->updateEditorGeometries(); never executed: q->updateEditorGeometries(); | 0 | ||||||||||||||||||||||||
| 3499 | q->setState(QAbstractItemView::NoState); | - | ||||||||||||||||||||||||
| 3500 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 3501 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
| 3502 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::ColumnsRemoved); | - | ||||||||||||||||||||||||
| 3503 | accessibleEvent.setFirstColumn(start); | - | ||||||||||||||||||||||||
| 3504 | accessibleEvent.setLastColumn(end); | - | ||||||||||||||||||||||||
| 3505 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||||||||
| 3506 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3507 | #endif | - | ||||||||||||||||||||||||
| 3508 | updateGeometry(); | - | ||||||||||||||||||||||||
| 3509 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3510 | - | |||||||||||||||||||||||||
| 3511 | - | |||||||||||||||||||||||||
| 3512 | /*! | - | ||||||||||||||||||||||||
| 3513 | \internal | - | ||||||||||||||||||||||||
| 3514 | - | |||||||||||||||||||||||||
| 3515 | This slot is called when rows have been inserted. | - | ||||||||||||||||||||||||
| 3516 | */ | - | ||||||||||||||||||||||||
| 3517 | void QAbstractItemViewPrivate::_q_rowsInserted(const QModelIndex &index, int start, int end) | - | ||||||||||||||||||||||||
| 3518 | { | - | ||||||||||||||||||||||||
| 3519 | Q_UNUSED(index) | - | ||||||||||||||||||||||||
| 3520 | Q_UNUSED(start) | - | ||||||||||||||||||||||||
| 3521 | Q_UNUSED(end) | - | ||||||||||||||||||||||||
| 3522 | - | |||||||||||||||||||||||||
| 3523 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 3524 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3525 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
| 3526 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::RowsInserted); | - | ||||||||||||||||||||||||
| 3527 | accessibleEvent.setFirstRow(start); | - | ||||||||||||||||||||||||
| 3528 | accessibleEvent.setLastRow(end); | - | ||||||||||||||||||||||||
| 3529 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||||||||
| 3530 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3531 | #endif | - | ||||||||||||||||||||||||
| 3532 | updateGeometry(); | - | ||||||||||||||||||||||||
| 3533 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3534 | - | |||||||||||||||||||||||||
| 3535 | /*! | - | ||||||||||||||||||||||||
| 3536 | \internal | - | ||||||||||||||||||||||||
| 3537 | - | |||||||||||||||||||||||||
| 3538 | This slot is called when columns have been inserted. | - | ||||||||||||||||||||||||
| 3539 | */ | - | ||||||||||||||||||||||||
| 3540 | void QAbstractItemViewPrivate::_q_columnsInserted(const QModelIndex &index, int start, int end) | - | ||||||||||||||||||||||||
| 3541 | { | - | ||||||||||||||||||||||||
| 3542 | Q_UNUSED(index) | - | ||||||||||||||||||||||||
| 3543 | Q_UNUSED(start) | - | ||||||||||||||||||||||||
| 3544 | Q_UNUSED(end) | - | ||||||||||||||||||||||||
| 3545 | - | |||||||||||||||||||||||||
| 3546 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3547 | if (q->isVisible())
| 0 | ||||||||||||||||||||||||
| 3548 | q->updateEditorGeometries(); never executed: q->updateEditorGeometries(); | 0 | ||||||||||||||||||||||||
| 3549 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 3550 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
| 3551 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::ColumnsInserted); | - | ||||||||||||||||||||||||
| 3552 | accessibleEvent.setFirstColumn(start); | - | ||||||||||||||||||||||||
| 3553 | accessibleEvent.setLastColumn(end); | - | ||||||||||||||||||||||||
| 3554 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||||||||
| 3555 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3556 | #endif | - | ||||||||||||||||||||||||
| 3557 | updateGeometry(); | - | ||||||||||||||||||||||||
| 3558 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3559 | - | |||||||||||||||||||||||||
| 3560 | /*! | - | ||||||||||||||||||||||||
| 3561 | \internal | - | ||||||||||||||||||||||||
| 3562 | */ | - | ||||||||||||||||||||||||
| 3563 | void QAbstractItemViewPrivate::_q_modelDestroyed() | - | ||||||||||||||||||||||||
| 3564 | { | - | ||||||||||||||||||||||||
| 3565 | model = QAbstractItemModelPrivate::staticEmptyModel(); | - | ||||||||||||||||||||||||
| 3566 | doDelayedReset(); | - | ||||||||||||||||||||||||
| 3567 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3568 | - | |||||||||||||||||||||||||
| 3569 | /*! | - | ||||||||||||||||||||||||
| 3570 | \internal | - | ||||||||||||||||||||||||
| 3571 | - | |||||||||||||||||||||||||
| 3572 | This slot is called when the layout is changed. | - | ||||||||||||||||||||||||
| 3573 | */ | - | ||||||||||||||||||||||||
| 3574 | void QAbstractItemViewPrivate::_q_layoutChanged() | - | ||||||||||||||||||||||||
| 3575 | { | - | ||||||||||||||||||||||||
| 3576 | doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 3577 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
| 3578 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3579 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
| 3580 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::ModelReset); | - | ||||||||||||||||||||||||
| 3581 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||||||||
| 3582 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3583 | #endif | - | ||||||||||||||||||||||||
| 3584 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3585 | - | |||||||||||||||||||||||||
| 3586 | void QAbstractItemViewPrivate::_q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int) | - | ||||||||||||||||||||||||
| 3587 | { | - | ||||||||||||||||||||||||
| 3588 | _q_layoutChanged(); | - | ||||||||||||||||||||||||
| 3589 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3590 | - | |||||||||||||||||||||||||
| 3591 | void QAbstractItemViewPrivate::_q_columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int) | - | ||||||||||||||||||||||||
| 3592 | { | - | ||||||||||||||||||||||||
| 3593 | _q_layoutChanged(); | - | ||||||||||||||||||||||||
| 3594 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3595 | - | |||||||||||||||||||||||||
| 3596 | /*! | - | ||||||||||||||||||||||||
| 3597 | This slot is called when the selection is changed. The previous | - | ||||||||||||||||||||||||
| 3598 | selection (which may be empty), is specified by \a deselected, and the | - | ||||||||||||||||||||||||
| 3599 | new selection by \a selected. | - | ||||||||||||||||||||||||
| 3600 | - | |||||||||||||||||||||||||
| 3601 | \sa setSelection() | - | ||||||||||||||||||||||||
| 3602 | */ | - | ||||||||||||||||||||||||
| 3603 | void QAbstractItemView::selectionChanged(const QItemSelection &selected, | - | ||||||||||||||||||||||||
| 3604 | const QItemSelection &deselected) | - | ||||||||||||||||||||||||
| 3605 | { | - | ||||||||||||||||||||||||
| 3606 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3607 | if (isVisible() && updatesEnabled()) {
| 0 | ||||||||||||||||||||||||
| 3608 | d->viewport->update(visualRegionForSelection(deselected) | visualRegionForSelection(selected)); | - | ||||||||||||||||||||||||
| 3609 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3610 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3611 | - | |||||||||||||||||||||||||
| 3612 | /*! | - | ||||||||||||||||||||||||
| 3613 | This slot is called when a new item becomes the current item. | - | ||||||||||||||||||||||||
| 3614 | The previous current item is specified by the \a previous index, and the new | - | ||||||||||||||||||||||||
| 3615 | item by the \a current index. | - | ||||||||||||||||||||||||
| 3616 | - | |||||||||||||||||||||||||
| 3617 | If you want to know about changes to items see the | - | ||||||||||||||||||||||||
| 3618 | dataChanged() signal. | - | ||||||||||||||||||||||||
| 3619 | */ | - | ||||||||||||||||||||||||
| 3620 | void QAbstractItemView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) | - | ||||||||||||||||||||||||
| 3621 | { | - | ||||||||||||||||||||||||
| 3622 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3623 | Q_ASSERT(d->model); | - | ||||||||||||||||||||||||
| 3624 | - | |||||||||||||||||||||||||
| 3625 | if (previous.isValid()) {
| 0 | ||||||||||||||||||||||||
| 3626 | QModelIndex buddy = d->model->buddy(previous); | - | ||||||||||||||||||||||||
| 3627 | QWidget *editor = d->editorForIndex(buddy).widget.data(); | - | ||||||||||||||||||||||||
| 3628 | if (editor && !d->persistent.contains(editor)) {
| 0 | ||||||||||||||||||||||||
| 3629 | commitData(editor); | - | ||||||||||||||||||||||||
| 3630 | if (current.row() != previous.row())
| 0 | ||||||||||||||||||||||||
| 3631 | closeEditor(editor, QAbstractItemDelegate::SubmitModelCache); never executed: closeEditor(editor, QAbstractItemDelegate::SubmitModelCache); | 0 | ||||||||||||||||||||||||
| 3632 | else | - | ||||||||||||||||||||||||
| 3633 | closeEditor(editor, QAbstractItemDelegate::NoHint); never executed: closeEditor(editor, QAbstractItemDelegate::NoHint); | 0 | ||||||||||||||||||||||||
| 3634 | } | - | ||||||||||||||||||||||||
| 3635 | if (isVisible()) {
| 0 | ||||||||||||||||||||||||
| 3636 | update(previous); | - | ||||||||||||||||||||||||
| 3637 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3638 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3639 | - | |||||||||||||||||||||||||
| 3640 | if (current.isValid() && !d->autoScrollTimer.isActive()) {
| 0 | ||||||||||||||||||||||||
| 3641 | if (isVisible()) {
| 0 | ||||||||||||||||||||||||
| 3642 | if (d->autoScroll)
| 0 | ||||||||||||||||||||||||
| 3643 | scrollTo(current); never executed: scrollTo(current); | 0 | ||||||||||||||||||||||||
| 3644 | update(current); | - | ||||||||||||||||||||||||
| 3645 | edit(current, CurrentChanged, 0); | - | ||||||||||||||||||||||||
| 3646 | if (current.row() == (d->model->rowCount(d->root) - 1))
| 0 | ||||||||||||||||||||||||
| 3647 | d->fetchMore(); never executed: d->fetchMore(); | 0 | ||||||||||||||||||||||||
| 3648 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3649 | d->shouldScrollToCurrentOnShow = d->autoScroll; | - | ||||||||||||||||||||||||
| 3650 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3651 | } | - | ||||||||||||||||||||||||
| 3652 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3653 | - | |||||||||||||||||||||||||
| 3654 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 3655 | /*! | - | ||||||||||||||||||||||||
| 3656 | Starts a drag by calling drag->exec() using the given \a supportedActions. | - | ||||||||||||||||||||||||
| 3657 | */ | - | ||||||||||||||||||||||||
| 3658 | void QAbstractItemView::startDrag(Qt::DropActions supportedActions) | - | ||||||||||||||||||||||||
| 3659 | { | - | ||||||||||||||||||||||||
| 3660 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3661 | QModelIndexList indexes = d->selectedDraggableIndexes(); | - | ||||||||||||||||||||||||
| 3662 | if (indexes.count() > 0) {
| 0 | ||||||||||||||||||||||||
| 3663 | QMimeData *data = d->model->mimeData(indexes); | - | ||||||||||||||||||||||||
| 3664 | if (!data)
| 0 | ||||||||||||||||||||||||
| 3665 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 3666 | QRect rect; | - | ||||||||||||||||||||||||
| 3667 | QPixmap pixmap = d->renderToPixmap(indexes, &rect); | - | ||||||||||||||||||||||||
| 3668 | rect.adjust(horizontalOffset(), verticalOffset(), 0, 0); | - | ||||||||||||||||||||||||
| 3669 | QDrag *drag = new QDrag(this); | - | ||||||||||||||||||||||||
| 3670 | drag->setPixmap(pixmap); | - | ||||||||||||||||||||||||
| 3671 | drag->setMimeData(data); | - | ||||||||||||||||||||||||
| 3672 | drag->setHotSpot(d->pressedPosition - rect.topLeft()); | - | ||||||||||||||||||||||||
| 3673 | Qt::DropAction defaultDropAction = Qt::IgnoreAction; | - | ||||||||||||||||||||||||
| 3674 | if (d->defaultDropAction != Qt::IgnoreAction && (supportedActions & d->defaultDropAction))
| 0 | ||||||||||||||||||||||||
| 3675 | defaultDropAction = d->defaultDropAction; never executed: defaultDropAction = d->defaultDropAction; | 0 | ||||||||||||||||||||||||
| 3676 | else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)
| 0 | ||||||||||||||||||||||||
| 3677 | defaultDropAction = Qt::CopyAction; never executed: defaultDropAction = Qt::CopyAction; | 0 | ||||||||||||||||||||||||
| 3678 | if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction)
| 0 | ||||||||||||||||||||||||
| 3679 | d->clearOrRemove(); never executed: d->clearOrRemove(); | 0 | ||||||||||||||||||||||||
| 3680 | // Reset the drop indicator | - | ||||||||||||||||||||||||
| 3681 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
| 3682 | d->dropIndicatorPosition = OnItem; | - | ||||||||||||||||||||||||
| 3683 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3684 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3685 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 3686 | - | |||||||||||||||||||||||||
| 3687 | /*! | - | ||||||||||||||||||||||||
| 3688 | Returns a QStyleOptionViewItem structure populated with the view's | - | ||||||||||||||||||||||||
| 3689 | palette, font, state, alignments etc. | - | ||||||||||||||||||||||||
| 3690 | */ | - | ||||||||||||||||||||||||
| 3691 | QStyleOptionViewItem QAbstractItemView::viewOptions() const | - | ||||||||||||||||||||||||
| 3692 | { | - | ||||||||||||||||||||||||
| 3693 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 3694 | QStyleOptionViewItem option; | - | ||||||||||||||||||||||||
| 3695 | option.init(this); | - | ||||||||||||||||||||||||
| 3696 | option.state &= ~QStyle::State_MouseOver; | - | ||||||||||||||||||||||||
| 3697 | option.font = font(); | - | ||||||||||||||||||||||||
| 3698 | - | |||||||||||||||||||||||||
| 3699 | #ifndef Q_DEAD_CODE_FROM_QT4_MAC | - | ||||||||||||||||||||||||
| 3700 | // On mac the focus appearance follows window activation | - | ||||||||||||||||||||||||
| 3701 | // not widget activation | - | ||||||||||||||||||||||||
| 3702 | if (!hasFocus())
| 0 | ||||||||||||||||||||||||
| 3703 | option.state &= ~QStyle::State_Active; never executed: option.state &= ~QStyle::State_Active; | 0 | ||||||||||||||||||||||||
| 3704 | #endif | - | ||||||||||||||||||||||||
| 3705 | - | |||||||||||||||||||||||||
| 3706 | option.state &= ~QStyle::State_HasFocus; | - | ||||||||||||||||||||||||
| 3707 | if (d->iconSize.isValid()) {
| 0 | ||||||||||||||||||||||||
| 3708 | option.decorationSize = d->iconSize; | - | ||||||||||||||||||||||||
| 3709 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3710 | int pm = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); | - | ||||||||||||||||||||||||
| 3711 | option.decorationSize = QSize(pm, pm); | - | ||||||||||||||||||||||||
| 3712 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3713 | option.decorationPosition = QStyleOptionViewItem::Left; | - | ||||||||||||||||||||||||
| 3714 | option.decorationAlignment = Qt::AlignCenter; | - | ||||||||||||||||||||||||
| 3715 | option.displayAlignment = Qt::AlignLeft|Qt::AlignVCenter; | - | ||||||||||||||||||||||||
| 3716 | option.textElideMode = d->textElideMode; | - | ||||||||||||||||||||||||
| 3717 | option.rect = QRect(); | - | ||||||||||||||||||||||||
| 3718 | option.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, this); | - | ||||||||||||||||||||||||
| 3719 | if (d->wrapItemText)
| 0 | ||||||||||||||||||||||||
| 3720 | option.features = QStyleOptionViewItem::WrapText; never executed: option.features = QStyleOptionViewItem::WrapText; | 0 | ||||||||||||||||||||||||
| 3721 | option.locale = locale(); | - | ||||||||||||||||||||||||
| 3722 | option.locale.setNumberOptions(QLocale::OmitGroupSeparator); | - | ||||||||||||||||||||||||
| 3723 | option.widget = this; | - | ||||||||||||||||||||||||
| 3724 | return option; never executed: return option; | 0 | ||||||||||||||||||||||||
| 3725 | } | - | ||||||||||||||||||||||||
| 3726 | - | |||||||||||||||||||||||||
| 3727 | QStyleOptionViewItem QAbstractItemViewPrivate::viewOptionsV1() const | - | ||||||||||||||||||||||||
| 3728 | { | - | ||||||||||||||||||||||||
| 3729 | Q_Q(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 3730 | return q->viewOptions(); never executed: return q->viewOptions(); | 0 | ||||||||||||||||||||||||
| 3731 | } | - | ||||||||||||||||||||||||
| 3732 | - | |||||||||||||||||||||||||
| 3733 | /*! | - | ||||||||||||||||||||||||
| 3734 | Returns the item view's state. | - | ||||||||||||||||||||||||
| 3735 | - | |||||||||||||||||||||||||
| 3736 | \sa setState() | - | ||||||||||||||||||||||||
| 3737 | */ | - | ||||||||||||||||||||||||
| 3738 | QAbstractItemView::State QAbstractItemView::state() const | - | ||||||||||||||||||||||||
| 3739 | { | - | ||||||||||||||||||||||||
| 3740 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 3741 | return d->state; never executed: return d->state; | 0 | ||||||||||||||||||||||||
| 3742 | } | - | ||||||||||||||||||||||||
| 3743 | - | |||||||||||||||||||||||||
| 3744 | /*! | - | ||||||||||||||||||||||||
| 3745 | Sets the item view's state to the given \a state. | - | ||||||||||||||||||||||||
| 3746 | - | |||||||||||||||||||||||||
| 3747 | \sa state() | - | ||||||||||||||||||||||||
| 3748 | */ | - | ||||||||||||||||||||||||
| 3749 | void QAbstractItemView::setState(State state) | - | ||||||||||||||||||||||||
| 3750 | { | - | ||||||||||||||||||||||||
| 3751 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3752 | d->state = state; | - | ||||||||||||||||||||||||
| 3753 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3754 | - | |||||||||||||||||||||||||
| 3755 | /*! | - | ||||||||||||||||||||||||
| 3756 | Schedules a layout of the items in the view to be executed when the | - | ||||||||||||||||||||||||
| 3757 | event processing starts. | - | ||||||||||||||||||||||||
| 3758 | - | |||||||||||||||||||||||||
| 3759 | Even if scheduleDelayedItemsLayout() is called multiple times before | - | ||||||||||||||||||||||||
| 3760 | events are processed, the view will only do the layout once. | - | ||||||||||||||||||||||||
| 3761 | - | |||||||||||||||||||||||||
| 3762 | \sa executeDelayedItemsLayout() | - | ||||||||||||||||||||||||
| 3763 | */ | - | ||||||||||||||||||||||||
| 3764 | void QAbstractItemView::scheduleDelayedItemsLayout() | - | ||||||||||||||||||||||||
| 3765 | { | - | ||||||||||||||||||||||||
| 3766 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3767 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
| 3768 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3769 | - | |||||||||||||||||||||||||
| 3770 | /*! | - | ||||||||||||||||||||||||
| 3771 | Executes the scheduled layouts without waiting for the event processing | - | ||||||||||||||||||||||||
| 3772 | to begin. | - | ||||||||||||||||||||||||
| 3773 | - | |||||||||||||||||||||||||
| 3774 | \sa scheduleDelayedItemsLayout() | - | ||||||||||||||||||||||||
| 3775 | */ | - | ||||||||||||||||||||||||
| 3776 | void QAbstractItemView::executeDelayedItemsLayout() | - | ||||||||||||||||||||||||
| 3777 | { | - | ||||||||||||||||||||||||
| 3778 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3779 | d->executePostedLayout(); | - | ||||||||||||||||||||||||
| 3780 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3781 | - | |||||||||||||||||||||||||
| 3782 | /*! | - | ||||||||||||||||||||||||
| 3783 | \since 4.1 | - | ||||||||||||||||||||||||
| 3784 | - | |||||||||||||||||||||||||
| 3785 | Marks the given \a region as dirty and schedules it to be updated. | - | ||||||||||||||||||||||||
| 3786 | You only need to call this function if you are implementing | - | ||||||||||||||||||||||||
| 3787 | your own view subclass. | - | ||||||||||||||||||||||||
| 3788 | - | |||||||||||||||||||||||||
| 3789 | \sa scrollDirtyRegion(), dirtyRegionOffset() | - | ||||||||||||||||||||||||
| 3790 | */ | - | ||||||||||||||||||||||||
| 3791 | - | |||||||||||||||||||||||||
| 3792 | void QAbstractItemView::setDirtyRegion(const QRegion ®ion) | - | ||||||||||||||||||||||||
| 3793 | { | - | ||||||||||||||||||||||||
| 3794 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3795 | d->setDirtyRegion(region); | - | ||||||||||||||||||||||||
| 3796 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3797 | - | |||||||||||||||||||||||||
| 3798 | /*! | - | ||||||||||||||||||||||||
| 3799 | Prepares the view for scrolling by (\a{dx},\a{dy}) pixels by moving the dirty regions in the | - | ||||||||||||||||||||||||
| 3800 | opposite direction. You only need to call this function if you are implementing a scrolling | - | ||||||||||||||||||||||||
| 3801 | viewport in your view subclass. | - | ||||||||||||||||||||||||
| 3802 | - | |||||||||||||||||||||||||
| 3803 | If you implement scrollContentsBy() in a subclass of QAbstractItemView, call this function | - | ||||||||||||||||||||||||
| 3804 | before you call QWidget::scroll() on the viewport. Alternatively, just call update(). | - | ||||||||||||||||||||||||
| 3805 | - | |||||||||||||||||||||||||
| 3806 | \sa scrollContentsBy(), dirtyRegionOffset(), setDirtyRegion() | - | ||||||||||||||||||||||||
| 3807 | */ | - | ||||||||||||||||||||||||
| 3808 | void QAbstractItemView::scrollDirtyRegion(int dx, int dy) | - | ||||||||||||||||||||||||
| 3809 | { | - | ||||||||||||||||||||||||
| 3810 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3811 | d->scrollDirtyRegion(dx, dy); | - | ||||||||||||||||||||||||
| 3812 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3813 | - | |||||||||||||||||||||||||
| 3814 | /*! | - | ||||||||||||||||||||||||
| 3815 | Returns the offset of the dirty regions in the view. | - | ||||||||||||||||||||||||
| 3816 | - | |||||||||||||||||||||||||
| 3817 | If you use scrollDirtyRegion() and implement a paintEvent() in a subclass of | - | ||||||||||||||||||||||||
| 3818 | QAbstractItemView, you should translate the area given by the paint event with | - | ||||||||||||||||||||||||
| 3819 | the offset returned from this function. | - | ||||||||||||||||||||||||
| 3820 | - | |||||||||||||||||||||||||
| 3821 | \sa scrollDirtyRegion(), setDirtyRegion() | - | ||||||||||||||||||||||||
| 3822 | */ | - | ||||||||||||||||||||||||
| 3823 | QPoint QAbstractItemView::dirtyRegionOffset() const | - | ||||||||||||||||||||||||
| 3824 | { | - | ||||||||||||||||||||||||
| 3825 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 3826 | return d->scrollDelayOffset; never executed: return d->scrollDelayOffset; | 0 | ||||||||||||||||||||||||
| 3827 | } | - | ||||||||||||||||||||||||
| 3828 | - | |||||||||||||||||||||||||
| 3829 | /*! | - | ||||||||||||||||||||||||
| 3830 | \internal | - | ||||||||||||||||||||||||
| 3831 | */ | - | ||||||||||||||||||||||||
| 3832 | void QAbstractItemView::startAutoScroll() | - | ||||||||||||||||||||||||
| 3833 | { | - | ||||||||||||||||||||||||
| 3834 | d_func()->startAutoScroll(); | - | ||||||||||||||||||||||||
| 3835 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3836 | - | |||||||||||||||||||||||||
| 3837 | /*! | - | ||||||||||||||||||||||||
| 3838 | \internal | - | ||||||||||||||||||||||||
| 3839 | */ | - | ||||||||||||||||||||||||
| 3840 | void QAbstractItemView::stopAutoScroll() | - | ||||||||||||||||||||||||
| 3841 | { | - | ||||||||||||||||||||||||
| 3842 | d_func()->stopAutoScroll(); | - | ||||||||||||||||||||||||
| 3843 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3844 | - | |||||||||||||||||||||||||
| 3845 | /*! | - | ||||||||||||||||||||||||
| 3846 | \internal | - | ||||||||||||||||||||||||
| 3847 | */ | - | ||||||||||||||||||||||||
| 3848 | void QAbstractItemView::doAutoScroll() | - | ||||||||||||||||||||||||
| 3849 | { | - | ||||||||||||||||||||||||
| 3850 | // find how much we should scroll with | - | ||||||||||||||||||||||||
| 3851 | Q_D(QAbstractItemView); | - | ||||||||||||||||||||||||
| 3852 | QScrollBar *verticalScroll = verticalScrollBar(); | - | ||||||||||||||||||||||||
| 3853 | QScrollBar *horizontalScroll = horizontalScrollBar(); | - | ||||||||||||||||||||||||
| 3854 | - | |||||||||||||||||||||||||
| 3855 | // QHeaderView does not (normally) have scrollbars | - | ||||||||||||||||||||||||
| 3856 | // It needs to use its parents scroll instead | - | ||||||||||||||||||||||||
| 3857 | QHeaderView *hv = qobject_cast<QHeaderView*>(this); | - | ||||||||||||||||||||||||
| 3858 | if (hv) {
| 0 | ||||||||||||||||||||||||
| 3859 | QAbstractScrollArea *parent = qobject_cast<QAbstractScrollArea*>(parentWidget()); | - | ||||||||||||||||||||||||
| 3860 | if (parent) {
| 0 | ||||||||||||||||||||||||
| 3861 | if (hv->orientation() == Qt::Horizontal) {
| 0 | ||||||||||||||||||||||||
| 3862 | if (!hv->horizontalScrollBar() || !hv->horizontalScrollBar()->isVisible())
| 0 | ||||||||||||||||||||||||
| 3863 | horizontalScroll = parent->horizontalScrollBar(); never executed: horizontalScroll = parent->horizontalScrollBar(); | 0 | ||||||||||||||||||||||||
| 3864 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3865 | if (!hv->verticalScrollBar() || !hv->verticalScrollBar()->isVisible())
| 0 | ||||||||||||||||||||||||
| 3866 | verticalScroll = parent->verticalScrollBar(); never executed: verticalScroll = parent->verticalScrollBar(); | 0 | ||||||||||||||||||||||||
| 3867 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3868 | } | - | ||||||||||||||||||||||||
| 3869 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3870 | - | |||||||||||||||||||||||||
| 3871 | int verticalStep = verticalScroll->pageStep(); | - | ||||||||||||||||||||||||
| 3872 | int horizontalStep = horizontalScroll->pageStep(); | - | ||||||||||||||||||||||||
| 3873 | if (d->autoScrollCount < qMax(verticalStep, horizontalStep))
| 0 | ||||||||||||||||||||||||
| 3874 | ++d->autoScrollCount; never executed: ++d->autoScrollCount; | 0 | ||||||||||||||||||||||||
| 3875 | - | |||||||||||||||||||||||||
| 3876 | int margin = d->autoScrollMargin; | - | ||||||||||||||||||||||||
| 3877 | int verticalValue = verticalScroll->value(); | - | ||||||||||||||||||||||||
| 3878 | int horizontalValue = horizontalScroll->value(); | - | ||||||||||||||||||||||||
| 3879 | - | |||||||||||||||||||||||||
| 3880 | QPoint pos = d->viewport->mapFromGlobal(QCursor::pos()); | - | ||||||||||||||||||||||||
| 3881 | QRect area = QWidgetPrivate::get(d->viewport)->clipRect(); | - | ||||||||||||||||||||||||
| 3882 | - | |||||||||||||||||||||||||
| 3883 | // do the scrolling if we are in the scroll margins | - | ||||||||||||||||||||||||
| 3884 | if (pos.y() - area.top() < margin)
| 0 | ||||||||||||||||||||||||
| 3885 | verticalScroll->setValue(verticalValue - d->autoScrollCount); never executed: verticalScroll->setValue(verticalValue - d->autoScrollCount); | 0 | ||||||||||||||||||||||||
| 3886 | else if (area.bottom() - pos.y() < margin)
| 0 | ||||||||||||||||||||||||
| 3887 | verticalScroll->setValue(verticalValue + d->autoScrollCount); never executed: verticalScroll->setValue(verticalValue + d->autoScrollCount); | 0 | ||||||||||||||||||||||||
| 3888 | if (pos.x() - area.left() < margin)
| 0 | ||||||||||||||||||||||||
| 3889 | horizontalScroll->setValue(horizontalValue - d->autoScrollCount); never executed: horizontalScroll->setValue(horizontalValue - d->autoScrollCount); | 0 | ||||||||||||||||||||||||
| 3890 | else if (area.right() - pos.x() < margin)
| 0 | ||||||||||||||||||||||||
| 3891 | horizontalScroll->setValue(horizontalValue + d->autoScrollCount); never executed: horizontalScroll->setValue(horizontalValue + d->autoScrollCount); | 0 | ||||||||||||||||||||||||
| 3892 | // if nothing changed, stop scrolling | - | ||||||||||||||||||||||||
| 3893 | bool verticalUnchanged = (verticalValue == verticalScroll->value()); | - | ||||||||||||||||||||||||
| 3894 | bool horizontalUnchanged = (horizontalValue == horizontalScroll->value()); | - | ||||||||||||||||||||||||
| 3895 | if (verticalUnchanged && horizontalUnchanged) {
| 0 | ||||||||||||||||||||||||
| 3896 | stopAutoScroll(); | - | ||||||||||||||||||||||||
| 3897 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 3898 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 3899 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
| 3900 | d->dropIndicatorPosition = QAbstractItemView::OnViewport; | - | ||||||||||||||||||||||||
| 3901 | #endif | - | ||||||||||||||||||||||||
| 3902 | d->viewport->update(); | - | ||||||||||||||||||||||||
| 3903 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3904 | } | - | ||||||||||||||||||||||||
| 3905 | - | |||||||||||||||||||||||||
| 3906 | /*! | - | ||||||||||||||||||||||||
| 3907 | Returns the SelectionFlags to be used when updating a selection with | - | ||||||||||||||||||||||||
| 3908 | to include the \a index specified. The \a event is a user input event, | - | ||||||||||||||||||||||||
| 3909 | such as a mouse or keyboard event. | - | ||||||||||||||||||||||||
| 3910 | - | |||||||||||||||||||||||||
| 3911 | Reimplement this function to define your own selection behavior. | - | ||||||||||||||||||||||||
| 3912 | - | |||||||||||||||||||||||||
| 3913 | \sa setSelection() | - | ||||||||||||||||||||||||
| 3914 | */ | - | ||||||||||||||||||||||||
| 3915 | QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand(const QModelIndex &index, | - | ||||||||||||||||||||||||
| 3916 | const QEvent *event) const | - | ||||||||||||||||||||||||
| 3917 | { | - | ||||||||||||||||||||||||
| 3918 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 3919 | Qt::KeyboardModifiers keyModifiers = Qt::NoModifier; | - | ||||||||||||||||||||||||
| 3920 | if (event) {
| 0 | ||||||||||||||||||||||||
| 3921 | switch (event->type()) { | - | ||||||||||||||||||||||||
| 3922 | case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||||||||||||||
| 3923 | case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||||||||
| 3924 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||||||||
| 3925 | case QEvent::MouseMove: never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||||||||
| 3926 | case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||
| 3927 | case QEvent::KeyRelease: never executed: case QEvent::KeyRelease: | 0 | ||||||||||||||||||||||||
| 3928 | keyModifiers = (static_cast<const QInputEvent*>(event))->modifiers(); | - | ||||||||||||||||||||||||
| 3929 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 3930 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 3931 | keyModifiers = QApplication::keyboardModifiers(); | - | ||||||||||||||||||||||||
| 3932 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3933 | } | - | ||||||||||||||||||||||||
| 3934 | switch (d->selectionMode) { | - | ||||||||||||||||||||||||
| 3935 | case NoSelection: // Never update selection model never executed: case NoSelection: | 0 | ||||||||||||||||||||||||
| 3936 | return QItemSelectionModel::NoUpdate; never executed: return QItemSelectionModel::NoUpdate; | 0 | ||||||||||||||||||||||||
| 3937 | case SingleSelection: // ClearAndSelect on valid index otherwise NoUpdate never executed: case SingleSelection: | 0 | ||||||||||||||||||||||||
| 3938 | if (event && event->type() == QEvent::MouseButtonRelease)
| 0 | ||||||||||||||||||||||||
| 3939 | return QItemSelectionModel::NoUpdate; never executed: return QItemSelectionModel::NoUpdate; | 0 | ||||||||||||||||||||||||
| 3940 | if ((keyModifiers & Qt::ControlModifier) && d->selectionModel->isSelected(index))
| 0 | ||||||||||||||||||||||||
| 3941 | return QItemSelectionModel::Deselect | d->selectionBehaviorFlags(); never executed: return QItemSelectionModel::Deselect | d->selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 3942 | else | - | ||||||||||||||||||||||||
| 3943 | return QItemSelectionModel::ClearAndSelect | d->selectionBehaviorFlags(); never executed: return QItemSelectionModel::ClearAndSelect | d->selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 3944 | case MultiSelection: never executed: case MultiSelection: | 0 | ||||||||||||||||||||||||
| 3945 | return d->multiSelectionCommand(index, event); never executed: return d->multiSelectionCommand(index, event); | 0 | ||||||||||||||||||||||||
| 3946 | case ExtendedSelection: never executed: case ExtendedSelection: | 0 | ||||||||||||||||||||||||
| 3947 | return d->extendedSelectionCommand(index, event); never executed: return d->extendedSelectionCommand(index, event); | 0 | ||||||||||||||||||||||||
| 3948 | case ContiguousSelection: never executed: case ContiguousSelection: | 0 | ||||||||||||||||||||||||
| 3949 | return d->contiguousSelectionCommand(index, event); never executed: return d->contiguousSelectionCommand(index, event); | 0 | ||||||||||||||||||||||||
| 3950 | } | - | ||||||||||||||||||||||||
| 3951 | return QItemSelectionModel::NoUpdate; never executed: return QItemSelectionModel::NoUpdate; | 0 | ||||||||||||||||||||||||
| 3952 | } | - | ||||||||||||||||||||||||
| 3953 | - | |||||||||||||||||||||||||
| 3954 | QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::multiSelectionCommand( | - | ||||||||||||||||||||||||
| 3955 | const QModelIndex &index, const QEvent *event) const | - | ||||||||||||||||||||||||
| 3956 | { | - | ||||||||||||||||||||||||
| 3957 | Q_UNUSED(index) | - | ||||||||||||||||||||||||
| 3958 | - | |||||||||||||||||||||||||
| 3959 | if (event) {
| 0 | ||||||||||||||||||||||||
| 3960 | switch (event->type()) { | - | ||||||||||||||||||||||||
| 3961 | case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||
| 3962 | if (static_cast<const QKeyEvent*>(event)->key() == Qt::Key_Space
| 0 | ||||||||||||||||||||||||
| 3963 | || static_cast<const QKeyEvent*>(event)->key() == Qt::Key_Select)
| 0 | ||||||||||||||||||||||||
| 3964 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); never executed: return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 3965 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 3966 | case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||||||||
| 3967 | if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton)
| 0 | ||||||||||||||||||||||||
| 3968 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); // toggle never executed: return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 3969 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 3970 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||||||||
| 3971 | if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton)
| 0 | ||||||||||||||||||||||||
| 3972 | return QItemSelectionModel::NoUpdate|selectionBehaviorFlags(); // finalize never executed: return QItemSelectionModel::NoUpdate|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 3973 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 3974 | case QEvent::MouseMove: never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||||||||
| 3975 | if (static_cast<const QMouseEvent*>(event)->buttons() & Qt::LeftButton)
| 0 | ||||||||||||||||||||||||
| 3976 | return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); // toggle drag select never executed: return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 3977 | default: code before this statement never executed: default:never executed: default: | 0 | ||||||||||||||||||||||||
| 3978 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 3979 | } | - | ||||||||||||||||||||||||
| 3980 | return QItemSelectionModel::NoUpdate; never executed: return QItemSelectionModel::NoUpdate; | 0 | ||||||||||||||||||||||||
| 3981 | } | - | ||||||||||||||||||||||||
| 3982 | - | |||||||||||||||||||||||||
| 3983 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); never executed: return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 3984 | } | - | ||||||||||||||||||||||||
| 3985 | - | |||||||||||||||||||||||||
| 3986 | QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::extendedSelectionCommand( | - | ||||||||||||||||||||||||
| 3987 | const QModelIndex &index, const QEvent *event) const | - | ||||||||||||||||||||||||
| 3988 | { | - | ||||||||||||||||||||||||
| 3989 | Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers(); | - | ||||||||||||||||||||||||
| 3990 | if (event) {
| 0 | ||||||||||||||||||||||||
| 3991 | switch (event->type()) { | - | ||||||||||||||||||||||||
| 3992 | case QEvent::MouseMove: { never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||||||||
| 3993 | // Toggle on MouseMove | - | ||||||||||||||||||||||||
| 3994 | modifiers = static_cast<const QMouseEvent*>(event)->modifiers(); | - | ||||||||||||||||||||||||
| 3995 | if (modifiers & Qt::ControlModifier)
| 0 | ||||||||||||||||||||||||
| 3996 | return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); never executed: return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 3997 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 3998 | } | - | ||||||||||||||||||||||||
| 3999 | case QEvent::MouseButtonPress: { never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||||||||
| 4000 | modifiers = static_cast<const QMouseEvent*>(event)->modifiers(); | - | ||||||||||||||||||||||||
| 4001 | const Qt::MouseButton button = static_cast<const QMouseEvent*>(event)->button(); | - | ||||||||||||||||||||||||
| 4002 | const bool rightButtonPressed = button & Qt::RightButton; | - | ||||||||||||||||||||||||
| 4003 | const bool shiftKeyPressed = modifiers & Qt::ShiftModifier; | - | ||||||||||||||||||||||||
| 4004 | const bool controlKeyPressed = modifiers & Qt::ControlModifier; | - | ||||||||||||||||||||||||
| 4005 | const bool indexIsSelected = selectionModel->isSelected(index); | - | ||||||||||||||||||||||||
| 4006 | if ((shiftKeyPressed || controlKeyPressed) && rightButtonPressed)
| 0 | ||||||||||||||||||||||||
| 4007 | return QItemSelectionModel::NoUpdate; never executed: return QItemSelectionModel::NoUpdate; | 0 | ||||||||||||||||||||||||
| 4008 | if (!shiftKeyPressed && !controlKeyPressed && indexIsSelected)
| 0 | ||||||||||||||||||||||||
| 4009 | return QItemSelectionModel::NoUpdate; never executed: return QItemSelectionModel::NoUpdate; | 0 | ||||||||||||||||||||||||
| 4010 | if (!index.isValid() && !rightButtonPressed && !shiftKeyPressed && !controlKeyPressed)
| 0 | ||||||||||||||||||||||||
| 4011 | return QItemSelectionModel::Clear; never executed: return QItemSelectionModel::Clear; | 0 | ||||||||||||||||||||||||
| 4012 | if (!index.isValid())
| 0 | ||||||||||||||||||||||||
| 4013 | return QItemSelectionModel::NoUpdate; never executed: return QItemSelectionModel::NoUpdate; | 0 | ||||||||||||||||||||||||
| 4014 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 4015 | } | - | ||||||||||||||||||||||||
| 4016 | case QEvent::MouseButtonRelease: { never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||||||||
| 4017 | // ClearAndSelect on MouseButtonRelease if MouseButtonPress on selected item or empty area | - | ||||||||||||||||||||||||
| 4018 | modifiers = static_cast<const QMouseEvent*>(event)->modifiers(); | - | ||||||||||||||||||||||||
| 4019 | const Qt::MouseButton button = static_cast<const QMouseEvent*>(event)->button(); | - | ||||||||||||||||||||||||
| 4020 | const bool rightButtonPressed = button & Qt::RightButton; | - | ||||||||||||||||||||||||
| 4021 | const bool shiftKeyPressed = modifiers & Qt::ShiftModifier; | - | ||||||||||||||||||||||||
| 4022 | const bool controlKeyPressed = modifiers & Qt::ControlModifier; | - | ||||||||||||||||||||||||
| 4023 | if (((index == pressedIndex && selectionModel->isSelected(index))
| 0 | ||||||||||||||||||||||||
| 4024 | || !index.isValid()) && state != QAbstractItemView::DragSelectingState
| 0 | ||||||||||||||||||||||||
| 4025 | && !shiftKeyPressed && !controlKeyPressed && (!rightButtonPressed || !index.isValid()))
| 0 | ||||||||||||||||||||||||
| 4026 | return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); never executed: return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4027 | return QItemSelectionModel::NoUpdate; never executed: return QItemSelectionModel::NoUpdate; | 0 | ||||||||||||||||||||||||
| 4028 | } | - | ||||||||||||||||||||||||
| 4029 | case QEvent::KeyPress: { never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||
| 4030 | // NoUpdate on Key movement and Ctrl | - | ||||||||||||||||||||||||
| 4031 | modifiers = static_cast<const QKeyEvent*>(event)->modifiers(); | - | ||||||||||||||||||||||||
| 4032 | switch (static_cast<const QKeyEvent*>(event)->key()) { | - | ||||||||||||||||||||||||
| 4033 | case Qt::Key_Backtab: never executed: case Qt::Key_Backtab: | 0 | ||||||||||||||||||||||||
| 4034 | modifiers = modifiers & ~Qt::ShiftModifier; // special case for backtab | - | ||||||||||||||||||||||||
| 4035 | case Qt::Key_Down: code before this statement never executed: case Qt::Key_Down:never executed: case Qt::Key_Down: | 0 | ||||||||||||||||||||||||
| 4036 | case Qt::Key_Up: never executed: case Qt::Key_Up: | 0 | ||||||||||||||||||||||||
| 4037 | case Qt::Key_Left: never executed: case Qt::Key_Left: | 0 | ||||||||||||||||||||||||
| 4038 | case Qt::Key_Right: never executed: case Qt::Key_Right: | 0 | ||||||||||||||||||||||||
| 4039 | case Qt::Key_Home: never executed: case Qt::Key_Home: | 0 | ||||||||||||||||||||||||
| 4040 | case Qt::Key_End: never executed: case Qt::Key_End: | 0 | ||||||||||||||||||||||||
| 4041 | case Qt::Key_PageUp: never executed: case Qt::Key_PageUp: | 0 | ||||||||||||||||||||||||
| 4042 | case Qt::Key_PageDown: never executed: case Qt::Key_PageDown: | 0 | ||||||||||||||||||||||||
| 4043 | case Qt::Key_Tab: never executed: case Qt::Key_Tab: | 0 | ||||||||||||||||||||||||
| 4044 | if (modifiers & Qt::ControlModifier
| 0 | ||||||||||||||||||||||||
| 4045 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 4046 | // Preserve historical tab order navigation behavior | - | ||||||||||||||||||||||||
| 4047 | || QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder | - | ||||||||||||||||||||||||
| 4048 | #endif | - | ||||||||||||||||||||||||
| 4049 | ) | - | ||||||||||||||||||||||||
| 4050 | return QItemSelectionModel::NoUpdate; never executed: return QItemSelectionModel::NoUpdate; | 0 | ||||||||||||||||||||||||
| 4051 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 4052 | case Qt::Key_Select: never executed: case Qt::Key_Select: | 0 | ||||||||||||||||||||||||
| 4053 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); never executed: return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4054 | case Qt::Key_Space:// Toggle on Ctrl-Qt::Key_Space, Select on Space never executed: case Qt::Key_Space: | 0 | ||||||||||||||||||||||||
| 4055 | if (modifiers & Qt::ControlModifier)
| 0 | ||||||||||||||||||||||||
| 4056 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); never executed: return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4057 | return QItemSelectionModel::Select|selectionBehaviorFlags(); never executed: return QItemSelectionModel::Select|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4058 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 4059 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 4060 | } | - | ||||||||||||||||||||||||
| 4061 | } | - | ||||||||||||||||||||||||
| 4062 | default: code before this statement never executed: default:never executed: default: | 0 | ||||||||||||||||||||||||
| 4063 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 4064 | } | - | ||||||||||||||||||||||||
| 4065 | } | - | ||||||||||||||||||||||||
| 4066 | - | |||||||||||||||||||||||||
| 4067 | if (modifiers & Qt::ShiftModifier)
| 0 | ||||||||||||||||||||||||
| 4068 | return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); never executed: return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4069 | if (modifiers & Qt::ControlModifier)
| 0 | ||||||||||||||||||||||||
| 4070 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); never executed: return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4071 | if (state == QAbstractItemView::DragSelectingState) {
| 0 | ||||||||||||||||||||||||
| 4072 | //when drag-selecting we need to clear any previous selection and select the current one | - | ||||||||||||||||||||||||
| 4073 | return QItemSelectionModel::Clear|QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); never executed: return QItemSelectionModel::Clear|QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4074 | } | - | ||||||||||||||||||||||||
| 4075 | - | |||||||||||||||||||||||||
| 4076 | return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); never executed: return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4077 | } | - | ||||||||||||||||||||||||
| 4078 | - | |||||||||||||||||||||||||
| 4079 | QItemSelectionModel::SelectionFlags | - | ||||||||||||||||||||||||
| 4080 | QAbstractItemViewPrivate::contiguousSelectionCommand(const QModelIndex &index, | - | ||||||||||||||||||||||||
| 4081 | const QEvent *event) const | - | ||||||||||||||||||||||||
| 4082 | { | - | ||||||||||||||||||||||||
| 4083 | QItemSelectionModel::SelectionFlags flags = extendedSelectionCommand(index, event); | - | ||||||||||||||||||||||||
| 4084 | const int Mask = QItemSelectionModel::Clear | QItemSelectionModel::Select | - | ||||||||||||||||||||||||
| 4085 | | QItemSelectionModel::Deselect | QItemSelectionModel::Toggle | - | ||||||||||||||||||||||||
| 4086 | | QItemSelectionModel::Current; | - | ||||||||||||||||||||||||
| 4087 | - | |||||||||||||||||||||||||
| 4088 | switch (flags & Mask) { | - | ||||||||||||||||||||||||
| 4089 | case QItemSelectionModel::Clear: never executed: case QItemSelectionModel::Clear: | 0 | ||||||||||||||||||||||||
| 4090 | case QItemSelectionModel::ClearAndSelect: never executed: case QItemSelectionModel::ClearAndSelect: | 0 | ||||||||||||||||||||||||
| 4091 | case QItemSelectionModel::SelectCurrent: never executed: case QItemSelectionModel::SelectCurrent: | 0 | ||||||||||||||||||||||||
| 4092 | return flags; never executed: return flags; | 0 | ||||||||||||||||||||||||
| 4093 | case QItemSelectionModel::NoUpdate: never executed: case QItemSelectionModel::NoUpdate: | 0 | ||||||||||||||||||||||||
| 4094 | if (event &&
| 0 | ||||||||||||||||||||||||
| 4095 | (event->type() == QEvent::MouseButtonPress
| 0 | ||||||||||||||||||||||||
| 4096 | || event->type() == QEvent::MouseButtonRelease))
| 0 | ||||||||||||||||||||||||
| 4097 | return flags; never executed: return flags; | 0 | ||||||||||||||||||||||||
| 4098 | return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); never executed: return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4099 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 4100 | return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); never executed: return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); | 0 | ||||||||||||||||||||||||
| 4101 | } | - | ||||||||||||||||||||||||
| 4102 | } | - | ||||||||||||||||||||||||
| 4103 | - | |||||||||||||||||||||||||
| 4104 | void QAbstractItemViewPrivate::fetchMore() | - | ||||||||||||||||||||||||
| 4105 | { | - | ||||||||||||||||||||||||
| 4106 | fetchMoreTimer.stop(); | - | ||||||||||||||||||||||||
| 4107 | if (!model->canFetchMore(root))
| 0 | ||||||||||||||||||||||||
| 4108 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 4109 | int last = model->rowCount(root) - 1; | - | ||||||||||||||||||||||||
| 4110 | if (last < 0) {
| 0 | ||||||||||||||||||||||||
| 4111 | model->fetchMore(root); | - | ||||||||||||||||||||||||
| 4112 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 4113 | } | - | ||||||||||||||||||||||||
| 4114 | - | |||||||||||||||||||||||||
| 4115 | QModelIndex index = model->index(last, 0, root); | - | ||||||||||||||||||||||||
| 4116 | QRect rect = q_func()->visualRect(index); | - | ||||||||||||||||||||||||
| 4117 | if (viewport->rect().intersects(rect))
| 0 | ||||||||||||||||||||||||
| 4118 | model->fetchMore(root); never executed: model->fetchMore(root); | 0 | ||||||||||||||||||||||||
| 4119 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4120 | - | |||||||||||||||||||||||||
| 4121 | bool QAbstractItemViewPrivate::shouldEdit(QAbstractItemView::EditTrigger trigger, | - | ||||||||||||||||||||||||
| 4122 | const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 4123 | { | - | ||||||||||||||||||||||||
| 4124 | if (!index.isValid())
| 0 | ||||||||||||||||||||||||
| 4125 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 4126 | Qt::ItemFlags flags = model->flags(index); | - | ||||||||||||||||||||||||
| 4127 | if (((flags & Qt::ItemIsEditable) == 0) || ((flags & Qt::ItemIsEnabled) == 0))
| 0 | ||||||||||||||||||||||||
| 4128 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 4129 | if (state == QAbstractItemView::EditingState)
| 0 | ||||||||||||||||||||||||
| 4130 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 4131 | if (hasEditor(index))
| 0 | ||||||||||||||||||||||||
| 4132 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 4133 | if (trigger == QAbstractItemView::AllEditTriggers) // force editing
| 0 | ||||||||||||||||||||||||
| 4134 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 4135 | if ((trigger & editTriggers) == QAbstractItemView::SelectedClicked
| 0 | ||||||||||||||||||||||||
| 4136 | && !selectionModel->isSelected(index))
| 0 | ||||||||||||||||||||||||
| 4137 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 4138 | return (trigger & editTriggers); never executed: return (trigger & editTriggers); | 0 | ||||||||||||||||||||||||
| 4139 | } | - | ||||||||||||||||||||||||
| 4140 | - | |||||||||||||||||||||||||
| 4141 | bool QAbstractItemViewPrivate::shouldForwardEvent(QAbstractItemView::EditTrigger trigger, | - | ||||||||||||||||||||||||
| 4142 | const QEvent *event) const | - | ||||||||||||||||||||||||
| 4143 | { | - | ||||||||||||||||||||||||
| 4144 | if (!event || (trigger & editTriggers) != QAbstractItemView::AnyKeyPressed)
| 0 | ||||||||||||||||||||||||
| 4145 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 4146 | - | |||||||||||||||||||||||||
| 4147 | switch (event->type()) { | - | ||||||||||||||||||||||||
| 4148 | case QEvent::KeyPress: never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||
| 4149 | case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||||||||||||||
| 4150 | case QEvent::MouseButtonPress: never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||||||||
| 4151 | case QEvent::MouseButtonRelease: never executed: case QEvent::MouseButtonRelease: | 0 | ||||||||||||||||||||||||
| 4152 | case QEvent::MouseMove: never executed: case QEvent::MouseMove: | 0 | ||||||||||||||||||||||||
| 4153 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 4154 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 4155 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 4156 | }; | - | ||||||||||||||||||||||||
| 4157 | - | |||||||||||||||||||||||||
| 4158 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 4159 | } | - | ||||||||||||||||||||||||
| 4160 | - | |||||||||||||||||||||||||
| 4161 | bool QAbstractItemViewPrivate::shouldAutoScroll(const QPoint &pos) const | - | ||||||||||||||||||||||||
| 4162 | { | - | ||||||||||||||||||||||||
| 4163 | if (!autoScroll)
| 0 | ||||||||||||||||||||||||
| 4164 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 4165 | QRect area = static_cast<QAbstractItemView*>(viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules | - | ||||||||||||||||||||||||
| 4166 | return (pos.y() - area.top() < autoScrollMargin) never executed: return (pos.y() - area.top() < autoScrollMargin) || (area.bottom() - pos.y() < autoScrollMargin) || (pos.x() - area.left() < autoScrollMargin) || (area.right() - pos.x() < autoScrollMargin); | 0 | ||||||||||||||||||||||||
| 4167 | || (area.bottom() - pos.y() < autoScrollMargin) never executed: return (pos.y() - area.top() < autoScrollMargin) || (area.bottom() - pos.y() < autoScrollMargin) || (pos.x() - area.left() < autoScrollMargin) || (area.right() - pos.x() < autoScrollMargin); | 0 | ||||||||||||||||||||||||
| 4168 | || (pos.x() - area.left() < autoScrollMargin) never executed: return (pos.y() - area.top() < autoScrollMargin) || (area.bottom() - pos.y() < autoScrollMargin) || (pos.x() - area.left() < autoScrollMargin) || (area.right() - pos.x() < autoScrollMargin); | 0 | ||||||||||||||||||||||||
| 4169 | || (area.right() - pos.x() < autoScrollMargin); never executed: return (pos.y() - area.top() < autoScrollMargin) || (area.bottom() - pos.y() < autoScrollMargin) || (pos.x() - area.left() < autoScrollMargin) || (area.right() - pos.x() < autoScrollMargin); | 0 | ||||||||||||||||||||||||
| 4170 | } | - | ||||||||||||||||||||||||
| 4171 | - | |||||||||||||||||||||||||
| 4172 | void QAbstractItemViewPrivate::doDelayedItemsLayout(int delay) | - | ||||||||||||||||||||||||
| 4173 | { | - | ||||||||||||||||||||||||
| 4174 | if (!delayedPendingLayout) {
| 0 | ||||||||||||||||||||||||
| 4175 | delayedPendingLayout = true; | - | ||||||||||||||||||||||||
| 4176 | delayedLayout.start(delay, q_func()); | - | ||||||||||||||||||||||||
| 4177 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4178 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4179 | - | |||||||||||||||||||||||||
| 4180 | void QAbstractItemViewPrivate::interruptDelayedItemsLayout() const | - | ||||||||||||||||||||||||
| 4181 | { | - | ||||||||||||||||||||||||
| 4182 | delayedLayout.stop(); | - | ||||||||||||||||||||||||
| 4183 | delayedPendingLayout = false; | - | ||||||||||||||||||||||||
| 4184 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4185 | - | |||||||||||||||||||||||||
| 4186 | void QAbstractItemViewPrivate::updateGeometry() | - | ||||||||||||||||||||||||
| 4187 | { | - | ||||||||||||||||||||||||
| 4188 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 4189 | if (sizeAdjustPolicy == QAbstractScrollArea::AdjustIgnored)
| 0 | ||||||||||||||||||||||||
| 4190 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 4191 | if (sizeAdjustPolicy == QAbstractScrollArea::AdjustToContents || !shownOnce)
| 0 | ||||||||||||||||||||||||
| 4192 | q->updateGeometry(); never executed: q->updateGeometry(); | 0 | ||||||||||||||||||||||||
| 4193 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4194 | - | |||||||||||||||||||||||||
| 4195 | QWidget *QAbstractItemViewPrivate::editor(const QModelIndex &index, | - | ||||||||||||||||||||||||
| 4196 | const QStyleOptionViewItem &options) | - | ||||||||||||||||||||||||
| 4197 | { | - | ||||||||||||||||||||||||
| 4198 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 4199 | QWidget *w = editorForIndex(index).widget.data(); | - | ||||||||||||||||||||||||
| 4200 | if (!w) {
| 0 | ||||||||||||||||||||||||
| 4201 | QAbstractItemDelegate *delegate = delegateForIndex(index); | - | ||||||||||||||||||||||||
| 4202 | if (!delegate)
| 0 | ||||||||||||||||||||||||
| 4203 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 4204 | w = delegate->createEditor(viewport, options, index); | - | ||||||||||||||||||||||||
| 4205 | if (w) {
| 0 | ||||||||||||||||||||||||
| 4206 | w->installEventFilter(delegate); | - | ||||||||||||||||||||||||
| 4207 | QObject::connect(w, SIGNAL(destroyed(QObject*)), q, SLOT(editorDestroyed(QObject*))); | - | ||||||||||||||||||||||||
| 4208 | delegate->updateEditorGeometry(w, options, index); | - | ||||||||||||||||||||||||
| 4209 | delegate->setEditorData(w, index); | - | ||||||||||||||||||||||||
| 4210 | addEditor(index, w, false); | - | ||||||||||||||||||||||||
| 4211 | if (w->parent() == viewport)
| 0 | ||||||||||||||||||||||||
| 4212 | QWidget::setTabOrder(q, w); never executed: QWidget::setTabOrder(q, w); | 0 | ||||||||||||||||||||||||
| 4213 | - | |||||||||||||||||||||||||
| 4214 | // Special cases for some editors containing QLineEdit | - | ||||||||||||||||||||||||
| 4215 | QWidget *focusWidget = w; | - | ||||||||||||||||||||||||
| 4216 | while (QWidget *fp = focusWidget->focusProxy())
| 0 | ||||||||||||||||||||||||
| 4217 | focusWidget = fp; never executed: focusWidget = fp; | 0 | ||||||||||||||||||||||||
| 4218 | #ifndef QT_NO_LINEEDIT | - | ||||||||||||||||||||||||
| 4219 | if (QLineEdit *le = qobject_cast<QLineEdit*>(focusWidget))
| 0 | ||||||||||||||||||||||||
| 4220 | le->selectAll(); never executed: le->selectAll(); | 0 | ||||||||||||||||||||||||
| 4221 | #endif | - | ||||||||||||||||||||||||
| 4222 | #ifndef QT_NO_SPINBOX | - | ||||||||||||||||||||||||
| 4223 | if (QSpinBox *sb = qobject_cast<QSpinBox*>(focusWidget))
| 0 | ||||||||||||||||||||||||
| 4224 | sb->selectAll(); never executed: sb->selectAll(); | 0 | ||||||||||||||||||||||||
| 4225 | else if (QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox*>(focusWidget))
| 0 | ||||||||||||||||||||||||
| 4226 | dsb->selectAll(); never executed: dsb->selectAll(); | 0 | ||||||||||||||||||||||||
| 4227 | #endif | - | ||||||||||||||||||||||||
| 4228 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4229 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4230 | - | |||||||||||||||||||||||||
| 4231 | return w; never executed: return w; | 0 | ||||||||||||||||||||||||
| 4232 | } | - | ||||||||||||||||||||||||
| 4233 | - | |||||||||||||||||||||||||
| 4234 | void QAbstractItemViewPrivate::updateEditorData(const QModelIndex &tl, const QModelIndex &br) | - | ||||||||||||||||||||||||
| 4235 | { | - | ||||||||||||||||||||||||
| 4236 | // we are counting on having relatively few editors | - | ||||||||||||||||||||||||
| 4237 | const bool checkIndexes = tl.isValid() && br.isValid();
| 0 | ||||||||||||||||||||||||
| 4238 | const QModelIndex parent = tl.parent(); | - | ||||||||||||||||||||||||
| 4239 | // QTBUG-25370: We need to copy the indexEditorHash, because while we're | - | ||||||||||||||||||||||||
| 4240 | // iterating over it, we are calling methods which can allow user code to | - | ||||||||||||||||||||||||
| 4241 | // call a method on *this which can modify the member indexEditorHash. | - | ||||||||||||||||||||||||
| 4242 | const QIndexEditorHash indexEditorHashCopy = indexEditorHash; | - | ||||||||||||||||||||||||
| 4243 | QIndexEditorHash::const_iterator it = indexEditorHashCopy.constBegin(); | - | ||||||||||||||||||||||||
| 4244 | for (; it != indexEditorHashCopy.constEnd(); ++it) {
| 0 | ||||||||||||||||||||||||
| 4245 | QWidget *editor = it.value().widget.data(); | - | ||||||||||||||||||||||||
| 4246 | const QModelIndex index = it.key(); | - | ||||||||||||||||||||||||
| 4247 | if (it.value().isStatic || !editor || !index.isValid() ||
| 0 | ||||||||||||||||||||||||
| 4248 | (checkIndexes
| 0 | ||||||||||||||||||||||||
| 4249 | && (index.row() < tl.row() || index.row() > br.row()
| 0 | ||||||||||||||||||||||||
| 4250 | || index.column() < tl.column() || index.column() > br.column()
| 0 | ||||||||||||||||||||||||
| 4251 | || index.parent() != parent)))
| 0 | ||||||||||||||||||||||||
| 4252 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 4253 | - | |||||||||||||||||||||||||
| 4254 | QAbstractItemDelegate *delegate = delegateForIndex(index); | - | ||||||||||||||||||||||||
| 4255 | if (delegate) {
| 0 | ||||||||||||||||||||||||
| 4256 | delegate->setEditorData(editor, index); | - | ||||||||||||||||||||||||
| 4257 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4258 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4259 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4260 | - | |||||||||||||||||||||||||
| 4261 | /*! | - | ||||||||||||||||||||||||
| 4262 | \internal | - | ||||||||||||||||||||||||
| 4263 | - | |||||||||||||||||||||||||
| 4264 | In DND if something has been moved then this is called. | - | ||||||||||||||||||||||||
| 4265 | Typically this means you should "remove" the selected item or row, | - | ||||||||||||||||||||||||
| 4266 | but the behavior is view dependant (table just clears the selected indexes for example). | - | ||||||||||||||||||||||||
| 4267 | - | |||||||||||||||||||||||||
| 4268 | Either remove the selected rows or clear them | - | ||||||||||||||||||||||||
| 4269 | */ | - | ||||||||||||||||||||||||
| 4270 | void QAbstractItemViewPrivate::clearOrRemove() | - | ||||||||||||||||||||||||
| 4271 | { | - | ||||||||||||||||||||||||
| 4272 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
| 4273 | const QItemSelection selection = selectionModel->selection(); | - | ||||||||||||||||||||||||
| 4274 | QList<QItemSelectionRange>::const_iterator it = selection.constBegin(); | - | ||||||||||||||||||||||||
| 4275 | - | |||||||||||||||||||||||||
| 4276 | if (!overwrite) {
| 0 | ||||||||||||||||||||||||
| 4277 | for (; it != selection.constEnd(); ++it) {
| 0 | ||||||||||||||||||||||||
| 4278 | QModelIndex parent = (*it).parent(); | - | ||||||||||||||||||||||||
| 4279 | if ((*it).left() != 0)
| 0 | ||||||||||||||||||||||||
| 4280 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 4281 | if ((*it).right() != (model->columnCount(parent) - 1))
| 0 | ||||||||||||||||||||||||
| 4282 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 4283 | int count = (*it).bottom() - (*it).top() + 1; | - | ||||||||||||||||||||||||
| 4284 | model->removeRows((*it).top(), count, parent); | - | ||||||||||||||||||||||||
| 4285 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4286 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 4287 | // we can't remove the rows so reset the items (i.e. the view is like a table) | - | ||||||||||||||||||||||||
| 4288 | QModelIndexList list = selection.indexes(); | - | ||||||||||||||||||||||||
| 4289 | for (int i=0; i < list.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 4290 | QModelIndex index = list.at(i); | - | ||||||||||||||||||||||||
| 4291 | QMap<int, QVariant> roles = model->itemData(index); | - | ||||||||||||||||||||||||
| 4292 | for (QMap<int, QVariant>::Iterator it = roles.begin(); it != roles.end(); ++it)
| 0 | ||||||||||||||||||||||||
| 4293 | it.value() = QVariant(); never executed: it.value() = QVariant(); | 0 | ||||||||||||||||||||||||
| 4294 | model->setItemData(index, roles); | - | ||||||||||||||||||||||||
| 4295 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4296 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4297 | #endif | - | ||||||||||||||||||||||||
| 4298 | } | - | ||||||||||||||||||||||||
| 4299 | - | |||||||||||||||||||||||||
| 4300 | /*! | - | ||||||||||||||||||||||||
| 4301 | \internal | - | ||||||||||||||||||||||||
| 4302 | - | |||||||||||||||||||||||||
| 4303 | When persistent aeditor gets/loses focus, we need to check | - | ||||||||||||||||||||||||
| 4304 | and setcorrectly the current index. | - | ||||||||||||||||||||||||
| 4305 | */ | - | ||||||||||||||||||||||||
| 4306 | void QAbstractItemViewPrivate::checkPersistentEditorFocus() | - | ||||||||||||||||||||||||
| 4307 | { | - | ||||||||||||||||||||||||
| 4308 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 4309 | if (QWidget *widget = QApplication::focusWidget()) {
| 0 | ||||||||||||||||||||||||
| 4310 | if (persistent.contains(widget)) {
| 0 | ||||||||||||||||||||||||
| 4311 | //a persistent editor has gained the focus | - | ||||||||||||||||||||||||
| 4312 | QModelIndex index = indexForEditor(widget); | - | ||||||||||||||||||||||||
| 4313 | if (selectionModel->currentIndex() != index)
| 0 | ||||||||||||||||||||||||
| 4314 | q->setCurrentIndex(index); never executed: q->setCurrentIndex(index); | 0 | ||||||||||||||||||||||||
| 4315 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4316 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4317 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4318 | - | |||||||||||||||||||||||||
| 4319 | - | |||||||||||||||||||||||||
| 4320 | const QEditorInfo & QAbstractItemViewPrivate::editorForIndex(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 4321 | { | - | ||||||||||||||||||||||||
| 4322 | static QEditorInfo nullInfo; | - | ||||||||||||||||||||||||
| 4323 | - | |||||||||||||||||||||||||
| 4324 | // do not try to search to avoid slow implicit cast from QModelIndex to QPersistentModelIndex | - | ||||||||||||||||||||||||
| 4325 | if (indexEditorHash.isEmpty())
| 0 | ||||||||||||||||||||||||
| 4326 | return nullInfo; never executed: return nullInfo; | 0 | ||||||||||||||||||||||||
| 4327 | - | |||||||||||||||||||||||||
| 4328 | QIndexEditorHash::const_iterator it = indexEditorHash.find(index); | - | ||||||||||||||||||||||||
| 4329 | if (it == indexEditorHash.end())
| 0 | ||||||||||||||||||||||||
| 4330 | return nullInfo; never executed: return nullInfo; | 0 | ||||||||||||||||||||||||
| 4331 | - | |||||||||||||||||||||||||
| 4332 | return it.value(); never executed: return it.value(); | 0 | ||||||||||||||||||||||||
| 4333 | } | - | ||||||||||||||||||||||||
| 4334 | - | |||||||||||||||||||||||||
| 4335 | bool QAbstractItemViewPrivate::hasEditor(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 4336 | { | - | ||||||||||||||||||||||||
| 4337 | // Search's implicit cast (QModelIndex to QPersistentModelIndex) is slow; use cheap pre-test to avoid when we can. | - | ||||||||||||||||||||||||
| 4338 | return !indexEditorHash.isEmpty() && indexEditorHash.contains(index); never executed: return !indexEditorHash.isEmpty() && indexEditorHash.contains(index); | 0 | ||||||||||||||||||||||||
| 4339 | } | - | ||||||||||||||||||||||||
| 4340 | - | |||||||||||||||||||||||||
| 4341 | QModelIndex QAbstractItemViewPrivate::indexForEditor(QWidget *editor) const | - | ||||||||||||||||||||||||
| 4342 | { | - | ||||||||||||||||||||||||
| 4343 | // do not try to search to avoid slow implicit cast from QModelIndex to QPersistentModelIndex | - | ||||||||||||||||||||||||
| 4344 | if (indexEditorHash.isEmpty())
| 0 | ||||||||||||||||||||||||
| 4345 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 4346 | - | |||||||||||||||||||||||||
| 4347 | QEditorIndexHash::const_iterator it = editorIndexHash.find(editor); | - | ||||||||||||||||||||||||
| 4348 | if (it == editorIndexHash.end())
| 0 | ||||||||||||||||||||||||
| 4349 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 4350 | - | |||||||||||||||||||||||||
| 4351 | return it.value(); never executed: return it.value(); | 0 | ||||||||||||||||||||||||
| 4352 | } | - | ||||||||||||||||||||||||
| 4353 | - | |||||||||||||||||||||||||
| 4354 | void QAbstractItemViewPrivate::removeEditor(QWidget *editor) | - | ||||||||||||||||||||||||
| 4355 | { | - | ||||||||||||||||||||||||
| 4356 | const auto it = editorIndexHash.constFind(editor); | - | ||||||||||||||||||||||||
| 4357 | if (it != editorIndexHash.cend()) {
| 0 | ||||||||||||||||||||||||
| 4358 | indexEditorHash.remove(it.value()); | - | ||||||||||||||||||||||||
| 4359 | editorIndexHash.erase(it); | - | ||||||||||||||||||||||||
| 4360 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4361 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4362 | - | |||||||||||||||||||||||||
| 4363 | void QAbstractItemViewPrivate::addEditor(const QModelIndex &index, QWidget *editor, bool isStatic) | - | ||||||||||||||||||||||||
| 4364 | { | - | ||||||||||||||||||||||||
| 4365 | editorIndexHash.insert(editor, index); | - | ||||||||||||||||||||||||
| 4366 | indexEditorHash.insert(index, QEditorInfo(editor, isStatic)); | - | ||||||||||||||||||||||||
| 4367 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4368 | - | |||||||||||||||||||||||||
| 4369 | bool QAbstractItemViewPrivate::sendDelegateEvent(const QModelIndex &index, QEvent *event) const | - | ||||||||||||||||||||||||
| 4370 | { | - | ||||||||||||||||||||||||
| 4371 | Q_Q(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 4372 | QModelIndex buddy = model->buddy(index); | - | ||||||||||||||||||||||||
| 4373 | QStyleOptionViewItem options = viewOptionsV1(); | - | ||||||||||||||||||||||||
| 4374 | options.rect = q->visualRect(buddy); | - | ||||||||||||||||||||||||
| 4375 | options.state |= (buddy == q->currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
| 0 | ||||||||||||||||||||||||
| 4376 | QAbstractItemDelegate *delegate = delegateForIndex(index); | - | ||||||||||||||||||||||||
| 4377 | return (event && delegate && delegate->editorEvent(event, model, options, buddy)); never executed: return (event && delegate && delegate->editorEvent(event, model, options, buddy)); | 0 | ||||||||||||||||||||||||
| 4378 | } | - | ||||||||||||||||||||||||
| 4379 | - | |||||||||||||||||||||||||
| 4380 | bool QAbstractItemViewPrivate::openEditor(const QModelIndex &index, QEvent *event) | - | ||||||||||||||||||||||||
| 4381 | { | - | ||||||||||||||||||||||||
| 4382 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||||||||
| 4383 | - | |||||||||||||||||||||||||
| 4384 | QModelIndex buddy = model->buddy(index); | - | ||||||||||||||||||||||||
| 4385 | QStyleOptionViewItem options = viewOptionsV1(); | - | ||||||||||||||||||||||||
| 4386 | options.rect = q->visualRect(buddy); | - | ||||||||||||||||||||||||
| 4387 | options.state |= (buddy == q->currentIndex() ? QStyle::State_HasFocus : QStyle::State_None);
| 0 | ||||||||||||||||||||||||
| 4388 | - | |||||||||||||||||||||||||
| 4389 | QWidget *w = editor(buddy, options); | - | ||||||||||||||||||||||||
| 4390 | if (!w)
| 0 | ||||||||||||||||||||||||
| 4391 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 4392 | - | |||||||||||||||||||||||||
| 4393 | q->setState(QAbstractItemView::EditingState); | - | ||||||||||||||||||||||||
| 4394 | w->show(); | - | ||||||||||||||||||||||||
| 4395 | w->setFocus(); | - | ||||||||||||||||||||||||
| 4396 | - | |||||||||||||||||||||||||
| 4397 | if (event)
| 0 | ||||||||||||||||||||||||
| 4398 | QApplication::sendEvent(w->focusProxy() ? w->focusProxy() : w, event); never executed: QApplication::sendEvent(w->focusProxy() ? w->focusProxy() : w, event); | 0 | ||||||||||||||||||||||||
| 4399 | - | |||||||||||||||||||||||||
| 4400 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 4401 | } | - | ||||||||||||||||||||||||
| 4402 | - | |||||||||||||||||||||||||
| 4403 | /* | - | ||||||||||||||||||||||||
| 4404 | \internal | - | ||||||||||||||||||||||||
| 4405 | - | |||||||||||||||||||||||||
| 4406 | returns the pair QRect/QModelIndex that should be painted on the viewports's rect | - | ||||||||||||||||||||||||
| 4407 | */ | - | ||||||||||||||||||||||||
| 4408 | - | |||||||||||||||||||||||||
| 4409 | QItemViewPaintPairs QAbstractItemViewPrivate::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const | - | ||||||||||||||||||||||||
| 4410 | { | - | ||||||||||||||||||||||||
| 4411 | Q_ASSERT(r); | - | ||||||||||||||||||||||||
| 4412 | Q_Q(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 4413 | QRect &rect = *r; | - | ||||||||||||||||||||||||
| 4414 | const QRect viewportRect = viewport->rect(); | - | ||||||||||||||||||||||||
| 4415 | QItemViewPaintPairs ret; | - | ||||||||||||||||||||||||
| 4416 | for (const auto &index : indexes) { | - | ||||||||||||||||||||||||
| 4417 | const QRect current = q->visualRect(index); | - | ||||||||||||||||||||||||
| 4418 | if (current.intersects(viewportRect)) {
| 0 | ||||||||||||||||||||||||
| 4419 | QItemViewPaintPair p = { current, index }; | - | ||||||||||||||||||||||||
| 4420 | ret += p; | - | ||||||||||||||||||||||||
| 4421 | rect |= current; | - | ||||||||||||||||||||||||
| 4422 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4423 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4424 | rect &= viewportRect; | - | ||||||||||||||||||||||||
| 4425 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
| 4426 | } | - | ||||||||||||||||||||||||
| 4427 | - | |||||||||||||||||||||||||
| 4428 | QPixmap QAbstractItemViewPrivate::renderToPixmap(const QModelIndexList &indexes, QRect *r) const | - | ||||||||||||||||||||||||
| 4429 | { | - | ||||||||||||||||||||||||
| 4430 | Q_ASSERT(r); | - | ||||||||||||||||||||||||
| 4431 | QItemViewPaintPairs paintPairs = draggablePaintPairs(indexes, r); | - | ||||||||||||||||||||||||
| 4432 | if (paintPairs.isEmpty())
| 0 | ||||||||||||||||||||||||
| 4433 | return QPixmap(); never executed: return QPixmap(); | 0 | ||||||||||||||||||||||||
| 4434 | - | |||||||||||||||||||||||||
| 4435 | qreal scale = 1.0f; | - | ||||||||||||||||||||||||
| 4436 | - | |||||||||||||||||||||||||
| 4437 | Q_Q(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 4438 | QWidget *window = q->window(); | - | ||||||||||||||||||||||||
| 4439 | if (window) {
| 0 | ||||||||||||||||||||||||
| 4440 | QWindow *windowHandle = window->windowHandle(); | - | ||||||||||||||||||||||||
| 4441 | if (windowHandle)
| 0 | ||||||||||||||||||||||||
| 4442 | scale = windowHandle->devicePixelRatio(); never executed: scale = windowHandle->devicePixelRatio(); | 0 | ||||||||||||||||||||||||
| 4443 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4444 | - | |||||||||||||||||||||||||
| 4445 | QPixmap pixmap(r->size() * scale); | - | ||||||||||||||||||||||||
| 4446 | pixmap.setDevicePixelRatio(scale); | - | ||||||||||||||||||||||||
| 4447 | - | |||||||||||||||||||||||||
| 4448 | pixmap.fill(Qt::transparent); | - | ||||||||||||||||||||||||
| 4449 | QPainter painter(&pixmap); | - | ||||||||||||||||||||||||
| 4450 | QStyleOptionViewItem option = viewOptionsV1(); | - | ||||||||||||||||||||||||
| 4451 | option.state |= QStyle::State_Selected; | - | ||||||||||||||||||||||||
| 4452 | for (int j = 0; j < paintPairs.count(); ++j) {
| 0 | ||||||||||||||||||||||||
| 4453 | option.rect = paintPairs.at(j).rect.translated(-r->topLeft()); | - | ||||||||||||||||||||||||
| 4454 | const QModelIndex ¤t = paintPairs.at(j).index; | - | ||||||||||||||||||||||||
| 4455 | adjustViewOptionsForIndex(&option, current); | - | ||||||||||||||||||||||||
| 4456 | delegateForIndex(current)->paint(&painter, option, current); | - | ||||||||||||||||||||||||
| 4457 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4458 | return pixmap; never executed: return pixmap; | 0 | ||||||||||||||||||||||||
| 4459 | } | - | ||||||||||||||||||||||||
| 4460 | - | |||||||||||||||||||||||||
| 4461 | void QAbstractItemViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command) | - | ||||||||||||||||||||||||
| 4462 | { | - | ||||||||||||||||||||||||
| 4463 | if (!selectionModel)
| 0 | ||||||||||||||||||||||||
| 4464 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 4465 | - | |||||||||||||||||||||||||
| 4466 | QItemSelection selection; | - | ||||||||||||||||||||||||
| 4467 | QModelIndex tl = model->index(0, 0, root); | - | ||||||||||||||||||||||||
| 4468 | QModelIndex br = model->index(model->rowCount(root) - 1, | - | ||||||||||||||||||||||||
| 4469 | model->columnCount(root) - 1, | - | ||||||||||||||||||||||||
| 4470 | root); | - | ||||||||||||||||||||||||
| 4471 | selection.append(QItemSelectionRange(tl, br)); | - | ||||||||||||||||||||||||
| 4472 | selectionModel->select(selection, command); | - | ||||||||||||||||||||||||
| 4473 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 4474 | - | |||||||||||||||||||||||||
| 4475 | QModelIndexList QAbstractItemViewPrivate::selectedDraggableIndexes() const | - | ||||||||||||||||||||||||
| 4476 | { | - | ||||||||||||||||||||||||
| 4477 | Q_Q(const QAbstractItemView); | - | ||||||||||||||||||||||||
| 4478 | QModelIndexList indexes = q->selectedIndexes(); | - | ||||||||||||||||||||||||
| 4479 | auto isNotDragEnabled = [this](const QModelIndex &index) { | - | ||||||||||||||||||||||||
| 4480 | return !isIndexDragEnabled(index); never executed: return !isIndexDragEnabled(index); | 0 | ||||||||||||||||||||||||
| 4481 | }; | - | ||||||||||||||||||||||||
| 4482 | indexes.erase(std::remove_if(indexes.begin(), indexes.end(), | - | ||||||||||||||||||||||||
| 4483 | isNotDragEnabled), | - | ||||||||||||||||||||||||
| 4484 | indexes.end()); | - | ||||||||||||||||||||||||
| 4485 | return indexes; never executed: return indexes; | 0 | ||||||||||||||||||||||||
| 4486 | } | - | ||||||||||||||||||||||||
| 4487 | - | |||||||||||||||||||||||||
| 4488 | - | |||||||||||||||||||||||||
| 4489 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 4490 | - | |||||||||||||||||||||||||
| 4491 | #include "moc_qabstractitemview.cpp" | - | ||||||||||||||||||||||||
| 4492 | - | |||||||||||||||||||||||||
| 4493 | #endif // QT_NO_ITEMVIEWS | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |