Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qcolumnview.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include <qglobal.h> | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | #ifndef QT_NO_COLUMNVIEW | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | #include "qcolumnview.h" | - | ||||||||||||||||||
39 | #include "qcolumnview_p.h" | - | ||||||||||||||||||
40 | #include "qcolumnviewgrip_p.h" | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | #include <qlistview.h> | - | ||||||||||||||||||
43 | #include <qabstractitemdelegate.h> | - | ||||||||||||||||||
44 | #include <qscrollbar.h> | - | ||||||||||||||||||
45 | #include <qpainter.h> | - | ||||||||||||||||||
46 | #include <qdebug.h> | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | #define ANIMATION_DURATION_MSEC 150 | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | /*! | - | ||||||||||||||||||
53 | \since 4.3 | - | ||||||||||||||||||
54 | \class QColumnView | - | ||||||||||||||||||
55 | \brief The QColumnView class provides a model/view implementation of a column view. | - | ||||||||||||||||||
56 | \ingroup model-view | - | ||||||||||||||||||
57 | \ingroup advanced | - | ||||||||||||||||||
58 | \inmodule QtWidgets | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | QColumnView displays a model in a number of QListViews, one for each | - | ||||||||||||||||||
61 | hierarchy in the tree. This is sometimes referred to as a cascading list. | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | The QColumnView class is one of the \l{Model/View Classes} | - | ||||||||||||||||||
64 | and is part of Qt's \l{Model/View Programming}{model/view framework}. | - | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | QColumnView implements the interfaces defined by the | - | ||||||||||||||||||
67 | QAbstractItemView class to allow it to display data provided by | - | ||||||||||||||||||
68 | models derived from the QAbstractItemModel class. | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | \image qcolumnview.png | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | \sa {Model/View Programming} | - | ||||||||||||||||||
73 | */ | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | /*! | - | ||||||||||||||||||
76 | Constructs a column view with a \a parent to represent a model's | - | ||||||||||||||||||
77 | data. Use setModel() to set the model. | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | \sa QAbstractItemModel | - | ||||||||||||||||||
80 | */ | - | ||||||||||||||||||
81 | QColumnView::QColumnView(QWidget * parent) | - | ||||||||||||||||||
82 | : QAbstractItemView(*new QColumnViewPrivate, parent) | - | ||||||||||||||||||
83 | { | - | ||||||||||||||||||
84 | Q_D(QColumnView); | - | ||||||||||||||||||
85 | d->initialize(); | - | ||||||||||||||||||
86 | } never executed: end of block | 0 | ||||||||||||||||||
87 | - | |||||||||||||||||||
88 | /*! | - | ||||||||||||||||||
89 | \internal | - | ||||||||||||||||||
90 | */ | - | ||||||||||||||||||
91 | QColumnView::QColumnView(QColumnViewPrivate & dd, QWidget * parent) | - | ||||||||||||||||||
92 | : QAbstractItemView(dd, parent) | - | ||||||||||||||||||
93 | { | - | ||||||||||||||||||
94 | Q_D(QColumnView); | - | ||||||||||||||||||
95 | d->initialize(); | - | ||||||||||||||||||
96 | } never executed: end of block | 0 | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | void QColumnViewPrivate::initialize() | - | ||||||||||||||||||
99 | { | - | ||||||||||||||||||
100 | Q_Q(QColumnView); | - | ||||||||||||||||||
101 | q->setTextElideMode(Qt::ElideMiddle); | - | ||||||||||||||||||
102 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
103 | QObject::connect(¤tAnimation, SIGNAL(finished()), q, SLOT(_q_changeCurrentColumn())); | - | ||||||||||||||||||
104 | currentAnimation.setDuration(ANIMATION_DURATION_MSEC); | - | ||||||||||||||||||
105 | currentAnimation.setTargetObject(hbar); | - | ||||||||||||||||||
106 | currentAnimation.setPropertyName("value"); | - | ||||||||||||||||||
107 | currentAnimation.setEasingCurve(QEasingCurve::InOutQuad); | - | ||||||||||||||||||
108 | #endif //QT_NO_ANIMATION | - | ||||||||||||||||||
109 | delete itemDelegate; | - | ||||||||||||||||||
110 | q->setItemDelegate(new QColumnViewDelegate(q)); | - | ||||||||||||||||||
111 | } never executed: end of block | 0 | ||||||||||||||||||
112 | - | |||||||||||||||||||
113 | /*! | - | ||||||||||||||||||
114 | Destroys the column view. | - | ||||||||||||||||||
115 | */ | - | ||||||||||||||||||
116 | QColumnView::~QColumnView() | - | ||||||||||||||||||
117 | { | - | ||||||||||||||||||
118 | } | - | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | /*! | - | ||||||||||||||||||
121 | \property QColumnView::resizeGripsVisible | - | ||||||||||||||||||
122 | \brief the way to specify if the list views gets resize grips or not | - | ||||||||||||||||||
123 | - | |||||||||||||||||||
124 | By default, \c visible is set to true | - | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | \sa setRootIndex() | - | ||||||||||||||||||
127 | */ | - | ||||||||||||||||||
128 | void QColumnView::setResizeGripsVisible(bool visible) | - | ||||||||||||||||||
129 | { | - | ||||||||||||||||||
130 | Q_D(QColumnView); | - | ||||||||||||||||||
131 | if (d->showResizeGrips == visible)
| 0 | ||||||||||||||||||
132 | return; never executed: return; | 0 | ||||||||||||||||||
133 | d->showResizeGrips = visible; | - | ||||||||||||||||||
134 | for (int i = 0; i < d->columns.count(); ++i) {
| 0 | ||||||||||||||||||
135 | QAbstractItemView *view = d->columns[i]; | - | ||||||||||||||||||
136 | if (visible) {
| 0 | ||||||||||||||||||
137 | QColumnViewGrip *grip = new QColumnViewGrip(view); | - | ||||||||||||||||||
138 | view->setCornerWidget(grip); | - | ||||||||||||||||||
139 | connect(grip, SIGNAL(gripMoved(int)), this, SLOT(_q_gripMoved(int))); | - | ||||||||||||||||||
140 | } else { never executed: end of block | 0 | ||||||||||||||||||
141 | QWidget *widget = view->cornerWidget(); | - | ||||||||||||||||||
142 | view->setCornerWidget(0); | - | ||||||||||||||||||
143 | widget->deleteLater(); | - | ||||||||||||||||||
144 | } never executed: end of block | 0 | ||||||||||||||||||
145 | } | - | ||||||||||||||||||
146 | } never executed: end of block | 0 | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | bool QColumnView::resizeGripsVisible() const | - | ||||||||||||||||||
149 | { | - | ||||||||||||||||||
150 | Q_D(const QColumnView); | - | ||||||||||||||||||
151 | return d->showResizeGrips; never executed: return d->showResizeGrips; | 0 | ||||||||||||||||||
152 | } | - | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | /*! | - | ||||||||||||||||||
155 | \reimp | - | ||||||||||||||||||
156 | */ | - | ||||||||||||||||||
157 | void QColumnView::setModel(QAbstractItemModel *model) | - | ||||||||||||||||||
158 | { | - | ||||||||||||||||||
159 | Q_D(QColumnView); | - | ||||||||||||||||||
160 | if (model == d->model)
| 0 | ||||||||||||||||||
161 | return; never executed: return; | 0 | ||||||||||||||||||
162 | d->closeColumns(); | - | ||||||||||||||||||
163 | QAbstractItemView::setModel(model); | - | ||||||||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | /*! | - | ||||||||||||||||||
167 | \reimp | - | ||||||||||||||||||
168 | */ | - | ||||||||||||||||||
169 | void QColumnView::setRootIndex(const QModelIndex &index) | - | ||||||||||||||||||
170 | { | - | ||||||||||||||||||
171 | Q_D(QColumnView); | - | ||||||||||||||||||
172 | if (!model())
| 0 | ||||||||||||||||||
173 | return; never executed: return; | 0 | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | d->closeColumns(); | - | ||||||||||||||||||
176 | Q_ASSERT(d->columns.count() == 0); | - | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | QAbstractItemView *view = d->createColumn(index, true); | - | ||||||||||||||||||
179 | if (view->selectionModel())
| 0 | ||||||||||||||||||
180 | view->selectionModel()->deleteLater(); never executed: view->selectionModel()->deleteLater(); | 0 | ||||||||||||||||||
181 | if (view->model())
| 0 | ||||||||||||||||||
182 | view->setSelectionModel(selectionModel()); never executed: view->setSelectionModel(selectionModel()); | 0 | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | QAbstractItemView::setRootIndex(index); | - | ||||||||||||||||||
185 | d->updateScrollbars(); | - | ||||||||||||||||||
186 | } never executed: end of block | 0 | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | /*! | - | ||||||||||||||||||
189 | \reimp | - | ||||||||||||||||||
190 | */ | - | ||||||||||||||||||
191 | bool QColumnView::isIndexHidden(const QModelIndex &index) const | - | ||||||||||||||||||
192 | { | - | ||||||||||||||||||
193 | Q_UNUSED(index); | - | ||||||||||||||||||
194 | return false; never executed: return false; | 0 | ||||||||||||||||||
195 | } | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | /*! | - | ||||||||||||||||||
198 | \reimp | - | ||||||||||||||||||
199 | */ | - | ||||||||||||||||||
200 | QModelIndex QColumnView::indexAt(const QPoint &point) const | - | ||||||||||||||||||
201 | { | - | ||||||||||||||||||
202 | Q_D(const QColumnView); | - | ||||||||||||||||||
203 | for (int i = 0; i < d->columns.size(); ++i) {
| 0 | ||||||||||||||||||
204 | QPoint topLeft = d->columns.at(i)->frameGeometry().topLeft(); | - | ||||||||||||||||||
205 | QPoint adjustedPoint(point.x() - topLeft.x(), point.y() - topLeft.y()); | - | ||||||||||||||||||
206 | QModelIndex index = d->columns.at(i)->indexAt(adjustedPoint); | - | ||||||||||||||||||
207 | if (index.isValid())
| 0 | ||||||||||||||||||
208 | return index; never executed: return index; | 0 | ||||||||||||||||||
209 | } never executed: end of block | 0 | ||||||||||||||||||
210 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||
211 | } | - | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | /*! | - | ||||||||||||||||||
214 | \reimp | - | ||||||||||||||||||
215 | */ | - | ||||||||||||||||||
216 | QRect QColumnView::visualRect(const QModelIndex &index) const | - | ||||||||||||||||||
217 | { | - | ||||||||||||||||||
218 | if (!index.isValid())
| 0 | ||||||||||||||||||
219 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||
220 | - | |||||||||||||||||||
221 | Q_D(const QColumnView); | - | ||||||||||||||||||
222 | for (int i = 0; i < d->columns.size(); ++i) {
| 0 | ||||||||||||||||||
223 | QRect rect = d->columns.at(i)->visualRect(index); | - | ||||||||||||||||||
224 | if (!rect.isNull()) {
| 0 | ||||||||||||||||||
225 | rect.translate(d->columns.at(i)->frameGeometry().topLeft()); | - | ||||||||||||||||||
226 | return rect; never executed: return rect; | 0 | ||||||||||||||||||
227 | } | - | ||||||||||||||||||
228 | } never executed: end of block | 0 | ||||||||||||||||||
229 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||
230 | } | - | ||||||||||||||||||
231 | - | |||||||||||||||||||
232 | /*! | - | ||||||||||||||||||
233 | \reimp | - | ||||||||||||||||||
234 | */ | - | ||||||||||||||||||
235 | void QColumnView::scrollContentsBy(int dx, int dy) | - | ||||||||||||||||||
236 | { | - | ||||||||||||||||||
237 | Q_D(QColumnView); | - | ||||||||||||||||||
238 | if (d->columns.isEmpty() || dx == 0)
| 0 | ||||||||||||||||||
239 | return; never executed: return; | 0 | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | dx = isRightToLeft() ? -dx : dx;
| 0 | ||||||||||||||||||
242 | for (int i = 0; i < d->columns.count(); ++i)
| 0 | ||||||||||||||||||
243 | d->columns.at(i)->move(d->columns.at(i)->x() + dx, 0); never executed: d->columns.at(i)->move(d->columns.at(i)->x() + dx, 0); | 0 | ||||||||||||||||||
244 | d->offset += dx; | - | ||||||||||||||||||
245 | QAbstractItemView::scrollContentsBy(dx, dy); | - | ||||||||||||||||||
246 | } never executed: end of block | 0 | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | /*! | - | ||||||||||||||||||
249 | \reimp | - | ||||||||||||||||||
250 | */ | - | ||||||||||||||||||
251 | void QColumnView::scrollTo(const QModelIndex &index, ScrollHint hint) | - | ||||||||||||||||||
252 | { | - | ||||||||||||||||||
253 | Q_D(QColumnView); | - | ||||||||||||||||||
254 | Q_UNUSED(hint); | - | ||||||||||||||||||
255 | if (!index.isValid() || d->columns.isEmpty())
| 0 | ||||||||||||||||||
256 | return; never executed: return; | 0 | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
259 | if (d->currentAnimation.state() == QPropertyAnimation::Running)
| 0 | ||||||||||||||||||
260 | return; never executed: return; | 0 | ||||||||||||||||||
261 | - | |||||||||||||||||||
262 | d->currentAnimation.stop(); | - | ||||||||||||||||||
263 | #endif //QT_NO_ANIMATION | - | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | // Fill up what is needed to get to index | - | ||||||||||||||||||
266 | d->closeColumns(index, true); | - | ||||||||||||||||||
267 | - | |||||||||||||||||||
268 | QModelIndex indexParent = index.parent(); | - | ||||||||||||||||||
269 | // Find the left edge of the column that contains index | - | ||||||||||||||||||
270 | int currentColumn = 0; | - | ||||||||||||||||||
271 | int leftEdge = 0; | - | ||||||||||||||||||
272 | while (currentColumn < d->columns.size()) {
| 0 | ||||||||||||||||||
273 | if (indexParent == d->columns.at(currentColumn)->rootIndex())
| 0 | ||||||||||||||||||
274 | break; never executed: break; | 0 | ||||||||||||||||||
275 | leftEdge += d->columns.at(currentColumn)->width(); | - | ||||||||||||||||||
276 | ++currentColumn; | - | ||||||||||||||||||
277 | } never executed: end of block | 0 | ||||||||||||||||||
278 | - | |||||||||||||||||||
279 | // Don't let us scroll above the root index | - | ||||||||||||||||||
280 | if (currentColumn == d->columns.size())
| 0 | ||||||||||||||||||
281 | return; never executed: return; | 0 | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | int indexColumn = currentColumn; | - | ||||||||||||||||||
284 | // Find the width of what we want to show (i.e. the right edge) | - | ||||||||||||||||||
285 | int visibleWidth = d->columns.at(currentColumn)->width(); | - | ||||||||||||||||||
286 | // We want to always try to show two columns | - | ||||||||||||||||||
287 | if (currentColumn + 1 < d->columns.size()) {
| 0 | ||||||||||||||||||
288 | ++currentColumn; | - | ||||||||||||||||||
289 | visibleWidth += d->columns.at(currentColumn)->width(); | - | ||||||||||||||||||
290 | } never executed: end of block | 0 | ||||||||||||||||||
291 | - | |||||||||||||||||||
292 | int rightEdge = leftEdge + visibleWidth; | - | ||||||||||||||||||
293 | if (isRightToLeft()) {
| 0 | ||||||||||||||||||
294 | leftEdge = viewport()->width() - leftEdge; | - | ||||||||||||||||||
295 | rightEdge = leftEdge - visibleWidth; | - | ||||||||||||||||||
296 | qSwap(rightEdge, leftEdge); | - | ||||||||||||||||||
297 | } never executed: end of block | 0 | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | // If it is already visible don't animate | - | ||||||||||||||||||
300 | if (leftEdge > -horizontalOffset()
| 0 | ||||||||||||||||||
301 | && rightEdge <= ( -horizontalOffset() + viewport()->size().width())) {
| 0 | ||||||||||||||||||
302 | d->columns.at(indexColumn)->scrollTo(index); | - | ||||||||||||||||||
303 | d->_q_changeCurrentColumn(); | - | ||||||||||||||||||
304 | return; never executed: return; | 0 | ||||||||||||||||||
305 | } | - | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | int newScrollbarValue = 0; | - | ||||||||||||||||||
308 | if (isRightToLeft()) {
| 0 | ||||||||||||||||||
309 | if (leftEdge < 0) {
| 0 | ||||||||||||||||||
310 | // scroll to the right | - | ||||||||||||||||||
311 | newScrollbarValue = viewport()->size().width() - leftEdge; | - | ||||||||||||||||||
312 | } else { never executed: end of block | 0 | ||||||||||||||||||
313 | // scroll to the left | - | ||||||||||||||||||
314 | newScrollbarValue = rightEdge + horizontalOffset(); | - | ||||||||||||||||||
315 | } never executed: end of block | 0 | ||||||||||||||||||
316 | } else { | - | ||||||||||||||||||
317 | if (leftEdge > -horizontalOffset()) {
| 0 | ||||||||||||||||||
318 | // scroll to the right | - | ||||||||||||||||||
319 | newScrollbarValue = rightEdge - viewport()->size().width(); | - | ||||||||||||||||||
320 | } else { never executed: end of block | 0 | ||||||||||||||||||
321 | // scroll to the left | - | ||||||||||||||||||
322 | newScrollbarValue = leftEdge; | - | ||||||||||||||||||
323 | } never executed: end of block | 0 | ||||||||||||||||||
324 | } | - | ||||||||||||||||||
325 | - | |||||||||||||||||||
326 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
327 | if (style()->styleHint(QStyle::SH_Widget_Animate, 0, this)) {
| 0 | ||||||||||||||||||
328 | d->currentAnimation.setEndValue(newScrollbarValue); | - | ||||||||||||||||||
329 | d->currentAnimation.start(); | - | ||||||||||||||||||
330 | } else never executed: end of block | 0 | ||||||||||||||||||
331 | #endif //QT_NO_ANIMATION | - | ||||||||||||||||||
332 | { | - | ||||||||||||||||||
333 | horizontalScrollBar()->setValue(newScrollbarValue); | - | ||||||||||||||||||
334 | } never executed: end of block | 0 | ||||||||||||||||||
335 | } | - | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | /*! | - | ||||||||||||||||||
338 | \reimp | - | ||||||||||||||||||
339 | Move left should go to the parent index | - | ||||||||||||||||||
340 | Move right should go to the child index or down if there is no child | - | ||||||||||||||||||
341 | */ | - | ||||||||||||||||||
342 | QModelIndex QColumnView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) | - | ||||||||||||||||||
343 | { | - | ||||||||||||||||||
344 | // the child views which have focus get to deal with this first and if | - | ||||||||||||||||||
345 | // they don't accept it then it comes up this view and we only grip left/right | - | ||||||||||||||||||
346 | Q_UNUSED(modifiers); | - | ||||||||||||||||||
347 | if (!model())
| 0 | ||||||||||||||||||
348 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||
349 | - | |||||||||||||||||||
350 | QModelIndex current = currentIndex(); | - | ||||||||||||||||||
351 | if (isRightToLeft()) {
| 0 | ||||||||||||||||||
352 | if (cursorAction == MoveLeft)
| 0 | ||||||||||||||||||
353 | cursorAction = MoveRight; never executed: cursorAction = MoveRight; | 0 | ||||||||||||||||||
354 | else if (cursorAction == MoveRight)
| 0 | ||||||||||||||||||
355 | cursorAction = MoveLeft; never executed: cursorAction = MoveLeft; | 0 | ||||||||||||||||||
356 | } never executed: end of block | 0 | ||||||||||||||||||
357 | switch (cursorAction) { | - | ||||||||||||||||||
358 | case MoveLeft: never executed: case MoveLeft: | 0 | ||||||||||||||||||
359 | if (current.parent().isValid() && current.parent() != rootIndex())
| 0 | ||||||||||||||||||
360 | return (current.parent()); never executed: return (current.parent()); | 0 | ||||||||||||||||||
361 | else | - | ||||||||||||||||||
362 | return current; never executed: return current; | 0 | ||||||||||||||||||
363 | - | |||||||||||||||||||
364 | case MoveRight: never executed: case MoveRight: | 0 | ||||||||||||||||||
365 | if (model()->hasChildren(current))
| 0 | ||||||||||||||||||
366 | return model()->index(0, 0, current); never executed: return model()->index(0, 0, current); | 0 | ||||||||||||||||||
367 | else | - | ||||||||||||||||||
368 | return current.sibling(current.row() + 1, current.column()); never executed: return current.sibling(current.row() + 1, current.column()); | 0 | ||||||||||||||||||
369 | - | |||||||||||||||||||
370 | default: never executed: default: | 0 | ||||||||||||||||||
371 | break; never executed: break; | 0 | ||||||||||||||||||
372 | } | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||
375 | } | - | ||||||||||||||||||
376 | - | |||||||||||||||||||
377 | /*! | - | ||||||||||||||||||
378 | \reimp | - | ||||||||||||||||||
379 | */ | - | ||||||||||||||||||
380 | void QColumnView::resizeEvent(QResizeEvent *event) | - | ||||||||||||||||||
381 | { | - | ||||||||||||||||||
382 | Q_D(QColumnView); | - | ||||||||||||||||||
383 | d->doLayout(); | - | ||||||||||||||||||
384 | d->updateScrollbars(); | - | ||||||||||||||||||
385 | if (!isRightToLeft()) {
| 0 | ||||||||||||||||||
386 | int diff = event->oldSize().width() - event->size().width(); | - | ||||||||||||||||||
387 | if (diff < 0 && horizontalScrollBar()->isVisible()
| 0 | ||||||||||||||||||
388 | && horizontalScrollBar()->value() == horizontalScrollBar()->maximum()) {
| 0 | ||||||||||||||||||
389 | horizontalScrollBar()->setMaximum(horizontalScrollBar()->maximum() + diff); | - | ||||||||||||||||||
390 | } never executed: end of block | 0 | ||||||||||||||||||
391 | } never executed: end of block | 0 | ||||||||||||||||||
392 | QAbstractItemView::resizeEvent(event); | - | ||||||||||||||||||
393 | } never executed: end of block | 0 | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | /*! | - | ||||||||||||||||||
396 | \internal | - | ||||||||||||||||||
397 | */ | - | ||||||||||||||||||
398 | void QColumnViewPrivate::updateScrollbars() | - | ||||||||||||||||||
399 | { | - | ||||||||||||||||||
400 | Q_Q(QColumnView); | - | ||||||||||||||||||
401 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
402 | if (currentAnimation.state() == QPropertyAnimation::Running)
| 0 | ||||||||||||||||||
403 | return; never executed: return; | 0 | ||||||||||||||||||
404 | #endif //QT_NO_ANIMATION | - | ||||||||||||||||||
405 | - | |||||||||||||||||||
406 | // find the total horizontal length of the laid out columns | - | ||||||||||||||||||
407 | int horizontalLength = 0; | - | ||||||||||||||||||
408 | if (!columns.isEmpty()) {
| 0 | ||||||||||||||||||
409 | horizontalLength = (columns.last()->x() + columns.last()->width()) - columns.first()->x(); | - | ||||||||||||||||||
410 | if (horizontalLength <= 0) // reverse mode
| 0 | ||||||||||||||||||
411 | horizontalLength = (columns.first()->x() + columns.first()->width()) - columns.last()->x(); never executed: horizontalLength = (columns.first()->x() + columns.first()->width()) - columns.last()->x(); | 0 | ||||||||||||||||||
412 | } never executed: end of block | 0 | ||||||||||||||||||
413 | - | |||||||||||||||||||
414 | QSize viewportSize = viewport->size(); | - | ||||||||||||||||||
415 | if (horizontalLength < viewportSize.width() && hbar->value() == 0) {
| 0 | ||||||||||||||||||
416 | hbar->setRange(0, 0); | - | ||||||||||||||||||
417 | } else { never executed: end of block | 0 | ||||||||||||||||||
418 | int visibleLength = qMin(horizontalLength + q->horizontalOffset(), viewportSize.width()); | - | ||||||||||||||||||
419 | int hiddenLength = horizontalLength - visibleLength; | - | ||||||||||||||||||
420 | if (hiddenLength != hbar->maximum())
| 0 | ||||||||||||||||||
421 | hbar->setRange(0, hiddenLength); never executed: hbar->setRange(0, hiddenLength); | 0 | ||||||||||||||||||
422 | } never executed: end of block | 0 | ||||||||||||||||||
423 | if (!columns.isEmpty()) {
| 0 | ||||||||||||||||||
424 | int pageStepSize = columns.at(0)->width(); | - | ||||||||||||||||||
425 | if (pageStepSize != hbar->pageStep())
| 0 | ||||||||||||||||||
426 | hbar->setPageStep(pageStepSize); never executed: hbar->setPageStep(pageStepSize); | 0 | ||||||||||||||||||
427 | } never executed: end of block | 0 | ||||||||||||||||||
428 | bool visible = (hbar->maximum() > 0); | - | ||||||||||||||||||
429 | if (visible != hbar->isVisible())
| 0 | ||||||||||||||||||
430 | hbar->setVisible(visible); never executed: hbar->setVisible(visible); | 0 | ||||||||||||||||||
431 | } never executed: end of block | 0 | ||||||||||||||||||
432 | - | |||||||||||||||||||
433 | /*! | - | ||||||||||||||||||
434 | \reimp | - | ||||||||||||||||||
435 | */ | - | ||||||||||||||||||
436 | int QColumnView::horizontalOffset() const | - | ||||||||||||||||||
437 | { | - | ||||||||||||||||||
438 | Q_D(const QColumnView); | - | ||||||||||||||||||
439 | return d->offset; never executed: return d->offset; | 0 | ||||||||||||||||||
440 | } | - | ||||||||||||||||||
441 | - | |||||||||||||||||||
442 | /*! | - | ||||||||||||||||||
443 | \reimp | - | ||||||||||||||||||
444 | */ | - | ||||||||||||||||||
445 | int QColumnView::verticalOffset() const | - | ||||||||||||||||||
446 | { | - | ||||||||||||||||||
447 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
448 | } | - | ||||||||||||||||||
449 | - | |||||||||||||||||||
450 | /*! | - | ||||||||||||||||||
451 | \reimp | - | ||||||||||||||||||
452 | */ | - | ||||||||||||||||||
453 | QRegion QColumnView::visualRegionForSelection(const QItemSelection &selection) const | - | ||||||||||||||||||
454 | { | - | ||||||||||||||||||
455 | int ranges = selection.count(); | - | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | if (ranges == 0)
| 0 | ||||||||||||||||||
458 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||||||||
459 | - | |||||||||||||||||||
460 | // Note that we use the top and bottom functions of the selection range | - | ||||||||||||||||||
461 | // since the data is stored in rows. | - | ||||||||||||||||||
462 | int firstRow = selection.at(0).top(); | - | ||||||||||||||||||
463 | int lastRow = selection.at(0).top(); | - | ||||||||||||||||||
464 | for (int i = 0; i < ranges; ++i) {
| 0 | ||||||||||||||||||
465 | firstRow = qMin(firstRow, selection.at(i).top()); | - | ||||||||||||||||||
466 | lastRow = qMax(lastRow, selection.at(i).bottom()); | - | ||||||||||||||||||
467 | } never executed: end of block | 0 | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | QModelIndex firstIdx = model()->index(qMin(firstRow, lastRow), 0, rootIndex()); | - | ||||||||||||||||||
470 | QModelIndex lastIdx = model()->index(qMax(firstRow, lastRow), 0, rootIndex()); | - | ||||||||||||||||||
471 | - | |||||||||||||||||||
472 | if (firstIdx == lastIdx)
| 0 | ||||||||||||||||||
473 | return visualRect(firstIdx); never executed: return visualRect(firstIdx); | 0 | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | QRegion firstRegion = visualRect(firstIdx); | - | ||||||||||||||||||
476 | QRegion lastRegion = visualRect(lastIdx); | - | ||||||||||||||||||
477 | return firstRegion.united(lastRegion); never executed: return firstRegion.united(lastRegion); | 0 | ||||||||||||||||||
478 | } | - | ||||||||||||||||||
479 | - | |||||||||||||||||||
480 | /*! | - | ||||||||||||||||||
481 | \reimp | - | ||||||||||||||||||
482 | */ | - | ||||||||||||||||||
483 | void QColumnView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) | - | ||||||||||||||||||
484 | { | - | ||||||||||||||||||
485 | Q_UNUSED(rect); | - | ||||||||||||||||||
486 | Q_UNUSED(command); | - | ||||||||||||||||||
487 | } never executed: end of block | 0 | ||||||||||||||||||
488 | - | |||||||||||||||||||
489 | /*! | - | ||||||||||||||||||
490 | \reimp | - | ||||||||||||||||||
491 | */ | - | ||||||||||||||||||
492 | void QColumnView::setSelectionModel(QItemSelectionModel *newSelectionModel) | - | ||||||||||||||||||
493 | { | - | ||||||||||||||||||
494 | Q_D(const QColumnView); | - | ||||||||||||||||||
495 | for (int i = 0; i < d->columns.size(); ++i) {
| 0 | ||||||||||||||||||
496 | if (d->columns.at(i)->selectionModel() == selectionModel()) {
| 0 | ||||||||||||||||||
497 | d->columns.at(i)->setSelectionModel(newSelectionModel); | - | ||||||||||||||||||
498 | break; never executed: break; | 0 | ||||||||||||||||||
499 | } | - | ||||||||||||||||||
500 | } never executed: end of block | 0 | ||||||||||||||||||
501 | QAbstractItemView::setSelectionModel(newSelectionModel); | - | ||||||||||||||||||
502 | } never executed: end of block | 0 | ||||||||||||||||||
503 | - | |||||||||||||||||||
504 | /*! | - | ||||||||||||||||||
505 | \reimp | - | ||||||||||||||||||
506 | */ | - | ||||||||||||||||||
507 | QSize QColumnView::sizeHint() const | - | ||||||||||||||||||
508 | { | - | ||||||||||||||||||
509 | Q_D(const QColumnView); | - | ||||||||||||||||||
510 | QSize sizeHint; | - | ||||||||||||||||||
511 | for (int i = 0; i < d->columns.size(); ++i) {
| 0 | ||||||||||||||||||
512 | sizeHint += d->columns.at(i)->sizeHint(); | - | ||||||||||||||||||
513 | } never executed: end of block | 0 | ||||||||||||||||||
514 | return sizeHint.expandedTo(QAbstractItemView::sizeHint()); never executed: return sizeHint.expandedTo(QAbstractItemView::sizeHint()); | 0 | ||||||||||||||||||
515 | } | - | ||||||||||||||||||
516 | - | |||||||||||||||||||
517 | /*! | - | ||||||||||||||||||
518 | \internal | - | ||||||||||||||||||
519 | Move all widgets from the corner grip and to the right | - | ||||||||||||||||||
520 | */ | - | ||||||||||||||||||
521 | void QColumnViewPrivate::_q_gripMoved(int offset) | - | ||||||||||||||||||
522 | { | - | ||||||||||||||||||
523 | Q_Q(QColumnView); | - | ||||||||||||||||||
524 | - | |||||||||||||||||||
525 | QObject *grip = q->sender(); | - | ||||||||||||||||||
526 | Q_ASSERT(grip); | - | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | if (q->isRightToLeft())
| 0 | ||||||||||||||||||
529 | offset = -1 * offset; never executed: offset = -1 * offset; | 0 | ||||||||||||||||||
530 | - | |||||||||||||||||||
531 | bool found = false; | - | ||||||||||||||||||
532 | for (int i = 0; i < columns.size(); ++i) {
| 0 | ||||||||||||||||||
533 | if (!found && columns.at(i)->cornerWidget() == grip) {
| 0 | ||||||||||||||||||
534 | found = true; | - | ||||||||||||||||||
535 | columnSizes[i] = columns.at(i)->width(); | - | ||||||||||||||||||
536 | if (q->isRightToLeft())
| 0 | ||||||||||||||||||
537 | columns.at(i)->move(columns.at(i)->x() + offset, 0); never executed: columns.at(i)->move(columns.at(i)->x() + offset, 0); | 0 | ||||||||||||||||||
538 | continue; never executed: continue; | 0 | ||||||||||||||||||
539 | } | - | ||||||||||||||||||
540 | if (!found)
| 0 | ||||||||||||||||||
541 | continue; never executed: continue; | 0 | ||||||||||||||||||
542 | - | |||||||||||||||||||
543 | int currentX = columns.at(i)->x(); | - | ||||||||||||||||||
544 | columns.at(i)->move(currentX + offset, 0); | - | ||||||||||||||||||
545 | } never executed: end of block | 0 | ||||||||||||||||||
546 | - | |||||||||||||||||||
547 | updateScrollbars(); | - | ||||||||||||||||||
548 | } never executed: end of block | 0 | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | /*! | - | ||||||||||||||||||
551 | \internal | - | ||||||||||||||||||
552 | - | |||||||||||||||||||
553 | Find where the current columns intersect parent's columns | - | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | Delete any extra columns and insert any needed columns. | - | ||||||||||||||||||
556 | */ | - | ||||||||||||||||||
557 | void QColumnViewPrivate::closeColumns(const QModelIndex &parent, bool build) | - | ||||||||||||||||||
558 | { | - | ||||||||||||||||||
559 | if (columns.isEmpty())
| 0 | ||||||||||||||||||
560 | return; never executed: return; | 0 | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | bool clearAll = !parent.isValid(); | - | ||||||||||||||||||
563 | bool passThroughRoot = false; | - | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | QList<QModelIndex> dirsToAppend; | - | ||||||||||||||||||
566 | - | |||||||||||||||||||
567 | // Find the last column that matches the parent's tree | - | ||||||||||||||||||
568 | int currentColumn = -1; | - | ||||||||||||||||||
569 | QModelIndex parentIndex = parent; | - | ||||||||||||||||||
570 | while (currentColumn == -1 && parentIndex.isValid()) {
| 0 | ||||||||||||||||||
571 | if (columns.isEmpty())
| 0 | ||||||||||||||||||
572 | break; never executed: break; | 0 | ||||||||||||||||||
573 | parentIndex = parentIndex.parent(); | - | ||||||||||||||||||
574 | if (root == parentIndex)
| 0 | ||||||||||||||||||
575 | passThroughRoot = true; never executed: passThroughRoot = true; | 0 | ||||||||||||||||||
576 | if (!parentIndex.isValid())
| 0 | ||||||||||||||||||
577 | break; never executed: break; | 0 | ||||||||||||||||||
578 | for (int i = columns.size() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||
579 | if (columns.at(i)->rootIndex() == parentIndex) {
| 0 | ||||||||||||||||||
580 | currentColumn = i; | - | ||||||||||||||||||
581 | break; never executed: break; | 0 | ||||||||||||||||||
582 | } | - | ||||||||||||||||||
583 | } never executed: end of block | 0 | ||||||||||||||||||
584 | if (currentColumn == -1)
| 0 | ||||||||||||||||||
585 | dirsToAppend.append(parentIndex); never executed: dirsToAppend.append(parentIndex); | 0 | ||||||||||||||||||
586 | } never executed: end of block | 0 | ||||||||||||||||||
587 | - | |||||||||||||||||||
588 | // Someone wants to go to an index that can be reached without changing | - | ||||||||||||||||||
589 | // the root index, don't allow them | - | ||||||||||||||||||
590 | if (!clearAll && !passThroughRoot && currentColumn == -1)
| 0 | ||||||||||||||||||
591 | return; never executed: return; | 0 | ||||||||||||||||||
592 | - | |||||||||||||||||||
593 | if (currentColumn == -1 && parent.isValid())
| 0 | ||||||||||||||||||
594 | currentColumn = 0; never executed: currentColumn = 0; | 0 | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | // Optimization so we don't go deleting and then creating the same thing | - | ||||||||||||||||||
597 | bool alreadyExists = false; | - | ||||||||||||||||||
598 | if (build && columns.size() > currentColumn + 1) {
| 0 | ||||||||||||||||||
599 | bool viewingParent = (columns.at(currentColumn + 1)->rootIndex() == parent); | - | ||||||||||||||||||
600 | bool viewingChild = (!model->hasChildren(parent)
| 0 | ||||||||||||||||||
601 | && !columns.at(currentColumn + 1)->rootIndex().isValid());
| 0 | ||||||||||||||||||
602 | if (viewingParent || viewingChild) {
| 0 | ||||||||||||||||||
603 | currentColumn++; | - | ||||||||||||||||||
604 | alreadyExists = true; | - | ||||||||||||||||||
605 | } never executed: end of block | 0 | ||||||||||||||||||
606 | } never executed: end of block | 0 | ||||||||||||||||||
607 | - | |||||||||||||||||||
608 | // Delete columns that don't match our path | - | ||||||||||||||||||
609 | for (int i = columns.size() - 1; i > currentColumn; --i) {
| 0 | ||||||||||||||||||
610 | QAbstractItemView* notShownAnymore = columns.at(i); | - | ||||||||||||||||||
611 | columns.removeAt(i); | - | ||||||||||||||||||
612 | notShownAnymore->setVisible(false); | - | ||||||||||||||||||
613 | if (notShownAnymore != previewColumn)
| 0 | ||||||||||||||||||
614 | notShownAnymore->deleteLater(); never executed: notShownAnymore->deleteLater(); | 0 | ||||||||||||||||||
615 | } never executed: end of block | 0 | ||||||||||||||||||
616 | - | |||||||||||||||||||
617 | if (columns.isEmpty()) {
| 0 | ||||||||||||||||||
618 | offset = 0; | - | ||||||||||||||||||
619 | updateScrollbars(); | - | ||||||||||||||||||
620 | } never executed: end of block | 0 | ||||||||||||||||||
621 | - | |||||||||||||||||||
622 | // Now fill in missing columns | - | ||||||||||||||||||
623 | while (!dirsToAppend.isEmpty()) {
| 0 | ||||||||||||||||||
624 | QAbstractItemView *newView = createColumn(dirsToAppend.takeLast(), true); | - | ||||||||||||||||||
625 | if (!dirsToAppend.isEmpty())
| 0 | ||||||||||||||||||
626 | newView->setCurrentIndex(dirsToAppend.last()); never executed: newView->setCurrentIndex(dirsToAppend.last()); | 0 | ||||||||||||||||||
627 | } never executed: end of block | 0 | ||||||||||||||||||
628 | - | |||||||||||||||||||
629 | if (build && !alreadyExists)
| 0 | ||||||||||||||||||
630 | createColumn(parent, false); never executed: createColumn(parent, false); | 0 | ||||||||||||||||||
631 | } never executed: end of block | 0 | ||||||||||||||||||
632 | - | |||||||||||||||||||
633 | void QColumnViewPrivate::_q_clicked(const QModelIndex &index) | - | ||||||||||||||||||
634 | { | - | ||||||||||||||||||
635 | Q_Q(QColumnView); | - | ||||||||||||||||||
636 | QModelIndex parent = index.parent(); | - | ||||||||||||||||||
637 | QAbstractItemView *columnClicked = 0; | - | ||||||||||||||||||
638 | for (int column = 0; column < columns.count(); ++column) {
| 0 | ||||||||||||||||||
639 | if (columns.at(column)->rootIndex() == parent) {
| 0 | ||||||||||||||||||
640 | columnClicked = columns[column]; | - | ||||||||||||||||||
641 | break; never executed: break; | 0 | ||||||||||||||||||
642 | } | - | ||||||||||||||||||
643 | } never executed: end of block | 0 | ||||||||||||||||||
644 | if (q->selectionModel() && columnClicked) {
| 0 | ||||||||||||||||||
645 | QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::Current; | - | ||||||||||||||||||
646 | if (columnClicked->selectionModel()->isSelected(index))
| 0 | ||||||||||||||||||
647 | flags |= QItemSelectionModel::Select; never executed: flags |= QItemSelectionModel::Select; | 0 | ||||||||||||||||||
648 | q->selectionModel()->setCurrentIndex(index, flags); | - | ||||||||||||||||||
649 | } never executed: end of block | 0 | ||||||||||||||||||
650 | } never executed: end of block | 0 | ||||||||||||||||||
651 | - | |||||||||||||||||||
652 | /*! | - | ||||||||||||||||||
653 | \internal | - | ||||||||||||||||||
654 | Create a new column for \a index. A grip is attached if requested and it is shown | - | ||||||||||||||||||
655 | if requested. | - | ||||||||||||||||||
656 | - | |||||||||||||||||||
657 | Return the new view | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | \sa createColumn(), setPreviewWidget() | - | ||||||||||||||||||
660 | \sa doLayout() | - | ||||||||||||||||||
661 | */ | - | ||||||||||||||||||
662 | QAbstractItemView *QColumnViewPrivate::createColumn(const QModelIndex &index, bool show) | - | ||||||||||||||||||
663 | { | - | ||||||||||||||||||
664 | Q_Q(QColumnView); | - | ||||||||||||||||||
665 | QAbstractItemView *view = 0; | - | ||||||||||||||||||
666 | if (model->hasChildren(index)) {
| 0 | ||||||||||||||||||
667 | view = q->createColumn(index); | - | ||||||||||||||||||
668 | q->connect(view, SIGNAL(clicked(QModelIndex)), | - | ||||||||||||||||||
669 | q, SLOT(_q_clicked(QModelIndex))); | - | ||||||||||||||||||
670 | } else { never executed: end of block | 0 | ||||||||||||||||||
671 | if (!previewColumn)
| 0 | ||||||||||||||||||
672 | setPreviewWidget(new QWidget(q)); never executed: setPreviewWidget(new QWidget(q)); | 0 | ||||||||||||||||||
673 | view = previewColumn; | - | ||||||||||||||||||
674 | view->setMinimumWidth(qMax(view->minimumWidth(), previewWidget->minimumWidth())); | - | ||||||||||||||||||
675 | } never executed: end of block | 0 | ||||||||||||||||||
676 | - | |||||||||||||||||||
677 | q->connect(view, SIGNAL(activated(QModelIndex)), | - | ||||||||||||||||||
678 | q, SIGNAL(activated(QModelIndex))); | - | ||||||||||||||||||
679 | q->connect(view, SIGNAL(clicked(QModelIndex)), | - | ||||||||||||||||||
680 | q, SIGNAL(clicked(QModelIndex))); | - | ||||||||||||||||||
681 | q->connect(view, SIGNAL(doubleClicked(QModelIndex)), | - | ||||||||||||||||||
682 | q, SIGNAL(doubleClicked(QModelIndex))); | - | ||||||||||||||||||
683 | q->connect(view, SIGNAL(entered(QModelIndex)), | - | ||||||||||||||||||
684 | q, SIGNAL(entered(QModelIndex))); | - | ||||||||||||||||||
685 | q->connect(view, SIGNAL(pressed(QModelIndex)), | - | ||||||||||||||||||
686 | q, SIGNAL(pressed(QModelIndex))); | - | ||||||||||||||||||
687 | - | |||||||||||||||||||
688 | view->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||
689 | view->setParent(viewport); | - | ||||||||||||||||||
690 | Q_ASSERT(view); | - | ||||||||||||||||||
691 | - | |||||||||||||||||||
692 | // Setup corner grip | - | ||||||||||||||||||
693 | if (showResizeGrips) {
| 0 | ||||||||||||||||||
694 | QColumnViewGrip *grip = new QColumnViewGrip(view); | - | ||||||||||||||||||
695 | view->setCornerWidget(grip); | - | ||||||||||||||||||
696 | q->connect(grip, SIGNAL(gripMoved(int)), q, SLOT(_q_gripMoved(int))); | - | ||||||||||||||||||
697 | } never executed: end of block | 0 | ||||||||||||||||||
698 | - | |||||||||||||||||||
699 | if (columnSizes.count() > columns.count()) {
| 0 | ||||||||||||||||||
700 | view->setGeometry(0, 0, columnSizes.at(columns.count()), viewport->height()); | - | ||||||||||||||||||
701 | } else { never executed: end of block | 0 | ||||||||||||||||||
702 | int initialWidth = view->sizeHint().width(); | - | ||||||||||||||||||
703 | if (q->isRightToLeft())
| 0 | ||||||||||||||||||
704 | view->setGeometry(viewport->width() - initialWidth, 0, initialWidth, viewport->height()); never executed: view->setGeometry(viewport->width() - initialWidth, 0, initialWidth, viewport->height()); | 0 | ||||||||||||||||||
705 | else | - | ||||||||||||||||||
706 | view->setGeometry(0, 0, initialWidth, viewport->height()); never executed: view->setGeometry(0, 0, initialWidth, viewport->height()); | 0 | ||||||||||||||||||
707 | columnSizes.resize(qMax(columnSizes.count(), columns.count() + 1)); | - | ||||||||||||||||||
708 | columnSizes[columns.count()] = initialWidth; | - | ||||||||||||||||||
709 | } never executed: end of block | 0 | ||||||||||||||||||
710 | if (!columns.isEmpty() && columns.last()->isHidden())
| 0 | ||||||||||||||||||
711 | columns.last()->setVisible(true); never executed: columns.last()->setVisible(true); | 0 | ||||||||||||||||||
712 | - | |||||||||||||||||||
713 | columns.append(view); | - | ||||||||||||||||||
714 | doLayout(); | - | ||||||||||||||||||
715 | updateScrollbars(); | - | ||||||||||||||||||
716 | if (show && view->isHidden())
| 0 | ||||||||||||||||||
717 | view->setVisible(true); never executed: view->setVisible(true); | 0 | ||||||||||||||||||
718 | return view; never executed: return view; | 0 | ||||||||||||||||||
719 | } | - | ||||||||||||||||||
720 | - | |||||||||||||||||||
721 | /*! | - | ||||||||||||||||||
722 | \fn void QColumnView::updatePreviewWidget(const QModelIndex &index) | - | ||||||||||||||||||
723 | - | |||||||||||||||||||
724 | This signal is emitted when the preview widget should be updated to | - | ||||||||||||||||||
725 | provide rich information about \a index | - | ||||||||||||||||||
726 | - | |||||||||||||||||||
727 | \sa previewWidget() | - | ||||||||||||||||||
728 | */ | - | ||||||||||||||||||
729 | - | |||||||||||||||||||
730 | /*! | - | ||||||||||||||||||
731 | To use a custom widget for the final column when you select | - | ||||||||||||||||||
732 | an item overload this function and return a widget. | - | ||||||||||||||||||
733 | \a index is the root index that will be assigned to the view. | - | ||||||||||||||||||
734 | - | |||||||||||||||||||
735 | Return the new view. QColumnView will automatically take ownership of the widget. | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | \sa setPreviewWidget() | - | ||||||||||||||||||
738 | */ | - | ||||||||||||||||||
739 | QAbstractItemView *QColumnView::createColumn(const QModelIndex &index) | - | ||||||||||||||||||
740 | { | - | ||||||||||||||||||
741 | QListView *view = new QListView(viewport()); | - | ||||||||||||||||||
742 | - | |||||||||||||||||||
743 | initializeColumn(view); | - | ||||||||||||||||||
744 | - | |||||||||||||||||||
745 | view->setRootIndex(index); | - | ||||||||||||||||||
746 | if (model()->canFetchMore(index))
| 0 | ||||||||||||||||||
747 | model()->fetchMore(index); never executed: model()->fetchMore(index); | 0 | ||||||||||||||||||
748 | - | |||||||||||||||||||
749 | return view; never executed: return view; | 0 | ||||||||||||||||||
750 | } | - | ||||||||||||||||||
751 | - | |||||||||||||||||||
752 | /*! | - | ||||||||||||||||||
753 | Copies the behavior and options of the column view and applies them to | - | ||||||||||||||||||
754 | the \a column such as the iconSize(), textElideMode() and | - | ||||||||||||||||||
755 | alternatingRowColors(). This can be useful when reimplementing | - | ||||||||||||||||||
756 | createColumn(). | - | ||||||||||||||||||
757 | - | |||||||||||||||||||
758 | \since 4.4 | - | ||||||||||||||||||
759 | \sa createColumn() | - | ||||||||||||||||||
760 | */ | - | ||||||||||||||||||
761 | void QColumnView::initializeColumn(QAbstractItemView *column) const | - | ||||||||||||||||||
762 | { | - | ||||||||||||||||||
763 | Q_D(const QColumnView); | - | ||||||||||||||||||
764 | - | |||||||||||||||||||
765 | column->setFrameShape(QFrame::NoFrame); | - | ||||||||||||||||||
766 | column->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | - | ||||||||||||||||||
767 | column->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); | - | ||||||||||||||||||
768 | column->setMinimumWidth(100); | - | ||||||||||||||||||
769 | column->setAttribute(Qt::WA_MacShowFocusRect, false); | - | ||||||||||||||||||
770 | - | |||||||||||||||||||
771 | #ifndef QT_NO_DRAGANDDROP | - | ||||||||||||||||||
772 | column->setDragDropMode(dragDropMode()); | - | ||||||||||||||||||
773 | column->setDragDropOverwriteMode(dragDropOverwriteMode()); | - | ||||||||||||||||||
774 | column->setDropIndicatorShown(showDropIndicator()); | - | ||||||||||||||||||
775 | #endif | - | ||||||||||||||||||
776 | column->setAlternatingRowColors(alternatingRowColors()); | - | ||||||||||||||||||
777 | column->setAutoScroll(hasAutoScroll()); | - | ||||||||||||||||||
778 | column->setEditTriggers(editTriggers()); | - | ||||||||||||||||||
779 | column->setHorizontalScrollMode(horizontalScrollMode()); | - | ||||||||||||||||||
780 | column->setIconSize(iconSize()); | - | ||||||||||||||||||
781 | column->setSelectionBehavior(selectionBehavior()); | - | ||||||||||||||||||
782 | column->setSelectionMode(selectionMode()); | - | ||||||||||||||||||
783 | column->setTabKeyNavigation(tabKeyNavigation()); | - | ||||||||||||||||||
784 | column->setTextElideMode(textElideMode()); | - | ||||||||||||||||||
785 | column->setVerticalScrollMode(verticalScrollMode()); | - | ||||||||||||||||||
786 | - | |||||||||||||||||||
787 | column->setModel(model()); | - | ||||||||||||||||||
788 | - | |||||||||||||||||||
789 | // Copy the custom delegate per row | - | ||||||||||||||||||
790 | QMapIterator<int, QPointer<QAbstractItemDelegate> > i(d->rowDelegates); | - | ||||||||||||||||||
791 | while (i.hasNext()) {
| 0 | ||||||||||||||||||
792 | i.next(); | - | ||||||||||||||||||
793 | column->setItemDelegateForRow(i.key(), i.value()); | - | ||||||||||||||||||
794 | } never executed: end of block | 0 | ||||||||||||||||||
795 | - | |||||||||||||||||||
796 | // set the delegate to be the columnview delegate | - | ||||||||||||||||||
797 | QAbstractItemDelegate *delegate = column->itemDelegate(); | - | ||||||||||||||||||
798 | column->setItemDelegate(d->itemDelegate); | - | ||||||||||||||||||
799 | delete delegate; | - | ||||||||||||||||||
800 | } never executed: end of block | 0 | ||||||||||||||||||
801 | - | |||||||||||||||||||
802 | /*! | - | ||||||||||||||||||
803 | Returns the preview widget, or 0 if there is none. | - | ||||||||||||||||||
804 | - | |||||||||||||||||||
805 | \sa setPreviewWidget(), updatePreviewWidget() | - | ||||||||||||||||||
806 | */ | - | ||||||||||||||||||
807 | QWidget *QColumnView::previewWidget() const | - | ||||||||||||||||||
808 | { | - | ||||||||||||||||||
809 | Q_D(const QColumnView); | - | ||||||||||||||||||
810 | return d->previewWidget; never executed: return d->previewWidget; | 0 | ||||||||||||||||||
811 | } | - | ||||||||||||||||||
812 | - | |||||||||||||||||||
813 | /*! | - | ||||||||||||||||||
814 | Sets the preview \a widget. | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | The \a widget becomes a child of the column view, and will be | - | ||||||||||||||||||
817 | destroyed when the column area is deleted or when a new widget is | - | ||||||||||||||||||
818 | set. | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | \sa previewWidget(), updatePreviewWidget() | - | ||||||||||||||||||
821 | */ | - | ||||||||||||||||||
822 | void QColumnView::setPreviewWidget(QWidget *widget) | - | ||||||||||||||||||
823 | { | - | ||||||||||||||||||
824 | Q_D(QColumnView); | - | ||||||||||||||||||
825 | d->setPreviewWidget(widget); | - | ||||||||||||||||||
826 | } never executed: end of block | 0 | ||||||||||||||||||
827 | - | |||||||||||||||||||
828 | /*! | - | ||||||||||||||||||
829 | \internal | - | ||||||||||||||||||
830 | */ | - | ||||||||||||||||||
831 | void QColumnViewPrivate::setPreviewWidget(QWidget *widget) | - | ||||||||||||||||||
832 | { | - | ||||||||||||||||||
833 | Q_Q(QColumnView); | - | ||||||||||||||||||
834 | if (previewColumn) {
| 0 | ||||||||||||||||||
835 | if (!columns.isEmpty() && columns.last() == previewColumn)
| 0 | ||||||||||||||||||
836 | columns.removeLast(); never executed: columns.removeLast(); | 0 | ||||||||||||||||||
837 | previewColumn->deleteLater(); | - | ||||||||||||||||||
838 | } never executed: end of block | 0 | ||||||||||||||||||
839 | QColumnViewPreviewColumn *column = new QColumnViewPreviewColumn(q); | - | ||||||||||||||||||
840 | column->setPreviewWidget(widget); | - | ||||||||||||||||||
841 | previewColumn = column; | - | ||||||||||||||||||
842 | previewColumn->hide(); | - | ||||||||||||||||||
843 | previewColumn->setFrameShape(QFrame::NoFrame); | - | ||||||||||||||||||
844 | previewColumn->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); | - | ||||||||||||||||||
845 | previewColumn->setSelectionMode(QAbstractItemView::NoSelection); | - | ||||||||||||||||||
846 | previewColumn->setMinimumWidth(qMax(previewColumn->verticalScrollBar()->width(), | - | ||||||||||||||||||
847 | previewColumn->minimumWidth())); | - | ||||||||||||||||||
848 | previewWidget = widget; | - | ||||||||||||||||||
849 | previewWidget->setParent(previewColumn->viewport()); | - | ||||||||||||||||||
850 | } never executed: end of block | 0 | ||||||||||||||||||
851 | - | |||||||||||||||||||
852 | /*! | - | ||||||||||||||||||
853 | Sets the column widths to the values given in the \a list. Extra values in the list are | - | ||||||||||||||||||
854 | kept and used when the columns are created. | - | ||||||||||||||||||
855 | - | |||||||||||||||||||
856 | If list contains too few values, only width of the rest of the columns will not be modified. | - | ||||||||||||||||||
857 | - | |||||||||||||||||||
858 | \sa columnWidths(), createColumn() | - | ||||||||||||||||||
859 | */ | - | ||||||||||||||||||
860 | void QColumnView::setColumnWidths(const QList<int> &list) | - | ||||||||||||||||||
861 | { | - | ||||||||||||||||||
862 | Q_D(QColumnView); | - | ||||||||||||||||||
863 | int i = 0; | - | ||||||||||||||||||
864 | const int listCount = list.count(); | - | ||||||||||||||||||
865 | const int count = qMin(listCount, d->columns.count()); | - | ||||||||||||||||||
866 | for (; i < count; ++i) {
| 0 | ||||||||||||||||||
867 | d->columns.at(i)->resize(list.at(i), d->columns.at(i)->height()); | - | ||||||||||||||||||
868 | d->columnSizes[i] = list.at(i); | - | ||||||||||||||||||
869 | } never executed: end of block | 0 | ||||||||||||||||||
870 | - | |||||||||||||||||||
871 | d->columnSizes.reserve(listCount); | - | ||||||||||||||||||
872 | for (; i < listCount; ++i)
| 0 | ||||||||||||||||||
873 | d->columnSizes.append(list.at(i)); never executed: d->columnSizes.append(list.at(i)); | 0 | ||||||||||||||||||
874 | } never executed: end of block | 0 | ||||||||||||||||||
875 | - | |||||||||||||||||||
876 | /*! | - | ||||||||||||||||||
877 | Returns a list of the width of all the columns in this view. | - | ||||||||||||||||||
878 | - | |||||||||||||||||||
879 | \sa setColumnWidths() | - | ||||||||||||||||||
880 | */ | - | ||||||||||||||||||
881 | QList<int> QColumnView::columnWidths() const | - | ||||||||||||||||||
882 | { | - | ||||||||||||||||||
883 | Q_D(const QColumnView); | - | ||||||||||||||||||
884 | QList<int> list; | - | ||||||||||||||||||
885 | const int columnCount = d->columns.count(); | - | ||||||||||||||||||
886 | list.reserve(columnCount); | - | ||||||||||||||||||
887 | for (int i = 0; i < columnCount; ++i)
| 0 | ||||||||||||||||||
888 | list.append(d->columnSizes.at(i)); never executed: list.append(d->columnSizes.at(i)); | 0 | ||||||||||||||||||
889 | return list; never executed: return list; | 0 | ||||||||||||||||||
890 | } | - | ||||||||||||||||||
891 | - | |||||||||||||||||||
892 | /*! | - | ||||||||||||||||||
893 | \reimp | - | ||||||||||||||||||
894 | */ | - | ||||||||||||||||||
895 | void QColumnView::rowsInserted(const QModelIndex &parent, int start, int end) | - | ||||||||||||||||||
896 | { | - | ||||||||||||||||||
897 | QAbstractItemView::rowsInserted(parent, start, end); | - | ||||||||||||||||||
898 | d_func()->checkColumnCreation(parent); | - | ||||||||||||||||||
899 | } never executed: end of block | 0 | ||||||||||||||||||
900 | - | |||||||||||||||||||
901 | /*! | - | ||||||||||||||||||
902 | \reimp | - | ||||||||||||||||||
903 | */ | - | ||||||||||||||||||
904 | void QColumnView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) | - | ||||||||||||||||||
905 | { | - | ||||||||||||||||||
906 | Q_D(QColumnView); | - | ||||||||||||||||||
907 | if (!current.isValid()) {
| 0 | ||||||||||||||||||
908 | QAbstractItemView::currentChanged(current, previous); | - | ||||||||||||||||||
909 | return; never executed: return; | 0 | ||||||||||||||||||
910 | } | - | ||||||||||||||||||
911 | - | |||||||||||||||||||
912 | QModelIndex currentParent = current.parent(); | - | ||||||||||||||||||
913 | // optimize for just moving up/down in a list where the child view doesn't change | - | ||||||||||||||||||
914 | if (currentParent == previous.parent()
| 0 | ||||||||||||||||||
915 | && model()->hasChildren(current) && model()->hasChildren(previous)) {
| 0 | ||||||||||||||||||
916 | for (int i = 0; i < d->columns.size(); ++i) {
| 0 | ||||||||||||||||||
917 | if (currentParent == d->columns.at(i)->rootIndex()) {
| 0 | ||||||||||||||||||
918 | if (d->columns.size() > i + 1) {
| 0 | ||||||||||||||||||
919 | QAbstractItemView::currentChanged(current, previous); | - | ||||||||||||||||||
920 | return; never executed: return; | 0 | ||||||||||||||||||
921 | } | - | ||||||||||||||||||
922 | break; never executed: break; | 0 | ||||||||||||||||||
923 | } | - | ||||||||||||||||||
924 | } never executed: end of block | 0 | ||||||||||||||||||
925 | } never executed: end of block | 0 | ||||||||||||||||||
926 | - | |||||||||||||||||||
927 | // Scrolling to the right we need to have an empty spot | - | ||||||||||||||||||
928 | bool found = false; | - | ||||||||||||||||||
929 | if (currentParent == previous) {
| 0 | ||||||||||||||||||
930 | for (int i = 0; i < d->columns.size(); ++i) {
| 0 | ||||||||||||||||||
931 | if (currentParent == d->columns.at(i)->rootIndex()) {
| 0 | ||||||||||||||||||
932 | found = true; | - | ||||||||||||||||||
933 | if (d->columns.size() < i + 2) {
| 0 | ||||||||||||||||||
934 | d->createColumn(current, false); | - | ||||||||||||||||||
935 | } never executed: end of block | 0 | ||||||||||||||||||
936 | break; never executed: break; | 0 | ||||||||||||||||||
937 | } | - | ||||||||||||||||||
938 | } never executed: end of block | 0 | ||||||||||||||||||
939 | } never executed: end of block | 0 | ||||||||||||||||||
940 | if (!found)
| 0 | ||||||||||||||||||
941 | d->closeColumns(current, true); never executed: d->closeColumns(current, true); | 0 | ||||||||||||||||||
942 | - | |||||||||||||||||||
943 | if (!model()->hasChildren(current))
| 0 | ||||||||||||||||||
944 | emit updatePreviewWidget(current); never executed: updatePreviewWidget(current); | 0 | ||||||||||||||||||
945 | - | |||||||||||||||||||
946 | QAbstractItemView::currentChanged(current, previous); | - | ||||||||||||||||||
947 | } never executed: end of block | 0 | ||||||||||||||||||
948 | - | |||||||||||||||||||
949 | /* | - | ||||||||||||||||||
950 | We have change the current column and need to update focus and selection models | - | ||||||||||||||||||
951 | on the new current column. | - | ||||||||||||||||||
952 | */ | - | ||||||||||||||||||
953 | void QColumnViewPrivate::_q_changeCurrentColumn() | - | ||||||||||||||||||
954 | { | - | ||||||||||||||||||
955 | Q_Q(QColumnView); | - | ||||||||||||||||||
956 | if (columns.isEmpty())
| 0 | ||||||||||||||||||
957 | return; never executed: return; | 0 | ||||||||||||||||||
958 | - | |||||||||||||||||||
959 | QModelIndex current = q->currentIndex(); | - | ||||||||||||||||||
960 | if (!current.isValid())
| 0 | ||||||||||||||||||
961 | return; never executed: return; | 0 | ||||||||||||||||||
962 | - | |||||||||||||||||||
963 | // We might have scrolled far to the left so we need to close all of the children | - | ||||||||||||||||||
964 | closeColumns(current, true); | - | ||||||||||||||||||
965 | - | |||||||||||||||||||
966 | // Set up the "current" column with focus | - | ||||||||||||||||||
967 | int currentColumn = qMax(0, columns.size() - 2); | - | ||||||||||||||||||
968 | QAbstractItemView *parentColumn = columns.at(currentColumn); | - | ||||||||||||||||||
969 | if (q->hasFocus())
| 0 | ||||||||||||||||||
970 | parentColumn->setFocus(Qt::OtherFocusReason); never executed: parentColumn->setFocus(Qt::OtherFocusReason); | 0 | ||||||||||||||||||
971 | q->setFocusProxy(parentColumn); | - | ||||||||||||||||||
972 | - | |||||||||||||||||||
973 | // find the column that is our current selection model and give it a new one. | - | ||||||||||||||||||
974 | for (int i = 0; i < columns.size(); ++i) {
| 0 | ||||||||||||||||||
975 | if (columns.at(i)->selectionModel() == q->selectionModel()) {
| 0 | ||||||||||||||||||
976 | QItemSelectionModel *replacementSelectionModel = | - | ||||||||||||||||||
977 | new QItemSelectionModel(parentColumn->model()); | - | ||||||||||||||||||
978 | replacementSelectionModel->setCurrentIndex( | - | ||||||||||||||||||
979 | q->selectionModel()->currentIndex(), QItemSelectionModel::Current); | - | ||||||||||||||||||
980 | replacementSelectionModel->select( | - | ||||||||||||||||||
981 | q->selectionModel()->selection(), QItemSelectionModel::Select); | - | ||||||||||||||||||
982 | QAbstractItemView *view = columns.at(i); | - | ||||||||||||||||||
983 | view->setSelectionModel(replacementSelectionModel); | - | ||||||||||||||||||
984 | view->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||
985 | if (columns.size() > i + 1) {
| 0 | ||||||||||||||||||
986 | const QModelIndex newRootIndex = columns.at(i + 1)->rootIndex(); | - | ||||||||||||||||||
987 | if (newRootIndex.isValid())
| 0 | ||||||||||||||||||
988 | view->setCurrentIndex(newRootIndex); never executed: view->setCurrentIndex(newRootIndex); | 0 | ||||||||||||||||||
989 | } never executed: end of block | 0 | ||||||||||||||||||
990 | break; never executed: break; | 0 | ||||||||||||||||||
991 | } | - | ||||||||||||||||||
992 | } never executed: end of block | 0 | ||||||||||||||||||
993 | parentColumn->selectionModel()->deleteLater(); | - | ||||||||||||||||||
994 | parentColumn->setFocusPolicy(Qt::StrongFocus); | - | ||||||||||||||||||
995 | parentColumn->setSelectionModel(q->selectionModel()); | - | ||||||||||||||||||
996 | // We want the parent selection to stay highlighted (but dimmed depending upon the color theme) | - | ||||||||||||||||||
997 | if (currentColumn > 0) {
| 0 | ||||||||||||||||||
998 | parentColumn = columns.at(currentColumn - 1); | - | ||||||||||||||||||
999 | if (parentColumn->currentIndex() != current.parent())
| 0 | ||||||||||||||||||
1000 | parentColumn->setCurrentIndex(current.parent()); never executed: parentColumn->setCurrentIndex(current.parent()); | 0 | ||||||||||||||||||
1001 | } never executed: end of block | 0 | ||||||||||||||||||
1002 | - | |||||||||||||||||||
1003 | if (columns.last()->isHidden()) {
| 0 | ||||||||||||||||||
1004 | columns.last()->setVisible(true); | - | ||||||||||||||||||
1005 | } never executed: end of block | 0 | ||||||||||||||||||
1006 | if (columns.last()->selectionModel())
| 0 | ||||||||||||||||||
1007 | columns.last()->selectionModel()->clear(); never executed: columns.last()->selectionModel()->clear(); | 0 | ||||||||||||||||||
1008 | updateScrollbars(); | - | ||||||||||||||||||
1009 | } never executed: end of block | 0 | ||||||||||||||||||
1010 | - | |||||||||||||||||||
1011 | /*! | - | ||||||||||||||||||
1012 | \reimp | - | ||||||||||||||||||
1013 | */ | - | ||||||||||||||||||
1014 | void QColumnView::selectAll() | - | ||||||||||||||||||
1015 | { | - | ||||||||||||||||||
1016 | if (!model() || !selectionModel())
| 0 | ||||||||||||||||||
1017 | return; never executed: return; | 0 | ||||||||||||||||||
1018 | - | |||||||||||||||||||
1019 | QModelIndexList indexList = selectionModel()->selectedIndexes(); | - | ||||||||||||||||||
1020 | QModelIndex parent = rootIndex(); | - | ||||||||||||||||||
1021 | QItemSelection selection; | - | ||||||||||||||||||
1022 | if (indexList.count() >= 1)
| 0 | ||||||||||||||||||
1023 | parent = indexList.at(0).parent(); never executed: parent = indexList.at(0).parent(); | 0 | ||||||||||||||||||
1024 | if (indexList.count() == 1) {
| 0 | ||||||||||||||||||
1025 | parent = indexList.at(0); | - | ||||||||||||||||||
1026 | if (!model()->hasChildren(parent))
| 0 | ||||||||||||||||||
1027 | parent = parent.parent(); never executed: parent = parent.parent(); | 0 | ||||||||||||||||||
1028 | else | - | ||||||||||||||||||
1029 | selection.append(QItemSelectionRange(parent, parent)); never executed: selection.append(QItemSelectionRange(parent, parent)); | 0 | ||||||||||||||||||
1030 | } | - | ||||||||||||||||||
1031 | - | |||||||||||||||||||
1032 | QModelIndex tl = model()->index(0, 0, parent); | - | ||||||||||||||||||
1033 | QModelIndex br = model()->index(model()->rowCount(parent) - 1, | - | ||||||||||||||||||
1034 | model()->columnCount(parent) - 1, | - | ||||||||||||||||||
1035 | parent); | - | ||||||||||||||||||
1036 | selection.append(QItemSelectionRange(tl, br)); | - | ||||||||||||||||||
1037 | selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect); | - | ||||||||||||||||||
1038 | } never executed: end of block | 0 | ||||||||||||||||||
1039 | - | |||||||||||||||||||
1040 | /* | - | ||||||||||||||||||
1041 | * private object implementation | - | ||||||||||||||||||
1042 | */ | - | ||||||||||||||||||
1043 | QColumnViewPrivate::QColumnViewPrivate() | - | ||||||||||||||||||
1044 | : QAbstractItemViewPrivate() | - | ||||||||||||||||||
1045 | ,showResizeGrips(true) | - | ||||||||||||||||||
1046 | ,offset(0) | - | ||||||||||||||||||
1047 | ,previewWidget(0) | - | ||||||||||||||||||
1048 | ,previewColumn(0) | - | ||||||||||||||||||
1049 | { | - | ||||||||||||||||||
1050 | } never executed: end of block | 0 | ||||||||||||||||||
1051 | - | |||||||||||||||||||
1052 | QColumnViewPrivate::~QColumnViewPrivate() | - | ||||||||||||||||||
1053 | { | - | ||||||||||||||||||
1054 | } | - | ||||||||||||||||||
1055 | - | |||||||||||||||||||
1056 | /*! | - | ||||||||||||||||||
1057 | \internal | - | ||||||||||||||||||
1058 | - | |||||||||||||||||||
1059 | */ | - | ||||||||||||||||||
1060 | void QColumnViewPrivate::_q_columnsInserted(const QModelIndex &parent, int start, int end) | - | ||||||||||||||||||
1061 | { | - | ||||||||||||||||||
1062 | QAbstractItemViewPrivate::_q_columnsInserted(parent, start, end); | - | ||||||||||||||||||
1063 | checkColumnCreation(parent); | - | ||||||||||||||||||
1064 | } never executed: end of block | 0 | ||||||||||||||||||
1065 | - | |||||||||||||||||||
1066 | /*! | - | ||||||||||||||||||
1067 | \internal | - | ||||||||||||||||||
1068 | - | |||||||||||||||||||
1069 | Makes sure we create a corresponding column as a result of changing the model. | - | ||||||||||||||||||
1070 | - | |||||||||||||||||||
1071 | */ | - | ||||||||||||||||||
1072 | void QColumnViewPrivate::checkColumnCreation(const QModelIndex &parent) | - | ||||||||||||||||||
1073 | { | - | ||||||||||||||||||
1074 | if (parent == q_func()->currentIndex() && model->hasChildren(parent)) {
| 0 | ||||||||||||||||||
1075 | //the parent has children and is the current | - | ||||||||||||||||||
1076 | //let's try to find out if there is already a mapping that is good | - | ||||||||||||||||||
1077 | for (int i = 0; i < columns.count(); ++i) {
| 0 | ||||||||||||||||||
1078 | QAbstractItemView *view = columns.at(i); | - | ||||||||||||||||||
1079 | if (view->rootIndex() == parent) {
| 0 | ||||||||||||||||||
1080 | if (view == previewColumn) {
| 0 | ||||||||||||||||||
1081 | //let's recreate the parent | - | ||||||||||||||||||
1082 | closeColumns(parent, false); | - | ||||||||||||||||||
1083 | createColumn(parent, true /*show*/); | - | ||||||||||||||||||
1084 | } never executed: end of block | 0 | ||||||||||||||||||
1085 | break; never executed: break; | 0 | ||||||||||||||||||
1086 | } | - | ||||||||||||||||||
1087 | } never executed: end of block | 0 | ||||||||||||||||||
1088 | } never executed: end of block | 0 | ||||||||||||||||||
1089 | } never executed: end of block | 0 | ||||||||||||||||||
1090 | - | |||||||||||||||||||
1091 | /*! | - | ||||||||||||||||||
1092 | \internal | - | ||||||||||||||||||
1093 | Place all of the columns where they belong inside of the viewport, resize as necessary. | - | ||||||||||||||||||
1094 | */ | - | ||||||||||||||||||
1095 | void QColumnViewPrivate::doLayout() | - | ||||||||||||||||||
1096 | { | - | ||||||||||||||||||
1097 | Q_Q(QColumnView); | - | ||||||||||||||||||
1098 | if (!model || columns.isEmpty())
| 0 | ||||||||||||||||||
1099 | return; never executed: return; | 0 | ||||||||||||||||||
1100 | - | |||||||||||||||||||
1101 | int viewportHeight = viewport->height(); | - | ||||||||||||||||||
1102 | int x = columns.at(0)->x(); | - | ||||||||||||||||||
1103 | - | |||||||||||||||||||
1104 | if (q->isRightToLeft()) {
| 0 | ||||||||||||||||||
1105 | x = viewport->width() + q->horizontalOffset(); | - | ||||||||||||||||||
1106 | for (int i = 0; i < columns.size(); ++i) {
| 0 | ||||||||||||||||||
1107 | QAbstractItemView *view = columns.at(i); | - | ||||||||||||||||||
1108 | x -= view->width(); | - | ||||||||||||||||||
1109 | if (x != view->x() || viewportHeight != view->height())
| 0 | ||||||||||||||||||
1110 | view->setGeometry(x, 0, view->width(), viewportHeight); never executed: view->setGeometry(x, 0, view->width(), viewportHeight); | 0 | ||||||||||||||||||
1111 | } never executed: end of block | 0 | ||||||||||||||||||
1112 | } else { never executed: end of block | 0 | ||||||||||||||||||
1113 | for (int i = 0; i < columns.size(); ++i) {
| 0 | ||||||||||||||||||
1114 | QAbstractItemView *view = columns.at(i); | - | ||||||||||||||||||
1115 | int currentColumnWidth = view->width(); | - | ||||||||||||||||||
1116 | if (x != view->x() || viewportHeight != view->height())
| 0 | ||||||||||||||||||
1117 | view->setGeometry(x, 0, currentColumnWidth, viewportHeight); never executed: view->setGeometry(x, 0, currentColumnWidth, viewportHeight); | 0 | ||||||||||||||||||
1118 | x += currentColumnWidth; | - | ||||||||||||||||||
1119 | } never executed: end of block | 0 | ||||||||||||||||||
1120 | } never executed: end of block | 0 | ||||||||||||||||||
1121 | } | - | ||||||||||||||||||
1122 | - | |||||||||||||||||||
1123 | /*! | - | ||||||||||||||||||
1124 | \internal | - | ||||||||||||||||||
1125 | - | |||||||||||||||||||
1126 | Draws a delegate with a > if an object has children. | - | ||||||||||||||||||
1127 | - | |||||||||||||||||||
1128 | \sa {Model/View Programming}, QItemDelegate | - | ||||||||||||||||||
1129 | */ | - | ||||||||||||||||||
1130 | void QColumnViewDelegate::paint(QPainter *painter, | - | ||||||||||||||||||
1131 | const QStyleOptionViewItem &option, | - | ||||||||||||||||||
1132 | const QModelIndex &index) const | - | ||||||||||||||||||
1133 | { | - | ||||||||||||||||||
1134 | drawBackground(painter, option, index ); | - | ||||||||||||||||||
1135 | - | |||||||||||||||||||
1136 | bool reverse = (option.direction == Qt::RightToLeft); | - | ||||||||||||||||||
1137 | int width = ((option.rect.height() * 2) / 3); | - | ||||||||||||||||||
1138 | // Modify the options to give us room to add an arrow | - | ||||||||||||||||||
1139 | QStyleOptionViewItem opt = option; | - | ||||||||||||||||||
1140 | if (reverse)
| 0 | ||||||||||||||||||
1141 | opt.rect.adjust(width,0,0,0); never executed: opt.rect.adjust(width,0,0,0); | 0 | ||||||||||||||||||
1142 | else | - | ||||||||||||||||||
1143 | opt.rect.adjust(0,0,-width,0); never executed: opt.rect.adjust(0,0,-width,0); | 0 | ||||||||||||||||||
1144 | - | |||||||||||||||||||
1145 | if (!(index.model()->flags(index) & Qt::ItemIsEnabled)) {
| 0 | ||||||||||||||||||
1146 | opt.showDecorationSelected = true; | - | ||||||||||||||||||
1147 | opt.state |= QStyle::State_Selected; | - | ||||||||||||||||||
1148 | } never executed: end of block | 0 | ||||||||||||||||||
1149 | - | |||||||||||||||||||
1150 | QItemDelegate::paint(painter, opt, index); | - | ||||||||||||||||||
1151 | - | |||||||||||||||||||
1152 | if (reverse)
| 0 | ||||||||||||||||||
1153 | opt.rect = QRect(option.rect.x(), option.rect.y(), width, option.rect.height()); never executed: opt.rect = QRect(option.rect.x(), option.rect.y(), width, option.rect.height()); | 0 | ||||||||||||||||||
1154 | else | - | ||||||||||||||||||
1155 | opt.rect = QRect(option.rect.x() + option.rect.width() - width, option.rect.y(), never executed: opt.rect = QRect(option.rect.x() + option.rect.width() - width, option.rect.y(), width, option.rect.height()); | 0 | ||||||||||||||||||
1156 | width, option.rect.height()); never executed: opt.rect = QRect(option.rect.x() + option.rect.width() - width, option.rect.y(), width, option.rect.height()); | 0 | ||||||||||||||||||
1157 | - | |||||||||||||||||||
1158 | // Draw > | - | ||||||||||||||||||
1159 | if (index.model()->hasChildren(index)) {
| 0 | ||||||||||||||||||
1160 | const QWidget *view = opt.widget; | - | ||||||||||||||||||
1161 | QStyle *style = view ? view->style() : QApplication::style();
| 0 | ||||||||||||||||||
1162 | style->drawPrimitive(QStyle::PE_IndicatorColumnViewArrow, &opt, painter, view); | - | ||||||||||||||||||
1163 | } never executed: end of block | 0 | ||||||||||||||||||
1164 | } never executed: end of block | 0 | ||||||||||||||||||
1165 | - | |||||||||||||||||||
1166 | QT_END_NAMESPACE | - | ||||||||||||||||||
1167 | - | |||||||||||||||||||
1168 | #include "moc_qcolumnview.cpp" | - | ||||||||||||||||||
1169 | - | |||||||||||||||||||
1170 | #endif // QT_NO_COLUMNVIEW | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |