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