Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qlistview.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Copyright (C) 2013 Samuel Gaist <samuel.gaist@deltech.ch> | - | ||||||||||||||||||||||||
5 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
6 | ** | - | ||||||||||||||||||||||||
7 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
8 | ** | - | ||||||||||||||||||||||||
9 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
15 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
16 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
17 | ** | - | ||||||||||||||||||||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
20 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
23 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
26 | ** | - | ||||||||||||||||||||||||
27 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
28 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
30 | ** | - | ||||||||||||||||||||||||
31 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
32 | ** | - | ||||||||||||||||||||||||
33 | ****************************************************************************/ | - | ||||||||||||||||||||||||
34 | - | |||||||||||||||||||||||||
35 | #include "qlistview.h" | - | ||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||
37 | #ifndef QT_NO_LISTVIEW | - | ||||||||||||||||||||||||
38 | #include <qabstractitemdelegate.h> | - | ||||||||||||||||||||||||
39 | #include <qapplication.h> | - | ||||||||||||||||||||||||
40 | #include <qpainter.h> | - | ||||||||||||||||||||||||
41 | #include <qbitmap.h> | - | ||||||||||||||||||||||||
42 | #include <qdrag.h> | - | ||||||||||||||||||||||||
43 | #include <qvector.h> | - | ||||||||||||||||||||||||
44 | #include <qstyle.h> | - | ||||||||||||||||||||||||
45 | #include <qevent.h> | - | ||||||||||||||||||||||||
46 | #include <qscrollbar.h> | - | ||||||||||||||||||||||||
47 | #include <qrubberband.h> | - | ||||||||||||||||||||||||
48 | #include <private/qlistview_p.h> | - | ||||||||||||||||||||||||
49 | #include <qdebug.h> | - | ||||||||||||||||||||||||
50 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
51 | #include <qaccessible.h> | - | ||||||||||||||||||||||||
52 | #endif | - | ||||||||||||||||||||||||
53 | - | |||||||||||||||||||||||||
54 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); | - | ||||||||||||||||||||||||
57 | - | |||||||||||||||||||||||||
58 | /*! | - | ||||||||||||||||||||||||
59 | \class QListView | - | ||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||
61 | \brief The QListView class provides a list or icon view onto a model. | - | ||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||
63 | \ingroup model-view | - | ||||||||||||||||||||||||
64 | \ingroup advanced | - | ||||||||||||||||||||||||
65 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||
67 | A QListView presents items stored in a model, either as a simple | - | ||||||||||||||||||||||||
68 | non-hierarchical list, or as a collection of icons. This class is used | - | ||||||||||||||||||||||||
69 | to provide lists and icon views that were previously provided by the | - | ||||||||||||||||||||||||
70 | \c QListBox and \c QIconView classes, but using the more flexible | - | ||||||||||||||||||||||||
71 | approach provided by Qt's model/view architecture. | - | ||||||||||||||||||||||||
72 | - | |||||||||||||||||||||||||
73 | The QListView class is one of the \l{Model/View Classes} | - | ||||||||||||||||||||||||
74 | and is part of Qt's \l{Model/View Programming}{model/view framework}. | - | ||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | This view does not display horizontal or vertical headers; to display | - | ||||||||||||||||||||||||
77 | a list of items with a horizontal header, use QTreeView instead. | - | ||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||
79 | QListView implements the interfaces defined by the | - | ||||||||||||||||||||||||
80 | QAbstractItemView class to allow it to display data provided by | - | ||||||||||||||||||||||||
81 | models derived from the QAbstractItemModel class. | - | ||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||
83 | Items in a list view can be displayed using one of two view modes: | - | ||||||||||||||||||||||||
84 | In \l ListMode, the items are displayed in the form of a simple list; | - | ||||||||||||||||||||||||
85 | in \l IconMode, the list view takes the form of an \e{icon view} in | - | ||||||||||||||||||||||||
86 | which the items are displayed with icons like files in a file manager. | - | ||||||||||||||||||||||||
87 | By default, the list view is in \l ListMode. To change the view mode, | - | ||||||||||||||||||||||||
88 | use the setViewMode() function, and to determine the current view mode, | - | ||||||||||||||||||||||||
89 | use viewMode(). | - | ||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||
91 | Items in these views are laid out in the direction specified by the | - | ||||||||||||||||||||||||
92 | flow() of the list view. The items may be fixed in place, or allowed | - | ||||||||||||||||||||||||
93 | to move, depending on the view's movement() state. | - | ||||||||||||||||||||||||
94 | - | |||||||||||||||||||||||||
95 | If the items in the model cannot be completely laid out in the | - | ||||||||||||||||||||||||
96 | direction of flow, they can be wrapped at the boundary of the view | - | ||||||||||||||||||||||||
97 | widget; this depends on isWrapping(). This property is useful when the | - | ||||||||||||||||||||||||
98 | items are being represented by an icon view. | - | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | The resizeMode() and layoutMode() govern how and when the items are | - | ||||||||||||||||||||||||
101 | laid out. Items are spaced according to their spacing(), and can exist | - | ||||||||||||||||||||||||
102 | within a notional grid of size specified by gridSize(). The items can | - | ||||||||||||||||||||||||
103 | be rendered as large or small icons depending on their iconSize(). | - | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | \table 100% | - | ||||||||||||||||||||||||
106 | \row \li \inlineimage windowsvista-listview.png Screenshot of a Windows Vista style list view | - | ||||||||||||||||||||||||
107 | \li \inlineimage macintosh-listview.png Screenshot of a Macintosh style table view | - | ||||||||||||||||||||||||
108 | \li \inlineimage fusion-listview.png Screenshot of a Fusion style table view | - | ||||||||||||||||||||||||
109 | \row \li A \l{Windows Vista Style Widget Gallery}{Windows Vista style} list view. | - | ||||||||||||||||||||||||
110 | \li A \l{Macintosh Style Widget Gallery}{Macintosh style} list view. | - | ||||||||||||||||||||||||
111 | \li A \l{Fusion Style Widget Gallery}{Fusion style} list view. | - | ||||||||||||||||||||||||
112 | \endtable | - | ||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||
114 | \section1 Improving Performance | - | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | It is possible to give the view hints about the data it is handling in order | - | ||||||||||||||||||||||||
117 | to improve its performance when displaying large numbers of items. One approach | - | ||||||||||||||||||||||||
118 | that can be taken for views that are intended to display items with equal sizes | - | ||||||||||||||||||||||||
119 | is to set the \l uniformItemSizes property to true. | - | ||||||||||||||||||||||||
120 | - | |||||||||||||||||||||||||
121 | \sa {View Classes}, {Item Views Puzzle Example}, QTreeView, QTableView, QListWidget | - | ||||||||||||||||||||||||
122 | */ | - | ||||||||||||||||||||||||
123 | - | |||||||||||||||||||||||||
124 | /*! | - | ||||||||||||||||||||||||
125 | \enum QListView::ViewMode | - | ||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||
127 | \value ListMode The items are laid out using TopToBottom flow, with Small size and Static movement | - | ||||||||||||||||||||||||
128 | \value IconMode The items are laid out using LeftToRight flow, with Large size and Free movement | - | ||||||||||||||||||||||||
129 | */ | - | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | /*! | - | ||||||||||||||||||||||||
132 | \enum QListView::Movement | - | ||||||||||||||||||||||||
133 | - | |||||||||||||||||||||||||
134 | \value Static The items cannot be moved by the user. | - | ||||||||||||||||||||||||
135 | \value Free The items can be moved freely by the user. | - | ||||||||||||||||||||||||
136 | \value Snap The items snap to the specified grid when moved; see | - | ||||||||||||||||||||||||
137 | setGridSize(). | - | ||||||||||||||||||||||||
138 | */ | - | ||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | /*! | - | ||||||||||||||||||||||||
141 | \enum QListView::Flow | - | ||||||||||||||||||||||||
142 | - | |||||||||||||||||||||||||
143 | \value LeftToRight The items are laid out in the view from the left | - | ||||||||||||||||||||||||
144 | to the right. | - | ||||||||||||||||||||||||
145 | \value TopToBottom The items are laid out in the view from the top | - | ||||||||||||||||||||||||
146 | to the bottom. | - | ||||||||||||||||||||||||
147 | */ | - | ||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||
149 | /*! | - | ||||||||||||||||||||||||
150 | \enum QListView::ResizeMode | - | ||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | \value Fixed The items will only be laid out the first time the view is shown. | - | ||||||||||||||||||||||||
153 | \value Adjust The items will be laid out every time the view is resized. | - | ||||||||||||||||||||||||
154 | */ | - | ||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||
156 | /*! | - | ||||||||||||||||||||||||
157 | \enum QListView::LayoutMode | - | ||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||
159 | \value SinglePass The items are laid out all at once. | - | ||||||||||||||||||||||||
160 | \value Batched The items are laid out in batches of \l batchSize items. | - | ||||||||||||||||||||||||
161 | \sa batchSize | - | ||||||||||||||||||||||||
162 | */ | - | ||||||||||||||||||||||||
163 | - | |||||||||||||||||||||||||
164 | /*! | - | ||||||||||||||||||||||||
165 | \since 4.2 | - | ||||||||||||||||||||||||
166 | \fn void QListView::indexesMoved(const QModelIndexList &indexes) | - | ||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||
168 | This signal is emitted when the specified \a indexes are moved in the view. | - | ||||||||||||||||||||||||
169 | */ | - | ||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||
171 | /*! | - | ||||||||||||||||||||||||
172 | Creates a new QListView with the given \a parent to view a model. | - | ||||||||||||||||||||||||
173 | Use setModel() to set the model. | - | ||||||||||||||||||||||||
174 | */ | - | ||||||||||||||||||||||||
175 | QListView::QListView(QWidget *parent) | - | ||||||||||||||||||||||||
176 | : QAbstractItemView(*new QListViewPrivate, parent) | - | ||||||||||||||||||||||||
177 | { | - | ||||||||||||||||||||||||
178 | setViewMode(ListMode); | - | ||||||||||||||||||||||||
179 | setSelectionMode(SingleSelection); | - | ||||||||||||||||||||||||
180 | setAttribute(Qt::WA_MacShowFocusRect); | - | ||||||||||||||||||||||||
181 | Q_D(QListView); // We rely on a qobject_cast for PM_DefaultFrameWidth to change | - | ||||||||||||||||||||||||
182 | d->updateStyledFrameWidths(); // hence we have to force an update now that the object has been constructed | - | ||||||||||||||||||||||||
183 | } never executed: end of block | 0 | ||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||
185 | /*! | - | ||||||||||||||||||||||||
186 | \internal | - | ||||||||||||||||||||||||
187 | */ | - | ||||||||||||||||||||||||
188 | QListView::QListView(QListViewPrivate &dd, QWidget *parent) | - | ||||||||||||||||||||||||
189 | : QAbstractItemView(dd, parent) | - | ||||||||||||||||||||||||
190 | { | - | ||||||||||||||||||||||||
191 | setViewMode(ListMode); | - | ||||||||||||||||||||||||
192 | setSelectionMode(SingleSelection); | - | ||||||||||||||||||||||||
193 | setAttribute(Qt::WA_MacShowFocusRect); | - | ||||||||||||||||||||||||
194 | Q_D(QListView); // We rely on a qobject_cast for PM_DefaultFrameWidth to change | - | ||||||||||||||||||||||||
195 | d->updateStyledFrameWidths(); // hence we have to force an update now that the object has been constructed | - | ||||||||||||||||||||||||
196 | } never executed: end of block | 0 | ||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | /*! | - | ||||||||||||||||||||||||
199 | Destroys the view. | - | ||||||||||||||||||||||||
200 | */ | - | ||||||||||||||||||||||||
201 | QListView::~QListView() | - | ||||||||||||||||||||||||
202 | { | - | ||||||||||||||||||||||||
203 | } | - | ||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||
205 | /*! | - | ||||||||||||||||||||||||
206 | \property QListView::movement | - | ||||||||||||||||||||||||
207 | \brief whether the items can be moved freely, are snapped to a | - | ||||||||||||||||||||||||
208 | grid, or cannot be moved at all. | - | ||||||||||||||||||||||||
209 | - | |||||||||||||||||||||||||
210 | This property determines how the user can move the items in the | - | ||||||||||||||||||||||||
211 | view. \l Static means that the items can't be moved the user. \l | - | ||||||||||||||||||||||||
212 | Free means that the user can drag and drop the items to any | - | ||||||||||||||||||||||||
213 | position in the view. \l Snap means that the user can drag and | - | ||||||||||||||||||||||||
214 | drop the items, but only to the positions in a notional grid | - | ||||||||||||||||||||||||
215 | signified by the gridSize property. | - | ||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||
217 | Setting this property when the view is visible will cause the | - | ||||||||||||||||||||||||
218 | items to be laid out again. | - | ||||||||||||||||||||||||
219 | - | |||||||||||||||||||||||||
220 | By default, this property is set to \l Static. | - | ||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||
222 | \sa gridSize, resizeMode, viewMode | - | ||||||||||||||||||||||||
223 | */ | - | ||||||||||||||||||||||||
224 | void QListView::setMovement(Movement movement) | - | ||||||||||||||||||||||||
225 | { | - | ||||||||||||||||||||||||
226 | Q_D(QListView); | - | ||||||||||||||||||||||||
227 | d->modeProperties |= uint(QListViewPrivate::Movement); | - | ||||||||||||||||||||||||
228 | d->movement = movement; | - | ||||||||||||||||||||||||
229 | - | |||||||||||||||||||||||||
230 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
231 | bool movable = (movement != Static); | - | ||||||||||||||||||||||||
232 | setDragEnabled(movable); | - | ||||||||||||||||||||||||
233 | d->viewport->setAcceptDrops(movable); | - | ||||||||||||||||||||||||
234 | #endif | - | ||||||||||||||||||||||||
235 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
236 | } never executed: end of block | 0 | ||||||||||||||||||||||||
237 | - | |||||||||||||||||||||||||
238 | QListView::Movement QListView::movement() const | - | ||||||||||||||||||||||||
239 | { | - | ||||||||||||||||||||||||
240 | Q_D(const QListView); | - | ||||||||||||||||||||||||
241 | return d->movement; never executed: return d->movement; | 0 | ||||||||||||||||||||||||
242 | } | - | ||||||||||||||||||||||||
243 | - | |||||||||||||||||||||||||
244 | /*! | - | ||||||||||||||||||||||||
245 | \property QListView::flow | - | ||||||||||||||||||||||||
246 | \brief which direction the items layout should flow. | - | ||||||||||||||||||||||||
247 | - | |||||||||||||||||||||||||
248 | If this property is \l LeftToRight, the items will be laid out left | - | ||||||||||||||||||||||||
249 | to right. If the \l isWrapping property is \c true, the layout will wrap | - | ||||||||||||||||||||||||
250 | when it reaches the right side of the visible area. If this | - | ||||||||||||||||||||||||
251 | property is \l TopToBottom, the items will be laid out from the top | - | ||||||||||||||||||||||||
252 | of the visible area, wrapping when it reaches the bottom. | - | ||||||||||||||||||||||||
253 | - | |||||||||||||||||||||||||
254 | Setting this property when the view is visible will cause the | - | ||||||||||||||||||||||||
255 | items to be laid out again. | - | ||||||||||||||||||||||||
256 | - | |||||||||||||||||||||||||
257 | By default, this property is set to \l TopToBottom. | - | ||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||
259 | \sa viewMode | - | ||||||||||||||||||||||||
260 | */ | - | ||||||||||||||||||||||||
261 | void QListView::setFlow(Flow flow) | - | ||||||||||||||||||||||||
262 | { | - | ||||||||||||||||||||||||
263 | Q_D(QListView); | - | ||||||||||||||||||||||||
264 | d->modeProperties |= uint(QListViewPrivate::Flow); | - | ||||||||||||||||||||||||
265 | d->flow = flow; | - | ||||||||||||||||||||||||
266 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
267 | } never executed: end of block | 0 | ||||||||||||||||||||||||
268 | - | |||||||||||||||||||||||||
269 | QListView::Flow QListView::flow() const | - | ||||||||||||||||||||||||
270 | { | - | ||||||||||||||||||||||||
271 | Q_D(const QListView); | - | ||||||||||||||||||||||||
272 | return d->flow; never executed: return d->flow; | 0 | ||||||||||||||||||||||||
273 | } | - | ||||||||||||||||||||||||
274 | - | |||||||||||||||||||||||||
275 | /*! | - | ||||||||||||||||||||||||
276 | \property QListView::isWrapping | - | ||||||||||||||||||||||||
277 | \brief whether the items layout should wrap. | - | ||||||||||||||||||||||||
278 | - | |||||||||||||||||||||||||
279 | This property holds whether the layout should wrap when there is | - | ||||||||||||||||||||||||
280 | no more space in the visible area. The point at which the layout wraps | - | ||||||||||||||||||||||||
281 | depends on the \l flow property. | - | ||||||||||||||||||||||||
282 | - | |||||||||||||||||||||||||
283 | Setting this property when the view is visible will cause the | - | ||||||||||||||||||||||||
284 | items to be laid out again. | - | ||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||
286 | By default, this property is \c false. | - | ||||||||||||||||||||||||
287 | - | |||||||||||||||||||||||||
288 | \sa viewMode | - | ||||||||||||||||||||||||
289 | */ | - | ||||||||||||||||||||||||
290 | void QListView::setWrapping(bool enable) | - | ||||||||||||||||||||||||
291 | { | - | ||||||||||||||||||||||||
292 | Q_D(QListView); | - | ||||||||||||||||||||||||
293 | d->modeProperties |= uint(QListViewPrivate::Wrap); | - | ||||||||||||||||||||||||
294 | d->setWrapping(enable); | - | ||||||||||||||||||||||||
295 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
296 | } never executed: end of block | 0 | ||||||||||||||||||||||||
297 | - | |||||||||||||||||||||||||
298 | bool QListView::isWrapping() const | - | ||||||||||||||||||||||||
299 | { | - | ||||||||||||||||||||||||
300 | Q_D(const QListView); | - | ||||||||||||||||||||||||
301 | return d->isWrapping(); never executed: return d->isWrapping(); | 0 | ||||||||||||||||||||||||
302 | } | - | ||||||||||||||||||||||||
303 | - | |||||||||||||||||||||||||
304 | /*! | - | ||||||||||||||||||||||||
305 | \property QListView::resizeMode | - | ||||||||||||||||||||||||
306 | \brief whether the items are laid out again when the view is resized. | - | ||||||||||||||||||||||||
307 | - | |||||||||||||||||||||||||
308 | If this property is \l Adjust, the items will be laid out again | - | ||||||||||||||||||||||||
309 | when the view is resized. If the value is \l Fixed, the items will | - | ||||||||||||||||||||||||
310 | not be laid out when the view is resized. | - | ||||||||||||||||||||||||
311 | - | |||||||||||||||||||||||||
312 | By default, this property is set to \l Fixed. | - | ||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||
314 | \sa movement, gridSize, viewMode | - | ||||||||||||||||||||||||
315 | */ | - | ||||||||||||||||||||||||
316 | void QListView::setResizeMode(ResizeMode mode) | - | ||||||||||||||||||||||||
317 | { | - | ||||||||||||||||||||||||
318 | Q_D(QListView); | - | ||||||||||||||||||||||||
319 | d->modeProperties |= uint(QListViewPrivate::ResizeMode); | - | ||||||||||||||||||||||||
320 | d->resizeMode = mode; | - | ||||||||||||||||||||||||
321 | } never executed: end of block | 0 | ||||||||||||||||||||||||
322 | - | |||||||||||||||||||||||||
323 | QListView::ResizeMode QListView::resizeMode() const | - | ||||||||||||||||||||||||
324 | { | - | ||||||||||||||||||||||||
325 | Q_D(const QListView); | - | ||||||||||||||||||||||||
326 | return d->resizeMode; never executed: return d->resizeMode; | 0 | ||||||||||||||||||||||||
327 | } | - | ||||||||||||||||||||||||
328 | - | |||||||||||||||||||||||||
329 | /*! | - | ||||||||||||||||||||||||
330 | \property QListView::layoutMode | - | ||||||||||||||||||||||||
331 | \brief determines whether the layout of items should happen immediately or be delayed. | - | ||||||||||||||||||||||||
332 | - | |||||||||||||||||||||||||
333 | This property holds the layout mode for the items. When the mode | - | ||||||||||||||||||||||||
334 | is \l SinglePass (the default), the items are laid out all in one go. | - | ||||||||||||||||||||||||
335 | When the mode is \l Batched, the items are laid out in batches of \l batchSize | - | ||||||||||||||||||||||||
336 | items, while processing events. This makes it possible to | - | ||||||||||||||||||||||||
337 | instantly view and interact with the visible items while the rest | - | ||||||||||||||||||||||||
338 | are being laid out. | - | ||||||||||||||||||||||||
339 | - | |||||||||||||||||||||||||
340 | \sa viewMode | - | ||||||||||||||||||||||||
341 | */ | - | ||||||||||||||||||||||||
342 | void QListView::setLayoutMode(LayoutMode mode) | - | ||||||||||||||||||||||||
343 | { | - | ||||||||||||||||||||||||
344 | Q_D(QListView); | - | ||||||||||||||||||||||||
345 | d->layoutMode = mode; | - | ||||||||||||||||||||||||
346 | } never executed: end of block | 0 | ||||||||||||||||||||||||
347 | - | |||||||||||||||||||||||||
348 | QListView::LayoutMode QListView::layoutMode() const | - | ||||||||||||||||||||||||
349 | { | - | ||||||||||||||||||||||||
350 | Q_D(const QListView); | - | ||||||||||||||||||||||||
351 | return d->layoutMode; never executed: return d->layoutMode; | 0 | ||||||||||||||||||||||||
352 | } | - | ||||||||||||||||||||||||
353 | - | |||||||||||||||||||||||||
354 | /*! | - | ||||||||||||||||||||||||
355 | \property QListView::spacing | - | ||||||||||||||||||||||||
356 | \brief the space around the items in the layout | - | ||||||||||||||||||||||||
357 | - | |||||||||||||||||||||||||
358 | This property is the size of the empty space that is padded around | - | ||||||||||||||||||||||||
359 | an item in the layout. | - | ||||||||||||||||||||||||
360 | - | |||||||||||||||||||||||||
361 | Setting this property when the view is visible will cause the | - | ||||||||||||||||||||||||
362 | items to be laid out again. | - | ||||||||||||||||||||||||
363 | - | |||||||||||||||||||||||||
364 | By default, this property contains a value of 0. | - | ||||||||||||||||||||||||
365 | - | |||||||||||||||||||||||||
366 | \sa viewMode | - | ||||||||||||||||||||||||
367 | */ | - | ||||||||||||||||||||||||
368 | void QListView::setSpacing(int space) | - | ||||||||||||||||||||||||
369 | { | - | ||||||||||||||||||||||||
370 | Q_D(QListView); | - | ||||||||||||||||||||||||
371 | d->modeProperties |= uint(QListViewPrivate::Spacing); | - | ||||||||||||||||||||||||
372 | d->setSpacing(space); | - | ||||||||||||||||||||||||
373 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
374 | } never executed: end of block | 0 | ||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||
376 | int QListView::spacing() const | - | ||||||||||||||||||||||||
377 | { | - | ||||||||||||||||||||||||
378 | Q_D(const QListView); | - | ||||||||||||||||||||||||
379 | return d->spacing(); never executed: return d->spacing(); | 0 | ||||||||||||||||||||||||
380 | } | - | ||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||
382 | /*! | - | ||||||||||||||||||||||||
383 | \property QListView::batchSize | - | ||||||||||||||||||||||||
384 | \brief the number of items laid out in each batch if \l layoutMode is | - | ||||||||||||||||||||||||
385 | set to \l Batched | - | ||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||
387 | The default value is 100. | - | ||||||||||||||||||||||||
388 | - | |||||||||||||||||||||||||
389 | \since 4.2 | - | ||||||||||||||||||||||||
390 | */ | - | ||||||||||||||||||||||||
391 | - | |||||||||||||||||||||||||
392 | void QListView::setBatchSize(int batchSize) | - | ||||||||||||||||||||||||
393 | { | - | ||||||||||||||||||||||||
394 | Q_D(QListView); | - | ||||||||||||||||||||||||
395 | if (batchSize <= 0) {
| 0 | ||||||||||||||||||||||||
396 | qWarning("Invalid batchSize (%d)", batchSize); | - | ||||||||||||||||||||||||
397 | return; never executed: return; | 0 | ||||||||||||||||||||||||
398 | } | - | ||||||||||||||||||||||||
399 | d->batchSize = batchSize; | - | ||||||||||||||||||||||||
400 | } never executed: end of block | 0 | ||||||||||||||||||||||||
401 | - | |||||||||||||||||||||||||
402 | int QListView::batchSize() const | - | ||||||||||||||||||||||||
403 | { | - | ||||||||||||||||||||||||
404 | Q_D(const QListView); | - | ||||||||||||||||||||||||
405 | return d->batchSize; never executed: return d->batchSize; | 0 | ||||||||||||||||||||||||
406 | } | - | ||||||||||||||||||||||||
407 | - | |||||||||||||||||||||||||
408 | /*! | - | ||||||||||||||||||||||||
409 | \property QListView::gridSize | - | ||||||||||||||||||||||||
410 | \brief the size of the layout grid | - | ||||||||||||||||||||||||
411 | - | |||||||||||||||||||||||||
412 | This property is the size of the grid in which the items are laid | - | ||||||||||||||||||||||||
413 | out. The default is an empty size which means that there is no | - | ||||||||||||||||||||||||
414 | grid and the layout is not done in a grid. Setting this property | - | ||||||||||||||||||||||||
415 | to a non-empty size switches on the grid layout. (When a grid | - | ||||||||||||||||||||||||
416 | layout is in force the \l spacing property is ignored.) | - | ||||||||||||||||||||||||
417 | - | |||||||||||||||||||||||||
418 | Setting this property when the view is visible will cause the | - | ||||||||||||||||||||||||
419 | items to be laid out again. | - | ||||||||||||||||||||||||
420 | - | |||||||||||||||||||||||||
421 | \sa viewMode | - | ||||||||||||||||||||||||
422 | */ | - | ||||||||||||||||||||||||
423 | void QListView::setGridSize(const QSize &size) | - | ||||||||||||||||||||||||
424 | { | - | ||||||||||||||||||||||||
425 | Q_D(QListView); | - | ||||||||||||||||||||||||
426 | d->modeProperties |= uint(QListViewPrivate::GridSize); | - | ||||||||||||||||||||||||
427 | d->setGridSize(size); | - | ||||||||||||||||||||||||
428 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
429 | } never executed: end of block | 0 | ||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||
431 | QSize QListView::gridSize() const | - | ||||||||||||||||||||||||
432 | { | - | ||||||||||||||||||||||||
433 | Q_D(const QListView); | - | ||||||||||||||||||||||||
434 | return d->gridSize(); never executed: return d->gridSize(); | 0 | ||||||||||||||||||||||||
435 | } | - | ||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||
437 | /*! | - | ||||||||||||||||||||||||
438 | \property QListView::viewMode | - | ||||||||||||||||||||||||
439 | \brief the view mode of the QListView. | - | ||||||||||||||||||||||||
440 | - | |||||||||||||||||||||||||
441 | This property will change the other unset properties to conform | - | ||||||||||||||||||||||||
442 | with the set view mode. QListView-specific properties that have already been set | - | ||||||||||||||||||||||||
443 | will not be changed, unless clearPropertyFlags() has been called. | - | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | Setting the view mode will enable or disable drag and drop based on the | - | ||||||||||||||||||||||||
446 | selected movement. For ListMode, the default movement is \l Static | - | ||||||||||||||||||||||||
447 | (drag and drop disabled); for IconMode, the default movement is | - | ||||||||||||||||||||||||
448 | \l Free (drag and drop enabled). | - | ||||||||||||||||||||||||
449 | - | |||||||||||||||||||||||||
450 | \sa isWrapping, spacing, gridSize, flow, movement, resizeMode | - | ||||||||||||||||||||||||
451 | */ | - | ||||||||||||||||||||||||
452 | void QListView::setViewMode(ViewMode mode) | - | ||||||||||||||||||||||||
453 | { | - | ||||||||||||||||||||||||
454 | Q_D(QListView); | - | ||||||||||||||||||||||||
455 | if (d->commonListView && d->viewMode == mode)
| 0 | ||||||||||||||||||||||||
456 | return; never executed: return; | 0 | ||||||||||||||||||||||||
457 | d->viewMode = mode; | - | ||||||||||||||||||||||||
458 | - | |||||||||||||||||||||||||
459 | delete d->commonListView; | - | ||||||||||||||||||||||||
460 | if (mode == ListMode) {
| 0 | ||||||||||||||||||||||||
461 | d->commonListView = new QListModeViewBase(this, d); | - | ||||||||||||||||||||||||
462 | if (!(d->modeProperties & QListViewPrivate::Wrap))
| 0 | ||||||||||||||||||||||||
463 | d->setWrapping(false); never executed: d->setWrapping(false); | 0 | ||||||||||||||||||||||||
464 | if (!(d->modeProperties & QListViewPrivate::Spacing))
| 0 | ||||||||||||||||||||||||
465 | d->setSpacing(0); never executed: d->setSpacing(0); | 0 | ||||||||||||||||||||||||
466 | if (!(d->modeProperties & QListViewPrivate::GridSize))
| 0 | ||||||||||||||||||||||||
467 | d->setGridSize(QSize()); never executed: d->setGridSize(QSize()); | 0 | ||||||||||||||||||||||||
468 | if (!(d->modeProperties & QListViewPrivate::Flow))
| 0 | ||||||||||||||||||||||||
469 | d->flow = TopToBottom; never executed: d->flow = TopToBottom; | 0 | ||||||||||||||||||||||||
470 | if (!(d->modeProperties & QListViewPrivate::Movement))
| 0 | ||||||||||||||||||||||||
471 | d->movement = Static; never executed: d->movement = Static; | 0 | ||||||||||||||||||||||||
472 | if (!(d->modeProperties & QListViewPrivate::ResizeMode))
| 0 | ||||||||||||||||||||||||
473 | d->resizeMode = Fixed; never executed: d->resizeMode = Fixed; | 0 | ||||||||||||||||||||||||
474 | if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible))
| 0 | ||||||||||||||||||||||||
475 | d->showElasticBand = false; never executed: d->showElasticBand = false; | 0 | ||||||||||||||||||||||||
476 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
477 | d->commonListView = new QIconModeViewBase(this, d); | - | ||||||||||||||||||||||||
478 | if (!(d->modeProperties & QListViewPrivate::Wrap))
| 0 | ||||||||||||||||||||||||
479 | d->setWrapping(true); never executed: d->setWrapping(true); | 0 | ||||||||||||||||||||||||
480 | if (!(d->modeProperties & QListViewPrivate::Spacing))
| 0 | ||||||||||||||||||||||||
481 | d->setSpacing(0); never executed: d->setSpacing(0); | 0 | ||||||||||||||||||||||||
482 | if (!(d->modeProperties & QListViewPrivate::GridSize))
| 0 | ||||||||||||||||||||||||
483 | d->setGridSize(QSize()); never executed: d->setGridSize(QSize()); | 0 | ||||||||||||||||||||||||
484 | if (!(d->modeProperties & QListViewPrivate::Flow))
| 0 | ||||||||||||||||||||||||
485 | d->flow = LeftToRight; never executed: d->flow = LeftToRight; | 0 | ||||||||||||||||||||||||
486 | if (!(d->modeProperties & QListViewPrivate::Movement))
| 0 | ||||||||||||||||||||||||
487 | d->movement = Free; never executed: d->movement = Free; | 0 | ||||||||||||||||||||||||
488 | if (!(d->modeProperties & QListViewPrivate::ResizeMode))
| 0 | ||||||||||||||||||||||||
489 | d->resizeMode = Fixed; never executed: d->resizeMode = Fixed; | 0 | ||||||||||||||||||||||||
490 | if (!(d->modeProperties & QListViewPrivate::SelectionRectVisible))
| 0 | ||||||||||||||||||||||||
491 | d->showElasticBand = true; never executed: d->showElasticBand = true; | 0 | ||||||||||||||||||||||||
492 | } never executed: end of block | 0 | ||||||||||||||||||||||||
493 | - | |||||||||||||||||||||||||
494 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
495 | bool movable = (d->movement != Static); | - | ||||||||||||||||||||||||
496 | setDragEnabled(movable); | - | ||||||||||||||||||||||||
497 | setAcceptDrops(movable); | - | ||||||||||||||||||||||||
498 | #endif | - | ||||||||||||||||||||||||
499 | d->clear(); | - | ||||||||||||||||||||||||
500 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
501 | } never executed: end of block | 0 | ||||||||||||||||||||||||
502 | - | |||||||||||||||||||||||||
503 | QListView::ViewMode QListView::viewMode() const | - | ||||||||||||||||||||||||
504 | { | - | ||||||||||||||||||||||||
505 | Q_D(const QListView); | - | ||||||||||||||||||||||||
506 | return d->viewMode; never executed: return d->viewMode; | 0 | ||||||||||||||||||||||||
507 | } | - | ||||||||||||||||||||||||
508 | - | |||||||||||||||||||||||||
509 | /*! | - | ||||||||||||||||||||||||
510 | Clears the QListView-specific property flags. See \l{viewMode}. | - | ||||||||||||||||||||||||
511 | - | |||||||||||||||||||||||||
512 | Properties inherited from QAbstractItemView are not covered by the | - | ||||||||||||||||||||||||
513 | property flags. Specifically, \l{QAbstractItemView::dragEnabled} | - | ||||||||||||||||||||||||
514 | {dragEnabled} and \l{QAbstractItemView::acceptDrops} | - | ||||||||||||||||||||||||
515 | {acceptsDrops} are computed by QListView when calling | - | ||||||||||||||||||||||||
516 | setMovement() or setViewMode(). | - | ||||||||||||||||||||||||
517 | */ | - | ||||||||||||||||||||||||
518 | void QListView::clearPropertyFlags() | - | ||||||||||||||||||||||||
519 | { | - | ||||||||||||||||||||||||
520 | Q_D(QListView); | - | ||||||||||||||||||||||||
521 | d->modeProperties = 0; | - | ||||||||||||||||||||||||
522 | } never executed: end of block | 0 | ||||||||||||||||||||||||
523 | - | |||||||||||||||||||||||||
524 | /*! | - | ||||||||||||||||||||||||
525 | Returns \c true if the \a row is hidden; otherwise returns \c false. | - | ||||||||||||||||||||||||
526 | */ | - | ||||||||||||||||||||||||
527 | bool QListView::isRowHidden(int row) const | - | ||||||||||||||||||||||||
528 | { | - | ||||||||||||||||||||||||
529 | Q_D(const QListView); | - | ||||||||||||||||||||||||
530 | return d->isHidden(row); never executed: return d->isHidden(row); | 0 | ||||||||||||||||||||||||
531 | } | - | ||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||
533 | /*! | - | ||||||||||||||||||||||||
534 | If \a hide is true, the given \a row will be hidden; otherwise | - | ||||||||||||||||||||||||
535 | the \a row will be shown. | - | ||||||||||||||||||||||||
536 | */ | - | ||||||||||||||||||||||||
537 | void QListView::setRowHidden(int row, bool hide) | - | ||||||||||||||||||||||||
538 | { | - | ||||||||||||||||||||||||
539 | Q_D(QListView); | - | ||||||||||||||||||||||||
540 | const bool hidden = d->isHidden(row); | - | ||||||||||||||||||||||||
541 | if (hide && !hidden)
| 0 | ||||||||||||||||||||||||
542 | d->commonListView->appendHiddenRow(row); never executed: d->commonListView->appendHiddenRow(row); | 0 | ||||||||||||||||||||||||
543 | else if (!hide && hidden)
| 0 | ||||||||||||||||||||||||
544 | d->commonListView->removeHiddenRow(row); never executed: d->commonListView->removeHiddenRow(row); | 0 | ||||||||||||||||||||||||
545 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
546 | d->viewport->update(); | - | ||||||||||||||||||||||||
547 | } never executed: end of block | 0 | ||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||
549 | /*! | - | ||||||||||||||||||||||||
550 | \reimp | - | ||||||||||||||||||||||||
551 | */ | - | ||||||||||||||||||||||||
552 | QRect QListView::visualRect(const QModelIndex &index) const | - | ||||||||||||||||||||||||
553 | { | - | ||||||||||||||||||||||||
554 | Q_D(const QListView); | - | ||||||||||||||||||||||||
555 | return d->mapToViewport(rectForIndex(index)); never executed: return d->mapToViewport(rectForIndex(index)); | 0 | ||||||||||||||||||||||||
556 | } | - | ||||||||||||||||||||||||
557 | - | |||||||||||||||||||||||||
558 | /*! | - | ||||||||||||||||||||||||
559 | \reimp | - | ||||||||||||||||||||||||
560 | */ | - | ||||||||||||||||||||||||
561 | void QListView::scrollTo(const QModelIndex &index, ScrollHint hint) | - | ||||||||||||||||||||||||
562 | { | - | ||||||||||||||||||||||||
563 | Q_D(QListView); | - | ||||||||||||||||||||||||
564 | - | |||||||||||||||||||||||||
565 | if (index.parent() != d->root || index.column() != d->column)
| 0 | ||||||||||||||||||||||||
566 | return; never executed: return; | 0 | ||||||||||||||||||||||||
567 | - | |||||||||||||||||||||||||
568 | const QRect rect = visualRect(index); | - | ||||||||||||||||||||||||
569 | if (hint == EnsureVisible && d->viewport->rect().contains(rect)) {
| 0 | ||||||||||||||||||||||||
570 | d->viewport->update(rect); | - | ||||||||||||||||||||||||
571 | return; never executed: return; | 0 | ||||||||||||||||||||||||
572 | } | - | ||||||||||||||||||||||||
573 | - | |||||||||||||||||||||||||
574 | if (d->flow == QListView::TopToBottom || d->isWrapping()) // vertical
| 0 | ||||||||||||||||||||||||
575 | verticalScrollBar()->setValue(d->verticalScrollToValue(index, rect, hint)); never executed: verticalScrollBar()->setValue(d->verticalScrollToValue(index, rect, hint)); | 0 | ||||||||||||||||||||||||
576 | - | |||||||||||||||||||||||||
577 | if (d->flow == QListView::LeftToRight || d->isWrapping()) // horizontal
| 0 | ||||||||||||||||||||||||
578 | horizontalScrollBar()->setValue(d->horizontalScrollToValue(index, rect, hint)); never executed: horizontalScrollBar()->setValue(d->horizontalScrollToValue(index, rect, hint)); | 0 | ||||||||||||||||||||||||
579 | } never executed: end of block | 0 | ||||||||||||||||||||||||
580 | - | |||||||||||||||||||||||||
581 | int QListViewPrivate::horizontalScrollToValue(const QModelIndex &index, const QRect &rect, | - | ||||||||||||||||||||||||
582 | QListView::ScrollHint hint) const | - | ||||||||||||||||||||||||
583 | { | - | ||||||||||||||||||||||||
584 | Q_Q(const QListView); | - | ||||||||||||||||||||||||
585 | const QRect area = viewport->rect(); | - | ||||||||||||||||||||||||
586 | const bool leftOf = q->isRightToLeft()
| 0 | ||||||||||||||||||||||||
587 | ? (rect.left() < area.left()) && (rect.right() < area.right())
| 0 | ||||||||||||||||||||||||
588 | : rect.left() < area.left(); | - | ||||||||||||||||||||||||
589 | const bool rightOf = q->isRightToLeft()
| 0 | ||||||||||||||||||||||||
590 | ? rect.right() > area.right() | - | ||||||||||||||||||||||||
591 | : (rect.right() > area.right()) && (rect.left() > area.left());
| 0 | ||||||||||||||||||||||||
592 | return commonListView->horizontalScrollToValue(q->visualIndex(index), hint, leftOf, rightOf, area, rect); never executed: return commonListView->horizontalScrollToValue(q->visualIndex(index), hint, leftOf, rightOf, area, rect); | 0 | ||||||||||||||||||||||||
593 | } | - | ||||||||||||||||||||||||
594 | - | |||||||||||||||||||||||||
595 | int QListViewPrivate::verticalScrollToValue(const QModelIndex &index, const QRect &rect, | - | ||||||||||||||||||||||||
596 | QListView::ScrollHint hint) const | - | ||||||||||||||||||||||||
597 | { | - | ||||||||||||||||||||||||
598 | Q_Q(const QListView); | - | ||||||||||||||||||||||||
599 | const QRect area = viewport->rect(); | - | ||||||||||||||||||||||||
600 | const bool above = (hint == QListView::EnsureVisible && rect.top() < area.top());
| 0 | ||||||||||||||||||||||||
601 | const bool below = (hint == QListView::EnsureVisible && rect.bottom() > area.bottom());
| 0 | ||||||||||||||||||||||||
602 | return commonListView->verticalScrollToValue(q->visualIndex(index), hint, above, below, area, rect); never executed: return commonListView->verticalScrollToValue(q->visualIndex(index), hint, above, below, area, rect); | 0 | ||||||||||||||||||||||||
603 | } | - | ||||||||||||||||||||||||
604 | - | |||||||||||||||||||||||||
605 | void QListViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command) | - | ||||||||||||||||||||||||
606 | { | - | ||||||||||||||||||||||||
607 | if (!selectionModel)
| 0 | ||||||||||||||||||||||||
608 | return; never executed: return; | 0 | ||||||||||||||||||||||||
609 | - | |||||||||||||||||||||||||
610 | QItemSelection selection; | - | ||||||||||||||||||||||||
611 | QModelIndex topLeft; | - | ||||||||||||||||||||||||
612 | int row = 0; | - | ||||||||||||||||||||||||
613 | const int colCount = model->columnCount(root); | - | ||||||||||||||||||||||||
614 | for(; row < model->rowCount(root); ++row) {
| 0 | ||||||||||||||||||||||||
615 | if (isHidden(row)) {
| 0 | ||||||||||||||||||||||||
616 | //it might be the end of a selection range | - | ||||||||||||||||||||||||
617 | if (topLeft.isValid()) {
| 0 | ||||||||||||||||||||||||
618 | QModelIndex bottomRight = model->index(row - 1, colCount - 1, root); | - | ||||||||||||||||||||||||
619 | selection.append(QItemSelectionRange(topLeft, bottomRight)); | - | ||||||||||||||||||||||||
620 | topLeft = QModelIndex(); | - | ||||||||||||||||||||||||
621 | } never executed: end of block | 0 | ||||||||||||||||||||||||
622 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
623 | } | - | ||||||||||||||||||||||||
624 | - | |||||||||||||||||||||||||
625 | if (!topLeft.isValid()) //start of a new selection range
| 0 | ||||||||||||||||||||||||
626 | topLeft = model->index(row, 0, root); never executed: topLeft = model->index(row, 0, root); | 0 | ||||||||||||||||||||||||
627 | } never executed: end of block | 0 | ||||||||||||||||||||||||
628 | - | |||||||||||||||||||||||||
629 | if (topLeft.isValid()) {
| 0 | ||||||||||||||||||||||||
630 | //last selected range | - | ||||||||||||||||||||||||
631 | QModelIndex bottomRight = model->index(row - 1, colCount - 1, root); | - | ||||||||||||||||||||||||
632 | selection.append(QItemSelectionRange(topLeft, bottomRight)); | - | ||||||||||||||||||||||||
633 | } never executed: end of block | 0 | ||||||||||||||||||||||||
634 | - | |||||||||||||||||||||||||
635 | if (!selection.isEmpty())
| 0 | ||||||||||||||||||||||||
636 | selectionModel->select(selection, command); never executed: selectionModel->select(selection, command); | 0 | ||||||||||||||||||||||||
637 | } never executed: end of block | 0 | ||||||||||||||||||||||||
638 | - | |||||||||||||||||||||||||
639 | /*! | - | ||||||||||||||||||||||||
640 | \reimp | - | ||||||||||||||||||||||||
641 | - | |||||||||||||||||||||||||
642 | We have a QListView way of knowing what elements are on the viewport | - | ||||||||||||||||||||||||
643 | through the intersectingSet function | - | ||||||||||||||||||||||||
644 | */ | - | ||||||||||||||||||||||||
645 | QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const | - | ||||||||||||||||||||||||
646 | { | - | ||||||||||||||||||||||||
647 | Q_ASSERT(r); | - | ||||||||||||||||||||||||
648 | Q_Q(const QListView); | - | ||||||||||||||||||||||||
649 | QRect &rect = *r; | - | ||||||||||||||||||||||||
650 | const QRect viewportRect = viewport->rect(); | - | ||||||||||||||||||||||||
651 | QItemViewPaintPairs ret; | - | ||||||||||||||||||||||||
652 | const QSet<QModelIndex> visibleIndexes = intersectingSet(viewportRect.translated(q->horizontalOffset(), q->verticalOffset())).toList().toSet(); | - | ||||||||||||||||||||||||
653 | for (int i = 0; i < indexes.count(); ++i) {
| 0 | ||||||||||||||||||||||||
654 | const QModelIndex &index = indexes.at(i); | - | ||||||||||||||||||||||||
655 | if (visibleIndexes.contains(index)) {
| 0 | ||||||||||||||||||||||||
656 | const QRect current = q->visualRect(index); | - | ||||||||||||||||||||||||
657 | ret += qMakePair(current, index); | - | ||||||||||||||||||||||||
658 | rect |= current; | - | ||||||||||||||||||||||||
659 | } never executed: end of block | 0 | ||||||||||||||||||||||||
660 | } never executed: end of block | 0 | ||||||||||||||||||||||||
661 | rect &= viewportRect; | - | ||||||||||||||||||||||||
662 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
663 | } | - | ||||||||||||||||||||||||
664 | - | |||||||||||||||||||||||||
665 | /*! | - | ||||||||||||||||||||||||
666 | \internal | - | ||||||||||||||||||||||||
667 | */ | - | ||||||||||||||||||||||||
668 | void QListView::reset() | - | ||||||||||||||||||||||||
669 | { | - | ||||||||||||||||||||||||
670 | Q_D(QListView); | - | ||||||||||||||||||||||||
671 | d->clear(); | - | ||||||||||||||||||||||||
672 | d->hiddenRows.clear(); | - | ||||||||||||||||||||||||
673 | QAbstractItemView::reset(); | - | ||||||||||||||||||||||||
674 | } never executed: end of block | 0 | ||||||||||||||||||||||||
675 | - | |||||||||||||||||||||||||
676 | /*! | - | ||||||||||||||||||||||||
677 | \internal | - | ||||||||||||||||||||||||
678 | */ | - | ||||||||||||||||||||||||
679 | void QListView::setRootIndex(const QModelIndex &index) | - | ||||||||||||||||||||||||
680 | { | - | ||||||||||||||||||||||||
681 | Q_D(QListView); | - | ||||||||||||||||||||||||
682 | d->column = qBound(0, d->column, d->model->columnCount(index) - 1); | - | ||||||||||||||||||||||||
683 | QAbstractItemView::setRootIndex(index); | - | ||||||||||||||||||||||||
684 | // sometimes we get an update before reset() is called | - | ||||||||||||||||||||||||
685 | d->clear(); | - | ||||||||||||||||||||||||
686 | d->hiddenRows.clear(); | - | ||||||||||||||||||||||||
687 | } never executed: end of block | 0 | ||||||||||||||||||||||||
688 | - | |||||||||||||||||||||||||
689 | /*! | - | ||||||||||||||||||||||||
690 | \internal | - | ||||||||||||||||||||||||
691 | - | |||||||||||||||||||||||||
692 | Scroll the view contents by \a dx and \a dy. | - | ||||||||||||||||||||||||
693 | */ | - | ||||||||||||||||||||||||
694 | - | |||||||||||||||||||||||||
695 | void QListView::scrollContentsBy(int dx, int dy) | - | ||||||||||||||||||||||||
696 | { | - | ||||||||||||||||||||||||
697 | Q_D(QListView); | - | ||||||||||||||||||||||||
698 | d->delayedAutoScroll.stop(); // auto scroll was canceled by the user scrolling | - | ||||||||||||||||||||||||
699 | d->commonListView->scrollContentsBy(dx, dy, d->state == QListView::DragSelectingState); | - | ||||||||||||||||||||||||
700 | } never executed: end of block | 0 | ||||||||||||||||||||||||
701 | - | |||||||||||||||||||||||||
702 | /*! | - | ||||||||||||||||||||||||
703 | \internal | - | ||||||||||||||||||||||||
704 | - | |||||||||||||||||||||||||
705 | Resize the internal contents to \a width and \a height and set the | - | ||||||||||||||||||||||||
706 | scroll bar ranges accordingly. | - | ||||||||||||||||||||||||
707 | */ | - | ||||||||||||||||||||||||
708 | void QListView::resizeContents(int width, int height) | - | ||||||||||||||||||||||||
709 | { | - | ||||||||||||||||||||||||
710 | Q_D(QListView); | - | ||||||||||||||||||||||||
711 | d->setContentsSize(width, height); | - | ||||||||||||||||||||||||
712 | } never executed: end of block | 0 | ||||||||||||||||||||||||
713 | - | |||||||||||||||||||||||||
714 | /*! | - | ||||||||||||||||||||||||
715 | \internal | - | ||||||||||||||||||||||||
716 | */ | - | ||||||||||||||||||||||||
717 | QSize QListView::contentsSize() const | - | ||||||||||||||||||||||||
718 | { | - | ||||||||||||||||||||||||
719 | Q_D(const QListView); | - | ||||||||||||||||||||||||
720 | return d->contentsSize(); never executed: return d->contentsSize(); | 0 | ||||||||||||||||||||||||
721 | } | - | ||||||||||||||||||||||||
722 | - | |||||||||||||||||||||||||
723 | /*! | - | ||||||||||||||||||||||||
724 | \reimp | - | ||||||||||||||||||||||||
725 | */ | - | ||||||||||||||||||||||||
726 | void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) | - | ||||||||||||||||||||||||
727 | { | - | ||||||||||||||||||||||||
728 | d_func()->commonListView->dataChanged(topLeft, bottomRight); | - | ||||||||||||||||||||||||
729 | QAbstractItemView::dataChanged(topLeft, bottomRight, roles); | - | ||||||||||||||||||||||||
730 | } never executed: end of block | 0 | ||||||||||||||||||||||||
731 | - | |||||||||||||||||||||||||
732 | /*! | - | ||||||||||||||||||||||||
733 | \reimp | - | ||||||||||||||||||||||||
734 | */ | - | ||||||||||||||||||||||||
735 | void QListView::rowsInserted(const QModelIndex &parent, int start, int end) | - | ||||||||||||||||||||||||
736 | { | - | ||||||||||||||||||||||||
737 | Q_D(QListView); | - | ||||||||||||||||||||||||
738 | // ### be smarter about inserted items | - | ||||||||||||||||||||||||
739 | d->clear(); | - | ||||||||||||||||||||||||
740 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
741 | QAbstractItemView::rowsInserted(parent, start, end); | - | ||||||||||||||||||||||||
742 | } never executed: end of block | 0 | ||||||||||||||||||||||||
743 | - | |||||||||||||||||||||||||
744 | /*! | - | ||||||||||||||||||||||||
745 | \reimp | - | ||||||||||||||||||||||||
746 | */ | - | ||||||||||||||||||||||||
747 | void QListView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) | - | ||||||||||||||||||||||||
748 | { | - | ||||||||||||||||||||||||
749 | Q_D(QListView); | - | ||||||||||||||||||||||||
750 | // if the parent is above d->root in the tree, nothing will happen | - | ||||||||||||||||||||||||
751 | QAbstractItemView::rowsAboutToBeRemoved(parent, start, end); | - | ||||||||||||||||||||||||
752 | if (parent == d->root) {
| 0 | ||||||||||||||||||||||||
753 | QSet<QPersistentModelIndex>::iterator it = d->hiddenRows.begin(); | - | ||||||||||||||||||||||||
754 | while (it != d->hiddenRows.end()) {
| 0 | ||||||||||||||||||||||||
755 | int hiddenRow = it->row(); | - | ||||||||||||||||||||||||
756 | if (hiddenRow >= start && hiddenRow <= end) {
| 0 | ||||||||||||||||||||||||
757 | it = d->hiddenRows.erase(it); | - | ||||||||||||||||||||||||
758 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
759 | ++it; | - | ||||||||||||||||||||||||
760 | } never executed: end of block | 0 | ||||||||||||||||||||||||
761 | } | - | ||||||||||||||||||||||||
762 | } never executed: end of block | 0 | ||||||||||||||||||||||||
763 | d->clear(); | - | ||||||||||||||||||||||||
764 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
765 | } never executed: end of block | 0 | ||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | /*! | - | ||||||||||||||||||||||||
768 | \reimp | - | ||||||||||||||||||||||||
769 | */ | - | ||||||||||||||||||||||||
770 | void QListView::mouseMoveEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
771 | { | - | ||||||||||||||||||||||||
772 | if (!isVisible())
| 0 | ||||||||||||||||||||||||
773 | return; never executed: return; | 0 | ||||||||||||||||||||||||
774 | Q_D(QListView); | - | ||||||||||||||||||||||||
775 | QAbstractItemView::mouseMoveEvent(e); | - | ||||||||||||||||||||||||
776 | if (state() == DragSelectingState
| 0 | ||||||||||||||||||||||||
777 | && d->showElasticBand
| 0 | ||||||||||||||||||||||||
778 | && d->selectionMode != SingleSelection
| 0 | ||||||||||||||||||||||||
779 | && d->selectionMode != NoSelection) {
| 0 | ||||||||||||||||||||||||
780 | QRect rect(d->pressedPosition, e->pos() + QPoint(horizontalOffset(), verticalOffset())); | - | ||||||||||||||||||||||||
781 | rect = rect.normalized(); | - | ||||||||||||||||||||||||
782 | d->viewport->update(d->mapToViewport(rect.united(d->elasticBand))); | - | ||||||||||||||||||||||||
783 | d->elasticBand = rect; | - | ||||||||||||||||||||||||
784 | } never executed: end of block | 0 | ||||||||||||||||||||||||
785 | } never executed: end of block | 0 | ||||||||||||||||||||||||
786 | - | |||||||||||||||||||||||||
787 | /*! | - | ||||||||||||||||||||||||
788 | \reimp | - | ||||||||||||||||||||||||
789 | */ | - | ||||||||||||||||||||||||
790 | void QListView::mouseReleaseEvent(QMouseEvent *e) | - | ||||||||||||||||||||||||
791 | { | - | ||||||||||||||||||||||||
792 | Q_D(QListView); | - | ||||||||||||||||||||||||
793 | QAbstractItemView::mouseReleaseEvent(e); | - | ||||||||||||||||||||||||
794 | // #### move this implementation into a dynamic class | - | ||||||||||||||||||||||||
795 | if (d->showElasticBand && d->elasticBand.isValid()) {
| 0 | ||||||||||||||||||||||||
796 | d->viewport->update(d->mapToViewport(d->elasticBand)); | - | ||||||||||||||||||||||||
797 | d->elasticBand = QRect(); | - | ||||||||||||||||||||||||
798 | } never executed: end of block | 0 | ||||||||||||||||||||||||
799 | } never executed: end of block | 0 | ||||||||||||||||||||||||
800 | - | |||||||||||||||||||||||||
801 | #ifndef QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||
802 | /*! | - | ||||||||||||||||||||||||
803 | \reimp | - | ||||||||||||||||||||||||
804 | */ | - | ||||||||||||||||||||||||
805 | void QListView::wheelEvent(QWheelEvent *e) | - | ||||||||||||||||||||||||
806 | { | - | ||||||||||||||||||||||||
807 | Q_D(QListView); | - | ||||||||||||||||||||||||
808 | if (e->orientation() == Qt::Vertical) {
| 0 | ||||||||||||||||||||||||
809 | if (e->angleDelta().x() == 0
| 0 | ||||||||||||||||||||||||
810 | && ((d->flow == TopToBottom && d->wrap) || (d->flow == LeftToRight && !d->wrap))
| 0 | ||||||||||||||||||||||||
811 | && d->vbar->minimum() == 0 && d->vbar->maximum() == 0) {
| 0 | ||||||||||||||||||||||||
812 | QPoint pixelDelta(e->pixelDelta().y(), e->pixelDelta().x()); | - | ||||||||||||||||||||||||
813 | QPoint angleDelta(e->angleDelta().y(), e->angleDelta().x()); | - | ||||||||||||||||||||||||
814 | QWheelEvent hwe(e->pos(), e->globalPos(), pixelDelta, angleDelta, e->delta(), | - | ||||||||||||||||||||||||
815 | Qt::Horizontal, e->buttons(), e->modifiers(), e->phase(), e->source()); | - | ||||||||||||||||||||||||
816 | if (e->spontaneous())
| 0 | ||||||||||||||||||||||||
817 | qt_sendSpontaneousEvent(d->hbar, &hwe); never executed: qt_sendSpontaneousEvent(d->hbar, &hwe); | 0 | ||||||||||||||||||||||||
818 | else | - | ||||||||||||||||||||||||
819 | QApplication::sendEvent(d->hbar, &hwe); never executed: QApplication::sendEvent(d->hbar, &hwe); | 0 | ||||||||||||||||||||||||
820 | e->setAccepted(hwe.isAccepted()); | - | ||||||||||||||||||||||||
821 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
822 | QApplication::sendEvent(d->vbar, e); | - | ||||||||||||||||||||||||
823 | } never executed: end of block | 0 | ||||||||||||||||||||||||
824 | } else { | - | ||||||||||||||||||||||||
825 | QApplication::sendEvent(d->hbar, e); | - | ||||||||||||||||||||||||
826 | } never executed: end of block | 0 | ||||||||||||||||||||||||
827 | } | - | ||||||||||||||||||||||||
828 | #endif // QT_NO_WHEELEVENT | - | ||||||||||||||||||||||||
829 | - | |||||||||||||||||||||||||
830 | /*! | - | ||||||||||||||||||||||||
831 | \reimp | - | ||||||||||||||||||||||||
832 | */ | - | ||||||||||||||||||||||||
833 | void QListView::timerEvent(QTimerEvent *e) | - | ||||||||||||||||||||||||
834 | { | - | ||||||||||||||||||||||||
835 | Q_D(QListView); | - | ||||||||||||||||||||||||
836 | if (e->timerId() == d->batchLayoutTimer.timerId()) {
| 0 | ||||||||||||||||||||||||
837 | if (d->doItemsLayout(d->batchSize)) { // layout is done
| 0 | ||||||||||||||||||||||||
838 | d->batchLayoutTimer.stop(); | - | ||||||||||||||||||||||||
839 | updateGeometries(); | - | ||||||||||||||||||||||||
840 | d->viewport->update(); | - | ||||||||||||||||||||||||
841 | } never executed: end of block | 0 | ||||||||||||||||||||||||
842 | } never executed: end of block | 0 | ||||||||||||||||||||||||
843 | QAbstractItemView::timerEvent(e); | - | ||||||||||||||||||||||||
844 | } never executed: end of block | 0 | ||||||||||||||||||||||||
845 | - | |||||||||||||||||||||||||
846 | /*! | - | ||||||||||||||||||||||||
847 | \reimp | - | ||||||||||||||||||||||||
848 | */ | - | ||||||||||||||||||||||||
849 | void QListView::resizeEvent(QResizeEvent *e) | - | ||||||||||||||||||||||||
850 | { | - | ||||||||||||||||||||||||
851 | Q_D(QListView); | - | ||||||||||||||||||||||||
852 | if (d->delayedPendingLayout)
| 0 | ||||||||||||||||||||||||
853 | return; never executed: return; | 0 | ||||||||||||||||||||||||
854 | - | |||||||||||||||||||||||||
855 | QSize delta = e->size() - e->oldSize(); | - | ||||||||||||||||||||||||
856 | - | |||||||||||||||||||||||||
857 | if (delta.isNull())
| 0 | ||||||||||||||||||||||||
858 | return; never executed: return; | 0 | ||||||||||||||||||||||||
859 | - | |||||||||||||||||||||||||
860 | bool listWrap = (d->viewMode == ListMode) && d->wrapItemText;
| 0 | ||||||||||||||||||||||||
861 | bool flowDimensionChanged = (d->flow == LeftToRight && delta.width() != 0)
| 0 | ||||||||||||||||||||||||
862 | || (d->flow == TopToBottom && delta.height() != 0);
| 0 | ||||||||||||||||||||||||
863 | - | |||||||||||||||||||||||||
864 | // We post a delayed relayout in the following cases : | - | ||||||||||||||||||||||||
865 | // - we're wrapping | - | ||||||||||||||||||||||||
866 | // - the state is NoState, we're adjusting and the size has changed in the flowing direction | - | ||||||||||||||||||||||||
867 | if (listWrap
| 0 | ||||||||||||||||||||||||
868 | || (state() == NoState && d->resizeMode == Adjust && flowDimensionChanged)) {
| 0 | ||||||||||||||||||||||||
869 | d->doDelayedItemsLayout(100); // wait 1/10 sec before starting the layout | - | ||||||||||||||||||||||||
870 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
871 | QAbstractItemView::resizeEvent(e); | - | ||||||||||||||||||||||||
872 | } never executed: end of block | 0 | ||||||||||||||||||||||||
873 | } | - | ||||||||||||||||||||||||
874 | - | |||||||||||||||||||||||||
875 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
876 | - | |||||||||||||||||||||||||
877 | /*! | - | ||||||||||||||||||||||||
878 | \reimp | - | ||||||||||||||||||||||||
879 | */ | - | ||||||||||||||||||||||||
880 | void QListView::dragMoveEvent(QDragMoveEvent *e) | - | ||||||||||||||||||||||||
881 | { | - | ||||||||||||||||||||||||
882 | Q_D(QListView); | - | ||||||||||||||||||||||||
883 | if (!d->commonListView->filterDragMoveEvent(e)) {
| 0 | ||||||||||||||||||||||||
884 | if (viewMode() == QListView::ListMode && flow() == QListView::LeftToRight)
| 0 | ||||||||||||||||||||||||
885 | static_cast<QListModeViewBase *>(d->commonListView)->dragMoveEvent(e); never executed: static_cast<QListModeViewBase *>(d->commonListView)->dragMoveEvent(e); | 0 | ||||||||||||||||||||||||
886 | else | - | ||||||||||||||||||||||||
887 | QAbstractItemView::dragMoveEvent(e); never executed: QAbstractItemView::dragMoveEvent(e); | 0 | ||||||||||||||||||||||||
888 | } | - | ||||||||||||||||||||||||
889 | } never executed: end of block | 0 | ||||||||||||||||||||||||
890 | - | |||||||||||||||||||||||||
891 | - | |||||||||||||||||||||||||
892 | /*! | - | ||||||||||||||||||||||||
893 | \reimp | - | ||||||||||||||||||||||||
894 | */ | - | ||||||||||||||||||||||||
895 | void QListView::dragLeaveEvent(QDragLeaveEvent *e) | - | ||||||||||||||||||||||||
896 | { | - | ||||||||||||||||||||||||
897 | if (!d_func()->commonListView->filterDragLeaveEvent(e))
| 0 | ||||||||||||||||||||||||
898 | QAbstractItemView::dragLeaveEvent(e); never executed: QAbstractItemView::dragLeaveEvent(e); | 0 | ||||||||||||||||||||||||
899 | } never executed: end of block | 0 | ||||||||||||||||||||||||
900 | - | |||||||||||||||||||||||||
901 | /*! | - | ||||||||||||||||||||||||
902 | \reimp | - | ||||||||||||||||||||||||
903 | */ | - | ||||||||||||||||||||||||
904 | void QListView::dropEvent(QDropEvent *e) | - | ||||||||||||||||||||||||
905 | { | - | ||||||||||||||||||||||||
906 | if (!d_func()->commonListView->filterDropEvent(e))
| 0 | ||||||||||||||||||||||||
907 | QAbstractItemView::dropEvent(e); never executed: QAbstractItemView::dropEvent(e); | 0 | ||||||||||||||||||||||||
908 | } never executed: end of block | 0 | ||||||||||||||||||||||||
909 | - | |||||||||||||||||||||||||
910 | /*! | - | ||||||||||||||||||||||||
911 | \reimp | - | ||||||||||||||||||||||||
912 | */ | - | ||||||||||||||||||||||||
913 | void QListView::startDrag(Qt::DropActions supportedActions) | - | ||||||||||||||||||||||||
914 | { | - | ||||||||||||||||||||||||
915 | if (!d_func()->commonListView->filterStartDrag(supportedActions))
| 0 | ||||||||||||||||||||||||
916 | QAbstractItemView::startDrag(supportedActions); never executed: QAbstractItemView::startDrag(supportedActions); | 0 | ||||||||||||||||||||||||
917 | } never executed: end of block | 0 | ||||||||||||||||||||||||
918 | - | |||||||||||||||||||||||||
919 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
920 | - | |||||||||||||||||||||||||
921 | /*! | - | ||||||||||||||||||||||||
922 | \reimp | - | ||||||||||||||||||||||||
923 | */ | - | ||||||||||||||||||||||||
924 | QStyleOptionViewItem QListView::viewOptions() const | - | ||||||||||||||||||||||||
925 | { | - | ||||||||||||||||||||||||
926 | Q_D(const QListView); | - | ||||||||||||||||||||||||
927 | QStyleOptionViewItem option = QAbstractItemView::viewOptions(); | - | ||||||||||||||||||||||||
928 | if (!d->iconSize.isValid()) { // otherwise it was already set in abstractitemview
| 0 | ||||||||||||||||||||||||
929 | int pm = (d->viewMode == QListView::ListMode
| 0 | ||||||||||||||||||||||||
930 | ? style()->pixelMetric(QStyle::PM_ListViewIconSize, 0, this) | - | ||||||||||||||||||||||||
931 | : style()->pixelMetric(QStyle::PM_IconViewIconSize, 0, this)); | - | ||||||||||||||||||||||||
932 | option.decorationSize = QSize(pm, pm); | - | ||||||||||||||||||||||||
933 | } never executed: end of block | 0 | ||||||||||||||||||||||||
934 | if (d->viewMode == QListView::IconMode) {
| 0 | ||||||||||||||||||||||||
935 | option.showDecorationSelected = false; | - | ||||||||||||||||||||||||
936 | option.decorationPosition = QStyleOptionViewItem::Top; | - | ||||||||||||||||||||||||
937 | option.displayAlignment = Qt::AlignCenter; | - | ||||||||||||||||||||||||
938 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
939 | option.decorationPosition = QStyleOptionViewItem::Left; | - | ||||||||||||||||||||||||
940 | } never executed: end of block | 0 | ||||||||||||||||||||||||
941 | - | |||||||||||||||||||||||||
942 | if (d->gridSize().isValid()) {
| 0 | ||||||||||||||||||||||||
943 | option.rect.setSize(d->gridSize()); | - | ||||||||||||||||||||||||
944 | } never executed: end of block | 0 | ||||||||||||||||||||||||
945 | - | |||||||||||||||||||||||||
946 | return option; never executed: return option; | 0 | ||||||||||||||||||||||||
947 | } | - | ||||||||||||||||||||||||
948 | - | |||||||||||||||||||||||||
949 | - | |||||||||||||||||||||||||
950 | /*! | - | ||||||||||||||||||||||||
951 | \reimp | - | ||||||||||||||||||||||||
952 | */ | - | ||||||||||||||||||||||||
953 | void QListView::paintEvent(QPaintEvent *e) | - | ||||||||||||||||||||||||
954 | { | - | ||||||||||||||||||||||||
955 | Q_D(QListView); | - | ||||||||||||||||||||||||
956 | if (!d->itemDelegate)
| 0 | ||||||||||||||||||||||||
957 | return; never executed: return; | 0 | ||||||||||||||||||||||||
958 | QStyleOptionViewItem option = d->viewOptionsV1(); | - | ||||||||||||||||||||||||
959 | QPainter painter(d->viewport); | - | ||||||||||||||||||||||||
960 | - | |||||||||||||||||||||||||
961 | const QVector<QModelIndex> toBeRendered = d->intersectingSet(e->rect().translated(horizontalOffset(), verticalOffset()), false); | - | ||||||||||||||||||||||||
962 | - | |||||||||||||||||||||||||
963 | const QModelIndex current = currentIndex(); | - | ||||||||||||||||||||||||
964 | const QModelIndex hover = d->hover; | - | ||||||||||||||||||||||||
965 | const QAbstractItemModel *itemModel = d->model; | - | ||||||||||||||||||||||||
966 | const QItemSelectionModel *selections = d->selectionModel; | - | ||||||||||||||||||||||||
967 | const bool focus = (hasFocus() || d->viewport->hasFocus()) && current.isValid();
| 0 | ||||||||||||||||||||||||
968 | const bool alternate = d->alternatingColors; | - | ||||||||||||||||||||||||
969 | const QStyle::State state = option.state; | - | ||||||||||||||||||||||||
970 | const QAbstractItemView::State viewState = this->state(); | - | ||||||||||||||||||||||||
971 | const bool enabled = (state & QStyle::State_Enabled) != 0; | - | ||||||||||||||||||||||||
972 | - | |||||||||||||||||||||||||
973 | bool alternateBase = false; | - | ||||||||||||||||||||||||
974 | int previousRow = -2; // trigger the alternateBase adjustment on first pass | - | ||||||||||||||||||||||||
975 | - | |||||||||||||||||||||||||
976 | int maxSize = (flow() == TopToBottom)
| 0 | ||||||||||||||||||||||||
977 | ? qMax(viewport()->size().width(), d->contentsSize().width()) - 2 * d->spacing() | - | ||||||||||||||||||||||||
978 | : qMax(viewport()->size().height(), d->contentsSize().height()) - 2 * d->spacing(); | - | ||||||||||||||||||||||||
979 | - | |||||||||||||||||||||||||
980 | QVector<QModelIndex>::const_iterator end = toBeRendered.constEnd(); | - | ||||||||||||||||||||||||
981 | for (QVector<QModelIndex>::const_iterator it = toBeRendered.constBegin(); it != end; ++it) {
| 0 | ||||||||||||||||||||||||
982 | Q_ASSERT((*it).isValid()); | - | ||||||||||||||||||||||||
983 | option.rect = visualRect(*it); | - | ||||||||||||||||||||||||
984 | - | |||||||||||||||||||||||||
985 | if (flow() == TopToBottom)
| 0 | ||||||||||||||||||||||||
986 | option.rect.setWidth(qMin(maxSize, option.rect.width())); never executed: option.rect.setWidth(qMin(maxSize, option.rect.width())); | 0 | ||||||||||||||||||||||||
987 | else | - | ||||||||||||||||||||||||
988 | option.rect.setHeight(qMin(maxSize, option.rect.height())); never executed: option.rect.setHeight(qMin(maxSize, option.rect.height())); | 0 | ||||||||||||||||||||||||
989 | - | |||||||||||||||||||||||||
990 | option.state = state; | - | ||||||||||||||||||||||||
991 | if (selections && selections->isSelected(*it))
| 0 | ||||||||||||||||||||||||
992 | option.state |= QStyle::State_Selected; never executed: option.state |= QStyle::State_Selected; | 0 | ||||||||||||||||||||||||
993 | if (enabled) {
| 0 | ||||||||||||||||||||||||
994 | QPalette::ColorGroup cg; | - | ||||||||||||||||||||||||
995 | if ((itemModel->flags(*it) & Qt::ItemIsEnabled) == 0) {
| 0 | ||||||||||||||||||||||||
996 | option.state &= ~QStyle::State_Enabled; | - | ||||||||||||||||||||||||
997 | cg = QPalette::Disabled; | - | ||||||||||||||||||||||||
998 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
999 | cg = QPalette::Normal; | - | ||||||||||||||||||||||||
1000 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1001 | option.palette.setCurrentColorGroup(cg); | - | ||||||||||||||||||||||||
1002 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1003 | if (focus && current == *it) {
| 0 | ||||||||||||||||||||||||
1004 | option.state |= QStyle::State_HasFocus; | - | ||||||||||||||||||||||||
1005 | if (viewState == EditingState)
| 0 | ||||||||||||||||||||||||
1006 | option.state |= QStyle::State_Editing; never executed: option.state |= QStyle::State_Editing; | 0 | ||||||||||||||||||||||||
1007 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1008 | if (*it == hover)
| 0 | ||||||||||||||||||||||||
1009 | option.state |= QStyle::State_MouseOver; never executed: option.state |= QStyle::State_MouseOver; | 0 | ||||||||||||||||||||||||
1010 | else | - | ||||||||||||||||||||||||
1011 | option.state &= ~QStyle::State_MouseOver; never executed: option.state &= ~QStyle::State_MouseOver; | 0 | ||||||||||||||||||||||||
1012 | - | |||||||||||||||||||||||||
1013 | if (alternate) {
| 0 | ||||||||||||||||||||||||
1014 | int row = (*it).row(); | - | ||||||||||||||||||||||||
1015 | if (row != previousRow + 1) {
| 0 | ||||||||||||||||||||||||
1016 | // adjust alternateBase according to rows in the "gap" | - | ||||||||||||||||||||||||
1017 | if (!d->hiddenRows.isEmpty()) {
| 0 | ||||||||||||||||||||||||
1018 | for (int r = qMax(previousRow + 1, 0); r < row; ++r) {
| 0 | ||||||||||||||||||||||||
1019 | if (!d->isHidden(r))
| 0 | ||||||||||||||||||||||||
1020 | alternateBase = !alternateBase; never executed: alternateBase = !alternateBase; | 0 | ||||||||||||||||||||||||
1021 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1022 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1023 | alternateBase = (row & 1) != 0; | - | ||||||||||||||||||||||||
1024 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1025 | } | - | ||||||||||||||||||||||||
1026 | if (alternateBase) {
| 0 | ||||||||||||||||||||||||
1027 | option.features |= QStyleOptionViewItem::Alternate; | - | ||||||||||||||||||||||||
1028 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1029 | option.features &= ~QStyleOptionViewItem::Alternate; | - | ||||||||||||||||||||||||
1030 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1031 | - | |||||||||||||||||||||||||
1032 | // draw background of the item (only alternate row). rest of the background | - | ||||||||||||||||||||||||
1033 | // is provided by the delegate | - | ||||||||||||||||||||||||
1034 | QStyle::State oldState = option.state; | - | ||||||||||||||||||||||||
1035 | option.state &= ~QStyle::State_Selected; | - | ||||||||||||||||||||||||
1036 | style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &option, &painter, this); | - | ||||||||||||||||||||||||
1037 | option.state = oldState; | - | ||||||||||||||||||||||||
1038 | - | |||||||||||||||||||||||||
1039 | alternateBase = !alternateBase; | - | ||||||||||||||||||||||||
1040 | previousRow = row; | - | ||||||||||||||||||||||||
1041 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1042 | - | |||||||||||||||||||||||||
1043 | d->delegateForIndex(*it)->paint(&painter, option, *it); | - | ||||||||||||||||||||||||
1044 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1045 | - | |||||||||||||||||||||||||
1046 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
1047 | d->commonListView->paintDragDrop(&painter); | - | ||||||||||||||||||||||||
1048 | #endif | - | ||||||||||||||||||||||||
1049 | - | |||||||||||||||||||||||||
1050 | #ifndef QT_NO_RUBBERBAND | - | ||||||||||||||||||||||||
1051 | // #### move this implementation into a dynamic class | - | ||||||||||||||||||||||||
1052 | if (d->showElasticBand && d->elasticBand.isValid()) {
| 0 | ||||||||||||||||||||||||
1053 | QStyleOptionRubberBand opt; | - | ||||||||||||||||||||||||
1054 | opt.initFrom(this); | - | ||||||||||||||||||||||||
1055 | opt.shape = QRubberBand::Rectangle; | - | ||||||||||||||||||||||||
1056 | opt.opaque = false; | - | ||||||||||||||||||||||||
1057 | opt.rect = d->mapToViewport(d->elasticBand, false).intersected( | - | ||||||||||||||||||||||||
1058 | d->viewport->rect().adjusted(-16, -16, 16, 16)); | - | ||||||||||||||||||||||||
1059 | painter.save(); | - | ||||||||||||||||||||||||
1060 | style()->drawControl(QStyle::CE_RubberBand, &opt, &painter); | - | ||||||||||||||||||||||||
1061 | painter.restore(); | - | ||||||||||||||||||||||||
1062 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1063 | #endif | - | ||||||||||||||||||||||||
1064 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||
1066 | /*! | - | ||||||||||||||||||||||||
1067 | \reimp | - | ||||||||||||||||||||||||
1068 | */ | - | ||||||||||||||||||||||||
1069 | QModelIndex QListView::indexAt(const QPoint &p) const | - | ||||||||||||||||||||||||
1070 | { | - | ||||||||||||||||||||||||
1071 | Q_D(const QListView); | - | ||||||||||||||||||||||||
1072 | QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1); | - | ||||||||||||||||||||||||
1073 | const QVector<QModelIndex> intersectVector = d->intersectingSet(rect); | - | ||||||||||||||||||||||||
1074 | QModelIndex index = intersectVector.count() > 0
| 0 | ||||||||||||||||||||||||
1075 | ? intersectVector.last() : QModelIndex(); | - | ||||||||||||||||||||||||
1076 | if (index.isValid() && visualRect(index).contains(p))
| 0 | ||||||||||||||||||||||||
1077 | return index; never executed: return index; | 0 | ||||||||||||||||||||||||
1078 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
1079 | } | - | ||||||||||||||||||||||||
1080 | - | |||||||||||||||||||||||||
1081 | /*! | - | ||||||||||||||||||||||||
1082 | \reimp | - | ||||||||||||||||||||||||
1083 | */ | - | ||||||||||||||||||||||||
1084 | int QListView::horizontalOffset() const | - | ||||||||||||||||||||||||
1085 | { | - | ||||||||||||||||||||||||
1086 | return d_func()->commonListView->horizontalOffset(); never executed: return d_func()->commonListView->horizontalOffset(); | 0 | ||||||||||||||||||||||||
1087 | } | - | ||||||||||||||||||||||||
1088 | - | |||||||||||||||||||||||||
1089 | /*! | - | ||||||||||||||||||||||||
1090 | \reimp | - | ||||||||||||||||||||||||
1091 | */ | - | ||||||||||||||||||||||||
1092 | int QListView::verticalOffset() const | - | ||||||||||||||||||||||||
1093 | { | - | ||||||||||||||||||||||||
1094 | return d_func()->commonListView->verticalOffset(); never executed: return d_func()->commonListView->verticalOffset(); | 0 | ||||||||||||||||||||||||
1095 | } | - | ||||||||||||||||||||||||
1096 | - | |||||||||||||||||||||||||
1097 | /*! | - | ||||||||||||||||||||||||
1098 | \reimp | - | ||||||||||||||||||||||||
1099 | */ | - | ||||||||||||||||||||||||
1100 | QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) | - | ||||||||||||||||||||||||
1101 | { | - | ||||||||||||||||||||||||
1102 | Q_D(QListView); | - | ||||||||||||||||||||||||
1103 | Q_UNUSED(modifiers); | - | ||||||||||||||||||||||||
1104 | - | |||||||||||||||||||||||||
1105 | QModelIndex current = currentIndex(); | - | ||||||||||||||||||||||||
1106 | if (!current.isValid()) {
| 0 | ||||||||||||||||||||||||
1107 | int rowCount = d->model->rowCount(d->root); | - | ||||||||||||||||||||||||
1108 | if (!rowCount)
| 0 | ||||||||||||||||||||||||
1109 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
1110 | int row = 0; | - | ||||||||||||||||||||||||
1111 | while (row < rowCount && d->isHiddenOrDisabled(row))
| 0 | ||||||||||||||||||||||||
1112 | ++row; never executed: ++row; | 0 | ||||||||||||||||||||||||
1113 | if (row >= rowCount)
| 0 | ||||||||||||||||||||||||
1114 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
1115 | return d->model->index(row, d->column, d->root); never executed: return d->model->index(row, d->column, d->root); | 0 | ||||||||||||||||||||||||
1116 | } | - | ||||||||||||||||||||||||
1117 | - | |||||||||||||||||||||||||
1118 | const QRect initialRect = rectForIndex(current); | - | ||||||||||||||||||||||||
1119 | QRect rect = initialRect; | - | ||||||||||||||||||||||||
1120 | if (rect.isEmpty()) {
| 0 | ||||||||||||||||||||||||
1121 | return d->model->index(0, d->column, d->root); never executed: return d->model->index(0, d->column, d->root); | 0 | ||||||||||||||||||||||||
1122 | } | - | ||||||||||||||||||||||||
1123 | if (d->gridSize().isValid()) rect.setSize(d->gridSize()); never executed: rect.setSize(d->gridSize());
| 0 | ||||||||||||||||||||||||
1124 | - | |||||||||||||||||||||||||
1125 | QSize contents = d->contentsSize(); | - | ||||||||||||||||||||||||
1126 | QVector<QModelIndex> intersectVector; | - | ||||||||||||||||||||||||
1127 | - | |||||||||||||||||||||||||
1128 | switch (cursorAction) { | - | ||||||||||||||||||||||||
1129 | case MoveLeft: never executed: case MoveLeft: | 0 | ||||||||||||||||||||||||
1130 | while (intersectVector.isEmpty()) {
| 0 | ||||||||||||||||||||||||
1131 | rect.translate(-rect.width(), 0); | - | ||||||||||||||||||||||||
1132 | if (rect.right() <= 0)
| 0 | ||||||||||||||||||||||||
1133 | return current; never executed: return current; | 0 | ||||||||||||||||||||||||
1134 | if (rect.left() < 0)
| 0 | ||||||||||||||||||||||||
1135 | rect.setLeft(0); never executed: rect.setLeft(0); | 0 | ||||||||||||||||||||||||
1136 | intersectVector = d->intersectingSet(rect); | - | ||||||||||||||||||||||||
1137 | d->removeCurrentAndDisabled(&intersectVector, current); | - | ||||||||||||||||||||||||
1138 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1139 | return d->closestIndex(initialRect, intersectVector); never executed: return d->closestIndex(initialRect, intersectVector); | 0 | ||||||||||||||||||||||||
1140 | case MoveRight: never executed: case MoveRight: | 0 | ||||||||||||||||||||||||
1141 | while (intersectVector.isEmpty()) {
| 0 | ||||||||||||||||||||||||
1142 | rect.translate(rect.width(), 0); | - | ||||||||||||||||||||||||
1143 | if (rect.left() >= contents.width())
| 0 | ||||||||||||||||||||||||
1144 | return current; never executed: return current; | 0 | ||||||||||||||||||||||||
1145 | if (rect.right() > contents.width())
| 0 | ||||||||||||||||||||||||
1146 | rect.setRight(contents.width()); never executed: rect.setRight(contents.width()); | 0 | ||||||||||||||||||||||||
1147 | intersectVector = d->intersectingSet(rect); | - | ||||||||||||||||||||||||
1148 | d->removeCurrentAndDisabled(&intersectVector, current); | - | ||||||||||||||||||||||||
1149 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1150 | return d->closestIndex(initialRect, intersectVector); never executed: return d->closestIndex(initialRect, intersectVector); | 0 | ||||||||||||||||||||||||
1151 | case MovePageUp: never executed: case MovePageUp: | 0 | ||||||||||||||||||||||||
1152 | // move current by (visibileRowCount - 1) items. | - | ||||||||||||||||||||||||
1153 | // rect.translate(0, -rect.height()); will happen in the switch fallthrough for MoveUp. | - | ||||||||||||||||||||||||
1154 | rect.moveTop(rect.top() - d->viewport->height() + 2 * rect.height()); | - | ||||||||||||||||||||||||
1155 | if (rect.top() < rect.height())
| 0 | ||||||||||||||||||||||||
1156 | rect.moveTop(rect.height()); never executed: rect.moveTop(rect.height()); | 0 | ||||||||||||||||||||||||
1157 | case MovePrevious: code before this statement never executed: case MovePrevious: never executed: case MovePrevious: | 0 | ||||||||||||||||||||||||
1158 | case MoveUp: never executed: case MoveUp: | 0 | ||||||||||||||||||||||||
1159 | while (intersectVector.isEmpty()) {
| 0 | ||||||||||||||||||||||||
1160 | rect.translate(0, -rect.height()); | - | ||||||||||||||||||||||||
1161 | if (rect.bottom() <= 0) {
| 0 | ||||||||||||||||||||||||
1162 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
1163 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
1164 | int row = d->batchStartRow() - 1; | - | ||||||||||||||||||||||||
1165 | while (row >= 0 && d->isHiddenOrDisabled(row)) | - | ||||||||||||||||||||||||
1166 | --row; | - | ||||||||||||||||||||||||
1167 | if (row >= 0) | - | ||||||||||||||||||||||||
1168 | return d->model->index(row, d->column, d->root); | - | ||||||||||||||||||||||||
1169 | } | - | ||||||||||||||||||||||||
1170 | #endif | - | ||||||||||||||||||||||||
1171 | return current; never executed: return current; | 0 | ||||||||||||||||||||||||
1172 | } | - | ||||||||||||||||||||||||
1173 | if (rect.top() < 0)
| 0 | ||||||||||||||||||||||||
1174 | rect.setTop(0); never executed: rect.setTop(0); | 0 | ||||||||||||||||||||||||
1175 | intersectVector = d->intersectingSet(rect); | - | ||||||||||||||||||||||||
1176 | d->removeCurrentAndDisabled(&intersectVector, current); | - | ||||||||||||||||||||||||
1177 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1178 | return d->closestIndex(initialRect, intersectVector); never executed: return d->closestIndex(initialRect, intersectVector); | 0 | ||||||||||||||||||||||||
1179 | case MovePageDown: never executed: case MovePageDown: | 0 | ||||||||||||||||||||||||
1180 | // move current by (visibileRowCount - 1) items. | - | ||||||||||||||||||||||||
1181 | // rect.translate(0, rect.height()); will happen in the switch fallthrough for MoveDown. | - | ||||||||||||||||||||||||
1182 | rect.moveTop(rect.top() + d->viewport->height() - 2 * rect.height()); | - | ||||||||||||||||||||||||
1183 | if (rect.bottom() > contents.height() - rect.height())
| 0 | ||||||||||||||||||||||||
1184 | rect.moveBottom(contents.height() - rect.height()); never executed: rect.moveBottom(contents.height() - rect.height()); | 0 | ||||||||||||||||||||||||
1185 | case MoveNext: code before this statement never executed: case MoveNext: never executed: case MoveNext: | 0 | ||||||||||||||||||||||||
1186 | case MoveDown: never executed: case MoveDown: | 0 | ||||||||||||||||||||||||
1187 | while (intersectVector.isEmpty()) {
| 0 | ||||||||||||||||||||||||
1188 | rect.translate(0, rect.height()); | - | ||||||||||||||||||||||||
1189 | if (rect.top() >= contents.height()) {
| 0 | ||||||||||||||||||||||||
1190 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
1191 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
1192 | int rowCount = d->model->rowCount(d->root); | - | ||||||||||||||||||||||||
1193 | int row = 0; | - | ||||||||||||||||||||||||
1194 | while (row < rowCount && d->isHiddenOrDisabled(row)) | - | ||||||||||||||||||||||||
1195 | ++row; | - | ||||||||||||||||||||||||
1196 | if (row < rowCount) | - | ||||||||||||||||||||||||
1197 | return d->model->index(row, d->column, d->root); | - | ||||||||||||||||||||||||
1198 | } | - | ||||||||||||||||||||||||
1199 | #endif | - | ||||||||||||||||||||||||
1200 | return current; never executed: return current; | 0 | ||||||||||||||||||||||||
1201 | } | - | ||||||||||||||||||||||||
1202 | if (rect.bottom() > contents.height())
| 0 | ||||||||||||||||||||||||
1203 | rect.setBottom(contents.height()); never executed: rect.setBottom(contents.height()); | 0 | ||||||||||||||||||||||||
1204 | intersectVector = d->intersectingSet(rect); | - | ||||||||||||||||||||||||
1205 | d->removeCurrentAndDisabled(&intersectVector, current); | - | ||||||||||||||||||||||||
1206 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1207 | return d->closestIndex(initialRect, intersectVector); never executed: return d->closestIndex(initialRect, intersectVector); | 0 | ||||||||||||||||||||||||
1208 | case MoveHome: never executed: case MoveHome: | 0 | ||||||||||||||||||||||||
1209 | return d->model->index(0, d->column, d->root); never executed: return d->model->index(0, d->column, d->root); | 0 | ||||||||||||||||||||||||
1210 | case MoveEnd: never executed: case MoveEnd: | 0 | ||||||||||||||||||||||||
1211 | return d->model->index(d->batchStartRow() - 1, d->column, d->root);} never executed: return d->model->index(d->batchStartRow() - 1, d->column, d->root); | 0 | ||||||||||||||||||||||||
1212 | - | |||||||||||||||||||||||||
1213 | return current; never executed: return current; | 0 | ||||||||||||||||||||||||
1214 | } | - | ||||||||||||||||||||||||
1215 | - | |||||||||||||||||||||||||
1216 | /*! | - | ||||||||||||||||||||||||
1217 | Returns the rectangle of the item at position \a index in the | - | ||||||||||||||||||||||||
1218 | model. The rectangle is in contents coordinates. | - | ||||||||||||||||||||||||
1219 | - | |||||||||||||||||||||||||
1220 | \sa visualRect() | - | ||||||||||||||||||||||||
1221 | */ | - | ||||||||||||||||||||||||
1222 | QRect QListView::rectForIndex(const QModelIndex &index) const | - | ||||||||||||||||||||||||
1223 | { | - | ||||||||||||||||||||||||
1224 | return d_func()->rectForIndex(index); never executed: return d_func()->rectForIndex(index); | 0 | ||||||||||||||||||||||||
1225 | } | - | ||||||||||||||||||||||||
1226 | - | |||||||||||||||||||||||||
1227 | /*! | - | ||||||||||||||||||||||||
1228 | \since 4.1 | - | ||||||||||||||||||||||||
1229 | - | |||||||||||||||||||||||||
1230 | Sets the contents position of the item at \a index in the model to the given | - | ||||||||||||||||||||||||
1231 | \a position. | - | ||||||||||||||||||||||||
1232 | If the list view's movement mode is Static or its view mode is ListView, | - | ||||||||||||||||||||||||
1233 | this function will have no effect. | - | ||||||||||||||||||||||||
1234 | */ | - | ||||||||||||||||||||||||
1235 | void QListView::setPositionForIndex(const QPoint &position, const QModelIndex &index) | - | ||||||||||||||||||||||||
1236 | { | - | ||||||||||||||||||||||||
1237 | Q_D(QListView); | - | ||||||||||||||||||||||||
1238 | if (d->movement == Static
| 0 | ||||||||||||||||||||||||
1239 | || !d->isIndexValid(index)
| 0 | ||||||||||||||||||||||||
1240 | || index.parent() != d->root
| 0 | ||||||||||||||||||||||||
1241 | || index.column() != d->column)
| 0 | ||||||||||||||||||||||||
1242 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1243 | - | |||||||||||||||||||||||||
1244 | d->executePostedLayout(); | - | ||||||||||||||||||||||||
1245 | d->commonListView->setPositionForIndex(position, index); | - | ||||||||||||||||||||||||
1246 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1247 | - | |||||||||||||||||||||||||
1248 | /*! | - | ||||||||||||||||||||||||
1249 | \reimp | - | ||||||||||||||||||||||||
1250 | */ | - | ||||||||||||||||||||||||
1251 | void QListView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) | - | ||||||||||||||||||||||||
1252 | { | - | ||||||||||||||||||||||||
1253 | Q_D(QListView); | - | ||||||||||||||||||||||||
1254 | if (!d->selectionModel)
| 0 | ||||||||||||||||||||||||
1255 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1256 | - | |||||||||||||||||||||||||
1257 | // if we are wrapping, we can only selecte inside the contents rectangle | - | ||||||||||||||||||||||||
1258 | int w = qMax(d->contentsSize().width(), d->viewport->width()); | - | ||||||||||||||||||||||||
1259 | int h = qMax(d->contentsSize().height(), d->viewport->height()); | - | ||||||||||||||||||||||||
1260 | if (d->wrap && !QRect(0, 0, w, h).intersects(rect))
| 0 | ||||||||||||||||||||||||
1261 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1262 | - | |||||||||||||||||||||||||
1263 | QItemSelection selection; | - | ||||||||||||||||||||||||
1264 | - | |||||||||||||||||||||||||
1265 | if (rect.width() == 1 && rect.height() == 1) {
| 0 | ||||||||||||||||||||||||
1266 | const QVector<QModelIndex> intersectVector = d->intersectingSet(rect.translated(horizontalOffset(), verticalOffset())); | - | ||||||||||||||||||||||||
1267 | QModelIndex tl; | - | ||||||||||||||||||||||||
1268 | if (!intersectVector.isEmpty())
| 0 | ||||||||||||||||||||||||
1269 | tl = intersectVector.last(); // special case for mouse press; only select the top item never executed: tl = intersectVector.last(); | 0 | ||||||||||||||||||||||||
1270 | if (tl.isValid() && d->isIndexEnabled(tl))
| 0 | ||||||||||||||||||||||||
1271 | selection.select(tl, tl); never executed: selection.select(tl, tl); | 0 | ||||||||||||||||||||||||
1272 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1273 | if (state() == DragSelectingState) { // visual selection mode (rubberband selection)
| 0 | ||||||||||||||||||||||||
1274 | selection = d->selection(rect.translated(horizontalOffset(), verticalOffset())); | - | ||||||||||||||||||||||||
1275 | } else { // logical selection mode (key and mouse click selection) never executed: end of block | 0 | ||||||||||||||||||||||||
1276 | QModelIndex tl, br; | - | ||||||||||||||||||||||||
1277 | // get the first item | - | ||||||||||||||||||||||||
1278 | const QRect topLeft(rect.left() + horizontalOffset(), rect.top() + verticalOffset(), 1, 1); | - | ||||||||||||||||||||||||
1279 | QVector<QModelIndex> intersectVector = d->intersectingSet(topLeft); | - | ||||||||||||||||||||||||
1280 | if (!intersectVector.isEmpty())
| 0 | ||||||||||||||||||||||||
1281 | tl = intersectVector.last(); never executed: tl = intersectVector.last(); | 0 | ||||||||||||||||||||||||
1282 | // get the last item | - | ||||||||||||||||||||||||
1283 | const QRect bottomRight(rect.right() + horizontalOffset(), rect.bottom() + verticalOffset(), 1, 1); | - | ||||||||||||||||||||||||
1284 | intersectVector = d->intersectingSet(bottomRight); | - | ||||||||||||||||||||||||
1285 | if (!intersectVector.isEmpty())
| 0 | ||||||||||||||||||||||||
1286 | br = intersectVector.last(); never executed: br = intersectVector.last(); | 0 | ||||||||||||||||||||||||
1287 | - | |||||||||||||||||||||||||
1288 | // get the ranges | - | ||||||||||||||||||||||||
1289 | if (tl.isValid() && br.isValid()
| 0 | ||||||||||||||||||||||||
1290 | && d->isIndexEnabled(tl)
| 0 | ||||||||||||||||||||||||
1291 | && d->isIndexEnabled(br)) {
| 0 | ||||||||||||||||||||||||
1292 | QRect first = rectForIndex(tl); | - | ||||||||||||||||||||||||
1293 | QRect last = rectForIndex(br); | - | ||||||||||||||||||||||||
1294 | QRect middle; | - | ||||||||||||||||||||||||
1295 | if (d->flow == LeftToRight) {
| 0 | ||||||||||||||||||||||||
1296 | QRect &top = first; | - | ||||||||||||||||||||||||
1297 | QRect &bottom = last; | - | ||||||||||||||||||||||||
1298 | // if bottom is above top, swap them | - | ||||||||||||||||||||||||
1299 | if (top.center().y() > bottom.center().y()) {
| 0 | ||||||||||||||||||||||||
1300 | QRect tmp = top; | - | ||||||||||||||||||||||||
1301 | top = bottom; | - | ||||||||||||||||||||||||
1302 | bottom = tmp; | - | ||||||||||||||||||||||||
1303 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1304 | // if the rect are on differnet lines, expand | - | ||||||||||||||||||||||||
1305 | if (top.top() != bottom.top()) {
| 0 | ||||||||||||||||||||||||
1306 | // top rectangle | - | ||||||||||||||||||||||||
1307 | if (isRightToLeft())
| 0 | ||||||||||||||||||||||||
1308 | top.setLeft(0); never executed: top.setLeft(0); | 0 | ||||||||||||||||||||||||
1309 | else | - | ||||||||||||||||||||||||
1310 | top.setRight(contentsSize().width()); never executed: top.setRight(contentsSize().width()); | 0 | ||||||||||||||||||||||||
1311 | // bottom rectangle | - | ||||||||||||||||||||||||
1312 | if (isRightToLeft())
| 0 | ||||||||||||||||||||||||
1313 | bottom.setRight(contentsSize().width()); never executed: bottom.setRight(contentsSize().width()); | 0 | ||||||||||||||||||||||||
1314 | else | - | ||||||||||||||||||||||||
1315 | bottom.setLeft(0); never executed: bottom.setLeft(0); | 0 | ||||||||||||||||||||||||
1316 | } else if (top.left() > bottom.right()) {
| 0 | ||||||||||||||||||||||||
1317 | if (isRightToLeft())
| 0 | ||||||||||||||||||||||||
1318 | bottom.setLeft(top.right()); never executed: bottom.setLeft(top.right()); | 0 | ||||||||||||||||||||||||
1319 | else | - | ||||||||||||||||||||||||
1320 | bottom.setRight(top.left()); never executed: bottom.setRight(top.left()); | 0 | ||||||||||||||||||||||||
1321 | } else { | - | ||||||||||||||||||||||||
1322 | if (isRightToLeft())
| 0 | ||||||||||||||||||||||||
1323 | top.setLeft(bottom.right()); never executed: top.setLeft(bottom.right()); | 0 | ||||||||||||||||||||||||
1324 | else | - | ||||||||||||||||||||||||
1325 | top.setRight(bottom.left()); never executed: top.setRight(bottom.left()); | 0 | ||||||||||||||||||||||||
1326 | } | - | ||||||||||||||||||||||||
1327 | // middle rectangle | - | ||||||||||||||||||||||||
1328 | if (top.bottom() < bottom.top()) {
| 0 | ||||||||||||||||||||||||
1329 | if (gridSize().isValid() && !gridSize().isNull())
| 0 | ||||||||||||||||||||||||
1330 | middle.setTop(top.top() + gridSize().height()); never executed: middle.setTop(top.top() + gridSize().height()); | 0 | ||||||||||||||||||||||||
1331 | else | - | ||||||||||||||||||||||||
1332 | middle.setTop(top.bottom() + 1); never executed: middle.setTop(top.bottom() + 1); | 0 | ||||||||||||||||||||||||
1333 | middle.setLeft(qMin(top.left(), bottom.left())); | - | ||||||||||||||||||||||||
1334 | middle.setBottom(bottom.top() - 1); | - | ||||||||||||||||||||||||
1335 | middle.setRight(qMax(top.right(), bottom.right())); | - | ||||||||||||||||||||||||
1336 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1337 | } else { // TopToBottom never executed: end of block | 0 | ||||||||||||||||||||||||
1338 | QRect &left = first; | - | ||||||||||||||||||||||||
1339 | QRect &right = last; | - | ||||||||||||||||||||||||
1340 | if (left.center().x() > right.center().x())
| 0 | ||||||||||||||||||||||||
1341 | qSwap(left, right); never executed: qSwap(left, right); | 0 | ||||||||||||||||||||||||
1342 | - | |||||||||||||||||||||||||
1343 | int ch = contentsSize().height(); | - | ||||||||||||||||||||||||
1344 | if (left.left() != right.left()) {
| 0 | ||||||||||||||||||||||||
1345 | // left rectangle | - | ||||||||||||||||||||||||
1346 | if (isRightToLeft())
| 0 | ||||||||||||||||||||||||
1347 | left.setTop(0); never executed: left.setTop(0); | 0 | ||||||||||||||||||||||||
1348 | else | - | ||||||||||||||||||||||||
1349 | left.setBottom(ch); never executed: left.setBottom(ch); | 0 | ||||||||||||||||||||||||
1350 | - | |||||||||||||||||||||||||
1351 | // top rectangle | - | ||||||||||||||||||||||||
1352 | if (isRightToLeft())
| 0 | ||||||||||||||||||||||||
1353 | right.setBottom(ch); never executed: right.setBottom(ch); | 0 | ||||||||||||||||||||||||
1354 | else | - | ||||||||||||||||||||||||
1355 | right.setTop(0); never executed: right.setTop(0); | 0 | ||||||||||||||||||||||||
1356 | // only set middle if the | - | ||||||||||||||||||||||||
1357 | middle.setTop(0); | - | ||||||||||||||||||||||||
1358 | middle.setBottom(ch); | - | ||||||||||||||||||||||||
1359 | if (gridSize().isValid() && !gridSize().isNull())
| 0 | ||||||||||||||||||||||||
1360 | middle.setLeft(left.left() + gridSize().width()); never executed: middle.setLeft(left.left() + gridSize().width()); | 0 | ||||||||||||||||||||||||
1361 | else | - | ||||||||||||||||||||||||
1362 | middle.setLeft(left.right() + 1); never executed: middle.setLeft(left.right() + 1); | 0 | ||||||||||||||||||||||||
1363 | middle.setRight(right.left() - 1); | - | ||||||||||||||||||||||||
1364 | } else if (left.bottom() < right.top()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1365 | left.setBottom(right.top() - 1); | - | ||||||||||||||||||||||||
1366 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1367 | right.setBottom(left.top() - 1); | - | ||||||||||||||||||||||||
1368 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1369 | } | - | ||||||||||||||||||||||||
1370 | - | |||||||||||||||||||||||||
1371 | // do the selections | - | ||||||||||||||||||||||||
1372 | QItemSelection topSelection = d->selection(first); | - | ||||||||||||||||||||||||
1373 | QItemSelection middleSelection = d->selection(middle); | - | ||||||||||||||||||||||||
1374 | QItemSelection bottomSelection = d->selection(last); | - | ||||||||||||||||||||||||
1375 | // merge | - | ||||||||||||||||||||||||
1376 | selection.merge(topSelection, QItemSelectionModel::Select); | - | ||||||||||||||||||||||||
1377 | selection.merge(middleSelection, QItemSelectionModel::Select); | - | ||||||||||||||||||||||||
1378 | selection.merge(bottomSelection, QItemSelectionModel::Select); | - | ||||||||||||||||||||||||
1379 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1380 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1381 | } | - | ||||||||||||||||||||||||
1382 | - | |||||||||||||||||||||||||
1383 | d->selectionModel->select(selection, command); | - | ||||||||||||||||||||||||
1384 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1385 | - | |||||||||||||||||||||||||
1386 | /*! | - | ||||||||||||||||||||||||
1387 | \reimp | - | ||||||||||||||||||||||||
1388 | - | |||||||||||||||||||||||||
1389 | Since 4.7, the returned region only contains rectangles intersecting | - | ||||||||||||||||||||||||
1390 | (or included in) the viewport. | - | ||||||||||||||||||||||||
1391 | */ | - | ||||||||||||||||||||||||
1392 | QRegion QListView::visualRegionForSelection(const QItemSelection &selection) const | - | ||||||||||||||||||||||||
1393 | { | - | ||||||||||||||||||||||||
1394 | Q_D(const QListView); | - | ||||||||||||||||||||||||
1395 | // ### NOTE: this is a potential bottleneck in non-static mode | - | ||||||||||||||||||||||||
1396 | int c = d->column; | - | ||||||||||||||||||||||||
1397 | QRegion selectionRegion; | - | ||||||||||||||||||||||||
1398 | const QRect &viewportRect = d->viewport->rect(); | - | ||||||||||||||||||||||||
1399 | for (int i = 0; i < selection.count(); ++i) {
| 0 | ||||||||||||||||||||||||
1400 | if (!selection.at(i).isValid())
| 0 | ||||||||||||||||||||||||
1401 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
1402 | QModelIndex parent = selection.at(i).topLeft().parent(); | - | ||||||||||||||||||||||||
1403 | //we only display the children of the root in a listview | - | ||||||||||||||||||||||||
1404 | //we're not interested in the other model indexes | - | ||||||||||||||||||||||||
1405 | if (parent != d->root)
| 0 | ||||||||||||||||||||||||
1406 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
1407 | int t = selection.at(i).topLeft().row(); | - | ||||||||||||||||||||||||
1408 | int b = selection.at(i).bottomRight().row(); | - | ||||||||||||||||||||||||
1409 | if (d->viewMode == IconMode || d->isWrapping()) { // in non-static mode, we have to go through all selected items
| 0 | ||||||||||||||||||||||||
1410 | for (int r = t; r <= b; ++r) {
| 0 | ||||||||||||||||||||||||
1411 | const QRect &rect = visualRect(d->model->index(r, c, parent)); | - | ||||||||||||||||||||||||
1412 | if (viewportRect.intersects(rect))
| 0 | ||||||||||||||||||||||||
1413 | selectionRegion += rect; never executed: selectionRegion += rect; | 0 | ||||||||||||||||||||||||
1414 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1415 | } else { // in static mode, we can optimize a bit never executed: end of block | 0 | ||||||||||||||||||||||||
1416 | while (t <= b && d->isHidden(t)) ++t; never executed: ++t;
| 0 | ||||||||||||||||||||||||
1417 | while (b >= t && d->isHidden(b)) --b; never executed: --b;
| 0 | ||||||||||||||||||||||||
1418 | const QModelIndex top = d->model->index(t, c, parent); | - | ||||||||||||||||||||||||
1419 | const QModelIndex bottom = d->model->index(b, c, parent); | - | ||||||||||||||||||||||||
1420 | QRect rect(visualRect(top).topLeft(), | - | ||||||||||||||||||||||||
1421 | visualRect(bottom).bottomRight()); | - | ||||||||||||||||||||||||
1422 | if (viewportRect.intersects(rect))
| 0 | ||||||||||||||||||||||||
1423 | selectionRegion += rect; never executed: selectionRegion += rect; | 0 | ||||||||||||||||||||||||
1424 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1425 | } | - | ||||||||||||||||||||||||
1426 | - | |||||||||||||||||||||||||
1427 | return selectionRegion; never executed: return selectionRegion; | 0 | ||||||||||||||||||||||||
1428 | } | - | ||||||||||||||||||||||||
1429 | - | |||||||||||||||||||||||||
1430 | /*! | - | ||||||||||||||||||||||||
1431 | \reimp | - | ||||||||||||||||||||||||
1432 | */ | - | ||||||||||||||||||||||||
1433 | QModelIndexList QListView::selectedIndexes() const | - | ||||||||||||||||||||||||
1434 | { | - | ||||||||||||||||||||||||
1435 | Q_D(const QListView); | - | ||||||||||||||||||||||||
1436 | if (!d->selectionModel)
| 0 | ||||||||||||||||||||||||
1437 | return QModelIndexList(); never executed: return QModelIndexList(); | 0 | ||||||||||||||||||||||||
1438 | - | |||||||||||||||||||||||||
1439 | QModelIndexList viewSelected = d->selectionModel->selectedIndexes(); | - | ||||||||||||||||||||||||
1440 | for (int i = 0; i < viewSelected.count();) {
| 0 | ||||||||||||||||||||||||
1441 | const QModelIndex &index = viewSelected.at(i); | - | ||||||||||||||||||||||||
1442 | if (!isIndexHidden(index) && index.parent() == d->root && index.column() == d->column)
| 0 | ||||||||||||||||||||||||
1443 | ++i; never executed: ++i; | 0 | ||||||||||||||||||||||||
1444 | else | - | ||||||||||||||||||||||||
1445 | viewSelected.removeAt(i); never executed: viewSelected.removeAt(i); | 0 | ||||||||||||||||||||||||
1446 | } | - | ||||||||||||||||||||||||
1447 | return viewSelected; never executed: return viewSelected; | 0 | ||||||||||||||||||||||||
1448 | } | - | ||||||||||||||||||||||||
1449 | - | |||||||||||||||||||||||||
1450 | /*! | - | ||||||||||||||||||||||||
1451 | \internal | - | ||||||||||||||||||||||||
1452 | - | |||||||||||||||||||||||||
1453 | Layout the items according to the flow and wrapping properties. | - | ||||||||||||||||||||||||
1454 | */ | - | ||||||||||||||||||||||||
1455 | void QListView::doItemsLayout() | - | ||||||||||||||||||||||||
1456 | { | - | ||||||||||||||||||||||||
1457 | Q_D(QListView); | - | ||||||||||||||||||||||||
1458 | // showing the scroll bars will trigger a resize event, | - | ||||||||||||||||||||||||
1459 | // so we set the state to expanding to avoid | - | ||||||||||||||||||||||||
1460 | // triggering another layout | - | ||||||||||||||||||||||||
1461 | QAbstractItemView::State oldState = state(); | - | ||||||||||||||||||||||||
1462 | setState(ExpandingState); | - | ||||||||||||||||||||||||
1463 | if (d->model->columnCount(d->root) > 0) { // no columns means no contents
| 0 | ||||||||||||||||||||||||
1464 | d->resetBatchStartRow(); | - | ||||||||||||||||||||||||
1465 | if (layoutMode() == SinglePass)
| 0 | ||||||||||||||||||||||||
1466 | d->doItemsLayout(d->model->rowCount(d->root)); // layout everything never executed: d->doItemsLayout(d->model->rowCount(d->root)); | 0 | ||||||||||||||||||||||||
1467 | else if (!d->batchLayoutTimer.isActive()) {
| 0 | ||||||||||||||||||||||||
1468 | if (!d->doItemsLayout(d->batchSize)) // layout is done
| 0 | ||||||||||||||||||||||||
1469 | d->batchLayoutTimer.start(0, this); // do a new batch as fast as possible never executed: d->batchLayoutTimer.start(0, this); | 0 | ||||||||||||||||||||||||
1470 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1471 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1472 | QAbstractItemView::doItemsLayout(); | - | ||||||||||||||||||||||||
1473 | setState(oldState); // restoring the oldState | - | ||||||||||||||||||||||||
1474 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1475 | - | |||||||||||||||||||||||||
1476 | /*! | - | ||||||||||||||||||||||||
1477 | \reimp | - | ||||||||||||||||||||||||
1478 | */ | - | ||||||||||||||||||||||||
1479 | void QListView::updateGeometries() | - | ||||||||||||||||||||||||
1480 | { | - | ||||||||||||||||||||||||
1481 | Q_D(QListView); | - | ||||||||||||||||||||||||
1482 | if (geometry().isEmpty() || d->model->rowCount(d->root) <= 0 || d->model->columnCount(d->root) <= 0) {
| 0 | ||||||||||||||||||||||||
1483 | horizontalScrollBar()->setRange(0, 0); | - | ||||||||||||||||||||||||
1484 | verticalScrollBar()->setRange(0, 0); | - | ||||||||||||||||||||||||
1485 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1486 | QModelIndex index = d->model->index(0, d->column, d->root); | - | ||||||||||||||||||||||||
1487 | QStyleOptionViewItem option = d->viewOptionsV1(); | - | ||||||||||||||||||||||||
1488 | QSize step = d->itemSize(option, index); | - | ||||||||||||||||||||||||
1489 | d->commonListView->updateHorizontalScrollBar(step); | - | ||||||||||||||||||||||||
1490 | d->commonListView->updateVerticalScrollBar(step); | - | ||||||||||||||||||||||||
1491 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1492 | - | |||||||||||||||||||||||||
1493 | QAbstractItemView::updateGeometries(); | - | ||||||||||||||||||||||||
1494 | - | |||||||||||||||||||||||||
1495 | // if the scroll bars are turned off, we resize the contents to the viewport | - | ||||||||||||||||||||||||
1496 | if (d->movement == Static && !d->isWrapping()) {
| 0 | ||||||||||||||||||||||||
1497 | d->layoutChildren(); // we need the viewport size to be updated | - | ||||||||||||||||||||||||
1498 | if (d->flow == TopToBottom) {
| 0 | ||||||||||||||||||||||||
1499 | if (horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) {
| 0 | ||||||||||||||||||||||||
1500 | d->setContentsSize(viewport()->width(), contentsSize().height()); | - | ||||||||||||||||||||||||
1501 | horizontalScrollBar()->setRange(0, 0); // we see all the contents anyway | - | ||||||||||||||||||||||||
1502 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1503 | } else { // LeftToRight never executed: end of block | 0 | ||||||||||||||||||||||||
1504 | if (verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) {
| 0 | ||||||||||||||||||||||||
1505 | d->setContentsSize(contentsSize().width(), viewport()->height()); | - | ||||||||||||||||||||||||
1506 | verticalScrollBar()->setRange(0, 0); // we see all the contents anyway | - | ||||||||||||||||||||||||
1507 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1508 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1509 | } | - | ||||||||||||||||||||||||
1510 | - | |||||||||||||||||||||||||
1511 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1512 | - | |||||||||||||||||||||||||
1513 | /*! | - | ||||||||||||||||||||||||
1514 | \reimp | - | ||||||||||||||||||||||||
1515 | */ | - | ||||||||||||||||||||||||
1516 | bool QListView::isIndexHidden(const QModelIndex &index) const | - | ||||||||||||||||||||||||
1517 | { | - | ||||||||||||||||||||||||
1518 | Q_D(const QListView); | - | ||||||||||||||||||||||||
1519 | return (d->isHidden(index.row()) never executed: return (d->isHidden(index.row()) && (index.parent() == d->root) && index.column() == d->column);
| 0 | ||||||||||||||||||||||||
1520 | && (index.parent() == d->root) never executed: return (d->isHidden(index.row()) && (index.parent() == d->root) && index.column() == d->column);
| 0 | ||||||||||||||||||||||||
1521 | && index.column() == d->column); never executed: return (d->isHidden(index.row()) && (index.parent() == d->root) && index.column() == d->column);
| 0 | ||||||||||||||||||||||||
1522 | } | - | ||||||||||||||||||||||||
1523 | - | |||||||||||||||||||||||||
1524 | /*! | - | ||||||||||||||||||||||||
1525 | \property QListView::modelColumn | - | ||||||||||||||||||||||||
1526 | \brief the column in the model that is visible | - | ||||||||||||||||||||||||
1527 | - | |||||||||||||||||||||||||
1528 | By default, this property contains 0, indicating that the first | - | ||||||||||||||||||||||||
1529 | column in the model will be shown. | - | ||||||||||||||||||||||||
1530 | */ | - | ||||||||||||||||||||||||
1531 | void QListView::setModelColumn(int column) | - | ||||||||||||||||||||||||
1532 | { | - | ||||||||||||||||||||||||
1533 | Q_D(QListView); | - | ||||||||||||||||||||||||
1534 | if (column < 0 || column >= d->model->columnCount(d->root))
| 0 | ||||||||||||||||||||||||
1535 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1536 | d->column = column; | - | ||||||||||||||||||||||||
1537 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
1538 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1539 | - | |||||||||||||||||||||||||
1540 | int QListView::modelColumn() const | - | ||||||||||||||||||||||||
1541 | { | - | ||||||||||||||||||||||||
1542 | Q_D(const QListView); | - | ||||||||||||||||||||||||
1543 | return d->column; never executed: return d->column; | 0 | ||||||||||||||||||||||||
1544 | } | - | ||||||||||||||||||||||||
1545 | - | |||||||||||||||||||||||||
1546 | /*! | - | ||||||||||||||||||||||||
1547 | \property QListView::uniformItemSizes | - | ||||||||||||||||||||||||
1548 | \brief whether all items in the listview have the same size | - | ||||||||||||||||||||||||
1549 | \since 4.1 | - | ||||||||||||||||||||||||
1550 | - | |||||||||||||||||||||||||
1551 | This property should only be set to true if it is guaranteed that all items | - | ||||||||||||||||||||||||
1552 | in the view have the same size. This enables the view to do some | - | ||||||||||||||||||||||||
1553 | optimizations for performance purposes. | - | ||||||||||||||||||||||||
1554 | - | |||||||||||||||||||||||||
1555 | By default, this property is \c false. | - | ||||||||||||||||||||||||
1556 | */ | - | ||||||||||||||||||||||||
1557 | void QListView::setUniformItemSizes(bool enable) | - | ||||||||||||||||||||||||
1558 | { | - | ||||||||||||||||||||||||
1559 | Q_D(QListView); | - | ||||||||||||||||||||||||
1560 | d->uniformItemSizes = enable; | - | ||||||||||||||||||||||||
1561 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1562 | - | |||||||||||||||||||||||||
1563 | bool QListView::uniformItemSizes() const | - | ||||||||||||||||||||||||
1564 | { | - | ||||||||||||||||||||||||
1565 | Q_D(const QListView); | - | ||||||||||||||||||||||||
1566 | return d->uniformItemSizes; never executed: return d->uniformItemSizes; | 0 | ||||||||||||||||||||||||
1567 | } | - | ||||||||||||||||||||||||
1568 | - | |||||||||||||||||||||||||
1569 | /*! | - | ||||||||||||||||||||||||
1570 | \property QListView::wordWrap | - | ||||||||||||||||||||||||
1571 | \brief the item text word-wrapping policy | - | ||||||||||||||||||||||||
1572 | \since 4.2 | - | ||||||||||||||||||||||||
1573 | - | |||||||||||||||||||||||||
1574 | If this property is \c true then the item text is wrapped where | - | ||||||||||||||||||||||||
1575 | necessary at word-breaks; otherwise it is not wrapped at all. | - | ||||||||||||||||||||||||
1576 | This property is \c false by default. | - | ||||||||||||||||||||||||
1577 | - | |||||||||||||||||||||||||
1578 | Please note that even if wrapping is enabled, the cell will not be | - | ||||||||||||||||||||||||
1579 | expanded to make room for the text. It will print ellipsis for | - | ||||||||||||||||||||||||
1580 | text that cannot be shown, according to the view's | - | ||||||||||||||||||||||||
1581 | \l{QAbstractItemView::}{textElideMode}. | - | ||||||||||||||||||||||||
1582 | */ | - | ||||||||||||||||||||||||
1583 | void QListView::setWordWrap(bool on) | - | ||||||||||||||||||||||||
1584 | { | - | ||||||||||||||||||||||||
1585 | Q_D(QListView); | - | ||||||||||||||||||||||||
1586 | if (d->wrapItemText == on)
| 0 | ||||||||||||||||||||||||
1587 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1588 | d->wrapItemText = on; | - | ||||||||||||||||||||||||
1589 | d->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
1590 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1591 | - | |||||||||||||||||||||||||
1592 | bool QListView::wordWrap() const | - | ||||||||||||||||||||||||
1593 | { | - | ||||||||||||||||||||||||
1594 | Q_D(const QListView); | - | ||||||||||||||||||||||||
1595 | return d->wrapItemText; never executed: return d->wrapItemText; | 0 | ||||||||||||||||||||||||
1596 | } | - | ||||||||||||||||||||||||
1597 | - | |||||||||||||||||||||||||
1598 | /*! | - | ||||||||||||||||||||||||
1599 | \property QListView::selectionRectVisible | - | ||||||||||||||||||||||||
1600 | \brief if the selection rectangle should be visible | - | ||||||||||||||||||||||||
1601 | \since 4.3 | - | ||||||||||||||||||||||||
1602 | - | |||||||||||||||||||||||||
1603 | If this property is \c true then the selection rectangle is visible; | - | ||||||||||||||||||||||||
1604 | otherwise it will be hidden. | - | ||||||||||||||||||||||||
1605 | - | |||||||||||||||||||||||||
1606 | \note The selection rectangle will only be visible if the selection mode | - | ||||||||||||||||||||||||
1607 | is in a mode where more than one item can be selected; i.e., it will not | - | ||||||||||||||||||||||||
1608 | draw a selection rectangle if the selection mode is | - | ||||||||||||||||||||||||
1609 | QAbstractItemView::SingleSelection. | - | ||||||||||||||||||||||||
1610 | - | |||||||||||||||||||||||||
1611 | By default, this property is \c false. | - | ||||||||||||||||||||||||
1612 | */ | - | ||||||||||||||||||||||||
1613 | void QListView::setSelectionRectVisible(bool show) | - | ||||||||||||||||||||||||
1614 | { | - | ||||||||||||||||||||||||
1615 | Q_D(QListView); | - | ||||||||||||||||||||||||
1616 | d->modeProperties |= uint(QListViewPrivate::SelectionRectVisible); | - | ||||||||||||||||||||||||
1617 | d->setSelectionRectVisible(show); | - | ||||||||||||||||||||||||
1618 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1619 | - | |||||||||||||||||||||||||
1620 | bool QListView::isSelectionRectVisible() const | - | ||||||||||||||||||||||||
1621 | { | - | ||||||||||||||||||||||||
1622 | Q_D(const QListView); | - | ||||||||||||||||||||||||
1623 | return d->isSelectionRectVisible(); never executed: return d->isSelectionRectVisible(); | 0 | ||||||||||||||||||||||||
1624 | } | - | ||||||||||||||||||||||||
1625 | - | |||||||||||||||||||||||||
1626 | /*! | - | ||||||||||||||||||||||||
1627 | \reimp | - | ||||||||||||||||||||||||
1628 | */ | - | ||||||||||||||||||||||||
1629 | bool QListView::event(QEvent *e) | - | ||||||||||||||||||||||||
1630 | { | - | ||||||||||||||||||||||||
1631 | return QAbstractItemView::event(e); never executed: return QAbstractItemView::event(e); | 0 | ||||||||||||||||||||||||
1632 | } | - | ||||||||||||||||||||||||
1633 | - | |||||||||||||||||||||||||
1634 | /* | - | ||||||||||||||||||||||||
1635 | * private object implementation | - | ||||||||||||||||||||||||
1636 | */ | - | ||||||||||||||||||||||||
1637 | - | |||||||||||||||||||||||||
1638 | QListViewPrivate::QListViewPrivate() | - | ||||||||||||||||||||||||
1639 | : QAbstractItemViewPrivate(), | - | ||||||||||||||||||||||||
1640 | commonListView(0), | - | ||||||||||||||||||||||||
1641 | wrap(false), | - | ||||||||||||||||||||||||
1642 | space(0), | - | ||||||||||||||||||||||||
1643 | flow(QListView::TopToBottom), | - | ||||||||||||||||||||||||
1644 | movement(QListView::Static), | - | ||||||||||||||||||||||||
1645 | resizeMode(QListView::Fixed), | - | ||||||||||||||||||||||||
1646 | layoutMode(QListView::SinglePass), | - | ||||||||||||||||||||||||
1647 | viewMode(QListView::ListMode), | - | ||||||||||||||||||||||||
1648 | modeProperties(0), | - | ||||||||||||||||||||||||
1649 | column(0), | - | ||||||||||||||||||||||||
1650 | uniformItemSizes(false), | - | ||||||||||||||||||||||||
1651 | batchSize(100), | - | ||||||||||||||||||||||||
1652 | showElasticBand(false) | - | ||||||||||||||||||||||||
1653 | { | - | ||||||||||||||||||||||||
1654 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1655 | - | |||||||||||||||||||||||||
1656 | QListViewPrivate::~QListViewPrivate() | - | ||||||||||||||||||||||||
1657 | { | - | ||||||||||||||||||||||||
1658 | delete commonListView; | - | ||||||||||||||||||||||||
1659 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1660 | - | |||||||||||||||||||||||||
1661 | void QListViewPrivate::clear() | - | ||||||||||||||||||||||||
1662 | { | - | ||||||||||||||||||||||||
1663 | // initialization of data structs | - | ||||||||||||||||||||||||
1664 | cachedItemSize = QSize(); | - | ||||||||||||||||||||||||
1665 | commonListView->clear(); | - | ||||||||||||||||||||||||
1666 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1667 | - | |||||||||||||||||||||||||
1668 | void QListViewPrivate::prepareItemsLayout() | - | ||||||||||||||||||||||||
1669 | { | - | ||||||||||||||||||||||||
1670 | Q_Q(QListView); | - | ||||||||||||||||||||||||
1671 | clear(); | - | ||||||||||||||||||||||||
1672 | - | |||||||||||||||||||||||||
1673 | //take the size as if there were scrollbar in order to prevent scrollbar to blink | - | ||||||||||||||||||||||||
1674 | layoutBounds = QRect(QPoint(), q->maximumViewportSize()); | - | ||||||||||||||||||||||||
1675 | - | |||||||||||||||||||||||||
1676 | int frameAroundContents = 0; | - | ||||||||||||||||||||||||
1677 | if (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents))
| 0 | ||||||||||||||||||||||||
1678 | frameAroundContents = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2; never executed: frameAroundContents = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2; | 0 | ||||||||||||||||||||||||
1679 | - | |||||||||||||||||||||||||
1680 | // maximumViewportSize() already takes scrollbar into account if policy is | - | ||||||||||||||||||||||||
1681 | // Qt::ScrollBarAlwaysOn but scrollbar extent must be deduced if policy | - | ||||||||||||||||||||||||
1682 | // is Qt::ScrollBarAsNeeded | - | ||||||||||||||||||||||||
1683 | int verticalMargin = vbarpolicy==Qt::ScrollBarAsNeeded
| 0 | ||||||||||||||||||||||||
1684 | ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, vbar) + frameAroundContents | - | ||||||||||||||||||||||||
1685 | : 0; | - | ||||||||||||||||||||||||
1686 | int horizontalMargin = hbarpolicy==Qt::ScrollBarAsNeeded
| 0 | ||||||||||||||||||||||||
1687 | ? q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, hbar) + frameAroundContents | - | ||||||||||||||||||||||||
1688 | : 0; | - | ||||||||||||||||||||||||
1689 | - | |||||||||||||||||||||||||
1690 | layoutBounds.adjust(0, 0, -verticalMargin, -horizontalMargin); | - | ||||||||||||||||||||||||
1691 | - | |||||||||||||||||||||||||
1692 | int rowCount = model->columnCount(root) <= 0 ? 0 : model->rowCount(root);
| 0 | ||||||||||||||||||||||||
1693 | commonListView->setRowCount(rowCount); | - | ||||||||||||||||||||||||
1694 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1695 | - | |||||||||||||||||||||||||
1696 | /*! | - | ||||||||||||||||||||||||
1697 | \internal | - | ||||||||||||||||||||||||
1698 | */ | - | ||||||||||||||||||||||||
1699 | bool QListViewPrivate::doItemsLayout(int delta) | - | ||||||||||||||||||||||||
1700 | { | - | ||||||||||||||||||||||||
1701 | int max = model->rowCount(root) - 1; | - | ||||||||||||||||||||||||
1702 | int first = batchStartRow(); | - | ||||||||||||||||||||||||
1703 | int last = qMin(first + delta - 1, max); | - | ||||||||||||||||||||||||
1704 | - | |||||||||||||||||||||||||
1705 | if (first == 0) {
| 0 | ||||||||||||||||||||||||
1706 | layoutChildren(); // make sure the viewport has the right size | - | ||||||||||||||||||||||||
1707 | prepareItemsLayout(); | - | ||||||||||||||||||||||||
1708 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1709 | - | |||||||||||||||||||||||||
1710 | if (max < 0 || last < first) {
| 0 | ||||||||||||||||||||||||
1711 | return true; // nothing to do never executed: return true; | 0 | ||||||||||||||||||||||||
1712 | } | - | ||||||||||||||||||||||||
1713 | - | |||||||||||||||||||||||||
1714 | QListViewLayoutInfo info; | - | ||||||||||||||||||||||||
1715 | info.bounds = layoutBounds; | - | ||||||||||||||||||||||||
1716 | info.grid = gridSize(); | - | ||||||||||||||||||||||||
1717 | info.spacing = (info.grid.isValid() ? 0 : spacing());
| 0 | ||||||||||||||||||||||||
1718 | info.first = first; | - | ||||||||||||||||||||||||
1719 | info.last = last; | - | ||||||||||||||||||||||||
1720 | info.wrap = isWrapping(); | - | ||||||||||||||||||||||||
1721 | info.flow = flow; | - | ||||||||||||||||||||||||
1722 | info.max = max; | - | ||||||||||||||||||||||||
1723 | - | |||||||||||||||||||||||||
1724 | return commonListView->doBatchedItemLayout(info, max); never executed: return commonListView->doBatchedItemLayout(info, max); | 0 | ||||||||||||||||||||||||
1725 | } | - | ||||||||||||||||||||||||
1726 | - | |||||||||||||||||||||||||
1727 | QListViewItem QListViewPrivate::indexToListViewItem(const QModelIndex &index) const | - | ||||||||||||||||||||||||
1728 | { | - | ||||||||||||||||||||||||
1729 | if (!index.isValid() || isHidden(index.row()))
| 0 | ||||||||||||||||||||||||
1730 | return QListViewItem(); never executed: return QListViewItem(); | 0 | ||||||||||||||||||||||||
1731 | - | |||||||||||||||||||||||||
1732 | return commonListView->indexToListViewItem(index); never executed: return commonListView->indexToListViewItem(index); | 0 | ||||||||||||||||||||||||
1733 | } | - | ||||||||||||||||||||||||
1734 | - | |||||||||||||||||||||||||
1735 | QRect QListViewPrivate::mapToViewport(const QRect &rect, bool extend) const | - | ||||||||||||||||||||||||
1736 | { | - | ||||||||||||||||||||||||
1737 | Q_Q(const QListView); | - | ||||||||||||||||||||||||
1738 | if (!rect.isValid())
| 0 | ||||||||||||||||||||||||
1739 | return rect; never executed: return rect; | 0 | ||||||||||||||||||||||||
1740 | - | |||||||||||||||||||||||||
1741 | QRect result = extend ? commonListView->mapToViewport(rect) : rect;
| 0 | ||||||||||||||||||||||||
1742 | int dx = -q->horizontalOffset(); | - | ||||||||||||||||||||||||
1743 | int dy = -q->verticalOffset(); | - | ||||||||||||||||||||||||
1744 | return result.adjusted(dx, dy, dx, dy); never executed: return result.adjusted(dx, dy, dx, dy); | 0 | ||||||||||||||||||||||||
1745 | } | - | ||||||||||||||||||||||||
1746 | - | |||||||||||||||||||||||||
1747 | QModelIndex QListViewPrivate::closestIndex(const QRect &target, | - | ||||||||||||||||||||||||
1748 | const QVector<QModelIndex> &candidates) const | - | ||||||||||||||||||||||||
1749 | { | - | ||||||||||||||||||||||||
1750 | int distance = 0; | - | ||||||||||||||||||||||||
1751 | int shortest = INT_MAX; | - | ||||||||||||||||||||||||
1752 | QModelIndex closest; | - | ||||||||||||||||||||||||
1753 | QVector<QModelIndex>::const_iterator it = candidates.begin(); | - | ||||||||||||||||||||||||
1754 | - | |||||||||||||||||||||||||
1755 | for (; it != candidates.end(); ++it) {
| 0 | ||||||||||||||||||||||||
1756 | if (!(*it).isValid())
| 0 | ||||||||||||||||||||||||
1757 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
1758 | - | |||||||||||||||||||||||||
1759 | const QRect indexRect = indexToListViewItem(*it).rect(); | - | ||||||||||||||||||||||||
1760 | - | |||||||||||||||||||||||||
1761 | //if the center x (or y) position of an item is included in the rect of the other item, | - | ||||||||||||||||||||||||
1762 | //we define the distance between them as the difference in x (or y) of their respective center. | - | ||||||||||||||||||||||||
1763 | // Otherwise, we use the nahattan length between the 2 items | - | ||||||||||||||||||||||||
1764 | if ((target.center().x() >= indexRect.x() && target.center().x() < indexRect.right())
| 0 | ||||||||||||||||||||||||
1765 | || (indexRect.center().x() >= target.x() && indexRect.center().x() < target.right())) {
| 0 | ||||||||||||||||||||||||
1766 | //one item's center is at the vertical of the other | - | ||||||||||||||||||||||||
1767 | distance = qAbs(indexRect.center().y() - target.center().y()); | - | ||||||||||||||||||||||||
1768 | } else if ((target.center().y() >= indexRect.y() && target.center().y() < indexRect.bottom()) never executed: end of block
| 0 | ||||||||||||||||||||||||
1769 | || (indexRect.center().y() >= target.y() && indexRect.center().y() < target.bottom())) {
| 0 | ||||||||||||||||||||||||
1770 | //one item's center is at the vertical of the other | - | ||||||||||||||||||||||||
1771 | distance = qAbs(indexRect.center().x() - target.center().x()); | - | ||||||||||||||||||||||||
1772 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1773 | distance = (indexRect.center() - target.center()).manhattanLength(); | - | ||||||||||||||||||||||||
1774 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1775 | if (distance < shortest) {
| 0 | ||||||||||||||||||||||||
1776 | shortest = distance; | - | ||||||||||||||||||||||||
1777 | closest = *it; | - | ||||||||||||||||||||||||
1778 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1779 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1780 | return closest; never executed: return closest; | 0 | ||||||||||||||||||||||||
1781 | } | - | ||||||||||||||||||||||||
1782 | - | |||||||||||||||||||||||||
1783 | QSize QListViewPrivate::itemSize(const QStyleOptionViewItem &option, const QModelIndex &index) const | - | ||||||||||||||||||||||||
1784 | { | - | ||||||||||||||||||||||||
1785 | if (!uniformItemSizes) {
| 0 | ||||||||||||||||||||||||
1786 | const QAbstractItemDelegate *delegate = delegateForIndex(index); | - | ||||||||||||||||||||||||
1787 | return delegate ? delegate->sizeHint(option, index) : QSize(); never executed: return delegate ? delegate->sizeHint(option, index) : QSize();
| 0 | ||||||||||||||||||||||||
1788 | } | - | ||||||||||||||||||||||||
1789 | if (!cachedItemSize.isValid()) { // the last item is probaly the largest, so we use its size
| 0 | ||||||||||||||||||||||||
1790 | int row = model->rowCount(root) - 1; | - | ||||||||||||||||||||||||
1791 | QModelIndex sample = model->index(row, column, root); | - | ||||||||||||||||||||||||
1792 | const QAbstractItemDelegate *delegate = delegateForIndex(sample); | - | ||||||||||||||||||||||||
1793 | cachedItemSize = delegate ? delegate->sizeHint(option, sample) : QSize();
| 0 | ||||||||||||||||||||||||
1794 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1795 | return cachedItemSize; never executed: return cachedItemSize; | 0 | ||||||||||||||||||||||||
1796 | } | - | ||||||||||||||||||||||||
1797 | - | |||||||||||||||||||||||||
1798 | QItemSelection QListViewPrivate::selection(const QRect &rect) const | - | ||||||||||||||||||||||||
1799 | { | - | ||||||||||||||||||||||||
1800 | QItemSelection selection; | - | ||||||||||||||||||||||||
1801 | QModelIndex tl, br; | - | ||||||||||||||||||||||||
1802 | const QVector<QModelIndex> intersectVector = intersectingSet(rect); | - | ||||||||||||||||||||||||
1803 | QVector<QModelIndex>::const_iterator it = intersectVector.begin(); | - | ||||||||||||||||||||||||
1804 | for (; it != intersectVector.end(); ++it) {
| 0 | ||||||||||||||||||||||||
1805 | if (!tl.isValid() && !br.isValid()) {
| 0 | ||||||||||||||||||||||||
1806 | tl = br = *it; | - | ||||||||||||||||||||||||
1807 | } else if ((*it).row() == (tl.row() - 1)) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1808 | tl = *it; // expand current range | - | ||||||||||||||||||||||||
1809 | } else if ((*it).row() == (br.row() + 1)) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1810 | br = (*it); // expand current range | - | ||||||||||||||||||||||||
1811 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1812 | selection.select(tl, br); // select current range | - | ||||||||||||||||||||||||
1813 | tl = br = *it; // start new range | - | ||||||||||||||||||||||||
1814 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1815 | } | - | ||||||||||||||||||||||||
1816 | - | |||||||||||||||||||||||||
1817 | if (tl.isValid() && br.isValid())
| 0 | ||||||||||||||||||||||||
1818 | selection.select(tl, br); never executed: selection.select(tl, br); | 0 | ||||||||||||||||||||||||
1819 | else if (tl.isValid())
| 0 | ||||||||||||||||||||||||
1820 | selection.select(tl, tl); never executed: selection.select(tl, tl); | 0 | ||||||||||||||||||||||||
1821 | else if (br.isValid())
| 0 | ||||||||||||||||||||||||
1822 | selection.select(br, br); never executed: selection.select(br, br); | 0 | ||||||||||||||||||||||||
1823 | - | |||||||||||||||||||||||||
1824 | return selection; never executed: return selection; | 0 | ||||||||||||||||||||||||
1825 | } | - | ||||||||||||||||||||||||
1826 | - | |||||||||||||||||||||||||
1827 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
1828 | QAbstractItemView::DropIndicatorPosition QListViewPrivate::position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const | - | ||||||||||||||||||||||||
1829 | { | - | ||||||||||||||||||||||||
1830 | if (viewMode == QListView::ListMode && flow == QListView::LeftToRight)
| 0 | ||||||||||||||||||||||||
1831 | return static_cast<QListModeViewBase *>(commonListView)->position(pos, rect, idx); never executed: return static_cast<QListModeViewBase *>(commonListView)->position(pos, rect, idx); | 0 | ||||||||||||||||||||||||
1832 | else | - | ||||||||||||||||||||||||
1833 | return QAbstractItemViewPrivate::position(pos, rect, idx); never executed: return QAbstractItemViewPrivate::position(pos, rect, idx); | 0 | ||||||||||||||||||||||||
1834 | } | - | ||||||||||||||||||||||||
1835 | - | |||||||||||||||||||||||||
1836 | bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex) | - | ||||||||||||||||||||||||
1837 | { | - | ||||||||||||||||||||||||
1838 | if (viewMode == QListView::ListMode && flow == QListView::LeftToRight)
| 0 | ||||||||||||||||||||||||
1839 | return static_cast<QListModeViewBase *>(commonListView)->dropOn(event, dropRow, dropCol, dropIndex); never executed: return static_cast<QListModeViewBase *>(commonListView)->dropOn(event, dropRow, dropCol, dropIndex); | 0 | ||||||||||||||||||||||||
1840 | else | - | ||||||||||||||||||||||||
1841 | return QAbstractItemViewPrivate::dropOn(event, dropRow, dropCol, dropIndex); never executed: return QAbstractItemViewPrivate::dropOn(event, dropRow, dropCol, dropIndex); | 0 | ||||||||||||||||||||||||
1842 | } | - | ||||||||||||||||||||||||
1843 | #endif | - | ||||||||||||||||||||||||
1844 | - | |||||||||||||||||||||||||
1845 | /* | - | ||||||||||||||||||||||||
1846 | * Common ListView Implementation | - | ||||||||||||||||||||||||
1847 | */ | - | ||||||||||||||||||||||||
1848 | - | |||||||||||||||||||||||||
1849 | void QCommonListViewBase::appendHiddenRow(int row) | - | ||||||||||||||||||||||||
1850 | { | - | ||||||||||||||||||||||||
1851 | dd->hiddenRows.insert(dd->model->index(row, 0, qq->rootIndex())); | - | ||||||||||||||||||||||||
1852 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1853 | - | |||||||||||||||||||||||||
1854 | void QCommonListViewBase::removeHiddenRow(int row) | - | ||||||||||||||||||||||||
1855 | { | - | ||||||||||||||||||||||||
1856 | dd->hiddenRows.remove(dd->model->index(row, 0, qq->rootIndex())); | - | ||||||||||||||||||||||||
1857 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1858 | - | |||||||||||||||||||||||||
1859 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
1860 | void QCommonListViewBase::paintDragDrop(QPainter *painter) | - | ||||||||||||||||||||||||
1861 | { | - | ||||||||||||||||||||||||
1862 | // FIXME: Until the we can provide a proper drop indicator | - | ||||||||||||||||||||||||
1863 | // in IconMode, it makes no sense to show it | - | ||||||||||||||||||||||||
1864 | dd->paintDropIndicator(painter); | - | ||||||||||||||||||||||||
1865 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1866 | #endif | - | ||||||||||||||||||||||||
1867 | - | |||||||||||||||||||||||||
1868 | void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step) | - | ||||||||||||||||||||||||
1869 | { | - | ||||||||||||||||||||||||
1870 | horizontalScrollBar()->setSingleStep(step.width() + spacing()); | - | ||||||||||||||||||||||||
1871 | horizontalScrollBar()->setPageStep(viewport()->width()); | - | ||||||||||||||||||||||||
1872 | - | |||||||||||||||||||||||||
1873 | // If both scroll bars are set to auto, we might end up in a situation with enough space | - | ||||||||||||||||||||||||
1874 | // for the actual content. But still one of the scroll bars will become enabled due to | - | ||||||||||||||||||||||||
1875 | // the other one using the space. The other one will become invisible in the same cycle. | - | ||||||||||||||||||||||||
1876 | // -> Infinite loop, QTBUG-39902 | - | ||||||||||||||||||||||||
1877 | const bool bothScrollBarsAuto = qq->verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded &&
| 0 | ||||||||||||||||||||||||
1878 | qq->horizontalScrollBarPolicy() == Qt::ScrollBarAsNeeded;
| 0 | ||||||||||||||||||||||||
1879 | - | |||||||||||||||||||||||||
1880 | const QSize viewportSize = qq->contentsRect().size(); | - | ||||||||||||||||||||||||
1881 | - | |||||||||||||||||||||||||
1882 | bool verticalWantsToShow = contentsSize.height() > viewportSize.height(); | - | ||||||||||||||||||||||||
1883 | bool horizontalWantsToShow; | - | ||||||||||||||||||||||||
1884 | if (verticalWantsToShow)
| 0 | ||||||||||||||||||||||||
1885 | horizontalWantsToShow = contentsSize.width() > viewportSize.width() - qq->verticalScrollBar()->width(); never executed: horizontalWantsToShow = contentsSize.width() > viewportSize.width() - qq->verticalScrollBar()->width(); | 0 | ||||||||||||||||||||||||
1886 | else | - | ||||||||||||||||||||||||
1887 | horizontalWantsToShow = contentsSize.width() > viewportSize.width(); never executed: horizontalWantsToShow = contentsSize.width() > viewportSize.width(); | 0 | ||||||||||||||||||||||||
1888 | - | |||||||||||||||||||||||||
1889 | if (bothScrollBarsAuto && !horizontalWantsToShow) {
| 0 | ||||||||||||||||||||||||
1890 | // break the infinite loop described above by setting the range to 0, 0. | - | ||||||||||||||||||||||||
1891 | // QAbstractScrollArea will then hide the scroll bar for us | - | ||||||||||||||||||||||||
1892 | horizontalScrollBar()->setRange(0, 0); | - | ||||||||||||||||||||||||
1893 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1894 | horizontalScrollBar()->setRange(0, contentsSize.width() - viewport()->width()); | - | ||||||||||||||||||||||||
1895 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1896 | } | - | ||||||||||||||||||||||||
1897 | - | |||||||||||||||||||||||||
1898 | void QCommonListViewBase::updateVerticalScrollBar(const QSize &step) | - | ||||||||||||||||||||||||
1899 | { | - | ||||||||||||||||||||||||
1900 | verticalScrollBar()->setSingleStep(step.height() + spacing()); | - | ||||||||||||||||||||||||
1901 | verticalScrollBar()->setPageStep(viewport()->height()); | - | ||||||||||||||||||||||||
1902 | - | |||||||||||||||||||||||||
1903 | // If both scroll bars are set to auto, we might end up in a situation with enough space | - | ||||||||||||||||||||||||
1904 | // for the actual content. But still one of the scroll bars will become enabled due to | - | ||||||||||||||||||||||||
1905 | // the other one using the space. The other one will become invisible in the same cycle. | - | ||||||||||||||||||||||||
1906 | // -> Infinite loop, QTBUG-39902 | - | ||||||||||||||||||||||||
1907 | const bool bothScrollBarsAuto = qq->verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded &&
| 0 | ||||||||||||||||||||||||
1908 | qq->horizontalScrollBarPolicy() == Qt::ScrollBarAsNeeded;
| 0 | ||||||||||||||||||||||||
1909 | - | |||||||||||||||||||||||||
1910 | const QSize viewportSize = qq->contentsRect().size(); | - | ||||||||||||||||||||||||
1911 | - | |||||||||||||||||||||||||
1912 | bool horizontalWantsToShow = contentsSize.width() > viewportSize.width(); | - | ||||||||||||||||||||||||
1913 | bool verticalWantsToShow; | - | ||||||||||||||||||||||||
1914 | if (horizontalWantsToShow)
| 0 | ||||||||||||||||||||||||
1915 | verticalWantsToShow = contentsSize.height() > viewportSize.height() - qq->horizontalScrollBar()->height(); never executed: verticalWantsToShow = contentsSize.height() > viewportSize.height() - qq->horizontalScrollBar()->height(); | 0 | ||||||||||||||||||||||||
1916 | else | - | ||||||||||||||||||||||||
1917 | verticalWantsToShow = contentsSize.height() > viewportSize.height(); never executed: verticalWantsToShow = contentsSize.height() > viewportSize.height(); | 0 | ||||||||||||||||||||||||
1918 | - | |||||||||||||||||||||||||
1919 | if (bothScrollBarsAuto && !verticalWantsToShow) {
| 0 | ||||||||||||||||||||||||
1920 | // break the infinite loop described above by setting the range to 0, 0. | - | ||||||||||||||||||||||||
1921 | // QAbstractScrollArea will then hide the scroll bar for us | - | ||||||||||||||||||||||||
1922 | verticalScrollBar()->setRange(0, 0); | - | ||||||||||||||||||||||||
1923 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1924 | verticalScrollBar()->setRange(0, contentsSize.height() - viewport()->height()); | - | ||||||||||||||||||||||||
1925 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1926 | } | - | ||||||||||||||||||||||||
1927 | - | |||||||||||||||||||||||||
1928 | void QCommonListViewBase::scrollContentsBy(int dx, int dy, bool /*scrollElasticBand*/) | - | ||||||||||||||||||||||||
1929 | { | - | ||||||||||||||||||||||||
1930 | dd->scrollContentsBy(isRightToLeft() ? -dx : dx, dy); | - | ||||||||||||||||||||||||
1931 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1932 | - | |||||||||||||||||||||||||
1933 | int QCommonListViewBase::verticalScrollToValue(int /*index*/, QListView::ScrollHint hint, | - | ||||||||||||||||||||||||
1934 | bool above, bool below, const QRect &area, const QRect &rect) const | - | ||||||||||||||||||||||||
1935 | { | - | ||||||||||||||||||||||||
1936 | int verticalValue = verticalScrollBar()->value(); | - | ||||||||||||||||||||||||
1937 | QRect adjusted = rect.adjusted(-spacing(), -spacing(), spacing(), spacing()); | - | ||||||||||||||||||||||||
1938 | if (hint == QListView::PositionAtTop || above)
| 0 | ||||||||||||||||||||||||
1939 | verticalValue += adjusted.top(); never executed: verticalValue += adjusted.top(); | 0 | ||||||||||||||||||||||||
1940 | else if (hint == QListView::PositionAtBottom || below)
| 0 | ||||||||||||||||||||||||
1941 | verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1); never executed: verticalValue += qMin(adjusted.top(), adjusted.bottom() - area.height() + 1); | 0 | ||||||||||||||||||||||||
1942 | else if (hint == QListView::PositionAtCenter)
| 0 | ||||||||||||||||||||||||
1943 | verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2); never executed: verticalValue += adjusted.top() - ((area.height() - adjusted.height()) / 2); | 0 | ||||||||||||||||||||||||
1944 | return verticalValue; never executed: return verticalValue; | 0 | ||||||||||||||||||||||||
1945 | } | - | ||||||||||||||||||||||||
1946 | - | |||||||||||||||||||||||||
1947 | int QCommonListViewBase::horizontalOffset() const | - | ||||||||||||||||||||||||
1948 | { | - | ||||||||||||||||||||||||
1949 | return (isRightToLeft() ? horizontalScrollBar()->maximum() - horizontalScrollBar()->value() : horizontalScrollBar()->value()); never executed: return (isRightToLeft() ? horizontalScrollBar()->maximum() - horizontalScrollBar()->value() : horizontalScrollBar()->value());
| 0 | ||||||||||||||||||||||||
1950 | } | - | ||||||||||||||||||||||||
1951 | - | |||||||||||||||||||||||||
1952 | int QCommonListViewBase::horizontalScrollToValue(const int /*index*/, QListView::ScrollHint hint, | - | ||||||||||||||||||||||||
1953 | bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const | - | ||||||||||||||||||||||||
1954 | { | - | ||||||||||||||||||||||||
1955 | int horizontalValue = horizontalScrollBar()->value(); | - | ||||||||||||||||||||||||
1956 | if (isRightToLeft()) {
| 0 | ||||||||||||||||||||||||
1957 | if (hint == QListView::PositionAtCenter) {
| 0 | ||||||||||||||||||||||||
1958 | horizontalValue += ((area.width() - rect.width()) / 2) - rect.left(); | - | ||||||||||||||||||||||||
1959 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1960 | if (leftOf)
| 0 | ||||||||||||||||||||||||
1961 | horizontalValue -= rect.left(); never executed: horizontalValue -= rect.left(); | 0 | ||||||||||||||||||||||||
1962 | else if (rightOf)
| 0 | ||||||||||||||||||||||||
1963 | horizontalValue += qMin(rect.left(), area.width() - rect.right()); never executed: horizontalValue += qMin(rect.left(), area.width() - rect.right()); | 0 | ||||||||||||||||||||||||
1964 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1965 | } else { | - | ||||||||||||||||||||||||
1966 | if (hint == QListView::PositionAtCenter) {
| 0 | ||||||||||||||||||||||||
1967 | horizontalValue += rect.left() - ((area.width()- rect.width()) / 2); | - | ||||||||||||||||||||||||
1968 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1969 | if (leftOf)
| 0 | ||||||||||||||||||||||||
1970 | horizontalValue += rect.left(); never executed: horizontalValue += rect.left(); | 0 | ||||||||||||||||||||||||
1971 | else if (rightOf)
| 0 | ||||||||||||||||||||||||
1972 | horizontalValue += qMin(rect.left(), rect.right() - area.width()); never executed: horizontalValue += qMin(rect.left(), rect.right() - area.width()); | 0 | ||||||||||||||||||||||||
1973 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1974 | } | - | ||||||||||||||||||||||||
1975 | return horizontalValue; never executed: return horizontalValue; | 0 | ||||||||||||||||||||||||
1976 | } | - | ||||||||||||||||||||||||
1977 | - | |||||||||||||||||||||||||
1978 | /* | - | ||||||||||||||||||||||||
1979 | * ListMode ListView Implementation | - | ||||||||||||||||||||||||
1980 | */ | - | ||||||||||||||||||||||||
1981 | QListModeViewBase::QListModeViewBase(QListView *q, QListViewPrivate *d) | - | ||||||||||||||||||||||||
1982 | : QCommonListViewBase(q, d) | - | ||||||||||||||||||||||||
1983 | { | - | ||||||||||||||||||||||||
1984 | dd->defaultDropAction = Qt::CopyAction; | - | ||||||||||||||||||||||||
1985 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1986 | - | |||||||||||||||||||||||||
1987 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
1988 | QAbstractItemView::DropIndicatorPosition QListModeViewBase::position(const QPoint &pos, const QRect &rect, const QModelIndex &index) const | - | ||||||||||||||||||||||||
1989 | { | - | ||||||||||||||||||||||||
1990 | QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport; | - | ||||||||||||||||||||||||
1991 | if (!dd->overwrite) {
| 0 | ||||||||||||||||||||||||
1992 | const int margin = 2; | - | ||||||||||||||||||||||||
1993 | if (pos.x() - rect.left() < margin) {
| 0 | ||||||||||||||||||||||||
1994 | r = QAbstractItemView::AboveItem; // Visually, on the left | - | ||||||||||||||||||||||||
1995 | } else if (rect.right() - pos.x() < margin) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1996 | r = QAbstractItemView::BelowItem; // Visually, on the right | - | ||||||||||||||||||||||||
1997 | } else if (rect.contains(pos, true)) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1998 | r = QAbstractItemView::OnItem; | - | ||||||||||||||||||||||||
1999 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2000 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2001 | QRect touchingRect = rect; | - | ||||||||||||||||||||||||
2002 | touchingRect.adjust(-1, -1, 1, 1); | - | ||||||||||||||||||||||||
2003 | if (touchingRect.contains(pos, false)) {
| 0 | ||||||||||||||||||||||||
2004 | r = QAbstractItemView::OnItem; | - | ||||||||||||||||||||||||
2005 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2006 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2007 | - | |||||||||||||||||||||||||
2008 | if (r == QAbstractItemView::OnItem && (!(dd->model->flags(index) & Qt::ItemIsDropEnabled)))
| 0 | ||||||||||||||||||||||||
2009 | r = pos.x() < rect.center().x() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem; never executed: r = pos.x() < rect.center().x() ? QAbstractItemView::AboveItem : QAbstractItemView::BelowItem;
| 0 | ||||||||||||||||||||||||
2010 | - | |||||||||||||||||||||||||
2011 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||
2012 | } | - | ||||||||||||||||||||||||
2013 | - | |||||||||||||||||||||||||
2014 | void QListModeViewBase::dragMoveEvent(QDragMoveEvent *event) | - | ||||||||||||||||||||||||
2015 | { | - | ||||||||||||||||||||||||
2016 | if (qq->dragDropMode() == QAbstractItemView::InternalMove
| 0 | ||||||||||||||||||||||||
2017 | && (event->source() != qq || !(event->possibleActions() & Qt::MoveAction)))
| 0 | ||||||||||||||||||||||||
2018 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2019 | - | |||||||||||||||||||||||||
2020 | // ignore by default | - | ||||||||||||||||||||||||
2021 | event->ignore(); | - | ||||||||||||||||||||||||
2022 | - | |||||||||||||||||||||||||
2023 | // can't use indexAt, doesn't account for spacing. | - | ||||||||||||||||||||||||
2024 | QPoint p = event->pos(); | - | ||||||||||||||||||||||||
2025 | QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1); | - | ||||||||||||||||||||||||
2026 | rect.adjust(-dd->spacing(), -dd->spacing(), dd->spacing(), dd->spacing()); | - | ||||||||||||||||||||||||
2027 | const QVector<QModelIndex> intersectVector = dd->intersectingSet(rect); | - | ||||||||||||||||||||||||
2028 | QModelIndex index = intersectVector.count() > 0
| 0 | ||||||||||||||||||||||||
2029 | ? intersectVector.last() : QModelIndex(); | - | ||||||||||||||||||||||||
2030 | dd->hover = index; | - | ||||||||||||||||||||||||
2031 | if (!dd->droppingOnItself(event, index)
| 0 | ||||||||||||||||||||||||
2032 | && dd->canDrop(event)) {
| 0 | ||||||||||||||||||||||||
2033 | - | |||||||||||||||||||||||||
2034 | if (index.isValid() && dd->showDropIndicator) {
| 0 | ||||||||||||||||||||||||
2035 | QRect rect = qq->visualRect(index); | - | ||||||||||||||||||||||||
2036 | dd->dropIndicatorPosition = position(event->pos(), rect, index); | - | ||||||||||||||||||||||||
2037 | // if spacing, should try to draw between items, not just next to item. | - | ||||||||||||||||||||||||
2038 | switch (dd->dropIndicatorPosition) { | - | ||||||||||||||||||||||||
2039 | case QAbstractItemView::AboveItem: never executed: case QAbstractItemView::AboveItem: | 0 | ||||||||||||||||||||||||
2040 | if (dd->isIndexDropEnabled(index.parent())) {
| 0 | ||||||||||||||||||||||||
2041 | dd->dropIndicatorRect = QRect(rect.left()-dd->spacing(), rect.top(), 0, rect.height()); | - | ||||||||||||||||||||||||
2042 | event->accept(); | - | ||||||||||||||||||||||||
2043 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2044 | dd->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
2045 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2046 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2047 | case QAbstractItemView::BelowItem: never executed: case QAbstractItemView::BelowItem: | 0 | ||||||||||||||||||||||||
2048 | if (dd->isIndexDropEnabled(index.parent())) {
| 0 | ||||||||||||||||||||||||
2049 | dd->dropIndicatorRect = QRect(rect.right()+dd->spacing(), rect.top(), 0, rect.height()); | - | ||||||||||||||||||||||||
2050 | event->accept(); | - | ||||||||||||||||||||||||
2051 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2052 | dd->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
2053 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2054 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2055 | case QAbstractItemView::OnItem: never executed: case QAbstractItemView::OnItem: | 0 | ||||||||||||||||||||||||
2056 | if (dd->isIndexDropEnabled(index)) {
| 0 | ||||||||||||||||||||||||
2057 | dd->dropIndicatorRect = rect; | - | ||||||||||||||||||||||||
2058 | event->accept(); | - | ||||||||||||||||||||||||
2059 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2060 | dd->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
2061 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2062 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2063 | case QAbstractItemView::OnViewport: never executed: case QAbstractItemView::OnViewport: | 0 | ||||||||||||||||||||||||
2064 | dd->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
2065 | if (dd->isIndexDropEnabled(qq->rootIndex())) {
| 0 | ||||||||||||||||||||||||
2066 | event->accept(); // allow dropping in empty areas | - | ||||||||||||||||||||||||
2067 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2068 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2069 | } | - | ||||||||||||||||||||||||
2070 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2071 | dd->dropIndicatorRect = QRect(); | - | ||||||||||||||||||||||||
2072 | dd->dropIndicatorPosition = QAbstractItemView::OnViewport; | - | ||||||||||||||||||||||||
2073 | if (dd->isIndexDropEnabled(qq->rootIndex())) {
| 0 | ||||||||||||||||||||||||
2074 | event->accept(); // allow dropping in empty areas | - | ||||||||||||||||||||||||
2075 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2076 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2077 | dd->viewport->update(); | - | ||||||||||||||||||||||||
2078 | } // can drop never executed: end of block | 0 | ||||||||||||||||||||||||
2079 | - | |||||||||||||||||||||||||
2080 | if (dd->shouldAutoScroll(event->pos()))
| 0 | ||||||||||||||||||||||||
2081 | qq->startAutoScroll(); never executed: qq->startAutoScroll(); | 0 | ||||||||||||||||||||||||
2082 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2083 | - | |||||||||||||||||||||||||
2084 | /*! | - | ||||||||||||||||||||||||
2085 | If the event hasn't already been accepted, determines the index to drop on. | - | ||||||||||||||||||||||||
2086 | - | |||||||||||||||||||||||||
2087 | if (row == -1 && col == -1) | - | ||||||||||||||||||||||||
2088 | // append to this drop index | - | ||||||||||||||||||||||||
2089 | else | - | ||||||||||||||||||||||||
2090 | // place at row, col in drop index | - | ||||||||||||||||||||||||
2091 | - | |||||||||||||||||||||||||
2092 | If it returns \c true a drop can be done, and dropRow, dropCol and dropIndex reflects the position of the drop. | - | ||||||||||||||||||||||||
2093 | \internal | - | ||||||||||||||||||||||||
2094 | */ | - | ||||||||||||||||||||||||
2095 | bool QListModeViewBase::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QModelIndex *dropIndex) | - | ||||||||||||||||||||||||
2096 | { | - | ||||||||||||||||||||||||
2097 | if (event->isAccepted())
| 0 | ||||||||||||||||||||||||
2098 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2099 | - | |||||||||||||||||||||||||
2100 | QModelIndex index; | - | ||||||||||||||||||||||||
2101 | if (dd->viewport->rect().contains(event->pos())) {
| 0 | ||||||||||||||||||||||||
2102 | // can't use indexAt, doesn't account for spacing. | - | ||||||||||||||||||||||||
2103 | QPoint p = event->pos(); | - | ||||||||||||||||||||||||
2104 | QRect rect(p.x() + horizontalOffset(), p.y() + verticalOffset(), 1, 1); | - | ||||||||||||||||||||||||
2105 | rect.adjust(-dd->spacing(), -dd->spacing(), dd->spacing(), dd->spacing()); | - | ||||||||||||||||||||||||
2106 | const QVector<QModelIndex> intersectVector = dd->intersectingSet(rect); | - | ||||||||||||||||||||||||
2107 | index = intersectVector.count() > 0
| 0 | ||||||||||||||||||||||||
2108 | ? intersectVector.last() : QModelIndex(); | - | ||||||||||||||||||||||||
2109 | if (!index.isValid())
| 0 | ||||||||||||||||||||||||
2110 | index = dd->root; never executed: index = dd->root; | 0 | ||||||||||||||||||||||||
2111 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2112 | - | |||||||||||||||||||||||||
2113 | // If we are allowed to do the drop | - | ||||||||||||||||||||||||
2114 | if (dd->model->supportedDropActions() & event->dropAction()) {
| 0 | ||||||||||||||||||||||||
2115 | int row = -1; | - | ||||||||||||||||||||||||
2116 | int col = -1; | - | ||||||||||||||||||||||||
2117 | if (index != dd->root) {
| 0 | ||||||||||||||||||||||||
2118 | dd->dropIndicatorPosition = position(event->pos(), qq->visualRect(index), index); | - | ||||||||||||||||||||||||
2119 | switch (dd->dropIndicatorPosition) { | - | ||||||||||||||||||||||||
2120 | case QAbstractItemView::AboveItem: never executed: case QAbstractItemView::AboveItem: | 0 | ||||||||||||||||||||||||
2121 | row = index.row(); | - | ||||||||||||||||||||||||
2122 | col = index.column(); | - | ||||||||||||||||||||||||
2123 | index = index.parent(); | - | ||||||||||||||||||||||||
2124 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2125 | case QAbstractItemView::BelowItem: never executed: case QAbstractItemView::BelowItem: | 0 | ||||||||||||||||||||||||
2126 | row = index.row() + 1; | - | ||||||||||||||||||||||||
2127 | col = index.column(); | - | ||||||||||||||||||||||||
2128 | index = index.parent(); | - | ||||||||||||||||||||||||
2129 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2130 | case QAbstractItemView::OnItem: never executed: case QAbstractItemView::OnItem: | 0 | ||||||||||||||||||||||||
2131 | case QAbstractItemView::OnViewport: never executed: case QAbstractItemView::OnViewport: | 0 | ||||||||||||||||||||||||
2132 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2133 | } | - | ||||||||||||||||||||||||
2134 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2135 | dd->dropIndicatorPosition = QAbstractItemView::OnViewport; | - | ||||||||||||||||||||||||
2136 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2137 | *dropIndex = index; | - | ||||||||||||||||||||||||
2138 | *dropRow = row; | - | ||||||||||||||||||||||||
2139 | *dropCol = col; | - | ||||||||||||||||||||||||
2140 | if (!dd->droppingOnItself(event, index))
| 0 | ||||||||||||||||||||||||
2141 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
2142 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2143 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2144 | } | - | ||||||||||||||||||||||||
2145 | - | |||||||||||||||||||||||||
2146 | #endif //QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
2147 | - | |||||||||||||||||||||||||
2148 | void QListModeViewBase::updateVerticalScrollBar(const QSize &step) | - | ||||||||||||||||||||||||
2149 | { | - | ||||||||||||||||||||||||
2150 | if (verticalScrollMode() == QAbstractItemView::ScrollPerItem
| 0 | ||||||||||||||||||||||||
2151 | && ((flow() == QListView::TopToBottom && !isWrapping())
| 0 | ||||||||||||||||||||||||
2152 | || (flow() == QListView::LeftToRight && isWrapping()))) {
| 0 | ||||||||||||||||||||||||
2153 | const int steps = (flow() == QListView::TopToBottom ? scrollValueMap : segmentPositions).count() - 1;
| 0 | ||||||||||||||||||||||||
2154 | if (steps > 0) {
| 0 | ||||||||||||||||||||||||
2155 | const int pageSteps = perItemScrollingPageSteps(viewport()->height(), contentsSize.height(), isWrapping()); | - | ||||||||||||||||||||||||
2156 | verticalScrollBar()->setSingleStep(1); | - | ||||||||||||||||||||||||
2157 | verticalScrollBar()->setPageStep(pageSteps); | - | ||||||||||||||||||||||||
2158 | verticalScrollBar()->setRange(0, steps - pageSteps); | - | ||||||||||||||||||||||||
2159 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2160 | verticalScrollBar()->setRange(0, 0); | - | ||||||||||||||||||||||||
2161 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2162 | // } else if (vertical && d->isWrapping() && d->movement == Static) { | - | ||||||||||||||||||||||||
2163 | // ### wrapped scrolling in flow direction | - | ||||||||||||||||||||||||
2164 | } else { | - | ||||||||||||||||||||||||
2165 | QCommonListViewBase::updateVerticalScrollBar(step); | - | ||||||||||||||||||||||||
2166 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2167 | } | - | ||||||||||||||||||||||||
2168 | - | |||||||||||||||||||||||||
2169 | void QListModeViewBase::updateHorizontalScrollBar(const QSize &step) | - | ||||||||||||||||||||||||
2170 | { | - | ||||||||||||||||||||||||
2171 | if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem
| 0 | ||||||||||||||||||||||||
2172 | && ((flow() == QListView::TopToBottom && isWrapping())
| 0 | ||||||||||||||||||||||||
2173 | || (flow() == QListView::LeftToRight && !isWrapping()))) {
| 0 | ||||||||||||||||||||||||
2174 | int steps = (flow() == QListView::TopToBottom ? segmentPositions : scrollValueMap).count() - 1;
| 0 | ||||||||||||||||||||||||
2175 | if (steps > 0) {
| 0 | ||||||||||||||||||||||||
2176 | const int pageSteps = perItemScrollingPageSteps(viewport()->width(), contentsSize.width(), isWrapping()); | - | ||||||||||||||||||||||||
2177 | horizontalScrollBar()->setSingleStep(1); | - | ||||||||||||||||||||||||
2178 | horizontalScrollBar()->setPageStep(pageSteps); | - | ||||||||||||||||||||||||
2179 | horizontalScrollBar()->setRange(0, steps - pageSteps); | - | ||||||||||||||||||||||||
2180 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2181 | horizontalScrollBar()->setRange(0, 0); | - | ||||||||||||||||||||||||
2182 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2183 | } else { | - | ||||||||||||||||||||||||
2184 | QCommonListViewBase::updateHorizontalScrollBar(step); | - | ||||||||||||||||||||||||
2185 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2186 | } | - | ||||||||||||||||||||||||
2187 | - | |||||||||||||||||||||||||
2188 | int QListModeViewBase::verticalScrollToValue(int index, QListView::ScrollHint hint, | - | ||||||||||||||||||||||||
2189 | bool above, bool below, const QRect &area, const QRect &rect) const | - | ||||||||||||||||||||||||
2190 | { | - | ||||||||||||||||||||||||
2191 | if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
| 0 | ||||||||||||||||||||||||
2192 | int value; | - | ||||||||||||||||||||||||
2193 | if (scrollValueMap.isEmpty()) {
| 0 | ||||||||||||||||||||||||
2194 | value = 0; | - | ||||||||||||||||||||||||
2195 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2196 | int scrollBarValue = verticalScrollBar()->value(); | - | ||||||||||||||||||||||||
2197 | int numHidden = 0; | - | ||||||||||||||||||||||||
2198 | for (int i = 0; i < flowPositions.count() - 1 && i <= scrollBarValue; ++i)
| 0 | ||||||||||||||||||||||||
2199 | if (isHidden(i))
| 0 | ||||||||||||||||||||||||
2200 | ++numHidden; never executed: ++numHidden; | 0 | ||||||||||||||||||||||||
2201 | value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()) - numHidden, flowPositions.count() - 1); | - | ||||||||||||||||||||||||
2202 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2203 | if (above)
| 0 | ||||||||||||||||||||||||
2204 | hint = QListView::PositionAtTop; never executed: hint = QListView::PositionAtTop; | 0 | ||||||||||||||||||||||||
2205 | else if (below)
| 0 | ||||||||||||||||||||||||
2206 | hint = QListView::PositionAtBottom; never executed: hint = QListView::PositionAtBottom; | 0 | ||||||||||||||||||||||||
2207 | if (hint == QListView::EnsureVisible)
| 0 | ||||||||||||||||||||||||
2208 | return value; never executed: return value; | 0 | ||||||||||||||||||||||||
2209 | - | |||||||||||||||||||||||||
2210 | return perItemScrollToValue(index, value, area.height(), hint, Qt::Vertical, isWrapping(), rect.height()); never executed: return perItemScrollToValue(index, value, area.height(), hint, Qt::Vertical, isWrapping(), rect.height()); | 0 | ||||||||||||||||||||||||
2211 | } | - | ||||||||||||||||||||||||
2212 | - | |||||||||||||||||||||||||
2213 | return QCommonListViewBase::verticalScrollToValue(index, hint, above, below, area, rect); never executed: return QCommonListViewBase::verticalScrollToValue(index, hint, above, below, area, rect); | 0 | ||||||||||||||||||||||||
2214 | } | - | ||||||||||||||||||||||||
2215 | - | |||||||||||||||||||||||||
2216 | int QListModeViewBase::horizontalOffset() const | - | ||||||||||||||||||||||||
2217 | { | - | ||||||||||||||||||||||||
2218 | if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {
| 0 | ||||||||||||||||||||||||
2219 | if (isWrapping()) {
| 0 | ||||||||||||||||||||||||
2220 | if (flow() == QListView::TopToBottom && !segmentPositions.isEmpty()) {
| 0 | ||||||||||||||||||||||||
2221 | const int max = segmentPositions.count() - 1; | - | ||||||||||||||||||||||||
2222 | int currentValue = qBound(0, horizontalScrollBar()->value(), max); | - | ||||||||||||||||||||||||
2223 | int position = segmentPositions.at(currentValue); | - | ||||||||||||||||||||||||
2224 | int maximumValue = qBound(0, horizontalScrollBar()->maximum(), max); | - | ||||||||||||||||||||||||
2225 | int maximum = segmentPositions.at(maximumValue); | - | ||||||||||||||||||||||||
2226 | return (isRightToLeft() ? maximum - position : position); never executed: return (isRightToLeft() ? maximum - position : position);
| 0 | ||||||||||||||||||||||||
2227 | } | - | ||||||||||||||||||||||||
2228 | } else if (flow() == QListView::LeftToRight && !flowPositions.isEmpty()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
2229 | int position = flowPositions.at(scrollValueMap.at(horizontalScrollBar()->value())); | - | ||||||||||||||||||||||||
2230 | int maximum = flowPositions.at(scrollValueMap.at(horizontalScrollBar()->maximum())); | - | ||||||||||||||||||||||||
2231 | return (isRightToLeft() ? maximum - position : position); never executed: return (isRightToLeft() ? maximum - position : position);
| 0 | ||||||||||||||||||||||||
2232 | } | - | ||||||||||||||||||||||||
2233 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2234 | return QCommonListViewBase::horizontalOffset(); never executed: return QCommonListViewBase::horizontalOffset(); | 0 | ||||||||||||||||||||||||
2235 | } | - | ||||||||||||||||||||||||
2236 | - | |||||||||||||||||||||||||
2237 | int QListModeViewBase::verticalOffset() const | - | ||||||||||||||||||||||||
2238 | { | - | ||||||||||||||||||||||||
2239 | if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) {
| 0 | ||||||||||||||||||||||||
2240 | if (isWrapping()) {
| 0 | ||||||||||||||||||||||||
2241 | if (flow() == QListView::LeftToRight && !segmentPositions.isEmpty()) {
| 0 | ||||||||||||||||||||||||
2242 | int value = verticalScrollBar()->value(); | - | ||||||||||||||||||||||||
2243 | if (value >= segmentPositions.count())
| 0 | ||||||||||||||||||||||||
2244 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
2245 | return segmentPositions.at(value) - spacing(); never executed: return segmentPositions.at(value) - spacing(); | 0 | ||||||||||||||||||||||||
2246 | } | - | ||||||||||||||||||||||||
2247 | } else if (flow() == QListView::TopToBottom && !flowPositions.isEmpty()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
2248 | int value = verticalScrollBar()->value(); | - | ||||||||||||||||||||||||
2249 | if (value > scrollValueMap.count())
| 0 | ||||||||||||||||||||||||
2250 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
2251 | return flowPositions.at(scrollValueMap.at(value)) - spacing(); never executed: return flowPositions.at(scrollValueMap.at(value)) - spacing(); | 0 | ||||||||||||||||||||||||
2252 | } | - | ||||||||||||||||||||||||
2253 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2254 | return QCommonListViewBase::verticalOffset(); never executed: return QCommonListViewBase::verticalOffset(); | 0 | ||||||||||||||||||||||||
2255 | } | - | ||||||||||||||||||||||||
2256 | - | |||||||||||||||||||||||||
2257 | int QListModeViewBase::horizontalScrollToValue(int index, QListView::ScrollHint hint, | - | ||||||||||||||||||||||||
2258 | bool leftOf, bool rightOf, const QRect &area, const QRect &rect) const | - | ||||||||||||||||||||||||
2259 | { | - | ||||||||||||||||||||||||
2260 | if (horizontalScrollMode() != QAbstractItemView::ScrollPerItem)
| 0 | ||||||||||||||||||||||||
2261 | return QCommonListViewBase::horizontalScrollToValue(index, hint, leftOf, rightOf, area, rect); never executed: return QCommonListViewBase::horizontalScrollToValue(index, hint, leftOf, rightOf, area, rect); | 0 | ||||||||||||||||||||||||
2262 | - | |||||||||||||||||||||||||
2263 | int value; | - | ||||||||||||||||||||||||
2264 | if (scrollValueMap.isEmpty())
| 0 | ||||||||||||||||||||||||
2265 | value = 0; never executed: value = 0; | 0 | ||||||||||||||||||||||||
2266 | else | - | ||||||||||||||||||||||||
2267 | value = qBound(0, scrollValueMap.at(horizontalScrollBar()->value()), flowPositions.count() - 1); never executed: value = qBound(0, scrollValueMap.at(horizontalScrollBar()->value()), flowPositions.count() - 1); | 0 | ||||||||||||||||||||||||
2268 | if (leftOf)
| 0 | ||||||||||||||||||||||||
2269 | hint = QListView::PositionAtTop; never executed: hint = QListView::PositionAtTop; | 0 | ||||||||||||||||||||||||
2270 | else if (rightOf)
| 0 | ||||||||||||||||||||||||
2271 | hint = QListView::PositionAtBottom; never executed: hint = QListView::PositionAtBottom; | 0 | ||||||||||||||||||||||||
2272 | if (hint == QListView::EnsureVisible)
| 0 | ||||||||||||||||||||||||
2273 | return value; never executed: return value; | 0 | ||||||||||||||||||||||||
2274 | - | |||||||||||||||||||||||||
2275 | return perItemScrollToValue(index, value, area.width(), hint, Qt::Horizontal, isWrapping(), rect.width()); never executed: return perItemScrollToValue(index, value, area.width(), hint, Qt::Horizontal, isWrapping(), rect.width()); | 0 | ||||||||||||||||||||||||
2276 | } | - | ||||||||||||||||||||||||
2277 | - | |||||||||||||||||||||||||
2278 | void QListModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) | - | ||||||||||||||||||||||||
2279 | { | - | ||||||||||||||||||||||||
2280 | // ### reorder this logic | - | ||||||||||||||||||||||||
2281 | const int verticalValue = verticalScrollBar()->value(); | - | ||||||||||||||||||||||||
2282 | const int horizontalValue = horizontalScrollBar()->value(); | - | ||||||||||||||||||||||||
2283 | const bool vertical = (verticalScrollMode() == QAbstractItemView::ScrollPerItem); | - | ||||||||||||||||||||||||
2284 | const bool horizontal = (horizontalScrollMode() == QAbstractItemView::ScrollPerItem); | - | ||||||||||||||||||||||||
2285 | - | |||||||||||||||||||||||||
2286 | if (isWrapping()) {
| 0 | ||||||||||||||||||||||||
2287 | if (segmentPositions.isEmpty())
| 0 | ||||||||||||||||||||||||
2288 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2289 | const int max = segmentPositions.count() - 1; | - | ||||||||||||||||||||||||
2290 | if (horizontal && flow() == QListView::TopToBottom && dx != 0) {
| 0 | ||||||||||||||||||||||||
2291 | int currentValue = qBound(0, horizontalValue, max); | - | ||||||||||||||||||||||||
2292 | int previousValue = qBound(0, currentValue + dx, max); | - | ||||||||||||||||||||||||
2293 | int currentCoordinate = segmentPositions.at(currentValue) - spacing(); | - | ||||||||||||||||||||||||
2294 | int previousCoordinate = segmentPositions.at(previousValue) - spacing(); | - | ||||||||||||||||||||||||
2295 | dx = previousCoordinate - currentCoordinate; | - | ||||||||||||||||||||||||
2296 | } else if (vertical && flow() == QListView::LeftToRight && dy != 0) { never executed: end of block
| 0 | ||||||||||||||||||||||||
2297 | int currentValue = qBound(0, verticalValue, max); | - | ||||||||||||||||||||||||
2298 | int previousValue = qBound(0, currentValue + dy, max); | - | ||||||||||||||||||||||||
2299 | int currentCoordinate = segmentPositions.at(currentValue) - spacing(); | - | ||||||||||||||||||||||||
2300 | int previousCoordinate = segmentPositions.at(previousValue) - spacing(); | - | ||||||||||||||||||||||||
2301 | dy = previousCoordinate - currentCoordinate; | - | ||||||||||||||||||||||||
2302 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2303 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2304 | if (flowPositions.isEmpty())
| 0 | ||||||||||||||||||||||||
2305 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2306 | const int max = scrollValueMap.count() - 1; | - | ||||||||||||||||||||||||
2307 | if (vertical && flow() == QListView::TopToBottom && dy != 0) {
| 0 | ||||||||||||||||||||||||
2308 | int currentValue = qBound(0, verticalValue, max); | - | ||||||||||||||||||||||||
2309 | int previousValue = qBound(0, currentValue + dy, max); | - | ||||||||||||||||||||||||
2310 | int currentCoordinate = flowPositions.at(scrollValueMap.at(currentValue)); | - | ||||||||||||||||||||||||
2311 | int previousCoordinate = flowPositions.at(scrollValueMap.at(previousValue)); | - | ||||||||||||||||||||||||
2312 | dy = previousCoordinate - currentCoordinate; | - | ||||||||||||||||||||||||
2313 | } else if (horizontal && flow() == QListView::LeftToRight && dx != 0) { never executed: end of block
| 0 | ||||||||||||||||||||||||
2314 | int currentValue = qBound(0, horizontalValue, max); | - | ||||||||||||||||||||||||
2315 | int previousValue = qBound(0, currentValue + dx, max); | - | ||||||||||||||||||||||||
2316 | int currentCoordinate = flowPositions.at(scrollValueMap.at(currentValue)); | - | ||||||||||||||||||||||||
2317 | int previousCoordinate = flowPositions.at(scrollValueMap.at(previousValue)); | - | ||||||||||||||||||||||||
2318 | dx = previousCoordinate - currentCoordinate; | - | ||||||||||||||||||||||||
2319 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2320 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2321 | QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand); | - | ||||||||||||||||||||||||
2322 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2323 | - | |||||||||||||||||||||||||
2324 | bool QListModeViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max) | - | ||||||||||||||||||||||||
2325 | { | - | ||||||||||||||||||||||||
2326 | doStaticLayout(info); | - | ||||||||||||||||||||||||
2327 | if (batchStartRow > max) { // stop items layout
| 0 | ||||||||||||||||||||||||
2328 | flowPositions.resize(flowPositions.count()); | - | ||||||||||||||||||||||||
2329 | segmentPositions.resize(segmentPositions.count()); | - | ||||||||||||||||||||||||
2330 | segmentStartRows.resize(segmentStartRows.count()); | - | ||||||||||||||||||||||||
2331 | return true; // done never executed: return true; | 0 | ||||||||||||||||||||||||
2332 | } | - | ||||||||||||||||||||||||
2333 | return false; // not done never executed: return false; | 0 | ||||||||||||||||||||||||
2334 | } | - | ||||||||||||||||||||||||
2335 | - | |||||||||||||||||||||||||
2336 | QListViewItem QListModeViewBase::indexToListViewItem(const QModelIndex &index) const | - | ||||||||||||||||||||||||
2337 | { | - | ||||||||||||||||||||||||
2338 | if (flowPositions.isEmpty()
| 0 | ||||||||||||||||||||||||
2339 | || segmentPositions.isEmpty()
| 0 | ||||||||||||||||||||||||
2340 | || index.row() >= flowPositions.count())
| 0 | ||||||||||||||||||||||||
2341 | return QListViewItem(); never executed: return QListViewItem(); | 0 | ||||||||||||||||||||||||
2342 | - | |||||||||||||||||||||||||
2343 | const int segment = qBinarySearch<int>(segmentStartRows, index.row(), | - | ||||||||||||||||||||||||
2344 | 0, segmentStartRows.count() - 1); | - | ||||||||||||||||||||||||
2345 | - | |||||||||||||||||||||||||
2346 | - | |||||||||||||||||||||||||
2347 | QStyleOptionViewItem options = viewOptions(); | - | ||||||||||||||||||||||||
2348 | options.rect.setSize(contentsSize); | - | ||||||||||||||||||||||||
2349 | QSize size = (uniformItemSizes() && cachedItemSize().isValid())
| 0 | ||||||||||||||||||||||||
2350 | ? cachedItemSize() : itemSize(options, index); | - | ||||||||||||||||||||||||
2351 | - | |||||||||||||||||||||||||
2352 | QPoint pos; | - | ||||||||||||||||||||||||
2353 | if (flow() == QListView::LeftToRight) {
| 0 | ||||||||||||||||||||||||
2354 | pos.setX(flowPositions.at(index.row())); | - | ||||||||||||||||||||||||
2355 | pos.setY(segmentPositions.at(segment)); | - | ||||||||||||||||||||||||
2356 | } else { // TopToBottom never executed: end of block | 0 | ||||||||||||||||||||||||
2357 | pos.setY(flowPositions.at(index.row())); | - | ||||||||||||||||||||||||
2358 | pos.setX(segmentPositions.at(segment)); | - | ||||||||||||||||||||||||
2359 | if (isWrapping()) { // make the items as wide as the segment
| 0 | ||||||||||||||||||||||||
2360 | int right = (segment + 1 >= segmentPositions.count()
| 0 | ||||||||||||||||||||||||
2361 | ? contentsSize.width() | - | ||||||||||||||||||||||||
2362 | : segmentPositions.at(segment + 1)); | - | ||||||||||||||||||||||||
2363 | size.setWidth(right - pos.x()); | - | ||||||||||||||||||||||||
2364 | } else { // make the items as wide as the viewport never executed: end of block | 0 | ||||||||||||||||||||||||
2365 | size.setWidth(qMax(size.width(), viewport()->width() - 2 * spacing())); | - | ||||||||||||||||||||||||
2366 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2367 | } | - | ||||||||||||||||||||||||
2368 | - | |||||||||||||||||||||||||
2369 | return QListViewItem(QRect(pos, size), index.row()); never executed: return QListViewItem(QRect(pos, size), index.row()); | 0 | ||||||||||||||||||||||||
2370 | } | - | ||||||||||||||||||||||||
2371 | - | |||||||||||||||||||||||||
2372 | QPoint QListModeViewBase::initStaticLayout(const QListViewLayoutInfo &info) | - | ||||||||||||||||||||||||
2373 | { | - | ||||||||||||||||||||||||
2374 | int x, y; | - | ||||||||||||||||||||||||
2375 | if (info.first == 0) {
| 0 | ||||||||||||||||||||||||
2376 | flowPositions.clear(); | - | ||||||||||||||||||||||||
2377 | segmentPositions.clear(); | - | ||||||||||||||||||||||||
2378 | segmentStartRows.clear(); | - | ||||||||||||||||||||||||
2379 | segmentExtents.clear(); | - | ||||||||||||||||||||||||
2380 | scrollValueMap.clear(); | - | ||||||||||||||||||||||||
2381 | x = info.bounds.left() + info.spacing; | - | ||||||||||||||||||||||||
2382 | y = info.bounds.top() + info.spacing; | - | ||||||||||||||||||||||||
2383 | segmentPositions.append(info.flow == QListView::LeftToRight ? y : x); | - | ||||||||||||||||||||||||
2384 | segmentStartRows.append(0); | - | ||||||||||||||||||||||||
2385 | } else if (info.wrap) { never executed: end of block
| 0 | ||||||||||||||||||||||||
2386 | if (info.flow == QListView::LeftToRight) {
| 0 | ||||||||||||||||||||||||
2387 | x = batchSavedPosition; | - | ||||||||||||||||||||||||
2388 | y = segmentPositions.last(); | - | ||||||||||||||||||||||||
2389 | } else { // flow == QListView::TopToBottom never executed: end of block | 0 | ||||||||||||||||||||||||
2390 | x = segmentPositions.last(); | - | ||||||||||||||||||||||||
2391 | y = batchSavedPosition; | - | ||||||||||||||||||||||||
2392 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2393 | } else { // not first and not wrap | - | ||||||||||||||||||||||||
2394 | if (info.flow == QListView::LeftToRight) {
| 0 | ||||||||||||||||||||||||
2395 | x = batchSavedPosition; | - | ||||||||||||||||||||||||
2396 | y = info.bounds.top() + info.spacing; | - | ||||||||||||||||||||||||
2397 | } else { // flow == QListView::TopToBottom never executed: end of block | 0 | ||||||||||||||||||||||||
2398 | x = info.bounds.left() + info.spacing; | - | ||||||||||||||||||||||||
2399 | y = batchSavedPosition; | - | ||||||||||||||||||||||||
2400 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2401 | } | - | ||||||||||||||||||||||||
2402 | return QPoint(x, y); never executed: return QPoint(x, y); | 0 | ||||||||||||||||||||||||
2403 | } | - | ||||||||||||||||||||||||
2404 | - | |||||||||||||||||||||||||
2405 | /*! | - | ||||||||||||||||||||||||
2406 | \internal | - | ||||||||||||||||||||||||
2407 | */ | - | ||||||||||||||||||||||||
2408 | void QListModeViewBase::doStaticLayout(const QListViewLayoutInfo &info) | - | ||||||||||||||||||||||||
2409 | { | - | ||||||||||||||||||||||||
2410 | const bool useItemSize = !info.grid.isValid(); | - | ||||||||||||||||||||||||
2411 | const QPoint topLeft = initStaticLayout(info); | - | ||||||||||||||||||||||||
2412 | QStyleOptionViewItem option = viewOptions(); | - | ||||||||||||||||||||||||
2413 | option.rect = info.bounds; | - | ||||||||||||||||||||||||
2414 | option.rect.adjust(info.spacing, info.spacing, -info.spacing, -info.spacing); | - | ||||||||||||||||||||||||
2415 | - | |||||||||||||||||||||||||
2416 | // The static layout data structures are as follows: | - | ||||||||||||||||||||||||
2417 | // One vector contains the coordinate in the direction of layout flow. | - | ||||||||||||||||||||||||
2418 | // Another vector contains the coordinates of the segments. | - | ||||||||||||||||||||||||
2419 | // A third vector contains the index (model row) of the first item | - | ||||||||||||||||||||||||
2420 | // of each segment. | - | ||||||||||||||||||||||||
2421 | - | |||||||||||||||||||||||||
2422 | int segStartPosition; | - | ||||||||||||||||||||||||
2423 | int segEndPosition; | - | ||||||||||||||||||||||||
2424 | int deltaFlowPosition; | - | ||||||||||||||||||||||||
2425 | int deltaSegPosition; | - | ||||||||||||||||||||||||
2426 | int deltaSegHint; | - | ||||||||||||||||||||||||
2427 | int flowPosition; | - | ||||||||||||||||||||||||
2428 | int segPosition; | - | ||||||||||||||||||||||||
2429 | - | |||||||||||||||||||||||||
2430 | if (info.flow == QListView::LeftToRight) {
| 0 | ||||||||||||||||||||||||
2431 | segStartPosition = info.bounds.left(); | - | ||||||||||||||||||||||||
2432 | segEndPosition = info.bounds.width(); | - | ||||||||||||||||||||||||
2433 | flowPosition = topLeft.x(); | - | ||||||||||||||||||||||||
2434 | segPosition = topLeft.y(); | - | ||||||||||||||||||||||||
2435 | deltaFlowPosition = info.grid.width(); // dx | - | ||||||||||||||||||||||||
2436 | deltaSegPosition = useItemSize ? batchSavedDeltaSeg : info.grid.height(); // dy
| 0 | ||||||||||||||||||||||||
2437 | deltaSegHint = info.grid.height(); | - | ||||||||||||||||||||||||
2438 | } else { // flow == QListView::TopToBottom never executed: end of block | 0 | ||||||||||||||||||||||||
2439 | segStartPosition = info.bounds.top(); | - | ||||||||||||||||||||||||
2440 | segEndPosition = info.bounds.height(); | - | ||||||||||||||||||||||||
2441 | flowPosition = topLeft.y(); | - | ||||||||||||||||||||||||
2442 | segPosition = topLeft.x(); | - | ||||||||||||||||||||||||
2443 | deltaFlowPosition = info.grid.height(); // dy | - | ||||||||||||||||||||||||
2444 | deltaSegPosition = useItemSize ? batchSavedDeltaSeg : info.grid.width(); // dx
| 0 | ||||||||||||||||||||||||
2445 | deltaSegHint = info.grid.width(); | - | ||||||||||||||||||||||||
2446 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2447 | - | |||||||||||||||||||||||||
2448 | for (int row = info.first; row <= info.last; ++row) {
| 0 | ||||||||||||||||||||||||
2449 | if (isHidden(row)) { // ###
| 0 | ||||||||||||||||||||||||
2450 | flowPositions.append(flowPosition); | - | ||||||||||||||||||||||||
2451 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2452 | // if we are not using a grid, we need to find the deltas | - | ||||||||||||||||||||||||
2453 | if (useItemSize) {
| 0 | ||||||||||||||||||||||||
2454 | QSize hint = itemSize(option, modelIndex(row)); | - | ||||||||||||||||||||||||
2455 | if (info.flow == QListView::LeftToRight) {
| 0 | ||||||||||||||||||||||||
2456 | deltaFlowPosition = hint.width() + info.spacing; | - | ||||||||||||||||||||||||
2457 | deltaSegHint = hint.height() + info.spacing; | - | ||||||||||||||||||||||||
2458 | } else { // TopToBottom never executed: end of block | 0 | ||||||||||||||||||||||||
2459 | deltaFlowPosition = hint.height() + info.spacing; | - | ||||||||||||||||||||||||
2460 | deltaSegHint = hint.width() + info.spacing; | - | ||||||||||||||||||||||||
2461 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2462 | } | - | ||||||||||||||||||||||||
2463 | // create new segment | - | ||||||||||||||||||||||||
2464 | if (info.wrap && (flowPosition + deltaFlowPosition >= segEndPosition)) {
| 0 | ||||||||||||||||||||||||
2465 | segmentExtents.append(flowPosition); | - | ||||||||||||||||||||||||
2466 | flowPosition = info.spacing + segStartPosition; | - | ||||||||||||||||||||||||
2467 | segPosition += deltaSegPosition; | - | ||||||||||||||||||||||||
2468 | if (info.wrap)
| 0 | ||||||||||||||||||||||||
2469 | segPosition += info.spacing; never executed: segPosition += info.spacing; | 0 | ||||||||||||||||||||||||
2470 | segmentPositions.append(segPosition); | - | ||||||||||||||||||||||||
2471 | segmentStartRows.append(row); | - | ||||||||||||||||||||||||
2472 | deltaSegPosition = 0; | - | ||||||||||||||||||||||||
2473 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2474 | // save the flow position of this item | - | ||||||||||||||||||||||||
2475 | scrollValueMap.append(flowPositions.count()); | - | ||||||||||||||||||||||||
2476 | flowPositions.append(flowPosition); | - | ||||||||||||||||||||||||
2477 | // prepare for the next item | - | ||||||||||||||||||||||||
2478 | deltaSegPosition = qMax(deltaSegHint, deltaSegPosition); | - | ||||||||||||||||||||||||
2479 | flowPosition += info.spacing + deltaFlowPosition; | - | ||||||||||||||||||||||||
2480 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2481 | } | - | ||||||||||||||||||||||||
2482 | // used when laying out next batch | - | ||||||||||||||||||||||||
2483 | batchSavedPosition = flowPosition; | - | ||||||||||||||||||||||||
2484 | batchSavedDeltaSeg = deltaSegPosition; | - | ||||||||||||||||||||||||
2485 | batchStartRow = info.last + 1; | - | ||||||||||||||||||||||||
2486 | if (info.last == info.max)
| 0 | ||||||||||||||||||||||||
2487 | flowPosition -= info.spacing; // remove extra spacing never executed: flowPosition -= info.spacing; | 0 | ||||||||||||||||||||||||
2488 | // set the contents size | - | ||||||||||||||||||||||||
2489 | QRect rect = info.bounds; | - | ||||||||||||||||||||||||
2490 | if (info.flow == QListView::LeftToRight) {
| 0 | ||||||||||||||||||||||||
2491 | rect.setRight(segmentPositions.count() == 1 ? flowPosition : info.bounds.right()); | - | ||||||||||||||||||||||||
2492 | rect.setBottom(segPosition + deltaSegPosition); | - | ||||||||||||||||||||||||
2493 | } else { // TopToBottom never executed: end of block | 0 | ||||||||||||||||||||||||
2494 | rect.setRight(segPosition + deltaSegPosition); | - | ||||||||||||||||||||||||
2495 | rect.setBottom(segmentPositions.count() == 1 ? flowPosition : info.bounds.bottom()); | - | ||||||||||||||||||||||||
2496 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2497 | contentsSize = QSize(rect.right(), rect.bottom()); | - | ||||||||||||||||||||||||
2498 | // if it is the last batch, save the end of the segments | - | ||||||||||||||||||||||||
2499 | if (info.last == info.max) {
| 0 | ||||||||||||||||||||||||
2500 | segmentExtents.append(flowPosition); | - | ||||||||||||||||||||||||
2501 | scrollValueMap.append(flowPositions.count()); | - | ||||||||||||||||||||||||
2502 | flowPositions.append(flowPosition); | - | ||||||||||||||||||||||||
2503 | segmentPositions.append(info.wrap ? segPosition + deltaSegPosition : INT_MAX); | - | ||||||||||||||||||||||||
2504 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2505 | // if the new items are visble, update the viewport | - | ||||||||||||||||||||||||
2506 | QRect changedRect(topLeft, rect.bottomRight()); | - | ||||||||||||||||||||||||
2507 | if (clipRect().intersects(changedRect))
| 0 | ||||||||||||||||||||||||
2508 | viewport()->update(); never executed: viewport()->update(); | 0 | ||||||||||||||||||||||||
2509 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2510 | - | |||||||||||||||||||||||||
2511 | /*! | - | ||||||||||||||||||||||||
2512 | \internal | - | ||||||||||||||||||||||||
2513 | Finds the set of items intersecting with \a area. | - | ||||||||||||||||||||||||
2514 | In this function, itemsize is counted from topleft to the start of the next item. | - | ||||||||||||||||||||||||
2515 | */ | - | ||||||||||||||||||||||||
2516 | QVector<QModelIndex> QListModeViewBase::intersectingSet(const QRect &area) const | - | ||||||||||||||||||||||||
2517 | { | - | ||||||||||||||||||||||||
2518 | QVector<QModelIndex> ret; | - | ||||||||||||||||||||||||
2519 | int segStartPosition; | - | ||||||||||||||||||||||||
2520 | int segEndPosition; | - | ||||||||||||||||||||||||
2521 | int flowStartPosition; | - | ||||||||||||||||||||||||
2522 | int flowEndPosition; | - | ||||||||||||||||||||||||
2523 | if (flow() == QListView::LeftToRight) {
| 0 | ||||||||||||||||||||||||
2524 | segStartPosition = area.top(); | - | ||||||||||||||||||||||||
2525 | segEndPosition = area.bottom(); | - | ||||||||||||||||||||||||
2526 | flowStartPosition = area.left(); | - | ||||||||||||||||||||||||
2527 | flowEndPosition = area.right(); | - | ||||||||||||||||||||||||
2528 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2529 | segStartPosition = area.left(); | - | ||||||||||||||||||||||||
2530 | segEndPosition = area.right(); | - | ||||||||||||||||||||||||
2531 | flowStartPosition = area.top(); | - | ||||||||||||||||||||||||
2532 | flowEndPosition = area.bottom(); | - | ||||||||||||||||||||||||
2533 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2534 | if (segmentPositions.count() < 2 || flowPositions.isEmpty())
| 0 | ||||||||||||||||||||||||
2535 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
2536 | // the last segment position is actually the edge of the last segment | - | ||||||||||||||||||||||||
2537 | const int segLast = segmentPositions.count() - 2; | - | ||||||||||||||||||||||||
2538 | int seg = qBinarySearch<int>(segmentPositions, segStartPosition, 0, segLast + 1); | - | ||||||||||||||||||||||||
2539 | for (; seg <= segLast && segmentPositions.at(seg) <= segEndPosition; ++seg) {
| 0 | ||||||||||||||||||||||||
2540 | int first = segmentStartRows.at(seg); | - | ||||||||||||||||||||||||
2541 | int last = (seg < segLast ? segmentStartRows.at(seg + 1) : batchStartRow) - 1;
| 0 | ||||||||||||||||||||||||
2542 | if (segmentExtents.at(seg) < flowStartPosition)
| 0 | ||||||||||||||||||||||||
2543 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
2544 | int row = qBinarySearch<int>(flowPositions, flowStartPosition, first, last); | - | ||||||||||||||||||||||||
2545 | for (; row <= last && flowPositions.at(row) <= flowEndPosition; ++row) {
| 0 | ||||||||||||||||||||||||
2546 | if (isHidden(row))
| 0 | ||||||||||||||||||||||||
2547 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
2548 | QModelIndex index = modelIndex(row); | - | ||||||||||||||||||||||||
2549 | if (index.isValid())
| 0 | ||||||||||||||||||||||||
2550 | ret += index; never executed: ret += index; | 0 | ||||||||||||||||||||||||
2551 | #if 0 // for debugging | - | ||||||||||||||||||||||||
2552 | else | - | ||||||||||||||||||||||||
2553 | qWarning("intersectingSet: row %d was invalid", row); | - | ||||||||||||||||||||||||
2554 | #endif | - | ||||||||||||||||||||||||
2555 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2556 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2557 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
2558 | } | - | ||||||||||||||||||||||||
2559 | - | |||||||||||||||||||||||||
2560 | void QListModeViewBase::dataChanged(const QModelIndex &, const QModelIndex &) | - | ||||||||||||||||||||||||
2561 | { | - | ||||||||||||||||||||||||
2562 | dd->doDelayedItemsLayout(); | - | ||||||||||||||||||||||||
2563 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2564 | - | |||||||||||||||||||||||||
2565 | - | |||||||||||||||||||||||||
2566 | QRect QListModeViewBase::mapToViewport(const QRect &rect) const | - | ||||||||||||||||||||||||
2567 | { | - | ||||||||||||||||||||||||
2568 | if (isWrapping())
| 0 | ||||||||||||||||||||||||
2569 | return rect; never executed: return rect; | 0 | ||||||||||||||||||||||||
2570 | // If the listview is in "listbox-mode", the items are as wide as the view. | - | ||||||||||||||||||||||||
2571 | // But we don't shrink the items. | - | ||||||||||||||||||||||||
2572 | QRect result = rect; | - | ||||||||||||||||||||||||
2573 | if (flow() == QListView::TopToBottom) {
| 0 | ||||||||||||||||||||||||
2574 | result.setLeft(spacing()); | - | ||||||||||||||||||||||||
2575 | result.setWidth(qMax(rect.width(), qMax(contentsSize.width(), viewport()->width()) - 2 * spacing())); | - | ||||||||||||||||||||||||
2576 | } else { // LeftToRight never executed: end of block | 0 | ||||||||||||||||||||||||
2577 | result.setTop(spacing()); | - | ||||||||||||||||||||||||
2578 | result.setHeight(qMax(rect.height(), qMax(contentsSize.height(), viewport()->height()) - 2 * spacing())); | - | ||||||||||||||||||||||||
2579 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2580 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
2581 | } | - | ||||||||||||||||||||||||
2582 | - | |||||||||||||||||||||||||
2583 | int QListModeViewBase::perItemScrollingPageSteps(int length, int bounds, bool wrap) const | - | ||||||||||||||||||||||||
2584 | { | - | ||||||||||||||||||||||||
2585 | QVector<int> positions; | - | ||||||||||||||||||||||||
2586 | if (wrap)
| 0 | ||||||||||||||||||||||||
2587 | positions = segmentPositions; never executed: positions = segmentPositions; | 0 | ||||||||||||||||||||||||
2588 | else if (!flowPositions.isEmpty()) {
| 0 | ||||||||||||||||||||||||
2589 | positions.reserve(scrollValueMap.size()); | - | ||||||||||||||||||||||||
2590 | foreach (int itemShown, scrollValueMap) | - | ||||||||||||||||||||||||
2591 | positions.append(flowPositions.at(itemShown)); never executed: positions.append(flowPositions.at(itemShown)); | 0 | ||||||||||||||||||||||||
2592 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2593 | if (positions.isEmpty() || bounds <= length)
| 0 | ||||||||||||||||||||||||
2594 | return positions.count(); never executed: return positions.count(); | 0 | ||||||||||||||||||||||||
2595 | if (uniformItemSizes()) {
| 0 | ||||||||||||||||||||||||
2596 | for (int i = 1; i < positions.count(); ++i)
| 0 | ||||||||||||||||||||||||
2597 | if (positions.at(i) > 0)
| 0 | ||||||||||||||||||||||||
2598 | return length / positions.at(i); never executed: return length / positions.at(i); | 0 | ||||||||||||||||||||||||
2599 | return 0; // all items had height 0 never executed: return 0; | 0 | ||||||||||||||||||||||||
2600 | } | - | ||||||||||||||||||||||||
2601 | int pageSteps = 0; | - | ||||||||||||||||||||||||
2602 | int steps = positions.count() - 1; | - | ||||||||||||||||||||||||
2603 | int max = qMax(length, bounds); | - | ||||||||||||||||||||||||
2604 | int min = qMin(length, bounds); | - | ||||||||||||||||||||||||
2605 | int pos = min - (max - positions.last()); | - | ||||||||||||||||||||||||
2606 | - | |||||||||||||||||||||||||
2607 | while (pos >= 0 && steps > 0) {
| 0 | ||||||||||||||||||||||||
2608 | pos -= (positions.at(steps) - positions.at(steps - 1)); | - | ||||||||||||||||||||||||
2609 | if (pos >= 0) //this item should be visible
| 0 | ||||||||||||||||||||||||
2610 | ++pageSteps; never executed: ++pageSteps; | 0 | ||||||||||||||||||||||||
2611 | --steps; | - | ||||||||||||||||||||||||
2612 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2613 | - | |||||||||||||||||||||||||
2614 | // at this point we know that positions has at least one entry | - | ||||||||||||||||||||||||
2615 | return qMax(pageSteps, 1); never executed: return qMax(pageSteps, 1); | 0 | ||||||||||||||||||||||||
2616 | } | - | ||||||||||||||||||||||||
2617 | - | |||||||||||||||||||||||||
2618 | int QListModeViewBase::perItemScrollToValue(int index, int scrollValue, int viewportSize, | - | ||||||||||||||||||||||||
2619 | QAbstractItemView::ScrollHint hint, | - | ||||||||||||||||||||||||
2620 | Qt::Orientation orientation, bool wrap, int itemExtent) const | - | ||||||||||||||||||||||||
2621 | { | - | ||||||||||||||||||||||||
2622 | if (index < 0)
| 0 | ||||||||||||||||||||||||
2623 | return scrollValue; never executed: return scrollValue; | 0 | ||||||||||||||||||||||||
2624 | - | |||||||||||||||||||||||||
2625 | itemExtent += spacing(); | - | ||||||||||||||||||||||||
2626 | QVector<int> visibleFlowPositions; | - | ||||||||||||||||||||||||
2627 | visibleFlowPositions.reserve(flowPositions.count() - 1); | - | ||||||||||||||||||||||||
2628 | for (int i = 0; i < flowPositions.count() - 1; i++) { // flowPositions count is +1 larger than actual row count
| 0 | ||||||||||||||||||||||||
2629 | if (!isHidden(i))
| 0 | ||||||||||||||||||||||||
2630 | visibleFlowPositions.append(flowPositions.at(i)); never executed: visibleFlowPositions.append(flowPositions.at(i)); | 0 | ||||||||||||||||||||||||
2631 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2632 | - | |||||||||||||||||||||||||
2633 | if (!wrap) {
| 0 | ||||||||||||||||||||||||
2634 | int topIndex = index; | - | ||||||||||||||||||||||||
2635 | const int bottomIndex = topIndex; | - | ||||||||||||||||||||||||
2636 | const int bottomCoordinate = visibleFlowPositions.at(index); | - | ||||||||||||||||||||||||
2637 | - | |||||||||||||||||||||||||
2638 | while (topIndex > 0 &&
| 0 | ||||||||||||||||||||||||
2639 | (bottomCoordinate - visibleFlowPositions.at(topIndex - 1) + itemExtent) <= (viewportSize)) {
| 0 | ||||||||||||||||||||||||
2640 | topIndex--; | - | ||||||||||||||||||||||||
2641 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2642 | - | |||||||||||||||||||||||||
2643 | const int itemCount = bottomIndex - topIndex + 1; | - | ||||||||||||||||||||||||
2644 | switch (hint) { | - | ||||||||||||||||||||||||
2645 | case QAbstractItemView::PositionAtTop: never executed: case QAbstractItemView::PositionAtTop: | 0 | ||||||||||||||||||||||||
2646 | return index; never executed: return index; | 0 | ||||||||||||||||||||||||
2647 | case QAbstractItemView::PositionAtBottom: never executed: case QAbstractItemView::PositionAtBottom: | 0 | ||||||||||||||||||||||||
2648 | return index - itemCount + 1; never executed: return index - itemCount + 1; | 0 | ||||||||||||||||||||||||
2649 | case QAbstractItemView::PositionAtCenter: never executed: case QAbstractItemView::PositionAtCenter: | 0 | ||||||||||||||||||||||||
2650 | return index - (itemCount / 2); never executed: return index - (itemCount / 2); | 0 | ||||||||||||||||||||||||
2651 | default: never executed: default: | 0 | ||||||||||||||||||||||||
2652 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2653 | } | - | ||||||||||||||||||||||||
2654 | } else { // wrapping | - | ||||||||||||||||||||||||
2655 | Qt::Orientation flowOrientation = (flow() == QListView::LeftToRight
| 0 | ||||||||||||||||||||||||
2656 | ? Qt::Horizontal : Qt::Vertical); | - | ||||||||||||||||||||||||
2657 | if (flowOrientation == orientation) { // scrolling in the "flow" direction
| 0 | ||||||||||||||||||||||||
2658 | // ### wrapped scrolling in the flow direction | - | ||||||||||||||||||||||||
2659 | return visibleFlowPositions.at(index); // ### always pixel based for now never executed: return visibleFlowPositions.at(index); | 0 | ||||||||||||||||||||||||
2660 | } else if (!segmentStartRows.isEmpty()) { // we are scrolling in the "segment" direction
| 0 | ||||||||||||||||||||||||
2661 | int segment = qBinarySearch<int>(segmentStartRows, index, 0, segmentStartRows.count() - 1); | - | ||||||||||||||||||||||||
2662 | int leftSegment = segment; | - | ||||||||||||||||||||||||
2663 | const int rightSegment = leftSegment; | - | ||||||||||||||||||||||||
2664 | const int bottomCoordinate = segmentPositions.at(segment); | - | ||||||||||||||||||||||||
2665 | - | |||||||||||||||||||||||||
2666 | while (leftSegment > scrollValue &&
| 0 | ||||||||||||||||||||||||
2667 | (bottomCoordinate - segmentPositions.at(leftSegment-1) + itemExtent) <= (viewportSize)) {
| 0 | ||||||||||||||||||||||||
2668 | leftSegment--; | - | ||||||||||||||||||||||||
2669 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2670 | - | |||||||||||||||||||||||||
2671 | const int segmentCount = rightSegment - leftSegment + 1; | - | ||||||||||||||||||||||||
2672 | switch (hint) { | - | ||||||||||||||||||||||||
2673 | case QAbstractItemView::PositionAtTop: never executed: case QAbstractItemView::PositionAtTop: | 0 | ||||||||||||||||||||||||
2674 | return segment; never executed: return segment; | 0 | ||||||||||||||||||||||||
2675 | case QAbstractItemView::PositionAtBottom: never executed: case QAbstractItemView::PositionAtBottom: | 0 | ||||||||||||||||||||||||
2676 | return segment - segmentCount + 1; never executed: return segment - segmentCount + 1; | 0 | ||||||||||||||||||||||||
2677 | case QAbstractItemView::PositionAtCenter: never executed: case QAbstractItemView::PositionAtCenter: | 0 | ||||||||||||||||||||||||
2678 | return segment - (segmentCount / 2); never executed: return segment - (segmentCount / 2); | 0 | ||||||||||||||||||||||||
2679 | default: never executed: default: | 0 | ||||||||||||||||||||||||
2680 | break; never executed: break; | 0 | ||||||||||||||||||||||||
2681 | } | - | ||||||||||||||||||||||||
2682 | } | - | ||||||||||||||||||||||||
2683 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2684 | return scrollValue; never executed: return scrollValue; | 0 | ||||||||||||||||||||||||
2685 | } | - | ||||||||||||||||||||||||
2686 | - | |||||||||||||||||||||||||
2687 | void QListModeViewBase::clear() | - | ||||||||||||||||||||||||
2688 | { | - | ||||||||||||||||||||||||
2689 | flowPositions.clear(); | - | ||||||||||||||||||||||||
2690 | segmentPositions.clear(); | - | ||||||||||||||||||||||||
2691 | segmentStartRows.clear(); | - | ||||||||||||||||||||||||
2692 | segmentExtents.clear(); | - | ||||||||||||||||||||||||
2693 | batchSavedPosition = 0; | - | ||||||||||||||||||||||||
2694 | batchStartRow = 0; | - | ||||||||||||||||||||||||
2695 | batchSavedDeltaSeg = 0; | - | ||||||||||||||||||||||||
2696 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2697 | - | |||||||||||||||||||||||||
2698 | /* | - | ||||||||||||||||||||||||
2699 | * IconMode ListView Implementation | - | ||||||||||||||||||||||||
2700 | */ | - | ||||||||||||||||||||||||
2701 | - | |||||||||||||||||||||||||
2702 | void QIconModeViewBase::setPositionForIndex(const QPoint &position, const QModelIndex &index) | - | ||||||||||||||||||||||||
2703 | { | - | ||||||||||||||||||||||||
2704 | if (index.row() >= items.count())
| 0 | ||||||||||||||||||||||||
2705 | return; never executed: return; | 0 | ||||||||||||||||||||||||
2706 | const QSize oldContents = contentsSize; | - | ||||||||||||||||||||||||
2707 | qq->update(index); // update old position | - | ||||||||||||||||||||||||
2708 | moveItem(index.row(), position); | - | ||||||||||||||||||||||||
2709 | qq->update(index); // update new position | - | ||||||||||||||||||||||||
2710 | - | |||||||||||||||||||||||||
2711 | if (contentsSize != oldContents)
| 0 | ||||||||||||||||||||||||
2712 | dd->viewUpdateGeometries(); // update the scroll bars never executed: dd->viewUpdateGeometries(); | 0 | ||||||||||||||||||||||||
2713 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2714 | - | |||||||||||||||||||||||||
2715 | void QIconModeViewBase::appendHiddenRow(int row) | - | ||||||||||||||||||||||||
2716 | { | - | ||||||||||||||||||||||||
2717 | if (row >= 0 && row < items.count()) //remove item
| 0 | ||||||||||||||||||||||||
2718 | tree.removeLeaf(items.at(row).rect(), row); never executed: tree.removeLeaf(items.at(row).rect(), row); | 0 | ||||||||||||||||||||||||
2719 | QCommonListViewBase::appendHiddenRow(row); | - | ||||||||||||||||||||||||
2720 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2721 | - | |||||||||||||||||||||||||
2722 | void QIconModeViewBase::removeHiddenRow(int row) | - | ||||||||||||||||||||||||
2723 | { | - | ||||||||||||||||||||||||
2724 | QCommonListViewBase::removeHiddenRow(row); | - | ||||||||||||||||||||||||
2725 | if (row >= 0 && row < items.count()) //insert item
| 0 | ||||||||||||||||||||||||
2726 | tree.insertLeaf(items.at(row).rect(), row); never executed: tree.insertLeaf(items.at(row).rect(), row); | 0 | ||||||||||||||||||||||||
2727 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2728 | - | |||||||||||||||||||||||||
2729 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
2730 | bool QIconModeViewBase::filterStartDrag(Qt::DropActions supportedActions) | - | ||||||||||||||||||||||||
2731 | { | - | ||||||||||||||||||||||||
2732 | // This function does the same thing as in QAbstractItemView::startDrag(), | - | ||||||||||||||||||||||||
2733 | // plus adding viewitems to the draggedItems list. | - | ||||||||||||||||||||||||
2734 | // We need these items to draw the drag items | - | ||||||||||||||||||||||||
2735 | QModelIndexList indexes = dd->selectionModel->selectedIndexes(); | - | ||||||||||||||||||||||||
2736 | if (indexes.count() > 0 ) {
| 0 | ||||||||||||||||||||||||
2737 | if (viewport()->acceptDrops()) {
| 0 | ||||||||||||||||||||||||
2738 | QModelIndexList::ConstIterator it = indexes.constBegin(); | - | ||||||||||||||||||||||||
2739 | for (; it != indexes.constEnd(); ++it)
| 0 | ||||||||||||||||||||||||
2740 | if (dd->model->flags(*it) & Qt::ItemIsDragEnabled
| 0 | ||||||||||||||||||||||||
2741 | && (*it).column() == dd->column)
| 0 | ||||||||||||||||||||||||
2742 | draggedItems.push_back(*it); never executed: draggedItems.push_back(*it); | 0 | ||||||||||||||||||||||||
2743 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2744 | - | |||||||||||||||||||||||||
2745 | QRect rect; | - | ||||||||||||||||||||||||
2746 | QPixmap pixmap = dd->renderToPixmap(indexes, &rect); | - | ||||||||||||||||||||||||
2747 | rect.adjust(horizontalOffset(), verticalOffset(), 0, 0); | - | ||||||||||||||||||||||||
2748 | QDrag *drag = new QDrag(qq); | - | ||||||||||||||||||||||||
2749 | drag->setMimeData(dd->model->mimeData(indexes)); | - | ||||||||||||||||||||||||
2750 | drag->setPixmap(pixmap); | - | ||||||||||||||||||||||||
2751 | drag->setHotSpot(dd->pressedPosition - rect.topLeft()); | - | ||||||||||||||||||||||||
2752 | Qt::DropAction action = drag->exec(supportedActions, dd->defaultDropAction); | - | ||||||||||||||||||||||||
2753 | draggedItems.clear(); | - | ||||||||||||||||||||||||
2754 | if (action == Qt::MoveAction)
| 0 | ||||||||||||||||||||||||
2755 | dd->clearOrRemove(); never executed: dd->clearOrRemove(); | 0 | ||||||||||||||||||||||||
2756 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2757 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
2758 | } | - | ||||||||||||||||||||||||
2759 | - | |||||||||||||||||||||||||
2760 | bool QIconModeViewBase::filterDropEvent(QDropEvent *e) | - | ||||||||||||||||||||||||
2761 | { | - | ||||||||||||||||||||||||
2762 | if (e->source() != qq)
| 0 | ||||||||||||||||||||||||
2763 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2764 | - | |||||||||||||||||||||||||
2765 | const QSize contents = contentsSize; | - | ||||||||||||||||||||||||
2766 | QPoint offset(horizontalOffset(), verticalOffset()); | - | ||||||||||||||||||||||||
2767 | QPoint end = e->pos() + offset; | - | ||||||||||||||||||||||||
2768 | if (qq->acceptDrops()) {
| 0 | ||||||||||||||||||||||||
2769 | const Qt::ItemFlags dropableFlags = Qt::ItemIsDropEnabled|Qt::ItemIsEnabled; | - | ||||||||||||||||||||||||
2770 | const QVector<QModelIndex> &dropIndices = intersectingSet(QRect(end, QSize(1, 1))); | - | ||||||||||||||||||||||||
2771 | foreach (const QModelIndex &index, dropIndices) | - | ||||||||||||||||||||||||
2772 | if ((index.flags() & dropableFlags) == dropableFlags)
| 0 | ||||||||||||||||||||||||
2773 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2774 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2775 | QPoint start = dd->pressedPosition; | - | ||||||||||||||||||||||||
2776 | QPoint delta = (dd->movement == QListView::Snap ? snapToGrid(end) - snapToGrid(start) : end - start);
| 0 | ||||||||||||||||||||||||
2777 | QList<QModelIndex> indexes = dd->selectionModel->selectedIndexes(); | - | ||||||||||||||||||||||||
2778 | for (int i = 0; i < indexes.count(); ++i) {
| 0 | ||||||||||||||||||||||||
2779 | QModelIndex index = indexes.at(i); | - | ||||||||||||||||||||||||
2780 | QRect rect = dd->rectForIndex(index); | - | ||||||||||||||||||||||||
2781 | viewport()->update(dd->mapToViewport(rect, false)); | - | ||||||||||||||||||||||||
2782 | QPoint dest = rect.topLeft() + delta; | - | ||||||||||||||||||||||||
2783 | if (qq->isRightToLeft())
| 0 | ||||||||||||||||||||||||
2784 | dest.setX(dd->flipX(dest.x()) - rect.width()); never executed: dest.setX(dd->flipX(dest.x()) - rect.width()); | 0 | ||||||||||||||||||||||||
2785 | moveItem(index.row(), dest); | - | ||||||||||||||||||||||||
2786 | qq->update(index); | - | ||||||||||||||||||||||||
2787 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2788 | dd->stopAutoScroll(); | - | ||||||||||||||||||||||||
2789 | draggedItems.clear(); | - | ||||||||||||||||||||||||
2790 | dd->emitIndexesMoved(indexes); | - | ||||||||||||||||||||||||
2791 | e->accept(); // we have handled the event | - | ||||||||||||||||||||||||
2792 | // if the size has not grown, we need to check if it has shrinked | - | ||||||||||||||||||||||||
2793 | if (contentsSize != contents) {
| 0 | ||||||||||||||||||||||||
2794 | if ((contentsSize.width() <= contents.width()
| 0 | ||||||||||||||||||||||||
2795 | || contentsSize.height() <= contents.height())) {
| 0 | ||||||||||||||||||||||||
2796 | updateContentsSize(); | - | ||||||||||||||||||||||||
2797 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2798 | dd->viewUpdateGeometries(); | - | ||||||||||||||||||||||||
2799 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2800 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
2801 | } | - | ||||||||||||||||||||||||
2802 | - | |||||||||||||||||||||||||
2803 | bool QIconModeViewBase::filterDragLeaveEvent(QDragLeaveEvent *e) | - | ||||||||||||||||||||||||
2804 | { | - | ||||||||||||||||||||||||
2805 | viewport()->update(draggedItemsRect()); // erase the area | - | ||||||||||||||||||||||||
2806 | draggedItemsPos = QPoint(-1, -1); // don't draw the dragged items | - | ||||||||||||||||||||||||
2807 | return QCommonListViewBase::filterDragLeaveEvent(e); never executed: return QCommonListViewBase::filterDragLeaveEvent(e); | 0 | ||||||||||||||||||||||||
2808 | } | - | ||||||||||||||||||||||||
2809 | - | |||||||||||||||||||||||||
2810 | bool QIconModeViewBase::filterDragMoveEvent(QDragMoveEvent *e) | - | ||||||||||||||||||||||||
2811 | { | - | ||||||||||||||||||||||||
2812 | if (e->source() != qq || !dd->canDrop(e))
| 0 | ||||||||||||||||||||||||
2813 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
2814 | - | |||||||||||||||||||||||||
2815 | // ignore by default | - | ||||||||||||||||||||||||
2816 | e->ignore(); | - | ||||||||||||||||||||||||
2817 | // get old dragged items rect | - | ||||||||||||||||||||||||
2818 | QRect itemsRect = this->itemsRect(draggedItems); | - | ||||||||||||||||||||||||
2819 | viewport()->update(itemsRect.translated(draggedItemsDelta())); | - | ||||||||||||||||||||||||
2820 | // update position | - | ||||||||||||||||||||||||
2821 | draggedItemsPos = e->pos(); | - | ||||||||||||||||||||||||
2822 | // get new items rect | - | ||||||||||||||||||||||||
2823 | viewport()->update(itemsRect.translated(draggedItemsDelta())); | - | ||||||||||||||||||||||||
2824 | // set the item under the cursor to current | - | ||||||||||||||||||||||||
2825 | QModelIndex index; | - | ||||||||||||||||||||||||
2826 | if (movement() == QListView::Snap) {
| 0 | ||||||||||||||||||||||||
2827 | QRect rect(snapToGrid(e->pos() + offset()), gridSize()); | - | ||||||||||||||||||||||||
2828 | const QVector<QModelIndex> intersectVector = intersectingSet(rect); | - | ||||||||||||||||||||||||
2829 | index = intersectVector.count() > 0 ? intersectVector.last() : QModelIndex();
| 0 | ||||||||||||||||||||||||
2830 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2831 | index = qq->indexAt(e->pos()); | - | ||||||||||||||||||||||||
2832 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2833 | // check if we allow drops here | - | ||||||||||||||||||||||||
2834 | if (draggedItems.contains(index))
| 0 | ||||||||||||||||||||||||
2835 | e->accept(); // allow changing item position never executed: e->accept(); | 0 | ||||||||||||||||||||||||
2836 | else if (dd->model->flags(index) & Qt::ItemIsDropEnabled)
| 0 | ||||||||||||||||||||||||
2837 | e->accept(); // allow dropping on dropenabled items never executed: e->accept(); | 0 | ||||||||||||||||||||||||
2838 | else if (!index.isValid())
| 0 | ||||||||||||||||||||||||
2839 | e->accept(); // allow dropping in empty areas never executed: e->accept(); | 0 | ||||||||||||||||||||||||
2840 | - | |||||||||||||||||||||||||
2841 | // the event was treated. do autoscrolling | - | ||||||||||||||||||||||||
2842 | if (dd->shouldAutoScroll(e->pos()))
| 0 | ||||||||||||||||||||||||
2843 | dd->startAutoScroll(); never executed: dd->startAutoScroll(); | 0 | ||||||||||||||||||||||||
2844 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
2845 | } | - | ||||||||||||||||||||||||
2846 | #endif // QT_NO_DRAGANDDROP | - | ||||||||||||||||||||||||
2847 | - | |||||||||||||||||||||||||
2848 | void QIconModeViewBase::setRowCount(int rowCount) | - | ||||||||||||||||||||||||
2849 | { | - | ||||||||||||||||||||||||
2850 | tree.create(qMax(rowCount - hiddenCount(), 0)); | - | ||||||||||||||||||||||||
2851 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2852 | - | |||||||||||||||||||||||||
2853 | void QIconModeViewBase::scrollContentsBy(int dx, int dy, bool scrollElasticBand) | - | ||||||||||||||||||||||||
2854 | { | - | ||||||||||||||||||||||||
2855 | if (scrollElasticBand)
| 0 | ||||||||||||||||||||||||
2856 | dd->scrollElasticBandBy(isRightToLeft() ? -dx : dx, dy); never executed: dd->scrollElasticBandBy(isRightToLeft() ? -dx : dx, dy); | 0 | ||||||||||||||||||||||||
2857 | - | |||||||||||||||||||||||||
2858 | QCommonListViewBase::scrollContentsBy(dx, dy, scrollElasticBand); | - | ||||||||||||||||||||||||
2859 | if (!draggedItems.isEmpty())
| 0 | ||||||||||||||||||||||||
2860 | viewport()->update(draggedItemsRect().translated(dx, dy)); never executed: viewport()->update(draggedItemsRect().translated(dx, dy)); | 0 | ||||||||||||||||||||||||
2861 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2862 | - | |||||||||||||||||||||||||
2863 | void QIconModeViewBase::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) | - | ||||||||||||||||||||||||
2864 | { | - | ||||||||||||||||||||||||
2865 | if (column() >= topLeft.column() && column() <= bottomRight.column()) {
| 0 | ||||||||||||||||||||||||
2866 | QStyleOptionViewItem option = viewOptions(); | - | ||||||||||||||||||||||||
2867 | int bottom = qMin(items.count(), bottomRight.row() + 1); | - | ||||||||||||||||||||||||
2868 | for (int row = topLeft.row(); row < bottom; ++row)
| 0 | ||||||||||||||||||||||||
2869 | items[row].resize(itemSize(option, modelIndex(row))); never executed: items[row].resize(itemSize(option, modelIndex(row))); | 0 | ||||||||||||||||||||||||
2870 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2871 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2872 | - | |||||||||||||||||||||||||
2873 | bool QIconModeViewBase::doBatchedItemLayout(const QListViewLayoutInfo &info, int max) | - | ||||||||||||||||||||||||
2874 | { | - | ||||||||||||||||||||||||
2875 | if (info.last >= items.count()) {
| 0 | ||||||||||||||||||||||||
2876 | //first we create the items | - | ||||||||||||||||||||||||
2877 | QStyleOptionViewItem option = viewOptions(); | - | ||||||||||||||||||||||||
2878 | for (int row = items.count(); row <= info.last; ++row) {
| 0 | ||||||||||||||||||||||||
2879 | QSize size = itemSize(option, modelIndex(row)); | - | ||||||||||||||||||||||||
2880 | QListViewItem item(QRect(0, 0, size.width(), size.height()), row); // default pos | - | ||||||||||||||||||||||||
2881 | items.append(item); | - | ||||||||||||||||||||||||
2882 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2883 | doDynamicLayout(info); | - | ||||||||||||||||||||||||
2884 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2885 | return (batchStartRow > max); // done never executed: return (batchStartRow > max); | 0 | ||||||||||||||||||||||||
2886 | } | - | ||||||||||||||||||||||||
2887 | - | |||||||||||||||||||||||||
2888 | QListViewItem QIconModeViewBase::indexToListViewItem(const QModelIndex &index) const | - | ||||||||||||||||||||||||
2889 | { | - | ||||||||||||||||||||||||
2890 | if (index.isValid() && index.row() < items.count())
| 0 | ||||||||||||||||||||||||
2891 | return items.at(index.row()); never executed: return items.at(index.row()); | 0 | ||||||||||||||||||||||||
2892 | return QListViewItem(); never executed: return QListViewItem(); | 0 | ||||||||||||||||||||||||
2893 | } | - | ||||||||||||||||||||||||
2894 | - | |||||||||||||||||||||||||
2895 | void QIconModeViewBase::initBspTree(const QSize &contents) | - | ||||||||||||||||||||||||
2896 | { | - | ||||||||||||||||||||||||
2897 | // remove all items from the tree | - | ||||||||||||||||||||||||
2898 | int leafCount = tree.leafCount(); | - | ||||||||||||||||||||||||
2899 | for (int l = 0; l < leafCount; ++l)
| 0 | ||||||||||||||||||||||||
2900 | tree.leaf(l).clear(); never executed: tree.leaf(l).clear(); | 0 | ||||||||||||||||||||||||
2901 | // we have to get the bounding rect of the items before we can initialize the tree | - | ||||||||||||||||||||||||
2902 | QBspTree::Node::Type type = QBspTree::Node::Both; // 2D | - | ||||||||||||||||||||||||
2903 | // simple heuristics to get better bsp | - | ||||||||||||||||||||||||
2904 | if (contents.height() / contents.width() >= 3)
| 0 | ||||||||||||||||||||||||
2905 | type = QBspTree::Node::HorizontalPlane; never executed: type = QBspTree::Node::HorizontalPlane; | 0 | ||||||||||||||||||||||||
2906 | else if (contents.width() / contents.height() >= 3)
| 0 | ||||||||||||||||||||||||
2907 | type = QBspTree::Node::VerticalPlane; never executed: type = QBspTree::Node::VerticalPlane; | 0 | ||||||||||||||||||||||||
2908 | // build tree for the bounding rect (not just the contents rect) | - | ||||||||||||||||||||||||
2909 | tree.init(QRect(0, 0, contents.width(), contents.height()), type); | - | ||||||||||||||||||||||||
2910 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2911 | - | |||||||||||||||||||||||||
2912 | QPoint QIconModeViewBase::initDynamicLayout(const QListViewLayoutInfo &info) | - | ||||||||||||||||||||||||
2913 | { | - | ||||||||||||||||||||||||
2914 | int x, y; | - | ||||||||||||||||||||||||
2915 | if (info.first == 0) {
| 0 | ||||||||||||||||||||||||
2916 | x = info.bounds.x() + info.spacing; | - | ||||||||||||||||||||||||
2917 | y = info.bounds.y() + info.spacing; | - | ||||||||||||||||||||||||
2918 | items.reserve(rowCount() - hiddenCount()); | - | ||||||||||||||||||||||||
2919 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2920 | int idx = info.first - 1; | - | ||||||||||||||||||||||||
2921 | while (idx > 0 && !items.at(idx).isValid())
| 0 | ||||||||||||||||||||||||
2922 | --idx; never executed: --idx; | 0 | ||||||||||||||||||||||||
2923 | const QListViewItem &item = items.at(idx); | - | ||||||||||||||||||||||||
2924 | x = item.x; | - | ||||||||||||||||||||||||
2925 | y = item.y; | - | ||||||||||||||||||||||||
2926 | if (info.flow == QListView::LeftToRight)
| 0 | ||||||||||||||||||||||||
2927 | x += (info.grid.isValid() ? info.grid.width() : item.w) + info.spacing; never executed: x += (info.grid.isValid() ? info.grid.width() : item.w) + info.spacing;
| 0 | ||||||||||||||||||||||||
2928 | else | - | ||||||||||||||||||||||||
2929 | y += (info.grid.isValid() ? info.grid.height() : item.h) + info.spacing; never executed: y += (info.grid.isValid() ? info.grid.height() : item.h) + info.spacing;
| 0 | ||||||||||||||||||||||||
2930 | } | - | ||||||||||||||||||||||||
2931 | return QPoint(x, y); never executed: return QPoint(x, y); | 0 | ||||||||||||||||||||||||
2932 | } | - | ||||||||||||||||||||||||
2933 | - | |||||||||||||||||||||||||
2934 | /*! | - | ||||||||||||||||||||||||
2935 | \internal | - | ||||||||||||||||||||||||
2936 | */ | - | ||||||||||||||||||||||||
2937 | void QIconModeViewBase::doDynamicLayout(const QListViewLayoutInfo &info) | - | ||||||||||||||||||||||||
2938 | { | - | ||||||||||||||||||||||||
2939 | const bool useItemSize = !info.grid.isValid(); | - | ||||||||||||||||||||||||
2940 | const QPoint topLeft = initDynamicLayout(info); | - | ||||||||||||||||||||||||
2941 | - | |||||||||||||||||||||||||
2942 | int segStartPosition; | - | ||||||||||||||||||||||||
2943 | int segEndPosition; | - | ||||||||||||||||||||||||
2944 | int deltaFlowPosition; | - | ||||||||||||||||||||||||
2945 | int deltaSegPosition; | - | ||||||||||||||||||||||||
2946 | int deltaSegHint; | - | ||||||||||||||||||||||||
2947 | int flowPosition; | - | ||||||||||||||||||||||||
2948 | int segPosition; | - | ||||||||||||||||||||||||
2949 | - | |||||||||||||||||||||||||
2950 | if (info.flow == QListView::LeftToRight) {
| 0 | ||||||||||||||||||||||||
2951 | segStartPosition = info.bounds.left() + info.spacing; | - | ||||||||||||||||||||||||
2952 | segEndPosition = info.bounds.right(); | - | ||||||||||||||||||||||||
2953 | deltaFlowPosition = info.grid.width(); // dx | - | ||||||||||||||||||||||||
2954 | deltaSegPosition = (useItemSize ? batchSavedDeltaSeg : info.grid.height()); // dy
| 0 | ||||||||||||||||||||||||
2955 | deltaSegHint = info.grid.height(); | - | ||||||||||||||||||||||||
2956 | flowPosition = topLeft.x(); | - | ||||||||||||||||||||||||
2957 | segPosition = topLeft.y(); | - | ||||||||||||||||||||||||
2958 | } else { // flow == QListView::TopToBottom never executed: end of block | 0 | ||||||||||||||||||||||||
2959 | segStartPosition = info.bounds.top() + info.spacing; | - | ||||||||||||||||||||||||
2960 | segEndPosition = info.bounds.bottom(); | - | ||||||||||||||||||||||||
2961 | deltaFlowPosition = info.grid.height(); // dy | - | ||||||||||||||||||||||||
2962 | deltaSegPosition = (useItemSize ? batchSavedDeltaSeg : info.grid.width()); // dx
| 0 | ||||||||||||||||||||||||
2963 | deltaSegHint = info.grid.width(); | - | ||||||||||||||||||||||||
2964 | flowPosition = topLeft.y(); | - | ||||||||||||||||||||||||
2965 | segPosition = topLeft.x(); | - | ||||||||||||||||||||||||
2966 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2967 | - | |||||||||||||||||||||||||
2968 | if (moved.count() != items.count())
| 0 | ||||||||||||||||||||||||
2969 | moved.resize(items.count()); never executed: moved.resize(items.count()); | 0 | ||||||||||||||||||||||||
2970 | - | |||||||||||||||||||||||||
2971 | QRect rect(QPoint(), topLeft); | - | ||||||||||||||||||||||||
2972 | QListViewItem *item = 0; | - | ||||||||||||||||||||||||
2973 | for (int row = info.first; row <= info.last; ++row) {
| 0 | ||||||||||||||||||||||||
2974 | item = &items[row]; | - | ||||||||||||||||||||||||
2975 | if (isHidden(row)) {
| 0 | ||||||||||||||||||||||||
2976 | item->invalidate(); | - | ||||||||||||||||||||||||
2977 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
2978 | // if we are not using a grid, we need to find the deltas | - | ||||||||||||||||||||||||
2979 | if (useItemSize) {
| 0 | ||||||||||||||||||||||||
2980 | if (info.flow == QListView::LeftToRight)
| 0 | ||||||||||||||||||||||||
2981 | deltaFlowPosition = item->w + info.spacing; never executed: deltaFlowPosition = item->w + info.spacing; | 0 | ||||||||||||||||||||||||
2982 | else | - | ||||||||||||||||||||||||
2983 | deltaFlowPosition = item->h + info.spacing; never executed: deltaFlowPosition = item->h + info.spacing; | 0 | ||||||||||||||||||||||||
2984 | } else { | - | ||||||||||||||||||||||||
2985 | item->w = qMin<int>(info.grid.width(), item->w); | - | ||||||||||||||||||||||||
2986 | item->h = qMin<int>(info.grid.height(), item->h); | - | ||||||||||||||||||||||||
2987 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2988 | - | |||||||||||||||||||||||||
2989 | // create new segment | - | ||||||||||||||||||||||||
2990 | if (info.wrap
| 0 | ||||||||||||||||||||||||
2991 | && flowPosition + deltaFlowPosition > segEndPosition
| 0 | ||||||||||||||||||||||||
2992 | && flowPosition > segStartPosition) {
| 0 | ||||||||||||||||||||||||
2993 | flowPosition = segStartPosition; | - | ||||||||||||||||||||||||
2994 | segPosition += deltaSegPosition; | - | ||||||||||||||||||||||||
2995 | if (useItemSize)
| 0 | ||||||||||||||||||||||||
2996 | deltaSegPosition = 0; never executed: deltaSegPosition = 0; | 0 | ||||||||||||||||||||||||
2997 | } never executed: end of block | 0 | ||||||||||||||||||||||||
2998 | // We must delay calculation of the seg adjustment, as this item | - | ||||||||||||||||||||||||
2999 | // may have caused a wrap to occur | - | ||||||||||||||||||||||||
3000 | if (useItemSize) {
| 0 | ||||||||||||||||||||||||
3001 | if (info.flow == QListView::LeftToRight)
| 0 | ||||||||||||||||||||||||
3002 | deltaSegHint = item->h + info.spacing; never executed: deltaSegHint = item->h + info.spacing; | 0 | ||||||||||||||||||||||||
3003 | else | - | ||||||||||||||||||||||||
3004 | deltaSegHint = item->w + info.spacing; never executed: deltaSegHint = item->w + info.spacing; | 0 | ||||||||||||||||||||||||
3005 | deltaSegPosition = qMax(deltaSegPosition, deltaSegHint); | - | ||||||||||||||||||||||||
3006 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3007 | - | |||||||||||||||||||||||||
3008 | // set the position of the item | - | ||||||||||||||||||||||||
3009 | // ### idealy we should have some sort of alignment hint for the item | - | ||||||||||||||||||||||||
3010 | // ### (normally that would be a point between the icon and the text) | - | ||||||||||||||||||||||||
3011 | if (!moved.testBit(row)) {
| 0 | ||||||||||||||||||||||||
3012 | if (info.flow == QListView::LeftToRight) {
| 0 | ||||||||||||||||||||||||
3013 | if (useItemSize) {
| 0 | ||||||||||||||||||||||||
3014 | item->x = flowPosition; | - | ||||||||||||||||||||||||
3015 | item->y = segPosition; | - | ||||||||||||||||||||||||
3016 | } else { // use grid never executed: end of block | 0 | ||||||||||||||||||||||||
3017 | item->x = flowPosition + ((deltaFlowPosition - item->w) / 2); | - | ||||||||||||||||||||||||
3018 | item->y = segPosition; | - | ||||||||||||||||||||||||
3019 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3020 | } else { // TopToBottom | - | ||||||||||||||||||||||||
3021 | if (useItemSize) {
| 0 | ||||||||||||||||||||||||
3022 | item->y = flowPosition; | - | ||||||||||||||||||||||||
3023 | item->x = segPosition; | - | ||||||||||||||||||||||||
3024 | } else { // use grid never executed: end of block | 0 | ||||||||||||||||||||||||
3025 | item->y = flowPosition + ((deltaFlowPosition - item->h) / 2); | - | ||||||||||||||||||||||||
3026 | item->x = segPosition; | - | ||||||||||||||||||||||||
3027 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3028 | } | - | ||||||||||||||||||||||||
3029 | } | - | ||||||||||||||||||||||||
3030 | - | |||||||||||||||||||||||||
3031 | // let the contents contain the new item | - | ||||||||||||||||||||||||
3032 | if (useItemSize)
| 0 | ||||||||||||||||||||||||
3033 | rect |= item->rect(); never executed: rect |= item->rect(); | 0 | ||||||||||||||||||||||||
3034 | else if (info.flow == QListView::LeftToRight)
| 0 | ||||||||||||||||||||||||
3035 | rect |= QRect(flowPosition, segPosition, deltaFlowPosition, deltaSegPosition); never executed: rect |= QRect(flowPosition, segPosition, deltaFlowPosition, deltaSegPosition); | 0 | ||||||||||||||||||||||||
3036 | else // flow == TopToBottom | - | ||||||||||||||||||||||||
3037 | rect |= QRect(segPosition, flowPosition, deltaSegPosition, deltaFlowPosition); never executed: rect |= QRect(segPosition, flowPosition, deltaSegPosition, deltaFlowPosition); | 0 | ||||||||||||||||||||||||
3038 | - | |||||||||||||||||||||||||
3039 | // prepare for next item | - | ||||||||||||||||||||||||
3040 | flowPosition += deltaFlowPosition; // current position + item width + gap | - | ||||||||||||||||||||||||
3041 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3042 | } | - | ||||||||||||||||||||||||
3043 | batchSavedDeltaSeg = deltaSegPosition; | - | ||||||||||||||||||||||||
3044 | batchStartRow = info.last + 1; | - | ||||||||||||||||||||||||
3045 | bool done = (info.last >= rowCount() - 1); | - | ||||||||||||||||||||||||
3046 | // resize the content area | - | ||||||||||||||||||||||||
3047 | if (done || !info.bounds.contains(item->rect())) {
| 0 | ||||||||||||||||||||||||
3048 | contentsSize = rect.size(); | - | ||||||||||||||||||||||||
3049 | if (info.flow == QListView::LeftToRight)
| 0 | ||||||||||||||||||||||||
3050 | contentsSize.rheight() += info.spacing; never executed: contentsSize.rheight() += info.spacing; | 0 | ||||||||||||||||||||||||
3051 | else | - | ||||||||||||||||||||||||
3052 | contentsSize.rwidth() += info.spacing; never executed: contentsSize.rwidth() += info.spacing; | 0 | ||||||||||||||||||||||||
3053 | } | - | ||||||||||||||||||||||||
3054 | if (rect.size().isEmpty())
| 0 | ||||||||||||||||||||||||
3055 | return; never executed: return; | 0 | ||||||||||||||||||||||||
3056 | // resize tree | - | ||||||||||||||||||||||||
3057 | int insertFrom = info.first; | - | ||||||||||||||||||||||||
3058 | if (done || info.first == 0) {
| 0 | ||||||||||||||||||||||||
3059 | initBspTree(rect.size()); | - | ||||||||||||||||||||||||
3060 | insertFrom = 0; | - | ||||||||||||||||||||||||
3061 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3062 | // insert items in tree | - | ||||||||||||||||||||||||
3063 | for (int row = insertFrom; row <= info.last; ++row)
| 0 | ||||||||||||||||||||||||
3064 | tree.insertLeaf(items.at(row).rect(), row); never executed: tree.insertLeaf(items.at(row).rect(), row); | 0 | ||||||||||||||||||||||||
3065 | // if the new items are visble, update the viewport | - | ||||||||||||||||||||||||
3066 | QRect changedRect(topLeft, rect.bottomRight()); | - | ||||||||||||||||||||||||
3067 | if (clipRect().intersects(changedRect))
| 0 | ||||||||||||||||||||||||
3068 | viewport()->update(); never executed: viewport()->update(); | 0 | ||||||||||||||||||||||||
3069 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3070 | - | |||||||||||||||||||||||||
3071 | QVector<QModelIndex> QIconModeViewBase::intersectingSet(const QRect &area) const | - | ||||||||||||||||||||||||
3072 | { | - | ||||||||||||||||||||||||
3073 | QIconModeViewBase *that = const_cast<QIconModeViewBase*>(this); | - | ||||||||||||||||||||||||
3074 | QBspTree::Data data(static_cast<void*>(that)); | - | ||||||||||||||||||||||||
3075 | QVector<QModelIndex> res; | - | ||||||||||||||||||||||||
3076 | that->interSectingVector = &res; | - | ||||||||||||||||||||||||
3077 | that->tree.climbTree(area, &QIconModeViewBase::addLeaf, data); | - | ||||||||||||||||||||||||
3078 | that->interSectingVector = 0; | - | ||||||||||||||||||||||||
3079 | return res; never executed: return res; | 0 | ||||||||||||||||||||||||
3080 | } | - | ||||||||||||||||||||||||
3081 | - | |||||||||||||||||||||||||
3082 | QRect QIconModeViewBase::itemsRect(const QVector<QModelIndex> &indexes) const | - | ||||||||||||||||||||||||
3083 | { | - | ||||||||||||||||||||||||
3084 | QVector<QModelIndex>::const_iterator it = indexes.begin(); | - | ||||||||||||||||||||||||
3085 | QListViewItem item = indexToListViewItem(*it); | - | ||||||||||||||||||||||||
3086 | QRect rect(item.x, item.y, item.w, item.h); | - | ||||||||||||||||||||||||
3087 | for (; it != indexes.end(); ++it) {
| 0 | ||||||||||||||||||||||||
3088 | item = indexToListViewItem(*it); | - | ||||||||||||||||||||||||
3089 | rect |= viewItemRect(item); | - | ||||||||||||||||||||||||
3090 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3091 | return rect; never executed: return rect; | 0 | ||||||||||||||||||||||||
3092 | } | - | ||||||||||||||||||||||||
3093 | - | |||||||||||||||||||||||||
3094 | int QIconModeViewBase::itemIndex(const QListViewItem &item) const | - | ||||||||||||||||||||||||
3095 | { | - | ||||||||||||||||||||||||
3096 | if (!item.isValid())
| 0 | ||||||||||||||||||||||||
3097 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
3098 | int i = item.indexHint; | - | ||||||||||||||||||||||||
3099 | if (i < items.count()) {
| 0 | ||||||||||||||||||||||||
3100 | if (items.at(i) == item)
| 0 | ||||||||||||||||||||||||
3101 | return i; never executed: return i; | 0 | ||||||||||||||||||||||||
3102 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
3103 | i = items.count() - 1; | - | ||||||||||||||||||||||||
3104 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3105 | - | |||||||||||||||||||||||||
3106 | int j = i; | - | ||||||||||||||||||||||||
3107 | int c = items.count(); | - | ||||||||||||||||||||||||
3108 | bool a = true; | - | ||||||||||||||||||||||||
3109 | bool b = true; | - | ||||||||||||||||||||||||
3110 | - | |||||||||||||||||||||||||
3111 | while (a || b) {
| 0 | ||||||||||||||||||||||||
3112 | if (a) {
| 0 | ||||||||||||||||||||||||
3113 | if (items.at(i) == item) {
| 0 | ||||||||||||||||||||||||
3114 | items.at(i).indexHint = i; | - | ||||||||||||||||||||||||
3115 | return i; never executed: return i; | 0 | ||||||||||||||||||||||||
3116 | } | - | ||||||||||||||||||||||||
3117 | a = ++i < c; | - | ||||||||||||||||||||||||
3118 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3119 | if (b) {
| 0 | ||||||||||||||||||||||||
3120 | if (items.at(j) == item) {
| 0 | ||||||||||||||||||||||||
3121 | items.at(j).indexHint = j; | - | ||||||||||||||||||||||||
3122 | return j; never executed: return j; | 0 | ||||||||||||||||||||||||
3123 | } | - | ||||||||||||||||||||||||
3124 | b = --j > -1; | - | ||||||||||||||||||||||||
3125 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3126 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3127 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
3128 | } | - | ||||||||||||||||||||||||
3129 | - | |||||||||||||||||||||||||
3130 | void QIconModeViewBase::addLeaf(QVector<int> &leaf, const QRect &area, | - | ||||||||||||||||||||||||
3131 | uint visited, QBspTree::Data data) | - | ||||||||||||||||||||||||
3132 | { | - | ||||||||||||||||||||||||
3133 | QListViewItem *vi; | - | ||||||||||||||||||||||||
3134 | QIconModeViewBase *_this = static_cast<QIconModeViewBase *>(data.ptr); | - | ||||||||||||||||||||||||
3135 | for (int i = 0; i < leaf.count(); ++i) {
| 0 | ||||||||||||||||||||||||
3136 | int idx = leaf.at(i); | - | ||||||||||||||||||||||||
3137 | if (idx < 0 || idx >= _this->items.count())
| 0 | ||||||||||||||||||||||||
3138 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
3139 | vi = &_this->items[idx]; | - | ||||||||||||||||||||||||
3140 | Q_ASSERT(vi); | - | ||||||||||||||||||||||||
3141 | if (vi->isValid() && vi->rect().intersects(area) && vi->visited != visited) {
| 0 | ||||||||||||||||||||||||
3142 | QModelIndex index = _this->dd->listViewItemToIndex(*vi); | - | ||||||||||||||||||||||||
3143 | Q_ASSERT(index.isValid()); | - | ||||||||||||||||||||||||
3144 | _this->interSectingVector->append(index); | - | ||||||||||||||||||||||||
3145 | vi->visited = visited; | - | ||||||||||||||||||||||||
3146 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3147 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3148 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3149 | - | |||||||||||||||||||||||||
3150 | void QIconModeViewBase::moveItem(int index, const QPoint &dest) | - | ||||||||||||||||||||||||
3151 | { | - | ||||||||||||||||||||||||
3152 | // does not impact on the bintree itself or the contents rect | - | ||||||||||||||||||||||||
3153 | QListViewItem *item = &items[index]; | - | ||||||||||||||||||||||||
3154 | QRect rect = item->rect(); | - | ||||||||||||||||||||||||
3155 | - | |||||||||||||||||||||||||
3156 | // move the item without removing it from the tree | - | ||||||||||||||||||||||||
3157 | tree.removeLeaf(rect, index); | - | ||||||||||||||||||||||||
3158 | item->move(dest); | - | ||||||||||||||||||||||||
3159 | tree.insertLeaf(QRect(dest, rect.size()), index); | - | ||||||||||||||||||||||||
3160 | - | |||||||||||||||||||||||||
3161 | // resize the contents area | - | ||||||||||||||||||||||||
3162 | contentsSize = (QRect(QPoint(0, 0), contentsSize)|QRect(dest, rect.size())).size(); | - | ||||||||||||||||||||||||
3163 | - | |||||||||||||||||||||||||
3164 | // mark the item as moved | - | ||||||||||||||||||||||||
3165 | if (moved.count() != items.count())
| 0 | ||||||||||||||||||||||||
3166 | moved.resize(items.count()); never executed: moved.resize(items.count()); | 0 | ||||||||||||||||||||||||
3167 | moved.setBit(index, true); | - | ||||||||||||||||||||||||
3168 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3169 | - | |||||||||||||||||||||||||
3170 | QPoint QIconModeViewBase::snapToGrid(const QPoint &pos) const | - | ||||||||||||||||||||||||
3171 | { | - | ||||||||||||||||||||||||
3172 | int x = pos.x() - (pos.x() % gridSize().width()); | - | ||||||||||||||||||||||||
3173 | int y = pos.y() - (pos.y() % gridSize().height()); | - | ||||||||||||||||||||||||
3174 | return QPoint(x, y); never executed: return QPoint(x, y); | 0 | ||||||||||||||||||||||||
3175 | } | - | ||||||||||||||||||||||||
3176 | - | |||||||||||||||||||||||||
3177 | QPoint QIconModeViewBase::draggedItemsDelta() const | - | ||||||||||||||||||||||||
3178 | { | - | ||||||||||||||||||||||||
3179 | if (movement() == QListView::Snap) {
| 0 | ||||||||||||||||||||||||
3180 | QPoint snapdelta = QPoint((offset().x() % gridSize().width()), | - | ||||||||||||||||||||||||
3181 | (offset().y() % gridSize().height())); | - | ||||||||||||||||||||||||
3182 | return snapToGrid(draggedItemsPos + snapdelta) - snapToGrid(pressedPosition()) - snapdelta; never executed: return snapToGrid(draggedItemsPos + snapdelta) - snapToGrid(pressedPosition()) - snapdelta; | 0 | ||||||||||||||||||||||||
3183 | } | - | ||||||||||||||||||||||||
3184 | return draggedItemsPos - pressedPosition(); never executed: return draggedItemsPos - pressedPosition(); | 0 | ||||||||||||||||||||||||
3185 | } | - | ||||||||||||||||||||||||
3186 | - | |||||||||||||||||||||||||
3187 | QRect QIconModeViewBase::draggedItemsRect() const | - | ||||||||||||||||||||||||
3188 | { | - | ||||||||||||||||||||||||
3189 | QRect rect = itemsRect(draggedItems); | - | ||||||||||||||||||||||||
3190 | rect.translate(draggedItemsDelta()); | - | ||||||||||||||||||||||||
3191 | return rect; never executed: return rect; | 0 | ||||||||||||||||||||||||
3192 | } | - | ||||||||||||||||||||||||
3193 | - | |||||||||||||||||||||||||
3194 | void QListViewPrivate::scrollElasticBandBy(int dx, int dy) | - | ||||||||||||||||||||||||
3195 | { | - | ||||||||||||||||||||||||
3196 | if (dx > 0) // right
| 0 | ||||||||||||||||||||||||
3197 | elasticBand.moveRight(elasticBand.right() + dx); never executed: elasticBand.moveRight(elasticBand.right() + dx); | 0 | ||||||||||||||||||||||||
3198 | else if (dx < 0) // left
| 0 | ||||||||||||||||||||||||
3199 | elasticBand.moveLeft(elasticBand.left() - dx); never executed: elasticBand.moveLeft(elasticBand.left() - dx); | 0 | ||||||||||||||||||||||||
3200 | if (dy > 0) // down
| 0 | ||||||||||||||||||||||||
3201 | elasticBand.moveBottom(elasticBand.bottom() + dy); never executed: elasticBand.moveBottom(elasticBand.bottom() + dy); | 0 | ||||||||||||||||||||||||
3202 | else if (dy < 0) // up
| 0 | ||||||||||||||||||||||||
3203 | elasticBand.moveTop(elasticBand.top() - dy); never executed: elasticBand.moveTop(elasticBand.top() - dy); | 0 | ||||||||||||||||||||||||
3204 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3205 | - | |||||||||||||||||||||||||
3206 | void QIconModeViewBase::clear() | - | ||||||||||||||||||||||||
3207 | { | - | ||||||||||||||||||||||||
3208 | tree.destroy(); | - | ||||||||||||||||||||||||
3209 | items.clear(); | - | ||||||||||||||||||||||||
3210 | moved.clear(); | - | ||||||||||||||||||||||||
3211 | batchStartRow = 0; | - | ||||||||||||||||||||||||
3212 | batchSavedDeltaSeg = 0; | - | ||||||||||||||||||||||||
3213 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3214 | - | |||||||||||||||||||||||||
3215 | void QIconModeViewBase::updateContentsSize() | - | ||||||||||||||||||||||||
3216 | { | - | ||||||||||||||||||||||||
3217 | QRect bounding; | - | ||||||||||||||||||||||||
3218 | for (int i = 0; i < items.count(); ++i)
| 0 | ||||||||||||||||||||||||
3219 | bounding |= items.at(i).rect(); never executed: bounding |= items.at(i).rect(); | 0 | ||||||||||||||||||||||||
3220 | contentsSize = bounding.size(); | - | ||||||||||||||||||||||||
3221 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3222 | - | |||||||||||||||||||||||||
3223 | /*! | - | ||||||||||||||||||||||||
3224 | \reimp | - | ||||||||||||||||||||||||
3225 | */ | - | ||||||||||||||||||||||||
3226 | void QListView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) | - | ||||||||||||||||||||||||
3227 | { | - | ||||||||||||||||||||||||
3228 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
3229 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
3230 | if (current.isValid()) {
| 0 | ||||||||||||||||||||||||
3231 | int entry = visualIndex(current); | - | ||||||||||||||||||||||||
3232 | QAccessibleEvent event(this, QAccessible::Focus); | - | ||||||||||||||||||||||||
3233 | event.setChild(entry); | - | ||||||||||||||||||||||||
3234 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
3235 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3236 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3237 | #endif | - | ||||||||||||||||||||||||
3238 | QAbstractItemView::currentChanged(current, previous); | - | ||||||||||||||||||||||||
3239 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3240 | - | |||||||||||||||||||||||||
3241 | /*! | - | ||||||||||||||||||||||||
3242 | \reimp | - | ||||||||||||||||||||||||
3243 | */ | - | ||||||||||||||||||||||||
3244 | void QListView::selectionChanged(const QItemSelection &selected, | - | ||||||||||||||||||||||||
3245 | const QItemSelection &deselected) | - | ||||||||||||||||||||||||
3246 | { | - | ||||||||||||||||||||||||
3247 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
3248 | if (QAccessible::isActive()) {
| 0 | ||||||||||||||||||||||||
3249 | // ### does not work properly for selection ranges. | - | ||||||||||||||||||||||||
3250 | QModelIndex sel = selected.indexes().value(0); | - | ||||||||||||||||||||||||
3251 | if (sel.isValid()) {
| 0 | ||||||||||||||||||||||||
3252 | int entry = visualIndex(sel); | - | ||||||||||||||||||||||||
3253 | QAccessibleEvent event(this, QAccessible::SelectionAdd); | - | ||||||||||||||||||||||||
3254 | event.setChild(entry); | - | ||||||||||||||||||||||||
3255 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
3256 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3257 | QModelIndex desel = deselected.indexes().value(0); | - | ||||||||||||||||||||||||
3258 | if (desel.isValid()) {
| 0 | ||||||||||||||||||||||||
3259 | int entry = visualIndex(desel); | - | ||||||||||||||||||||||||
3260 | QAccessibleEvent event(this, QAccessible::SelectionRemove); | - | ||||||||||||||||||||||||
3261 | event.setChild(entry); | - | ||||||||||||||||||||||||
3262 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
3263 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3264 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3265 | #endif | - | ||||||||||||||||||||||||
3266 | QAbstractItemView::selectionChanged(selected, deselected); | - | ||||||||||||||||||||||||
3267 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3268 | - | |||||||||||||||||||||||||
3269 | int QListView::visualIndex(const QModelIndex &index) const | - | ||||||||||||||||||||||||
3270 | { | - | ||||||||||||||||||||||||
3271 | Q_D(const QListView); | - | ||||||||||||||||||||||||
3272 | d->executePostedLayout(); | - | ||||||||||||||||||||||||
3273 | QListViewItem itm = d->indexToListViewItem(index); | - | ||||||||||||||||||||||||
3274 | int visualIndex = d->commonListView->itemIndex(itm); | - | ||||||||||||||||||||||||
3275 | for (int row = 0; row <= index.row() && visualIndex >= 0; row++) {
| 0 | ||||||||||||||||||||||||
3276 | if (d->isHidden(row))
| 0 | ||||||||||||||||||||||||
3277 | visualIndex--; never executed: visualIndex--; | 0 | ||||||||||||||||||||||||
3278 | } never executed: end of block | 0 | ||||||||||||||||||||||||
3279 | return visualIndex; never executed: return visualIndex; | 0 | ||||||||||||||||||||||||
3280 | } | - | ||||||||||||||||||||||||
3281 | - | |||||||||||||||||||||||||
3282 | - | |||||||||||||||||||||||||
3283 | /*! | - | ||||||||||||||||||||||||
3284 | \since 5.2 | - | ||||||||||||||||||||||||
3285 | \reimp | - | ||||||||||||||||||||||||
3286 | */ | - | ||||||||||||||||||||||||
3287 | QSize QListView::viewportSizeHint() const | - | ||||||||||||||||||||||||
3288 | { | - | ||||||||||||||||||||||||
3289 | return QAbstractItemView::viewportSizeHint(); never executed: return QAbstractItemView::viewportSizeHint(); | 0 | ||||||||||||||||||||||||
3290 | } | - | ||||||||||||||||||||||||
3291 | - | |||||||||||||||||||||||||
3292 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
3293 | - | |||||||||||||||||||||||||
3294 | #include "moc_qlistview.cpp" | - | ||||||||||||||||||||||||
3295 | - | |||||||||||||||||||||||||
3296 | #endif // QT_NO_LISTVIEW | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |