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) | - | ||||||||||||||||||
153 | return; | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | if (selectionBehavior != QAbstractItemView::SelectRows) { | - | ||||||||||||||||||
156 | q->update(hover); //update the old one | - | ||||||||||||||||||
157 | q->update(index); //update the new one | - | ||||||||||||||||||
158 | } else { | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
164 | hover = index; | - | ||||||||||||||||||
165 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
173 | viewportEnteredNeeded = false; | - | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | if (index.isValid()) { | - | ||||||||||||||||||
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())) { | - | ||||||||||||||||||
180 | QStatusTipEvent tip(statustip); | - | ||||||||||||||||||
181 | QApplication::sendEvent(parent, &tip); | - | ||||||||||||||||||
182 | shouldClearStatusTip = !statustip.isEmpty(); | - | ||||||||||||||||||
183 | } | - | ||||||||||||||||||
184 | #endif | - | ||||||||||||||||||
185 | } else { | - | ||||||||||||||||||
186 | #ifndef QT_NO_STATUSTIP | - | ||||||||||||||||||
187 | if (parent && shouldClearStatusTip) { | - | ||||||||||||||||||
188 | QString emptyString; | - | ||||||||||||||||||
189 | QStatusTipEvent tip( emptyString ); | - | ||||||||||||||||||
190 | QApplication::sendEvent(parent, &tip); | - | ||||||||||||||||||
191 | } | - | ||||||||||||||||||
192 | #endif | - | ||||||||||||||||||
193 | emit q->viewportEntered(); | - | ||||||||||||||||||
194 | } | - | ||||||||||||||||||
195 | enteredIndex = index; | - | ||||||||||||||||||
196 | } | - | ||||||||||||||||||
197 | } | - | ||||||||||||||||||
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)) { | - | ||||||||||||||||||
207 | switch (scroller->state()) { | - | ||||||||||||||||||
208 | case QScroller::Pressed: | - | ||||||||||||||||||
209 | // store the current selection in case we start scrolling | - | ||||||||||||||||||
210 | if (q->selectionModel()) { | - | ||||||||||||||||||
211 | oldSelection = q->selectionModel()->selection(); | - | ||||||||||||||||||
212 | oldCurrent = q->selectionModel()->currentIndex(); | - | ||||||||||||||||||
213 | } | - | ||||||||||||||||||
214 | break; | - | ||||||||||||||||||
215 | - | |||||||||||||||||||
216 | case QScroller::Dragging: | - | ||||||||||||||||||
217 | // restore the old selection if we really start scrolling | - | ||||||||||||||||||
218 | if (q->selectionModel()) { | - | ||||||||||||||||||
219 | q->selectionModel()->select(oldSelection, QItemSelectionModel::ClearAndSelect); | - | ||||||||||||||||||
220 | q->selectionModel()->setCurrentIndex(oldCurrent, QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||
221 | } | - | ||||||||||||||||||
222 | // fall through | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | default: | - | ||||||||||||||||||
225 | oldSelection = QItemSelection(); | - | ||||||||||||||||||
226 | oldCurrent = QModelIndex(); | - | ||||||||||||||||||
227 | break; | - | ||||||||||||||||||
228 | } | - | ||||||||||||||||||
229 | } | - | ||||||||||||||||||
230 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
623 | - | |||||||||||||||||||
624 | /*! | - | ||||||||||||||||||
625 | \internal | - | ||||||||||||||||||
626 | */ | - | ||||||||||||||||||
627 | QAbstractItemView::QAbstractItemView(QAbstractItemViewPrivate &dd, QWidget *parent) | - | ||||||||||||||||||
628 | : QAbstractScrollArea(dd, parent) | - | ||||||||||||||||||
629 | { | - | ||||||||||||||||||
630 | d_func()->init(); | - | ||||||||||||||||||
631 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
673 | return; | - | ||||||||||||||||||
674 | if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) { | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
703 | d->model = (model ? model : QAbstractItemModelPrivate::staticEmptyModel()); | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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); | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
845 | return; | - | ||||||||||||||||||
846 | - | |||||||||||||||||||
847 | if (d->itemDelegate) { | - | ||||||||||||||||||
848 | if (d->delegateRefCount(d->itemDelegate) == 1) { | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
854 | } | - | ||||||||||||||||||
855 | - | |||||||||||||||||||
856 | if (delegate) { | - | ||||||||||||||||||
857 | if (d->delegateRefCount(delegate) == 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 | } | - | ||||||||||||||||||
863 | } | - | ||||||||||||||||||
864 | d->itemDelegate = delegate; | - | ||||||||||||||||||
865 | viewport()->update(); | - | ||||||||||||||||||
866 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||
867 | } | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
887 | return QAbstractScrollArea::inputMethodQuery(query); | - | ||||||||||||||||||
888 | return visualRect(current); | - | ||||||||||||||||||
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)) { | - | ||||||||||||||||||
916 | if (d->delegateRefCount(rowDelegate) == 1) { | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
922 | d->rowDelegates.remove(row); | - | ||||||||||||||||||
923 | } | - | ||||||||||||||||||
924 | if (delegate) { | - | ||||||||||||||||||
925 | if (d->delegateRefCount(delegate) == 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 | } | - | ||||||||||||||||||
931 | d->rowDelegates.insert(row, delegate); | - | ||||||||||||||||||
932 | } | - | ||||||||||||||||||
933 | viewport()->update(); | - | ||||||||||||||||||
934 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||
935 | } | - | ||||||||||||||||||
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); | - | ||||||||||||||||||
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)) { | - | ||||||||||||||||||
976 | if (d->delegateRefCount(columnDelegate) == 1) { | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
982 | d->columnDelegates.remove(column); | - | ||||||||||||||||||
983 | } | - | ||||||||||||||||||
984 | if (delegate) { | - | ||||||||||||||||||
985 | if (d->delegateRefCount(delegate) == 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 | } | - | ||||||||||||||||||
991 | d->columnDelegates.insert(column, delegate); | - | ||||||||||||||||||
992 | } | - | ||||||||||||||||||
993 | viewport()->update(); | - | ||||||||||||||||||
994 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||
995 | } | - | ||||||||||||||||||
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); | - | ||||||||||||||||||
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); | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1037 | - | |||||||||||||||||||
1038 | QAbstractItemView::SelectionMode QAbstractItemView::selectionMode() const | - | ||||||||||||||||||
1039 | { | - | ||||||||||||||||||
1040 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1041 | return d->selectionMode; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1059 | - | |||||||||||||||||||
1060 | QAbstractItemView::SelectionBehavior QAbstractItemView::selectionBehavior() const | - | ||||||||||||||||||
1061 | { | - | ||||||||||||||||||
1062 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1063 | return d->selectionBehavior; | - | ||||||||||||||||||
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))) { | - | ||||||||||||||||||
1084 | QItemSelectionModel::SelectionFlags command = selectionCommand(index, 0); | - | ||||||||||||||||||
1085 | d->selectionModel->setCurrentIndex(index, command); | - | ||||||||||||||||||
1086 | d->currentIndexSet = true; | - | ||||||||||||||||||
1087 | if ((command & QItemSelectionModel::Current) == 0) | - | ||||||||||||||||||
1088 | d->currentSelectionStartIndex = index; | - | ||||||||||||||||||
1089 | } | - | ||||||||||||||||||
1090 | } | - | ||||||||||||||||||
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(); | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
1119 | d->releaseEditor(info.widget.data(), d->indexForEditor(info.widget.data())); | - | ||||||||||||||||||
1120 | } | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
1128 | d->selectionModel->reset(); | - | ||||||||||||||||||
1129 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
1130 | if (QAccessible::isActive()) { | - | ||||||||||||||||||
1131 | QAccessibleTableModelChangeEvent accessibleEvent(this, QAccessibleTableModelChangeEvent::ModelReset); | - | ||||||||||||||||||
1132 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||
1133 | } | - | ||||||||||||||||||
1134 | #endif | - | ||||||||||||||||||
1135 | d->updateGeometry(); | - | ||||||||||||||||||
1136 | } | - | ||||||||||||||||||
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); | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
1178 | d->selectAll(QItemSelectionModel::ClearAndSelect | - | ||||||||||||||||||
1179 | |d->selectionBehaviorFlags()); | - | ||||||||||||||||||
1180 | else if (mode != SingleSelection) | - | ||||||||||||||||||
1181 | d->selectAll(selectionCommand(d->model->index(0, 0, d->root))); | - | ||||||||||||||||||
1182 | } | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
1214 | d->selectionModel->clearSelection(); | - | ||||||||||||||||||
1215 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1245 | - | |||||||||||||||||||
1246 | QAbstractItemView::EditTriggers QAbstractItemView::editTriggers() const | - | ||||||||||||||||||
1247 | { | - | ||||||||||||||||||
1248 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1249 | return d->editTriggers; | - | ||||||||||||||||||
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); never executed: // setSingleStep(-1) => step with 1verticalScrollBar()->d_func()->itemviewChangeSingleStep(1); never executed: verticalScrollBar()->d_func()->itemviewChangeSingleStep(1); | 0 | ||||||||||||||||||
1272 | else | - | ||||||||||||||||||
1273 | verticalScrollBar()->setSingleStep(-1); never executed: // Ensure that the view can update single stepverticalScrollBar()->setSingleStep(-1); 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; | - | ||||||||||||||||||
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); never executed: // setSingleStep(-1) => step with 1horizontalScrollBar()->d_func()->itemviewChangeSingleStep(1); never executed: horizontalScrollBar()->d_func()->itemviewChangeSingleStep(1); | 0 | ||||||||||||||||||
1310 | else | - | ||||||||||||||||||
1311 | horizontalScrollBar()->setSingleStep(-1); never executed: // Ensure that the view can update single stephorizontalScrollBar()->setSingleStep(-1); 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; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1355 | - | |||||||||||||||||||
1356 | bool QAbstractItemView::dragDropOverwriteMode() const | - | ||||||||||||||||||
1357 | { | - | ||||||||||||||||||
1358 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1359 | return d->overwrite; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1382 | - | |||||||||||||||||||
1383 | bool QAbstractItemView::hasAutoScroll() const | - | ||||||||||||||||||
1384 | { | - | ||||||||||||||||||
1385 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1386 | return d->autoScroll; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1402 | - | |||||||||||||||||||
1403 | int QAbstractItemView::autoScrollMargin() const | - | ||||||||||||||||||
1404 | { | - | ||||||||||||||||||
1405 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1406 | return d->autoScrollMargin; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1419 | - | |||||||||||||||||||
1420 | bool QAbstractItemView::tabKeyNavigation() const | - | ||||||||||||||||||
1421 | { | - | ||||||||||||||||||
1422 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1423 | return d->tabKeyNavigation; | - | ||||||||||||||||||
1424 | } | - | ||||||||||||||||||
1425 | - | |||||||||||||||||||
1426 | /*! | - | ||||||||||||||||||
1427 | \since 5.2 | - | ||||||||||||||||||
1428 | \reimp | - | ||||||||||||||||||
1429 | */ | - | ||||||||||||||||||
1430 | QSize QAbstractItemView::viewportSizeHint() const | - | ||||||||||||||||||
1431 | { | - | ||||||||||||||||||
1432 | return QAbstractScrollArea::viewportSizeHint(); | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1448 | - | |||||||||||||||||||
1449 | bool QAbstractItemView::showDropIndicator() const | - | ||||||||||||||||||
1450 | { | - | ||||||||||||||||||
1451 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1452 | return d->showDropIndicator; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1467 | - | |||||||||||||||||||
1468 | bool QAbstractItemView::dragEnabled() const | - | ||||||||||||||||||
1469 | { | - | ||||||||||||||||||
1470 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1471 | return d->dragEnabled; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1508 | - | |||||||||||||||||||
1509 | QAbstractItemView::DragDropMode QAbstractItemView::dragDropMode() const | - | ||||||||||||||||||
1510 | { | - | ||||||||||||||||||
1511 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1512 | DragDropMode setBehavior = d->dragDropMode; | - | ||||||||||||||||||
1513 | if (!dragEnabled() && !acceptDrops()) | - | ||||||||||||||||||
1514 | return NoDragDrop; | - | ||||||||||||||||||
1515 | - | |||||||||||||||||||
1516 | if (dragEnabled() && !acceptDrops()) | - | ||||||||||||||||||
1517 | return DragOnly; | - | ||||||||||||||||||
1518 | - | |||||||||||||||||||
1519 | if (!dragEnabled() && acceptDrops()) | - | ||||||||||||||||||
1520 | return DropOnly; | - | ||||||||||||||||||
1521 | - | |||||||||||||||||||
1522 | if (dragEnabled() && acceptDrops()) { | - | ||||||||||||||||||
1523 | if (setBehavior == InternalMove) | - | ||||||||||||||||||
1524 | return setBehavior; | - | ||||||||||||||||||
1525 | else | - | ||||||||||||||||||
1526 | return DragDrop; | - | ||||||||||||||||||
1527 | } | - | ||||||||||||||||||
1528 | - | |||||||||||||||||||
1529 | return NoDragDrop; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1547 | - | |||||||||||||||||||
1548 | Qt::DropAction QAbstractItemView::defaultDropAction() const | - | ||||||||||||||||||
1549 | { | - | ||||||||||||||||||
1550 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1551 | return d->defaultDropAction; | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
1571 | d->viewport->update(); | - | ||||||||||||||||||
1572 | } | - | ||||||||||||||||||
1573 | - | |||||||||||||||||||
1574 | bool QAbstractItemView::alternatingRowColors() const | - | ||||||||||||||||||
1575 | { | - | ||||||||||||||||||
1576 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1577 | return d->alternatingColors; | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
1591 | return; | - | ||||||||||||||||||
1592 | d->iconSize = size; | - | ||||||||||||||||||
1593 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||
1594 | emit iconSizeChanged(size); | - | ||||||||||||||||||
1595 | } | - | ||||||||||||||||||
1596 | - | |||||||||||||||||||
1597 | QSize QAbstractItemView::iconSize() const | - | ||||||||||||||||||
1598 | { | - | ||||||||||||||||||
1599 | Q_D(const QAbstractItemView); | - | ||||||||||||||||||
1600 | return d->iconSize; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1615 | - | |||||||||||||||||||
1616 | Qt::TextElideMode QAbstractItemView::textElideMode() const | - | ||||||||||||||||||
1617 | { | - | ||||||||||||||||||
1618 | return d_func()->textElideMode; | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
1628 | QKeyEvent event(QEvent::KeyPress, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier); | - | ||||||||||||||||||
1629 | keyPressEvent(&event); | - | ||||||||||||||||||
1630 | if (event.isAccepted()) | - | ||||||||||||||||||
1631 | return true; | - | ||||||||||||||||||
1632 | } | - | ||||||||||||||||||
1633 | return QAbstractScrollArea::focusNextPrevChild(next); | - | ||||||||||||||||||
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(); 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: | - | ||||||||||||||||||
1696 | case QEvent::HoverEnter: | - | ||||||||||||||||||
1697 | d->setHoverIndex(indexAt(static_cast<QHoverEvent*>(event)->pos())); | - | ||||||||||||||||||
1698 | break; | - | ||||||||||||||||||
1699 | case QEvent::HoverLeave: | - | ||||||||||||||||||
1700 | d->setHoverIndex(QModelIndex()); | - | ||||||||||||||||||
1701 | break; | - | ||||||||||||||||||
1702 | case QEvent::Enter: | - | ||||||||||||||||||
1703 | d->viewportEnteredNeeded = true; | - | ||||||||||||||||||
1704 | break; | - | ||||||||||||||||||
1705 | case QEvent::Leave: | - | ||||||||||||||||||
1706 | #ifndef QT_NO_STATUSTIP | - | ||||||||||||||||||
1707 | if (d->shouldClearStatusTip && d->parent) { | - | ||||||||||||||||||
1708 | QString empty; | - | ||||||||||||||||||
1709 | QStatusTipEvent tip(empty); | - | ||||||||||||||||||
1710 | QApplication::sendEvent(d->parent, &tip); | - | ||||||||||||||||||
1711 | d->shouldClearStatusTip = false; | - | ||||||||||||||||||
1712 | } | - | ||||||||||||||||||
1713 | #endif | - | ||||||||||||||||||
1714 | d->enteredIndex = QModelIndex(); | - | ||||||||||||||||||
1715 | break; | - | ||||||||||||||||||
1716 | case QEvent::ToolTip: | - | ||||||||||||||||||
1717 | case QEvent::QueryWhatsThis: | - | ||||||||||||||||||
1718 | case QEvent::WhatsThis: { | - | ||||||||||||||||||
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); | - | ||||||||||||||||||
1724 | - | |||||||||||||||||||
1725 | QAbstractItemDelegate *delegate = d->delegateForIndex(index); | - | ||||||||||||||||||
1726 | if (!delegate) | - | ||||||||||||||||||
1727 | return false; | - | ||||||||||||||||||
1728 | return delegate->helpEvent(he, this, option, index); | - | ||||||||||||||||||
1729 | } | - | ||||||||||||||||||
1730 | case QEvent::FontChange: | - | ||||||||||||||||||
1731 | d->doDelayedItemsLayout(); // the size of the items will change | - | ||||||||||||||||||
1732 | break; | - | ||||||||||||||||||
1733 | case QEvent::WindowActivate: | - | ||||||||||||||||||
1734 | case QEvent::WindowDeactivate: | - | ||||||||||||||||||
1735 | d->viewport->update(); | - | ||||||||||||||||||
1736 | break; | - | ||||||||||||||||||
1737 | case QEvent::ScrollPrepare: | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
1743 | - | |||||||||||||||||||
1744 | default: | - | ||||||||||||||||||
1745 | break; | - | ||||||||||||||||||
1746 | } | - | ||||||||||||||||||
1747 | return QAbstractScrollArea::viewportEvent(event); | - | ||||||||||||||||||
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 | - | ||||||||||||||||||
1763 | || (d->state == EditingState && d->hasEditor(index))) | - | ||||||||||||||||||
1764 | return; | - | ||||||||||||||||||
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(); | - | ||||||||||||||||||
1771 | QPoint offset = d->offset(); | - | ||||||||||||||||||
1772 | if ((command & QItemSelectionModel::Current) == 0) { | - | ||||||||||||||||||
1773 | d->pressedPosition = pos + offset; | - | ||||||||||||||||||
1774 | d->currentSelectionStartIndex = index; | - | ||||||||||||||||||
1775 | } | - | ||||||||||||||||||
1776 | else if (!d->currentSelectionStartIndex.isValid()) | - | ||||||||||||||||||
1777 | d->currentSelectionStartIndex = currentIndex(); | - | ||||||||||||||||||
1778 | - | |||||||||||||||||||
1779 | if (edit(index, NoEditTriggers, event)) | - | ||||||||||||||||||
1780 | return; | - | ||||||||||||||||||
1781 | - | |||||||||||||||||||
1782 | if (index.isValid() && d->isIndexEnabled(index)) { | - | ||||||||||||||||||
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)) { | - | ||||||||||||||||||
1790 | command &= ~QItemSelectionModel::Toggle; | - | ||||||||||||||||||
1791 | d->ctrlDragSelectionFlag = d->selectionModel->isSelected(index) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select; | - | ||||||||||||||||||
1792 | command |= d->ctrlDragSelectionFlag; | - | ||||||||||||||||||
1793 | } | - | ||||||||||||||||||
1794 | - | |||||||||||||||||||
1795 | if ((command & QItemSelectionModel::Current) == 0) { | - | ||||||||||||||||||
1796 | setSelection(QRect(pos, QSize(1, 1)), command); | - | ||||||||||||||||||
1797 | } else { | - | ||||||||||||||||||
1798 | QRect rect(visualRect(d->currentSelectionStartIndex).center(), pos); | - | ||||||||||||||||||
1799 | setSelection(rect, command); | - | ||||||||||||||||||
1800 | } | - | ||||||||||||||||||
1801 | - | |||||||||||||||||||
1802 | // signal handlers may change the model | - | ||||||||||||||||||
1803 | emit pressed(index); | - | ||||||||||||||||||
1804 | if (d->autoScroll) { | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1809 | - | |||||||||||||||||||
1810 | } else { | - | ||||||||||||||||||
1811 | // Forces a finalize() even if mouse is pressed, but not on a item | - | ||||||||||||||||||
1812 | d->selectionModel->select(QModelIndex(), QItemSelectionModel::Select); | - | ||||||||||||||||||
1813 | } | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
1828 | return; | - | ||||||||||||||||||
1829 | - | |||||||||||||||||||
1830 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
1831 | if (state() == DraggingState) { | - | ||||||||||||||||||
1832 | topLeft = d->pressedPosition - d->offset(); | - | ||||||||||||||||||
1833 | if ((topLeft - bottomRight).manhattanLength() > QApplication::startDragDistance()) { | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
1839 | return; | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
1846 | || edit(index, NoEditTriggers, event)) | - | ||||||||||||||||||
1847 | return; | - | ||||||||||||||||||
1848 | - | |||||||||||||||||||
1849 | if (d->selectionMode != SingleSelection) | - | ||||||||||||||||||
1850 | topLeft = d->pressedPosition - d->offset(); | - | ||||||||||||||||||
1851 | else | - | ||||||||||||||||||
1852 | topLeft = bottomRight; | - | ||||||||||||||||||
1853 | - | |||||||||||||||||||
1854 | d->checkMouseMove(index); | - | ||||||||||||||||||
1855 | - | |||||||||||||||||||
1856 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
1857 | if (d->pressedIndex.isValid() | - | ||||||||||||||||||
1858 | && d->dragEnabled | - | ||||||||||||||||||
1859 | && (state() != DragSelectingState) | - | ||||||||||||||||||
1860 | && (event->buttons() != Qt::NoButton) | - | ||||||||||||||||||
1861 | && !d->selectedDraggableIndexes().isEmpty()) { | - | ||||||||||||||||||
1862 | setState(DraggingState); | - | ||||||||||||||||||
1863 | return; | - | ||||||||||||||||||
1864 | } | - | ||||||||||||||||||
1865 | #endif | - | ||||||||||||||||||
1866 | - | |||||||||||||||||||
1867 | if ((event->buttons() & Qt::LeftButton) && d->selectionAllowed(index) && d->selectionModel) { | - | ||||||||||||||||||
1868 | setState(DragSelectingState); | - | ||||||||||||||||||
1869 | QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); | - | ||||||||||||||||||
1870 | if (d->ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate && command.testFlag(QItemSelectionModel::Toggle)) { | - | ||||||||||||||||||
1871 | command &= ~QItemSelectionModel::Toggle; | - | ||||||||||||||||||
1872 | command |= d->ctrlDragSelectionFlag; | - | ||||||||||||||||||
1873 | } | - | ||||||||||||||||||
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() | - | ||||||||||||||||||
1881 | && (index != d->selectionModel->currentIndex()) | - | ||||||||||||||||||
1882 | && d->isIndexEnabled(index)) | - | ||||||||||||||||||
1883 | d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||
1884 | } | - | ||||||||||||||||||
1885 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
1902 | if (d->isIndexValid(index) | - | ||||||||||||||||||
1903 | && d->isIndexEnabled(index) | - | ||||||||||||||||||
1904 | && d->sendDelegateEvent(index, event)) | - | ||||||||||||||||||
1905 | update(index); | - | ||||||||||||||||||
1906 | return; | - | ||||||||||||||||||
1907 | } | - | ||||||||||||||||||
1908 | - | |||||||||||||||||||
1909 | bool click = (index == d->pressedIndex && index.isValid()); | - | ||||||||||||||||||
1910 | bool selectedClicked = click && (event->button() == Qt::LeftButton) && d->pressedAlreadySelected; | - | ||||||||||||||||||
1911 | EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers); | - | ||||||||||||||||||
1912 | bool edited = edit(index, trigger, event); | - | ||||||||||||||||||
1913 | - | |||||||||||||||||||
1914 | d->ctrlDragSelectionFlag = QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
1915 | - | |||||||||||||||||||
1916 | if (d->selectionModel && d->noSelectionOnMousePress) { | - | ||||||||||||||||||
1917 | d->noSelectionOnMousePress = false; | - | ||||||||||||||||||
1918 | d->selectionModel->select(index, selectionCommand(index, event)); | - | ||||||||||||||||||
1919 | } | - | ||||||||||||||||||
1920 | - | |||||||||||||||||||
1921 | setState(NoState); | - | ||||||||||||||||||
1922 | - | |||||||||||||||||||
1923 | if (click) { | - | ||||||||||||||||||
1924 | if (event->button() == Qt::LeftButton) | - | ||||||||||||||||||
1925 | emit clicked(index); | - | ||||||||||||||||||
1926 | if (edited) | - | ||||||||||||||||||
1927 | return; | - | ||||||||||||||||||
1928 | QStyleOptionViewItem option = d->viewOptionsV1(); | - | ||||||||||||||||||
1929 | if (d->pressedAlreadySelected) | - | ||||||||||||||||||
1930 | option.state |= QStyle::State_Selected; | - | ||||||||||||||||||
1931 | if ((model()->flags(index) & Qt::ItemIsEnabled) | - | ||||||||||||||||||
1932 | && style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this)) | - | ||||||||||||||||||
1933 | emit activated(index); | - | ||||||||||||||||||
1934 | } | - | ||||||||||||||||||
1935 | } | - | ||||||||||||||||||
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() | - | ||||||||||||||||||
1948 | || !d->isIndexEnabled(index) | - | ||||||||||||||||||
1949 | || (d->pressedIndex != index)) { | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
1960 | && !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) | - | ||||||||||||||||||
1961 | emit activated(persistent); | - | ||||||||||||||||||
1962 | } | - | ||||||||||||||||||
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 | - | ||||||||||||||||||
1976 | && (event->source() != this|| !(event->possibleActions() & Qt::MoveAction))) | - | ||||||||||||||||||
1977 | return; | - | ||||||||||||||||||
1978 | - | |||||||||||||||||||
1979 | if (d_func()->canDrop(event)) { | - | ||||||||||||||||||
1980 | event->accept(); | - | ||||||||||||||||||
1981 | setState(DraggingState); | - | ||||||||||||||||||
1982 | } else { | - | ||||||||||||||||||
1983 | event->ignore(); | - | ||||||||||||||||||
1984 | } | - | ||||||||||||||||||
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 | - | ||||||||||||||||||
1999 | && (event->source() != this || !(event->possibleActions() & Qt::MoveAction))) | - | ||||||||||||||||||
2000 | return; | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
2008 | && d->canDrop(event)) { | - | ||||||||||||||||||
2009 | - | |||||||||||||||||||
2010 | if (index.isValid() && d->showDropIndicator) { | - | ||||||||||||||||||
2011 | QRect rect = visualRect(index); | - | ||||||||||||||||||
2012 | d->dropIndicatorPosition = d->position(event->pos(), rect, index); | - | ||||||||||||||||||
2013 | switch (d->dropIndicatorPosition) { | - | ||||||||||||||||||
2014 | case AboveItem: | - | ||||||||||||||||||
2015 | if (d->isIndexDropEnabled(index.parent())) { | - | ||||||||||||||||||
2016 | d->dropIndicatorRect = QRect(rect.left(), rect.top(), rect.width(), 0); | - | ||||||||||||||||||
2017 | event->acceptProposedAction(); | - | ||||||||||||||||||
2018 | } else { | - | ||||||||||||||||||
2019 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||
2020 | } | - | ||||||||||||||||||
2021 | break; | - | ||||||||||||||||||
2022 | case BelowItem: | - | ||||||||||||||||||
2023 | if (d->isIndexDropEnabled(index.parent())) { | - | ||||||||||||||||||
2024 | d->dropIndicatorRect = QRect(rect.left(), rect.bottom(), rect.width(), 0); | - | ||||||||||||||||||
2025 | event->acceptProposedAction(); | - | ||||||||||||||||||
2026 | } else { | - | ||||||||||||||||||
2027 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||
2028 | } | - | ||||||||||||||||||
2029 | break; | - | ||||||||||||||||||
2030 | case OnItem: | - | ||||||||||||||||||
2031 | if (d->isIndexDropEnabled(index)) { | - | ||||||||||||||||||
2032 | d->dropIndicatorRect = rect; | - | ||||||||||||||||||
2033 | event->acceptProposedAction(); | - | ||||||||||||||||||
2034 | } else { | - | ||||||||||||||||||
2035 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||
2036 | } | - | ||||||||||||||||||
2037 | break; | - | ||||||||||||||||||
2038 | case OnViewport: | - | ||||||||||||||||||
2039 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||
2040 | if (d->isIndexDropEnabled(rootIndex())) { | - | ||||||||||||||||||
2041 | event->acceptProposedAction(); // allow dropping in empty areas | - | ||||||||||||||||||
2042 | } | - | ||||||||||||||||||
2043 | break; | - | ||||||||||||||||||
2044 | } | - | ||||||||||||||||||
2045 | } else { | - | ||||||||||||||||||
2046 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||
2047 | d->dropIndicatorPosition = OnViewport; | - | ||||||||||||||||||
2048 | if (d->isIndexDropEnabled(rootIndex())) { | - | ||||||||||||||||||
2049 | event->acceptProposedAction(); // allow dropping in empty areas | - | ||||||||||||||||||
2050 | } | - | ||||||||||||||||||
2051 | } | - | ||||||||||||||||||
2052 | d->viewport->update(); | - | ||||||||||||||||||
2053 | } // can drop | - | ||||||||||||||||||
2054 | - | |||||||||||||||||||
2055 | if (d->shouldAutoScroll(event->pos())) | - | ||||||||||||||||||
2056 | startAutoScroll(); | - | ||||||||||||||||||
2057 | } | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
2069 | dropAction = Qt::MoveAction; | - | ||||||||||||||||||
2070 | if (event->source() == q | - | ||||||||||||||||||
2071 | && event->possibleActions() & Qt::MoveAction | - | ||||||||||||||||||
2072 | && dropAction == Qt::MoveAction) { | - | ||||||||||||||||||
2073 | QModelIndexList selectedIndexes = q->selectedIndexes(); | - | ||||||||||||||||||
2074 | QModelIndex child = index; | - | ||||||||||||||||||
2075 | while (child.isValid() && child != root) { | - | ||||||||||||||||||
2076 | if (selectedIndexes.contains(child)) | - | ||||||||||||||||||
2077 | return true; | - | ||||||||||||||||||
2078 | child = child.parent(); | - | ||||||||||||||||||
2079 | } | - | ||||||||||||||||||
2080 | } | - | ||||||||||||||||||
2081 | return false; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
2110 | if (event->source() != this || !(event->possibleActions() & Qt::MoveAction)) | - | ||||||||||||||||||
2111 | return; | - | ||||||||||||||||||
2112 | } | - | ||||||||||||||||||
2113 | - | |||||||||||||||||||
2114 | QModelIndex index; | - | ||||||||||||||||||
2115 | int col = -1; | - | ||||||||||||||||||
2116 | int row = -1; | - | ||||||||||||||||||
2117 | if (d->dropOn(event, &row, &col, &index)) { | - | ||||||||||||||||||
2118 | const Qt::DropAction action = dragDropMode() == InternalMove ? Qt::MoveAction : event->dropAction(); | - | ||||||||||||||||||
2119 | if (d->model->dropMimeData(event->mimeData(), action, row, col, index)) { | - | ||||||||||||||||||
2120 | if (action != event->dropAction()) { | - | ||||||||||||||||||
2121 | event->setDropAction(action); | - | ||||||||||||||||||
2122 | event->accept(); | - | ||||||||||||||||||
2123 | } else { | - | ||||||||||||||||||
2124 | event->acceptProposedAction(); | - | ||||||||||||||||||
2125 | } | - | ||||||||||||||||||
2126 | } | - | ||||||||||||||||||
2127 | } | - | ||||||||||||||||||
2128 | stopAutoScroll(); | - | ||||||||||||||||||
2129 | setState(NoState); | - | ||||||||||||||||||
2130 | d->viewport->update(); | - | ||||||||||||||||||
2131 | } | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
2148 | return false; | - | ||||||||||||||||||
2149 | - | |||||||||||||||||||
2150 | QModelIndex index; | - | ||||||||||||||||||
2151 | // rootIndex() (i.e. the viewport) might be a valid index | - | ||||||||||||||||||
2152 | if (viewport->rect().contains(event->pos())) { | - | ||||||||||||||||||
2153 | index = q->indexAt(event->pos()); | - | ||||||||||||||||||
2154 | if (!index.isValid() || !q->visualRect(index).contains(event->pos())) | - | ||||||||||||||||||
2155 | index = root; | - | ||||||||||||||||||
2156 | } | - | ||||||||||||||||||
2157 | - | |||||||||||||||||||
2158 | // If we are allowed to do the drop | - | ||||||||||||||||||
2159 | if (model->supportedDropActions() & event->dropAction()) { | - | ||||||||||||||||||
2160 | int row = -1; | - | ||||||||||||||||||
2161 | int col = -1; | - | ||||||||||||||||||
2162 | if (index != root) { | - | ||||||||||||||||||
2163 | dropIndicatorPosition = position(event->pos(), q->visualRect(index), index); | - | ||||||||||||||||||
2164 | switch (dropIndicatorPosition) { | - | ||||||||||||||||||
2165 | case QAbstractItemView::AboveItem: | - | ||||||||||||||||||
2166 | row = index.row(); | - | ||||||||||||||||||
2167 | col = index.column(); | - | ||||||||||||||||||
2168 | index = index.parent(); | - | ||||||||||||||||||
2169 | break; | - | ||||||||||||||||||
2170 | case QAbstractItemView::BelowItem: | - | ||||||||||||||||||
2171 | row = index.row() + 1; | - | ||||||||||||||||||
2172 | col = index.column(); | - | ||||||||||||||||||
2173 | index = index.parent(); | - | ||||||||||||||||||
2174 | break; | - | ||||||||||||||||||
2175 | case QAbstractItemView::OnItem: | - | ||||||||||||||||||
2176 | case QAbstractItemView::OnViewport: | - | ||||||||||||||||||
2177 | break; | - | ||||||||||||||||||
2178 | } | - | ||||||||||||||||||
2179 | } else { | - | ||||||||||||||||||
2180 | dropIndicatorPosition = QAbstractItemView::OnViewport; | - | ||||||||||||||||||
2181 | } | - | ||||||||||||||||||
2182 | *dropIndex = index; | - | ||||||||||||||||||
2183 | *dropRow = row; | - | ||||||||||||||||||
2184 | *dropCol = col; | - | ||||||||||||||||||
2185 | if (!droppingOnItself(event, index)) | - | ||||||||||||||||||
2186 | return true; | - | ||||||||||||||||||
2187 | } | - | ||||||||||||||||||
2188 | return false; | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
2196 | const int margin = 2; | - | ||||||||||||||||||
2197 | if (pos.y() - rect.top() < margin) { | - | ||||||||||||||||||
2198 | r = QAbstractItemView::AboveItem; | - | ||||||||||||||||||
2199 | } else if (rect.bottom() - pos.y() < margin) { | - | ||||||||||||||||||
2200 | r = QAbstractItemView::BelowItem; | - | ||||||||||||||||||
2201 | } else if (rect.contains(pos, true)) { | - | ||||||||||||||||||
2202 | r = QAbstractItemView::OnItem; | - | ||||||||||||||||||
2203 | } | - | ||||||||||||||||||
2204 | } else { | - | ||||||||||||||||||
2205 | QRect touchingRect = rect; | - | ||||||||||||||||||
2206 | touchingRect.adjust(-1, -1, 1, 1); | - | ||||||||||||||||||
2207 | if (touchingRect.contains(pos, false)) { | - | ||||||||||||||||||
2208 | r = QAbstractItemView::OnItem; | - | ||||||||||||||||||
2209 | } | - | ||||||||||||||||||
2210 | } | - | ||||||||||||||||||
2211 | - | |||||||||||||||||||
2212 | if (r == QAbstractItemView::OnItem && (!(model->flags(index) & Qt::ItemIsDropEnabled))) | - | ||||||||||||||||||
2213 | r = pos.y() < rect.center().y() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem; | - | ||||||||||||||||||
2214 | - | |||||||||||||||||||
2215 | return r; | - | ||||||||||||||||||
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 | - | ||||||||||||||||||
2235 | && !d->currentIndexSet | - | ||||||||||||||||||
2236 | && !currentIndexValid) { | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
2241 | selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||
2242 | d->autoScroll = autoScroll; | - | ||||||||||||||||||
2243 | } | - | ||||||||||||||||||
2244 | - | |||||||||||||||||||
2245 | if (model && currentIndexValid) { | - | ||||||||||||||||||
2246 | if (currentIndex().flags() != Qt::ItemIsEditable) | - | ||||||||||||||||||
2247 | setAttribute(Qt::WA_InputMethodEnabled, false); | - | ||||||||||||||||||
2248 | else | - | ||||||||||||||||||
2249 | setAttribute(Qt::WA_InputMethodEnabled); | - | ||||||||||||||||||
2250 | } | - | ||||||||||||||||||
2251 | - | |||||||||||||||||||
2252 | if (!currentIndexValid) | - | ||||||||||||||||||
2253 | setAttribute(Qt::WA_InputMethodEnabled, false); | - | ||||||||||||||||||
2254 | - | |||||||||||||||||||
2255 | d->viewport->update(); | - | ||||||||||||||||||
2256 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
2334 | QVariant variant; | - | ||||||||||||||||||
2335 | if (d->model) | - | ||||||||||||||||||
2336 | variant = d->model->data(currentIndex(), Qt::DisplayRole); | - | ||||||||||||||||||
2337 | if (variant.type() == QVariant::String) | - | ||||||||||||||||||
2338 | QApplication::clipboard()->setText(variant.toString()); | - | ||||||||||||||||||
2339 | event->accept(); | - | ||||||||||||||||||
2340 | } | - | ||||||||||||||||||
2341 | #endif | - | ||||||||||||||||||
2342 | - | |||||||||||||||||||
2343 | QPersistentModelIndex newCurrent; | - | ||||||||||||||||||
2344 | d->moveCursorUpdatedView = false; | - | ||||||||||||||||||
2345 | switch (event->key()) { | - | ||||||||||||||||||
2346 | case Qt::Key_Down: | - | ||||||||||||||||||
2347 | newCurrent = moveCursor(MoveDown, event->modifiers()); | - | ||||||||||||||||||
2348 | break; | - | ||||||||||||||||||
2349 | case Qt::Key_Up: | - | ||||||||||||||||||
2350 | newCurrent = moveCursor(MoveUp, event->modifiers()); | - | ||||||||||||||||||
2351 | break; | - | ||||||||||||||||||
2352 | case Qt::Key_Left: | - | ||||||||||||||||||
2353 | newCurrent = moveCursor(MoveLeft, event->modifiers()); | - | ||||||||||||||||||
2354 | break; | - | ||||||||||||||||||
2355 | case Qt::Key_Right: | - | ||||||||||||||||||
2356 | newCurrent = moveCursor(MoveRight, event->modifiers()); | - | ||||||||||||||||||
2357 | break; | - | ||||||||||||||||||
2358 | case Qt::Key_Home: | - | ||||||||||||||||||
2359 | newCurrent = moveCursor(MoveHome, event->modifiers()); | - | ||||||||||||||||||
2360 | break; | - | ||||||||||||||||||
2361 | case Qt::Key_End: | - | ||||||||||||||||||
2362 | newCurrent = moveCursor(MoveEnd, event->modifiers()); | - | ||||||||||||||||||
2363 | break; | - | ||||||||||||||||||
2364 | case Qt::Key_PageUp: | - | ||||||||||||||||||
2365 | newCurrent = moveCursor(MovePageUp, event->modifiers()); | - | ||||||||||||||||||
2366 | break; | - | ||||||||||||||||||
2367 | case Qt::Key_PageDown: | - | ||||||||||||||||||
2368 | newCurrent = moveCursor(MovePageDown, event->modifiers()); | - | ||||||||||||||||||
2369 | break; | - | ||||||||||||||||||
2370 | case Qt::Key_Tab: | - | ||||||||||||||||||
2371 | if (d->tabKeyNavigation) | - | ||||||||||||||||||
2372 | newCurrent = moveCursor(MoveNext, event->modifiers()); | - | ||||||||||||||||||
2373 | break; | - | ||||||||||||||||||
2374 | case Qt::Key_Backtab: | - | ||||||||||||||||||
2375 | if (d->tabKeyNavigation) | - | ||||||||||||||||||
2376 | newCurrent = moveCursor(MovePrevious, event->modifiers()); | - | ||||||||||||||||||
2377 | break; | - | ||||||||||||||||||
2378 | } | - | ||||||||||||||||||
2379 | - | |||||||||||||||||||
2380 | QPersistentModelIndex oldCurrent = currentIndex(); | - | ||||||||||||||||||
2381 | if (newCurrent != oldCurrent && newCurrent.isValid() && d->isIndexEnabled(newCurrent)) { | - | ||||||||||||||||||
2382 | if (!hasFocus() && QApplication::focusWidget() == indexWidget(oldCurrent)) | - | ||||||||||||||||||
2383 | setFocus(); | - | ||||||||||||||||||
2384 | QItemSelectionModel::SelectionFlags command = selectionCommand(newCurrent, event); | - | ||||||||||||||||||
2385 | if (command != QItemSelectionModel::NoUpdate | - | ||||||||||||||||||
2386 | || style()->styleHint(QStyle::SH_ItemView_MovementWithoutUpdatingSelection, 0, this)) { | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
2389 | d->selectionModel->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||
2390 | if (!d->currentSelectionStartIndex.isValid()) | - | ||||||||||||||||||
2391 | d->currentSelectionStartIndex = oldCurrent; | - | ||||||||||||||||||
2392 | QRect rect(visualRect(d->currentSelectionStartIndex).center(), visualRect(newCurrent).center()); | - | ||||||||||||||||||
2393 | setSelection(rect, command); | - | ||||||||||||||||||
2394 | } else { | - | ||||||||||||||||||
2395 | d->selectionModel->setCurrentIndex(newCurrent, command); | - | ||||||||||||||||||
2396 | d->currentSelectionStartIndex = newCurrent; | - | ||||||||||||||||||
2397 | if (newCurrent.isValid()) { | - | ||||||||||||||||||
2398 | // We copy the same behaviour as for mousePressEvent(). | - | ||||||||||||||||||
2399 | QRect rect(visualRect(newCurrent).center(), QSize(1, 1)); | - | ||||||||||||||||||
2400 | setSelection(rect, command); | - | ||||||||||||||||||
2401 | } | - | ||||||||||||||||||
2402 | } | - | ||||||||||||||||||
2403 | event->accept(); | - | ||||||||||||||||||
2404 | return; | - | ||||||||||||||||||
2405 | } | - | ||||||||||||||||||
2406 | } | - | ||||||||||||||||||
2407 | - | |||||||||||||||||||
2408 | switch (event->key()) { | - | ||||||||||||||||||
2409 | // ignored keys | - | ||||||||||||||||||
2410 | case Qt::Key_Down: | - | ||||||||||||||||||
2411 | case Qt::Key_Up: | - | ||||||||||||||||||
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: | - | ||||||||||||||||||
2419 | case Qt::Key_Right: | - | ||||||||||||||||||
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: | - | ||||||||||||||||||
2429 | case Qt::Key_End: | - | ||||||||||||||||||
2430 | case Qt::Key_PageUp: | - | ||||||||||||||||||
2431 | case Qt::Key_PageDown: | - | ||||||||||||||||||
2432 | case Qt::Key_Escape: | - | ||||||||||||||||||
2433 | case Qt::Key_Shift: | - | ||||||||||||||||||
2434 | case Qt::Key_Control: | - | ||||||||||||||||||
2435 | case Qt::Key_Delete: | - | ||||||||||||||||||
2436 | case Qt::Key_Backspace: | - | ||||||||||||||||||
2437 | event->ignore(); | - | ||||||||||||||||||
2438 | break; | - | ||||||||||||||||||
2439 | case Qt::Key_Space: | - | ||||||||||||||||||
2440 | case Qt::Key_Select: | - | ||||||||||||||||||
2441 | if (!edit(currentIndex(), AnyKeyPressed, event) && d->selectionModel) | - | ||||||||||||||||||
2442 | d->selectionModel->select(currentIndex(), selectionCommand(currentIndex(), event)); | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
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: | - | ||||||||||||||||||
2465 | if (!edit(currentIndex(), EditKeyPressed, event)) | - | ||||||||||||||||||
2466 | event->ignore(); | - | ||||||||||||||||||
2467 | break; | - | ||||||||||||||||||
2468 | case Qt::Key_Enter: | - | ||||||||||||||||||
2469 | case Qt::Key_Return: | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
2474 | if (currentIndex().isValid()) | - | ||||||||||||||||||
2475 | emit activated(currentIndex()); | - | ||||||||||||||||||
2476 | event->ignore(); | - | ||||||||||||||||||
2477 | } | - | ||||||||||||||||||
2478 | break; | - | ||||||||||||||||||
2479 | #endif | - | ||||||||||||||||||
2480 | default: { | - | ||||||||||||||||||
2481 | if (event == QKeySequence::SelectAll && selectionMode() != NoSelection) { | - | ||||||||||||||||||
2482 | selectAll(); | - | ||||||||||||||||||
2483 | break; | - | ||||||||||||||||||
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)) { | - | ||||||||||||||||||
2493 | keyboardSearch(event->text()); | - | ||||||||||||||||||
2494 | event->accept(); | - | ||||||||||||||||||
2495 | } else { | - | ||||||||||||||||||
2496 | event->ignore(); | - | ||||||||||||||||||
2497 | } | - | ||||||||||||||||||
2498 | break; } | - | ||||||||||||||||||
2499 | } | - | ||||||||||||||||||
2500 | if (d->moveCursorUpdatedView) | - | ||||||||||||||||||
2501 | event->accept(); | - | ||||||||||||||||||
2502 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
2526 | d->fetchMore(); | - | ||||||||||||||||||
2527 | else if (event->timerId() == d->delayedReset.timerId()) | - | ||||||||||||||||||
2528 | reset(); | - | ||||||||||||||||||
2529 | else if (event->timerId() == d->autoScrollTimer.timerId()) | - | ||||||||||||||||||
2530 | doAutoScroll(); | - | ||||||||||||||||||
2531 | else if (event->timerId() == d->updateTimer.timerId()) | - | ||||||||||||||||||
2532 | d->updateDirtyRegion(); | - | ||||||||||||||||||
2533 | else if (event->timerId() == d->delayedEditing.timerId()) { | - | ||||||||||||||||||
2534 | d->delayedEditing.stop(); | - | ||||||||||||||||||
2535 | edit(currentIndex()); | - | ||||||||||||||||||
2536 | } else if (event->timerId() == d->delayedLayout.timerId()) { | - | ||||||||||||||||||
2537 | d->delayedLayout.stop(); | - | ||||||||||||||||||
2538 | if (isVisible()) { | - | ||||||||||||||||||
2539 | d->interruptDelayedItemsLayout(); | - | ||||||||||||||||||
2540 | doItemsLayout(); | - | ||||||||||||||||||
2541 | const QModelIndex current = currentIndex(); | - | ||||||||||||||||||
2542 | if (current.isValid() && d->state == QAbstractItemView::EditingState) | - | ||||||||||||||||||
2543 | scrollTo(current); | - | ||||||||||||||||||
2544 | } | - | ||||||||||||||||||
2545 | } else if (event->timerId() == d->delayedAutoScroll.timerId()) { | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
2550 | scrollTo(d->pressedIndex); | - | ||||||||||||||||||
2551 | } | - | ||||||||||||||||||
2552 | } | - | ||||||||||||||||||
2553 | - | |||||||||||||||||||
2554 | /*! | - | ||||||||||||||||||
2555 | \reimp | - | ||||||||||||||||||
2556 | */ | - | ||||||||||||||||||
2557 | void QAbstractItemView::inputMethodEvent(QInputMethodEvent *event) | - | ||||||||||||||||||
2558 | { | - | ||||||||||||||||||
2559 | if (event->commitString().isEmpty() && event->preeditString().isEmpty()) { | - | ||||||||||||||||||
2560 | event->ignore(); | - | ||||||||||||||||||
2561 | return; | - | ||||||||||||||||||
2562 | } | - | ||||||||||||||||||
2563 | if (!edit(currentIndex(), AnyKeyPressed, event)) { | - | ||||||||||||||||||
2564 | if (!event->commitString().isEmpty()) | - | ||||||||||||||||||
2565 | keyboardSearch(event->commitString()); | - | ||||||||||||||||||
2566 | event->ignore(); | - | ||||||||||||||||||
2567 | } | - | ||||||||||||||||||
2568 | } | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
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 | QList<auto isHidden = [this](const QModelIndex >::iterator it&idx) { | - | ||||||||||||||||||
2615 | return isIndexHidden(idx); never executed: return isIndexHidden(idx); | 0 | ||||||||||||||||||
2616 | }; | - | ||||||||||||||||||
2617 | const auto end = indexes.beginend(); | - | ||||||||||||||||||
2618 | while (it !=indexes.end()) | - | ||||||||||||||||||
iferase(isIndexHidden(*it)) | ||||||||||||||||||||
it =std::remove_if(indexes.erase(itbegin(), end, isHidden), end); | ||||||||||||||||||||
2619 | else never executed: end of block | 0 | ||||||||||||||||||
++it; never executed: }end of block never executed: end of block | ||||||||||||||||||||
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)) | - | ||||||||||||||||||
2641 | return false; | - | ||||||||||||||||||
2642 | - | |||||||||||||||||||
2643 | if (QWidget *w = (d->persistent.isEmpty() ? static_cast<QWidget*>(0) : d->editorForIndex(index).widget.data())) { | - | ||||||||||||||||||
2644 | if (w->focusPolicy() == Qt::NoFocus) | - | ||||||||||||||||||
2645 | return false; | - | ||||||||||||||||||
2646 | w->setFocus(); | - | ||||||||||||||||||
2647 | return true; | - | ||||||||||||||||||
2648 | } | - | ||||||||||||||||||
2649 | - | |||||||||||||||||||
2650 | if (trigger == DoubleClicked) { | - | ||||||||||||||||||
2651 | d->delayedEditing.stop(); | - | ||||||||||||||||||
2652 | d->delayedAutoScroll.stop(); | - | ||||||||||||||||||
2653 | } else if (trigger == CurrentChanged) { | - | ||||||||||||||||||
2654 | d->delayedEditing.stop(); | - | ||||||||||||||||||
2655 | } | - | ||||||||||||||||||
2656 | - | |||||||||||||||||||
2657 | if (d->sendDelegateEvent(index, event)) { | - | ||||||||||||||||||
2658 | update(index); | - | ||||||||||||||||||
2659 | return true; | - | ||||||||||||||||||
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))) | - | ||||||||||||||||||
2667 | return false; | - | ||||||||||||||||||
2668 | - | |||||||||||||||||||
2669 | if (d->delayedEditing.isActive()) | - | ||||||||||||||||||
2670 | return false; | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
2675 | return false; | - | ||||||||||||||||||
2676 | - | |||||||||||||||||||
2677 | // we may get a double click event later | - | ||||||||||||||||||
2678 | if (trigger == SelectedClicked) | - | ||||||||||||||||||
2679 | d->delayedEditing.start(QApplication::doubleClickInterval(), this); | - | ||||||||||||||||||
2680 | else | - | ||||||||||||||||||
2681 | d->openEditor(index, d->shouldForwardEvent(trigger, event) ? event : 0); | - | ||||||||||||||||||
2682 | - | |||||||||||||||||||
2683 | return true; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
2704 | return; | - | ||||||||||||||||||
2705 | if (d->delayedPendingLayout) { | - | ||||||||||||||||||
2706 | // doItemsLayout() will end up calling this function again | - | ||||||||||||||||||
2707 | d->executePostedLayout(); | - | ||||||||||||||||||
2708 | return; | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
2715 | QModelIndex index = it.value(); | - | ||||||||||||||||||
2716 | QWidget *editor = it.key(); | - | ||||||||||||||||||
2717 | if (index.isValid() && editor) { | - | ||||||||||||||||||
2718 | option.rect = visualRect(index); | - | ||||||||||||||||||
2719 | if (option.rect.isValid()) { | - | ||||||||||||||||||
2720 | editor->show(); | - | ||||||||||||||||||
2721 | QAbstractItemDelegate *delegate = d->delegateForIndex(index); | - | ||||||||||||||||||
2722 | if (delegate) | - | ||||||||||||||||||
2723 | delegate->updateEditorGeometry(editor, option, index); | - | ||||||||||||||||||
2724 | } else { | - | ||||||||||||||||||
2725 | editorsToHide << editor; | - | ||||||||||||||||||
2726 | } | - | ||||||||||||||||||
2727 | ++it; | - | ||||||||||||||||||
2728 | } else { | - | ||||||||||||||||||
2729 | d->indexEditorHash.remove(it.value()); | - | ||||||||||||||||||
2730 | it = d->editorIndexHash.erase(it); | - | ||||||||||||||||||
2731 | editorsToRelease << editor; | - | ||||||||||||||||||
2732 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
2738 | editorsToHide.at(i)->hide(); | - | ||||||||||||||||||
2739 | } | - | ||||||||||||||||||
2740 | for (int i = 0; i < editorsToRelease.count(); ++i) { | - | ||||||||||||||||||
2741 | d->releaseEditor(editorsToRelease.at(i)); | - | ||||||||||||||||||
2742 | } | - | ||||||||||||||||||
2743 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
2765 | d->model->fetchMore(d->root); | - | ||||||||||||||||||
2766 | QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos()); | - | ||||||||||||||||||
2767 | if (viewport()->rect().contains(posInVp)) | - | ||||||||||||||||||
2768 | d->checkMouseMove(posInVp); | - | ||||||||||||||||||
2769 | } | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
2778 | d->model->fetchMore(d->root); | - | ||||||||||||||||||
2779 | QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos()); | - | ||||||||||||||||||
2780 | if (viewport()->rect().contains(posInVp)) | - | ||||||||||||||||||
2781 | d->checkMouseMove(posInVp); | - | ||||||||||||||||||
2782 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
2815 | bool isPersistent = d->persistent.contains(editor); | - | ||||||||||||||||||
2816 | bool hadFocus = editor->hasFocus(); | - | ||||||||||||||||||
2817 | QModelIndex index = d->indexForEditor(editor); | - | ||||||||||||||||||
2818 | if (!index.isValid()) | - | ||||||||||||||||||
2819 | return; // the editor was not registered | - | ||||||||||||||||||
2820 | - | |||||||||||||||||||
2821 | if (!isPersistent) { | - | ||||||||||||||||||
2822 | setState(NoState); | - | ||||||||||||||||||
2823 | QModelIndex index = d->indexForEditor(editor); | - | ||||||||||||||||||
2824 | editor->removeEventFilter(d->delegateForIndex(index)); | - | ||||||||||||||||||
2825 | d->removeEditor(editor); | - | ||||||||||||||||||
2826 | } | - | ||||||||||||||||||
2827 | if (hadFocus) { | - | ||||||||||||||||||
2828 | if (focusPolicy() != Qt::NoFocus) | - | ||||||||||||||||||
2829 | setFocus(); // this will send a focusLost event to the editor | - | ||||||||||||||||||
2830 | else | - | ||||||||||||||||||
2831 | editor->clearFocus(); | - | ||||||||||||||||||
2832 | } else { | - | ||||||||||||||||||
2833 | d->checkPersistentEditorFocus(); | - | ||||||||||||||||||
2834 | } | - | ||||||||||||||||||
2835 | - | |||||||||||||||||||
2836 | QPointer<QWidget> ed = editor; | - | ||||||||||||||||||
2837 | QApplication::sendPostedEvents(editor, 0); | - | ||||||||||||||||||
2838 | editor = ed; | - | ||||||||||||||||||
2839 | - | |||||||||||||||||||
2840 | if (!isPersistent && editor) | - | ||||||||||||||||||
2841 | d->releaseEditor(editor, index); | - | ||||||||||||||||||
2842 | } | - | ||||||||||||||||||
2843 | - | |||||||||||||||||||
2844 | // The EndEditHint part | - | ||||||||||||||||||
2845 | QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
2846 | if (d->selectionMode != NoSelection) | - | ||||||||||||||||||
2847 | flags = QItemSelectionModel::ClearAndSelect | d->selectionBehaviorFlags(); | - | ||||||||||||||||||
2848 | switch (hint) { | - | ||||||||||||||||||
2849 | case QAbstractItemDelegate::EditNextItem: { | - | ||||||||||||||||||
2850 | QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); | - | ||||||||||||||||||
2851 | if (index.isValid()) { | - | ||||||||||||||||||
2852 | QPersistentModelIndex persistent(index); | - | ||||||||||||||||||
2853 | d->selectionModel->setCurrentIndex(persistent, flags); | - | ||||||||||||||||||
2854 | // currentChanged signal would have already started editing | - | ||||||||||||||||||
2855 | if (index.flags() & Qt::ItemIsEditable | - | ||||||||||||||||||
2856 | && (!(editTriggers() & QAbstractItemView::CurrentChanged))) | - | ||||||||||||||||||
2857 | edit(persistent); | - | ||||||||||||||||||
2858 | } break; } | - | ||||||||||||||||||
2859 | case QAbstractItemDelegate::EditPreviousItem: { | - | ||||||||||||||||||
2860 | QModelIndex index = moveCursor(MovePrevious, Qt::NoModifier); | - | ||||||||||||||||||
2861 | if (index.isValid()) { | - | ||||||||||||||||||
2862 | QPersistentModelIndex persistent(index); | - | ||||||||||||||||||
2863 | d->selectionModel->setCurrentIndex(persistent, flags); | - | ||||||||||||||||||
2864 | // currentChanged signal would have already started editing | - | ||||||||||||||||||
2865 | if (index.flags() & Qt::ItemIsEditable | - | ||||||||||||||||||
2866 | && (!(editTriggers() & QAbstractItemView::CurrentChanged))) | - | ||||||||||||||||||
2867 | edit(persistent); | - | ||||||||||||||||||
2868 | } break; } | - | ||||||||||||||||||
2869 | case QAbstractItemDelegate::SubmitModelCache: | - | ||||||||||||||||||
2870 | d->model->submit(); | - | ||||||||||||||||||
2871 | break; | - | ||||||||||||||||||
2872 | case QAbstractItemDelegate::RevertModelCache: | - | ||||||||||||||||||
2873 | d->model->revert(); | - | ||||||||||||||||||
2874 | break; | - | ||||||||||||||||||
2875 | default: | - | ||||||||||||||||||
2876 | break; | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
2889 | return; | - | ||||||||||||||||||
2890 | QModelIndex index = d->indexForEditor(editor); | - | ||||||||||||||||||
2891 | if (!index.isValid()) | - | ||||||||||||||||||
2892 | return; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
2913 | setState(NoState); | - | ||||||||||||||||||
2914 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
2986 | return; | - | ||||||||||||||||||
2987 | - | |||||||||||||||||||
2988 | QModelIndex start = currentIndex().isValid() ? currentIndex() | - | ||||||||||||||||||
2989 | : d->model->index(0, 0, d->root); | - | ||||||||||||||||||
2990 | bool skipRow = false; | - | ||||||||||||||||||
2991 | bool keyboardTimeWasValid = d->keyboardInputTime.isValid(); | - | ||||||||||||||||||
2992 | qint64 keyboardInputTimeElapsed; | - | ||||||||||||||||||
2993 | if (keyboardTimeWasValid) | - | ||||||||||||||||||
2994 | keyboardInputTimeElapsed = d->keyboardInputTime.restart(); | - | ||||||||||||||||||
2995 | else | - | ||||||||||||||||||
2996 | d->keyboardInputTime.start(); | - | ||||||||||||||||||
2997 | if (search.isEmpty() || !keyboardTimeWasValid | - | ||||||||||||||||||
2998 | || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) { | - | ||||||||||||||||||
2999 | d->keyboardInput = search; | - | ||||||||||||||||||
3000 | skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0) | - | ||||||||||||||||||
3001 | } else { | - | ||||||||||||||||||
3002 | d->keyboardInput += search; | - | ||||||||||||||||||
3003 | } | - | ||||||||||||||||||
3004 | - | |||||||||||||||||||
3005 | // special case for searches with same key like 'aaaaa' | - | ||||||||||||||||||
3006 | bool sameKey = false; | - | ||||||||||||||||||
3007 | if (d->keyboardInput.length() > 1) { | - | ||||||||||||||||||
3008 | int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.length() - 1)); | - | ||||||||||||||||||
3009 | sameKey = (c == d->keyboardInput.length()); | - | ||||||||||||||||||
3010 | if (sameKey) | - | ||||||||||||||||||
3011 | skipRow = true; | - | ||||||||||||||||||
3012 | } | - | ||||||||||||||||||
3013 | - | |||||||||||||||||||
3014 | // skip if we are searching for the same key or a new search started | - | ||||||||||||||||||
3015 | if (skipRow) { | - | ||||||||||||||||||
3016 | QModelIndex parent = start.parent(); | - | ||||||||||||||||||
3017 | int newRow = (start.row() < d->model->rowCount(parent) - 1) ? start.row() + 1 : 0; | - | ||||||||||||||||||
3018 | start = d->model->index(newRow, start.column(), parent); | - | ||||||||||||||||||
3019 | } | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
3030 | break; | - | ||||||||||||||||||
3031 | firstMatch = match.value(0); | - | ||||||||||||||||||
3032 | previous = match; | - | ||||||||||||||||||
3033 | if (firstMatch.isValid()) { | - | ||||||||||||||||||
3034 | if (d->isIndexEnabled(firstMatch)) { | - | ||||||||||||||||||
3035 | setCurrentIndex(firstMatch); | - | ||||||||||||||||||
3036 | break; | - | ||||||||||||||||||
3037 | } | - | ||||||||||||||||||
3038 | int row = firstMatch.row() + 1; | - | ||||||||||||||||||
3039 | if (row >= d->model->rowCount(firstMatch.parent())) | - | ||||||||||||||||||
3040 | row = 0; | - | ||||||||||||||||||
3041 | current = firstMatch.sibling(row, firstMatch.column()); | - | ||||||||||||||||||
3042 | - | |||||||||||||||||||
3043 | //avoid infinite loop if all the matching items are disabled. | - | ||||||||||||||||||
3044 | if (!startMatch.isValid()) | - | ||||||||||||||||||
3045 | startMatch = firstMatch; | - | ||||||||||||||||||
3046 | else if (startMatch == firstMatch) | - | ||||||||||||||||||
3047 | break; | - | ||||||||||||||||||
3048 | } | - | ||||||||||||||||||
3049 | } while (current != start && firstMatch.isValid()); | - | ||||||||||||||||||
3050 | } | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
3062 | return QSize(); | - | ||||||||||||||||||
3063 | return d->delegateForIndex(index)->sizeHint(d->viewOptionsV1(), index); | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
3087 | return -1; | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
3095 | const QModelIndex index = d->model->index(row, c, d->root); | - | ||||||||||||||||||
3096 | if (QWidget *editor = d->editorForIndex(index).widget.data()) | - | ||||||||||||||||||
3097 | height = qMax(height, editor->height()); | - | ||||||||||||||||||
3098 | if (const QAbstractItemDelegate *delegate = d->delegateForIndex(index)) | - | ||||||||||||||||||
3099 | height = qMax(height, delegate->sizeHint(option, index).height()); | - | ||||||||||||||||||
3100 | } | - | ||||||||||||||||||
3101 | return height; | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
3117 | return -1; | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
3125 | const QModelIndex index = d->model->index(r, column, d->root); | - | ||||||||||||||||||
3126 | if (QWidget *editor = d->editorForIndex(index).widget.data()) | - | ||||||||||||||||||
3127 | width = qMax(width, editor->sizeHint().width()); | - | ||||||||||||||||||
3128 | if (const QAbstractItemDelegate *delegate = d->delegateForIndex(index)) | - | ||||||||||||||||||
3129 | width = qMax(width, delegate->sizeHint(option, index).width()); | - | ||||||||||||||||||
3130 | } | - | ||||||||||||||||||
3131 | return width; | - | ||||||||||||||||||
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); | - | ||||||||||||||||||
3146 | - | |||||||||||||||||||
3147 | QWidget *editor = d->editor(index, options); | - | ||||||||||||||||||
3148 | if (editor) { | - | ||||||||||||||||||
3149 | editor->show(); | - | ||||||||||||||||||
3150 | d->persistent.insert(editor); | - | ||||||||||||||||||
3151 | } | - | ||||||||||||||||||
3152 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
3163 | if (index == selectionModel()->currentIndex()) | - | ||||||||||||||||||
3164 | closeEditor(editor, QAbstractItemDelegate::RevertModelCache); | - | ||||||||||||||||||
3165 | d->persistent.remove(editor); | - | ||||||||||||||||||
3166 | d->removeEditor(editor); | - | ||||||||||||||||||
3167 | d->releaseEditor(editor, index); | - | ||||||||||||||||||
3168 | } | - | ||||||||||||||||||
3169 | } | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
3201 | return; | - | ||||||||||||||||||
3202 | if (indexWidget(index) == widget) | - | ||||||||||||||||||
3203 | return; | - | ||||||||||||||||||
3204 | if (QWidget *oldWidget = indexWidget(index)) { | - | ||||||||||||||||||
3205 | d->persistent.remove(oldWidget); | - | ||||||||||||||||||
3206 | d->removeEditor(oldWidget); | - | ||||||||||||||||||
3207 | oldWidget->deleteLater(); | - | ||||||||||||||||||
3208 | } | - | ||||||||||||||||||
3209 | if (widget) { | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
3216 | widget->setGeometry(visualRect(index)); | - | ||||||||||||||||||
3217 | } | - | ||||||||||||||||||
3218 | } | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
3229 | if (QWidget *editor = d->editorForIndex(index).widget.data()) | - | ||||||||||||||||||
3230 | return editor; | - | ||||||||||||||||||
3231 | - | |||||||||||||||||||
3232 | return 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 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
3258 | d->executePostedLayout(); | - | ||||||||||||||||||
3259 | updateGeometries(); | - | ||||||||||||||||||
3260 | } | - | ||||||||||||||||||
3261 | verticalScrollBar()->setValue(verticalScrollBar()->maximum()); | - | ||||||||||||||||||
3262 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
3279 | d->viewport->update(rect); | - | ||||||||||||||||||
3280 | } | - | ||||||||||||||||||
3281 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
3300 | QAbstractItemDelegate *delegate = d->delegateForIndex(topLeft); | - | ||||||||||||||||||
3301 | if (delegate) { | - | ||||||||||||||||||
3302 | delegate->setEditorData(editorInfo.widget.data(), topLeft); | - | ||||||||||||||||||
3303 | } | - | ||||||||||||||||||
3304 | } | - | ||||||||||||||||||
3305 | if (isVisible() && !d->delayedPendingLayout) { | - | ||||||||||||||||||
3306 | // otherwise the items will be update later anyway | - | ||||||||||||||||||
3307 | update(topLeft); | - | ||||||||||||||||||
3308 | } | - | ||||||||||||||||||
3309 | } else { | - | ||||||||||||||||||
3310 | d->updateEditorData(topLeft, bottomRight); | - | ||||||||||||||||||
3311 | if (isVisible() && !d->delayedPendingLayout) | - | ||||||||||||||||||
3312 | d->viewport->update(); | - | ||||||||||||||||||
3313 | } | - | ||||||||||||||||||
3314 | - | |||||||||||||||||||
3315 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
3316 | if (QAccessible::isActive()) { | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
3324 | #endif | - | ||||||||||||||||||
3325 | d->updateGeometry(); | - | ||||||||||||||||||
3326 | } | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
3339 | d_func()->fetchMoreTimer.start(0, this); //fetch more later | - | ||||||||||||||||||
3340 | else | - | ||||||||||||||||||
3341 | updateEditorGeometries(); | - | ||||||||||||||||||
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 | - | ||||||||||||||||||
3359 | && current.isValid() | - | ||||||||||||||||||
3360 | && current.row() >= start | - | ||||||||||||||||||
3361 | && current.row() <= end | - | ||||||||||||||||||
3362 | && current.parent() == parent) { | - | ||||||||||||||||||
3363 | int totalToRemove = end - start + 1; | - | ||||||||||||||||||
3364 | if (d->model->rowCount(parent) <= totalToRemove) { // no more children | - | ||||||||||||||||||
3365 | QModelIndex index = parent; | - | ||||||||||||||||||
3366 | while (index != d->root && !d->isIndexEnabled(index)) | - | ||||||||||||||||||
3367 | index = index.parent(); | - | ||||||||||||||||||
3368 | if (index != d->root) | - | ||||||||||||||||||
3369 | setCurrentIndex(index); | - | ||||||||||||||||||
3370 | } else { | - | ||||||||||||||||||
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))); | - | ||||||||||||||||||
3376 | if (row > d->model->rowCount(parent)) { | - | ||||||||||||||||||
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))); | - | ||||||||||||||||||
3381 | } | - | ||||||||||||||||||
3382 | setCurrentIndex(next); | - | ||||||||||||||||||
3383 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
3389 | const QModelIndex index = i.value(); | - | ||||||||||||||||||
3390 | if (index.row() >= start && index.row() <= end && d->model->parent(index) == parent) { | - | ||||||||||||||||||
3391 | QWidget *editor = i.key(); | - | ||||||||||||||||||
3392 | QEditorInfo info = d->indexEditorHash.take(index); | - | ||||||||||||||||||
3393 | i = d->editorIndexHash.erase(i); | - | ||||||||||||||||||
3394 | if (info.widget) | - | ||||||||||||||||||
3395 | d->releaseEditor(editor, index); | - | ||||||||||||||||||
3396 | } else { | - | ||||||||||||||||||
3397 | ++i; | - | ||||||||||||||||||
3398 | } | - | ||||||||||||||||||
3399 | } | - | ||||||||||||||||||
3400 | } | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
3417 | q->updateEditorGeometries(); | - | ||||||||||||||||||
3418 | q->setState(QAbstractItemView::NoState); | - | ||||||||||||||||||
3419 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
3420 | if (QAccessible::isActive()) { | - | ||||||||||||||||||
3421 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::RowsRemoved); | - | ||||||||||||||||||
3422 | accessibleEvent.setFirstRow(start); | - | ||||||||||||||||||
3423 | accessibleEvent.setLastRow(end); | - | ||||||||||||||||||
3424 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||
3425 | } | - | ||||||||||||||||||
3426 | #endif | - | ||||||||||||||||||
3427 | updateGeometry(); | - | ||||||||||||||||||
3428 | } | - | ||||||||||||||||||
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() | - | ||||||||||||||||||
3446 | && selectionMode == QAbstractItemView::SingleSelection | - | ||||||||||||||||||
3447 | && current.column() >= start | - | ||||||||||||||||||
3448 | && current.column() <= end) { | - | ||||||||||||||||||
3449 | int totalToRemove = end - start + 1; | - | ||||||||||||||||||
3450 | if (model->columnCount(parent) < totalToRemove) { // no more columns | - | ||||||||||||||||||
3451 | QModelIndex index = parent; | - | ||||||||||||||||||
3452 | while (index.isValid() && !isIndexEnabled(index)) | - | ||||||||||||||||||
3453 | index = index.parent(); | - | ||||||||||||||||||
3454 | if (index.isValid()) | - | ||||||||||||||||||
3455 | q->setCurrentIndex(index); | - | ||||||||||||||||||
3456 | } else { | - | ||||||||||||||||||
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))); | - | ||||||||||||||||||
3462 | q->setCurrentIndex(next); | - | ||||||||||||||||||
3463 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
3469 | QModelIndex index = it.value(); | - | ||||||||||||||||||
3470 | if (index.column() <= start && index.column() >= end && model->parent(index) == parent) { | - | ||||||||||||||||||
3471 | QWidget *editor = it.key(); | - | ||||||||||||||||||
3472 | QEditorInfo info = indexEditorHash.take(it.value()); | - | ||||||||||||||||||
3473 | it = editorIndexHash.erase(it); | - | ||||||||||||||||||
3474 | if (info.widget) | - | ||||||||||||||||||
3475 | releaseEditor(editor, index); | - | ||||||||||||||||||
3476 | } else { | - | ||||||||||||||||||
3477 | ++it; | - | ||||||||||||||||||
3478 | } | - | ||||||||||||||||||
3479 | } | - | ||||||||||||||||||
3480 | - | |||||||||||||||||||
3481 | } | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
3498 | q->updateEditorGeometries(); | - | ||||||||||||||||||
3499 | q->setState(QAbstractItemView::NoState); | - | ||||||||||||||||||
3500 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
3501 | if (QAccessible::isActive()) { | - | ||||||||||||||||||
3502 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::ColumnsRemoved); | - | ||||||||||||||||||
3503 | accessibleEvent.setFirstColumn(start); | - | ||||||||||||||||||
3504 | accessibleEvent.setLastColumn(end); | - | ||||||||||||||||||
3505 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||
3506 | } | - | ||||||||||||||||||
3507 | #endif | - | ||||||||||||||||||
3508 | updateGeometry(); | - | ||||||||||||||||||
3509 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
3526 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::RowsInserted); | - | ||||||||||||||||||
3527 | accessibleEvent.setFirstRow(start); | - | ||||||||||||||||||
3528 | accessibleEvent.setLastRow(end); | - | ||||||||||||||||||
3529 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||
3530 | } | - | ||||||||||||||||||
3531 | #endif | - | ||||||||||||||||||
3532 | updateGeometry(); | - | ||||||||||||||||||
3533 | } | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
3548 | q->updateEditorGeometries(); | - | ||||||||||||||||||
3549 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
3550 | if (QAccessible::isActive()) { | - | ||||||||||||||||||
3551 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::ColumnsInserted); | - | ||||||||||||||||||
3552 | accessibleEvent.setFirstColumn(start); | - | ||||||||||||||||||
3553 | accessibleEvent.setLastColumn(end); | - | ||||||||||||||||||
3554 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||
3555 | } | - | ||||||||||||||||||
3556 | #endif | - | ||||||||||||||||||
3557 | updateGeometry(); | - | ||||||||||||||||||
3558 | } | - | ||||||||||||||||||
3559 | - | |||||||||||||||||||
3560 | /*! | - | ||||||||||||||||||
3561 | \internal | - | ||||||||||||||||||
3562 | */ | - | ||||||||||||||||||
3563 | void QAbstractItemViewPrivate::_q_modelDestroyed() | - | ||||||||||||||||||
3564 | { | - | ||||||||||||||||||
3565 | model = QAbstractItemModelPrivate::staticEmptyModel(); | - | ||||||||||||||||||
3566 | doDelayedReset(); | - | ||||||||||||||||||
3567 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
3580 | QAccessibleTableModelChangeEvent accessibleEvent(q, QAccessibleTableModelChangeEvent::ModelReset); | - | ||||||||||||||||||
3581 | QAccessible::updateAccessibility(&accessibleEvent); | - | ||||||||||||||||||
3582 | } | - | ||||||||||||||||||
3583 | #endif | - | ||||||||||||||||||
3584 | } | - | ||||||||||||||||||
3585 | - | |||||||||||||||||||
3586 | void QAbstractItemViewPrivate::_q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int) | - | ||||||||||||||||||
3587 | { | - | ||||||||||||||||||
3588 | _q_layoutChanged(); | - | ||||||||||||||||||
3589 | } | - | ||||||||||||||||||
3590 | - | |||||||||||||||||||
3591 | void QAbstractItemViewPrivate::_q_columnsMoved(const QModelIndex &, int, int, const QModelIndex &, int) | - | ||||||||||||||||||
3592 | { | - | ||||||||||||||||||
3593 | _q_layoutChanged(); | - | ||||||||||||||||||
3594 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
3608 | d->viewport->update(visualRegionForSelection(deselected) | visualRegionForSelection(selected)); | - | ||||||||||||||||||
3609 | } | - | ||||||||||||||||||
3610 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
3626 | QModelIndex buddy = d->model->buddy(previous); | - | ||||||||||||||||||
3627 | QWidget *editor = d->editorForIndex(buddy).widget.data(); | - | ||||||||||||||||||
3628 | if (editor && !d->persistent.contains(editor)) { | - | ||||||||||||||||||
3629 | commitData(editor); | - | ||||||||||||||||||
3630 | if (current.row() != previous.row()) | - | ||||||||||||||||||
3631 | closeEditor(editor, QAbstractItemDelegate::SubmitModelCache); | - | ||||||||||||||||||
3632 | else | - | ||||||||||||||||||
3633 | closeEditor(editor, QAbstractItemDelegate::NoHint); | - | ||||||||||||||||||
3634 | } | - | ||||||||||||||||||
3635 | if (isVisible()) { | - | ||||||||||||||||||
3636 | update(previous); | - | ||||||||||||||||||
3637 | } | - | ||||||||||||||||||
3638 | } | - | ||||||||||||||||||
3639 | - | |||||||||||||||||||
3640 | if (current.isValid() && !d->autoScrollTimer.isActive()) { | - | ||||||||||||||||||
3641 | if (isVisible()) { | - | ||||||||||||||||||
3642 | if (d->autoScroll) | - | ||||||||||||||||||
3643 | scrollTo(current); | - | ||||||||||||||||||
3644 | update(current); | - | ||||||||||||||||||
3645 | edit(current, CurrentChanged, 0); | - | ||||||||||||||||||
3646 | if (current.row() == (d->model->rowCount(d->root) - 1)) | - | ||||||||||||||||||
3647 | d->fetchMore(); | - | ||||||||||||||||||
3648 | } else { | - | ||||||||||||||||||
3649 | d->shouldScrollToCurrentOnShow = d->autoScroll; | - | ||||||||||||||||||
3650 | } | - | ||||||||||||||||||
3651 | } | - | ||||||||||||||||||
3652 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
3663 | QMimeData *data = d->model->mimeData(indexes); | - | ||||||||||||||||||
3664 | if (!data) | - | ||||||||||||||||||
3665 | return; | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
3675 | defaultDropAction = d->defaultDropAction; | - | ||||||||||||||||||
3676 | else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove) | - | ||||||||||||||||||
3677 | defaultDropAction = Qt::CopyAction; | - | ||||||||||||||||||
3678 | if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction) | - | ||||||||||||||||||
3679 | d->clearOrRemove(); | - | ||||||||||||||||||
3680 | // Reset the drop indicator | - | ||||||||||||||||||
3681 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||
3682 | d->dropIndicatorPosition = OnItem; | - | ||||||||||||||||||
3683 | } | - | ||||||||||||||||||
3684 | } | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
3703 | option.state &= ~QStyle::State_Active; | - | ||||||||||||||||||
3704 | #endif | - | ||||||||||||||||||
3705 | - | |||||||||||||||||||
3706 | option.state &= ~QStyle::State_HasFocus; | - | ||||||||||||||||||
3707 | if (d->iconSize.isValid()) { | - | ||||||||||||||||||
3708 | option.decorationSize = d->iconSize; | - | ||||||||||||||||||
3709 | } else { | - | ||||||||||||||||||
3710 | int pm = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); | - | ||||||||||||||||||
3711 | option.decorationSize = QSize(pm, pm); | - | ||||||||||||||||||
3712 | } | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
3720 | option.features = QStyleOptionViewItem::WrapText; | - | ||||||||||||||||||
3721 | option.locale = locale(); | - | ||||||||||||||||||
3722 | option.locale.setNumberOptions(QLocale::OmitGroupSeparator); | - | ||||||||||||||||||
3723 | option.widget = this; | - | ||||||||||||||||||
3724 | return option; | - | ||||||||||||||||||
3725 | } | - | ||||||||||||||||||
3726 | - | |||||||||||||||||||
3727 | QStyleOptionViewItem QAbstractItemViewPrivate::viewOptionsV1() const | - | ||||||||||||||||||
3728 | { | - | ||||||||||||||||||
3729 | Q_Q(const QAbstractItemView); | - | ||||||||||||||||||
3730 | return q->viewOptions(); | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
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; | - | ||||||||||||||||||
3827 | } | - | ||||||||||||||||||
3828 | - | |||||||||||||||||||
3829 | /*! | - | ||||||||||||||||||
3830 | \internal | - | ||||||||||||||||||
3831 | */ | - | ||||||||||||||||||
3832 | void QAbstractItemView::startAutoScroll() | - | ||||||||||||||||||
3833 | { | - | ||||||||||||||||||
3834 | d_func()->startAutoScroll(); | - | ||||||||||||||||||
3835 | } | - | ||||||||||||||||||
3836 | - | |||||||||||||||||||
3837 | /*! | - | ||||||||||||||||||
3838 | \internal | - | ||||||||||||||||||
3839 | */ | - | ||||||||||||||||||
3840 | void QAbstractItemView::stopAutoScroll() | - | ||||||||||||||||||
3841 | { | - | ||||||||||||||||||
3842 | d_func()->stopAutoScroll(); | - | ||||||||||||||||||
3843 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
3859 | QAbstractScrollArea *parent = qobject_cast<QAbstractScrollArea*>(parentWidget()); | - | ||||||||||||||||||
3860 | if (parent) { | - | ||||||||||||||||||
3861 | if (hv->orientation() == Qt::Horizontal) { | - | ||||||||||||||||||
3862 | if (!hv->horizontalScrollBar() || !hv->horizontalScrollBar()->isVisible()) | - | ||||||||||||||||||
3863 | horizontalScroll = parent->horizontalScrollBar(); | - | ||||||||||||||||||
3864 | } else { | - | ||||||||||||||||||
3865 | if (!hv->verticalScrollBar() || !hv->verticalScrollBar()->isVisible()) | - | ||||||||||||||||||
3866 | verticalScroll = parent->verticalScrollBar(); | - | ||||||||||||||||||
3867 | } | - | ||||||||||||||||||
3868 | } | - | ||||||||||||||||||
3869 | } | - | ||||||||||||||||||
3870 | - | |||||||||||||||||||
3871 | int verticalStep = verticalScroll->pageStep(); | - | ||||||||||||||||||
3872 | int horizontalStep = horizontalScroll->pageStep(); | - | ||||||||||||||||||
3873 | if (d->autoScrollCount < qMax(verticalStep, horizontalStep)) | - | ||||||||||||||||||
3874 | ++d->autoScrollCount; | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
3885 | verticalScroll->setValue(verticalValue - d->autoScrollCount); | - | ||||||||||||||||||
3886 | else if (area.bottom() - pos.y() < margin) | - | ||||||||||||||||||
3887 | verticalScroll->setValue(verticalValue + d->autoScrollCount); | - | ||||||||||||||||||
3888 | if (pos.x() - area.left() < margin) | - | ||||||||||||||||||
3889 | horizontalScroll->setValue(horizontalValue - d->autoScrollCount); | - | ||||||||||||||||||
3890 | else if (area.right() - pos.x() < margin) | - | ||||||||||||||||||
3891 | horizontalScroll->setValue(horizontalValue + d->autoScrollCount); | - | ||||||||||||||||||
3892 | // if nothing changed, stop scrolling | - | ||||||||||||||||||
3893 | bool verticalUnchanged = (verticalValue == verticalScroll->value()); | - | ||||||||||||||||||
3894 | bool horizontalUnchanged = (horizontalValue == horizontalScroll->value()); | - | ||||||||||||||||||
3895 | if (verticalUnchanged && horizontalUnchanged) { | - | ||||||||||||||||||
3896 | stopAutoScroll(); | - | ||||||||||||||||||
3897 | } else { | - | ||||||||||||||||||
3898 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
3899 | d->dropIndicatorRect = QRect(); | - | ||||||||||||||||||
3900 | d->dropIndicatorPosition = QAbstractItemView::OnViewport; | - | ||||||||||||||||||
3901 | #endif | - | ||||||||||||||||||
3902 | d->viewport->update(); | - | ||||||||||||||||||
3903 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
3921 | switch (event->type()) { | - | ||||||||||||||||||
3922 | case QEvent::MouseButtonDblClick: | - | ||||||||||||||||||
3923 | case QEvent::MouseButtonPress: | - | ||||||||||||||||||
3924 | case QEvent::MouseButtonRelease: | - | ||||||||||||||||||
3925 | case QEvent::MouseMove: | - | ||||||||||||||||||
3926 | case QEvent::KeyPress: | - | ||||||||||||||||||
3927 | case QEvent::KeyRelease: | - | ||||||||||||||||||
3928 | keyModifiers = (static_cast<const QInputEvent*>(event))->modifiers(); | - | ||||||||||||||||||
3929 | break; | - | ||||||||||||||||||
3930 | default: | - | ||||||||||||||||||
3931 | keyModifiers = QApplication::keyboardModifiers(); | - | ||||||||||||||||||
3932 | } | - | ||||||||||||||||||
3933 | } | - | ||||||||||||||||||
3934 | switch (d->selectionMode) { | - | ||||||||||||||||||
3935 | case NoSelection: // Never update selection model | - | ||||||||||||||||||
3936 | return QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
3937 | case SingleSelection: // ClearAndSelect on valid index otherwise NoUpdate | - | ||||||||||||||||||
3938 | if (event && event->type() == QEvent::MouseButtonRelease) | - | ||||||||||||||||||
3939 | return QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
3940 | if ((keyModifiers & Qt::ControlModifier) && d->selectionModel->isSelected(index)) | - | ||||||||||||||||||
3941 | return QItemSelectionModel::Deselect | d->selectionBehaviorFlags(); | - | ||||||||||||||||||
3942 | else | - | ||||||||||||||||||
3943 | return QItemSelectionModel::ClearAndSelect | d->selectionBehaviorFlags(); | - | ||||||||||||||||||
3944 | case MultiSelection: | - | ||||||||||||||||||
3945 | return d->multiSelectionCommand(index, event); | - | ||||||||||||||||||
3946 | case ExtendedSelection: | - | ||||||||||||||||||
3947 | return d->extendedSelectionCommand(index, event); | - | ||||||||||||||||||
3948 | case ContiguousSelection: | - | ||||||||||||||||||
3949 | return d->contiguousSelectionCommand(index, event); | - | ||||||||||||||||||
3950 | } | - | ||||||||||||||||||
3951 | return QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
3952 | } | - | ||||||||||||||||||
3953 | - | |||||||||||||||||||
3954 | QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::multiSelectionCommand( | - | ||||||||||||||||||
3955 | const QModelIndex &index, const QEvent *event) const | - | ||||||||||||||||||
3956 | { | - | ||||||||||||||||||
3957 | Q_UNUSED(index) | - | ||||||||||||||||||
3958 | - | |||||||||||||||||||
3959 | if (event) { | - | ||||||||||||||||||
3960 | switch (event->type()) { | - | ||||||||||||||||||
3961 | case QEvent::KeyPress: | - | ||||||||||||||||||
3962 | if (static_cast<const QKeyEvent*>(event)->key() == Qt::Key_Space | - | ||||||||||||||||||
3963 | || static_cast<const QKeyEvent*>(event)->key() == Qt::Key_Select) | - | ||||||||||||||||||
3964 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | - | ||||||||||||||||||
3965 | break; | - | ||||||||||||||||||
3966 | case QEvent::MouseButtonPress: | - | ||||||||||||||||||
3967 | if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton) | - | ||||||||||||||||||
3968 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); // toggle | - | ||||||||||||||||||
3969 | break; | - | ||||||||||||||||||
3970 | case QEvent::MouseButtonRelease: | - | ||||||||||||||||||
3971 | if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton) | - | ||||||||||||||||||
3972 | return QItemSelectionModel::NoUpdate|selectionBehaviorFlags(); // finalize | - | ||||||||||||||||||
3973 | break; | - | ||||||||||||||||||
3974 | case QEvent::MouseMove: | - | ||||||||||||||||||
3975 | if (static_cast<const QMouseEvent*>(event)->buttons() & Qt::LeftButton) | - | ||||||||||||||||||
3976 | return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); // toggle drag select | - | ||||||||||||||||||
3977 | default: | - | ||||||||||||||||||
3978 | break; | - | ||||||||||||||||||
3979 | } | - | ||||||||||||||||||
3980 | return QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
3981 | } | - | ||||||||||||||||||
3982 | - | |||||||||||||||||||
3983 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
3991 | switch (event->type()) { | - | ||||||||||||||||||
3992 | case QEvent::MouseMove: { | - | ||||||||||||||||||
3993 | // Toggle on MouseMove | - | ||||||||||||||||||
3994 | modifiers = static_cast<const QMouseEvent*>(event)->modifiers(); | - | ||||||||||||||||||
3995 | if (modifiers & Qt::ControlModifier) | - | ||||||||||||||||||
3996 | return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); | - | ||||||||||||||||||
3997 | break; | - | ||||||||||||||||||
3998 | } | - | ||||||||||||||||||
3999 | case QEvent::MouseButtonPress: { | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
4007 | return QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
4008 | if (!shiftKeyPressed && !controlKeyPressed && indexIsSelected) | - | ||||||||||||||||||
4009 | return QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
4010 | if (!index.isValid() && !rightButtonPressed && !shiftKeyPressed && !controlKeyPressed) | - | ||||||||||||||||||
4011 | return QItemSelectionModel::Clear; | - | ||||||||||||||||||
4012 | if (!index.isValid()) | - | ||||||||||||||||||
4013 | return QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
4014 | break; | - | ||||||||||||||||||
4015 | } | - | ||||||||||||||||||
4016 | case QEvent::MouseButtonRelease: { | - | ||||||||||||||||||
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)) | - | ||||||||||||||||||
4024 | || !index.isValid()) && state != QAbstractItemView::DragSelectingState | - | ||||||||||||||||||
4025 | && !shiftKeyPressed && !controlKeyPressed && (!rightButtonPressed || !index.isValid())) | - | ||||||||||||||||||
4026 | return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); | - | ||||||||||||||||||
4027 | return QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
4028 | } | - | ||||||||||||||||||
4029 | case QEvent::KeyPress: { | - | ||||||||||||||||||
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: | - | ||||||||||||||||||
4034 | modifiers = modifiers & ~Qt::ShiftModifier; // special case for backtab | - | ||||||||||||||||||
4035 | case Qt::Key_Down: | - | ||||||||||||||||||
4036 | case Qt::Key_Up: | - | ||||||||||||||||||
4037 | case Qt::Key_Left: | - | ||||||||||||||||||
4038 | case Qt::Key_Right: | - | ||||||||||||||||||
4039 | case Qt::Key_Home: | - | ||||||||||||||||||
4040 | case Qt::Key_End: | - | ||||||||||||||||||
4041 | case Qt::Key_PageUp: | - | ||||||||||||||||||
4042 | case Qt::Key_PageDown: | - | ||||||||||||||||||
4043 | case Qt::Key_Tab: | - | ||||||||||||||||||
4044 | if (modifiers & Qt::ControlModifier | - | ||||||||||||||||||
4045 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||
4046 | // Preserve historical tab order navigation behavior | - | ||||||||||||||||||
4047 | || QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder | - | ||||||||||||||||||
4048 | #endif | - | ||||||||||||||||||
4049 | ) | - | ||||||||||||||||||
4050 | return QItemSelectionModel::NoUpdate; | - | ||||||||||||||||||
4051 | break; | - | ||||||||||||||||||
4052 | case Qt::Key_Select: | - | ||||||||||||||||||
4053 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | - | ||||||||||||||||||
4054 | case Qt::Key_Space:// Toggle on Ctrl-Qt::Key_Space, Select on Space | - | ||||||||||||||||||
4055 | if (modifiers & Qt::ControlModifier) | - | ||||||||||||||||||
4056 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | - | ||||||||||||||||||
4057 | return QItemSelectionModel::Select|selectionBehaviorFlags(); | - | ||||||||||||||||||
4058 | default: | - | ||||||||||||||||||
4059 | break; | - | ||||||||||||||||||
4060 | } | - | ||||||||||||||||||
4061 | } | - | ||||||||||||||||||
4062 | default: | - | ||||||||||||||||||
4063 | break; | - | ||||||||||||||||||
4064 | } | - | ||||||||||||||||||
4065 | } | - | ||||||||||||||||||
4066 | - | |||||||||||||||||||
4067 | if (modifiers & Qt::ShiftModifier) | - | ||||||||||||||||||
4068 | return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); | - | ||||||||||||||||||
4069 | if (modifiers & Qt::ControlModifier) | - | ||||||||||||||||||
4070 | return QItemSelectionModel::Toggle|selectionBehaviorFlags(); | - | ||||||||||||||||||
4071 | if (state == QAbstractItemView::DragSelectingState) { | - | ||||||||||||||||||
4072 | //when drag-selecting we need to clear any previous selection and select the current one | - | ||||||||||||||||||
4073 | return QItemSelectionModel::Clear|QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); | - | ||||||||||||||||||
4074 | } | - | ||||||||||||||||||
4075 | - | |||||||||||||||||||
4076 | return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); | - | ||||||||||||||||||
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: | - | ||||||||||||||||||
4090 | case QItemSelectionModel::ClearAndSelect: | - | ||||||||||||||||||
4091 | case QItemSelectionModel::SelectCurrent: | - | ||||||||||||||||||
4092 | return flags; | - | ||||||||||||||||||
4093 | case QItemSelectionModel::NoUpdate: | - | ||||||||||||||||||
4094 | if (event && | - | ||||||||||||||||||
4095 | (event->type() == QEvent::MouseButtonPress | - | ||||||||||||||||||
4096 | || event->type() == QEvent::MouseButtonRelease)) | - | ||||||||||||||||||
4097 | return flags; | - | ||||||||||||||||||
4098 | return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); | - | ||||||||||||||||||
4099 | default: | - | ||||||||||||||||||
4100 | return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); | - | ||||||||||||||||||
4101 | } | - | ||||||||||||||||||
4102 | } | - | ||||||||||||||||||
4103 | - | |||||||||||||||||||
4104 | void QAbstractItemViewPrivate::fetchMore() | - | ||||||||||||||||||
4105 | { | - | ||||||||||||||||||
4106 | fetchMoreTimer.stop(); | - | ||||||||||||||||||
4107 | if (!model->canFetchMore(root)) | - | ||||||||||||||||||
4108 | return; | - | ||||||||||||||||||
4109 | int last = model->rowCount(root) - 1; | - | ||||||||||||||||||
4110 | if (last < 0) { | - | ||||||||||||||||||
4111 | model->fetchMore(root); | - | ||||||||||||||||||
4112 | return; | - | ||||||||||||||||||
4113 | } | - | ||||||||||||||||||
4114 | - | |||||||||||||||||||
4115 | QModelIndex index = model->index(last, 0, root); | - | ||||||||||||||||||
4116 | QRect rect = q_func()->visualRect(index); | - | ||||||||||||||||||
4117 | if (viewport->rect().intersects(rect)) | - | ||||||||||||||||||
4118 | model->fetchMore(root); | - | ||||||||||||||||||
4119 | } | - | ||||||||||||||||||
4120 | - | |||||||||||||||||||
4121 | bool QAbstractItemViewPrivate::shouldEdit(QAbstractItemView::EditTrigger trigger, | - | ||||||||||||||||||
4122 | const QModelIndex &index) const | - | ||||||||||||||||||
4123 | { | - | ||||||||||||||||||
4124 | if (!index.isValid()) | - | ||||||||||||||||||
4125 | return false; | - | ||||||||||||||||||
4126 | Qt::ItemFlags flags = model->flags(index); | - | ||||||||||||||||||
4127 | if (((flags & Qt::ItemIsEditable) == 0) || ((flags & Qt::ItemIsEnabled) == 0)) | - | ||||||||||||||||||
4128 | return false; | - | ||||||||||||||||||
4129 | if (state == QAbstractItemView::EditingState) | - | ||||||||||||||||||
4130 | return false; | - | ||||||||||||||||||
4131 | if (hasEditor(index)) | - | ||||||||||||||||||
4132 | return false; | - | ||||||||||||||||||
4133 | if (trigger == QAbstractItemView::AllEditTriggers) // force editing | - | ||||||||||||||||||
4134 | return true; | - | ||||||||||||||||||
4135 | if ((trigger & editTriggers) == QAbstractItemView::SelectedClicked | - | ||||||||||||||||||
4136 | && !selectionModel->isSelected(index)) | - | ||||||||||||||||||
4137 | return false; | - | ||||||||||||||||||
4138 | return (trigger & editTriggers); | - | ||||||||||||||||||
4139 | } | - | ||||||||||||||||||
4140 | - | |||||||||||||||||||
4141 | bool QAbstractItemViewPrivate::shouldForwardEvent(QAbstractItemView::EditTrigger trigger, | - | ||||||||||||||||||
4142 | const QEvent *event) const | - | ||||||||||||||||||
4143 | { | - | ||||||||||||||||||
4144 | if (!event || (trigger & editTriggers) != QAbstractItemView::AnyKeyPressed) | - | ||||||||||||||||||
4145 | return false; | - | ||||||||||||||||||
4146 | - | |||||||||||||||||||
4147 | switch (event->type()) { | - | ||||||||||||||||||
4148 | case QEvent::KeyPress: | - | ||||||||||||||||||
4149 | case QEvent::MouseButtonDblClick: | - | ||||||||||||||||||
4150 | case QEvent::MouseButtonPress: | - | ||||||||||||||||||
4151 | case QEvent::MouseButtonRelease: | - | ||||||||||||||||||
4152 | case QEvent::MouseMove: | - | ||||||||||||||||||
4153 | return true; | - | ||||||||||||||||||
4154 | default: | - | ||||||||||||||||||
4155 | break; | - | ||||||||||||||||||
4156 | }; | - | ||||||||||||||||||
4157 | - | |||||||||||||||||||
4158 | return false; | - | ||||||||||||||||||
4159 | } | - | ||||||||||||||||||
4160 | - | |||||||||||||||||||
4161 | bool QAbstractItemViewPrivate::shouldAutoScroll(const QPoint &pos) const | - | ||||||||||||||||||
4162 | { | - | ||||||||||||||||||
4163 | if (!autoScroll) | - | ||||||||||||||||||
4164 | return false; | - | ||||||||||||||||||
4165 | QRect area = static_cast<QAbstractItemView*>(viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules | - | ||||||||||||||||||
4166 | return (pos.y() - area.top() < autoScrollMargin) | - | ||||||||||||||||||
4167 | || (area.bottom() - pos.y() < autoScrollMargin) | - | ||||||||||||||||||
4168 | || (pos.x() - area.left() < autoScrollMargin) | - | ||||||||||||||||||
4169 | || (area.right() - pos.x() < autoScrollMargin); | - | ||||||||||||||||||
4170 | } | - | ||||||||||||||||||
4171 | - | |||||||||||||||||||
4172 | void QAbstractItemViewPrivate::doDelayedItemsLayout(int delay) | - | ||||||||||||||||||
4173 | { | - | ||||||||||||||||||
4174 | if (!delayedPendingLayout) { | - | ||||||||||||||||||
4175 | delayedPendingLayout = true; | - | ||||||||||||||||||
4176 | delayedLayout.start(delay, q_func()); | - | ||||||||||||||||||
4177 | } | - | ||||||||||||||||||
4178 | } | - | ||||||||||||||||||
4179 | - | |||||||||||||||||||
4180 | void QAbstractItemViewPrivate::interruptDelayedItemsLayout() const | - | ||||||||||||||||||
4181 | { | - | ||||||||||||||||||
4182 | delayedLayout.stop(); | - | ||||||||||||||||||
4183 | delayedPendingLayout = false; | - | ||||||||||||||||||
4184 | } | - | ||||||||||||||||||
4185 | - | |||||||||||||||||||
4186 | void QAbstractItemViewPrivate::updateGeometry() | - | ||||||||||||||||||
4187 | { | - | ||||||||||||||||||
4188 | Q_Q(QAbstractItemView); | - | ||||||||||||||||||
4189 | if (sizeAdjustPolicy == QAbstractScrollArea::AdjustIgnored) | - | ||||||||||||||||||
4190 | return; | - | ||||||||||||||||||
4191 | if (sizeAdjustPolicy == QAbstractScrollArea::AdjustToContents || !shownOnce) | - | ||||||||||||||||||
4192 | q->updateGeometry(); | - | ||||||||||||||||||
4193 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
4201 | QAbstractItemDelegate *delegate = delegateForIndex(index); | - | ||||||||||||||||||
4202 | if (!delegate) | - | ||||||||||||||||||
4203 | return 0; | - | ||||||||||||||||||
4204 | w = delegate->createEditor(viewport, options, index); | - | ||||||||||||||||||
4205 | if (w) { | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
4212 | QWidget::setTabOrder(q, w); | - | ||||||||||||||||||
4213 | - | |||||||||||||||||||
4214 | // Special cases for some editors containing QLineEdit | - | ||||||||||||||||||
4215 | QWidget *focusWidget = w; | - | ||||||||||||||||||
4216 | while (QWidget *fp = focusWidget->focusProxy()) | - | ||||||||||||||||||
4217 | focusWidget = fp; | - | ||||||||||||||||||
4218 | #ifndef QT_NO_LINEEDIT | - | ||||||||||||||||||
4219 | if (QLineEdit *le = qobject_cast<QLineEdit*>(focusWidget)) | - | ||||||||||||||||||
4220 | le->selectAll(); | - | ||||||||||||||||||
4221 | #endif | - | ||||||||||||||||||
4222 | #ifndef QT_NO_SPINBOX | - | ||||||||||||||||||
4223 | if (QSpinBox *sb = qobject_cast<QSpinBox*>(focusWidget)) | - | ||||||||||||||||||
4224 | sb->selectAll(); | - | ||||||||||||||||||
4225 | else if (QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox*>(focusWidget)) | - | ||||||||||||||||||
4226 | dsb->selectAll(); | - | ||||||||||||||||||
4227 | #endif | - | ||||||||||||||||||
4228 | } | - | ||||||||||||||||||
4229 | } | - | ||||||||||||||||||
4230 | - | |||||||||||||||||||
4231 | return w; | - | ||||||||||||||||||
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(); | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
4245 | QWidget *editor = it.value().widget.data(); | - | ||||||||||||||||||
4246 | const QModelIndex index = it.key(); | - | ||||||||||||||||||
4247 | if (it.value().isStatic || !editor || !index.isValid() || | - | ||||||||||||||||||
4248 | (checkIndexes | - | ||||||||||||||||||
4249 | && (index.row() < tl.row() || index.row() > br.row() | - | ||||||||||||||||||
4250 | || index.column() < tl.column() || index.column() > br.column() | - | ||||||||||||||||||
4251 | || index.parent() != parent))) | - | ||||||||||||||||||
4252 | continue; | - | ||||||||||||||||||
4253 | - | |||||||||||||||||||
4254 | QAbstractItemDelegate *delegate = delegateForIndex(index); | - | ||||||||||||||||||
4255 | if (delegate) { | - | ||||||||||||||||||
4256 | delegate->setEditorData(editor, index); | - | ||||||||||||||||||
4257 | } | - | ||||||||||||||||||
4258 | } | - | ||||||||||||||||||
4259 | } | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
4277 | for (; it != selection.constEnd(); ++it) { | - | ||||||||||||||||||
4278 | QModelIndex parent = (*it).parent(); | - | ||||||||||||||||||
4279 | if ((*it).left() != 0) | - | ||||||||||||||||||
4280 | continue; | - | ||||||||||||||||||
4281 | if ((*it).right() != (model->columnCount(parent) - 1)) | - | ||||||||||||||||||
4282 | continue; | - | ||||||||||||||||||
4283 | int count = (*it).bottom() - (*it).top() + 1; | - | ||||||||||||||||||
4284 | model->removeRows((*it).top(), count, parent); | - | ||||||||||||||||||
4285 | } | - | ||||||||||||||||||
4286 | } else { | - | ||||||||||||||||||
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) { | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
4293 | it.value() = QVariant(); | - | ||||||||||||||||||
4294 | model->setItemData(index, roles); | - | ||||||||||||||||||
4295 | } | - | ||||||||||||||||||
4296 | } | - | ||||||||||||||||||
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()) { | - | ||||||||||||||||||
4310 | if (persistent.contains(widget)) { | - | ||||||||||||||||||
4311 | //a persistent editor has gained the focus | - | ||||||||||||||||||
4312 | QModelIndex index = indexForEditor(widget); | - | ||||||||||||||||||
4313 | if (selectionModel->currentIndex() != index) | - | ||||||||||||||||||
4314 | q->setCurrentIndex(index); | - | ||||||||||||||||||
4315 | } | - | ||||||||||||||||||
4316 | } | - | ||||||||||||||||||
4317 | } | - | ||||||||||||||||||
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()) | - | ||||||||||||||||||
4326 | return nullInfo; | - | ||||||||||||||||||
4327 | - | |||||||||||||||||||
4328 | QIndexEditorHash::const_iterator it = indexEditorHash.find(index); | - | ||||||||||||||||||
4329 | if (it == indexEditorHash.end()) | - | ||||||||||||||||||
4330 | return nullInfo; | - | ||||||||||||||||||
4331 | - | |||||||||||||||||||
4332 | return it.value(); | - | ||||||||||||||||||
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.find(index) !=isEmpty() && indexEditorHash.constEnd();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()) | - | ||||||||||||||||||
4345 | return QModelIndex(); | - | ||||||||||||||||||
4346 | - | |||||||||||||||||||
4347 | QEditorIndexHash::const_iterator it = editorIndexHash.find(editor); | - | ||||||||||||||||||
4348 | if (it == editorIndexHash.end()) | - | ||||||||||||||||||
4349 | return QModelIndex(); | - | ||||||||||||||||||
4350 | - | |||||||||||||||||||
4351 | return it.value(); | - | ||||||||||||||||||
4352 | } | - | ||||||||||||||||||
4353 | - | |||||||||||||||||||
4354 | void QAbstractItemViewPrivate::removeEditor(QWidget *editor) | - | ||||||||||||||||||
4355 | { | - | ||||||||||||||||||
4356 | QEditorIndexHash::iteratorconst auto it = editorIndexHash.findconstFind(editor); | - | ||||||||||||||||||
4357 | if (it != editorIndexHash.endcend()) {
| 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 | } | - | ||||||||||||||||||
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); | - | ||||||||||||||||||
4376 | QAbstractItemDelegate *delegate = delegateForIndex(index); | - | ||||||||||||||||||
4377 | return (event && delegate && delegate->editorEvent(event, model, options, buddy)); | - | ||||||||||||||||||
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); | - | ||||||||||||||||||
4388 | - | |||||||||||||||||||
4389 | QWidget *w = editor(buddy, options); | - | ||||||||||||||||||
4390 | if (!w) | - | ||||||||||||||||||
4391 | return false; | - | ||||||||||||||||||
4392 | - | |||||||||||||||||||
4393 | q->setState(QAbstractItemView::EditingState); | - | ||||||||||||||||||
4394 | w->show(); | - | ||||||||||||||||||
4395 | w->setFocus(); | - | ||||||||||||||||||
4396 | - | |||||||||||||||||||
4397 | if (event) | - | ||||||||||||||||||
4398 | QApplication::sendEvent(w->focusProxy() ? w->focusProxy() : w, event); | - | ||||||||||||||||||
4399 | - | |||||||||||||||||||
4400 | return true; | - | ||||||||||||||||||
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 (int i = 0; i < indexes.count(); ++i) {const QModelIndexauto &index =: indexes.at(i);) { | - | ||||||||||||||||||
4417 | const QRect current = q->visualRect(index); | - | ||||||||||||||||||
4418 | if (current.intersects(viewportRect)) {
| 0 | ||||||||||||||||||
4419 | ret += qMakePair(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).firstrect.translated(-r->topLeft()); | - | ||||||||||||||||||
4454 | const QModelIndex ¤t = paintPairs.at(j).secondindex; | - | ||||||||||||||||||
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) | - | ||||||||||||||||||
4464 | return; | - | ||||||||||||||||||
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 | } | - | ||||||||||||||||||
4474 | - | |||||||||||||||||||
4475 | QModelIndexList QAbstractItemViewPrivate::selectedDraggableIndexes() const | - | ||||||||||||||||||
4476 | { | - | ||||||||||||||||||
4477 | Q_Q(const QAbstractItemView); | - | ||||||||||||||||||
4478 | QModelIndexList indexes = q->selectedIndexes(); | - | ||||||||||||||||||
4479 | for(int iauto isNotDragEnabled = indexes.count() - 1 ; i >= 0; --i[this](const QModelIndex &index) { | - | ||||||||||||||||||
4480 | if (!return !isIndexDragEnabled(index); never executed: return !isIndexDragEnabled(index); | 0 | ||||||||||||||||||
4481 | }; | - | ||||||||||||||||||
4482 | indexes.aterase(i)))std::remove_if(indexes.removeAt(i); | - | ||||||||||||||||||
}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 |