author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qabstractitemview.h" |
|
43 |
||
44 |
#ifndef QT_NO_ITEMVIEWS |
|
45 |
#include <qpointer.h> |
|
46 |
#include <qapplication.h> |
|
47 |
#include <qclipboard.h> |
|
48 |
#include <qpainter.h> |
|
49 |
#include <qstyle.h> |
|
50 |
#include <qdrag.h> |
|
51 |
#include <qevent.h> |
|
52 |
#include <qscrollbar.h> |
|
53 |
#include <qwhatsthis.h> |
|
54 |
#include <qtooltip.h> |
|
55 |
#include <qdatetime.h> |
|
56 |
#include <qlineedit.h> |
|
57 |
#include <qspinbox.h> |
|
58 |
#include <qstyleditemdelegate.h> |
|
59 |
#include <private/qabstractitemview_p.h> |
|
60 |
#include <private/qabstractitemmodel_p.h> |
|
61 |
#ifndef QT_NO_ACCESSIBILITY |
|
62 |
#include <qaccessible.h> |
|
63 |
#endif |
|
64 |
#include <private/qsoftkeymanager_p.h> |
|
65 |
||
66 |
QT_BEGIN_NAMESPACE |
|
67 |
||
68 |
QAbstractItemViewPrivate::QAbstractItemViewPrivate() |
|
69 |
: model(QAbstractItemModelPrivate::staticEmptyModel()), |
|
70 |
itemDelegate(0), |
|
71 |
selectionModel(0), |
|
72 |
ctrlDragSelectionFlag(QItemSelectionModel::NoUpdate), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
noSelectionOnMousePress(false), |
0 | 74 |
selectionMode(QAbstractItemView::ExtendedSelection), |
75 |
selectionBehavior(QAbstractItemView::SelectItems), |
|
76 |
currentlyCommittingEditor(0), |
|
77 |
pressedModifiers(Qt::NoModifier), |
|
78 |
pressedPosition(QPoint(-1, -1)), |
|
79 |
pressedAlreadySelected(false), |
|
80 |
viewportEnteredNeeded(false), |
|
81 |
state(QAbstractItemView::NoState), |
|
82 |
editTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed), |
|
83 |
lastTrigger(QAbstractItemView::NoEditTriggers), |
|
84 |
tabKeyNavigation(false), |
|
85 |
#ifndef QT_NO_DRAGANDDROP |
|
86 |
showDropIndicator(true), |
|
87 |
dragEnabled(false), |
|
88 |
dragDropMode(QAbstractItemView::NoDragDrop), |
|
89 |
overwrite(false), |
|
90 |
dropIndicatorPosition(QAbstractItemView::OnItem), |
|
91 |
defaultDropAction(Qt::IgnoreAction), |
|
92 |
#endif |
|
93 |
#ifdef QT_SOFTKEYS_ENABLED |
|
94 |
doneSoftKey(0), |
|
95 |
#endif |
|
96 |
autoScroll(true), |
|
97 |
autoScrollMargin(16), |
|
98 |
autoScrollCount(0), |
|
99 |
shouldScrollToCurrentOnShow(false), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
shouldClearStatusTip(false), |
0 | 101 |
alternatingColors(false), |
102 |
textElideMode(Qt::ElideRight), |
|
103 |
verticalScrollMode(QAbstractItemView::ScrollPerItem), |
|
104 |
horizontalScrollMode(QAbstractItemView::ScrollPerItem), |
|
105 |
currentIndexSet(false), |
|
106 |
wrapItemText(false), |
|
107 |
delayedPendingLayout(false) |
|
108 |
{ |
|
109 |
} |
|
110 |
||
111 |
QAbstractItemViewPrivate::~QAbstractItemViewPrivate() |
|
112 |
{ |
|
113 |
} |
|
114 |
||
115 |
void QAbstractItemViewPrivate::init() |
|
116 |
{ |
|
117 |
Q_Q(QAbstractItemView); |
|
118 |
q->setItemDelegate(new QStyledItemDelegate(q)); |
|
119 |
||
120 |
vbar->setRange(0, 0); |
|
121 |
hbar->setRange(0, 0); |
|
122 |
||
123 |
QObject::connect(vbar, SIGNAL(actionTriggered(int)), |
|
124 |
q, SLOT(verticalScrollbarAction(int))); |
|
125 |
QObject::connect(hbar, SIGNAL(actionTriggered(int)), |
|
126 |
q, SLOT(horizontalScrollbarAction(int))); |
|
127 |
QObject::connect(vbar, SIGNAL(valueChanged(int)), |
|
128 |
q, SLOT(verticalScrollbarValueChanged(int))); |
|
129 |
QObject::connect(hbar, SIGNAL(valueChanged(int)), |
|
130 |
q, SLOT(horizontalScrollbarValueChanged(int))); |
|
131 |
||
132 |
viewport->setBackgroundRole(QPalette::Base); |
|
133 |
||
134 |
doDelayedItemsLayout(); |
|
135 |
||
136 |
q->setAttribute(Qt::WA_InputMethodEnabled); |
|
137 |
||
138 |
#ifdef QT_SOFTKEYS_ENABLED |
|
139 |
doneSoftKey = QSoftKeyManager::createKeyedAction(QSoftKeyManager::DoneSoftKey, Qt::Key_Back, q); |
|
140 |
#endif |
|
141 |
} |
|
142 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
void QAbstractItemViewPrivate::setHoverIndex(const QPersistentModelIndex &index) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
Q_Q(QAbstractItemView); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
if (hover == index) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
149 |
if (selectionBehavior != QAbstractItemView::SelectRows) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
150 |
q->update(hover); //update the old one |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
151 |
q->update(index); //update the new one |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
152 |
} else { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
153 |
QRect oldHoverRect = q->visualRect(hover); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
154 |
QRect newHoverRect = q->visualRect(index); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
155 |
viewport->update(QRect(0, newHoverRect.y(), viewport->width(), newHoverRect.height())); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
156 |
viewport->update(QRect(0, oldHoverRect.y(), viewport->width(), oldHoverRect.height())); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
157 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
hover = index; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
|
0 | 161 |
void QAbstractItemViewPrivate::checkMouseMove(const QPersistentModelIndex &index) |
162 |
{ |
|
163 |
//we take a persistent model index because the model might change by emitting signals |
|
164 |
Q_Q(QAbstractItemView); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
setHoverIndex(index); |
0 | 166 |
if (viewportEnteredNeeded || enteredIndex != index) { |
167 |
viewportEnteredNeeded = false; |
|
168 |
||
169 |
if (index.isValid()) { |
|
170 |
emit q->entered(index); |
|
171 |
#ifndef QT_NO_STATUSTIP |
|
172 |
QString statustip = model->data(index, Qt::StatusTipRole).toString(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
if (parent && (shouldClearStatusTip || !statustip.isEmpty())) { |
0 | 174 |
QStatusTipEvent tip(statustip); |
175 |
QApplication::sendEvent(parent, &tip); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
shouldClearStatusTip = !statustip.isEmpty(); |
0 | 177 |
} |
178 |
#endif |
|
179 |
} else { |
|
180 |
#ifndef QT_NO_STATUSTIP |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
if (parent && shouldClearStatusTip) { |
0 | 182 |
QString emptyString; |
183 |
QStatusTipEvent tip( emptyString ); |
|
184 |
QApplication::sendEvent(parent, &tip); |
|
185 |
} |
|
186 |
#endif |
|
187 |
emit q->viewportEntered(); |
|
188 |
} |
|
189 |
enteredIndex = index; |
|
190 |
} |
|
191 |
} |
|
192 |
||
193 |
||
194 |
/*! |
|
195 |
\class QAbstractItemView |
|
196 |
||
197 |
\brief The QAbstractItemView class provides the basic functionality for |
|
198 |
item view classes. |
|
199 |
||
200 |
\ingroup model-view |
|
201 |
||
202 |
||
203 |
QAbstractItemView class is the base class for every standard view |
|
204 |
that uses a QAbstractItemModel. QAbstractItemView is an abstract |
|
205 |
class and cannot itself be instantiated. It provides a standard |
|
206 |
interface for interoperating with models through the signals and |
|
207 |
slots mechanism, enabling subclasses to be kept up-to-date with |
|
208 |
changes to their models. This class provides standard support for |
|
209 |
keyboard and mouse navigation, viewport scrolling, item editing, |
|
210 |
and selections. The keyboard navigation implements this |
|
211 |
functionality: |
|
212 |
||
213 |
\table |
|
214 |
\header |
|
215 |
\o Keys |
|
216 |
\o Functionality |
|
217 |
\row |
|
218 |
\o Arrow keys |
|
219 |
\o Changes the current item and selects it. |
|
220 |
\row |
|
221 |
\o Ctrl+Arrow keys |
|
222 |
\o Changes the current item but does not select it. |
|
223 |
\row |
|
224 |
\o Shift+Arrow keys |
|
225 |
\o Changes the current item and selects it. The previously |
|
226 |
selected item(s) is not deselected. |
|
227 |
\row |
|
228 |
\o Ctr+Space |
|
229 |
\o Toggles selection of the current item. |
|
230 |
\row |
|
231 |
\o Tab/Backtab |
|
232 |
\o Changes the current item to the next/previous item. |
|
233 |
\row |
|
234 |
\o Home/End |
|
235 |
\o Selects the first/last item in the model. |
|
236 |
\row |
|
237 |
\o Page up/Page down |
|
238 |
\o Scrolls the rows shown up/down by the number of |
|
239 |
visible rows in the view. |
|
240 |
\row |
|
241 |
\o Ctrl+A |
|
242 |
\o Selects all items in the model. |
|
243 |
\endtable |
|
244 |
||
245 |
Note that the above table assumes that the |
|
246 |
\l{selectionMode}{selection mode} allows the operations. For |
|
247 |
instance, you cannot select items if the selection mode is |
|
248 |
QAbstractItemView::NoSelection. |
|
249 |
||
250 |
The QAbstractItemView class is one of the \l{Model/View Classes} |
|
251 |
and is part of Qt's \l{Model/View Programming}{model/view framework}. |
|
252 |
||
253 |
The view classes that inherit QAbstractItemView only need |
|
254 |
to implement their own view-specific functionality, such as |
|
255 |
drawing items, returning the geometry of items, finding items, |
|
256 |
etc. |
|
257 |
||
258 |
QAbstractItemView provides common slots such as edit() and |
|
259 |
setCurrentIndex(). Many protected slots are also provided, including |
|
260 |
dataChanged(), rowsInserted(), rowsAboutToBeRemoved(), selectionChanged(), |
|
261 |
and currentChanged(). |
|
262 |
||
263 |
The root item is returned by rootIndex(), and the current item by |
|
264 |
currentIndex(). To make sure that an item is visible use |
|
265 |
scrollTo(). |
|
266 |
||
267 |
Some of QAbstractItemView's functions are concerned with |
|
268 |
scrolling, for example setHorizontalScrollMode() and |
|
269 |
setVerticalScrollMode(). To set the range of the scroll bars, you |
|
270 |
can, for example, reimplement the view's resizeEvent() function: |
|
271 |
||
272 |
\snippet doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp 0 |
|
273 |
||
274 |
Note that the range is not updated until the widget is shown. |
|
275 |
||
276 |
Several other functions are concerned with selection control; for |
|
277 |
example setSelectionMode(), and setSelectionBehavior(). This class |
|
278 |
provides a default selection model to work with |
|
279 |
(selectionModel()), but this can be replaced by using |
|
280 |
setSelectionModel() with an instance of QItemSelectionModel. |
|
281 |
||
282 |
For complete control over the display and editing of items you can |
|
283 |
specify a delegate with setItemDelegate(). |
|
284 |
||
285 |
QAbstractItemView provides a lot of protected functions. Some are |
|
286 |
concerned with editing, for example, edit(), and commitData(), |
|
287 |
whilst others are keyboard and mouse event handlers. |
|
288 |
||
289 |
\note If you inherit QAbstractItemView and intend to update the contents |
|
290 |
of the viewport, you should use viewport->update() instead of |
|
291 |
\l{QWidget::update()}{update()} as all painting operations take place on the |
|
292 |
viewport. |
|
293 |
||
294 |
\sa {View Classes}, {Model/View Programming}, QAbstractItemModel, {Chart Example} |
|
295 |
*/ |
|
296 |
||
297 |
/*! |
|
298 |
\enum QAbstractItemView::SelectionMode |
|
299 |
||
300 |
This enum indicates how the view responds to user selections: |
|
301 |
||
302 |
\value SingleSelection When the user selects an item, any already-selected |
|
303 |
item becomes unselected, and the user cannot unselect the selected item by |
|
304 |
clicking on it. |
|
305 |
||
306 |
\value ContiguousSelection When the user selects an item in the usual way, |
|
307 |
the selection is cleared and the new item selected. However, if the user |
|
308 |
presses the Shift key while clicking on an item, all items between the |
|
309 |
current item and the clicked item are selected or unselected, depending on |
|
310 |
the state of the clicked item. |
|
311 |
||
312 |
\value ExtendedSelection When the user selects an item in the usual way, |
|
313 |
the selection is cleared and the new item selected. However, if the user |
|
314 |
presses the Ctrl key when clicking on an item, the clicked item gets |
|
315 |
toggled and all other items are left untouched. If the user presses the |
|
316 |
Shift key while clicking on an item, all items between the current item |
|
317 |
and the clicked item are selected or unselected, depending on the state of |
|
318 |
the clicked item. Multiple items can be selected by dragging the mouse over |
|
319 |
them. |
|
320 |
||
321 |
\value MultiSelection When the user selects an item in the usual way, the |
|
322 |
selection status of that item is toggled and the other items are left |
|
323 |
alone. Multiple items can be toggled by dragging the mouse over them. |
|
324 |
||
325 |
\value NoSelection Items cannot be selected. |
|
326 |
||
327 |
The most commonly used modes are SingleSelection and ExtendedSelection. |
|
328 |
*/ |
|
329 |
||
330 |
/*! |
|
331 |
\enum QAbstractItemView::SelectionBehavior |
|
332 |
||
333 |
\value SelectItems Selecting single items. |
|
334 |
\value SelectRows Selecting only rows. |
|
335 |
\value SelectColumns Selecting only columns. |
|
336 |
*/ |
|
337 |
||
338 |
/*! |
|
339 |
\enum QAbstractItemView::ScrollHint |
|
340 |
||
341 |
\value EnsureVisible Scroll to ensure that the item is visible. |
|
342 |
\value PositionAtTop Scroll to position the item at the top of the |
|
343 |
viewport. |
|
344 |
\value PositionAtBottom Scroll to position the item at the bottom of the |
|
345 |
viewport. |
|
346 |
\value PositionAtCenter Scroll to position the item at the center of the |
|
347 |
viewport. |
|
348 |
*/ |
|
349 |
||
350 |
||
351 |
/*! |
|
352 |
\enum QAbstractItemView::EditTrigger |
|
353 |
||
354 |
This enum describes actions which will initiate item editing. |
|
355 |
||
356 |
\value NoEditTriggers No editing possible. |
|
357 |
\value CurrentChanged Editing start whenever current item changes. |
|
358 |
\value DoubleClicked Editing starts when an item is double clicked. |
|
359 |
\value SelectedClicked Editing starts when clicking on an already selected |
|
360 |
item. |
|
361 |
\value EditKeyPressed Editing starts when the platform edit key has been |
|
362 |
pressed over an item. |
|
363 |
\value AnyKeyPressed Editing starts when any key is pressed over an item. |
|
364 |
\value AllEditTriggers Editing starts for all above actions. |
|
365 |
*/ |
|
366 |
||
367 |
/*! |
|
368 |
\enum QAbstractItemView::CursorAction |
|
369 |
||
370 |
This enum describes the different ways to navigate between items, |
|
371 |
\sa moveCursor() |
|
372 |
||
373 |
\value MoveUp Move to the item above the current item. |
|
374 |
\value MoveDown Move to the item below the current item. |
|
375 |
\value MoveLeft Move to the item left of the current item. |
|
376 |
\value MoveRight Move to the item right of the current item. |
|
377 |
\value MoveHome Move to the top-left corner item. |
|
378 |
\value MoveEnd Move to the bottom-right corner item. |
|
379 |
\value MovePageUp Move one page up above the current item. |
|
380 |
\value MovePageDown Move one page down below the current item. |
|
381 |
\value MoveNext Move to the item after the current item. |
|
382 |
\value MovePrevious Move to the item before the current item. |
|
383 |
*/ |
|
384 |
||
385 |
/*! |
|
386 |
\enum QAbstractItemView::State |
|
387 |
||
388 |
Describes the different states the view can be in. This is usually |
|
389 |
only interesting when reimplementing your own view. |
|
390 |
||
391 |
\value NoState The is the default state. |
|
392 |
\value DraggingState The user is dragging items. |
|
393 |
\value DragSelectingState The user is selecting items. |
|
394 |
\value EditingState The user is editing an item in a widget editor. |
|
395 |
\value ExpandingState The user is opening a branch of items. |
|
396 |
\value CollapsingState The user is closing a branch of items. |
|
397 |
\value AnimatingState The item view is performing an animation. |
|
398 |
*/ |
|
399 |
||
400 |
/*! |
|
401 |
\since 4.2 |
|
402 |
\enum QAbstractItemView::ScrollMode |
|
403 |
||
404 |
\value ScrollPerItem The view will scroll the contents one item at a time. |
|
405 |
\value ScrollPerPixel The view will scroll the contents one pixel at a time. |
|
406 |
*/ |
|
407 |
||
408 |
/*! |
|
409 |
\fn QRect QAbstractItemView::visualRect(const QModelIndex &index) const = 0 |
|
410 |
Returns the rectangle on the viewport occupied by the item at \a index. |
|
411 |
||
412 |
If your item is displayed in several areas then visualRect should return |
|
413 |
the primary area that contains index and not the complete area that index |
|
414 |
might encompasses, touch or cause drawing. |
|
415 |
||
416 |
In the base class this is a pure virtual function. |
|
417 |
||
418 |
\sa indexAt(), visualRegionForSelection() |
|
419 |
*/ |
|
420 |
||
421 |
/*! |
|
422 |
\fn void QAbstractItemView::scrollTo(const QModelIndex &index, ScrollHint hint) = 0 |
|
423 |
||
424 |
Scrolls the view if necessary to ensure that the item at \a index |
|
425 |
is visible. The view will try to position the item according to the given \a hint. |
|
426 |
||
427 |
In the base class this is a pure virtual function. |
|
428 |
*/ |
|
429 |
||
430 |
/*! |
|
431 |
\fn QModelIndex QAbstractItemView::indexAt(const QPoint &point) const = 0 |
|
432 |
||
433 |
Returns the model index of the item at the viewport coordinates \a point. |
|
434 |
||
435 |
In the base class this is a pure virtual function. |
|
436 |
||
437 |
\sa visualRect() |
|
438 |
*/ |
|
439 |
||
440 |
/*! |
|
441 |
\fn void QAbstractItemView::activated(const QModelIndex &index) |
|
442 |
||
443 |
This signal is emitted when the item specified by \a index is |
|
444 |
activated by the user. How to activate items depends on the |
|
445 |
platform; e.g., by single- or double-clicking the item, or by |
|
446 |
pressing the Return or Enter key when the item is current. |
|
447 |
||
448 |
\sa clicked(), doubleClicked(), entered(), pressed() |
|
449 |
*/ |
|
450 |
||
451 |
/*! |
|
452 |
\fn void QAbstractItemView::entered(const QModelIndex &index) |
|
453 |
||
454 |
This signal is emitted when the mouse cursor enters the item |
|
455 |
specified by \a index. |
|
456 |
Mouse tracking needs to be enabled for this feature to work. |
|
457 |
||
458 |
\sa viewportEntered(), activated(), clicked(), doubleClicked(), pressed() |
|
459 |
*/ |
|
460 |
||
461 |
/*! |
|
462 |
\fn void QAbstractItemView::viewportEntered() |
|
463 |
||
464 |
This signal is emitted when the mouse cursor enters the viewport. |
|
465 |
Mouse tracking needs to be enabled for this feature to work. |
|
466 |
||
467 |
\sa entered() |
|
468 |
*/ |
|
469 |
||
470 |
/*! |
|
471 |
\fn void QAbstractItemView::pressed(const QModelIndex &index) |
|
472 |
||
473 |
This signal is emitted when a mouse button is pressed. The item |
|
474 |
the mouse was pressed on is specified by \a index. The signal is |
|
475 |
only emitted when the index is valid. |
|
476 |
||
477 |
Use the QApplication::mouseButtons() function to get the state |
|
478 |
of the mouse buttons. |
|
479 |
||
480 |
\sa activated(), clicked(), doubleClicked(), entered() |
|
481 |
*/ |
|
482 |
||
483 |
/*! |
|
484 |
\fn void QAbstractItemView::clicked(const QModelIndex &index) |
|
485 |
||
486 |
This signal is emitted when a mouse button is clicked. The item |
|
487 |
the mouse was clicked on is specified by \a index. The signal is |
|
488 |
only emitted when the index is valid. |
|
489 |
||
490 |
\sa activated(), doubleClicked(), entered(), pressed() |
|
491 |
*/ |
|
492 |
||
493 |
/*! |
|
494 |
\fn void QAbstractItemView::doubleClicked(const QModelIndex &index) |
|
495 |
||
496 |
This signal is emitted when a mouse button is double-clicked. The |
|
497 |
item the mouse was double-clicked on is specified by \a index. |
|
498 |
The signal is only emitted when the index is valid. |
|
499 |
||
500 |
\sa clicked(), activated() |
|
501 |
*/ |
|
502 |
||
503 |
/*! |
|
504 |
\fn QModelIndex QAbstractItemView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) = 0 |
|
505 |
||
506 |
Returns a QModelIndex object pointing to the next object in the view, |
|
507 |
based on the given \a cursorAction and keyboard modifiers specified |
|
508 |
by \a modifiers. |
|
509 |
||
510 |
In the base class this is a pure virtual function. |
|
511 |
*/ |
|
512 |
||
513 |
/*! |
|
514 |
\fn int QAbstractItemView::horizontalOffset() const = 0 |
|
515 |
||
516 |
Returns the horizontal offset of the view. |
|
517 |
||
518 |
In the base class this is a pure virtual function. |
|
519 |
||
520 |
\sa verticalOffset() |
|
521 |
*/ |
|
522 |
||
523 |
/*! |
|
524 |
\fn int QAbstractItemView::verticalOffset() const = 0 |
|
525 |
||
526 |
Returns the vertical offset of the view. |
|
527 |
||
528 |
In the base class this is a pure virtual function. |
|
529 |
||
530 |
\sa horizontalOffset() |
|
531 |
*/ |
|
532 |
||
533 |
/*! |
|
534 |
\fn bool QAbstractItemView::isIndexHidden(const QModelIndex &index) const |
|
535 |
||
536 |
Returns true if the item referred to by the given \a index is hidden in the view, |
|
537 |
otherwise returns false. |
|
538 |
||
539 |
Hiding is a view specific feature. For example in TableView a column can be marked |
|
540 |
as hidden or a row in the TreeView. |
|
541 |
||
542 |
In the base class this is a pure virtual function. |
|
543 |
*/ |
|
544 |
||
545 |
/*! |
|
546 |
\fn void QAbstractItemView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) |
|
547 |
||
548 |
Applies the selection \a flags to the items in or touched by the |
|
549 |
rectangle, \a rect. |
|
550 |
||
551 |
When implementing your own itemview setSelection should call |
|
552 |
selectionModel()->select(selection, flags) where selection |
|
553 |
is either an empty QModelIndex or a QItemSelection that contains |
|
554 |
all items that are contained in \a rect. |
|
555 |
||
556 |
\sa selectionCommand(), selectedIndexes() |
|
557 |
*/ |
|
558 |
||
559 |
/*! |
|
560 |
\fn QRegion QAbstractItemView::visualRegionForSelection(const QItemSelection &selection) const = 0 |
|
561 |
||
562 |
Returns the region from the viewport of the items in the given |
|
563 |
\a selection. |
|
564 |
||
565 |
In the base class this is a pure virtual function. |
|
566 |
||
567 |
\sa visualRect(), selectedIndexes() |
|
568 |
*/ |
|
569 |
||
570 |
/*! |
|
571 |
\fn void QAbstractItemView::update() |
|
572 |
\internal |
|
573 |
*/ |
|
574 |
||
575 |
/*! |
|
576 |
Constructs an abstract item view with the given \a parent. |
|
577 |
*/ |
|
578 |
QAbstractItemView::QAbstractItemView(QWidget *parent) |
|
579 |
: QAbstractScrollArea(*(new QAbstractItemViewPrivate), parent) |
|
580 |
{ |
|
581 |
d_func()->init(); |
|
582 |
} |
|
583 |
||
584 |
/*! |
|
585 |
\internal |
|
586 |
*/ |
|
587 |
QAbstractItemView::QAbstractItemView(QAbstractItemViewPrivate &dd, QWidget *parent) |
|
588 |
: QAbstractScrollArea(dd, parent) |
|
589 |
{ |
|
590 |
d_func()->init(); |
|
591 |
} |
|
592 |
||
593 |
/*! |
|
594 |
Destroys the view. |
|
595 |
*/ |
|
596 |
QAbstractItemView::~QAbstractItemView() |
|
597 |
{ |
|
598 |
} |
|
599 |
||
600 |
/*! |
|
601 |
Sets the \a model for the view to present. |
|
602 |
||
603 |
This function will create and set a new selection model, replacing any |
|
604 |
model that was previously set with setSelectionModel(). However, the old |
|
605 |
selection model will not be deleted as it may be shared between several |
|
606 |
views. We recommend that you delete the old selection model if it is no |
|
607 |
longer required. This is done with the following code: |
|
608 |
||
609 |
\snippet doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp 2 |
|
610 |
||
611 |
If both the old model and the old selection model do not have parents, or |
|
612 |
if their parents are long-lived objects, it may be preferable to call their |
|
613 |
deleteLater() functions to explicitly delete them. |
|
614 |
||
615 |
The view \e{does not} take ownership of the model unless it is the model's |
|
616 |
parent object because the view may be shared between many different views. |
|
617 |
||
618 |
\sa selectionModel(), setSelectionModel() |
|
619 |
*/ |
|
620 |
void QAbstractItemView::setModel(QAbstractItemModel *model) |
|
621 |
{ |
|
622 |
Q_D(QAbstractItemView); |
|
623 |
if (model == d->model) |
|
624 |
return; |
|
625 |
if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) { |
|
626 |
disconnect(d->model, SIGNAL(destroyed()), |
|
627 |
this, SLOT(_q_modelDestroyed())); |
|
628 |
disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
629 |
this, SLOT(dataChanged(QModelIndex,QModelIndex))); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
630 |
disconnect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
631 |
this, SLOT(_q_headerDataChanged())); |
0 | 632 |
disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), |
633 |
this, SLOT(rowsInserted(QModelIndex,int,int))); |
|
634 |
disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
635 |
this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int))); |
|
636 |
disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
637 |
this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); |
|
638 |
disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), |
|
639 |
this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); |
|
640 |
disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)), |
|
641 |
this, SLOT(_q_columnsRemoved(QModelIndex,int,int))); |
|
642 |
disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)), |
|
643 |
this, SLOT(_q_columnsInserted(QModelIndex,int,int))); |
|
644 |
||
645 |
disconnect(d->model, SIGNAL(modelReset()), this, SLOT(reset())); |
|
646 |
disconnect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged())); |
|
647 |
} |
|
648 |
d->model = (model ? model : QAbstractItemModelPrivate::staticEmptyModel()); |
|
649 |
||
650 |
// These asserts do basic sanity checking of the model |
|
651 |
Q_ASSERT_X(d->model->index(0,0) == d->model->index(0,0), |
|
652 |
"QAbstractItemView::setModel", |
|
653 |
"A model should return the exact same index " |
|
654 |
"(including its internal id/pointer) when asked for it twice in a row."); |
|
655 |
Q_ASSERT_X(d->model->index(0,0).parent() == QModelIndex(), |
|
656 |
"QAbstractItemView::setModel", |
|
657 |
"The parent of a top level index should be invalid"); |
|
658 |
||
659 |
if (d->model != QAbstractItemModelPrivate::staticEmptyModel()) { |
|
660 |
connect(d->model, SIGNAL(destroyed()), |
|
661 |
this, SLOT(_q_modelDestroyed())); |
|
662 |
connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
663 |
this, SLOT(dataChanged(QModelIndex,QModelIndex))); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
664 |
connect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
665 |
this, SLOT(_q_headerDataChanged())); |
0 | 666 |
connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), |
667 |
this, SLOT(rowsInserted(QModelIndex,int,int))); |
|
668 |
connect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
669 |
this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int))); |
|
670 |
connect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
671 |
this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); |
|
672 |
connect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), |
|
673 |
this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); |
|
674 |
connect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)), |
|
675 |
this, SLOT(_q_columnsRemoved(QModelIndex,int,int))); |
|
676 |
connect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)), |
|
677 |
this, SLOT(_q_columnsInserted(QModelIndex,int,int))); |
|
678 |
||
679 |
connect(d->model, SIGNAL(modelReset()), this, SLOT(reset())); |
|
680 |
connect(d->model, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged())); |
|
681 |
} |
|
682 |
setSelectionModel(new QItemSelectionModel(d->model, this)); |
|
683 |
reset(); // kill editors, set new root and do layout |
|
684 |
} |
|
685 |
||
686 |
/*! |
|
687 |
Returns the model that this view is presenting. |
|
688 |
*/ |
|
689 |
QAbstractItemModel *QAbstractItemView::model() const |
|
690 |
{ |
|
691 |
Q_D(const QAbstractItemView); |
|
692 |
return (d->model == QAbstractItemModelPrivate::staticEmptyModel() ? 0 : d->model); |
|
693 |
} |
|
694 |
||
695 |
/*! |
|
696 |
Sets the current selection model to the given \a selectionModel. |
|
697 |
||
698 |
Note that, if you call setModel() after this function, the given \a selectionModel |
|
699 |
will be replaced by one created by the view. |
|
700 |
||
701 |
\note It is up to the application to delete the old selection model if it is no |
|
702 |
longer needed; i.e., if it is not being used by other views. This will happen |
|
703 |
automatically when its parent object is deleted. However, if it does not have a |
|
704 |
parent, or if the parent is a long-lived object, it may be preferable to call its |
|
705 |
deleteLater() function to explicitly delete it. |
|
706 |
||
707 |
\sa selectionModel(), setModel(), clearSelection() |
|
708 |
*/ |
|
709 |
void QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel) |
|
710 |
{ |
|
711 |
// ### if the given model is null, we should use the original selection model |
|
712 |
Q_ASSERT(selectionModel); |
|
713 |
Q_D(QAbstractItemView); |
|
714 |
||
715 |
if (selectionModel->model() != d->model) { |
|
716 |
qWarning("QAbstractItemView::setSelectionModel() failed: " |
|
717 |
"Trying to set a selection model, which works on " |
|
718 |
"a different model than the view."); |
|
719 |
return; |
|
720 |
} |
|
721 |
||
722 |
if (d->selectionModel) { |
|
723 |
disconnect(d->selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
|
724 |
this, SLOT(selectionChanged(QItemSelection,QItemSelection))); |
|
725 |
disconnect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), |
|
726 |
this, SLOT(currentChanged(QModelIndex,QModelIndex))); |
|
727 |
} |
|
728 |
||
729 |
d->selectionModel = selectionModel; |
|
730 |
||
731 |
if (d->selectionModel) { |
|
732 |
connect(d->selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
|
733 |
this, SLOT(selectionChanged(QItemSelection,QItemSelection))); |
|
734 |
connect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), |
|
735 |
this, SLOT(currentChanged(QModelIndex,QModelIndex))); |
|
736 |
} |
|
737 |
} |
|
738 |
||
739 |
/*! |
|
740 |
Returns the current selection model. |
|
741 |
||
742 |
\sa setSelectionModel(), selectedIndexes() |
|
743 |
*/ |
|
744 |
QItemSelectionModel* QAbstractItemView::selectionModel() const |
|
745 |
{ |
|
746 |
Q_D(const QAbstractItemView); |
|
747 |
return d->selectionModel; |
|
748 |
} |
|
749 |
||
750 |
/*! |
|
751 |
Sets the item delegate for this view and its model to \a delegate. |
|
752 |
This is useful if you want complete control over the editing and |
|
753 |
display of items. |
|
754 |
||
755 |
Any existing delegate will be removed, but not deleted. QAbstractItemView |
|
756 |
does not take ownership of \a delegate. |
|
757 |
||
758 |
\warning You should not share the same instance of a delegate between views. |
|
759 |
Doing so can cause incorrect or unintuitive editing behavior since each |
|
760 |
view connected to a given delegate may receive the \l{QAbstractItemDelegate::}{closeEditor()} |
|
761 |
signal, and attempt to access, modify or close an editor that has already been closed. |
|
762 |
||
763 |
\sa itemDelegate() |
|
764 |
*/ |
|
765 |
void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *delegate) |
|
766 |
{ |
|
767 |
Q_D(QAbstractItemView); |
|
768 |
if (delegate == d->itemDelegate) |
|
769 |
return; |
|
770 |
||
771 |
if (d->itemDelegate) { |
|
772 |
if (d->delegateRefCount(d->itemDelegate) == 1) { |
|
773 |
disconnect(d->itemDelegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), |
|
774 |
this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); |
|
775 |
disconnect(d->itemDelegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); |
|
776 |
disconnect(d->itemDelegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout())); |
|
777 |
} |
|
778 |
} |
|
779 |
||
780 |
if (delegate) { |
|
781 |
if (d->delegateRefCount(delegate) == 0) { |
|
782 |
connect(delegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), |
|
783 |
this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); |
|
784 |
connect(delegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); |
|
785 |
qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
786 |
connect(delegate, SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout()), Qt::QueuedConnection); |
|
787 |
} |
|
788 |
} |
|
789 |
d->itemDelegate = delegate; |
|
790 |
viewport()->update(); |
|
791 |
} |
|
792 |
||
793 |
/*! |
|
794 |
Returns the item delegate used by this view and model. This is |
|
795 |
either one set with setItemDelegate(), or the default one. |
|
796 |
||
797 |
\sa setItemDelegate() |
|
798 |
*/ |
|
799 |
QAbstractItemDelegate *QAbstractItemView::itemDelegate() const |
|
800 |
{ |
|
801 |
return d_func()->itemDelegate; |
|
802 |
} |
|
803 |
||
804 |
/*! |
|
805 |
\reimp |
|
806 |
*/ |
|
807 |
QVariant QAbstractItemView::inputMethodQuery(Qt::InputMethodQuery query) const |
|
808 |
{ |
|
809 |
const QModelIndex current = currentIndex(); |
|
810 |
if (!current.isValid() || query != Qt::ImMicroFocus) |
|
811 |
return QAbstractScrollArea::inputMethodQuery(query); |
|
812 |
return visualRect(current); |
|
813 |
} |
|
814 |
||
815 |
/*! |
|
816 |
\since 4.2 |
|
817 |
||
818 |
Sets the given item \a delegate used by this view and model for the given |
|
819 |
\a row. All items on \a row will be drawn and managed by \a delegate |
|
820 |
instead of using the default delegate (i.e., itemDelegate()). |
|
821 |
||
822 |
Any existing row delegate for \a row will be removed, but not |
|
823 |
deleted. QAbstractItemView does not take ownership of \a delegate. |
|
824 |
||
825 |
\note If a delegate has been assigned to both a row and a column, the row |
|
826 |
delegate (i.e., this delegate) will take presedence and manage the |
|
827 |
intersecting cell index. |
|
828 |
||
829 |
\warning You should not share the same instance of a delegate between views. |
|
830 |
Doing so can cause incorrect or unintuitive editing behavior since each |
|
831 |
view connected to a given delegate may receive the \l{QAbstractItemDelegate::}{closeEditor()} |
|
832 |
signal, and attempt to access, modify or close an editor that has already been closed. |
|
833 |
||
834 |
\sa itemDelegateForRow(), setItemDelegateForColumn(), itemDelegate() |
|
835 |
*/ |
|
836 |
void QAbstractItemView::setItemDelegateForRow(int row, QAbstractItemDelegate *delegate) |
|
837 |
{ |
|
838 |
Q_D(QAbstractItemView); |
|
839 |
if (QAbstractItemDelegate *rowDelegate = d->rowDelegates.value(row, 0)) { |
|
840 |
if (d->delegateRefCount(rowDelegate) == 1) { |
|
841 |
disconnect(rowDelegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), |
|
842 |
this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); |
|
843 |
disconnect(rowDelegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); |
|
844 |
} |
|
845 |
d->rowDelegates.remove(row); |
|
846 |
} |
|
847 |
if (delegate) { |
|
848 |
if (d->delegateRefCount(delegate) == 0) { |
|
849 |
connect(delegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), |
|
850 |
this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); |
|
851 |
connect(delegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); |
|
852 |
} |
|
853 |
d->rowDelegates.insert(row, delegate); |
|
854 |
} |
|
855 |
viewport()->update(); |
|
856 |
} |
|
857 |
||
858 |
/*! |
|
859 |
\since 4.2 |
|
860 |
||
861 |
Returns the item delegate used by this view and model for the given \a row, |
|
862 |
or 0 if no delegate has been assigned. You can call itemDelegate() to get a |
|
863 |
pointer to the current delegate for a given index. |
|
864 |
||
865 |
\sa setItemDelegateForRow(), itemDelegateForColumn(), setItemDelegate() |
|
866 |
*/ |
|
867 |
QAbstractItemDelegate *QAbstractItemView::itemDelegateForRow(int row) const |
|
868 |
{ |
|
869 |
Q_D(const QAbstractItemView); |
|
870 |
return d->rowDelegates.value(row, 0); |
|
871 |
} |
|
872 |
||
873 |
/*! |
|
874 |
\since 4.2 |
|
875 |
||
876 |
Sets the given item \a delegate used by this view and model for the given |
|
877 |
\a column. All items on \a column will be drawn and managed by \a delegate |
|
878 |
instead of using the default delegate (i.e., itemDelegate()). |
|
879 |
||
880 |
Any existing column delegate for \a column will be removed, but not |
|
881 |
deleted. QAbstractItemView does not take ownership of \a delegate. |
|
882 |
||
883 |
\note If a delegate has been assigned to both a row and a column, the row |
|
884 |
delegate will take presedence and manage the intersecting cell index. |
|
885 |
||
886 |
\warning You should not share the same instance of a delegate between views. |
|
887 |
Doing so can cause incorrect or unintuitive editing behavior since each |
|
888 |
view connected to a given delegate may receive the \l{QAbstractItemDelegate::}{closeEditor()} |
|
889 |
signal, and attempt to access, modify or close an editor that has already been closed. |
|
890 |
||
891 |
\sa itemDelegateForColumn(), setItemDelegateForRow(), itemDelegate() |
|
892 |
*/ |
|
893 |
void QAbstractItemView::setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate) |
|
894 |
{ |
|
895 |
Q_D(QAbstractItemView); |
|
896 |
if (QAbstractItemDelegate *columnDelegate = d->columnDelegates.value(column, 0)) { |
|
897 |
if (d->delegateRefCount(columnDelegate) == 1) { |
|
898 |
disconnect(columnDelegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), |
|
899 |
this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); |
|
900 |
disconnect(columnDelegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); |
|
901 |
} |
|
902 |
d->columnDelegates.remove(column); |
|
903 |
} |
|
904 |
if (delegate) { |
|
905 |
if (d->delegateRefCount(delegate) == 0) { |
|
906 |
connect(delegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), |
|
907 |
this, SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint))); |
|
908 |
connect(delegate, SIGNAL(commitData(QWidget*)), this, SLOT(commitData(QWidget*))); |
|
909 |
} |
|
910 |
d->columnDelegates.insert(column, delegate); |
|
911 |
} |
|
912 |
viewport()->update(); |
|
913 |
} |
|
914 |
||
915 |
/*! |
|
916 |
\since 4.2 |
|
917 |
||
918 |
Returns the item delegate used by this view and model for the given \a |
|
919 |
column. You can call itemDelegate() to get a pointer to the current delegate |
|
920 |
for a given index. |
|
921 |
||
922 |
\sa setItemDelegateForColumn(), itemDelegateForRow(), itemDelegate() |
|
923 |
*/ |
|
924 |
QAbstractItemDelegate *QAbstractItemView::itemDelegateForColumn(int column) const |
|
925 |
{ |
|
926 |
Q_D(const QAbstractItemView); |
|
927 |
return d->columnDelegates.value(column, 0); |
|
928 |
} |
|
929 |
||
930 |
/*! |
|
931 |
Returns the item delegate used by this view and model for |
|
932 |
the given \a index. |
|
933 |
*/ |
|
934 |
QAbstractItemDelegate *QAbstractItemView::itemDelegate(const QModelIndex &index) const |
|
935 |
{ |
|
936 |
Q_D(const QAbstractItemView); |
|
937 |
return d->delegateForIndex(index); |
|
938 |
} |
|
939 |
||
940 |
/*! |
|
941 |
\property QAbstractItemView::selectionMode |
|
942 |
\brief which selection mode the view operates in |
|
943 |
||
944 |
This property controls whether the user can select one or many items |
|
945 |
and, in many-item selections, whether the selection must be a |
|
946 |
continuous range of items. |
|
947 |
||
948 |
\sa SelectionMode SelectionBehavior |
|
949 |
*/ |
|
950 |
void QAbstractItemView::setSelectionMode(SelectionMode mode) |
|
951 |
{ |
|
952 |
Q_D(QAbstractItemView); |
|
953 |
d->selectionMode = mode; |
|
954 |
} |
|
955 |
||
956 |
QAbstractItemView::SelectionMode QAbstractItemView::selectionMode() const |
|
957 |
{ |
|
958 |
Q_D(const QAbstractItemView); |
|
959 |
return d->selectionMode; |
|
960 |
} |
|
961 |
||
962 |
/*! |
|
963 |
\property QAbstractItemView::selectionBehavior |
|
964 |
\brief which selection behavior the view uses |
|
965 |
||
966 |
This property holds whether selections are done |
|
967 |
in terms of single items, rows or columns. |
|
968 |
||
969 |
\sa SelectionMode SelectionBehavior |
|
970 |
*/ |
|
971 |
||
972 |
void QAbstractItemView::setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior) |
|
973 |
{ |
|
974 |
Q_D(QAbstractItemView); |
|
975 |
d->selectionBehavior = behavior; |
|
976 |
} |
|
977 |
||
978 |
QAbstractItemView::SelectionBehavior QAbstractItemView::selectionBehavior() const |
|
979 |
{ |
|
980 |
Q_D(const QAbstractItemView); |
|
981 |
return d->selectionBehavior; |
|
982 |
} |
|
983 |
||
984 |
/*! |
|
985 |
Sets the current item to be the item at \a index. |
|
986 |
||
987 |
Unless the current selection mode is |
|
988 |
\l{QAbstractItemView::}{NoSelection}, the item is also be selected. |
|
989 |
Note that this function also updates the starting position for any |
|
990 |
new selections the user performs. |
|
991 |
||
992 |
To set an item as the current item without selecting it, call |
|
993 |
||
994 |
\c{selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);} |
|
995 |
||
996 |
\sa currentIndex(), currentChanged(), selectionMode |
|
997 |
*/ |
|
998 |
void QAbstractItemView::setCurrentIndex(const QModelIndex &index) |
|
999 |
{ |
|
1000 |
Q_D(QAbstractItemView); |
|
1001 |
if (d->selectionModel && (!index.isValid() || d->isIndexEnabled(index))) { |
|
1002 |
QItemSelectionModel::SelectionFlags command = selectionCommand(index, 0); |
|
1003 |
d->selectionModel->setCurrentIndex(index, command); |
|
1004 |
d->currentIndexSet = true; |
|
1005 |
if ((command & QItemSelectionModel::Current) == 0) |
|
1006 |
d->pressedPosition = visualRect(currentIndex()).center() + d->offset(); |
|
1007 |
} |
|
1008 |
} |
|
1009 |
||
1010 |
/*! |
|
1011 |
Returns the model index of the current item. |
|
1012 |
||
1013 |
\sa setCurrentIndex() |
|
1014 |
*/ |
|
1015 |
QModelIndex QAbstractItemView::currentIndex() const |
|
1016 |
{ |
|
1017 |
Q_D(const QAbstractItemView); |
|
1018 |
return d->selectionModel ? d->selectionModel->currentIndex() : QModelIndex(); |
|
1019 |
} |
|
1020 |
||
1021 |
||
1022 |
/*! |
|
1023 |
Reset the internal state of the view. |
|
1024 |
||
1025 |
\warning This function will reset open editors, scroll bar positions, |
|
1026 |
selections, etc. Existing changes will not be committed. If you would like |
|
1027 |
to save your changes when resetting the view, you can reimplement this |
|
1028 |
function, commit your changes, and then call the superclass' |
|
1029 |
implementation. |
|
1030 |
*/ |
|
1031 |
void QAbstractItemView::reset() |
|
1032 |
{ |
|
1033 |
Q_D(QAbstractItemView); |
|
1034 |
d->delayedReset.stop(); //make sure we stop the timer |
|
1035 |
QList<QEditorInfo>::const_iterator it = d->editors.constBegin(); |
|
1036 |
for (; it != d->editors.constEnd(); ++it) |
|
1037 |
d->releaseEditor(it->editor); |
|
1038 |
d->editors.clear(); |
|
1039 |
d->persistent.clear(); |
|
1040 |
d->currentIndexSet = false; |
|
1041 |
setState(NoState); |
|
1042 |
setRootIndex(QModelIndex()); |
|
1043 |
if (d->selectionModel) |
|
1044 |
d->selectionModel->reset(); |
|
1045 |
} |
|
1046 |
||
1047 |
/*! |
|
1048 |
Sets the root item to the item at the given \a index. |
|
1049 |
||
1050 |
\sa rootIndex() |
|
1051 |
*/ |
|
1052 |
void QAbstractItemView::setRootIndex(const QModelIndex &index) |
|
1053 |
{ |
|
1054 |
Q_D(QAbstractItemView); |
|
1055 |
if (index.isValid() && index.model() != d->model) { |
|
1056 |
qWarning("QAbstractItemView::setRootIndex failed : index must be from the currently set model"); |
|
1057 |
return; |
|
1058 |
} |
|
1059 |
d->root = index; |
|
1060 |
d->doDelayedItemsLayout(); |
|
1061 |
} |
|
1062 |
||
1063 |
/*! |
|
1064 |
Returns the model index of the model's root item. The root item is |
|
1065 |
the parent item to the view's toplevel items. The root can be invalid. |
|
1066 |
||
1067 |
\sa setRootIndex() |
|
1068 |
*/ |
|
1069 |
QModelIndex QAbstractItemView::rootIndex() const |
|
1070 |
{ |
|
1071 |
return QModelIndex(d_func()->root); |
|
1072 |
} |
|
1073 |
||
1074 |
/*! |
|
1075 |
Selects all items in the view. |
|
1076 |
This function will use the selection behavior |
|
1077 |
set on the view when selecting. |
|
1078 |
||
1079 |
\sa setSelection(), selectedIndexes(), clearSelection() |
|
1080 |
*/ |
|
1081 |
void QAbstractItemView::selectAll() |
|
1082 |
{ |
|
1083 |
Q_D(QAbstractItemView); |
|
1084 |
SelectionMode mode = d->selectionMode; |
|
1085 |
if (mode == MultiSelection || mode == ExtendedSelection) |
|
1086 |
d->selectAll(QItemSelectionModel::ClearAndSelect |
|
1087 |
|d->selectionBehaviorFlags()); |
|
1088 |
else if (mode != SingleSelection) |
|
1089 |
d->selectAll(selectionCommand(d->model->index(0, 0, d->root))); |
|
1090 |
} |
|
1091 |
||
1092 |
/*! |
|
1093 |
Starts editing the item corresponding to the given \a index if it is |
|
1094 |
editable. |
|
1095 |
||
1096 |
Note that this function does not change the current index. Since the current |
|
1097 |
index defines the next and previous items to edit, users may find that |
|
1098 |
keyboard navigation does not work as expected. To provide consistent navigation |
|
1099 |
behavior, call setCurrentIndex() before this function with the same model |
|
1100 |
index. |
|
1101 |
||
1102 |
\sa QModelIndex::flags() |
|
1103 |
*/ |
|
1104 |
void QAbstractItemView::edit(const QModelIndex &index) |
|
1105 |
{ |
|
1106 |
Q_D(QAbstractItemView); |
|
1107 |
if (!d->isIndexValid(index)) |
|
1108 |
qWarning("edit: index was invalid"); |
|
1109 |
if (!edit(index, AllEditTriggers, 0)) |
|
1110 |
qWarning("edit: editing failed"); |
|
1111 |
} |
|
1112 |
||
1113 |
/*! |
|
1114 |
Deselects all selected items. The current index will not be changed. |
|
1115 |
||
1116 |
\sa setSelection(), selectAll() |
|
1117 |
*/ |
|
1118 |
void QAbstractItemView::clearSelection() |
|
1119 |
{ |
|
1120 |
Q_D(QAbstractItemView); |
|
1121 |
if (d->selectionModel) |
|
1122 |
d->selectionModel->clearSelection(); |
|
1123 |
} |
|
1124 |
||
1125 |
/*! |
|
1126 |
\internal |
|
1127 |
||
1128 |
This function is intended to lay out the items in the view. |
|
1129 |
The default implementation just calls updateGeometries() and updates the viewport. |
|
1130 |
*/ |
|
1131 |
void QAbstractItemView::doItemsLayout() |
|
1132 |
{ |
|
1133 |
Q_D(QAbstractItemView); |
|
1134 |
d->interruptDelayedItemsLayout(); |
|
1135 |
updateGeometries(); |
|
1136 |
d->viewport->update(); |
|
1137 |
} |
|
1138 |
||
1139 |
/*! |
|
1140 |
\property QAbstractItemView::editTriggers |
|
1141 |
\brief which actions will initiate item editing |
|
1142 |
||
1143 |
This property is a selection of flags defined by |
|
1144 |
\l{EditTrigger}, combined using the OR |
|
1145 |
operator. The view will only initiate the editing of an item if the |
|
1146 |
action performed is set in this property. |
|
1147 |
*/ |
|
1148 |
void QAbstractItemView::setEditTriggers(EditTriggers actions) |
|
1149 |
{ |
|
1150 |
Q_D(QAbstractItemView); |
|
1151 |
d->editTriggers = actions; |
|
1152 |
} |
|
1153 |
||
1154 |
QAbstractItemView::EditTriggers QAbstractItemView::editTriggers() const |
|
1155 |
{ |
|
1156 |
Q_D(const QAbstractItemView); |
|
1157 |
return d->editTriggers; |
|
1158 |
} |
|
1159 |
||
1160 |
/*! |
|
1161 |
\since 4.2 |
|
1162 |
\property QAbstractItemView::verticalScrollMode |
|
1163 |
\brief how the view scrolls its contents in the vertical direction |
|
1164 |
||
1165 |
This property controlls how the view scroll its contents vertically. |
|
1166 |
Scrolling can be done either per pixel or per item. |
|
1167 |
*/ |
|
1168 |
||
1169 |
void QAbstractItemView::setVerticalScrollMode(ScrollMode mode) |
|
1170 |
{ |
|
1171 |
Q_D(QAbstractItemView); |
|
1172 |
if (mode == d->verticalScrollMode) |
|
1173 |
return; |
|
1174 |
QModelIndex topLeft = indexAt(QPoint(0, 0)); |
|
1175 |
d->verticalScrollMode = mode; |
|
1176 |
updateGeometries(); // update the scroll bars |
|
1177 |
scrollTo(topLeft, QAbstractItemView::PositionAtTop); |
|
1178 |
} |
|
1179 |
||
1180 |
QAbstractItemView::ScrollMode QAbstractItemView::verticalScrollMode() const |
|
1181 |
{ |
|
1182 |
Q_D(const QAbstractItemView); |
|
1183 |
return d->verticalScrollMode; |
|
1184 |
} |
|
1185 |
||
1186 |
/*! |
|
1187 |
\since 4.2 |
|
1188 |
\property QAbstractItemView::horizontalScrollMode |
|
1189 |
\brief how the view scrolls its contents in the horizontal direction |
|
1190 |
||
1191 |
This property controlls how the view scroll its contents horizontally. |
|
1192 |
Scrolling can be done either per pixel or per item. |
|
1193 |
*/ |
|
1194 |
||
1195 |
void QAbstractItemView::setHorizontalScrollMode(ScrollMode mode) |
|
1196 |
{ |
|
1197 |
Q_D(QAbstractItemView); |
|
1198 |
d->horizontalScrollMode = mode; |
|
1199 |
updateGeometries(); // update the scroll bars |
|
1200 |
} |
|
1201 |
||
1202 |
QAbstractItemView::ScrollMode QAbstractItemView::horizontalScrollMode() const |
|
1203 |
{ |
|
1204 |
Q_D(const QAbstractItemView); |
|
1205 |
return d->horizontalScrollMode; |
|
1206 |
} |
|
1207 |
||
1208 |
#ifndef QT_NO_DRAGANDDROP |
|
1209 |
/*! |
|
1210 |
\since 4.2 |
|
1211 |
\property QAbstractItemView::dragDropOverwriteMode |
|
1212 |
\brief the view's drag and drop behavior |
|
1213 |
||
1214 |
If its value is \c true, the selected data will overwrite the |
|
1215 |
existing item data when dropped, while moving the data will clear |
|
1216 |
the item. If its value is \c false, the selected data will be |
|
1217 |
inserted as a new item when the data is dropped. When the data is |
|
1218 |
moved, the item is removed as well. |
|
1219 |
||
1220 |
The default value is \c false, as in the QListView and QTreeView |
|
1221 |
subclasses. In the QTableView subclass, on the other hand, the |
|
1222 |
property has been set to \c true. |
|
1223 |
||
1224 |
Note: This is not intended to prevent overwriting of items. |
|
1225 |
The model's implementation of flags() should do that by not |
|
1226 |
returning Qt::ItemIsDropEnabled. |
|
1227 |
||
1228 |
\sa dragDropMode |
|
1229 |
*/ |
|
1230 |
void QAbstractItemView::setDragDropOverwriteMode(bool overwrite) |
|
1231 |
{ |
|
1232 |
Q_D(QAbstractItemView); |
|
1233 |
d->overwrite = overwrite; |
|
1234 |
} |
|
1235 |
||
1236 |
bool QAbstractItemView::dragDropOverwriteMode() const |
|
1237 |
{ |
|
1238 |
Q_D(const QAbstractItemView); |
|
1239 |
return d->overwrite; |
|
1240 |
} |
|
1241 |
#endif |
|
1242 |
||
1243 |
/*! |
|
1244 |
\property QAbstractItemView::autoScroll |
|
1245 |
\brief whether autoscrolling in drag move events is enabled |
|
1246 |
||
1247 |
If this property is set to true (the default), the |
|
1248 |
QAbstractItemView automatically scrolls the contents of the view |
|
1249 |
if the user drags within 16 pixels of the viewport edge. If the current |
|
1250 |
item changes, then the view will scroll automatically to ensure that the |
|
1251 |
current item is fully visible. |
|
1252 |
||
1253 |
This property only works if the viewport accepts drops. Autoscroll is |
|
1254 |
switched off by setting this property to false. |
|
1255 |
*/ |
|
1256 |
||
1257 |
void QAbstractItemView::setAutoScroll(bool enable) |
|
1258 |
{ |
|
1259 |
Q_D(QAbstractItemView); |
|
1260 |
d->autoScroll = enable; |
|
1261 |
} |
|
1262 |
||
1263 |
bool QAbstractItemView::hasAutoScroll() const |
|
1264 |
{ |
|
1265 |
Q_D(const QAbstractItemView); |
|
1266 |
return d->autoScroll; |
|
1267 |
} |
|
1268 |
||
1269 |
/*! |
|
1270 |
\since 4.4 |
|
1271 |
\property QAbstractItemView::autoScrollMargin |
|
1272 |
\brief the size of the area when auto scrolling is triggered |
|
1273 |
||
1274 |
This property controlls the size of the area at the edge of the viewport that |
|
1275 |
triggers autoscrolling. The default value is 16 pixels. |
|
1276 |
*/ |
|
1277 |
void QAbstractItemView::setAutoScrollMargin(int margin) |
|
1278 |
{ |
|
1279 |
Q_D(QAbstractItemView); |
|
1280 |
d->autoScrollMargin = margin; |
|
1281 |
} |
|
1282 |
||
1283 |
int QAbstractItemView::autoScrollMargin() const |
|
1284 |
{ |
|
1285 |
Q_D(const QAbstractItemView); |
|
1286 |
return d->autoScrollMargin; |
|
1287 |
} |
|
1288 |
||
1289 |
/*! |
|
1290 |
\property QAbstractItemView::tabKeyNavigation |
|
1291 |
\brief whether item navigation with tab and backtab is enabled. |
|
1292 |
*/ |
|
1293 |
||
1294 |
void QAbstractItemView::setTabKeyNavigation(bool enable) |
|
1295 |
{ |
|
1296 |
Q_D(QAbstractItemView); |
|
1297 |
d->tabKeyNavigation = enable; |
|
1298 |
} |
|
1299 |
||
1300 |
bool QAbstractItemView::tabKeyNavigation() const |
|
1301 |
{ |
|
1302 |
Q_D(const QAbstractItemView); |
|
1303 |
return d->tabKeyNavigation; |
|
1304 |
} |
|
1305 |
||
1306 |
#ifndef QT_NO_DRAGANDDROP |
|
1307 |
/*! |
|
1308 |
\property QAbstractItemView::showDropIndicator |
|
1309 |
\brief whether the drop indicator is shown when dragging items and dropping. |
|
1310 |
||
1311 |
\sa dragEnabled DragDropMode dragDropOverwriteMode acceptDrops |
|
1312 |
*/ |
|
1313 |
||
1314 |
void QAbstractItemView::setDropIndicatorShown(bool enable) |
|
1315 |
{ |
|
1316 |
Q_D(QAbstractItemView); |
|
1317 |
d->showDropIndicator = enable; |
|
1318 |
} |
|
1319 |
||
1320 |
bool QAbstractItemView::showDropIndicator() const |
|
1321 |
{ |
|
1322 |
Q_D(const QAbstractItemView); |
|
1323 |
return d->showDropIndicator; |
|
1324 |
} |
|
1325 |
||
1326 |
/*! |
|
1327 |
\property QAbstractItemView::dragEnabled |
|
1328 |
\brief whether the view supports dragging of its own items |
|
1329 |
||
1330 |
\sa showDropIndicator DragDropMode dragDropOverwriteMode acceptDrops |
|
1331 |
*/ |
|
1332 |
||
1333 |
void QAbstractItemView::setDragEnabled(bool enable) |
|
1334 |
{ |
|
1335 |
Q_D(QAbstractItemView); |
|
1336 |
d->dragEnabled = enable; |
|
1337 |
} |
|
1338 |
||
1339 |
bool QAbstractItemView::dragEnabled() const |
|
1340 |
{ |
|
1341 |
Q_D(const QAbstractItemView); |
|
1342 |
return d->dragEnabled; |
|
1343 |
} |
|
1344 |
||
1345 |
/*! |
|
1346 |
\since 4.2 |
|
1347 |
\enum QAbstractItemView::DragDropMode |
|
1348 |
||
1349 |
Describes the various drag and drop events the view can act upon. |
|
1350 |
By default the view does not support dragging or dropping (\c |
|
1351 |
NoDragDrop). |
|
1352 |
||
1353 |
\value NoDragDrop Does not support dragging or dropping. |
|
1354 |
\value DragOnly The view supports dragging of its own items |
|
1355 |
\value DropOnly The view accepts drops |
|
1356 |
\value DragDrop The view supports both dragging and dropping |
|
1357 |
\value InternalMove The view accepts move (\bold{not copy}) operations only |
|
1358 |
from itself. |
|
1359 |
||
1360 |
Note that the model used needs to provide support for drag and drop operations. |
|
1361 |
||
1362 |
\sa setDragDropMode() {Using Drag and Drop with Item Views} |
|
1363 |
*/ |
|
1364 |
||
1365 |
/*! |
|
1366 |
\property QAbstractItemView::dragDropMode |
|
1367 |
\brief the drag and drop event the view will act upon |
|
1368 |
||
1369 |
\since 4.2 |
|
1370 |
\sa showDropIndicator dragDropOverwriteMode |
|
1371 |
*/ |
|
1372 |
void QAbstractItemView::setDragDropMode(DragDropMode behavior) |
|
1373 |
{ |
|
1374 |
Q_D(QAbstractItemView); |
|
1375 |
d->dragDropMode = behavior; |
|
1376 |
setDragEnabled(behavior == DragOnly || behavior == DragDrop || behavior == InternalMove); |
|
1377 |
setAcceptDrops(behavior == DropOnly || behavior == DragDrop || behavior == InternalMove); |
|
1378 |
} |
|
1379 |
||
1380 |
QAbstractItemView::DragDropMode QAbstractItemView::dragDropMode() const |
|
1381 |
{ |
|
1382 |
Q_D(const QAbstractItemView); |
|
1383 |
DragDropMode setBehavior = d->dragDropMode; |
|
1384 |
if (!dragEnabled() && !acceptDrops()) |
|
1385 |
return NoDragDrop; |
|
1386 |
||
1387 |
if (dragEnabled() && !acceptDrops()) |
|
1388 |
return DragOnly; |
|
1389 |
||
1390 |
if (!dragEnabled() && acceptDrops()) |
|
1391 |
return DropOnly; |
|
1392 |
||
1393 |
if (dragEnabled() && acceptDrops()) { |
|
1394 |
if (setBehavior == InternalMove) |
|
1395 |
return setBehavior; |
|
1396 |
else |
|
1397 |
return DragDrop; |
|
1398 |
} |
|
1399 |
||
1400 |
return NoDragDrop; |
|
1401 |
} |
|
1402 |
||
1403 |
/*! |
|
1404 |
\property QAbstractItemView::defaultDropAction |
|
1405 |
\brief the drop action that will be used by default in QAbstractItemView::drag() |
|
1406 |
||
1407 |
If the property is not set, the drop action is CopyAction when the supported |
|
1408 |
actions support CopyAction. |
|
1409 |
||
1410 |
\since 4.6 |
|
1411 |
\sa showDropIndicator dragDropOverwriteMode |
|
1412 |
*/ |
|
1413 |
void QAbstractItemView::setDefaultDropAction(Qt::DropAction dropAction) |
|
1414 |
{ |
|
1415 |
Q_D(QAbstractItemView); |
|
1416 |
d->defaultDropAction = dropAction; |
|
1417 |
} |
|
1418 |
||
1419 |
Qt::DropAction QAbstractItemView::defaultDropAction() const |
|
1420 |
{ |
|
1421 |
Q_D(const QAbstractItemView); |
|
1422 |
return d->defaultDropAction; |
|
1423 |
} |
|
1424 |
||
1425 |
#endif // QT_NO_DRAGANDDROP |
|
1426 |
||
1427 |
/*! |
|
1428 |
\property QAbstractItemView::alternatingRowColors |
|
1429 |
\brief whether to draw the background using alternating colors |
|
1430 |
||
1431 |
If this property is true, the item background will be drawn using |
|
1432 |
QPalette::Base and QPalette::AlternateBase; otherwise the background |
|
1433 |
will be drawn using the QPalette::Base color. |
|
1434 |
||
1435 |
By default, this property is false. |
|
1436 |
*/ |
|
1437 |
void QAbstractItemView::setAlternatingRowColors(bool enable) |
|
1438 |
{ |
|
1439 |
Q_D(QAbstractItemView); |
|
1440 |
d->alternatingColors = enable; |
|
1441 |
if (isVisible()) |
|
1442 |
d->viewport->update(); |
|
1443 |
} |
|
1444 |
||
1445 |
bool QAbstractItemView::alternatingRowColors() const |
|
1446 |
{ |
|
1447 |
Q_D(const QAbstractItemView); |
|
1448 |
return d->alternatingColors; |
|
1449 |
} |
|
1450 |
||
1451 |
/*! |
|
1452 |
\property QAbstractItemView::iconSize |
|
1453 |
\brief the size of items' icons |
|
1454 |
||
1455 |
Setting this property when the view is visible will cause the |
|
1456 |
items to be laid out again. |
|
1457 |
*/ |
|
1458 |
void QAbstractItemView::setIconSize(const QSize &size) |
|
1459 |
{ |
|
1460 |
Q_D(QAbstractItemView); |
|
1461 |
if (size == d->iconSize) |
|
1462 |
return; |
|
1463 |
d->iconSize = size; |
|
1464 |
d->doDelayedItemsLayout(); |
|
1465 |
} |
|
1466 |
||
1467 |
QSize QAbstractItemView::iconSize() const |
|
1468 |
{ |
|
1469 |
Q_D(const QAbstractItemView); |
|
1470 |
return d->iconSize; |
|
1471 |
} |
|
1472 |
||
1473 |
/*! |
|
1474 |
\property QAbstractItemView::textElideMode |
|
1475 |
||
1476 |
\brief the position of the "..." in elided text. |
|
1477 |
||
1478 |
The default value for all item views is Qt::ElideRight. |
|
1479 |
*/ |
|
1480 |
void QAbstractItemView::setTextElideMode(Qt::TextElideMode mode) |
|
1481 |
{ |
|
1482 |
Q_D(QAbstractItemView); |
|
1483 |
d->textElideMode = mode; |
|
1484 |
} |
|
1485 |
||
1486 |
Qt::TextElideMode QAbstractItemView::textElideMode() const |
|
1487 |
{ |
|
1488 |
return d_func()->textElideMode; |
|
1489 |
} |
|
1490 |
||
1491 |
/*! |
|
1492 |
\reimp |
|
1493 |
*/ |
|
1494 |
bool QAbstractItemView::focusNextPrevChild(bool next) |
|
1495 |
{ |
|
1496 |
Q_D(QAbstractItemView); |
|
1497 |
if (d->tabKeyNavigation && isEnabled() && d->viewport->isEnabled()) { |
|
1498 |
QKeyEvent event(QEvent::KeyPress, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier); |
|
1499 |
keyPressEvent(&event); |
|
1500 |
if (event.isAccepted()) |
|
1501 |
return true; |
|
1502 |
} |
|
1503 |
return QAbstractScrollArea::focusNextPrevChild(next); |
|
1504 |
} |
|
1505 |
||
1506 |
/*! |
|
1507 |
\reimp |
|
1508 |
*/ |
|
1509 |
bool QAbstractItemView::event(QEvent *event) |
|
1510 |
{ |
|
1511 |
Q_D(QAbstractItemView); |
|
1512 |
switch (event->type()) { |
|
1513 |
case QEvent::Paint: |
|
1514 |
//we call this here because the scrollbars' visibility might be altered |
|
1515 |
//so this can't be done in the paintEvent method |
|
1516 |
d->executePostedLayout(); //make sure we set the layout properly |
|
1517 |
break; |
|
1518 |
case QEvent::Show: |
|
1519 |
d->executePostedLayout(); //make sure we set the layout properly |
|
1520 |
if (d->shouldScrollToCurrentOnShow) { |
|
1521 |
d->shouldScrollToCurrentOnShow = false; |
|
1522 |
const QModelIndex current = currentIndex(); |
|
1523 |
if (current.isValid() && (d->state == QAbstractItemView::EditingState || d->autoScroll)) |
|
1524 |
scrollTo(current); |
|
1525 |
} |
|
1526 |
break; |
|
1527 |
case QEvent::LocaleChange: |
|
1528 |
viewport()->update(); |
|
1529 |
break; |
|
1530 |
case QEvent::LayoutDirectionChange: |
|
1531 |
case QEvent::ApplicationLayoutDirectionChange: |
|
1532 |
updateGeometries(); |
|
1533 |
break; |
|
1534 |
case QEvent::StyleChange: |
|
1535 |
doItemsLayout(); |
|
1536 |
break; |
|
1537 |
case QEvent::FocusOut: |
|
1538 |
d->checkPersistentEditorFocus(); |
|
1539 |
break; |
|
1540 |
case QEvent::FontChange: |
|
1541 |
d->doDelayedItemsLayout(); // the size of the items will change |
|
1542 |
break; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1543 |
#ifdef QT_SOFTKEYS_ENABLED |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1544 |
case QEvent::LanguageChange: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1545 |
d->doneSoftKey->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::DoneSoftKey)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1546 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1547 |
#endif |
0 | 1548 |
default: |
1549 |
break; |
|
1550 |
} |
|
1551 |
return QAbstractScrollArea::event(event); |
|
1552 |
} |
|
1553 |
||
1554 |
/*! |
|
1555 |
\fn bool QAbstractItemView::viewportEvent(QEvent *event) |
|
1556 |
||
1557 |
This function is used to handle tool tips, and What's |
|
1558 |
This? mode, if the given \a event is a QEvent::ToolTip,or a |
|
1559 |
QEvent::WhatsThis. It passes all other |
|
1560 |
events on to its base class viewportEvent() handler. |
|
1561 |
*/ |
|
1562 |
bool QAbstractItemView::viewportEvent(QEvent *event) |
|
1563 |
{ |
|
1564 |
Q_D(QAbstractItemView); |
|
1565 |
switch (event->type()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1566 |
case QEvent::HoverMove: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1567 |
case QEvent::HoverEnter: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1568 |
d->setHoverIndex(indexAt(static_cast<QHoverEvent*>(event)->pos())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1569 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1570 |
case QEvent::HoverLeave: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1571 |
d->setHoverIndex(QModelIndex()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1572 |
break; |
0 | 1573 |
case QEvent::Enter: |
1574 |
d->viewportEnteredNeeded = true; |
|
1575 |
break; |
|
1576 |
case QEvent::Leave: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1577 |
#ifndef QT_NO_STATUSTIP |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1578 |
if (d->shouldClearStatusTip && d->parent) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1579 |
QString empty; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1580 |
QStatusTipEvent tip(empty); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1581 |
QApplication::sendEvent(d->parent, &tip); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1582 |
d->shouldClearStatusTip = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1583 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1584 |
#endif |
0 | 1585 |
d->enteredIndex = QModelIndex(); |
1586 |
break; |
|
1587 |
case QEvent::ToolTip: |
|
1588 |
case QEvent::QueryWhatsThis: |
|
1589 |
case QEvent::WhatsThis: { |
|
1590 |
QHelpEvent *he = static_cast<QHelpEvent*>(event); |
|
1591 |
const QModelIndex index = indexAt(he->pos()); |
|
1592 |
QStyleOptionViewItemV4 option = d->viewOptionsV4(); |
|
1593 |
option.rect = visualRect(index); |
|
1594 |
option.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None); |
|
1595 |
bool retval = false; |
|
1596 |
// ### Qt 5: make this a normal function call to a virtual function |
|
1597 |
QMetaObject::invokeMethod(d->delegateForIndex(index), "helpEvent", |
|
1598 |
Q_RETURN_ARG(bool, retval), |
|
1599 |
Q_ARG(QHelpEvent *, he), |
|
1600 |
Q_ARG(QAbstractItemView *, this), |
|
1601 |
Q_ARG(QStyleOptionViewItem, option), |
|
1602 |
Q_ARG(QModelIndex, index)); |
|
1603 |
return retval; |
|
1604 |
} |
|
1605 |
case QEvent::FontChange: |
|
1606 |
d->doDelayedItemsLayout(); // the size of the items will change |
|
1607 |
break; |
|
1608 |
case QEvent::WindowActivate: |
|
1609 |
case QEvent::WindowDeactivate: |
|
1610 |
d->viewport->update(); |
|
1611 |
break; |
|
1612 |
default: |
|
1613 |
break; |
|
1614 |
} |
|
1615 |
return QAbstractScrollArea::viewportEvent(event); |
|
1616 |
} |
|
1617 |
||
1618 |
/*! |
|
1619 |
This function is called with the given \a event when a mouse button is pressed |
|
1620 |
while the cursor is inside the widget. If a valid item is pressed on it is made |
|
1621 |
into the current item. This function emits the pressed() signal. |
|
1622 |
*/ |
|
1623 |
void QAbstractItemView::mousePressEvent(QMouseEvent *event) |
|
1624 |
{ |
|
1625 |
Q_D(QAbstractItemView); |
|
1626 |
d->delayedAutoScroll.stop(); //any interaction with the view cancel the auto scrolling |
|
1627 |
QPoint pos = event->pos(); |
|
1628 |
QPersistentModelIndex index = indexAt(pos); |
|
1629 |
||
1630 |
if (!d->selectionModel |
|
1631 |
|| (d->state == EditingState && d->hasEditor(index))) |
|
1632 |
return; |
|
1633 |
||
1634 |
d->pressedAlreadySelected = d->selectionModel->isSelected(index); |
|
1635 |
d->pressedIndex = index; |
|
1636 |
d->pressedModifiers = event->modifiers(); |
|
1637 |
QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1638 |
d->noSelectionOnMousePress = command == QItemSelectionModel::NoUpdate || !index.isValid(); |
0 | 1639 |
QPoint offset = d->offset(); |
1640 |
if ((command & QItemSelectionModel::Current) == 0) |
|
1641 |
d->pressedPosition = pos + offset; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1642 |
else if (!indexAt(d->pressedPosition - offset).isValid()) |
0 | 1643 |
d->pressedPosition = visualRect(currentIndex()).center() + offset; |
1644 |
||
1645 |
if (edit(index, NoEditTriggers, event)) |
|
1646 |
return; |
|
1647 |
||
1648 |
if (index.isValid() && d->isIndexEnabled(index)) { |
|
1649 |
// we disable scrollTo for mouse press so the item doesn't change position |
|
1650 |
// when the user is interacting with it (ie. clicking on it) |
|
1651 |
bool autoScroll = d->autoScroll; |
|
1652 |
d->autoScroll = false; |
|
1653 |
d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); |
|
1654 |
d->autoScroll = autoScroll; |
|
1655 |
QRect rect(d->pressedPosition - offset, pos); |
|
1656 |
if (command.testFlag(QItemSelectionModel::Toggle)) { |
|
1657 |
command &= ~QItemSelectionModel::Toggle; |
|
1658 |
d->ctrlDragSelectionFlag = d->selectionModel->isSelected(index) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select; |
|
1659 |
command |= d->ctrlDragSelectionFlag; |
|
1660 |
} |
|
1661 |
setSelection(rect, command); |
|
1662 |
||
1663 |
// signal handlers may change the model |
|
1664 |
emit pressed(index); |
|
1665 |
if (d->autoScroll) { |
|
1666 |
//we delay the autoscrolling to filter out double click event |
|
1667 |
//100 is to be sure that there won't be a double-click misinterpreted as a 2 single clicks |
|
1668 |
d->delayedAutoScroll.start(QApplication::doubleClickInterval()+100, this); |
|
1669 |
} |
|
1670 |
||
1671 |
} else { |
|
1672 |
// Forces a finalize() even if mouse is pressed, but not on a item |
|
1673 |
d->selectionModel->select(QModelIndex(), QItemSelectionModel::Select); |
|
1674 |
} |
|
1675 |
} |
|
1676 |
||
1677 |
/*! |
|
1678 |
This function is called with the given \a event when a mouse move event is |
|
1679 |
sent to the widget. If a selection is in progress and new items are moved |
|
1680 |
over the selection is extended; if a drag is in progress it is continued. |
|
1681 |
*/ |
|
1682 |
void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) |
|
1683 |
{ |
|
1684 |
Q_D(QAbstractItemView); |
|
1685 |
QPoint topLeft; |
|
1686 |
QPoint bottomRight = event->pos(); |
|
1687 |
||
1688 |
if (state() == ExpandingState || state() == CollapsingState) |
|
1689 |
return; |
|
1690 |
||
1691 |
#ifndef QT_NO_DRAGANDDROP |
|
1692 |
if (state() == DraggingState) { |
|
1693 |
topLeft = d->pressedPosition - d->offset(); |
|
1694 |
if ((topLeft - bottomRight).manhattanLength() > QApplication::startDragDistance()) { |
|
1695 |
d->pressedIndex = QModelIndex(); |
|
1696 |
startDrag(d->model->supportedDragActions()); |
|
1697 |
setState(NoState); // the startDrag will return when the dnd operation is done |
|
1698 |
stopAutoScroll(); |
|
1699 |
} |
|
1700 |
return; |
|
1701 |
} |
|
1702 |
#endif // QT_NO_DRAGANDDROP |
|
1703 |
||
1704 |
QPersistentModelIndex index = indexAt(bottomRight); |
|
1705 |
QModelIndex buddy = d->model->buddy(d->pressedIndex); |
|
1706 |
if ((state() == EditingState && d->hasEditor(buddy)) |
|
1707 |
|| edit(index, NoEditTriggers, event)) |
|
1708 |
return; |
|
1709 |
||
1710 |
if (d->selectionMode != SingleSelection) |
|
1711 |
topLeft = d->pressedPosition - d->offset(); |
|
1712 |
else |
|
1713 |
topLeft = bottomRight; |
|
1714 |
||
1715 |
d->checkMouseMove(index); |
|
1716 |
||
1717 |
#ifndef QT_NO_DRAGANDDROP |
|
1718 |
if (d->pressedIndex.isValid() |
|
1719 |
&& d->dragEnabled |
|
1720 |
&& (state() != DragSelectingState) |
|
1721 |
&& (event->buttons() != Qt::NoButton) |
|
1722 |
&& !d->selectedDraggableIndexes().isEmpty()) { |
|
1723 |
setState(DraggingState); |
|
1724 |
return; |
|
1725 |
} |
|
1726 |
#endif |
|
1727 |
||
1728 |
if ((event->buttons() & Qt::LeftButton) && d->selectionAllowed(index) && d->selectionModel) { |
|
1729 |
setState(DragSelectingState); |
|
1730 |
QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); |
|
1731 |
if (d->ctrlDragSelectionFlag != QItemSelectionModel::NoUpdate && command.testFlag(QItemSelectionModel::Toggle)) { |
|
1732 |
command &= ~QItemSelectionModel::Toggle; |
|
1733 |
command |= d->ctrlDragSelectionFlag; |
|
1734 |
} |
|
1735 |
||
1736 |
// Do the normalize ourselves, since QRect::normalized() is flawed |
|
1737 |
QRect selectionRect = QRect(topLeft, bottomRight); |
|
1738 |
setSelection(selectionRect, command); |
|
1739 |
||
1740 |
// set at the end because it might scroll the view |
|
1741 |
if (index.isValid() |
|
1742 |
&& (index != d->selectionModel->currentIndex()) |
|
1743 |
&& d->isIndexEnabled(index)) |
|
1744 |
d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate); |
|
1745 |
} |
|
1746 |
} |
|
1747 |
||
1748 |
/*! |
|
1749 |
This function is called with the given \a event when a mouse button is released, |
|
1750 |
after a mouse press event on the widget. If a user presses the mouse inside your |
|
1751 |
widget and then drags the mouse to another location before releasing the mouse button, |
|
1752 |
your widget receives the release event. The function will emit the clicked() signal if an |
|
1753 |
item was being pressed. |
|
1754 |
*/ |
|
1755 |
void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event) |
|
1756 |
{ |
|
1757 |
Q_D(QAbstractItemView); |
|
1758 |
||
1759 |
QPoint pos = event->pos(); |
|
1760 |
QPersistentModelIndex index = indexAt(pos); |
|
1761 |
||
1762 |
if (state() == EditingState) { |
|
1763 |
if (d->isIndexValid(index) |
|
1764 |
&& d->isIndexEnabled(index) |
|
1765 |
&& d->sendDelegateEvent(index, event)) |
|
1766 |
update(index); |
|
1767 |
return; |
|
1768 |
} |
|
1769 |
||
1770 |
bool click = (index == d->pressedIndex && index.isValid()); |
|
1771 |
bool selectedClicked = click && (event->button() & Qt::LeftButton) && d->pressedAlreadySelected; |
|
1772 |
EditTrigger trigger = (selectedClicked ? SelectedClicked : NoEditTriggers); |
|
1773 |
bool edited = edit(index, trigger, event); |
|
1774 |
||
1775 |
d->ctrlDragSelectionFlag = QItemSelectionModel::NoUpdate; |
|
1776 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1777 |
if (d->selectionModel && d->noSelectionOnMousePress) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1778 |
d->noSelectionOnMousePress = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1779 |
d->selectionModel->select(index, selectionCommand(index, event)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1780 |
} |
0 | 1781 |
|
1782 |
setState(NoState); |
|
1783 |
||
1784 |
if (click) { |
|
1785 |
emit clicked(index); |
|
1786 |
if (edited) |
|
1787 |
return; |
|
1788 |
if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) |
|
1789 |
emit activated(index); |
|
1790 |
} |
|
1791 |
} |
|
1792 |
||
1793 |
/*! |
|
1794 |
This function is called with the given \a event when a mouse button is |
|
1795 |
double clicked inside the widget. If the double-click is on a valid item it |
|
1796 |
emits the doubleClicked() signal and calls edit() on the item. |
|
1797 |
*/ |
|
1798 |
void QAbstractItemView::mouseDoubleClickEvent(QMouseEvent *event) |
|
1799 |
{ |
|
1800 |
Q_D(QAbstractItemView); |
|
1801 |
||
1802 |
QModelIndex index = indexAt(event->pos()); |
|
1803 |
if (!index.isValid() |
|
1804 |
|| !d->isIndexEnabled(index) |
|
1805 |
|| (d->pressedIndex != index)) { |
|
1806 |
QMouseEvent me(QEvent::MouseButtonPress, |
|
1807 |
event->pos(), event->button(), |
|
1808 |
event->buttons(), event->modifiers()); |
|
1809 |
mousePressEvent(&me); |
|
1810 |
return; |
|
1811 |
} |
|
1812 |
// signal handlers may change the model |
|
1813 |
QPersistentModelIndex persistent = index; |
|
1814 |
emit doubleClicked(persistent); |
|
1815 |
if ((event->button() & Qt::LeftButton) && !edit(persistent, DoubleClicked, event) |
|
1816 |
&& !style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) |
|
1817 |
emit activated(persistent); |
|
1818 |
} |
|
1819 |
||
1820 |
#ifndef QT_NO_DRAGANDDROP |
|
1821 |
||
1822 |
/*! |
|
1823 |
This function is called with the given \a event when a drag and drop operation enters |
|
1824 |
the widget. If the drag is over a valid dropping place (e.g. over an item that |
|
1825 |
accepts drops), the event is accepted; otherwise it is ignored. |
|
1826 |
||
1827 |
\sa dropEvent() startDrag() |
|
1828 |
*/ |
|
1829 |
void QAbstractItemView::dragEnterEvent(QDragEnterEvent *event) |
|
1830 |
{ |
|
1831 |
if (dragDropMode() == InternalMove |
|
1832 |
&& (event->source() != this|| !(event->possibleActions() & Qt::MoveAction))) |
|
1833 |
return; |
|
1834 |
||
1835 |
if (d_func()->canDecode(event)) { |
|
1836 |
event->accept(); |
|
1837 |
setState(DraggingState); |
|
1838 |
} else { |
|
1839 |
event->ignore(); |
|
1840 |
} |
|
1841 |
} |
|
1842 |
||
1843 |
/*! |
|
1844 |
This function is called continuously with the given \a event during a drag and |
|
1845 |
drop operation over the widget. It can cause the view to scroll if, for example, |
|
1846 |
the user drags a selection to view's right or bottom edge. In this case, the |
|
1847 |
event will be accepted; otherwise it will be ignored. |
|
1848 |
||
1849 |
\sa dropEvent() startDrag() |
|
1850 |
*/ |
|
1851 |
void QAbstractItemView::dragMoveEvent(QDragMoveEvent *event) |
|
1852 |
{ |
|
1853 |
Q_D(QAbstractItemView); |
|
1854 |
if (dragDropMode() == InternalMove |
|
1855 |
&& (event->source() != this || !(event->possibleActions() & Qt::MoveAction))) |
|
1856 |
return; |
|
1857 |
||
1858 |
// ignore by default |
|
1859 |
event->ignore(); |
|
1860 |
||
1861 |
QModelIndex index = indexAt(event->pos()); |
|
1862 |
d->hover = index; |
|
1863 |
if (!d->droppingOnItself(event, index) |
|
1864 |
&& d->canDecode(event)) { |
|
1865 |
||
1866 |
if (index.isValid() && d->showDropIndicator) { |
|
1867 |
QRect rect = visualRect(index); |
|
1868 |
d->dropIndicatorPosition = d->position(event->pos(), rect, index); |
|
1869 |
switch (d->dropIndicatorPosition) { |
|
1870 |
case AboveItem: |
|
1871 |
if (d->isIndexDropEnabled(index.parent())) { |
|
1872 |
d->dropIndicatorRect = QRect(rect.left(), rect.top(), rect.width(), 0); |
|
1873 |
event->accept(); |
|
1874 |
} else { |
|
1875 |
d->dropIndicatorRect = QRect(); |
|
1876 |
} |
|
1877 |
break; |
|
1878 |
case BelowItem: |
|
1879 |
if (d->isIndexDropEnabled(index.parent())) { |
|
1880 |
d->dropIndicatorRect = QRect(rect.left(), rect.bottom(), rect.width(), 0); |
|
1881 |
event->accept(); |
|
1882 |
} else { |
|
1883 |
d->dropIndicatorRect = QRect(); |
|
1884 |
} |
|
1885 |
break; |
|
1886 |
case OnItem: |
|
1887 |
if (d->isIndexDropEnabled(index)) { |
|
1888 |
d->dropIndicatorRect = rect; |
|
1889 |
event->accept(); |
|
1890 |
} else { |
|
1891 |
d->dropIndicatorRect = QRect(); |
|
1892 |
} |
|
1893 |
break; |
|
1894 |
case OnViewport: |
|
1895 |
d->dropIndicatorRect = QRect(); |
|
1896 |
if (d->isIndexDropEnabled(rootIndex())) { |
|
1897 |
event->accept(); // allow dropping in empty areas |
|
1898 |
} |
|
1899 |
break; |
|
1900 |
} |
|
1901 |
} else { |
|
1902 |
d->dropIndicatorRect = QRect(); |
|
1903 |
d->dropIndicatorPosition = OnViewport; |
|
1904 |
if (d->isIndexDropEnabled(rootIndex())) { |
|
1905 |
event->accept(); // allow dropping in empty areas |
|
1906 |
} |
|
1907 |
} |
|
1908 |
d->viewport->update(); |
|
1909 |
} // can decode |
|
1910 |
||
1911 |
if (d->shouldAutoScroll(event->pos())) |
|
1912 |
startAutoScroll(); |
|
1913 |
} |
|
1914 |
||
1915 |
/*! |
|
1916 |
\internal |
|
1917 |
Return true if this is a move from ourself and \a index is a child of the selection that |
|
1918 |
is being moved. |
|
1919 |
*/ |
|
1920 |
bool QAbstractItemViewPrivate::droppingOnItself(QDropEvent *event, const QModelIndex &index) |
|
1921 |
{ |
|
1922 |
Q_Q(QAbstractItemView); |
|
1923 |
Qt::DropAction dropAction = event->dropAction(); |
|
1924 |
if (q->dragDropMode() == QAbstractItemView::InternalMove) |
|
1925 |
dropAction = Qt::MoveAction; |
|
1926 |
if (event->source() == q |
|
1927 |
&& event->possibleActions() & Qt::MoveAction |
|
1928 |
&& dropAction == Qt::MoveAction) { |
|
1929 |
QModelIndexList selectedIndexes = q->selectedIndexes(); |
|
1930 |
QModelIndex child = index; |
|
1931 |
while (child.isValid() && child != root) { |
|
1932 |
if (selectedIndexes.contains(child)) |
|
1933 |
return true; |
|
1934 |
child = child.parent(); |
|
1935 |
} |
|
1936 |
} |
|
1937 |
return false; |
|
1938 |
} |
|
1939 |
||
1940 |
/*! |
|
1941 |
\fn void QAbstractItemView::dragLeaveEvent(QDragLeaveEvent *event) |
|
1942 |
||
1943 |
This function is called when the item being dragged leaves the view. |
|
1944 |
The \a event describes the state of the drag and drop operation. |
|
1945 |
*/ |
|
1946 |
void QAbstractItemView::dragLeaveEvent(QDragLeaveEvent *) |
|
1947 |
{ |
|
1948 |
Q_D(QAbstractItemView); |
|
1949 |
stopAutoScroll(); |
|
1950 |
setState(NoState); |
|
1951 |
d->hover = QModelIndex(); |
|
1952 |
d->viewport->update(); |
|
1953 |
} |
|
1954 |
||
1955 |
/*! |
|
1956 |
This function is called with the given \a event when a drop event occurs over |
|
1957 |
the widget. If the model accepts the even position the drop event is accepted; |
|
1958 |
otherwise it is ignored. |
|
1959 |
||
1960 |
\sa startDrag() |
|
1961 |
*/ |
|
1962 |
void QAbstractItemView::dropEvent(QDropEvent *event) |
|
1963 |
{ |
|
1964 |
Q_D(QAbstractItemView); |
|
1965 |
if (dragDropMode() == InternalMove) { |
|
1966 |
if (event->source() != this || !(event->possibleActions() & Qt::MoveAction)) |
|
1967 |
return; |
|
1968 |
} |
|
1969 |
||
1970 |
QModelIndex index; |
|
1971 |
int col = -1; |
|
1972 |
int row = -1; |
|
1973 |
if (d->dropOn(event, &row, &col, &index)) { |
|
1974 |
if (d->model->dropMimeData(event->mimeData(), |
|
1975 |
dragDropMode() == InternalMove ? Qt::MoveAction : event->dropAction(), row, col, index)) { |
|
1976 |
if (dragDropMode() == InternalMove) |
|
1977 |
event->setDropAction(Qt::MoveAction); |
|
1978 |
event->accept(); |
|
1979 |
} |
|
1980 |
} |
|
1981 |
stopAutoScroll(); |
|
1982 |
setState(NoState); |
|
1983 |
d->viewport->update(); |
|
1984 |
} |
|
1985 |
||
1986 |
/*! |
|
1987 |
If the event hasn't already been accepted, determines the index to drop on. |
|
1988 |
||
1989 |
if (row == -1 && col == -1) |
|
1990 |
// append to this drop index |
|
1991 |
else |
|
1992 |
// place at row, col in drop index |
|
1993 |
||
1994 |
If it returns true a drop can be done, and dropRow, dropCol and dropIndex reflects the position of the drop. |
|
1995 |
\internal |
|
1996 |
*/ |
|
1997 |
bool QAbstractItemViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex) |
|
1998 |
{ |
|
1999 |
Q_Q(QAbstractItemView); |
|
2000 |
if (event->isAccepted()) |
|
2001 |
return false; |
|
2002 |
||
2003 |
QModelIndex index; |
|
2004 |
// rootIndex() (i.e. the viewport) might be a valid index |
|
2005 |
if (viewport->rect().contains(event->pos())) { |
|
2006 |
index = q->indexAt(event->pos()); |
|
2007 |
if (!index.isValid() || !q->visualRect(index).contains(event->pos())) |
|
2008 |
index = root; |
|
2009 |
} |
|
2010 |
||
2011 |
// If we are allowed to do the drop |
|
2012 |
if (model->supportedDropActions() & event->dropAction()) { |
|
2013 |
int row = -1; |
|
2014 |
int col = -1; |
|
2015 |
if (index != root) { |
|
2016 |
dropIndicatorPosition = position(event->pos(), q->visualRect(index), index); |
|
2017 |
switch (dropIndicatorPosition) { |
|
2018 |
case QAbstractItemView::AboveItem: |
|
2019 |
row = index.row(); |
|
2020 |
col = index.column(); |
|
2021 |
index = index.parent(); |
|
2022 |
break; |
|
2023 |
case QAbstractItemView::BelowItem: |
|
2024 |
row = index.row() + 1; |
|
2025 |
col = index.column(); |
|
2026 |
index = index.parent(); |
|
2027 |
break; |
|
2028 |
case QAbstractItemView::OnItem: |
|
2029 |
case QAbstractItemView::OnViewport: |
|
2030 |
break; |
|
2031 |
} |
|
2032 |
} else { |
|
2033 |
dropIndicatorPosition = QAbstractItemView::OnViewport; |
|
2034 |
} |
|
2035 |
*dropIndex = index; |
|
2036 |
*dropRow = row; |
|
2037 |
*dropCol = col; |
|
2038 |
if (!droppingOnItself(event, index)) |
|
2039 |
return true; |
|
2040 |
} |
|
2041 |
return false; |
|
2042 |
} |
|
2043 |
||
2044 |
QAbstractItemView::DropIndicatorPosition |
|
2045 |
QAbstractItemViewPrivate::position(const QPoint &pos, const QRect &rect, const QModelIndex &index) const |
|
2046 |
{ |
|
2047 |
QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport; |
|
2048 |
if (!overwrite) { |
|
2049 |
const int margin = 2; |
|
2050 |
if (pos.y() - rect.top() < margin) { |
|
2051 |
r = QAbstractItemView::AboveItem; |
|
2052 |
} else if (rect.bottom() - pos.y() < margin) { |
|
2053 |
r = QAbstractItemView::BelowItem; |
|
2054 |
} else if (rect.contains(pos, true)) { |
|
2055 |
r = QAbstractItemView::OnItem; |
|
2056 |
} |
|
2057 |
} else { |
|
2058 |
QRect touchingRect = rect; |
|
2059 |
touchingRect.adjust(-1, -1, 1, 1); |
|
2060 |
if (touchingRect.contains(pos, false)) { |
|
2061 |
r = QAbstractItemView::OnItem; |
|
2062 |
} |
|
2063 |
} |
|
2064 |
||
2065 |
if (r == QAbstractItemView::OnItem && (!(model->flags(index) & Qt::ItemIsDropEnabled))) |
|
2066 |
r = pos.y() < rect.center().y() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem; |
|
2067 |
||
2068 |
return r; |
|
2069 |
} |
|
2070 |
||
2071 |
#endif // QT_NO_DRAGANDDROP |
|
2072 |
||
2073 |
/*! |
|
2074 |
This function is called with the given \a event when the widget obtains the focus. |
|
2075 |
By default, the event is ignored. |
|
2076 |
||
2077 |
\sa setFocus(), focusOutEvent() |
|
2078 |
*/ |
|
2079 |
void QAbstractItemView::focusInEvent(QFocusEvent *event) |
|
2080 |
{ |
|
2081 |
Q_D(QAbstractItemView); |
|
2082 |
QAbstractScrollArea::focusInEvent(event); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2083 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2084 |
const QItemSelectionModel* model = selectionModel(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2085 |
const bool currentIndexValid = currentIndex().isValid(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2086 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2087 |
if (model |
0 | 2088 |
&& !d->currentIndexSet |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2089 |
&& !currentIndexValid) { |
0 | 2090 |
bool autoScroll = d->autoScroll; |
2091 |
d->autoScroll = false; |
|
2092 |
QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); // first visible index |
|
2093 |
if (index.isValid() && d->isIndexEnabled(index)) |
|
2094 |
selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); |
|
2095 |
d->autoScroll = autoScroll; |
|
2096 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2097 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2098 |
if (model && currentIndexValid) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2099 |
if (currentIndex().flags() != Qt::ItemIsEditable) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2100 |
setAttribute(Qt::WA_InputMethodEnabled, false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2101 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2102 |
setAttribute(Qt::WA_InputMethodEnabled); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2103 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2104 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2105 |
if (!currentIndexValid) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2106 |
setAttribute(Qt::WA_InputMethodEnabled, false); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2107 |
|
0 | 2108 |
d->viewport->update(); |
2109 |
} |
|
2110 |
||
2111 |
/*! |
|
2112 |
This function is called with the given \a event when the widget |
|
2113 |
looses the focus. By default, the event is ignored. |
|
2114 |
||
2115 |
\sa clearFocus(), focusInEvent() |
|
2116 |
*/ |
|
2117 |
void QAbstractItemView::focusOutEvent(QFocusEvent *event) |
|
2118 |
{ |
|
2119 |
Q_D(QAbstractItemView); |
|
2120 |
QAbstractScrollArea::focusOutEvent(event); |
|
2121 |
d->viewport->update(); |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2122 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2123 |
#ifdef QT_SOFTKEYS_ENABLED |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2124 |
if(!hasEditFocus()) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2125 |
removeAction(d->doneSoftKey); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2126 |
#endif |
0 | 2127 |
} |
2128 |
||
2129 |
/*! |
|
2130 |
This function is called with the given \a event when a key event is sent to |
|
2131 |
the widget. The default implementation handles basic cursor movement, e.g. Up, |
|
2132 |
Down, Left, Right, Home, PageUp, and PageDown; the activated() signal is |
|
2133 |
emitted if the current index is valid and the activation key is pressed |
|
2134 |
(e.g. Enter or Return, depending on the platform). |
|
2135 |
This function is where editing is initiated by key press, e.g. if F2 is |
|
2136 |
pressed. |
|
2137 |
||
2138 |
\sa edit(), moveCursor(), keyboardSearch(), tabKeyNavigation |
|
2139 |
*/ |
|
2140 |
void QAbstractItemView::keyPressEvent(QKeyEvent *event) |
|
2141 |
{ |
|
2142 |
Q_D(QAbstractItemView); |
|
2143 |
d->delayedAutoScroll.stop(); //any interaction with the view cancel the auto scrolling |
|
2144 |
||
2145 |
#ifdef QT_KEYPAD_NAVIGATION |
|
2146 |
switch (event->key()) { |
|
2147 |
case Qt::Key_Select: |
|
2148 |
if (QApplication::keypadNavigationEnabled()) { |
|
2149 |
if (!hasEditFocus()) { |
|
2150 |
setEditFocus(true); |
|
2151 |
#ifdef QT_SOFTKEYS_ENABLED |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2152 |
// If we can't keypad navigate to any direction, there is no sense to add |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2153 |
// "Done" softkey, since it basically does nothing when there is |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2154 |
// only one widget in screen |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2155 |
if(QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2156 |
|| QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2157 |
addAction(d->doneSoftKey); |
0 | 2158 |
#endif |
2159 |
return; |
|
2160 |
} |
|
2161 |
} |
|
2162 |
break; |
|
2163 |
case Qt::Key_Back: |
|
2164 |
if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { |
|
2165 |
#ifdef QT_SOFTKEYS_ENABLED |
|
2166 |
removeAction(d->doneSoftKey); |
|
2167 |
#endif |
|
2168 |
setEditFocus(false); |
|
2169 |
} else { |
|
2170 |
event->ignore(); |
|
2171 |
} |
|
2172 |
return; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2173 |
case Qt::Key_Down: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2174 |
case Qt::Key_Up: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2175 |
// Let's ignore vertical navigation events, only if there is no other widget |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2176 |
// what can take the focus in vertical direction. This means widget can handle navigation events |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2177 |
// even the widget don't have edit focus, and there is no other widget in requested direction. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2178 |
if(QApplication::keypadNavigationEnabled() && !hasEditFocus() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2179 |
&& QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2180 |
event->ignore(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2181 |
return; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2182 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2183 |
break; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2184 |
case Qt::Key_Left: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2185 |
case Qt::Key_Right: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2186 |
// Similar logic as in up and down events |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2187 |
if(QApplication::keypadNavigationEnabled() && !hasEditFocus() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2188 |
&& (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this))) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2189 |
event->ignore(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2190 |
return; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2191 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2192 |
break; |
0 | 2193 |
default: |
2194 |
if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { |
|
2195 |
event->ignore(); |
|
2196 |
return; |
|
2197 |
} |
|
2198 |
} |
|
2199 |
#endif |
|
2200 |
||
2201 |
#if !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT) |
|
2202 |
if (event == QKeySequence::Copy) { |
|
2203 |
QVariant variant; |
|
2204 |
if (d->model) |
|
2205 |
variant = d->model->data(currentIndex(), Qt::DisplayRole); |
|
2206 |
if (variant.type() == QVariant::String) |
|
2207 |
QApplication::clipboard()->setText(variant.toString()); |
|
2208 |
event->accept(); |
|
2209 |
} |
|
2210 |
#endif |
|
2211 |
||
2212 |
QPersistentModelIndex newCurrent; |
|
2213 |
switch (event->key()) { |
|
2214 |
case Qt::Key_Down: |
|
2215 |
newCurrent = moveCursor(MoveDown, event->modifiers()); |
|
2216 |
break; |
|
2217 |
case Qt::Key_Up: |
|
2218 |
newCurrent = moveCursor(MoveUp, event->modifiers()); |
|
2219 |
break; |
|
2220 |
case Qt::Key_Left: |
|
2221 |
newCurrent = moveCursor(MoveLeft, event->modifiers()); |
|
2222 |
break; |
|
2223 |
case Qt::Key_Right: |
|
2224 |
newCurrent = moveCursor(MoveRight, event->modifiers()); |
|
2225 |
break; |
|
2226 |
case Qt::Key_Home: |
|
2227 |
newCurrent = moveCursor(MoveHome, event->modifiers()); |
|
2228 |
break; |
|
2229 |
case Qt::Key_End: |
|
2230 |
newCurrent = moveCursor(MoveEnd, event->modifiers()); |
|
2231 |
break; |
|
2232 |
case Qt::Key_PageUp: |
|
2233 |
newCurrent = moveCursor(MovePageUp, event->modifiers()); |
|
2234 |
break; |
|
2235 |
case Qt::Key_PageDown: |
|
2236 |
newCurrent = moveCursor(MovePageDown, event->modifiers()); |
|
2237 |
break; |
|
2238 |
case Qt::Key_Tab: |
|
2239 |
if (d->tabKeyNavigation) |
|
2240 |
newCurrent = moveCursor(MoveNext, event->modifiers()); |
|
2241 |
break; |
|
2242 |
case Qt::Key_Backtab: |
|
2243 |
if (d->tabKeyNavigation) |
|
2244 |
newCurrent = moveCursor(MovePrevious, event->modifiers()); |
|
2245 |
break; |
|
2246 |
} |
|
2247 |
||
2248 |
QPersistentModelIndex oldCurrent = currentIndex(); |
|
2249 |
if (newCurrent != oldCurrent && newCurrent.isValid() && d->isIndexEnabled(newCurrent)) { |
|
2250 |
if (!hasFocus() && QApplication::focusWidget() == indexWidget(oldCurrent)) |
|
2251 |
setFocus(); |
|
2252 |
QItemSelectionModel::SelectionFlags command = selectionCommand(newCurrent, event); |
|
2253 |
if (command != QItemSelectionModel::NoUpdate |
|
2254 |
|| style()->styleHint(QStyle::SH_ItemView_MovementWithoutUpdatingSelection, 0, this)) { |
|
2255 |
// note that we don't check if the new current index is enabled because moveCursor() makes sure it is |
|
2256 |
if (command & QItemSelectionModel::Current) { |
|
2257 |
d->selectionModel->setCurrentIndex(newCurrent, QItemSelectionModel::NoUpdate); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2258 |
if (!indexAt(d->pressedPosition - d->offset()).isValid()) |
0 | 2259 |
d->pressedPosition = visualRect(oldCurrent).center() + d->offset(); |
2260 |
QRect rect(d->pressedPosition - d->offset(), visualRect(newCurrent).center()); |
|
2261 |
setSelection(rect, command); |
|
2262 |
} else { |
|
2263 |
d->selectionModel->setCurrentIndex(newCurrent, command); |
|
2264 |
d->pressedPosition = visualRect(newCurrent).center() + d->offset(); |
|
2265 |
// We copy the same behaviour as for mousePressEvent(). |
|
2266 |
QRect rect(d->pressedPosition - d->offset(), QSize(1, 1)); |
|
2267 |
setSelection(rect, command); |
|
2268 |
} |
|
2269 |
return; |
|
2270 |
} |
|
2271 |
} |
|
2272 |
||
2273 |
switch (event->key()) { |
|
2274 |
// ignored keys |
|
2275 |
case Qt::Key_Down: |
|
2276 |
case Qt::Key_Up: |
|
2277 |
#ifdef QT_KEYPAD_NAVIGATION |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2278 |
if (QApplication::keypadNavigationEnabled() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical)) { |
0 | 2279 |
event->accept(); // don't change focus |
2280 |
break; |
|
2281 |
} |
|
2282 |
#endif |
|
2283 |
case Qt::Key_Left: |
|
2284 |
case Qt::Key_Right: |
|
2285 |
#ifdef QT_KEYPAD_NAVIGATION |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2286 |
if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2287 |
&& (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2288 |
|| (QWidgetPrivate::inTabWidget(this) && d->model->columnCount(d->root) > 1))) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2289 |
event->accept(); // don't change focus |
0 | 2290 |
break; |
2291 |
} |
|
2292 |
#endif // QT_KEYPAD_NAVIGATION |
|
2293 |
case Qt::Key_Home: |
|
2294 |
case Qt::Key_End: |
|
2295 |
case Qt::Key_PageUp: |
|
2296 |
case Qt::Key_PageDown: |
|
2297 |
case Qt::Key_Escape: |
|
2298 |
case Qt::Key_Shift: |
|
2299 |
case Qt::Key_Control: |
|
2300 |
event->ignore(); |
|
2301 |
break; |
|
2302 |
case Qt::Key_Space: |
|
2303 |
case Qt::Key_Select: |
|
2304 |
if (!edit(currentIndex(), AnyKeyPressed, event) && d->selectionModel) |
|
2305 |
d->selectionModel->select(currentIndex(), selectionCommand(currentIndex(), event)); |
|
2306 |
#ifdef QT_KEYPAD_NAVIGATION |
|
2307 |
if ( event->key()==Qt::Key_Select ) { |
|
2308 |
// Also do Key_Enter action. |
|
2309 |
if (currentIndex().isValid()) { |
|
2310 |
if (state() != EditingState) |
|
2311 |
emit activated(currentIndex()); |
|
2312 |
} else { |
|
2313 |
event->ignore(); |
|
2314 |
} |
|
2315 |
} |
|
2316 |
#endif |
|
2317 |
break; |
|
2318 |
#ifdef Q_WS_MAC |
|
2319 |
case Qt::Key_Enter: |
|
2320 |
case Qt::Key_Return: |
|
2321 |
// Propagate the enter if you couldn't edit the item and there are no |
|
2322 |
// current editors (if there are editors, the event was most likely propagated from it). |
|
2323 |
if (!edit(currentIndex(), EditKeyPressed, event) && d->editors.isEmpty()) |
|
2324 |
event->ignore(); |
|
2325 |
break; |
|
2326 |
#else |
|
2327 |
case Qt::Key_F2: |
|
2328 |
if (!edit(currentIndex(), EditKeyPressed, event)) |
|
2329 |
event->ignore(); |
|
2330 |
break; |
|
2331 |
case Qt::Key_Enter: |
|
2332 |
case Qt::Key_Return: |
|
2333 |
// ### we can't open the editor on enter, becuse |
|
2334 |
// some widgets will forward the enter event back |
|
2335 |
// to the viewport, starting an endless loop |
|
2336 |
if (state() != EditingState || hasFocus()) { |
|
2337 |
if (currentIndex().isValid()) |
|
2338 |
emit activated(currentIndex()); |
|
2339 |
event->ignore(); |
|
2340 |
} |
|
2341 |
break; |
|
2342 |
#endif |
|
2343 |
case Qt::Key_A: |
|
2344 |
if (event->modifiers() & Qt::ControlModifier) { |
|
2345 |
selectAll(); |
|
2346 |
break; |
|
2347 |
} |
|
2348 |
default: { |
|
2349 |
#ifdef Q_WS_MAC |
|
2350 |
if (event->key() == Qt::Key_O && event->modifiers() & Qt::ControlModifier && currentIndex().isValid()) { |
|
2351 |
emit activated(currentIndex()); |
|
2352 |
break; |
|
2353 |
} |
|
2354 |
#endif |
|
2355 |
bool modified = (event->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier)); |
|
2356 |
if (!event->text().isEmpty() && !modified && !edit(currentIndex(), AnyKeyPressed, event)) { |
|
2357 |
keyboardSearch(event->text()); |
|
2358 |
event->accept(); |
|
2359 |
} else { |
|
2360 |
event->ignore(); |
|
2361 |
} |
|
2362 |
break; } |
|
2363 |
} |
|
2364 |
} |
|
2365 |
||
2366 |
/*! |
|
2367 |
This function is called with the given \a event when a resize event is sent to |
|
2368 |
the widget. |
|
2369 |
||
2370 |
\sa QWidget::resizeEvent() |
|
2371 |
*/ |
|
2372 |
void QAbstractItemView::resizeEvent(QResizeEvent *event) |
|
2373 |
{ |
|
2374 |
QAbstractScrollArea::resizeEvent(event); |
|
2375 |
updateGeometries(); |
|
2376 |
} |
|
2377 |
||
2378 |
/*! |
|
2379 |
This function is called with the given \a event when a timer event is sent |
|
2380 |
to the widget. |
|
2381 |
||
2382 |
\sa QObject::timerEvent() |
|
2383 |
*/ |
|
2384 |
void QAbstractItemView::timerEvent(QTimerEvent *event) |
|
2385 |
{ |
|
2386 |
Q_D(QAbstractItemView); |
|
2387 |
if (event->timerId() == d->fetchMoreTimer.timerId()) |
|
2388 |
d->fetchMore(); |
|
2389 |
else if (event->timerId() == d->delayedReset.timerId()) |
|
2390 |
reset(); |
|
2391 |
else if (event->timerId() == d->autoScrollTimer.timerId()) |
|
2392 |
doAutoScroll(); |
|
2393 |
else if (event->timerId() == d->updateTimer.timerId()) |
|
2394 |
d->updateDirtyRegion(); |
|
2395 |
else if (event->timerId() == d->delayedEditing.timerId()) { |
|
2396 |
d->delayedEditing.stop(); |
|
2397 |
edit(currentIndex()); |
|
2398 |
} else if (event->timerId() == d->delayedLayout.timerId()) { |
|
2399 |
d->delayedLayout.stop(); |
|
2400 |
if (isVisible()) { |
|
2401 |
d->interruptDelayedItemsLayout(); |
|
2402 |
doItemsLayout(); |
|
2403 |
const QModelIndex current = currentIndex(); |
|
2404 |
if (current.isValid() && d->state == QAbstractItemView::EditingState) |
|
2405 |
scrollTo(current); |
|
2406 |
} |
|
2407 |
} else if (event->timerId() == d->delayedAutoScroll.timerId()) { |
|
2408 |
d->delayedAutoScroll.stop(); |
|
2409 |
//end of the timer: if the current item is still the same as the one when the mouse press occurred |
|
2410 |
//we only get here if there was no double click |
|
2411 |
if (d->pressedIndex.isValid() && d->pressedIndex == currentIndex()) |
|
2412 |
scrollTo(d->pressedIndex); |
|
2413 |
} |
|
2414 |
} |
|
2415 |
||
2416 |
/*! |
|
2417 |
\reimp |
|
2418 |
*/ |
|
2419 |
void QAbstractItemView::inputMethodEvent(QInputMethodEvent *event) |
|
2420 |
{ |
|
2421 |
if (event->commitString().isEmpty() && event->preeditString().isEmpty()) { |
|
2422 |
event->ignore(); |
|
2423 |
return; |
|
2424 |
} |
|
2425 |
if (!edit(currentIndex(), AnyKeyPressed, event)) { |
|
2426 |
if (!event->commitString().isEmpty()) |
|
2427 |
keyboardSearch(event->commitString()); |
|
2428 |
event->ignore(); |
|
2429 |
} |
|
2430 |
} |
|
2431 |
||
2432 |
#ifndef QT_NO_DRAGANDDROP |
|
2433 |
/*! |
|
2434 |
\enum QAbstractItemView::DropIndicatorPosition |
|
2435 |
||
2436 |
This enum indicates the position of the drop indicator in |
|
2437 |
relation to the index at the current mouse position: |
|
2438 |
||
2439 |
\value OnItem The item will be dropped on the index. |
|
2440 |
||
2441 |
\value AboveItem The item will be dropped above the index. |
|
2442 |
||
2443 |
\value BelowItem The item will be dropped below the index. |
|
2444 |
||
2445 |
\value OnViewport The item will be dropped onto a region of the viewport with |
|
2446 |
no items. The way each view handles items dropped onto the viewport depends on |
|
2447 |
the behavior of the underlying model in use. |
|
2448 |
*/ |
|
2449 |
||
2450 |
||
2451 |
/*! |
|
2452 |
\since 4.1 |
|
2453 |
||
2454 |
Returns the position of the drop indicator in relation to the closest item. |
|
2455 |
*/ |
|
2456 |
QAbstractItemView::DropIndicatorPosition QAbstractItemView::dropIndicatorPosition() const |
|
2457 |
{ |
|
2458 |
Q_D(const QAbstractItemView); |
|
2459 |
return d->dropIndicatorPosition; |
|
2460 |
} |
|
2461 |
#endif |
|
2462 |
||
2463 |
/*! |
|
2464 |
This convenience function returns a list of all selected and |
|
2465 |
non-hidden item indexes in the view. The list contains no |
|
2466 |
duplicates, and is not sorted. |
|
2467 |
||
2468 |
\sa QItemSelectionModel::selectedIndexes() |
|
2469 |
*/ |
|
2470 |
QModelIndexList QAbstractItemView::selectedIndexes() const |
|
2471 |
{ |
|
2472 |
Q_D(const QAbstractItemView); |
|
2473 |
QModelIndexList indexes; |
|
2474 |
if (d->selectionModel) { |
|
2475 |
indexes = d->selectionModel->selectedIndexes(); |
|
2476 |
QList<QModelIndex>::iterator it = indexes.begin(); |
|
2477 |
while (it != indexes.end()) |
|
2478 |
if (isIndexHidden(*it)) |
|
2479 |
it = indexes.erase(it); |
|
2480 |
else |
|
2481 |
++it; |
|
2482 |
} |
|
2483 |
return indexes; |
|
2484 |
} |
|
2485 |
||
2486 |
/*! |
|
2487 |
Starts editing the item at \a index, creating an editor if |
|
2488 |
necessary, and returns true if the view's \l{State} is now |
|
2489 |
EditingState; otherwise returns false. |
|
2490 |
||
2491 |
The action that caused the editing process is described by |
|
2492 |
\a trigger, and the associated event is specified by \a event. |
|
2493 |
||
2494 |
Editing can be forced by specifying the \a trigger to be |
|
2495 |
QAbstractItemView::AllEditTriggers. |
|
2496 |
||
2497 |
\sa closeEditor() |
|
2498 |
*/ |
|
2499 |
bool QAbstractItemView::edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) |
|
2500 |
{ |
|
2501 |
Q_D(QAbstractItemView); |
|
2502 |
||
2503 |
if (!d->isIndexValid(index)) |
|
2504 |
return false; |
|
2505 |
||
2506 |
if (QWidget *w = (d->persistent.isEmpty() ? static_cast<QWidget*>(0) : d->editorForIndex(index).editor.data())) { |
|
2507 |
if (w->focusPolicy() == Qt::NoFocus) |
|
2508 |
return false; |
|
2509 |
w->setFocus(); |
|
2510 |
return true; |
|
2511 |
} |
|
2512 |
||
2513 |
if (trigger == DoubleClicked) { |
|
2514 |
d->delayedEditing.stop(); |
|
2515 |
d->delayedAutoScroll.stop(); |
|
2516 |
} else if (trigger == CurrentChanged) { |
|
2517 |
d->delayedEditing.stop(); |
|
2518 |
} |
|
2519 |
||
2520 |
if (d->sendDelegateEvent(index, event)) { |
|
2521 |
update(index); |
|
2522 |
return true; |
|
2523 |
} |
|
2524 |
||
2525 |
// save the previous trigger before updating |
|
2526 |
EditTriggers lastTrigger = d->lastTrigger; |
|
2527 |
d->lastTrigger = trigger; |
|
2528 |
||
2529 |
if (!d->shouldEdit(trigger, d->model->buddy(index))) |
|
2530 |
return false; |
|
2531 |
||
2532 |
if (d->delayedEditing.isActive()) |
|
2533 |
return false; |
|
2534 |
||
2535 |
// we will receive a mouseButtonReleaseEvent after a |
|
2536 |
// mouseDoubleClickEvent, so we need to check the previous trigger |
|
2537 |
if (lastTrigger == DoubleClicked && trigger == SelectedClicked) |
|
2538 |
return false; |
|
2539 |
||
2540 |
// we may get a double click event later |
|
2541 |
if (trigger == SelectedClicked) |
|
2542 |
d->delayedEditing.start(QApplication::doubleClickInterval(), this); |
|
2543 |
else |
|
2544 |
d->openEditor(index, d->shouldForwardEvent(trigger, event) ? event : 0); |
|
2545 |
||
2546 |
return true; |
|
2547 |
} |
|
2548 |
||
2549 |
/*! |
|
2550 |
\internal |
|
2551 |
Updates the data shown in the open editor widgets in the view. |
|
2552 |
*/ |
|
2553 |
void QAbstractItemView::updateEditorData() |
|
2554 |
{ |
|
2555 |
Q_D(QAbstractItemView); |
|
2556 |
d->updateEditorData(QModelIndex(), QModelIndex()); |
|
2557 |
} |
|
2558 |
||
2559 |
/*! |
|
2560 |
\internal |
|
2561 |
Updates the geometry of the open editor widgets in the view. |
|
2562 |
*/ |
|
2563 |
void QAbstractItemView::updateEditorGeometries() |
|
2564 |
{ |
|
2565 |
Q_D(QAbstractItemView); |
|
2566 |
if(d->editors.isEmpty()) |
|
2567 |
return; |
|
2568 |
QStyleOptionViewItemV4 option = d->viewOptionsV4(); |
|
2569 |
QList<QEditorInfo>::iterator it = d->editors.begin(); |
|
2570 |
QWidgetList editorsToRelease; |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2571 |
QWidgetList editorsToHide; |
0 | 2572 |
while (it != d->editors.end()) { |
2573 |
QModelIndex index = it->index; |
|
2574 |
QWidget *editor = it->editor; |
|
2575 |
if (index.isValid() && editor) { |
|
2576 |
option.rect = visualRect(index); |
|
2577 |
if (option.rect.isValid()) { |
|
2578 |
editor->show(); |
|
2579 |
QAbstractItemDelegate *delegate = d->delegateForIndex(index); |
|
2580 |
if (delegate) |
|
2581 |
delegate->updateEditorGeometry(editor, option, index); |
|
2582 |
} else { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2583 |
editorsToHide << editor; |
0 | 2584 |
} |
2585 |
++it; |
|
2586 |
} else { |
|
2587 |
it = d->editors.erase(it); |
|
2588 |
editorsToRelease << editor; |
|
2589 |
} |
|
2590 |
} |
|
2591 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2592 |
//we hide and release the editor outside of the loop because it might change the focus and try |
0 | 2593 |
//to change the d->editors list. |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2594 |
for (int i = 0; i < editorsToHide.count(); ++i) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2595 |
editorsToHide.at(i)->hide(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2596 |
} |
0 | 2597 |
for (int i = 0; i < editorsToRelease.count(); ++i) { |
2598 |
d->releaseEditor(editorsToRelease.at(i)); |
|
2599 |
} |
|
2600 |
} |
|
2601 |
||
2602 |
/*! |
|
2603 |
\since 4.4 |
|
2604 |
||
2605 |
Updates the geometry of the child widgets of the view. |
|
2606 |
*/ |
|
2607 |
void QAbstractItemView::updateGeometries() |
|
2608 |
{ |
|
2609 |
updateEditorGeometries(); |
|
2610 |
d_func()->fetchMoreTimer.start(0, this); //fetch more later |
|
2611 |
} |
|
2612 |
||
2613 |
/*! |
|
2614 |
\internal |
|
2615 |
*/ |
|
2616 |
void QAbstractItemView::verticalScrollbarValueChanged(int value) |
|
2617 |
{ |
|
2618 |
Q_D(QAbstractItemView); |
|
2619 |
if (verticalScrollBar()->maximum() == value && d->model->canFetchMore(d->root)) |
|
2620 |
d->model->fetchMore(d->root); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2621 |
QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2622 |
if (viewport()->rect().contains(posInVp)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2623 |
d->checkMouseMove(posInVp); |
0 | 2624 |
} |
2625 |
||
2626 |
/*! |
|
2627 |
\internal |
|
2628 |
*/ |
|
2629 |
void QAbstractItemView::horizontalScrollbarValueChanged(int value) |
|
2630 |
{ |
|
2631 |
Q_D(QAbstractItemView); |
|
2632 |
if (horizontalScrollBar()->maximum() == value && d->model->canFetchMore(d->root)) |
|
2633 |
d->model->fetchMore(d->root); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2634 |
QPoint posInVp = viewport()->mapFromGlobal(QCursor::pos()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2635 |
if (viewport()->rect().contains(posInVp)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2636 |
d->checkMouseMove(posInVp); |
0 | 2637 |
} |
2638 |
||
2639 |
/*! |
|
2640 |
\internal |
|
2641 |
*/ |
|
2642 |
void QAbstractItemView::verticalScrollbarAction(int) |
|
2643 |
{ |
|
2644 |
//do nothing |
|
2645 |
} |
|
2646 |
||
2647 |
/*! |
|
2648 |
\internal |
|
2649 |
*/ |
|
2650 |
void QAbstractItemView::horizontalScrollbarAction(int) |
|
2651 |
{ |
|
2652 |
//do nothing |
|
2653 |
} |
|
2654 |
||
2655 |
/*! |
|
2656 |
Closes the given \a editor, and releases it. The \a hint is |
|
2657 |
used to specify how the view should respond to the end of the editing |
|
2658 |
operation. For example, the hint may indicate that the next item in |
|
2659 |
the view should be opened for editing. |
|
2660 |
||
2661 |
\sa edit(), commitData() |
|
2662 |
*/ |
|
2663 |
||
2664 |
void QAbstractItemView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint) |
|
2665 |
{ |
|
2666 |
Q_D(QAbstractItemView); |
|
2667 |
||
2668 |
// Close the editor |
|
2669 |
if (editor) { |
|
2670 |
bool isPersistent = d->persistent.contains(editor); |
|
2671 |
bool hadFocus = editor->hasFocus(); |
|
2672 |
QModelIndex index = d->indexForEditor(editor); |
|
2673 |
if (!index.isValid()) |
|
2674 |
return; // the editor was not registered |
|
2675 |
||
2676 |
if (!isPersistent) { |
|
2677 |
setState(NoState); |
|
2678 |
QModelIndex index = d->indexForEditor(editor); |
|
2679 |
editor->removeEventFilter(d->delegateForIndex(index)); |
|
2680 |
d->removeEditor(editor); |
|
2681 |
} |
|
2682 |
if (hadFocus) |
|
2683 |
setFocus(); // this will send a focusLost event to the editor |
|
2684 |
else |
|
2685 |
d->checkPersistentEditorFocus(); |
|
2686 |
||
2687 |
QPointer<QWidget> ed = editor; |
|
2688 |
QApplication::sendPostedEvents(editor, 0); |
|
2689 |
editor = ed; |
|
2690 |
||
2691 |
if (!isPersistent && editor) |
|
2692 |
d->releaseEditor(editor); |
|
2693 |
} |
|
2694 |
||
2695 |
// The EndEditHint part |
|
2696 |
QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::ClearAndSelect |
|
2697 |
| d->selectionBehaviorFlags(); |
|
2698 |
switch (hint) { |
|
2699 |
case QAbstractItemDelegate::EditNextItem: { |
|
2700 |
QModelIndex index = moveCursor(MoveNext, Qt::NoModifier); |
|
2701 |
if (index.isValid()) { |
|
2702 |
QPersistentModelIndex persistent(index); |
|
2703 |
d->selectionModel->setCurrentIndex(persistent, flags); |
|
2704 |
// currentChanged signal would have already started editing |
|
2705 |
if (index.flags() & Qt::ItemIsEditable |
|
2706 |
&& (!(editTriggers() & QAbstractItemView::CurrentChanged))) |
|
2707 |
edit(persistent); |
|
2708 |
} break; } |
|
2709 |
case QAbstractItemDelegate::EditPreviousItem: { |
|
2710 |
QModelIndex index = moveCursor(MovePrevious, Qt::NoModifier); |
|
2711 |
if (index.isValid()) { |
|
2712 |
QPersistentModelIndex persistent(index); |
|
2713 |
d->selectionModel->setCurrentIndex(persistent, flags); |
|
2714 |
// currentChanged signal would have already started editing |
|
2715 |
if (index.flags() & Qt::ItemIsEditable |
|
2716 |
&& (!(editTriggers() & QAbstractItemView::CurrentChanged))) |
|
2717 |
edit(persistent); |
|
2718 |
} break; } |
|
2719 |
case QAbstractItemDelegate::SubmitModelCache: |
|
2720 |
d->model->submit(); |
|
2721 |
break; |
|
2722 |
case QAbstractItemDelegate::RevertModelCache: |
|
2723 |
d->model->revert(); |
|
2724 |
break; |
|
2725 |
default: |
|
2726 |
break; |
|
2727 |
} |
|
2728 |
} |
|
2729 |
||
2730 |
/*! |
|
2731 |
Commit the data in the \a editor to the model. |
|
2732 |
||
2733 |
\sa closeEditor() |
|
2734 |
*/ |
|
2735 |
void QAbstractItemView::commitData(QWidget *editor) |
|
2736 |
{ |
|
2737 |
Q_D(QAbstractItemView); |
|
2738 |
if (!editor || !d->itemDelegate || d->currentlyCommittingEditor) |
|
2739 |
return; |
|
2740 |
QModelIndex index = d->indexForEditor(editor); |
|
2741 |
if (!index.isValid()) |
|
2742 |
return; |
|
2743 |
d->currentlyCommittingEditor = editor; |
|
2744 |
QAbstractItemDelegate *delegate = d->delegateForIndex(index); |
|
2745 |
editor->removeEventFilter(delegate); |
|
2746 |
delegate->setModelData(editor, d->model, index); |
|
2747 |
editor->installEventFilter(delegate); |
|
2748 |
d->currentlyCommittingEditor = 0; |
|
2749 |
} |
|
2750 |
||
2751 |
/*! |
|
2752 |
This function is called when the given \a editor has been destroyed. |
|
2753 |
||
2754 |
\sa closeEditor() |
|
2755 |
*/ |
|
2756 |
void QAbstractItemView::editorDestroyed(QObject *editor) |
|
2757 |
{ |
|
2758 |
Q_D(QAbstractItemView); |
|
2759 |
QWidget *w = qobject_cast<QWidget*>(editor); |
|
2760 |
d->removeEditor(w); |
|
2761 |
d->persistent.remove(w); |
|
2762 |
if (state() == EditingState) |
|
2763 |
setState(NoState); |
|
2764 |
} |
|
2765 |
||
2766 |
/*! |
|
2767 |
\obsolete |
|
2768 |
Sets the horizontal scroll bar's steps per item to \a steps. |
|
2769 |
||
2770 |
This is the number of steps used by the horizontal scroll bar to |
|
2771 |
represent the width of an item. |
|
2772 |
||
2773 |
Note that if the view has a horizontal header, the item steps |
|
2774 |
will be ignored and the header section size will be used instead. |
|
2775 |
||
2776 |
\sa horizontalStepsPerItem() setVerticalStepsPerItem() |
|
2777 |
*/ |
|
2778 |
void QAbstractItemView::setHorizontalStepsPerItem(int steps) |
|
2779 |
{ |
|
2780 |
Q_UNUSED(steps); |
|
2781 |
// do nothing |
|
2782 |
} |
|
2783 |
||
2784 |
/*! |
|
2785 |
\obsolete |
|
2786 |
Returns the horizontal scroll bar's steps per item. |
|
2787 |
||
2788 |
\sa setHorizontalStepsPerItem() verticalStepsPerItem() |
|
2789 |
*/ |
|
2790 |
int QAbstractItemView::horizontalStepsPerItem() const |
|
2791 |
{ |
|
2792 |
return 1; |
|
2793 |
} |
|
2794 |
||
2795 |
/*! |
|
2796 |
\obsolete |
|
2797 |
Sets the vertical scroll bar's steps per item to \a steps. |
|
2798 |
||
2799 |
This is the number of steps used by the vertical scroll bar to |
|
2800 |
represent the height of an item. |
|
2801 |
||
2802 |
Note that if the view has a vertical header, the item steps |
|
2803 |
will be ignored and the header section size will be used instead. |
|
2804 |
||
2805 |
\sa verticalStepsPerItem() setHorizontalStepsPerItem() |
|
2806 |
*/ |
|
2807 |
void QAbstractItemView::setVerticalStepsPerItem(int steps) |
|
2808 |
{ |
|
2809 |
Q_UNUSED(steps); |
|
2810 |
// do nothing |
|
2811 |
} |
|
2812 |
||
2813 |
/*! |
|
2814 |
\obsolete |
|
2815 |
Returns the vertical scroll bar's steps per item. |
|
2816 |
||
2817 |
\sa setVerticalStepsPerItem() horizontalStepsPerItem() |
|
2818 |
*/ |
|
2819 |
int QAbstractItemView::verticalStepsPerItem() const |
|
2820 |
{ |
|
2821 |
return 1; |
|
2822 |
} |
|
2823 |
||
2824 |
/*! |
|
2825 |
Moves to and selects the item best matching the string \a search. |
|
2826 |
If no item is found nothing happens. |
|
2827 |
||
2828 |
In the default implementation, the search is reset if \a search is empty, or |
|
2829 |
the time interval since the last search has exceeded |
|
2830 |
QApplication::keyboardInputInterval(). |
|
2831 |
*/ |
|
2832 |
void QAbstractItemView::keyboardSearch(const QString &search) |
|
2833 |
{ |
|
2834 |
Q_D(QAbstractItemView); |
|
2835 |
if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root)) |
|
2836 |
return; |
|
2837 |
||
2838 |
QModelIndex start = currentIndex().isValid() ? currentIndex() |
|
2839 |
: d->model->index(0, 0, d->root); |
|
2840 |
QTime now(QTime::currentTime()); |
|
2841 |
bool skipRow = false; |
|
2842 |
if (search.isEmpty() |
|
2843 |
|| (d->keyboardInputTime.msecsTo(now) > QApplication::keyboardInputInterval())) { |
|
2844 |
d->keyboardInput = search; |
|
2845 |
skipRow = currentIndex().isValid(); //if it is not valid we should really start at QModelIndex(0,0) |
|
2846 |
} else { |
|
2847 |
d->keyboardInput += search; |
|
2848 |
} |
|
2849 |
d->keyboardInputTime = now; |
|
2850 |
||
2851 |
// special case for searches with same key like 'aaaaa' |
|
2852 |
bool sameKey = false; |
|
2853 |
if (d->keyboardInput.length() > 1) { |
|
2854 |
int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.length() - 1)); |
|
2855 |
sameKey = (c == d->keyboardInput.length()); |
|
2856 |
if (sameKey) |
|
2857 |
skipRow = true; |
|
2858 |
} |
|
2859 |
||
2860 |
// skip if we are searching for the same key or a new search started |
|
2861 |
if (skipRow) { |
|
2862 |
QModelIndex parent = start.parent(); |
|
2863 |
int newRow = (start.row() < d->model->rowCount(parent) - 1) ? start.row() + 1 : 0; |
|
2864 |
start = d->model->index(newRow, start.column(), parent); |
|
2865 |
} |
|
2866 |
||
2867 |
// search from start with wraparound |
|
2868 |
const QString searchString = sameKey ? QString(d->keyboardInput.at(0)) : d->keyboardInput; |
|
2869 |
QModelIndex current = start; |
|
2870 |
QModelIndexList match; |
|
2871 |
QModelIndex firstMatch; |
|
2872 |
QModelIndex startMatch; |
|
2873 |
QModelIndexList previous; |
|
2874 |
do { |
|
2875 |
match = d->model->match(current, Qt::DisplayRole, searchString); |
|
2876 |
if (match == previous) |
|
2877 |
break; |
|
2878 |
firstMatch = match.value(0); |
|
2879 |
previous = match; |
|
2880 |
if (firstMatch.isValid()) { |
|
2881 |
if (d->isIndexEnabled(firstMatch)) { |
|
2882 |
setCurrentIndex(firstMatch); |
|
2883 |
break; |
|
2884 |
} |
|
2885 |
int row = firstMatch.row() + 1; |
|
2886 |
if (row >= d->model->rowCount(firstMatch.parent())) |
|
2887 |
row = 0; |
|
2888 |
current = firstMatch.sibling(row, firstMatch.column()); |
|
2889 |
||
2890 |
//avoid infinite loop if all the matching items are disabled. |
|
2891 |
if (!startMatch.isValid()) |
|
2892 |
startMatch = firstMatch; |
|
2893 |
else if (startMatch == firstMatch) |
|
2894 |
break; |
|
2895 |
} |
|
2896 |
} while (current != start && firstMatch.isValid()); |
|
2897 |
} |
|
2898 |
||
2899 |
/*! |
|
2900 |
Returns the size hint for the item with the specified \a index or |
|
2901 |
an invalid size for invalid indexes. |
|
2902 |
||
2903 |
\sa sizeHintForRow(), sizeHintForColumn() |
|
2904 |
*/ |
|
2905 |
QSize QAbstractItemView::sizeHintForIndex(const QModelIndex &index) const |
|
2906 |
{ |
|
2907 |
Q_D(const QAbstractItemView); |
|
2908 |
if (!d->isIndexValid(index) || !d->itemDelegate) |
|
2909 |
return QSize(); |
|
2910 |
return d->delegateForIndex(index)->sizeHint(d->viewOptionsV4(), index); |
|
2911 |
} |
|
2912 |
||
2913 |
/*! |
|
2914 |
Returns the height size hint for the specified \a row or -1 if |
|
2915 |
there is no model. |
|
2916 |
||
2917 |
The returned height is calculated using the size hints of the |
|
2918 |
given \a row's items, i.e. the returned value is the maximum |
|
2919 |
height among the items. Note that to control the height of a row, |
|
2920 |
you must reimplement the QAbstractItemDelegate::sizeHint() |
|
2921 |
function. |
|
2922 |
||
2923 |
This function is used in views with a vertical header to find the |
|
2924 |
size hint for a header section based on the contents of the given |
|
2925 |
\a row. |
|
2926 |
||
2927 |
\sa sizeHintForColumn() |
|
2928 |
*/ |
|
2929 |
int QAbstractItemView::sizeHintForRow(int row) const |
|
2930 |
{ |
|
2931 |
Q_D(const QAbstractItemView); |
|
2932 |
||
2933 |
if (row < 0 || row >= d->model->rowCount() || !model()) |
|
2934 |
return -1; |
|
2935 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2936 |
ensurePolished(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2937 |
|
0 | 2938 |
QStyleOptionViewItemV4 option = d->viewOptionsV4(); |
2939 |
int height = 0; |
|
2940 |
int colCount = d->model->columnCount(d->root); |
|
2941 |
QModelIndex index; |
|
2942 |
for (int c = 0; c < colCount; ++c) { |
|
2943 |
index = d->model->index(row, c, d->root); |
|
2944 |
if (QWidget *editor = d->editorForIndex(index).editor) |
|
2945 |
height = qMax(height, editor->size().height()); |
|
2946 |
int hint = d->delegateForIndex(index)->sizeHint(option, index).height(); |
|
2947 |
height = qMax(height, hint); |
|
2948 |
} |
|
2949 |
return height; |
|
2950 |
} |
|
2951 |
||
2952 |
/*! |
|
2953 |
Returns the width size hint for the specified \a column or -1 if there is no model. |
|
2954 |
||
2955 |
This function is used in views with a horizontal header to find the size hint for |
|
2956 |
a header section based on the contents of the given \a column. |
|
2957 |
||
2958 |
\sa sizeHintForRow() |
|
2959 |
*/ |
|
2960 |
int QAbstractItemView::sizeHintForColumn(int column) const |
|
2961 |
{ |
|
2962 |
Q_D(const QAbstractItemView); |
|
2963 |
||
2964 |
if (column < 0 || column >= d->model->columnCount() || !model()) |
|
2965 |
return -1; |
|
2966 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2967 |
ensurePolished(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2968 |
|
0 | 2969 |
QStyleOptionViewItemV4 option = d->viewOptionsV4(); |
2970 |
int width = 0; |
|
2971 |
int rows = d->model->rowCount(d->root); |
|
2972 |
QModelIndex index; |
|
2973 |
for (int r = 0; r < rows; ++r) { |
|
2974 |
index = d->model->index(r, column, d->root); |
|
2975 |
if (QWidget *editor = d->editorForIndex(index).editor) |
|
2976 |
width = qMax(width, editor->sizeHint().width()); |
|
2977 |
int hint = d->delegateForIndex(index)->sizeHint(option, index).width(); |
|
2978 |
width = qMax(width, hint); |
|
2979 |
} |
|
2980 |
return width; |
|
2981 |
} |
|
2982 |
||
2983 |
/*! |
|
2984 |
Opens a persistent editor on the item at the given \a index. |
|
2985 |
If no editor exists, the delegate will create a new editor. |
|
2986 |
||
2987 |
\sa closePersistentEditor() |
|
2988 |
*/ |
|
2989 |
void QAbstractItemView::openPersistentEditor(const QModelIndex &index) |
|
2990 |
{ |
|
2991 |
Q_D(QAbstractItemView); |
|
2992 |
QStyleOptionViewItemV4 options = d->viewOptionsV4(); |
|
2993 |
options.rect = visualRect(index); |
|
2994 |
options.state |= (index == currentIndex() ? QStyle::State_HasFocus : QStyle::State_None); |
|
2995 |
||
2996 |
QWidget *editor = d->editor(index, options); |
|
2997 |
if (editor) { |
|
2998 |
editor->show(); |
|
2999 |
d->persistent.insert(editor); |
|
3000 |
} |
|
3001 |
} |
|
3002 |
||
3003 |
/*! |
|
3004 |
Closes the persistent editor for the item at the given \a index. |
|
3005 |
||
3006 |
\sa openPersistentEditor() |
|
3007 |
*/ |
|
3008 |
void QAbstractItemView::closePersistentEditor(const QModelIndex &index) |
|
3009 |
{ |
|
3010 |
Q_D(QAbstractItemView); |
|
3011 |
QWidget *editor = d->editorForIndex(index).editor; |
|
3012 |
if (editor) { |
|
3013 |
if (index == selectionModel()->currentIndex()) |
|
3014 |
closeEditor(editor, QAbstractItemDelegate::RevertModelCache); |
|
3015 |
d->persistent.remove(editor); |
|
3016 |
d->removeEditor(editor); |
|
3017 |
d->releaseEditor(editor); |
|
3018 |
} |
|
3019 |
} |
|
3020 |
||
3021 |
/*! |
|
3022 |
\since 4.1 |
|
3023 |
||
3024 |
Sets the given \a widget on the item at the given \a index, passing the |
|
3025 |
ownership of the widget to the viewport. |
|
3026 |
||
3027 |
If \a index is invalid (e.g., if you pass the root index), this function |
|
3028 |
will do nothing. |
|
3029 |
||
3030 |
The given \a widget's \l{QWidget}{autoFillBackground} property must be set |
|
3031 |
to true, otherwise the widget's background will be transparent, showing |
|
3032 |
both the model data and the item at the given \a index. |
|
3033 |
||
3034 |
If index widget A is replaced with index widget B, index widget A will be |
|
3035 |
deleted. For example, in the code snippet below, the QLineEdit object will |
|
3036 |
be deleted. |
|
3037 |
||
3038 |
\snippet doc/src/snippets/code/src_gui_itemviews_qabstractitemview.cpp 1 |
|
3039 |
||
3040 |
This function should only be used to display static content within the |
|
3041 |
visible area corresponding to an item of data. If you want to display |
|
3042 |
custom dynamic content or implement a custom editor widget, subclass |
|
3043 |
QItemDelegate instead. |
|
3044 |
||
3045 |
\sa {Delegate Classes} |
|
3046 |
*/ |
|
3047 |
void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget) |
|
3048 |
{ |
|
3049 |
Q_D(QAbstractItemView); |
|
3050 |
if (!d->isIndexValid(index)) |
|
3051 |
return; |
|
3052 |
if (QWidget *oldWidget = indexWidget(index)) { |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
3053 |
d->persistent.remove(oldWidget); |
0 | 3054 |
d->removeEditor(oldWidget); |
3055 |
oldWidget->deleteLater(); |
|
3056 |
} |
|
3057 |
if (widget) { |
|
3058 |
widget->setParent(viewport()); |
|
3059 |
d->persistent.insert(widget); |
|
3060 |
d->addEditor(index, widget, true); |
|
3061 |
widget->show(); |
|
3062 |
dataChanged(index, index); // update the geometry |
|
3063 |
if (!d->delayedPendingLayout) |
|
3064 |
widget->setGeometry(visualRect(index)); |
|
3065 |
} |
|
3066 |
} |
|
3067 |
||
3068 |
/*! |
|
3069 |
\since 4.1 |
|
3070 |
||
3071 |
Returns the widget for the item at the given \a index. |
|
3072 |
*/ |
|
3073 |
QWidget* QAbstractItemView::indexWidget(const QModelIndex &index) const |
|
3074 |
{ |
|
3075 |
Q_D(const QAbstractItemView); |
|
3076 |
if (!d->isIndexValid(index)) |
|
3077 |
return 0; |
|
3078 |
return d->editorForIndex(index).editor; |
|
3079 |
} |
|
3080 |
||
3081 |
/*! |
|
3082 |
\since 4.1 |
|
3083 |
||
3084 |
Scrolls the view to the top. |
|
3085 |
||
3086 |
\sa scrollTo(), scrollToBottom() |
|
3087 |
*/ |
|
3088 |
void QAbstractItemView::scrollToTop() |
|
3089 |
{ |
|
3090 |
verticalScrollBar()->setValue(verticalScrollBar()->minimum()); |
|
3091 |
} |
|
3092 |
||
3093 |
/*! |
|
3094 |
\since 4.1 |
|
3095 |
||
3096 |
Scrolls the view to the bottom. |
|
3097 |
||
3098 |
\sa scrollTo(), scrollToTop() |
|
3099 |
*/ |
|
3100 |
void QAbstractItemView::scrollToBottom() |
|
3101 |
{ |
|
3102 |
Q_D(QAbstractItemView); |
|
3103 |
if (d->delayedPendingLayout) { |
|
3104 |
d->executePostedLayout(); |
|
3105 |
updateGeometries(); |
|
3106 |
} |
|
3107 |
verticalScrollBar()->setValue(verticalScrollBar()->maximum()); |
|
3108 |
} |
|
3109 |
||
3110 |
/*! |
|
3111 |
\since 4.3 |
|
3112 |
||
3113 |
Updates the area occupied by the given \a index. |
|
3114 |
||
3115 |
*/ |
|
3116 |
void QAbstractItemView::update(const QModelIndex &index) |
|
3117 |
{ |
|
3118 |
Q_D(QAbstractItemView); |
|
3119 |
if (index.isValid()) { |
|
3120 |
const QRect rect = visualRect(index); |
|
3121 |
//this test is important for peformance reason |
|
3122 |
//For example in dataChanged we simply update all the cells without checking |
|
3123 |
//it can be a major bottleneck to update rects that aren't even part of the viewport |
|
3124 |
if (d->viewport->rect().intersects(rect)) |
|
3125 |
d->viewport->update(rect); |
|
3126 |
} |
|
3127 |
} |
|
3128 |
||
3129 |
/*! |
|
3130 |
This slot is called when items are changed in the model. The |
|
3131 |
changed items are those from \a topLeft to \a bottomRight |
|
3132 |
inclusive. If just one item is changed \a topLeft == \a |
|
3133 |
bottomRight. |
|
3134 |
*/ |
|
3135 |
void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) |
|
3136 |
{ |
|
3137 |
// Single item changed |
|
3138 |
Q_D(QAbstractItemView); |
|
3139 |
if (topLeft == bottomRight && topLeft.isValid()) { |
|
3140 |
const QEditorInfo editorInfo = d->editorForIndex(topLeft); |
|
3141 |
//we don't update the edit data if it is static |
|
3142 |
if (!editorInfo.isStatic && editorInfo.editor) { |
|
3143 |
QAbstractItemDelegate *delegate = d->delegateForIndex(topLeft); |
|
3144 |
if (delegate) { |
|
3145 |
delegate->setEditorData(editorInfo.editor, topLeft); |
|
3146 |
} |
|
3147 |
} |
|
3148 |
if (isVisible() && !d->delayedPendingLayout) { |
|
3149 |
// otherwise the items will be update later anyway |
|
3150 |
update(topLeft); |
|
3151 |
} |
|
3152 |
return; |
|
3153 |
} |
|
3154 |
d->updateEditorData(topLeft, bottomRight); |
|
3155 |
if (!isVisible() || d->delayedPendingLayout) |
|
3156 |
return; // no need to update |
|
3157 |
d->viewport->update(); |
|
3158 |
} |
|
3159 |
||
3160 |
/*! |
|
3161 |
This slot is called when rows are inserted. The new rows are those |
|
3162 |
under the given \a parent from \a start to \a end inclusive. The |
|
3163 |
base class implementation calls fetchMore() on the model to check |
|
3164 |
for more data. |
|
3165 |
||
3166 |
\sa rowsAboutToBeRemoved() |
|
3167 |
*/ |
|
3168 |
void QAbstractItemView::rowsInserted(const QModelIndex &, int, int) |
|
3169 |
{ |
|
3170 |
if (!isVisible()) |
|
3171 |
d_func()->fetchMoreTimer.start(0, this); //fetch more later |
|
3172 |
else |
|
3173 |
updateEditorGeometries(); |
|
3174 |
} |
|
3175 |
||
3176 |
/*! |
|
3177 |
This slot is called when rows are about to be removed. The deleted rows are |
|
3178 |
those under the given \a parent from \a start to \a end inclusive. |
|
3179 |
||
3180 |
\sa rowsInserted() |
|
3181 |
*/ |
|
3182 |
void QAbstractItemView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) |
|
3183 |
{ |
|
3184 |
Q_D(QAbstractItemView); |
|
3185 |
||
3186 |
setState(CollapsingState); |
|
3187 |
||
3188 |
// Ensure one selected item in single selection mode. |
|
3189 |
QModelIndex current = currentIndex(); |
|
3190 |
if (d->selectionMode == SingleSelection |
|
3191 |
&& current.isValid() |
|
3192 |
&& current.row() >= start |
|
3193 |
&& current.row() <= end |
|
3194 |
&& current.parent() == parent) { |
|
3195 |
int totalToRemove = end - start + 1; |
|
3196 |
if (d->model->rowCount(parent) <= totalToRemove) { // no more children |
|
3197 |
QModelIndex index = parent; |
|
3198 |
while (index != d->root && !d->isIndexEnabled(index)) |
|
3199 |
index = index.parent(); |
|
3200 |
if (index != d->root) |
|
3201 |
setCurrentIndex(index); |
|
3202 |
} else { |
|
3203 |
int row = end + 1; |
|
3204 |
QModelIndex next; |
|
3205 |
do { // find the next visible and enabled item |
|
3206 |
next = d->model->index(row++, current.column(), current.parent()); |
|
3207 |
} while (next.isValid() && (isIndexHidden(next) || !d->isIndexEnabled(next))); |
|
3208 |
if (row > d->model->rowCount(parent)) { |
|
3209 |
row = start - 1; |
|
3210 |
do { // find the previous visible and enabled item |
|
3211 |
next = d->model->index(row--, current.column(), current.parent()); |
|
3212 |
} while (next.isValid() && (isIndexHidden(next) || !d->isIndexEnabled(next))); |
|
3213 |
} |
|
3214 |
setCurrentIndex(next); |
|
3215 |
} |
|
3216 |
} |
|
3217 |
||
3218 |
// Remove all affected editors; this is more efficient than waiting for updateGeometries() to clean out editors for invalid indexes |
|
3219 |
for (int i = d->editors.size() - 1; i >= 0; --i) { |
|
3220 |
const QModelIndex index = d->editors.at(i).index; |
|
3221 |
QWidget *editor = d->editors.at(i).editor; |
|
3222 |
if (index.row() >= start && index.row() <= end && d->model->parent(index) == parent) { |
|
3223 |
d->editors.removeAt(i); |
|
3224 |
d->releaseEditor(editor); |
|
3225 |
} |
|
3226 |
} |
|
3227 |
} |
|
3228 |
||
3229 |
/*! |
|
3230 |
\internal |
|
3231 |
||
3232 |
This slot is called when rows have been removed. The deleted |
|
3233 |
rows are those under the given \a parent from \a start to \a end |
|
3234 |
inclusive. |
|
3235 |
*/ |
|
3236 |
void QAbstractItemViewPrivate::_q_rowsRemoved(const QModelIndex &, int, int) |
|
3237 |
{ |
|
3238 |
Q_Q(QAbstractItemView); |
|
3239 |
if (q->isVisible()) |
|
3240 |
q->updateEditorGeometries(); |
|
3241 |
q->setState(QAbstractItemView::NoState); |
|
3242 |
} |
|
3243 |
||
3244 |
/*! |
|
3245 |
\internal |
|
3246 |
||
3247 |
This slot is called when columns are about to be removed. The deleted |
|
3248 |
columns are those under the given \a parent from \a start to \a end |
|
3249 |
inclusive. |
|
3250 |
*/ |
|
3251 |
void QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) |
|
3252 |
{ |
|
3253 |
Q_Q(QAbstractItemView); |
|
3254 |
||
3255 |
q->setState(QAbstractItemView::CollapsingState); |
|
3256 |
||
3257 |
// Ensure one selected item in single selection mode. |
|
3258 |
QModelIndex current = q->currentIndex(); |
|
3259 |
if (current.isValid() |
|
3260 |
&& selectionMode == QAbstractItemView::SingleSelection |
|
3261 |
&& current.column() >= start |
|
3262 |
&& current.column() <= end) { |
|
3263 |
int totalToRemove = end - start + 1; |
|
3264 |
if (model->columnCount(parent) < totalToRemove) { // no more columns |
|
3265 |
QModelIndex index = parent; |
|
3266 |
while (index.isValid() && !isIndexEnabled(index)) |
|
3267 |
index = index.parent(); |
|
3268 |
if (index.isValid()) |
|
3269 |
q->setCurrentIndex(index); |
|
3270 |
} else { |
|
3271 |
int column = end; |
|
3272 |
QModelIndex next; |
|
3273 |
do { // find the next visible and enabled item |
|
3274 |
next = model->index(current.row(), column++, current.parent()); |
|
3275 |
} while (next.isValid() && (q->isIndexHidden(next) || !isIndexEnabled(next))); |
|
3276 |
q->setCurrentIndex(next); |
|
3277 |
} |
|
3278 |
} |
|
3279 |
||
3280 |
// Remove all affected editors; this is more efficient than waiting for updateGeometries() to clean out editors for invalid indexes |
|
3281 |
QList<QEditorInfo>::iterator it = editors.begin(); |
|
3282 |
while (it != editors.end()) { |
|
3283 |
QModelIndex index = it->index; |
|
3284 |
if (index.column() <= start && index.column() >= end && model->parent(index) == parent) { |
|
3285 |
QWidget *editor = it->editor; |
|
3286 |
it = editors.erase(it); |
|
3287 |
releaseEditor(editor); |
|
3288 |
} else { |
|
3289 |
++it; |
|
3290 |
} |
|
3291 |
} |
|
3292 |
} |
|
3293 |
||
3294 |
/*! |
|
3295 |
\internal |
|
3296 |
||
3297 |
This slot is called when columns have been removed. The deleted |
|
3298 |
rows are those under the given \a parent from \a start to \a end |
|
3299 |
inclusive. |
|
3300 |
*/ |
|
3301 |
void QAbstractItemViewPrivate::_q_columnsRemoved(const QModelIndex &, int, int) |
|
3302 |
{ |
|
3303 |
Q_Q(QAbstractItemView); |
|
3304 |
if (q->isVisible()) |
|
3305 |
q->updateEditorGeometries(); |
|
3306 |
q->setState(QAbstractItemView::NoState); |
|
3307 |
} |
|
3308 |
||
3309 |
/*! |
|
3310 |
\internal |
|
3311 |
||
3312 |
This slot is called when rows have been inserted. |
|
3313 |
*/ |
|
3314 |
void QAbstractItemViewPrivate::_q_columnsInserted(const QModelIndex &, int, int) |
|
3315 |
{ |
|
3316 |
Q_Q(QAbstractItemView); |
|
3317 |
if (q->isVisible()) |
|
3318 |
q->updateEditorGeometries(); |
|
3319 |
} |
|
3320 |
||
3321 |
||
3322 |
||
3323 |
/*! |
|
3324 |
\internal |
|
3325 |
*/ |
|
3326 |
void QAbstractItemViewPrivate::_q_modelDestroyed() |
|
3327 |
{ |
|
3328 |
model = QAbstractItemModelPrivate::staticEmptyModel(); |
|
3329 |
doDelayedReset(); |
|
3330 |
} |
|
3331 |
||
3332 |
/*! |
|
3333 |
\internal |
|
3334 |
||
3335 |
This slot is called when the layout is changed. |
|
3336 |
*/ |
|
3337 |
void QAbstractItemViewPrivate::_q_layoutChanged() |
|
3338 |
{ |
|
3339 |
doDelayedItemsLayout(); |
|
3340 |
} |
|
3341 |
||
3342 |
/*! |
|
3343 |
This slot is called when the selection is changed. The previous |
|
3344 |
selection (which may be empty), is specified by \a deselected, and the |
|
3345 |
new selection by \a selected. |
|
3346 |
||
3347 |
\sa setSelection() |
|
3348 |
*/ |
|
3349 |
void QAbstractItemView::selectionChanged(const QItemSelection &selected, |
|
3350 |
const QItemSelection &deselected) |
|
3351 |
{ |
|
3352 |
Q_D(QAbstractItemView); |
|
3353 |
if (isVisible() && updatesEnabled()) { |
|
3354 |
d->viewport->update(visualRegionForSelection(deselected) | visualRegionForSelection(selected)); |
|
3355 |
} |
|
3356 |
} |
|
3357 |
||
3358 |
/*! |
|
3359 |
This slot is called when a new item becomes the current item. |
|
3360 |
The previous current item is specified by the \a previous index, and the new |
|
3361 |
item by the \a current index. |
|
3362 |
||
3363 |
If you want to know about changes to items see the |
|
3364 |
dataChanged() signal. |
|
3365 |
*/ |
|
3366 |
void QAbstractItemView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) |
|
3367 |
{ |
|
3368 |
Q_D(QAbstractItemView); |
|
3369 |
Q_ASSERT(d->model); |
|
3370 |
||
3371 |
if (previous.isValid()) { |
|
3372 |
QModelIndex buddy = d->model->buddy(previous); |
|
3373 |
QWidget *editor = d->editorForIndex(buddy).editor; |
|
3374 |
if (editor && !d->persistent.contains(editor)) { |
|
3375 |
commitData(editor); |
|
3376 |
if (current.row() != previous.row()) |
|
3377 |
closeEditor(editor, QAbstractItemDelegate::SubmitModelCache); |
|
3378 |
else |
|
3379 |
closeEditor(editor, QAbstractItemDelegate::NoHint); |
|
3380 |
} |
|
3381 |
if (isVisible()) { |
|
3382 |
update(previous); |
|
3383 |
} |
|
3384 |
} |
|
3385 |
||
3386 |
if (current.isValid() && !d->autoScrollTimer.isActive()) { |
|
3387 |
if (isVisible()) { |
|
3388 |
if (d->autoScroll) |
|
3389 |
scrollTo(current); |
|
3390 |
update(current); |
|
3391 |
edit(current, CurrentChanged, 0); |
|
3392 |
if (current.row() == (d->model->rowCount(d->root) - 1)) |
|
3393 |
d->fetchMore(); |
|
3394 |
} else { |
|
3395 |
d->shouldScrollToCurrentOnShow = d->autoScroll; |
|
3396 |
} |
|
3397 |
} |
|
3398 |
} |
|
3399 |
||
3400 |
#ifndef QT_NO_DRAGANDDROP |
|
3401 |
/*! |
|
3402 |
Starts a drag by calling drag->exec() using the given \a supportedActions. |
|
3403 |
*/ |
|
3404 |
void QAbstractItemView::startDrag(Qt::DropActions supportedActions) |
|
3405 |
{ |
|
3406 |
Q_D(QAbstractItemView); |
|
3407 |
QModelIndexList indexes = d->selectedDraggableIndexes(); |
|
3408 |
if (indexes.count() > 0) { |
|
3409 |
QMimeData *data = d->model->mimeData(indexes); |
|
3410 |
if (!data) |
|
3411 |
return; |
|
3412 |
QRect rect; |
|
3413 |
QPixmap pixmap = d->renderToPixmap(indexes, &rect); |
|
3414 |
rect.adjust(horizontalOffset(), verticalOffset(), 0, 0); |
|
3415 |
QDrag *drag = new QDrag(this); |
|
3416 |
drag->setPixmap(pixmap); |
|
3417 |
drag->setMimeData(data); |
|
3418 |
drag->setHotSpot(d->pressedPosition - rect.topLeft()); |
|
3419 |
Qt::DropAction defaultDropAction = Qt::IgnoreAction; |
|
3420 |
if (d->defaultDropAction != Qt::IgnoreAction && (supportedActions & d->defaultDropAction)) |
|
3421 |
defaultDropAction = d->defaultDropAction; |
|
3422 |
else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove) |
|
3423 |
defaultDropAction = Qt::CopyAction; |
|
3424 |
if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction) |
|
3425 |
d->clearOrRemove(); |
|
3426 |
} |
|
3427 |
} |
|
3428 |
#endif // QT_NO_DRAGANDDROP |
|
3429 |
||
3430 |
/*! |
|
3431 |
Returns a QStyleOptionViewItem structure populated with the view's |
|
3432 |
palette, font, state, alignments etc. |
|
3433 |
*/ |
|
3434 |
QStyleOptionViewItem QAbstractItemView::viewOptions() const |
|
3435 |
{ |
|
3436 |
Q_D(const QAbstractItemView); |
|
3437 |
QStyleOptionViewItem option; |
|
3438 |
option.init(this); |
|
3439 |
option.state &= ~QStyle::State_MouseOver; |
|
3440 |
option.font = font(); |
|
3441 |
||
3442 |
#ifndef Q_WS_MAC |
|
3443 |
// On mac the focus appearance follows window activation |
|
3444 |
// not widget activation |
|
3445 |
if (!hasFocus()) |
|
3446 |
option.state &= ~QStyle::State_Active; |
|
3447 |
#endif |
|
3448 |
||
3449 |
option.state &= ~QStyle::State_HasFocus; |
|
3450 |
if (d->iconSize.isValid()) { |
|
3451 |
option.decorationSize = d->iconSize; |
|
3452 |
} else { |
|
3453 |
int pm = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); |
|
3454 |
option.decorationSize = QSize(pm, pm); |
|
3455 |
} |
|
3456 |
option.decorationPosition = QStyleOptionViewItem::Left; |
|
3457 |
option.decorationAlignment = Qt::AlignCenter; |
|
3458 |
option.displayAlignment = Qt::AlignLeft|Qt::AlignVCenter; |
|
3459 |
option.textElideMode = d->textElideMode; |
|
3460 |
option.rect = QRect(); |
|
3461 |
option.showDecorationSelected = style()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, 0, this); |
|
3462 |
return option; |
|
3463 |
} |
|
3464 |
||
3465 |
QStyleOptionViewItemV4 QAbstractItemViewPrivate::viewOptionsV4() const |
|
3466 |
{ |
|
3467 |
Q_Q(const QAbstractItemView); |
|
3468 |
QStyleOptionViewItemV4 option = q->viewOptions(); |
|
3469 |
if (wrapItemText) |
|
3470 |
option.features = QStyleOptionViewItemV2::WrapText; |
|
3471 |
option.locale = q->locale(); |
|
3472 |
option.locale.setNumberOptions(QLocale::OmitGroupSeparator); |
|
3473 |
option.widget = q; |
|
3474 |
return option; |
|
3475 |
} |
|
3476 |
||
3477 |
/*! |
|
3478 |
Returns the item view's state. |
|
3479 |
||
3480 |
\sa setState() |
|
3481 |
*/ |
|
3482 |
QAbstractItemView::State QAbstractItemView::state() const |
|
3483 |
{ |
|
3484 |
Q_D(const QAbstractItemView); |
|
3485 |
return d->state; |
|
3486 |
} |
|
3487 |
||
3488 |
/*! |
|
3489 |
Sets the item view's state to the given \a state. |
|
3490 |
||
3491 |
\sa state() |
|
3492 |
*/ |
|
3493 |
void QAbstractItemView::setState(State state) |
|
3494 |
{ |
|
3495 |
Q_D(QAbstractItemView); |
|
3496 |
d->state = state; |
|
3497 |
} |
|
3498 |
||
3499 |
/*! |
|
3500 |
Schedules a layout of the items in the view to be executed when the |
|
3501 |
event processing starts. |
|
3502 |
||
3503 |
Even if scheduleDelayedItemsLayout() is called multiple times before |
|
3504 |
events are processed, the view will only do the layout once. |
|
3505 |
||
3506 |
\sa executeDelayedItemsLayout() |
|
3507 |
*/ |
|
3508 |
void QAbstractItemView::scheduleDelayedItemsLayout() |
|
3509 |
{ |
|
3510 |
Q_D(QAbstractItemView); |
|
3511 |
d->doDelayedItemsLayout(); |
|
3512 |
} |
|
3513 |
||
3514 |
/*! |
|
3515 |
Executes the scheduled layouts without waiting for the event processing |
|
3516 |
to begin. |
|
3517 |
||
3518 |
\sa scheduleDelayedItemsLayout() |
|
3519 |
*/ |
|
3520 |
void QAbstractItemView::executeDelayedItemsLayout() |
|
3521 |
{ |
|
3522 |
Q_D(QAbstractItemView); |
|
3523 |
d->executePostedLayout(); |
|
3524 |
} |
|
3525 |
||
3526 |
/*! |
|
3527 |
\since 4.1 |
|
3528 |
||
3529 |
Marks the given \a region as dirty and schedules it to be updated. |
|
3530 |
You only need to call this function if you are implementing |
|
3531 |
your own view subclass. |
|
3532 |
||
3533 |
\sa scrollDirtyRegion(), dirtyRegionOffset() |
|
3534 |
*/ |
|
3535 |
||
3536 |
void QAbstractItemView::setDirtyRegion(const QRegion ®ion) |
|
3537 |
{ |
|
3538 |
Q_D(QAbstractItemView); |
|
3539 |
d->setDirtyRegion(region); |
|
3540 |
} |
|
3541 |
||
3542 |
/*! |
|
3543 |
Prepares the view for scrolling by (\a{dx},\a{dy}) pixels by moving the dirty regions in the |
|
3544 |
opposite direction. You only need to call this function if you are implementing a scrolling |
|
3545 |
viewport in your view subclass. |
|
3546 |
||
3547 |
If you implement scrollContentsBy() in a subclass of QAbstractItemView, call this function |
|
3548 |
before you call QWidget::scroll() on the viewport. Alternatively, just call update(). |
|
3549 |
||
3550 |
\sa scrollContentsBy(), dirtyRegionOffset(), setDirtyRegion() |
|
3551 |
*/ |
|
3552 |
void QAbstractItemView::scrollDirtyRegion(int dx, int dy) |
|
3553 |
{ |
|
3554 |
Q_D(QAbstractItemView); |
|
3555 |
d->scrollDirtyRegion(dx, dy); |
|
3556 |
} |
|
3557 |
||
3558 |
/*! |
|
3559 |
Returns the offset of the dirty regions in the view. |
|
3560 |
||
3561 |
If you use scrollDirtyRegion() and implement a paintEvent() in a subclass of |
|
3562 |
QAbstractItemView, you should translate the area given by the paint event with |
|
3563 |
the offset returned from this function. |
|
3564 |
||
3565 |
\sa scrollDirtyRegion(), setDirtyRegion() |
|
3566 |
*/ |
|
3567 |
QPoint QAbstractItemView::dirtyRegionOffset() const |
|
3568 |
{ |
|
3569 |
Q_D(const QAbstractItemView); |
|
3570 |
return d->scrollDelayOffset; |
|
3571 |
} |
|
3572 |
||
3573 |
/*! |
|
3574 |
\internal |
|
3575 |
*/ |
|
3576 |
void QAbstractItemView::startAutoScroll() |
|
3577 |
{ |
|
3578 |
d_func()->startAutoScroll(); |
|
3579 |
} |
|
3580 |
||
3581 |
/*! |
|
3582 |
\internal |
|
3583 |
*/ |
|
3584 |
void QAbstractItemView::stopAutoScroll() |
|
3585 |
{ |
|
3586 |
d_func()->stopAutoScroll(); |
|
3587 |
} |
|
3588 |
||
3589 |
/*! |
|
3590 |
\internal |
|
3591 |
*/ |
|
3592 |
void QAbstractItemView::doAutoScroll() |
|
3593 |
{ |
|
3594 |
// find how much we should scroll with |
|
3595 |
Q_D(QAbstractItemView); |
|
3596 |
int verticalStep = verticalScrollBar()->pageStep(); |
|
3597 |
int horizontalStep = horizontalScrollBar()->pageStep(); |
|
3598 |
if (d->autoScrollCount < qMax(verticalStep, horizontalStep)) |
|
3599 |
++d->autoScrollCount; |
|
3600 |
||
3601 |
int margin = d->autoScrollMargin; |
|
3602 |
int verticalValue = verticalScrollBar()->value(); |
|
3603 |
int horizontalValue = horizontalScrollBar()->value(); |
|
3604 |
||
3605 |
QPoint pos = d->viewport->mapFromGlobal(QCursor::pos()); |
|
3606 |
QRect area = static_cast<QAbstractItemView*>(d->viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules |
|
3607 |
||
3608 |
// do the scrolling if we are in the scroll margins |
|
3609 |
if (pos.y() - area.top() < margin) |
|
3610 |
verticalScrollBar()->setValue(verticalValue - d->autoScrollCount); |
|
3611 |
else if (area.bottom() - pos.y() < margin) |
|
3612 |
verticalScrollBar()->setValue(verticalValue + d->autoScrollCount); |
|
3613 |
if (pos.x() - area.left() < margin) |
|
3614 |
horizontalScrollBar()->setValue(horizontalValue - d->autoScrollCount); |
|
3615 |
else if (area.right() - pos.x() < margin) |
|
3616 |
horizontalScrollBar()->setValue(horizontalValue + d->autoScrollCount); |
|
3617 |
// if nothing changed, stop scrolling |
|
3618 |
bool verticalUnchanged = (verticalValue == verticalScrollBar()->value()); |
|
3619 |
bool horizontalUnchanged = (horizontalValue == horizontalScrollBar()->value()); |
|
3620 |
if (verticalUnchanged && horizontalUnchanged) { |
|
3621 |
stopAutoScroll(); |
|
3622 |
} else { |
|
3623 |
#ifndef QT_NO_DRAGANDDROP |
|
3624 |
d->dropIndicatorRect = QRect(); |
|
3625 |
d->dropIndicatorPosition = QAbstractItemView::OnViewport; |
|
3626 |
#endif |
|
3627 |
d->viewport->update(); |
|
3628 |
} |
|
3629 |
} |
|
3630 |
||
3631 |
/*! |
|
3632 |
Returns the SelectionFlags to be used when updating a selection with |
|
3633 |
to include the \a index specified. The \a event is a user input event, |
|
3634 |
such as a mouse or keyboard event. |
|
3635 |
||
3636 |
Reimplement this function to define your own selection behavior. |
|
3637 |
||
3638 |
\sa setSelection() |
|
3639 |
*/ |
|
3640 |
QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand(const QModelIndex &index, |
|
3641 |
const QEvent *event) const |
|
3642 |
{ |
|
3643 |
Q_D(const QAbstractItemView); |
|
3644 |
switch (d->selectionMode) { |
|
3645 |
case NoSelection: // Never update selection model |
|
3646 |
return QItemSelectionModel::NoUpdate; |
|
3647 |
case SingleSelection: // ClearAndSelect on valid index otherwise NoUpdate |
|
3648 |
if (event && event->type() == QEvent::MouseButtonRelease) |
|
3649 |
return QItemSelectionModel::NoUpdate; |
|
3650 |
return QItemSelectionModel::ClearAndSelect|d->selectionBehaviorFlags(); |
|
3651 |
case MultiSelection: |
|
3652 |
return d->multiSelectionCommand(index, event); |
|
3653 |
case ExtendedSelection: |
|
3654 |
return d->extendedSelectionCommand(index, event); |
|
3655 |
case ContiguousSelection: |
|
3656 |
return d->contiguousSelectionCommand(index, event); |
|
3657 |
} |
|
3658 |
return QItemSelectionModel::NoUpdate; |
|
3659 |
} |
|
3660 |
||
3661 |
QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::multiSelectionCommand( |
|
3662 |
const QModelIndex &index, const QEvent *event) const |
|
3663 |
{ |
|
3664 |
Q_UNUSED(index); |
|
3665 |
||
3666 |
if (event) { |
|
3667 |
switch (event->type()) { |
|
3668 |
case QEvent::KeyPress: |
|
3669 |
if (static_cast<const QKeyEvent*>(event)->key() == Qt::Key_Space |
|
3670 |
|| static_cast<const QKeyEvent*>(event)->key() == Qt::Key_Select) |
|
3671 |
return QItemSelectionModel::Toggle|selectionBehaviorFlags(); |
|
3672 |
break; |
|
3673 |
case QEvent::MouseButtonPress: |
|
3674 |
if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton) |
|
3675 |
return QItemSelectionModel::Toggle|selectionBehaviorFlags(); // toggle |
|
3676 |
break; |
|
3677 |
case QEvent::MouseButtonRelease: |
|
3678 |
if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton) |
|
3679 |
return QItemSelectionModel::NoUpdate|selectionBehaviorFlags(); // finalize |
|
3680 |
break; |
|
3681 |
case QEvent::MouseMove: |
|
3682 |
if (static_cast<const QMouseEvent*>(event)->buttons() & Qt::LeftButton) |
|
3683 |
return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); // toggle drag select |
|
3684 |
default: |
|
3685 |
break; |
|
3686 |
} |
|
3687 |
return QItemSelectionModel::NoUpdate; |
|
3688 |
} |
|
3689 |
||
3690 |
return QItemSelectionModel::Toggle|selectionBehaviorFlags(); |
|
3691 |
} |
|
3692 |
||
3693 |
QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::extendedSelectionCommand( |
|
3694 |
const QModelIndex &index, const QEvent *event) const |
|
3695 |
{ |
|
3696 |
Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers(); |
|
3697 |
if (event) { |
|
3698 |
switch (event->type()) { |
|
3699 |
case QEvent::MouseMove: { |
|
3700 |
// Toggle on MouseMove |
|
3701 |
modifiers = static_cast<const QMouseEvent*>(event)->modifiers(); |
|
3702 |
if (modifiers & Qt::ControlModifier) |
|
3703 |
return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); |
|
3704 |
break; |
|
3705 |
} |
|
3706 |
case QEvent::MouseButtonPress: { |
|
3707 |
modifiers = static_cast<const QMouseEvent*>(event)->modifiers(); |
|
3708 |
const Qt::MouseButton button = static_cast<const QMouseEvent*>(event)->button(); |
|
3709 |
const bool rightButtonPressed = button & Qt::RightButton; |
|
3710 |
const bool shiftKeyPressed = modifiers & Qt::ShiftModifier; |
|
3711 |
const bool controlKeyPressed = modifiers & Qt::ControlModifier; |
|
3712 |
const bool indexIsSelected = selectionModel->isSelected(index); |
|
3713 |
if ((shiftKeyPressed || controlKeyPressed) && rightButtonPressed) |
|
3714 |
return QItemSelectionModel::NoUpdate; |
|
3715 |
if (!shiftKeyPressed && !controlKeyPressed && indexIsSelected) |
|
3716 |
return QItemSelectionModel::NoUpdate; |
|
3717 |
if (!index.isValid() && !rightButtonPressed && !shiftKeyPressed && !controlKeyPressed) |
|
3718 |
return QItemSelectionModel::Clear; |
|
3719 |
if (!index.isValid()) |
|
3720 |
return QItemSelectionModel::NoUpdate; |
|
3721 |
break; |
|
3722 |
} |
|
3723 |
case QEvent::MouseButtonRelease: { |
|
3724 |
// ClearAndSelect on MouseButtonRelease if MouseButtonPress on selected item or empty area |
|
3725 |
modifiers = static_cast<const QMouseEvent*>(event)->modifiers(); |
|
3726 |
const Qt::MouseButton button = static_cast<const QMouseEvent*>(event)->button(); |
|
3727 |
const bool rightButtonPressed = button & Qt::RightButton; |
|
3728 |
const bool shiftKeyPressed = modifiers & Qt::ShiftModifier; |
|
3729 |
const bool controlKeyPressed = modifiers & Qt::ControlModifier; |
|
3730 |
if (((index == pressedIndex && selectionModel->isSelected(index)) |
|
3731 |
|| !index.isValid()) && state != QAbstractItemView::DragSelectingState |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3732 |
&& !shiftKeyPressed && !controlKeyPressed && (!rightButtonPressed || !index.isValid())) |
0 | 3733 |
return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); |
3734 |
return QItemSelectionModel::NoUpdate; |
|
3735 |
} |
|
3736 |
case QEvent::KeyPress: { |
|
3737 |
// NoUpdate on Key movement and Ctrl |
|
3738 |
modifiers = static_cast<const QKeyEvent*>(event)->modifiers(); |
|
3739 |
switch (static_cast<const QKeyEvent*>(event)->key()) { |
|
3740 |
case Qt::Key_Backtab: |
|
3741 |
modifiers = modifiers & ~Qt::ShiftModifier; // special case for backtab |
|
3742 |
case Qt::Key_Down: |
|
3743 |
case Qt::Key_Up: |
|
3744 |
case Qt::Key_Left: |
|
3745 |
case Qt::Key_Right: |
|
3746 |
case Qt::Key_Home: |
|
3747 |
case Qt::Key_End: |
|
3748 |
case Qt::Key_PageUp: |
|
3749 |
case Qt::Key_PageDown: |
|
3750 |
case Qt::Key_Tab: |
|
3751 |
if (modifiers & Qt::ControlModifier |
|
3752 |
#ifdef QT_KEYPAD_NAVIGATION |
|
3753 |
// Preserve historical tab order navigation behavior |
|
3754 |
|| QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder |
|
3755 |
#endif |
|
3756 |
) |
|
3757 |
return QItemSelectionModel::NoUpdate; |
|
3758 |
break; |
|
3759 |
case Qt::Key_Select: |
|
3760 |
return QItemSelectionModel::Toggle|selectionBehaviorFlags(); |
|
3761 |
case Qt::Key_Space:// Toggle on Ctrl-Qt::Key_Space, Select on Space |
|
3762 |
if (modifiers & Qt::ControlModifier) |
|
3763 |
return QItemSelectionModel::Toggle|selectionBehaviorFlags(); |
|
3764 |
return QItemSelectionModel::Select|selectionBehaviorFlags(); |
|
3765 |
default: |
|
3766 |
break; |
|
3767 |
} |
|
3768 |
} |
|
3769 |
default: |
|
3770 |
break; |
|
3771 |
} |
|
3772 |
} |
|
3773 |
||
3774 |
if (modifiers & Qt::ShiftModifier) |
|
3775 |
return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); |
|
3776 |
if (modifiers & Qt::ControlModifier) |
|
3777 |
return QItemSelectionModel::Toggle|selectionBehaviorFlags(); |
|
3778 |
if (state == QAbstractItemView::DragSelectingState) { |
|
3779 |
//when drag-selecting we need to clear any previous selection and select the current one |
|
3780 |
return QItemSelectionModel::Clear|QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); |
|
3781 |
} |
|
3782 |
||
3783 |
return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); |
|
3784 |
} |
|
3785 |
||
3786 |
QItemSelectionModel::SelectionFlags |
|
3787 |
QAbstractItemViewPrivate::contiguousSelectionCommand(const QModelIndex &index, |
|
3788 |
const QEvent *event) const |
|
3789 |
{ |
|
3790 |
QItemSelectionModel::SelectionFlags flags = extendedSelectionCommand(index, event); |
|
3791 |
const int Mask = QItemSelectionModel::Clear | QItemSelectionModel::Select |
|
3792 |
| QItemSelectionModel::Deselect | QItemSelectionModel::Toggle |
|
3793 |
| QItemSelectionModel::Current; |
|
3794 |
||
3795 |
switch (flags & Mask) { |
|
3796 |
case QItemSelectionModel::Clear: |
|
3797 |
case QItemSelectionModel::ClearAndSelect: |
|
3798 |
case QItemSelectionModel::SelectCurrent: |
|
3799 |
return flags; |
|
3800 |
case QItemSelectionModel::NoUpdate: |
|
3801 |
if (event && |
|
3802 |
(event->type() == QEvent::MouseButtonPress |
|
3803 |
|| event->type() == QEvent::MouseButtonRelease)) |
|
3804 |
return flags; |
|
3805 |
return QItemSelectionModel::ClearAndSelect|selectionBehaviorFlags(); |
|
3806 |
default: |
|
3807 |
return QItemSelectionModel::SelectCurrent|selectionBehaviorFlags(); |
|
3808 |
} |
|
3809 |
} |
|
3810 |
||
3811 |
void QAbstractItemViewPrivate::fetchMore() |
|
3812 |
{ |
|
3813 |
fetchMoreTimer.stop(); |
|
3814 |
if (!model->canFetchMore(root)) |
|
3815 |
return; |
|
3816 |
int last = model->rowCount(root) - 1; |
|
3817 |
if (last < 0) { |
|
3818 |
model->fetchMore(root); |
|
3819 |
return; |
|
3820 |
} |
|
3821 |
||
3822 |
QModelIndex index = model->index(last, 0, root); |
|
3823 |
QRect rect = q_func()->visualRect(index); |
|
3824 |
if (viewport->rect().intersects(rect)) |
|
3825 |
model->fetchMore(root); |
|
3826 |
} |
|
3827 |
||
3828 |
bool QAbstractItemViewPrivate::shouldEdit(QAbstractItemView::EditTrigger trigger, |
|
3829 |
const QModelIndex &index) const |
|
3830 |
{ |
|
3831 |
if (!index.isValid()) |
|
3832 |
return false; |
|
3833 |
Qt::ItemFlags flags = model->flags(index); |
|
3834 |
if (((flags & Qt::ItemIsEditable) == 0) || ((flags & Qt::ItemIsEnabled) == 0)) |
|
3835 |
return false; |
|
3836 |
if (state == QAbstractItemView::EditingState) |
|
3837 |
return false; |
|
3838 |
if (hasEditor(index)) |
|
3839 |
return false; |
|
3840 |
if (trigger == QAbstractItemView::AllEditTriggers) // force editing |
|
3841 |
return true; |
|
3842 |
if ((trigger & editTriggers) == QAbstractItemView::SelectedClicked |
|
3843 |
&& !selectionModel->isSelected(index)) |
|
3844 |
return false; |
|
3845 |
return (trigger & editTriggers); |
|
3846 |
} |
|
3847 |
||
3848 |
bool QAbstractItemViewPrivate::shouldForwardEvent(QAbstractItemView::EditTrigger trigger, |
|
3849 |
const QEvent *event) const |
|
3850 |
{ |
|
3851 |
if (!event || (trigger & editTriggers) != QAbstractItemView::AnyKeyPressed) |
|
3852 |
return false; |
|
3853 |
||
3854 |
switch (event->type()) { |
|
3855 |
case QEvent::KeyPress: |
|
3856 |
case QEvent::MouseButtonDblClick: |
|
3857 |
case QEvent::MouseButtonPress: |
|
3858 |
case QEvent::MouseButtonRelease: |
|
3859 |
case QEvent::MouseMove: |
|
3860 |
return true; |
|
3861 |
default: |
|
3862 |
break; |
|
3863 |
}; |
|
3864 |
||
3865 |
return false; |
|
3866 |
} |
|
3867 |
||
3868 |
bool QAbstractItemViewPrivate::shouldAutoScroll(const QPoint &pos) const |
|
3869 |
{ |
|
3870 |
if (!autoScroll) |
|
3871 |
return false; |
|
3872 |
QRect area = static_cast<QAbstractItemView*>(viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules |
|
3873 |
return (pos.y() - area.top() < autoScrollMargin) |
|
3874 |
|| (area.bottom() - pos.y() < autoScrollMargin) |
|
3875 |
|| (pos.x() - area.left() < autoScrollMargin) |
|
3876 |
|| (area.right() - pos.x() < autoScrollMargin); |
|
3877 |
} |
|
3878 |
||
3879 |
void QAbstractItemViewPrivate::doDelayedItemsLayout(int delay) |
|
3880 |
{ |
|
3881 |
if (!delayedPendingLayout) { |
|
3882 |
delayedPendingLayout = true; |
|
3883 |
delayedLayout.start(delay, q_func()); |
|
3884 |
} |
|
3885 |
} |
|
3886 |
||
3887 |
void QAbstractItemViewPrivate::interruptDelayedItemsLayout() const |
|
3888 |
{ |
|
3889 |
delayedLayout.stop(); |
|
3890 |
delayedPendingLayout = false; |
|
3891 |
} |
|
3892 |
||
3893 |
||
3894 |
||
3895 |
QWidget *QAbstractItemViewPrivate::editor(const QModelIndex &index, |
|
3896 |
const QStyleOptionViewItem &options) |
|
3897 |
{ |
|
3898 |
Q_Q(QAbstractItemView); |
|
3899 |
QWidget *w = editorForIndex(index).editor; |
|
3900 |
if (!w) { |
|
3901 |
QAbstractItemDelegate *delegate = delegateForIndex(index); |
|
3902 |
if (!delegate) |
|
3903 |
return 0; |
|
3904 |
w = delegate->createEditor(viewport, options, index); |
|
3905 |
if (w) { |
|
3906 |
w->installEventFilter(delegate); |
|
3907 |
QObject::connect(w, SIGNAL(destroyed(QObject*)), q, SLOT(editorDestroyed(QObject*))); |
|
3908 |
delegate->updateEditorGeometry(w, options, index); |
|
3909 |
delegate->setEditorData(w, index); |
|
3910 |
addEditor(index, w, false); |
|
3911 |
if (w->parent() == viewport) |
|
3912 |
QWidget::setTabOrder(q, w); |
|
3913 |
||
3914 |
// Special cases for some editors containing QLineEdit |
|
3915 |
QWidget *focusWidget = w; |
|
3916 |
while (QWidget *fp = focusWidget->focusProxy()) |
|
3917 |
focusWidget = fp; |
|
3918 |
#ifndef QT_NO_LINEEDIT |
|
3919 |
if (QLineEdit *le = qobject_cast<QLineEdit*>(focusWidget)) |
|
3920 |
le->selectAll(); |
|
3921 |
#endif |
|
3922 |
#ifndef QT_NO_SPINBOX |
|
3923 |
if (QSpinBox *sb = qobject_cast<QSpinBox*>(focusWidget)) |
|
3924 |
sb->selectAll(); |
|
3925 |
else if (QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox*>(focusWidget)) |
|
3926 |
dsb->selectAll(); |
|
3927 |
#endif |
|
3928 |
} |
|
3929 |
} |
|
3930 |
return w; |
|
3931 |
} |
|
3932 |
||
3933 |
void QAbstractItemViewPrivate::updateEditorData(const QModelIndex &tl, const QModelIndex &br) |
|
3934 |
{ |
|
3935 |
// we are counting on having relatively few editors |
|
3936 |
const bool checkIndexes = tl.isValid() && br.isValid(); |
|
3937 |
const QModelIndex parent = tl.parent(); |
|
3938 |
QList<QEditorInfo>::const_iterator it = editors.constBegin(); |
|
3939 |
for (; it != editors.constEnd(); ++it) { |
|
3940 |
QWidget *editor = it->editor; |
|
3941 |
const QModelIndex index = it->index; |
|
3942 |
if (it->isStatic || editor == 0 || !index.isValid() || |
|
3943 |
(checkIndexes |
|
3944 |
&& (index.row() < tl.row() || index.row() > br.row() |
|
3945 |
|| index.column() < tl.column() || index.column() > br.column() |
|
3946 |
|| index.parent() != parent))) |
|
3947 |
continue; |
|
3948 |
||
3949 |
QAbstractItemDelegate *delegate = delegateForIndex(index); |
|
3950 |
if (delegate) { |
|
3951 |
delegate->setEditorData(editor, index); |
|
3952 |
} |
|
3953 |
} |
|
3954 |
} |
|
3955 |
||
3956 |
/*! |
|
3957 |
\internal |
|
3958 |
||
3959 |
In DND if something has been moved then this is called. |
|
3960 |
Typically this means you should "remove" the selected item or row, |
|
3961 |
but the behavior is view dependant (table just clears the selected indexes for example). |
|
3962 |
||
3963 |
Either remove the selected rows or clear them |
|
3964 |
*/ |
|
3965 |
void QAbstractItemViewPrivate::clearOrRemove() |
|
3966 |
{ |
|
3967 |
#ifndef QT_NO_DRAGANDDROP |
|
3968 |
const QItemSelection selection = selectionModel->selection(); |
|
3969 |
QList<QItemSelectionRange>::const_iterator it = selection.constBegin(); |
|
3970 |
||
3971 |
if (!overwrite) { |
|
3972 |
for (; it != selection.constEnd(); ++it) { |
|
3973 |
QModelIndex parent = (*it).parent(); |
|
3974 |
if ((*it).left() != 0) |
|
3975 |
continue; |
|
3976 |
if ((*it).right() != (model->columnCount(parent) - 1)) |
|
3977 |
continue; |
|
3978 |
int count = (*it).bottom() - (*it).top() + 1; |
|
3979 |
model->removeRows((*it).top(), count, parent); |
|
3980 |
} |
|
3981 |
} else { |
|
3982 |
// we can't remove the rows so reset the items (i.e. the view is like a table) |
|
3983 |
QModelIndexList list = selection.indexes(); |
|
3984 |
for (int i=0; i < list.size(); ++i) { |
|
3985 |
QModelIndex index = list.at(i); |
|
3986 |
QMap<int, QVariant> roles = model->itemData(index); |
|
3987 |
for (QMap<int, QVariant>::Iterator it = roles.begin(); it != roles.end(); ++it) |
|
3988 |
it.value() = QVariant(); |
|
3989 |
model->setItemData(index, roles); |
|
3990 |
} |
|
3991 |
} |
|
3992 |
#endif |
|
3993 |
} |
|
3994 |
||
3995 |
/*! |
|
3996 |
\internal |
|
3997 |
||
3998 |
When persistent aeditor gets/loses focus, we need to check |
|
3999 |
and setcorrectly the current index. |
|
4000 |
*/ |
|
4001 |
void QAbstractItemViewPrivate::checkPersistentEditorFocus() |
|
4002 |
{ |
|
4003 |
Q_Q(QAbstractItemView); |
|
4004 |
if (QWidget *widget = QApplication::focusWidget()) { |
|
4005 |
if (persistent.contains(widget)) { |
|
4006 |
//a persistent editor has gained the focus |
|
4007 |
QModelIndex index = indexForEditor(widget); |
|
4008 |
if (selectionModel->currentIndex() != index) |
|
4009 |
q->setCurrentIndex(index); |
|
4010 |
} |
|
4011 |
} |
|
4012 |
} |
|
4013 |
||
4014 |
||
4015 |
QEditorInfo QAbstractItemViewPrivate::editorForIndex(const QModelIndex &index) const |
|
4016 |
{ |
|
4017 |
QList<QEditorInfo>::const_iterator it = editors.constBegin(); |
|
4018 |
for (; it != editors.constEnd(); ++it) { |
|
4019 |
if (it->index == index) |
|
4020 |
return *it; |
|
4021 |
} |
|
4022 |
||
4023 |
return QEditorInfo(); |
|
4024 |
} |
|
4025 |
||
4026 |
QModelIndex QAbstractItemViewPrivate::indexForEditor(QWidget *editor) const |
|
4027 |
{ |
|
4028 |
QList<QEditorInfo>::const_iterator it = editors.constBegin(); |
|
4029 |
for (; it != editors.constEnd(); ++it) { |
|
4030 |
if (it->editor == editor) |
|
4031 |
return it->index; |
|
4032 |
} |
|
4033 |
return QModelIndex(); |
|
4034 |
} |
|
4035 |
||
4036 |
void QAbstractItemViewPrivate::removeEditor(QWidget *editor) |
|
4037 |
{ |
|
4038 |
QList<QEditorInfo>::iterator it = editors.begin(); |
|
4039 |
for (; it != editors.end(); ) { |
|
4040 |
if (it->editor == editor) |
|
4041 |
it = editors.erase(it); |
|
4042 |
else |
|
4043 |
++it; |
|
4044 |
} |
|
4045 |
} |
|
4046 |
||
4047 |
void QAbstractItemViewPrivate::addEditor(const QModelIndex &index, QWidget *editor, bool isStatic) |
|
4048 |
{ |
|
4049 |
editors.append(QEditorInfo(index, editor, isStatic)); |
|
4050 |
} |
|
4051 |
||
4052 |
bool QAbstractItemViewPrivate::sendDelegateEvent(const QModelIndex &index, QEvent *event) const |
|
4053 |
{ |
|
4054 |
Q_Q(const QAbstractItemView); |
|
4055 |
QModelIndex buddy = model->buddy(index); |
|
4056 |
QStyleOptionViewItemV4 options = viewOptionsV4(); |
|
4057 |
options.rect = q->visualRect(buddy); |
|
4058 |
options.state |= (buddy == q->currentIndex() ? QStyle::State_HasFocus : QStyle::State_None); |
|
4059 |
QAbstractItemDelegate *delegate = delegateForIndex(index); |
|
4060 |
return (event && delegate && delegate->editorEvent(event, model, options, buddy)); |
|
4061 |
} |
|
4062 |
||
4063 |
bool QAbstractItemViewPrivate::openEditor(const QModelIndex &index, QEvent *event) |
|
4064 |
{ |
|
4065 |
Q_Q(QAbstractItemView); |
|
4066 |
||
4067 |
QModelIndex buddy = model->buddy(index); |
|
4068 |
QStyleOptionViewItemV4 options = viewOptionsV4(); |
|
4069 |
options.rect = q->visualRect(buddy); |
|
4070 |
options.state |= (buddy == q->currentIndex() ? QStyle::State_HasFocus : QStyle::State_None); |
|
4071 |
||
4072 |
QWidget *w = editor(buddy, options); |
|
4073 |
if (!w) |
|
4074 |
return false; |
|
4075 |
||
4076 |
if (event) |
|
4077 |
QApplication::sendEvent(w->focusProxy() ? w->focusProxy() : w, event); |
|
4078 |
||
4079 |
q->setState(QAbstractItemView::EditingState); |
|
4080 |
w->show(); |
|
4081 |
w->setFocus(); |
|
4082 |
||
4083 |
return true; |
|
4084 |
} |
|
4085 |
||
4086 |
/* |
|
4087 |
\internal |
|
4088 |
||
4089 |
returns the pair QRect/QModelIndex that should be painted on the viewports's rect |
|
4090 |
*/ |
|
4091 |
||
4092 |
QItemViewPaintPairs QAbstractItemViewPrivate::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const |
|
4093 |
{ |
|
4094 |
Q_ASSERT(r); |
|
4095 |
Q_Q(const QAbstractItemView); |
|
4096 |
QRect &rect = *r; |
|
4097 |
const QRect viewportRect = viewport->rect(); |
|
4098 |
QItemViewPaintPairs ret; |
|
4099 |
for (int i = 0; i < indexes.count(); ++i) { |
|
4100 |
const QModelIndex &index = indexes.at(i); |
|
4101 |
const QRect current = q->visualRect(index); |
|
4102 |
if (current.intersects(viewportRect)) { |
|
4103 |
ret += qMakePair(current, index); |
|
4104 |
rect |= current; |
|
4105 |
} |
|
4106 |
} |
|
4107 |
rect &= viewportRect; |
|
4108 |
return ret; |
|
4109 |
} |
|
4110 |
||
4111 |
QPixmap QAbstractItemViewPrivate::renderToPixmap(const QModelIndexList &indexes, QRect *r) const |
|
4112 |
{ |
|
4113 |
Q_ASSERT(r); |
|
4114 |
QItemViewPaintPairs paintPairs = draggablePaintPairs(indexes, r); |
|
4115 |
if (paintPairs.isEmpty()) |
|
4116 |
return QPixmap(); |
|
4117 |
QPixmap pixmap(r->size()); |
|
4118 |
pixmap.fill(Qt::transparent); |
|
4119 |
QPainter painter(&pixmap); |
|
4120 |
QStyleOptionViewItemV4 option = viewOptionsV4(); |
|
4121 |
option.state |= QStyle::State_Selected; |
|
4122 |
for (int j = 0; j < paintPairs.count(); ++j) { |
|
4123 |
option.rect = paintPairs.at(j).first.translated(-r->topLeft()); |
|
4124 |
const QModelIndex ¤t = paintPairs.at(j).second; |
|
4125 |
delegateForIndex(current)->paint(&painter, option, current); |
|
4126 |
} |
|
4127 |
return pixmap; |
|
4128 |
} |
|
4129 |
||
4130 |
void QAbstractItemViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command) |
|
4131 |
{ |
|
4132 |
if (!selectionModel) |
|
4133 |
return; |
|
4134 |
||
4135 |
QItemSelection selection; |
|
4136 |
QModelIndex tl = model->index(0, 0, root); |
|
4137 |
QModelIndex br = model->index(model->rowCount(root) - 1, |
|
4138 |
model->columnCount(root) - 1, |
|
4139 |
root); |
|
4140 |
selection.append(QItemSelectionRange(tl, br)); |
|
4141 |
selectionModel->select(selection, command); |
|
4142 |
} |
|
4143 |
||
4144 |
QModelIndexList QAbstractItemViewPrivate::selectedDraggableIndexes() const |
|
4145 |
{ |
|
4146 |
Q_Q(const QAbstractItemView); |
|
4147 |
QModelIndexList indexes = q->selectedIndexes(); |
|
4148 |
for(int i = indexes.count() - 1 ; i >= 0; --i) { |
|
4149 |
if (!isIndexDragEnabled(indexes.at(i))) |
|
4150 |
indexes.removeAt(i); |
|
4151 |
} |
|
4152 |
return indexes; |
|
4153 |
} |
|
4154 |
||
4155 |
||
4156 |
QT_END_NAMESPACE |
|
4157 |
||
4158 |
#include "moc_qabstractitemview.cpp" |
|
4159 |
||
4160 |
#endif // QT_NO_ITEMVIEWS |