| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | QTreeView::QTreeView(QWidget *parent) | - |
| 9 | : QAbstractItemView(*new QTreeViewPrivate, parent) | - |
| 10 | { | - |
| 11 | QTreeViewPrivate * const d = d_func(); | - |
| 12 | d->initialize(); | - |
| 13 | } | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | QTreeView::QTreeView(QTreeViewPrivate &dd, QWidget *parent) | - |
| 19 | : QAbstractItemView(dd, parent) | - |
| 20 | { | - |
| 21 | QTreeViewPrivate * const d = d_func(); | - |
| 22 | d->initialize(); | - |
| 23 | } | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | QTreeView::~QTreeView() | - |
| 29 | { | - |
| 30 | } | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | void QTreeView::setModel(QAbstractItemModel *model) | - |
| 36 | { | - |
| 37 | QTreeViewPrivate * const d = d_func(); | - |
| 38 | if (model == d->model) | - |
| 39 | return; | - |
| 40 | if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) { | - |
| 41 | disconnect(d->model, "2""rowsRemoved(QModelIndex,int,int)", | - |
| 42 | this, "1""rowsRemoved(QModelIndex,int,int)"); | - |
| 43 | | - |
| 44 | disconnect(d->model, "2""modelAboutToBeReset()", this, "1""_q_modelAboutToBeReset()"); | - |
| 45 | } | - |
| 46 | | - |
| 47 | if (d->selectionModel) { | - |
| 48 | disconnect(d->selectionModel, "2""currentRowChanged(QModelIndex,QModelIndex)", | - |
| 49 | d->model, "1""submit()"); | - |
| 50 | disconnect(d->model, "2""rowsRemoved(QModelIndex,int,int)", | - |
| 51 | this, "1""rowsRemoved(QModelIndex,int,int)"); | - |
| 52 | disconnect(d->model, "2""modelAboutToBeReset()", this, "1""_q_modelAboutToBeReset()"); | - |
| 53 | } | - |
| 54 | d->viewItems.clear(); | - |
| 55 | d->expandedIndexes.clear(); | - |
| 56 | d->hiddenIndexes.clear(); | - |
| 57 | d->header->setModel(model); | - |
| 58 | QAbstractItemView::setModel(model); | - |
| 59 | | - |
| 60 | | - |
| 61 | disconnect(d->model, "2""rowsRemoved(QModelIndex,int,int)", | - |
| 62 | this, "1""_q_rowsRemoved(QModelIndex,int,int)"); | - |
| 63 | | - |
| 64 | disconnect(d->model, "2""layoutChanged()", | - |
| 65 | d->header, "1""_q_layoutChanged()"); | - |
| 66 | | - |
| 67 | connect(d->model, "2""rowsRemoved(QModelIndex,int,int)", | - |
| 68 | this, "1""rowsRemoved(QModelIndex,int,int)"); | - |
| 69 | | - |
| 70 | connect(d->model, "2""modelAboutToBeReset()", "1""_q_modelAboutToBeReset()"); | - |
| 71 | | - |
| 72 | if (d->sortingEnabled) | - |
| 73 | d->_q_sortIndicatorChanged(header()->sortIndicatorSection(), header()->sortIndicatorOrder()); | - |
| 74 | } | - |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | void QTreeView::setRootIndex(const QModelIndex &index) | - |
| 80 | { | - |
| 81 | QTreeViewPrivate * const d = d_func(); | - |
| 82 | d->header->setRootIndex(index); | - |
| 83 | QAbstractItemView::setRootIndex(index); | - |
| 84 | } | - |
| 85 | | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | void QTreeView::setSelectionModel(QItemSelectionModel *selectionModel) | - |
| 90 | { | - |
| 91 | QTreeViewPrivate * const d = d_func(); | - |
| 92 | qt_noop(); | - |
| 93 | if (d->selectionModel) { | - |
| 94 | | - |
| 95 | disconnect(d->selectionModel, "2""currentRowChanged(QModelIndex,QModelIndex)", | - |
| 96 | d->model, "1""submit()"); | - |
| 97 | } | - |
| 98 | | - |
| 99 | d->header->setSelectionModel(selectionModel); | - |
| 100 | QAbstractItemView::setSelectionModel(selectionModel); | - |
| 101 | | - |
| 102 | if (d->selectionModel) { | - |
| 103 | | - |
| 104 | connect(d->selectionModel, "2""currentRowChanged(QModelIndex,QModelIndex)", | - |
| 105 | d->model, "1""submit()"); | - |
| 106 | } | - |
| 107 | } | - |
| 108 | | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | QHeaderView *QTreeView::header() const | - |
| 115 | { | - |
| 116 | const QTreeViewPrivate * const d = d_func(); | - |
| 117 | return d->header; | - |
| 118 | } | - |
| 119 | void QTreeView::setHeader(QHeaderView *header) | - |
| 120 | { | - |
| 121 | QTreeViewPrivate * const d = d_func(); | - |
| 122 | if (header == d->header || !header) | - |
| 123 | return; | - |
| 124 | if (d->header && d->header->parent() == this) | - |
| 125 | delete d->header; | - |
| 126 | d->header = header; | - |
| 127 | d->header->setParent(this); | - |
| 128 | d->header->d_func()->setAllowUserMoveOfSection0(false); | - |
| 129 | | - |
| 130 | if (!d->header->model()) { | - |
| 131 | d->header->setModel(d->model); | - |
| 132 | if (d->selectionModel) | - |
| 133 | d->header->setSelectionModel(d->selectionModel); | - |
| 134 | } | - |
| 135 | | - |
| 136 | connect(d->header, "2""sectionResized(int,int,int)", | - |
| 137 | this, "1""columnResized(int,int,int)"); | - |
| 138 | connect(d->header, "2""sectionMoved(int,int,int)", | - |
| 139 | this, "1""columnMoved()"); | - |
| 140 | connect(d->header, "2""sectionCountChanged(int,int)", | - |
| 141 | this, "1""columnCountChanged(int,int)"); | - |
| 142 | connect(d->header, "2""sectionHandleDoubleClicked(int)", | - |
| 143 | this, "1""resizeColumnToContents(int)"); | - |
| 144 | connect(d->header, "2""geometriesChanged()", | - |
| 145 | this, "1""updateGeometries()"); | - |
| 146 | | - |
| 147 | setSortingEnabled(d->sortingEnabled); | - |
| 148 | } | - |
| 149 | int QTreeView::autoExpandDelay() const | - |
| 150 | { | - |
| 151 | const QTreeViewPrivate * const d = d_func(); | - |
| 152 | return d->autoExpandDelay; | - |
| 153 | } | - |
| 154 | | - |
| 155 | void QTreeView::setAutoExpandDelay(int delay) | - |
| 156 | { | - |
| 157 | QTreeViewPrivate * const d = d_func(); | - |
| 158 | d->autoExpandDelay = delay; | - |
| 159 | } | - |
| 160 | int QTreeView::indentation() const | - |
| 161 | { | - |
| 162 | const QTreeViewPrivate * const d = d_func(); | - |
| 163 | return d->indent; | - |
| 164 | } | - |
| 165 | | - |
| 166 | void QTreeView::setIndentation(int i) | - |
| 167 | { | - |
| 168 | QTreeViewPrivate * const d = d_func(); | - |
| 169 | if (i != d->indent) { | - |
| 170 | d->indent = i; | - |
| 171 | d->viewport->update(); | - |
| 172 | } | - |
| 173 | } | - |
| 174 | bool QTreeView::rootIsDecorated() const | - |
| 175 | { | - |
| 176 | const QTreeViewPrivate * const d = d_func(); | - |
| 177 | return d->rootDecoration; | - |
| 178 | } | - |
| 179 | | - |
| 180 | void QTreeView::setRootIsDecorated(bool show) | - |
| 181 | { | - |
| 182 | QTreeViewPrivate * const d = d_func(); | - |
| 183 | if (show != d->rootDecoration) { | - |
| 184 | d->rootDecoration = show; | - |
| 185 | d->viewport->update(); | - |
| 186 | } | - |
| 187 | } | - |
| 188 | bool QTreeView::uniformRowHeights() const | - |
| 189 | { | - |
| 190 | const QTreeViewPrivate * const d = d_func(); | - |
| 191 | return d->uniformRowHeights; | - |
| 192 | } | - |
| 193 | | - |
| 194 | void QTreeView::setUniformRowHeights(bool uniform) | - |
| 195 | { | - |
| 196 | QTreeViewPrivate * const d = d_func(); | - |
| 197 | d->uniformRowHeights = uniform; | - |
| 198 | } | - |
| 199 | bool QTreeView::itemsExpandable() const | - |
| 200 | { | - |
| 201 | const QTreeViewPrivate * const d = d_func(); | - |
| 202 | return d->itemsExpandable; | - |
| 203 | } | - |
| 204 | | - |
| 205 | void QTreeView::setItemsExpandable(bool enable) | - |
| 206 | { | - |
| 207 | QTreeViewPrivate * const d = d_func(); | - |
| 208 | d->itemsExpandable = enable; | - |
| 209 | } | - |
| 210 | bool QTreeView::expandsOnDoubleClick() const | - |
| 211 | { | - |
| 212 | const QTreeViewPrivate * const d = d_func(); | - |
| 213 | return d->expandsOnDoubleClick; | - |
| 214 | } | - |
| 215 | | - |
| 216 | void QTreeView::setExpandsOnDoubleClick(bool enable) | - |
| 217 | { | - |
| 218 | QTreeViewPrivate * const d = d_func(); | - |
| 219 | d->expandsOnDoubleClick = enable; | - |
| 220 | } | - |
| 221 | | - |
| 222 | | - |
| 223 | | - |
| 224 | | - |
| 225 | int QTreeView::columnViewportPosition(int column) const | - |
| 226 | { | - |
| 227 | const QTreeViewPrivate * const d = d_func(); | - |
| 228 | return d->header->sectionViewportPosition(column); | - |
| 229 | } | - |
| 230 | | - |
| 231 | | - |
| 232 | | - |
| 233 | | - |
| 234 | | - |
| 235 | | - |
| 236 | int QTreeView::columnWidth(int column) const | - |
| 237 | { | - |
| 238 | const QTreeViewPrivate * const d = d_func(); | - |
| 239 | return d->header->sectionSize(column); | - |
| 240 | } | - |
| 241 | void QTreeView::setColumnWidth(int column, int width) | - |
| 242 | { | - |
| 243 | QTreeViewPrivate * const d = d_func(); | - |
| 244 | d->header->resizeSection(column, width); | - |
| 245 | } | - |
| 246 | | - |
| 247 | | - |
| 248 | | - |
| 249 | | - |
| 250 | | - |
| 251 | int QTreeView::columnAt(int x) const | - |
| 252 | { | - |
| 253 | const QTreeViewPrivate * const d = d_func(); | - |
| 254 | return d->header->logicalIndexAt(x); | - |
| 255 | } | - |
| 256 | | - |
| 257 | | - |
| 258 | | - |
| 259 | | - |
| 260 | | - |
| 261 | | - |
| 262 | bool QTreeView::isColumnHidden(int column) const | - |
| 263 | { | - |
| 264 | const QTreeViewPrivate * const d = d_func(); | - |
| 265 | return d->header->isSectionHidden(column); | - |
| 266 | } | - |
| 267 | | - |
| 268 | | - |
| 269 | | - |
| 270 | | - |
| 271 | | - |
| 272 | | - |
| 273 | void QTreeView::setColumnHidden(int column, bool hide) | - |
| 274 | { | - |
| 275 | QTreeViewPrivate * const d = d_func(); | - |
| 276 | if (column < 0 || column >= d->header->count()) | - |
| 277 | return; | - |
| 278 | d->header->setSectionHidden(column, hide); | - |
| 279 | } | - |
| 280 | bool QTreeView::isHeaderHidden() const | - |
| 281 | { | - |
| 282 | const QTreeViewPrivate * const d = d_func(); | - |
| 283 | return d->header->isHidden(); | - |
| 284 | } | - |
| 285 | | - |
| 286 | void QTreeView::setHeaderHidden(bool hide) | - |
| 287 | { | - |
| 288 | QTreeViewPrivate * const d = d_func(); | - |
| 289 | d->header->setHidden(hide); | - |
| 290 | } | - |
| 291 | | - |
| 292 | | - |
| 293 | | - |
| 294 | | - |
| 295 | | - |
| 296 | | - |
| 297 | | - |
| 298 | bool QTreeView::isRowHidden(int row, const QModelIndex &parent) const | - |
| 299 | { | - |
| 300 | const QTreeViewPrivate * const d = d_func(); | - |
| 301 | if (!d->model) | - |
| 302 | return false; | - |
| 303 | return d->isRowHidden(d->model->index(row, 0, parent)); | - |
| 304 | } | - |
| 305 | | - |
| 306 | | - |
| 307 | | - |
| 308 | | - |
| 309 | | - |
| 310 | | - |
| 311 | void QTreeView::setRowHidden(int row, const QModelIndex &parent, bool hide) | - |
| 312 | { | - |
| 313 | QTreeViewPrivate * const d = d_func(); | - |
| 314 | if (!d->model) | - |
| 315 | return; | - |
| 316 | QModelIndex index = d->model->index(row, 0, parent); | - |
| 317 | if (!index.isValid()) | - |
| 318 | return; | - |
| 319 | | - |
| 320 | if (hide) { | - |
| 321 | d->hiddenIndexes.insert(index); | - |
| 322 | } else if(d->isPersistent(index)) { | - |
| 323 | d->hiddenIndexes.remove(index); | - |
| 324 | } | - |
| 325 | | - |
| 326 | d->doDelayedItemsLayout(); | - |
| 327 | } | - |
| 328 | bool QTreeView::isFirstColumnSpanned(int row, const QModelIndex &parent) const | - |
| 329 | { | - |
| 330 | const QTreeViewPrivate * const d = d_func(); | - |
| 331 | if (d->spanningIndexes.isEmpty() || !d->model) | - |
| 332 | return false; | - |
| 333 | QModelIndex index = d->model->index(row, 0, parent); | - |
| 334 | for (int i = 0; i < d->spanningIndexes.count(); ++i) | - |
| 335 | if (d->spanningIndexes.at(i) == index) | - |
| 336 | return true; | - |
| 337 | return false; | - |
| 338 | } | - |
| 339 | void QTreeView::setFirstColumnSpanned(int row, const QModelIndex &parent, bool span) | - |
| 340 | { | - |
| 341 | QTreeViewPrivate * const d = d_func(); | - |
| 342 | if (!d->model) | - |
| 343 | return; | - |
| 344 | QModelIndex index = d->model->index(row, 0, parent); | - |
| 345 | if (!index.isValid()) | - |
| 346 | return; | - |
| 347 | | - |
| 348 | if (span) { | - |
| 349 | QPersistentModelIndex persistent(index); | - |
| 350 | if (!d->spanningIndexes.contains(persistent)) | - |
| 351 | d->spanningIndexes.append(persistent); | - |
| 352 | } else { | - |
| 353 | QPersistentModelIndex persistent(index); | - |
| 354 | int i = d->spanningIndexes.indexOf(persistent); | - |
| 355 | if (i >= 0) | - |
| 356 | d->spanningIndexes.remove(i); | - |
| 357 | } | - |
| 358 | | - |
| 359 | d->executePostedLayout(); | - |
| 360 | int i = d->viewIndex(index); | - |
| 361 | if (i >= 0) | - |
| 362 | d->viewItems[i].spanning = span; | - |
| 363 | | - |
| 364 | d->viewport->update(); | - |
| 365 | } | - |
| 366 | | - |
| 367 | | - |
| 368 | | - |
| 369 | | - |
| 370 | void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) | - |
| 371 | { | - |
| 372 | QTreeViewPrivate * const d = d_func(); | - |
| 373 | | - |
| 374 | | - |
| 375 | if (d->delayedPendingLayout) | - |
| 376 | return; | - |
| 377 | | - |
| 378 | | - |
| 379 | | - |
| 380 | | - |
| 381 | bool sizeChanged = false; | - |
| 382 | int topViewIndex = d->viewIndex(topLeft); | - |
| 383 | if (topViewIndex == 0) { | - |
| 384 | int newDefaultItemHeight = indexRowSizeHint(topLeft); | - |
| 385 | sizeChanged = d->defaultItemHeight != newDefaultItemHeight; | - |
| 386 | d->defaultItemHeight = newDefaultItemHeight; | - |
| 387 | } | - |
| 388 | | - |
| 389 | if (topViewIndex != -1) { | - |
| 390 | if (topLeft.row() == bottomRight.row()) { | - |
| 391 | int oldHeight = d->itemHeight(topViewIndex); | - |
| 392 | d->invalidateHeightCache(topViewIndex); | - |
| 393 | sizeChanged |= (oldHeight != d->itemHeight(topViewIndex)); | - |
| 394 | if (topLeft.column() == 0) | - |
| 395 | d->viewItems[topViewIndex].hasChildren = d->hasVisibleChildren(topLeft); | - |
| 396 | } else { | - |
| 397 | int bottomViewIndex = d->viewIndex(bottomRight); | - |
| 398 | for (int i = topViewIndex; i <= bottomViewIndex; ++i) { | - |
| 399 | int oldHeight = d->itemHeight(i); | - |
| 400 | d->invalidateHeightCache(i); | - |
| 401 | sizeChanged |= (oldHeight != d->itemHeight(i)); | - |
| 402 | if (topLeft.column() == 0) | - |
| 403 | d->viewItems[i].hasChildren = d->hasVisibleChildren(d->viewItems.at(i).index); | - |
| 404 | } | - |
| 405 | } | - |
| 406 | } | - |
| 407 | | - |
| 408 | if (sizeChanged) { | - |
| 409 | d->updateScrollBars(); | - |
| 410 | d->viewport->update(); | - |
| 411 | } | - |
| 412 | QAbstractItemView::dataChanged(topLeft, bottomRight, roles); | - |
| 413 | } | - |
| 414 | void QTreeView::hideColumn(int column) | - |
| 415 | { | - |
| 416 | QTreeViewPrivate * const d = d_func(); | - |
| 417 | d->header->hideSection(column); | - |
| 418 | } | - |
| 419 | | - |
| 420 | | - |
| 421 | | - |
| 422 | | - |
| 423 | | - |
| 424 | | - |
| 425 | void QTreeView::showColumn(int column) | - |
| 426 | { | - |
| 427 | QTreeViewPrivate * const d = d_func(); | - |
| 428 | d->header->showSection(column); | - |
| 429 | } | - |
| 430 | void QTreeView::expand(const QModelIndex &index) | - |
| 431 | { | - |
| 432 | QTreeViewPrivate * const d = d_func(); | - |
| 433 | if (!d->isIndexValid(index)) | - |
| 434 | return; | - |
| 435 | if (d->delayedPendingLayout) { | - |
| 436 | | - |
| 437 | if (d->storeExpanded(index)) | - |
| 438 | expanded(index); | - |
| 439 | return; | - |
| 440 | } | - |
| 441 | | - |
| 442 | int i = d->viewIndex(index); | - |
| 443 | if (i != -1) { | - |
| 444 | d->expand(i, true); | - |
| 445 | if (!d->isAnimating()) { | - |
| 446 | updateGeometries(); | - |
| 447 | d->viewport->update(); | - |
| 448 | } | - |
| 449 | } else if (d->storeExpanded(index)) { | - |
| 450 | expanded(index); | - |
| 451 | } | - |
| 452 | } | - |
| 453 | void QTreeView::collapse(const QModelIndex &index) | - |
| 454 | { | - |
| 455 | QTreeViewPrivate * const d = d_func(); | - |
| 456 | if (!d->isIndexValid(index)) | - |
| 457 | return; | - |
| 458 | | - |
| 459 | d->delayedAutoScroll.stop(); | - |
| 460 | | - |
| 461 | if (d->delayedPendingLayout) { | - |
| 462 | | - |
| 463 | if (d->isPersistent(index) && d->expandedIndexes.remove(index)) | - |
| 464 | collapsed(index); | - |
| 465 | return; | - |
| 466 | } | - |
| 467 | int i = d->viewIndex(index); | - |
| 468 | if (i != -1) { | - |
| 469 | d->collapse(i, true); | - |
| 470 | if (!d->isAnimating()) { | - |
| 471 | updateGeometries(); | - |
| 472 | viewport()->update(); | - |
| 473 | } | - |
| 474 | } else { | - |
| 475 | if (d->isPersistent(index) && d->expandedIndexes.remove(index)) | - |
| 476 | collapsed(index); | - |
| 477 | } | - |
| 478 | } | - |
| 479 | bool QTreeView::isExpanded(const QModelIndex &index) const | - |
| 480 | { | - |
| 481 | const QTreeViewPrivate * const d = d_func(); | - |
| 482 | return d->isIndexExpanded(index); | - |
| 483 | } | - |
| 484 | | - |
| 485 | | - |
| 486 | | - |
| 487 | | - |
| 488 | | - |
| 489 | | - |
| 490 | | - |
| 491 | void QTreeView::setExpanded(const QModelIndex &index, bool expanded) | - |
| 492 | { | - |
| 493 | if (expanded) | - |
| 494 | this->expand(index); | - |
| 495 | else | - |
| 496 | this->collapse(index); | - |
| 497 | } | - |
| 498 | void QTreeView::setSortingEnabled(bool enable) | - |
| 499 | { | - |
| 500 | QTreeViewPrivate * const d = d_func(); | - |
| 501 | header()->setSortIndicatorShown(enable); | - |
| 502 | header()->setSectionsClickable(enable); | - |
| 503 | if (enable) { | - |
| 504 | | - |
| 505 | | - |
| 506 | sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder()); | - |
| 507 | connect(header(), "2""sortIndicatorChanged(int,Qt::SortOrder)", | - |
| 508 | this, "1""_q_sortIndicatorChanged(int,Qt::SortOrder)", Qt::UniqueConnection); | - |
| 509 | } else { | - |
| 510 | disconnect(header(), "2""sortIndicatorChanged(int,Qt::SortOrder)", | - |
| 511 | this, "1""_q_sortIndicatorChanged(int,Qt::SortOrder)"); | - |
| 512 | } | - |
| 513 | d->sortingEnabled = enable; | - |
| 514 | } | - |
| 515 | | - |
| 516 | bool QTreeView::isSortingEnabled() const | - |
| 517 | { | - |
| 518 | const QTreeViewPrivate * const d = d_func(); | - |
| 519 | return d->sortingEnabled; | - |
| 520 | } | - |
| 521 | void QTreeView::setAnimated(bool animate) | - |
| 522 | { | - |
| 523 | QTreeViewPrivate * const d = d_func(); | - |
| 524 | d->animationsEnabled = animate; | - |
| 525 | } | - |
| 526 | | - |
| 527 | bool QTreeView::isAnimated() const | - |
| 528 | { | - |
| 529 | const QTreeViewPrivate * const d = d_func(); | - |
| 530 | return d->animationsEnabled; | - |
| 531 | } | - |
| 532 | void QTreeView::setAllColumnsShowFocus(bool enable) | - |
| 533 | { | - |
| 534 | QTreeViewPrivate * const d = d_func(); | - |
| 535 | if (d->allColumnsShowFocus == enable) | - |
| 536 | return; | - |
| 537 | d->allColumnsShowFocus = enable; | - |
| 538 | d->viewport->update(); | - |
| 539 | } | - |
| 540 | | - |
| 541 | bool QTreeView::allColumnsShowFocus() const | - |
| 542 | { | - |
| 543 | const QTreeViewPrivate * const d = d_func(); | - |
| 544 | return d->allColumnsShowFocus; | - |
| 545 | } | - |
| 546 | void QTreeView::setWordWrap(bool on) | - |
| 547 | { | - |
| 548 | QTreeViewPrivate * const d = d_func(); | - |
| 549 | if (d->wrapItemText == on) | - |
| 550 | return; | - |
| 551 | d->wrapItemText = on; | - |
| 552 | d->doDelayedItemsLayout(); | - |
| 553 | } | - |
| 554 | | - |
| 555 | bool QTreeView::wordWrap() const | - |
| 556 | { | - |
| 557 | const QTreeViewPrivate * const d = d_func(); | - |
| 558 | return d->wrapItemText; | - |
| 559 | } | - |
| 560 | | - |
| 561 | | - |
| 562 | | - |
| 563 | | - |
| 564 | | - |
| 565 | void QTreeView::keyboardSearch(const QString &search) | - |
| 566 | { | - |
| 567 | QTreeViewPrivate * const d = d_func(); | - |
| 568 | if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root)) | - |
| 569 | return; | - |
| 570 | | - |
| 571 | QModelIndex start; | - |
| 572 | if (currentIndex().isValid()) | - |
| 573 | start = currentIndex(); | - |
| 574 | else | - |
| 575 | start = d->model->index(0, 0, d->root); | - |
| 576 | | - |
| 577 | bool skipRow = false; | - |
| 578 | bool keyboardTimeWasValid = d->keyboardInputTime.isValid(); | - |
| 579 | qint64 keyboardInputTimeElapsed = d->keyboardInputTime.restart(); | - |
| 580 | if (search.isEmpty() || !keyboardTimeWasValid | - |
| 581 | || keyboardInputTimeElapsed > QApplication::keyboardInputInterval()) { | - |
| 582 | d->keyboardInput = search; | - |
| 583 | skipRow = currentIndex().isValid(); | - |
| 584 | } else { | - |
| 585 | d->keyboardInput += search; | - |
| 586 | } | - |
| 587 | | - |
| 588 | | - |
| 589 | bool sameKey = false; | - |
| 590 | if (d->keyboardInput.length() > 1) { | - |
| 591 | int c = d->keyboardInput.count(d->keyboardInput.at(d->keyboardInput.length() - 1)); | - |
| 592 | sameKey = (c == d->keyboardInput.length()); | - |
| 593 | if (sameKey) | - |
| 594 | skipRow = true; | - |
| 595 | } | - |
| 596 | | - |
| 597 | | - |
| 598 | if (skipRow) { | - |
| 599 | if (indexBelow(start).isValid()) | - |
| 600 | start = indexBelow(start); | - |
| 601 | else | - |
| 602 | start = d->model->index(0, start.column(), d->root); | - |
| 603 | } | - |
| 604 | | - |
| 605 | d->executePostedLayout(); | - |
| 606 | int startIndex = d->viewIndex(start); | - |
| 607 | if (startIndex <= -1) | - |
| 608 | return; | - |
| 609 | | - |
| 610 | int previousLevel = -1; | - |
| 611 | int bestAbove = -1; | - |
| 612 | int bestBelow = -1; | - |
| 613 | QString searchString = sameKey ? QString(d->keyboardInput.at(0)) : d->keyboardInput; | - |
| 614 | for (int i = 0; i < d->viewItems.count(); ++i) { | - |
| 615 | if ((int)d->viewItems.at(i).level > previousLevel) { | - |
| 616 | QModelIndex searchFrom = d->viewItems.at(i).index; | - |
| 617 | if (start.column() > 0) | - |
| 618 | searchFrom = searchFrom.sibling(searchFrom.row(), start.column()); | - |
| 619 | if (searchFrom.parent() == start.parent()) | - |
| 620 | searchFrom = start; | - |
| 621 | QModelIndexList match = d->model->match(searchFrom, Qt::DisplayRole, searchString); | - |
| 622 | if (match.count()) { | - |
| 623 | int hitIndex = d->viewIndex(match.at(0)); | - |
| 624 | if (hitIndex >= 0 && hitIndex < startIndex) | - |
| 625 | bestAbove = bestAbove == -1 ? hitIndex : qMin(hitIndex, bestAbove); | - |
| 626 | else if (hitIndex >= startIndex) | - |
| 627 | bestBelow = bestBelow == -1 ? hitIndex : qMin(hitIndex, bestBelow); | - |
| 628 | } | - |
| 629 | } | - |
| 630 | previousLevel = d->viewItems.at(i).level; | - |
| 631 | } | - |
| 632 | | - |
| 633 | QModelIndex index; | - |
| 634 | if (bestBelow > -1) | - |
| 635 | index = d->viewItems.at(bestBelow).index; | - |
| 636 | else if (bestAbove > -1) | - |
| 637 | index = d->viewItems.at(bestAbove).index; | - |
| 638 | | - |
| 639 | if (start.column() > 0) | - |
| 640 | index = index.sibling(index.row(), start.column()); | - |
| 641 | | - |
| 642 | if (index.isValid()) { | - |
| 643 | QItemSelectionModel::SelectionFlags flags = (d->selectionMode == SingleSelection | - |
| 644 | ? QItemSelectionModel::SelectionFlags( | - |
| 645 | QItemSelectionModel::ClearAndSelect | - |
| 646 | |d->selectionBehaviorFlags()) | - |
| 647 | : QItemSelectionModel::SelectionFlags( | - |
| 648 | QItemSelectionModel::NoUpdate)); | - |
| 649 | selectionModel()->setCurrentIndex(index, flags); | - |
| 650 | } | - |
| 651 | } | - |
| 652 | | - |
| 653 | | - |
| 654 | | - |
| 655 | | - |
| 656 | | - |
| 657 | QRect QTreeView::visualRect(const QModelIndex &index) const | - |
| 658 | { | - |
| 659 | const QTreeViewPrivate * const d = d_func(); | - |
| 660 | | - |
| 661 | if (!d->isIndexValid(index) || isIndexHidden(index)) | - |
| 662 | return QRect(); | - |
| 663 | | - |
| 664 | d->executePostedLayout(); | - |
| 665 | | - |
| 666 | int vi = d->viewIndex(index); | - |
| 667 | if (vi < 0) | - |
| 668 | return QRect(); | - |
| 669 | | - |
| 670 | bool spanning = d->viewItems.at(vi).spanning; | - |
| 671 | | - |
| 672 | | - |
| 673 | int x = (spanning ? 0 : columnViewportPosition(index.column())); | - |
| 674 | int w = (spanning ? d->header->length() : columnWidth(index.column())); | - |
| 675 | | - |
| 676 | if (index.column() == 0) { | - |
| 677 | int i = d->indentationForItem(vi); | - |
| 678 | w -= i; | - |
| 679 | if (!isRightToLeft()) | - |
| 680 | x += i; | - |
| 681 | } | - |
| 682 | | - |
| 683 | int y = d->coordinateForItem(vi); | - |
| 684 | int h = d->itemHeight(vi); | - |
| 685 | | - |
| 686 | return QRect(x, y, w, h); | - |
| 687 | } | - |
| 688 | void QTreeView::scrollTo(const QModelIndex &index, ScrollHint hint) | - |
| 689 | { | - |
| 690 | QTreeViewPrivate * const d = d_func(); | - |
| 691 | | - |
| 692 | if (!d->isIndexValid(index)) evaluated: !d->isIndexValid(index)| yes Evaluation Count:30 | yes Evaluation Count:5635 |
| 30-5635 |
| 693 | return; executed: return;Execution Count:30 | 30 |
| 694 | | - |
| 695 | d->executePostedLayout(); | - |
| 696 | d->updateScrollBars(); | - |
| 697 | | - |
| 698 | | - |
| 699 | QModelIndex parent = index.parent(); | - |
| 700 | while (parent != d->root && parent.isValid() && state() == NoState && d->itemsExpandable) { evaluated: parent != d->root| yes Evaluation Count:56 | yes Evaluation Count:5635 |
partially evaluated: parent.isValid()| yes Evaluation Count:56 | no Evaluation Count:0 |
partially evaluated: state() == NoState| yes Evaluation Count:56 | no Evaluation Count:0 |
partially evaluated: d->itemsExpandable| yes Evaluation Count:56 | no Evaluation Count:0 |
| 0-5635 |
| 701 | if (!isExpanded(parent)) evaluated: !isExpanded(parent)| yes Evaluation Count:7 | yes Evaluation Count:49 |
| 7-49 |
| 702 | expand(parent); executed: expand(parent);Execution Count:7 | 7 |
| 703 | parent = d->model->parent(parent); | - |
| 704 | } executed: }Execution Count:56 | 56 |
| 705 | | - |
| 706 | int item = d->viewIndex(index); | - |
| 707 | if (item < 0) partially evaluated: item < 0| no Evaluation Count:0 | yes Evaluation Count:5635 |
| 0-5635 |
| 708 | return; | 0 |
| 709 | | - |
| 710 | QRect area = d->viewport->rect(); | - |
| 711 | | - |
| 712 | | - |
| 713 | if (verticalScrollMode() == QAbstractItemView::ScrollPerItem) { evaluated: verticalScrollMode() == QAbstractItemView::ScrollPerItem| yes Evaluation Count:2897 | yes Evaluation Count:2738 |
| 2738-2897 |
| 714 | int top = verticalScrollBar()->value(); | - |
| 715 | int bottom = top + verticalScrollBar()->pageStep(); | - |
| 716 | if (hint == EnsureVisible && item >= top && item < bottom) { evaluated: hint == EnsureVisible| yes Evaluation Count:2889 | yes Evaluation Count:8 |
evaluated: item >= top| yes Evaluation Count:2882 | yes Evaluation Count:7 |
evaluated: item < bottom| yes Evaluation Count:2842 | yes Evaluation Count:40 |
| 7-2889 |
| 717 | | - |
| 718 | } else if (hint == PositionAtTop || (hint == EnsureVisible && item < top)) { evaluated: hint == PositionAtTop| yes Evaluation Count:7 | yes Evaluation Count:48 |
evaluated: hint == EnsureVisible| yes Evaluation Count:47 | yes Evaluation Count:1 |
evaluated: item < top| yes Evaluation Count:7 | yes Evaluation Count:40 |
executed: }Execution Count:2842 | 1-2842 |
| 719 | verticalScrollBar()->setValue(item); | - |
| 720 | } else { executed: }Execution Count:14 | 14 |
| 721 | const int currentItemHeight = d->itemHeight(item); | - |
| 722 | int y = (hint == PositionAtCenter partially evaluated: hint == PositionAtCenter| no Evaluation Count:0 | yes Evaluation Count:41 |
| 0-41 |
| 723 | | - |
| 724 | ? area.height() / 2 + currentItemHeight - 1 | - |
| 725 | | - |
| 726 | : area.height()); | - |
| 727 | if (y > currentItemHeight) { partially evaluated: y > currentItemHeight| yes Evaluation Count:41 | no Evaluation Count:0 |
| 0-41 |
| 728 | while (item >= 0) { evaluated: item >= 0| yes Evaluation Count:357 | yes Evaluation Count:1 |
| 1-357 |
| 729 | y -= d->itemHeight(item); | - |
| 730 | if (y < 0) { evaluated: y < 0| yes Evaluation Count:40 | yes Evaluation Count:317 |
| 40-317 |
| 731 | item++; | - |
| 732 | break; executed: break;Execution Count:40 | 40 |
| 733 | } | - |
| 734 | item--; | - |
| 735 | } executed: }Execution Count:317 | 317 |
| 736 | } executed: }Execution Count:41 | 41 |
| 737 | verticalScrollBar()->setValue(item); | - |
| 738 | } executed: }Execution Count:41 | 41 |
| 739 | } else { | - |
| 740 | QRect rect(columnViewportPosition(index.column()), | - |
| 741 | d->coordinateForItem(item), | - |
| 742 | columnWidth(index.column()), | - |
| 743 | d->itemHeight(item)); | - |
| 744 | | - |
| 745 | if (rect.isEmpty()) { partially evaluated: rect.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:2738 |
| 0-2738 |
| 746 | | - |
| 747 | } else if (hint == EnsureVisible && area.contains(rect)) { evaluated: hint == EnsureVisible| yes Evaluation Count:2736 | yes Evaluation Count:2 |
evaluated: area.contains(rect)| yes Evaluation Count:461 | yes Evaluation Count:2275 |
| 0-2736 |
| 748 | d->viewport->update(rect); | - |
| 749 | | - |
| 750 | } else { executed: }Execution Count:461 | 461 |
| 751 | bool above = (hint == EnsureVisible evaluated: hint == EnsureVisible| yes Evaluation Count:2275 | yes Evaluation Count:2 |
| 2-2275 |
| 752 | && (rect.top() < area.top() evaluated: rect.top() < area.top()| yes Evaluation Count:4 | yes Evaluation Count:2271 |
| 4-2271 |
| 753 | || area.height() < rect.height())); partially evaluated: area.height() < rect.height()| no Evaluation Count:0 | yes Evaluation Count:2271 |
| 0-2271 |
| 754 | bool below = (hint == EnsureVisible evaluated: hint == EnsureVisible| yes Evaluation Count:2275 | yes Evaluation Count:2 |
| 2-2275 |
| 755 | && rect.bottom() > area.bottom() evaluated: rect.bottom() > area.bottom()| yes Evaluation Count:1873 | yes Evaluation Count:402 |
| 402-1873 |
| 756 | && rect.height() < area.height()); partially evaluated: rect.height() < area.height()| yes Evaluation Count:1873 | no Evaluation Count:0 |
| 0-1873 |
| 757 | | - |
| 758 | int verticalValue = verticalScrollBar()->value(); | - |
| 759 | if (hint == PositionAtTop || above) evaluated: hint == PositionAtTop| yes Evaluation Count:2 | yes Evaluation Count:2275 |
evaluated: above| yes Evaluation Count:4 | yes Evaluation Count:2271 |
| 2-2275 |
| 760 | verticalValue += rect.top(); executed: verticalValue += rect.top();Execution Count:6 | 6 |
| 761 | else if (hint == PositionAtBottom || below) partially evaluated: hint == PositionAtBottom| no Evaluation Count:0 | yes Evaluation Count:2271 |
evaluated: below| yes Evaluation Count:1873 | yes Evaluation Count:398 |
| 0-2271 |
| 762 | verticalValue += rect.bottom() - area.height(); executed: verticalValue += rect.bottom() - area.height();Execution Count:1873 | 1873 |
| 763 | else if (hint == PositionAtCenter) partially evaluated: hint == PositionAtCenter| no Evaluation Count:0 | yes Evaluation Count:398 |
| 0-398 |
| 764 | verticalValue += rect.top() - ((area.height() - rect.height()) / 2); never executed: verticalValue += rect.top() - ((area.height() - rect.height()) / 2); | 0 |
| 765 | verticalScrollBar()->setValue(verticalValue); | - |
| 766 | } executed: }Execution Count:2277 | 2277 |
| 767 | } | - |
| 768 | | - |
| 769 | int viewportWidth = d->viewport->width(); | - |
| 770 | int horizontalOffset = d->header->offset(); | - |
| 771 | int horizontalPosition = d->header->sectionPosition(index.column()); | - |
| 772 | int cellWidth = d->header->sectionSize(index.column()); | - |
| 773 | | - |
| 774 | if (hint == PositionAtCenter) { partially evaluated: hint == PositionAtCenter| no Evaluation Count:0 | yes Evaluation Count:5635 |
| 0-5635 |
| 775 | horizontalScrollBar()->setValue(horizontalPosition - ((viewportWidth - cellWidth) / 2)); | - |
| 776 | } else { | 0 |
| 777 | if (horizontalPosition - horizontalOffset < 0 || cellWidth > viewportWidth) evaluated: horizontalPosition - horizontalOffset < 0| yes Evaluation Count:2355 | yes Evaluation Count:3280 |
evaluated: cellWidth > viewportWidth| yes Evaluation Count:25 | yes Evaluation Count:3255 |
| 25-3280 |
| 778 | horizontalScrollBar()->setValue(horizontalPosition); executed: horizontalScrollBar()->setValue(horizontalPosition);Execution Count:2380 | 2380 |
| 779 | else if (horizontalPosition - horizontalOffset + cellWidth > viewportWidth) evaluated: horizontalPosition - horizontalOffset + cellWidth > viewportWidth| yes Evaluation Count:1317 | yes Evaluation Count:1938 |
| 1317-1938 |
| 780 | horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth); executed: horizontalScrollBar()->setValue(horizontalPosition - viewportWidth + cellWidth);Execution Count:1317 | 1317 |
| 781 | } | - |
| 782 | } | - |
| 783 | | - |
| 784 | | - |
| 785 | | - |
| 786 | | - |
| 787 | void QTreeView::timerEvent(QTimerEvent *event) | - |
| 788 | { | - |
| 789 | QTreeViewPrivate * const d = d_func(); | - |
| 790 | if (event->timerId() == d->columnResizeTimerID) { | - |
| 791 | updateGeometries(); | - |
| 792 | killTimer(d->columnResizeTimerID); | - |
| 793 | d->columnResizeTimerID = 0; | - |
| 794 | QRect rect; | - |
| 795 | int viewportHeight = d->viewport->height(); | - |
| 796 | int viewportWidth = d->viewport->width(); | - |
| 797 | for (int i = d->columnsToUpdate.size() - 1; i >= 0; --i) { | - |
| 798 | int column = d->columnsToUpdate.at(i); | - |
| 799 | int x = columnViewportPosition(column); | - |
| 800 | if (isRightToLeft()) | - |
| 801 | rect |= QRect(0, 0, x + columnWidth(column), viewportHeight); | - |
| 802 | else | - |
| 803 | rect |= QRect(x, 0, viewportWidth - x, viewportHeight); | - |
| 804 | } | - |
| 805 | d->viewport->update(rect.normalized()); | - |
| 806 | d->columnsToUpdate.clear(); | - |
| 807 | } else if (event->timerId() == d->openTimer.timerId()) { | - |
| 808 | QPoint pos = d->viewport->mapFromGlobal(QCursor::pos()); | - |
| 809 | if (state() == QAbstractItemView::DraggingState | - |
| 810 | && d->viewport->rect().contains(pos)) { | - |
| 811 | QModelIndex index = indexAt(pos); | - |
| 812 | setExpanded(index, !isExpanded(index)); | - |
| 813 | } | - |
| 814 | d->openTimer.stop(); | - |
| 815 | } | - |
| 816 | | - |
| 817 | QAbstractItemView::timerEvent(event); | - |
| 818 | } | - |
| 819 | | - |
| 820 | | - |
| 821 | | - |
| 822 | | - |
| 823 | | - |
| 824 | void QTreeView::dragMoveEvent(QDragMoveEvent *event) | - |
| 825 | { | - |
| 826 | QTreeViewPrivate * const d = d_func(); | - |
| 827 | if (d->autoExpandDelay >= 0) | - |
| 828 | d->openTimer.start(d->autoExpandDelay, this); | - |
| 829 | QAbstractItemView::dragMoveEvent(event); | - |
| 830 | } | - |
| 831 | | - |
| 832 | | - |
| 833 | | - |
| 834 | | - |
| 835 | | - |
| 836 | bool QTreeView::viewportEvent(QEvent *event) | - |
| 837 | { | - |
| 838 | QTreeViewPrivate * const d = d_func(); | - |
| 839 | switch (event->type()) { | - |
| 840 | case QEvent::HoverEnter: | - |
| 841 | case QEvent::HoverLeave: | - |
| 842 | case QEvent::HoverMove: { | - |
| 843 | QHoverEvent *he = static_cast<QHoverEvent*>(event); | - |
| 844 | int oldBranch = d->hoverBranch; | - |
| 845 | d->hoverBranch = d->itemDecorationAt(he->pos()); | - |
| 846 | QModelIndex newIndex = indexAt(he->pos()); | - |
| 847 | if (d->hover != newIndex || d->hoverBranch != oldBranch) { | - |
| 848 | | - |
| 849 | | - |
| 850 | QRect rect = visualRect(newIndex); | - |
| 851 | rect.setX(0); | - |
| 852 | rect.setWidth(viewport()->width()); | - |
| 853 | viewport()->update(rect); | - |
| 854 | } | - |
| 855 | break; } | - |
| 856 | default: | - |
| 857 | break; | - |
| 858 | } | - |
| 859 | return QAbstractItemView::viewportEvent(event); | - |
| 860 | } | - |
| 861 | | - |
| 862 | | - |
| 863 | | - |
| 864 | | - |
| 865 | void QTreeView::paintEvent(QPaintEvent *event) | - |
| 866 | { | - |
| 867 | QTreeViewPrivate * const d = d_func(); | - |
| 868 | d->executePostedLayout(); | - |
| 869 | QPainter painter(viewport()); | - |
| 870 | | - |
| 871 | if (d->isAnimating()) { | - |
| 872 | drawTree(&painter, event->region() - d->animatedOperation.rect()); | - |
| 873 | d->drawAnimatedOperation(&painter); | - |
| 874 | } else | - |
| 875 | | - |
| 876 | { | - |
| 877 | drawTree(&painter, event->region()); | - |
| 878 | | - |
| 879 | d->paintDropIndicator(&painter); | - |
| 880 | | - |
| 881 | } | - |
| 882 | } | - |
| 883 | | - |
| 884 | void QTreeViewPrivate::paintAlternatingRowColors(QPainter *painter, QStyleOptionViewItem *option, int y, int bottom) const | - |
| 885 | { | - |
| 886 | const QTreeView * const q = q_func(); | - |
| 887 | if (!alternatingColors || !q->style()->styleHint(QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea, option, q)) | - |
| 888 | return; | - |
| 889 | int rowHeight = defaultItemHeight; | - |
| 890 | if (rowHeight <= 0) { | - |
| 891 | rowHeight = itemDelegate->sizeHint(*option, QModelIndex()).height(); | - |
| 892 | if (rowHeight <= 0) | - |
| 893 | return; | - |
| 894 | } | - |
| 895 | while (y <= bottom) { | - |
| 896 | option->rect.setRect(0, y, viewport->width(), rowHeight); | - |
| 897 | if (current & 1) { | - |
| 898 | option->features |= QStyleOptionViewItem::Alternate; | - |
| 899 | } else { | - |
| 900 | option->features &= ~QStyleOptionViewItem::Alternate; | - |
| 901 | } | - |
| 902 | ++current; | - |
| 903 | q->style()->drawPrimitive(QStyle::PE_PanelItemViewRow, option, painter, q); | - |
| 904 | y += rowHeight; | - |
| 905 | } | - |
| 906 | } | - |
| 907 | | - |
| 908 | bool QTreeViewPrivate::expandOrCollapseItemAtPos(const QPoint &pos) | - |
| 909 | { | - |
| 910 | QTreeView * const q = q_func(); | - |
| 911 | | - |
| 912 | if ((state != QAbstractItemView::NoState | - |
| 913 | && state != QAbstractItemView::EditingState) | - |
| 914 | || !viewport->rect().contains(pos)) | - |
| 915 | return true; | - |
| 916 | | - |
| 917 | int i = itemDecorationAt(pos); | - |
| 918 | if ((i != -1) && itemsExpandable && hasVisibleChildren(viewItems.at(i).index)) { | - |
| 919 | if (viewItems.at(i).expanded) | - |
| 920 | collapse(i, true); | - |
| 921 | else | - |
| 922 | expand(i, true); | - |
| 923 | if (!isAnimating()) { | - |
| 924 | q->updateGeometries(); | - |
| 925 | viewport->update(); | - |
| 926 | } | - |
| 927 | return true; | - |
| 928 | } | - |
| 929 | return false; | - |
| 930 | } | - |
| 931 | | - |
| 932 | void QTreeViewPrivate::_q_modelDestroyed() | - |
| 933 | { | - |
| 934 | | - |
| 935 | | - |
| 936 | viewItems.clear(); | - |
| 937 | QAbstractItemViewPrivate::_q_modelDestroyed(); | - |
| 938 | } | - |
| 939 | | - |
| 940 | | - |
| 941 | | - |
| 942 | | - |
| 943 | | - |
| 944 | | - |
| 945 | QItemViewPaintPairs QTreeViewPrivate::draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const | - |
| 946 | { | - |
| 947 | qt_noop(); | - |
| 948 | const QTreeView * const q = q_func(); | - |
| 949 | if (spanningIndexes.isEmpty()) | - |
| 950 | return QAbstractItemViewPrivate::draggablePaintPairs(indexes, r); | - |
| 951 | QModelIndexList list; | - |
| 952 | for (QForeachContainer<__typeof__(indexes)> _container_(indexes); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QModelIndex &idx = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
| 953 | if (idx.column() > 0 && q->isFirstColumnSpanned(idx.row(), idx.parent())) | - |
| 954 | continue; | - |
| 955 | list << idx; | - |
| 956 | } | - |
| 957 | return QAbstractItemViewPrivate::draggablePaintPairs(list, r); | - |
| 958 | } | - |
| 959 | | - |
| 960 | void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItem *option, const QModelIndex ¤t) const | - |
| 961 | { | - |
| 962 | const int row = viewIndex(current); | - |
| 963 | option->state = option->state | (viewItems.at(row).expanded ? QStyle::State_Open : QStyle::State_None) | - |
| 964 | | (viewItems.at(row).hasChildren ? QStyle::State_Children : QStyle::State_None) | - |
| 965 | | (viewItems.at(row).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None); | - |
| 966 | | - |
| 967 | option->showDecorationSelected = (selectionBehavior & QTreeView::SelectRows) | - |
| 968 | || option->showDecorationSelected; | - |
| 969 | | - |
| 970 | QVector<int> logicalIndices; | - |
| 971 | QVector<QStyleOptionViewItem::ViewItemPosition> viewItemPosList; | - |
| 972 | const bool spanning = viewItems.at(row).spanning; | - |
| 973 | const int left = (spanning ? header->visualIndex(0) : 0); | - |
| 974 | const int right = (spanning ? header->visualIndex(0) : header->count() - 1 ); | - |
| 975 | calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right); | - |
| 976 | | - |
| 977 | int columnIndex = 0; | - |
| 978 | for (int visualIndex = 0; visualIndex < current.column(); ++visualIndex) { | - |
| 979 | int logicalIndex = header->logicalIndex(visualIndex); | - |
| 980 | if (!header->isSectionHidden(logicalIndex)) { | - |
| 981 | ++columnIndex; | - |
| 982 | } | - |
| 983 | } | - |
| 984 | | - |
| 985 | option->viewItemPosition = viewItemPosList.at(columnIndex); | - |
| 986 | } | - |
| 987 | void QTreeView::drawTree(QPainter *painter, const QRegion ®ion) const | - |
| 988 | { | - |
| 989 | const QTreeViewPrivate * const d = d_func(); | - |
| 990 | const QVector<QTreeViewItem> viewItems = d->viewItems; | - |
| 991 | | - |
| 992 | QStyleOptionViewItem option = d->viewOptions(); | - |
| 993 | const QStyle::State state = option.state; | - |
| 994 | d->current = 0; | - |
| 995 | | - |
| 996 | if (viewItems.count() == 0 || d->header->count() == 0 || !d->itemDelegate) { | - |
| 997 | d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1); | - |
| 998 | return; | - |
| 999 | } | - |
| 1000 | | - |
| 1001 | int firstVisibleItemOffset = 0; | - |
| 1002 | const int firstVisibleItem = d->firstVisibleItem(&firstVisibleItemOffset); | - |
| 1003 | if (firstVisibleItem < 0) { | - |
| 1004 | d->paintAlternatingRowColors(painter, &option, 0, region.boundingRect().bottom()+1); | - |
| 1005 | return; | - |
| 1006 | } | - |
| 1007 | | - |
| 1008 | const int viewportWidth = d->viewport->width(); | - |
| 1009 | | - |
| 1010 | QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos()); | - |
| 1011 | d->hoverBranch = d->itemDecorationAt(hoverPos); | - |
| 1012 | | - |
| 1013 | QVector<QRect> rects = region.rects(); | - |
| 1014 | QVector<int> drawn; | - |
| 1015 | bool multipleRects = (rects.size() > 1); | - |
| 1016 | for (int a = 0; a < rects.size(); ++a) { | - |
| 1017 | const QRect area = (multipleRects | - |
| 1018 | ? QRect(0, rects.at(a).y(), viewportWidth, rects.at(a).height()) | - |
| 1019 | : rects.at(a)); | - |
| 1020 | d->leftAndRight = d->startAndEndColumns(area); | - |
| 1021 | | - |
| 1022 | int i = firstVisibleItem; | - |
| 1023 | int y = firstVisibleItemOffset; | - |
| 1024 | | - |
| 1025 | | - |
| 1026 | for (; i < viewItems.count(); ++i) { | - |
| 1027 | const int itemHeight = d->itemHeight(i); | - |
| 1028 | if (y + itemHeight > area.top()) | - |
| 1029 | break; | - |
| 1030 | y += itemHeight; | - |
| 1031 | } | - |
| 1032 | | - |
| 1033 | | - |
| 1034 | for (; i < viewItems.count() && y <= area.bottom(); ++i) { | - |
| 1035 | const int itemHeight = d->itemHeight(i); | - |
| 1036 | option.rect.setRect(0, y, viewportWidth, itemHeight); | - |
| 1037 | option.state = state | (viewItems.at(i).expanded ? QStyle::State_Open : QStyle::State_None) | - |
| 1038 | | (viewItems.at(i).hasChildren ? QStyle::State_Children : QStyle::State_None) | - |
| 1039 | | (viewItems.at(i).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None); | - |
| 1040 | d->current = i; | - |
| 1041 | d->spanning = viewItems.at(i).spanning; | - |
| 1042 | if (!multipleRects || !drawn.contains(i)) { | - |
| 1043 | drawRow(painter, option, viewItems.at(i).index); | - |
| 1044 | if (multipleRects) | - |
| 1045 | drawn.append(i); | - |
| 1046 | } | - |
| 1047 | y += itemHeight; | - |
| 1048 | } | - |
| 1049 | | - |
| 1050 | if (y <= area.bottom()) { | - |
| 1051 | d->current = i; | - |
| 1052 | d->paintAlternatingRowColors(painter, &option, y, area.bottom()); | - |
| 1053 | } | - |
| 1054 | } | - |
| 1055 | } | - |
| 1056 | | - |
| 1057 | | - |
| 1058 | static inline bool ancestorOf(QObject *widget, QObject *other) | - |
| 1059 | { | - |
| 1060 | for (QObject *parent = other; parent != 0; parent = parent->parent()) { | - |
| 1061 | if (parent == widget) | - |
| 1062 | return true; | - |
| 1063 | } | - |
| 1064 | return false; | - |
| 1065 | } | - |
| 1066 | | - |
| 1067 | void QTreeViewPrivate::calcLogicalIndices(QVector<int> *logicalIndices, QVector<QStyleOptionViewItem::ViewItemPosition> *itemPositions, int left, int right) const | - |
| 1068 | { | - |
| 1069 | const int columnCount = header->count(); | - |
| 1070 | | - |
| 1071 | | - |
| 1072 | | - |
| 1073 | int logicalIndexBeforeLeft = -1, logicalIndexAfterRight = -1; | - |
| 1074 | for (int visualIndex = left - 1; visualIndex >= 0; --visualIndex) { | - |
| 1075 | int logicalIndex = header->logicalIndex(visualIndex); | - |
| 1076 | if (!header->isSectionHidden(logicalIndex)) { | - |
| 1077 | logicalIndexBeforeLeft = logicalIndex; | - |
| 1078 | break; | - |
| 1079 | } | - |
| 1080 | } | - |
| 1081 | | - |
| 1082 | for (int visualIndex = left; visualIndex < columnCount; ++visualIndex) { | - |
| 1083 | int logicalIndex = header->logicalIndex(visualIndex); | - |
| 1084 | if (!header->isSectionHidden(logicalIndex)) { | - |
| 1085 | if (visualIndex > right) { | - |
| 1086 | logicalIndexAfterRight = logicalIndex; | - |
| 1087 | break; | - |
| 1088 | } | - |
| 1089 | logicalIndices->append(logicalIndex); | - |
| 1090 | } | - |
| 1091 | } | - |
| 1092 | | - |
| 1093 | itemPositions->resize(logicalIndices->count()); | - |
| 1094 | for (int currentLogicalSection = 0; currentLogicalSection < logicalIndices->count(); ++currentLogicalSection) { | - |
| 1095 | const int headerSection = logicalIndices->at(currentLogicalSection); | - |
| 1096 | | - |
| 1097 | int nextLogicalSection = currentLogicalSection + 1 >= logicalIndices->count() | - |
| 1098 | ? logicalIndexAfterRight | - |
| 1099 | : logicalIndices->at(currentLogicalSection + 1); | - |
| 1100 | int prevLogicalSection = currentLogicalSection - 1 < 0 | - |
| 1101 | ? logicalIndexBeforeLeft | - |
| 1102 | : logicalIndices->at(currentLogicalSection - 1); | - |
| 1103 | QStyleOptionViewItem::ViewItemPosition pos; | - |
| 1104 | if (columnCount == 1 || (nextLogicalSection == 0 && prevLogicalSection == -1) | - |
| 1105 | || (headerSection == 0 && nextLogicalSection == -1) || spanning) | - |
| 1106 | pos = QStyleOptionViewItem::OnlyOne; | - |
| 1107 | else if (headerSection == 0 || (nextLogicalSection != 0 && prevLogicalSection == -1)) | - |
| 1108 | pos = QStyleOptionViewItem::Beginning; | - |
| 1109 | else if (nextLogicalSection == 0 || nextLogicalSection == -1) | - |
| 1110 | pos = QStyleOptionViewItem::End; | - |
| 1111 | else | - |
| 1112 | pos = QStyleOptionViewItem::Middle; | - |
| 1113 | (*itemPositions)[currentLogicalSection] = pos; | - |
| 1114 | } | - |
| 1115 | } | - |
| 1116 | void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, | - |
| 1117 | const QModelIndex &index) const | - |
| 1118 | { | - |
| 1119 | const QTreeViewPrivate * const d = d_func(); | - |
| 1120 | QStyleOptionViewItem opt = option; | - |
| 1121 | const QPoint offset = d->scrollDelayOffset; | - |
| 1122 | const int y = option.rect.y() + offset.y(); | - |
| 1123 | const QModelIndex parent = index.parent(); | - |
| 1124 | const QHeaderView *header = d->header; | - |
| 1125 | const QModelIndex current = currentIndex(); | - |
| 1126 | const QModelIndex hover = d->hover; | - |
| 1127 | const bool reverse = isRightToLeft(); | - |
| 1128 | const QStyle::State state = opt.state; | - |
| 1129 | const bool spanning = d->spanning; | - |
| 1130 | const int left = (spanning ? header->visualIndex(0) : d->leftAndRight.first); | - |
| 1131 | const int right = (spanning ? header->visualIndex(0) : d->leftAndRight.second); | - |
| 1132 | const bool alternate = d->alternatingColors; | - |
| 1133 | const bool enabled = (state & QStyle::State_Enabled) != 0; | - |
| 1134 | const bool allColumnsShowFocus = d->allColumnsShowFocus; | - |
| 1135 | | - |
| 1136 | | - |
| 1137 | | - |
| 1138 | | - |
| 1139 | bool indexWidgetHasFocus = false; | - |
| 1140 | if ((current.row() == index.row()) && !d->editorIndexHash.isEmpty()) { | - |
| 1141 | const int r = index.row(); | - |
| 1142 | QWidget *fw = QApplication::focusWidget(); | - |
| 1143 | for (int c = 0; c < header->count(); ++c) { | - |
| 1144 | QModelIndex idx = d->model->index(r, c, parent); | - |
| 1145 | if (QWidget *editor = indexWidget(idx)) { | - |
| 1146 | if (ancestorOf(editor, fw)) { | - |
| 1147 | indexWidgetHasFocus = true; | - |
| 1148 | break; | - |
| 1149 | } | - |
| 1150 | } | - |
| 1151 | } | - |
| 1152 | } | - |
| 1153 | | - |
| 1154 | const bool widgetHasFocus = hasFocus(); | - |
| 1155 | bool currentRowHasFocus = false; | - |
| 1156 | if (allColumnsShowFocus && widgetHasFocus && current.isValid()) { | - |
| 1157 | | - |
| 1158 | const int r = index.row(); | - |
| 1159 | for (int c = 0; c < left && !currentRowHasFocus; ++c) { | - |
| 1160 | QModelIndex idx = d->model->index(r, c, parent); | - |
| 1161 | currentRowHasFocus = (idx == current); | - |
| 1162 | } | - |
| 1163 | QModelIndex parent = d->model->parent(index); | - |
| 1164 | for (int c = right; c < header->count() && !currentRowHasFocus; ++c) { | - |
| 1165 | currentRowHasFocus = (d->model->index(r, c, parent) == current); | - |
| 1166 | } | - |
| 1167 | } | - |
| 1168 | | - |
| 1169 | | - |
| 1170 | | - |
| 1171 | opt.showDecorationSelected = (d->selectionBehavior & SelectRows) | - |
| 1172 | || option.showDecorationSelected; | - |
| 1173 | | - |
| 1174 | int width, height = option.rect.height(); | - |
| 1175 | int position; | - |
| 1176 | QModelIndex modelIndex; | - |
| 1177 | const bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows | - |
| 1178 | && index.parent() == hover.parent() | - |
| 1179 | && index.row() == hover.row(); | - |
| 1180 | | - |
| 1181 | QVector<int> logicalIndices; | - |
| 1182 | QVector<QStyleOptionViewItem::ViewItemPosition> viewItemPosList; | - |
| 1183 | d->calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right); | - |
| 1184 | | - |
| 1185 | for (int currentLogicalSection = 0; currentLogicalSection < logicalIndices.count(); ++currentLogicalSection) { | - |
| 1186 | int headerSection = logicalIndices.at(currentLogicalSection); | - |
| 1187 | position = columnViewportPosition(headerSection) + offset.x(); | - |
| 1188 | width = header->sectionSize(headerSection); | - |
| 1189 | | - |
| 1190 | if (spanning) { | - |
| 1191 | int lastSection = header->logicalIndex(header->count() - 1); | - |
| 1192 | if (!reverse) { | - |
| 1193 | width = columnViewportPosition(lastSection) + header->sectionSize(lastSection) - position; | - |
| 1194 | } else { | - |
| 1195 | width += position - columnViewportPosition(lastSection); | - |
| 1196 | position = columnViewportPosition(lastSection); | - |
| 1197 | } | - |
| 1198 | } | - |
| 1199 | | - |
| 1200 | modelIndex = d->model->index(index.row(), headerSection, parent); | - |
| 1201 | if (!modelIndex.isValid()) | - |
| 1202 | continue; | - |
| 1203 | opt.state = state; | - |
| 1204 | | - |
| 1205 | opt.viewItemPosition = viewItemPosList.at(currentLogicalSection); | - |
| 1206 | | - |
| 1207 | | - |
| 1208 | if (indexWidgetHasFocus) | - |
| 1209 | opt.state |= QStyle::State_Active; | - |
| 1210 | | - |
| 1211 | if (d->selectionModel->isSelected(modelIndex)) | - |
| 1212 | opt.state |= QStyle::State_Selected; | - |
| 1213 | if (widgetHasFocus && (current == modelIndex)) { | - |
| 1214 | if (allColumnsShowFocus) | - |
| 1215 | currentRowHasFocus = true; | - |
| 1216 | else | - |
| 1217 | opt.state |= QStyle::State_HasFocus; | - |
| 1218 | } | - |
| 1219 | if ((hoverRow || modelIndex == hover) | - |
| 1220 | && (option.showDecorationSelected || (d->hoverBranch == -1))) | - |
| 1221 | opt.state |= QStyle::State_MouseOver; | - |
| 1222 | else | - |
| 1223 | opt.state &= ~QStyle::State_MouseOver; | - |
| 1224 | | - |
| 1225 | if (enabled) { | - |
| 1226 | QPalette::ColorGroup cg; | - |
| 1227 | if ((d->model->flags(modelIndex) & Qt::ItemIsEnabled) == 0) { | - |
| 1228 | opt.state &= ~QStyle::State_Enabled; | - |
| 1229 | cg = QPalette::Disabled; | - |
| 1230 | } else if (opt.state & QStyle::State_Active) { | - |
| 1231 | cg = QPalette::Active; | - |
| 1232 | } else { | - |
| 1233 | cg = QPalette::Inactive; | - |
| 1234 | } | - |
| 1235 | opt.palette.setCurrentColorGroup(cg); | - |
| 1236 | } | - |
| 1237 | | - |
| 1238 | if (alternate) { | - |
| 1239 | if (d->current & 1) { | - |
| 1240 | opt.features |= QStyleOptionViewItem::Alternate; | - |
| 1241 | } else { | - |
| 1242 | opt.features &= ~QStyleOptionViewItem::Alternate; | - |
| 1243 | } | - |
| 1244 | } | - |
| 1245 | | - |
| 1246 | | - |
| 1247 | | - |
| 1248 | | - |
| 1249 | | - |
| 1250 | if (headerSection == 0) { | - |
| 1251 | const int i = d->indentationForItem(d->current); | - |
| 1252 | QRect branches(reverse ? position + width - i : position, y, i, height); | - |
| 1253 | const bool setClipRect = branches.width() > width; | - |
| 1254 | if (setClipRect) { | - |
| 1255 | painter->save(); | - |
| 1256 | painter->setClipRect(QRect(position, y, width, height)); | - |
| 1257 | } | - |
| 1258 | | - |
| 1259 | opt.rect = branches; | - |
| 1260 | style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); | - |
| 1261 | | - |
| 1262 | | - |
| 1263 | | - |
| 1264 | QStyle::State oldState = opt.state; | - |
| 1265 | opt.state &= ~QStyle::State_Selected; | - |
| 1266 | opt.rect.setRect(reverse ? position : i + position, y, width - i, height); | - |
| 1267 | style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); | - |
| 1268 | opt.state = oldState; | - |
| 1269 | | - |
| 1270 | if (d->indent != 0) | - |
| 1271 | drawBranches(painter, branches, index); | - |
| 1272 | if (setClipRect) | - |
| 1273 | painter->restore(); | - |
| 1274 | } else { | - |
| 1275 | QStyle::State oldState = opt.state; | - |
| 1276 | opt.state &= ~QStyle::State_Selected; | - |
| 1277 | opt.rect.setRect(position, y, width, height); | - |
| 1278 | style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this); | - |
| 1279 | opt.state = oldState; | - |
| 1280 | } | - |
| 1281 | | - |
| 1282 | d->delegateForIndex(modelIndex)->paint(painter, opt, modelIndex); | - |
| 1283 | } | - |
| 1284 | | - |
| 1285 | if (currentRowHasFocus) { | - |
| 1286 | QStyleOptionFocusRect o; | - |
| 1287 | o.QStyleOption::operator=(option); | - |
| 1288 | o.state |= QStyle::State_KeyboardFocusChange; | - |
| 1289 | QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) | - |
| 1290 | ? QPalette::Normal : QPalette::Disabled; | - |
| 1291 | o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index) | - |
| 1292 | ? QPalette::Highlight : QPalette::Background); | - |
| 1293 | int x = 0; | - |
| 1294 | if (!option.showDecorationSelected) | - |
| 1295 | x = header->sectionPosition(0) + d->indentationForItem(d->current); | - |
| 1296 | QRect focusRect(x - header->offset(), y, header->length() - x, height); | - |
| 1297 | o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), focusRect); | - |
| 1298 | style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter); | - |
| 1299 | | - |
| 1300 | | - |
| 1301 | if (allColumnsShowFocus && !option.showDecorationSelected | - |
| 1302 | && header->sectionsMoved() && (header->visualIndex(0) != 0)) { | - |
| 1303 | QRect sectionRect(0, y, header->sectionPosition(0), height); | - |
| 1304 | o.rect = style()->visualRect(layoutDirection(), d->viewport->rect(), sectionRect); | - |
| 1305 | style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter); | - |
| 1306 | } | - |
| 1307 | } | - |
| 1308 | } | - |
| 1309 | | - |
| 1310 | | - |
| 1311 | | - |
| 1312 | | - |
| 1313 | | - |
| 1314 | | - |
| 1315 | void QTreeView::drawBranches(QPainter *painter, const QRect &rect, | - |
| 1316 | const QModelIndex &index) const | - |
| 1317 | { | - |
| 1318 | const QTreeViewPrivate * const d = d_func(); | - |
| 1319 | const bool reverse = isRightToLeft(); | - |
| 1320 | const int indent = d->indent; | - |
| 1321 | const int outer = d->rootDecoration ? 0 : 1; | - |
| 1322 | const int item = d->current; | - |
| 1323 | const QTreeViewItem &viewItem = d->viewItems.at(item); | - |
| 1324 | int level = viewItem.level; | - |
| 1325 | QRect primitive(reverse ? rect.left() : rect.right() + 1, rect.top(), indent, rect.height()); | - |
| 1326 | | - |
| 1327 | QModelIndex parent = index.parent(); | - |
| 1328 | QModelIndex current = parent; | - |
| 1329 | QModelIndex ancestor = current.parent(); | - |
| 1330 | | - |
| 1331 | QStyleOptionViewItem opt = viewOptions(); | - |
| 1332 | QStyle::State extraFlags = QStyle::State_None; | - |
| 1333 | if (isEnabled()) | - |
| 1334 | extraFlags |= QStyle::State_Enabled; | - |
| 1335 | if (window()->isActiveWindow()) | - |
| 1336 | extraFlags |= QStyle::State_Active; | - |
| 1337 | QPoint oldBO = painter->brushOrigin(); | - |
| 1338 | if (verticalScrollMode() == QAbstractItemView::ScrollPerPixel) | - |
| 1339 | painter->setBrushOrigin(QPoint(0, verticalOffset())); | - |
| 1340 | | - |
| 1341 | if (d->alternatingColors) { | - |
| 1342 | if (d->current & 1) { | - |
| 1343 | opt.features |= QStyleOptionViewItem::Alternate; | - |
| 1344 | } else { | - |
| 1345 | opt.features &= ~QStyleOptionViewItem::Alternate; | - |
| 1346 | } | - |
| 1347 | } | - |
| 1348 | | - |
| 1349 | | - |
| 1350 | | - |
| 1351 | bool hoverRow = selectionBehavior() == QAbstractItemView::SelectRows | - |
| 1352 | && opt.showDecorationSelected | - |
| 1353 | && index.parent() == d->hover.parent() | - |
| 1354 | && index.row() == d->hover.row(); | - |
| 1355 | | - |
| 1356 | if (d->selectionModel->isSelected(index)) | - |
| 1357 | extraFlags |= QStyle::State_Selected; | - |
| 1358 | | - |
| 1359 | if (level >= outer) { | - |
| 1360 | | - |
| 1361 | primitive.moveLeft(reverse ? primitive.left() : primitive.left() - indent); | - |
| 1362 | opt.rect = primitive; | - |
| 1363 | | - |
| 1364 | const bool expanded = viewItem.expanded; | - |
| 1365 | const bool children = viewItem.hasChildren; | - |
| 1366 | bool moreSiblings = viewItem.hasMoreSiblings; | - |
| 1367 | | - |
| 1368 | opt.state = QStyle::State_Item | extraFlags | - |
| 1369 | | (moreSiblings ? QStyle::State_Sibling : QStyle::State_None) | - |
| 1370 | | (children ? QStyle::State_Children : QStyle::State_None) | - |
| 1371 | | (expanded ? QStyle::State_Open : QStyle::State_None); | - |
| 1372 | if (hoverRow || item == d->hoverBranch) | - |
| 1373 | opt.state |= QStyle::State_MouseOver; | - |
| 1374 | else | - |
| 1375 | opt.state &= ~QStyle::State_MouseOver; | - |
| 1376 | style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this); | - |
| 1377 | } | - |
| 1378 | | - |
| 1379 | for (--level; level >= outer; --level) { | - |
| 1380 | primitive.moveLeft(reverse ? primitive.left() + indent : primitive.left() - indent); | - |
| 1381 | opt.rect = primitive; | - |
| 1382 | opt.state = extraFlags; | - |
| 1383 | bool moreSiblings = false; | - |
| 1384 | if (d->hiddenIndexes.isEmpty()) { | - |
| 1385 | moreSiblings = (d->model->rowCount(ancestor) - 1 > current.row()); | - |
| 1386 | } else { | - |
| 1387 | int successor = item + viewItem.total + 1; | - |
| 1388 | while (successor < d->viewItems.size() | - |
| 1389 | && d->viewItems.at(successor).level >= uint(level)) { | - |
| 1390 | const QTreeViewItem &successorItem = d->viewItems.at(successor); | - |
| 1391 | if (successorItem.level == uint(level)) { | - |
| 1392 | moreSiblings = true; | - |
| 1393 | break; | - |
| 1394 | } | - |
| 1395 | successor += successorItem.total + 1; | - |
| 1396 | } | - |
| 1397 | } | - |
| 1398 | if (moreSiblings) | - |
| 1399 | opt.state |= QStyle::State_Sibling; | - |
| 1400 | if (hoverRow || item == d->hoverBranch) | - |
| 1401 | opt.state |= QStyle::State_MouseOver; | - |
| 1402 | else | - |
| 1403 | opt.state &= ~QStyle::State_MouseOver; | - |
| 1404 | style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, painter, this); | - |
| 1405 | current = ancestor; | - |
| 1406 | ancestor = current.parent(); | - |
| 1407 | } | - |
| 1408 | painter->setBrushOrigin(oldBO); | - |
| 1409 | } | - |
| 1410 | | - |
| 1411 | | - |
| 1412 | | - |
| 1413 | | - |
| 1414 | void QTreeView::mousePressEvent(QMouseEvent *event) | - |
| 1415 | { | - |
| 1416 | QTreeViewPrivate * const d = d_func(); | - |
| 1417 | bool handled = false; | - |
| 1418 | if (style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, this) == QEvent::MouseButtonPress) | - |
| 1419 | handled = d->expandOrCollapseItemAtPos(event->pos()); | - |
| 1420 | if (!handled && d->itemDecorationAt(event->pos()) == -1) | - |
| 1421 | QAbstractItemView::mousePressEvent(event); | - |
| 1422 | } | - |
| 1423 | | - |
| 1424 | | - |
| 1425 | | - |
| 1426 | | - |
| 1427 | void QTreeView::mouseReleaseEvent(QMouseEvent *event) | - |
| 1428 | { | - |
| 1429 | QTreeViewPrivate * const d = d_func(); | - |
| 1430 | if (d->itemDecorationAt(event->pos()) == -1) { | - |
| 1431 | QAbstractItemView::mouseReleaseEvent(event); | - |
| 1432 | } else { | - |
| 1433 | if (state() == QAbstractItemView::DragSelectingState) | - |
| 1434 | setState(QAbstractItemView::NoState); | - |
| 1435 | if (style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, this) == QEvent::MouseButtonRelease) | - |
| 1436 | d->expandOrCollapseItemAtPos(event->pos()); | - |
| 1437 | } | - |
| 1438 | } | - |
| 1439 | | - |
| 1440 | | - |
| 1441 | | - |
| 1442 | | - |
| 1443 | void QTreeView::mouseDoubleClickEvent(QMouseEvent *event) | - |
| 1444 | { | - |
| 1445 | QTreeViewPrivate * const d = d_func(); | - |
| 1446 | if (state() != NoState || !d->viewport->rect().contains(event->pos())) | - |
| 1447 | return; | - |
| 1448 | | - |
| 1449 | int i = d->itemDecorationAt(event->pos()); | - |
| 1450 | if (i == -1) { | - |
| 1451 | i = d->itemAtCoordinate(event->y()); | - |
| 1452 | if (i == -1) | - |
| 1453 | return; | - |
| 1454 | | - |
| 1455 | const QPersistentModelIndex firstColumnIndex = d->viewItems.at(i).index; | - |
| 1456 | const QPersistentModelIndex persistent = indexAt(event->pos()); | - |
| 1457 | | - |
| 1458 | if (d->pressedIndex != persistent) { | - |
| 1459 | mousePressEvent(event); | - |
| 1460 | return; | - |
| 1461 | } | - |
| 1462 | | - |
| 1463 | | - |
| 1464 | doubleClicked(persistent); | - |
| 1465 | | - |
| 1466 | if (!persistent.isValid()) | - |
| 1467 | return; | - |
| 1468 | | - |
| 1469 | if (edit(persistent, DoubleClicked, event) || state() != NoState) | - |
| 1470 | return; | - |
| 1471 | | - |
| 1472 | if (!style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, 0, this)) | - |
| 1473 | activated(persistent); | - |
| 1474 | | - |
| 1475 | d->executePostedLayout(); | - |
| 1476 | if (d->itemsExpandable | - |
| 1477 | && d->expandsOnDoubleClick | - |
| 1478 | && d->hasVisibleChildren(persistent)) { | - |
| 1479 | if (!((i < d->viewItems.count()) && (d->viewItems.at(i).index == firstColumnIndex))) { | - |
| 1480 | | - |
| 1481 | for (i = 0; i < d->viewItems.count(); ++i) { | - |
| 1482 | if (d->viewItems.at(i).index == firstColumnIndex) | - |
| 1483 | break; | - |
| 1484 | } | - |
| 1485 | if (i == d->viewItems.count()) | - |
| 1486 | return; | - |
| 1487 | } | - |
| 1488 | if (d->viewItems.at(i).expanded) | - |
| 1489 | d->collapse(i, true); | - |
| 1490 | else | - |
| 1491 | d->expand(i, true); | - |
| 1492 | updateGeometries(); | - |
| 1493 | viewport()->update(); | - |
| 1494 | } | - |
| 1495 | } | - |
| 1496 | } | - |
| 1497 | | - |
| 1498 | | - |
| 1499 | | - |
| 1500 | | - |
| 1501 | void QTreeView::mouseMoveEvent(QMouseEvent *event) | - |
| 1502 | { | - |
| 1503 | QTreeViewPrivate * const d = d_func(); | - |
| 1504 | if (d->itemDecorationAt(event->pos()) == -1) | - |
| 1505 | QAbstractItemView::mouseMoveEvent(event); | - |
| 1506 | } | - |
| 1507 | | - |
| 1508 | | - |
| 1509 | | - |
| 1510 | | - |
| 1511 | void QTreeView::keyPressEvent(QKeyEvent *event) | - |
| 1512 | { | - |
| 1513 | QTreeViewPrivate * const d = d_func(); | - |
| 1514 | QModelIndex current = currentIndex(); | - |
| 1515 | | - |
| 1516 | if (d->isIndexValid(current) && d->model && d->itemsExpandable) { | - |
| 1517 | switch (event->key()) { | - |
| 1518 | case Qt::Key_Asterisk: { | - |
| 1519 | QStack<QModelIndex> parents; | - |
| 1520 | parents.push(current); | - |
| 1521 | while (!parents.isEmpty()) { | - |
| 1522 | QModelIndex parent = parents.pop(); | - |
| 1523 | for (int row = 0; row < d->model->rowCount(parent); ++row) { | - |
| 1524 | QModelIndex child = d->model->index(row, 0, parent); | - |
| 1525 | if (!d->isIndexValid(child)) | - |
| 1526 | break; | - |
| 1527 | parents.push(child); | - |
| 1528 | expand(child); | - |
| 1529 | } | - |
| 1530 | } | - |
| 1531 | expand(current); | - |
| 1532 | break; } | - |
| 1533 | case Qt::Key_Plus: | - |
| 1534 | expand(current); | - |
| 1535 | break; | - |
| 1536 | case Qt::Key_Minus: | - |
| 1537 | collapse(current); | - |
| 1538 | break; | - |
| 1539 | } | - |
| 1540 | } | - |
| 1541 | | - |
| 1542 | QAbstractItemView::keyPressEvent(event); | - |
| 1543 | } | - |
| 1544 | | - |
| 1545 | | - |
| 1546 | | - |
| 1547 | | - |
| 1548 | QModelIndex QTreeView::indexAt(const QPoint &point) const | - |
| 1549 | { | - |
| 1550 | const QTreeViewPrivate * const d = d_func(); | - |
| 1551 | d->executePostedLayout(); | - |
| 1552 | | - |
| 1553 | int visualIndex = d->itemAtCoordinate(point.y()); | - |
| 1554 | QModelIndex idx = d->modelIndex(visualIndex); | - |
| 1555 | if (!idx.isValid()) | - |
| 1556 | return QModelIndex(); | - |
| 1557 | | - |
| 1558 | if (d->viewItems.at(visualIndex).spanning) | - |
| 1559 | return idx; | - |
| 1560 | | - |
| 1561 | int column = d->columnAt(point.x()); | - |
| 1562 | if (column == idx.column()) | - |
| 1563 | return idx; | - |
| 1564 | if (column < 0) | - |
| 1565 | return QModelIndex(); | - |
| 1566 | return idx.sibling(idx.row(), column); | - |
| 1567 | } | - |
| 1568 | | - |
| 1569 | | - |
| 1570 | | - |
| 1571 | | - |
| 1572 | QModelIndex QTreeView::indexAbove(const QModelIndex &index) const | - |
| 1573 | { | - |
| 1574 | const QTreeViewPrivate * const d = d_func(); | - |
| 1575 | if (!d->isIndexValid(index)) | - |
| 1576 | return QModelIndex(); | - |
| 1577 | d->executePostedLayout(); | - |
| 1578 | int i = d->viewIndex(index); | - |
| 1579 | if (--i < 0) | - |
| 1580 | return QModelIndex(); | - |
| 1581 | const QModelIndex firstColumnIndex = d->viewItems.at(i).index; | - |
| 1582 | return firstColumnIndex.sibling(firstColumnIndex.row(), index.column()); | - |
| 1583 | } | - |
| 1584 | | - |
| 1585 | | - |
| 1586 | | - |
| 1587 | | - |
| 1588 | QModelIndex QTreeView::indexBelow(const QModelIndex &index) const | - |
| 1589 | { | - |
| 1590 | const QTreeViewPrivate * const d = d_func(); | - |
| 1591 | if (!d->isIndexValid(index)) | - |
| 1592 | return QModelIndex(); | - |
| 1593 | d->executePostedLayout(); | - |
| 1594 | int i = d->viewIndex(index); | - |
| 1595 | if (++i >= d->viewItems.count()) | - |
| 1596 | return QModelIndex(); | - |
| 1597 | const QModelIndex firstColumnIndex = d->viewItems.at(i).index; | - |
| 1598 | return firstColumnIndex.sibling(firstColumnIndex.row(), index.column()); | - |
| 1599 | } | - |
| 1600 | | - |
| 1601 | | - |
| 1602 | | - |
| 1603 | | - |
| 1604 | | - |
| 1605 | | - |
| 1606 | void QTreeView::doItemsLayout() | - |
| 1607 | { | - |
| 1608 | QTreeViewPrivate * const d = d_func(); | - |
| 1609 | if (d->hasRemovedItems) { | - |
| 1610 | | - |
| 1611 | d->hasRemovedItems = false; | - |
| 1612 | QSet<QPersistentModelIndex>::iterator it = d->expandedIndexes.begin(); | - |
| 1613 | while (it != d->expandedIndexes.end()) { | - |
| 1614 | if (!it->isValid()) | - |
| 1615 | it = d->expandedIndexes.erase(it); | - |
| 1616 | else | - |
| 1617 | ++it; | - |
| 1618 | } | - |
| 1619 | it = d->hiddenIndexes.begin(); | - |
| 1620 | while (it != d->hiddenIndexes.end()) { | - |
| 1621 | if (!it->isValid()) | - |
| 1622 | it = d->hiddenIndexes.erase(it); | - |
| 1623 | else | - |
| 1624 | ++it; | - |
| 1625 | } | - |
| 1626 | } | - |
| 1627 | d->viewItems.clear(); | - |
| 1628 | QModelIndex parent = d->root; | - |
| 1629 | if (d->model->hasChildren(parent)) { | - |
| 1630 | d->layout(-1); | - |
| 1631 | } | - |
| 1632 | QAbstractItemView::doItemsLayout(); | - |
| 1633 | d->header->doItemsLayout(); | - |
| 1634 | } | - |
| 1635 | | - |
| 1636 | | - |
| 1637 | | - |
| 1638 | | - |
| 1639 | void QTreeView::reset() | - |
| 1640 | { | - |
| 1641 | QTreeViewPrivate * const d = d_func(); | - |
| 1642 | d->expandedIndexes.clear(); | - |
| 1643 | d->hiddenIndexes.clear(); | - |
| 1644 | d->spanningIndexes.clear(); | - |
| 1645 | d->viewItems.clear(); | - |
| 1646 | QAbstractItemView::reset(); | - |
| 1647 | } | - |
| 1648 | int QTreeView::horizontalOffset() const | - |
| 1649 | { | - |
| 1650 | const QTreeViewPrivate * const d = d_func(); | - |
| 1651 | return d->header->offset(); | - |
| 1652 | } | - |
| 1653 | | - |
| 1654 | | - |
| 1655 | | - |
| 1656 | | - |
| 1657 | | - |
| 1658 | | - |
| 1659 | int QTreeView::verticalOffset() const | - |
| 1660 | { | - |
| 1661 | const QTreeViewPrivate * const d = d_func(); | - |
| 1662 | if (d->verticalScrollMode == QAbstractItemView::ScrollPerItem) { | - |
| 1663 | if (d->uniformRowHeights) | - |
| 1664 | return verticalScrollBar()->value() * d->defaultItemHeight; | - |
| 1665 | | - |
| 1666 | | - |
| 1667 | | - |
| 1668 | d->executePostedLayout(); | - |
| 1669 | int offset = 0; | - |
| 1670 | for (int i = 0; i < d->viewItems.count(); ++i) { | - |
| 1671 | if (i == verticalScrollBar()->value()) | - |
| 1672 | return offset; | - |
| 1673 | offset += d->itemHeight(i); | - |
| 1674 | } | - |
| 1675 | return 0; | - |
| 1676 | } | - |
| 1677 | | - |
| 1678 | return verticalScrollBar()->value(); | - |
| 1679 | } | - |
| 1680 | | - |
| 1681 | | - |
| 1682 | | - |
| 1683 | | - |
| 1684 | | - |
| 1685 | QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) | - |
| 1686 | { | - |
| 1687 | QTreeViewPrivate * const d = d_func(); | - |
| 1688 | (void)modifiers;; | - |
| 1689 | | - |
| 1690 | d->executePostedLayout(); | - |
| 1691 | | - |
| 1692 | QModelIndex current = currentIndex(); | - |
| 1693 | if (!current.isValid()) { | - |
| 1694 | int i = d->below(-1); | - |
| 1695 | int c = 0; | - |
| 1696 | while (c < d->header->count() && d->header->isSectionHidden(c)) | - |
| 1697 | ++c; | - |
| 1698 | if (i < d->viewItems.count() && c < d->header->count()) { | - |
| 1699 | return d->modelIndex(i, c); | - |
| 1700 | } | - |
| 1701 | return QModelIndex(); | - |
| 1702 | } | - |
| 1703 | int vi = -1; | - |
| 1704 | if (vi < 0) | - |
| 1705 | vi = qMax(0, d->viewIndex(current)); | - |
| 1706 | | - |
| 1707 | if (isRightToLeft()) { | - |
| 1708 | if (cursorAction == MoveRight) | - |
| 1709 | cursorAction = MoveLeft; | - |
| 1710 | else if (cursorAction == MoveLeft) | - |
| 1711 | cursorAction = MoveRight; | - |
| 1712 | } | - |
| 1713 | switch (cursorAction) { | - |
| 1714 | case MoveNext: | - |
| 1715 | case MoveDown: | - |
| 1716 | | - |
| 1717 | | - |
| 1718 | | - |
| 1719 | | - |
| 1720 | return d->modelIndex(d->below(vi), current.column()); | - |
| 1721 | case MovePrevious: | - |
| 1722 | case MoveUp: | - |
| 1723 | | - |
| 1724 | | - |
| 1725 | | - |
| 1726 | | - |
| 1727 | return d->modelIndex(d->above(vi), current.column()); | - |
| 1728 | case MoveLeft: { | - |
| 1729 | QScrollBar *sb = horizontalScrollBar(); | - |
| 1730 | if (vi < d->viewItems.count() && d->viewItems.at(vi).expanded && d->itemsExpandable && sb->value() == sb->minimum()) { | - |
| 1731 | d->collapse(vi, true); | - |
| 1732 | d->moveCursorUpdatedView = true; | - |
| 1733 | } else { | - |
| 1734 | bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this); | - |
| 1735 | if (descend) { | - |
| 1736 | QModelIndex par = current.parent(); | - |
| 1737 | if (par.isValid() && par != rootIndex()) | - |
| 1738 | return par; | - |
| 1739 | else | - |
| 1740 | descend = false; | - |
| 1741 | } | - |
| 1742 | if (!descend) { | - |
| 1743 | if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) { | - |
| 1744 | int visualColumn = d->header->visualIndex(current.column()) - 1; | - |
| 1745 | while (visualColumn >= 0 && isColumnHidden(d->header->logicalIndex(visualColumn))) | - |
| 1746 | visualColumn--; | - |
| 1747 | int newColumn = d->header->logicalIndex(visualColumn); | - |
| 1748 | QModelIndex next = current.sibling(current.row(), newColumn); | - |
| 1749 | if (next.isValid()) | - |
| 1750 | return next; | - |
| 1751 | } | - |
| 1752 | | - |
| 1753 | int oldValue = sb->value(); | - |
| 1754 | sb->setValue(sb->value() - sb->singleStep()); | - |
| 1755 | if (oldValue != sb->value()) | - |
| 1756 | d->moveCursorUpdatedView = true; | - |
| 1757 | } | - |
| 1758 | | - |
| 1759 | } | - |
| 1760 | updateGeometries(); | - |
| 1761 | viewport()->update(); | - |
| 1762 | break; | - |
| 1763 | } | - |
| 1764 | case MoveRight: | - |
| 1765 | if (vi < d->viewItems.count() && !d->viewItems.at(vi).expanded && d->itemsExpandable | - |
| 1766 | && d->hasVisibleChildren(d->viewItems.at(vi).index)) { | - |
| 1767 | d->expand(vi, true); | - |
| 1768 | d->moveCursorUpdatedView = true; | - |
| 1769 | } else { | - |
| 1770 | bool descend = style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, this); | - |
| 1771 | if (descend) { | - |
| 1772 | QModelIndex idx = d->modelIndex(d->below(vi)); | - |
| 1773 | if (idx.parent() == current) | - |
| 1774 | return idx; | - |
| 1775 | else | - |
| 1776 | descend = false; | - |
| 1777 | } | - |
| 1778 | if (!descend) { | - |
| 1779 | if (d->selectionBehavior == SelectItems || d->selectionBehavior == SelectColumns) { | - |
| 1780 | int visualColumn = d->header->visualIndex(current.column()) + 1; | - |
| 1781 | while (visualColumn < d->model->columnCount(current.parent()) && isColumnHidden(d->header->logicalIndex(visualColumn))) | - |
| 1782 | visualColumn++; | - |
| 1783 | | - |
| 1784 | QModelIndex next = current.sibling(current.row(), visualColumn); | - |
| 1785 | if (next.isValid()) | - |
| 1786 | return next; | - |
| 1787 | } | - |
| 1788 | | - |
| 1789 | | - |
| 1790 | QScrollBar *sb = horizontalScrollBar(); | - |
| 1791 | int oldValue = sb->value(); | - |
| 1792 | sb->setValue(sb->value() + sb->singleStep()); | - |
| 1793 | if (oldValue != sb->value()) | - |
| 1794 | d->moveCursorUpdatedView = true; | - |
| 1795 | } | - |
| 1796 | } | - |
| 1797 | updateGeometries(); | - |
| 1798 | viewport()->update(); | - |
| 1799 | break; | - |
| 1800 | case MovePageUp: | - |
| 1801 | return d->modelIndex(d->pageUp(vi), current.column()); | - |
| 1802 | case MovePageDown: | - |
| 1803 | return d->modelIndex(d->pageDown(vi), current.column()); | - |
| 1804 | case MoveHome: | - |
| 1805 | return d->model->index(0, current.column(), d->root); | - |
| 1806 | case MoveEnd: | - |
| 1807 | return d->modelIndex(d->viewItems.count() - 1, current.column()); | - |
| 1808 | } | - |
| 1809 | return current; | - |
| 1810 | } | - |
| 1811 | | - |
| 1812 | | - |
| 1813 | | - |
| 1814 | | - |
| 1815 | | - |
| 1816 | | - |
| 1817 | | - |
| 1818 | void QTreeView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) | - |
| 1819 | { | - |
| 1820 | QTreeViewPrivate * const d = d_func(); | - |
| 1821 | if (!selectionModel() || rect.isNull()) | - |
| 1822 | return; | - |
| 1823 | | - |
| 1824 | d->executePostedLayout(); | - |
| 1825 | QPoint tl(isRightToLeft() ? qMax(rect.left(), rect.right()) | - |
| 1826 | : qMin(rect.left(), rect.right()), qMin(rect.top(), rect.bottom())); | - |
| 1827 | QPoint br(isRightToLeft() ? qMin(rect.left(), rect.right()) : | - |
| 1828 | qMax(rect.left(), rect.right()), qMax(rect.top(), rect.bottom())); | - |
| 1829 | QModelIndex topLeft = indexAt(tl); | - |
| 1830 | QModelIndex bottomRight = indexAt(br); | - |
| 1831 | if (!topLeft.isValid() && !bottomRight.isValid()) { | - |
| 1832 | if (command & QItemSelectionModel::Clear) | - |
| 1833 | selectionModel()->clear(); | - |
| 1834 | return; | - |
| 1835 | } | - |
| 1836 | if (!topLeft.isValid() && !d->viewItems.isEmpty()) | - |
| 1837 | topLeft = d->viewItems.first().index; | - |
| 1838 | if (!bottomRight.isValid() && !d->viewItems.isEmpty()) { | - |
| 1839 | const int column = d->header->logicalIndex(d->header->count() - 1); | - |
| 1840 | const QModelIndex index = d->viewItems.last().index; | - |
| 1841 | bottomRight = index.sibling(index.row(), column); | - |
| 1842 | } | - |
| 1843 | | - |
| 1844 | if (!d->isIndexEnabled(topLeft) || !d->isIndexEnabled(bottomRight)) | - |
| 1845 | return; | - |
| 1846 | | - |
| 1847 | d->select(topLeft, bottomRight, command); | - |
| 1848 | } | - |
| 1849 | QRegion QTreeView::visualRegionForSelection(const QItemSelection &selection) const | - |
| 1850 | { | - |
| 1851 | const QTreeViewPrivate * const d = d_func(); | - |
| 1852 | if (selection.isEmpty()) | - |
| 1853 | return QRegion(); | - |
| 1854 | | - |
| 1855 | QRegion selectionRegion; | - |
| 1856 | const QRect &viewportRect = d->viewport->rect(); | - |
| 1857 | for (int i = 0; i < selection.count(); ++i) { | - |
| 1858 | QItemSelectionRange range = selection.at(i); | - |
| 1859 | if (!range.isValid()) | - |
| 1860 | continue; | - |
| 1861 | QModelIndex parent = range.parent(); | - |
| 1862 | QModelIndex leftIndex = range.topLeft(); | - |
| 1863 | int columnCount = d->model->columnCount(parent); | - |
| 1864 | while (leftIndex.isValid() && isIndexHidden(leftIndex)) { | - |
| 1865 | if (leftIndex.column() + 1 < columnCount) | - |
| 1866 | leftIndex = d->model->index(leftIndex.row(), leftIndex.column() + 1, parent); | - |
| 1867 | else | - |
| 1868 | leftIndex = QModelIndex(); | - |
| 1869 | } | - |
| 1870 | if (!leftIndex.isValid()) | - |
| 1871 | continue; | - |
| 1872 | const QRect leftRect = visualRect(leftIndex); | - |
| 1873 | int top = leftRect.top(); | - |
| 1874 | QModelIndex rightIndex = range.bottomRight(); | - |
| 1875 | while (rightIndex.isValid() && isIndexHidden(rightIndex)) { | - |
| 1876 | if (rightIndex.column() - 1 >= 0) | - |
| 1877 | rightIndex = d->model->index(rightIndex.row(), rightIndex.column() - 1, parent); | - |
| 1878 | else | - |
| 1879 | rightIndex = QModelIndex(); | - |
| 1880 | } | - |
| 1881 | if (!rightIndex.isValid()) | - |
| 1882 | continue; | - |
| 1883 | const QRect rightRect = visualRect(rightIndex); | - |
| 1884 | int bottom = rightRect.bottom(); | - |
| 1885 | if (top > bottom) | - |
| 1886 | qSwap<int>(top, bottom); | - |
| 1887 | int height = bottom - top + 1; | - |
| 1888 | if (d->header->sectionsMoved()) { | - |
| 1889 | for (int c = range.left(); c <= range.right(); ++c) { | - |
| 1890 | const QRect rangeRect(columnViewportPosition(c), top, columnWidth(c), height); | - |
| 1891 | if (viewportRect.intersects(rangeRect)) | - |
| 1892 | selectionRegion += rangeRect; | - |
| 1893 | } | - |
| 1894 | } else { | - |
| 1895 | QRect combined = leftRect|rightRect; | - |
| 1896 | combined.setX(columnViewportPosition(isRightToLeft() ? range.right() : range.left())); | - |
| 1897 | if (viewportRect.intersects(combined)) | - |
| 1898 | selectionRegion += combined; | - |
| 1899 | } | - |
| 1900 | } | - |
| 1901 | return selectionRegion; | - |
| 1902 | } | - |
| 1903 | | - |
| 1904 | | - |
| 1905 | | - |
| 1906 | | - |
| 1907 | QModelIndexList QTreeView::selectedIndexes() const | - |
| 1908 | { | - |
| 1909 | QModelIndexList viewSelected; | - |
| 1910 | QModelIndexList modelSelected; | - |
| 1911 | if (selectionModel()) | - |
| 1912 | modelSelected = selectionModel()->selectedIndexes(); | - |
| 1913 | for (int i = 0; i < modelSelected.count(); ++i) { | - |
| 1914 | | - |
| 1915 | QModelIndex index = modelSelected.at(i); | - |
| 1916 | while (index.isValid() && !isIndexHidden(index)) | - |
| 1917 | index = index.parent(); | - |
| 1918 | if (index.isValid()) | - |
| 1919 | continue; | - |
| 1920 | viewSelected.append(modelSelected.at(i)); | - |
| 1921 | } | - |
| 1922 | return viewSelected; | - |
| 1923 | } | - |
| 1924 | | - |
| 1925 | | - |
| 1926 | | - |
| 1927 | | - |
| 1928 | void QTreeView::scrollContentsBy(int dx, int dy) | - |
| 1929 | { | - |
| 1930 | QTreeViewPrivate * const d = d_func(); | - |
| 1931 | | - |
| 1932 | d->delayedAutoScroll.stop(); | - |
| 1933 | | - |
| 1934 | dx = isRightToLeft() ? -dx : dx; | - |
| 1935 | if (dx) { | - |
| 1936 | if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) { | - |
| 1937 | int oldOffset = d->header->offset(); | - |
| 1938 | if (horizontalScrollBar()->value() == horizontalScrollBar()->maximum()) | - |
| 1939 | d->header->setOffsetToLastSection(); | - |
| 1940 | else | - |
| 1941 | d->header->setOffsetToSectionPosition(horizontalScrollBar()->value()); | - |
| 1942 | int newOffset = d->header->offset(); | - |
| 1943 | dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset; | - |
| 1944 | } else { | - |
| 1945 | d->header->setOffset(horizontalScrollBar()->value()); | - |
| 1946 | } | - |
| 1947 | } | - |
| 1948 | | - |
| 1949 | const int itemHeight = d->defaultItemHeight <= 0 ? sizeHintForRow(0) : d->defaultItemHeight; | - |
| 1950 | if (d->viewItems.isEmpty() || itemHeight == 0) | - |
| 1951 | return; | - |
| 1952 | | - |
| 1953 | | - |
| 1954 | int viewCount = d->viewport->height() / itemHeight; | - |
| 1955 | int maxDeltaY = qMin(d->viewItems.count(), viewCount); | - |
| 1956 | | - |
| 1957 | if (qAbs(dy) > qAbs(maxDeltaY) && d->editorIndexHash.isEmpty()) { | - |
| 1958 | verticalScrollBar()->update(); | - |
| 1959 | d->viewport->update(); | - |
| 1960 | return; | - |
| 1961 | } | - |
| 1962 | | - |
| 1963 | if (dy && verticalScrollMode() == QAbstractItemView::ScrollPerItem) { | - |
| 1964 | int currentScrollbarValue = verticalScrollBar()->value(); | - |
| 1965 | int previousScrollbarValue = currentScrollbarValue + dy; | - |
| 1966 | int currentViewIndex = currentScrollbarValue; | - |
| 1967 | int previousViewIndex = previousScrollbarValue; | - |
| 1968 | const QVector<QTreeViewItem> viewItems = d->viewItems; | - |
| 1969 | dy = 0; | - |
| 1970 | if (previousViewIndex < currentViewIndex) { | - |
| 1971 | for (int i = previousViewIndex; i < currentViewIndex; ++i) { | - |
| 1972 | if (i < d->viewItems.count()) | - |
| 1973 | dy -= d->itemHeight(i); | - |
| 1974 | } | - |
| 1975 | } else if (previousViewIndex > currentViewIndex) { | - |
| 1976 | for (int i = previousViewIndex - 1; i >= currentViewIndex; --i) { | - |
| 1977 | if (i < d->viewItems.count()) | - |
| 1978 | dy += d->itemHeight(i); | - |
| 1979 | } | - |
| 1980 | } | - |
| 1981 | } | - |
| 1982 | | - |
| 1983 | d->scrollContentsBy(dx, dy); | - |
| 1984 | } | - |
| 1985 | | - |
| 1986 | | - |
| 1987 | | - |
| 1988 | | - |
| 1989 | void QTreeView::columnMoved() | - |
| 1990 | { | - |
| 1991 | QTreeViewPrivate * const d = d_func(); | - |
| 1992 | updateEditorGeometries(); | - |
| 1993 | d->viewport->update(); | - |
| 1994 | } | - |
| 1995 | | - |
| 1996 | | - |
| 1997 | | - |
| 1998 | | - |
| 1999 | void QTreeView::reexpand() | - |
| 2000 | { | - |
| 2001 | | - |
| 2002 | } | - |
| 2003 | | - |
| 2004 | | - |
| 2005 | | - |
| 2006 | | - |
| 2007 | | - |
| 2008 | void QTreeView::rowsInserted(const QModelIndex &parent, int start, int end) | - |
| 2009 | { | - |
| 2010 | QTreeViewPrivate * const d = d_func(); | - |
| 2011 | | - |
| 2012 | if (d->delayedPendingLayout) { | - |
| 2013 | QAbstractItemView::rowsInserted(parent, start, end); | - |
| 2014 | return; | - |
| 2015 | } | - |
| 2016 | | - |
| 2017 | | - |
| 2018 | if (parent.column() != 0 && parent.isValid()) { | - |
| 2019 | QAbstractItemView::rowsInserted(parent, start, end); | - |
| 2020 | return; | - |
| 2021 | } | - |
| 2022 | | - |
| 2023 | const int parentRowCount = d->model->rowCount(parent); | - |
| 2024 | const int delta = end - start + 1; | - |
| 2025 | if (parent != d->root && !d->isIndexExpanded(parent) && parentRowCount > delta) { | - |
| 2026 | QAbstractItemView::rowsInserted(parent, start, end); | - |
| 2027 | return; | - |
| 2028 | } | - |
| 2029 | | - |
| 2030 | const int parentItem = d->viewIndex(parent); | - |
| 2031 | if (((parentItem != -1) && d->viewItems.at(parentItem).expanded) | - |
| 2032 | || (parent == d->root)) { | - |
| 2033 | d->doDelayedItemsLayout(); | - |
| 2034 | } else if (parentItem != -1 && (d->model->rowCount(parent) == end - start + 1)) { | - |
| 2035 | | - |
| 2036 | d->viewItems[parentItem].hasChildren = true; | - |
| 2037 | viewport()->update(); | - |
| 2038 | } | - |
| 2039 | QAbstractItemView::rowsInserted(parent, start, end); | - |
| 2040 | } | - |
| 2041 | | - |
| 2042 | | - |
| 2043 | | - |
| 2044 | | - |
| 2045 | | - |
| 2046 | void QTreeView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) | - |
| 2047 | { | - |
| 2048 | QTreeViewPrivate * const d = d_func(); | - |
| 2049 | QAbstractItemView::rowsAboutToBeRemoved(parent, start, end); | - |
| 2050 | d->viewItems.clear(); | - |
| 2051 | } | - |
| 2052 | | - |
| 2053 | | - |
| 2054 | | - |
| 2055 | | - |
| 2056 | | - |
| 2057 | | - |
| 2058 | | - |
| 2059 | void QTreeView::rowsRemoved(const QModelIndex &parent, int start, int end) | - |
| 2060 | { | - |
| 2061 | QTreeViewPrivate * const d = d_func(); | - |
| 2062 | d->viewItems.clear(); | - |
| 2063 | d->doDelayedItemsLayout(); | - |
| 2064 | d->hasRemovedItems = true; | - |
| 2065 | d->_q_rowsRemoved(parent, start, end); | - |
| 2066 | } | - |
| 2067 | | - |
| 2068 | | - |
| 2069 | | - |
| 2070 | | - |
| 2071 | | - |
| 2072 | void QTreeView::columnCountChanged(int oldCount, int newCount) | - |
| 2073 | { | - |
| 2074 | QTreeViewPrivate * const d = d_func(); | - |
| 2075 | if (oldCount == 0 && newCount > 0) { | - |
| 2076 | | - |
| 2077 | d->doDelayedItemsLayout(); | - |
| 2078 | } | - |
| 2079 | | - |
| 2080 | if (isVisible()) | - |
| 2081 | updateGeometries(); | - |
| 2082 | viewport()->update(); | - |
| 2083 | } | - |
| 2084 | | - |
| 2085 | | - |
| 2086 | | - |
| 2087 | | - |
| 2088 | | - |
| 2089 | | - |
| 2090 | void QTreeView::resizeColumnToContents(int column) | - |
| 2091 | { | - |
| 2092 | QTreeViewPrivate * const d = d_func(); | - |
| 2093 | d->executePostedLayout(); | - |
| 2094 | if (column < 0 || column >= d->header->count()) | - |
| 2095 | return; | - |
| 2096 | int contents = sizeHintForColumn(column); | - |
| 2097 | int header = d->header->isHidden() ? 0 : d->header->sectionSizeHint(column); | - |
| 2098 | d->header->resizeSection(column, qMax(contents, header)); | - |
| 2099 | } | - |
| 2100 | | - |
| 2101 | | - |
| 2102 | | - |
| 2103 | | - |
| 2104 | | - |
| 2105 | | - |
| 2106 | | - |
| 2107 | void QTreeView::sortByColumn(int column) | - |
| 2108 | { | - |
| 2109 | QTreeViewPrivate * const d = d_func(); | - |
| 2110 | sortByColumn(column, d->header->sortIndicatorOrder()); | - |
| 2111 | } | - |
| 2112 | void QTreeView::sortByColumn(int column, Qt::SortOrder order) | - |
| 2113 | { | - |
| 2114 | QTreeViewPrivate * const d = d_func(); | - |
| 2115 | | - |
| 2116 | | - |
| 2117 | d->header->setSortIndicator(column, order); | - |
| 2118 | | - |
| 2119 | if (!d->sortingEnabled) | - |
| 2120 | d->model->sort(column, order); | - |
| 2121 | } | - |
| 2122 | | - |
| 2123 | | - |
| 2124 | | - |
| 2125 | | - |
| 2126 | void QTreeView::selectAll() | - |
| 2127 | { | - |
| 2128 | QTreeViewPrivate * const d = d_func(); | - |
| 2129 | if (!selectionModel()) | - |
| 2130 | return; | - |
| 2131 | SelectionMode mode = d->selectionMode; | - |
| 2132 | d->executePostedLayout(); | - |
| 2133 | if (mode != SingleSelection && mode != NoSelection && !d->viewItems.isEmpty()) { | - |
| 2134 | const QModelIndex &idx = d->viewItems.last().index; | - |
| 2135 | QModelIndex lastItemIndex = idx.sibling(idx.row(), d->model->columnCount(idx.parent()) - 1); | - |
| 2136 | d->select(d->viewItems.first().index, lastItemIndex, | - |
| 2137 | QItemSelectionModel::ClearAndSelect | - |
| 2138 | |QItemSelectionModel::Rows); | - |
| 2139 | } | - |
| 2140 | } | - |
| 2141 | void QTreeView::expandAll() | - |
| 2142 | { | - |
| 2143 | QTreeViewPrivate * const d = d_func(); | - |
| 2144 | d->viewItems.clear(); | - |
| 2145 | d->interruptDelayedItemsLayout(); | - |
| 2146 | d->layout(-1, true); | - |
| 2147 | updateGeometries(); | - |
| 2148 | d->viewport->update(); | - |
| 2149 | } | - |
| 2150 | void QTreeView::collapseAll() | - |
| 2151 | { | - |
| 2152 | QTreeViewPrivate * const d = d_func(); | - |
| 2153 | d->expandedIndexes.clear(); | - |
| 2154 | doItemsLayout(); | - |
| 2155 | } | - |
| 2156 | | - |
| 2157 | | - |
| 2158 | | - |
| 2159 | | - |
| 2160 | | - |
| 2161 | | - |
| 2162 | | - |
| 2163 | void QTreeView::expandToDepth(int depth) | - |
| 2164 | { | - |
| 2165 | QTreeViewPrivate * const d = d_func(); | - |
| 2166 | d->viewItems.clear(); | - |
| 2167 | d->expandedIndexes.clear(); | - |
| 2168 | d->interruptDelayedItemsLayout(); | - |
| 2169 | d->layout(-1); | - |
| 2170 | for (int i = 0; i < d->viewItems.count(); ++i) { | - |
| 2171 | if (d->viewItems.at(i).level <= (uint)depth) { | - |
| 2172 | d->viewItems[i].expanded = true; | - |
| 2173 | d->layout(i); | - |
| 2174 | d->storeExpanded(d->viewItems.at(i).index); | - |
| 2175 | } | - |
| 2176 | } | - |
| 2177 | updateGeometries(); | - |
| 2178 | d->viewport->update(); | - |
| 2179 | } | - |
| 2180 | void QTreeView::columnResized(int column, int , int ) | - |
| 2181 | { | - |
| 2182 | QTreeViewPrivate * const d = d_func(); | - |
| 2183 | d->columnsToUpdate.append(column); | - |
| 2184 | if (d->columnResizeTimerID == 0) | - |
| 2185 | d->columnResizeTimerID = startTimer(0); | - |
| 2186 | } | - |
| 2187 | | - |
| 2188 | | - |
| 2189 | | - |
| 2190 | | - |
| 2191 | void QTreeView::updateGeometries() | - |
| 2192 | { | - |
| 2193 | QTreeViewPrivate * const d = d_func(); | - |
| 2194 | if (d->header) { | - |
| 2195 | if (d->geometryRecursionBlock) | - |
| 2196 | return; | - |
| 2197 | d->geometryRecursionBlock = true; | - |
| 2198 | QSize hint = d->header->isHidden() ? QSize(0, 0) : d->header->sizeHint(); | - |
| 2199 | setViewportMargins(0, hint.height(), 0, 0); | - |
| 2200 | QRect vg = d->viewport->geometry(); | - |
| 2201 | QRect geometryRect(vg.left(), vg.top() - hint.height(), vg.width(), hint.height()); | - |
| 2202 | d->header->setGeometry(geometryRect); | - |
| 2203 | | - |
| 2204 | QMetaObject::invokeMethod(d->header, "updateGeometries"); | - |
| 2205 | d->updateScrollBars(); | - |
| 2206 | d->geometryRecursionBlock = false; | - |
| 2207 | } | - |
| 2208 | QAbstractItemView::updateGeometries(); | - |
| 2209 | } | - |
| 2210 | int QTreeView::sizeHintForColumn(int column) const | - |
| 2211 | { | - |
| 2212 | const QTreeViewPrivate * const d = d_func(); | - |
| 2213 | d->executePostedLayout(); | - |
| 2214 | if (d->viewItems.isEmpty()) | - |
| 2215 | return -1; | - |
| 2216 | ensurePolished(); | - |
| 2217 | int w = 0; | - |
| 2218 | QStyleOptionViewItem option = d->viewOptions(); | - |
| 2219 | const QVector<QTreeViewItem> viewItems = d->viewItems; | - |
| 2220 | | - |
| 2221 | int start = 0; | - |
| 2222 | int end = viewItems.count(); | - |
| 2223 | if(end > 1000) { | - |
| 2224 | | - |
| 2225 | start = qMax(0, d->firstVisibleItem() - 100); | - |
| 2226 | end = qMin(end, start + 900); | - |
| 2227 | } | - |
| 2228 | | - |
| 2229 | for (int i = start; i < end; ++i) { | - |
| 2230 | if (viewItems.at(i).spanning) | - |
| 2231 | continue; | - |
| 2232 | QModelIndex index = viewItems.at(i).index; | - |
| 2233 | index = index.sibling(index.row(), column); | - |
| 2234 | QWidget *editor = d->editorForIndex(index).widget.data(); | - |
| 2235 | if (editor && d->persistent.contains(editor)) { | - |
| 2236 | w = qMax(w, editor->sizeHint().width()); | - |
| 2237 | int min = editor->minimumSize().width(); | - |
| 2238 | int max = editor->maximumSize().width(); | - |
| 2239 | w = qBound(min, w, max); | - |
| 2240 | } | - |
| 2241 | int hint = d->delegateForIndex(index)->sizeHint(option, index).width(); | - |
| 2242 | w = qMax(w, hint + (column == 0 ? d->indentationForItem(i) : 0)); | - |
| 2243 | } | - |
| 2244 | return w; | - |
| 2245 | } | - |
| 2246 | | - |
| 2247 | | - |
| 2248 | | - |
| 2249 | | - |
| 2250 | | - |
| 2251 | | - |
| 2252 | int QTreeView::indexRowSizeHint(const QModelIndex &index) const | - |
| 2253 | { | - |
| 2254 | const QTreeViewPrivate * const d = d_func(); | - |
| 2255 | if (!d->isIndexValid(index) || !d->itemDelegate) | - |
| 2256 | return 0; | - |
| 2257 | | - |
| 2258 | int start = -1; | - |
| 2259 | int end = -1; | - |
| 2260 | int indexRow = index.row(); | - |
| 2261 | int count = d->header->count(); | - |
| 2262 | bool emptyHeader = (count == 0); | - |
| 2263 | QModelIndex parent = index.parent(); | - |
| 2264 | | - |
| 2265 | if (count && isVisible()) { | - |
| 2266 | | - |
| 2267 | start = d->header->visualIndexAt(0); | - |
| 2268 | } else { | - |
| 2269 | | - |
| 2270 | count = d->model->columnCount(parent); | - |
| 2271 | } | - |
| 2272 | | - |
| 2273 | if (isRightToLeft()) { | - |
| 2274 | start = (start == -1 ? count - 1 : start); | - |
| 2275 | end = 0; | - |
| 2276 | } else { | - |
| 2277 | start = (start == -1 ? 0 : start); | - |
| 2278 | end = count - 1; | - |
| 2279 | } | - |
| 2280 | | - |
| 2281 | if (end < start) | - |
| 2282 | qSwap(end, start); | - |
| 2283 | | - |
| 2284 | int height = -1; | - |
| 2285 | QStyleOptionViewItem option = d->viewOptions(); | - |
| 2286 | | - |
| 2287 | | - |
| 2288 | | - |
| 2289 | | - |
| 2290 | | - |
| 2291 | option.rect.setWidth(-1); | - |
| 2292 | | - |
| 2293 | for (int column = start; column <= end; ++column) { | - |
| 2294 | int logicalColumn = emptyHeader ? column : d->header->logicalIndex(column); | - |
| 2295 | if (d->header->isSectionHidden(logicalColumn)) | - |
| 2296 | continue; | - |
| 2297 | QModelIndex idx = d->model->index(indexRow, logicalColumn, parent); | - |
| 2298 | if (idx.isValid()) { | - |
| 2299 | QWidget *editor = d->editorForIndex(idx).widget.data(); | - |
| 2300 | if (editor && d->persistent.contains(editor)) { | - |
| 2301 | height = qMax(height, editor->sizeHint().height()); | - |
| 2302 | int min = editor->minimumSize().height(); | - |
| 2303 | int max = editor->maximumSize().height(); | - |
| 2304 | height = qBound(min, height, max); | - |
| 2305 | } | - |
| 2306 | int hint = d->delegateForIndex(idx)->sizeHint(option, idx).height(); | - |
| 2307 | height = qMax(height, hint); | - |
| 2308 | } | - |
| 2309 | } | - |
| 2310 | | - |
| 2311 | return height; | - |
| 2312 | } | - |
| 2313 | | - |
| 2314 | | - |
| 2315 | | - |
| 2316 | | - |
| 2317 | | - |
| 2318 | | - |
| 2319 | int QTreeView::rowHeight(const QModelIndex &index) const | - |
| 2320 | { | - |
| 2321 | const QTreeViewPrivate * const d = d_func(); | - |
| 2322 | d->executePostedLayout(); | - |
| 2323 | int i = d->viewIndex(index); | - |
| 2324 | if (i == -1) | - |
| 2325 | return 0; | - |
| 2326 | return d->itemHeight(i); | - |
| 2327 | } | - |
| 2328 | | - |
| 2329 | | - |
| 2330 | | - |
| 2331 | | - |
| 2332 | void QTreeView::horizontalScrollbarAction(int action) | - |
| 2333 | { | - |
| 2334 | QAbstractItemView::horizontalScrollbarAction(action); | - |
| 2335 | } | - |
| 2336 | | - |
| 2337 | | - |
| 2338 | | - |
| 2339 | | - |
| 2340 | bool QTreeView::isIndexHidden(const QModelIndex &index) const | - |
| 2341 | { | - |
| 2342 | return (isColumnHidden(index.column()) || isRowHidden(index.row(), index.parent())); | - |
| 2343 | } | - |
| 2344 | | - |
| 2345 | | - |
| 2346 | | - |
| 2347 | | - |
| 2348 | void QTreeViewPrivate::initialize() | - |
| 2349 | { | - |
| 2350 | QTreeView * const q = q_func(); | - |
| 2351 | updateStyledFrameWidths(); | - |
| 2352 | q->setSelectionBehavior(QAbstractItemView::SelectRows); | - |
| 2353 | q->setSelectionMode(QAbstractItemView::SingleSelection); | - |
| 2354 | q->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); | - |
| 2355 | q->setAttribute(Qt::WA_MacShowFocusRect); | - |
| 2356 | | - |
| 2357 | QHeaderView *header = new QHeaderView(Qt::Horizontal, q); | - |
| 2358 | header->setSectionsMovable(true); | - |
| 2359 | header->setStretchLastSection(true); | - |
| 2360 | header->setDefaultAlignment(Qt::AlignLeft|Qt::AlignVCenter); | - |
| 2361 | q->setHeader(header); | - |
| 2362 | | - |
| 2363 | QObject::connect(&animatedOperation, "2""finished()", q, "1""_q_endAnimatedOperation()"); | - |
| 2364 | | - |
| 2365 | } | - |
| 2366 | | - |
| 2367 | void QTreeViewPrivate::expand(int item, bool emitSignal) | - |
| 2368 | { | - |
| 2369 | QTreeView * const q = q_func(); | - |
| 2370 | | - |
| 2371 | if (item == -1 || viewItems.at(item).expanded) | - |
| 2372 | return; | - |
| 2373 | | - |
| 2374 | | - |
| 2375 | if (emitSignal && animationsEnabled) | - |
| 2376 | prepareAnimatedOperation(item, QVariantAnimation::Forward); | - |
| 2377 | | - |
| 2378 | | - |
| 2379 | if (state != QAbstractItemView::AnimatingState) | - |
| 2380 | stateBeforeAnimation = state; | - |
| 2381 | q->setState(QAbstractItemView::ExpandingState); | - |
| 2382 | const QModelIndex index = viewItems.at(item).index; | - |
| 2383 | storeExpanded(index); | - |
| 2384 | viewItems[item].expanded = true; | - |
| 2385 | layout(item); | - |
| 2386 | q->setState(stateBeforeAnimation); | - |
| 2387 | | - |
| 2388 | if (model->canFetchMore(index)) | - |
| 2389 | model->fetchMore(index); | - |
| 2390 | if (emitSignal) { | - |
| 2391 | q->expanded(index); | - |
| 2392 | | - |
| 2393 | if (animationsEnabled) | - |
| 2394 | beginAnimatedOperation(); | - |
| 2395 | | - |
| 2396 | } | - |
| 2397 | } | - |
| 2398 | | - |
| 2399 | void QTreeViewPrivate::insertViewItems(int pos, int count, const QTreeViewItem &viewItem) | - |
| 2400 | { | - |
| 2401 | QTreeView * const q = q_func(); | - |
| 2402 | (void)q; | - |
| 2403 | viewItems.insert(pos, count, viewItem); | - |
| 2404 | QTreeViewItem *items = viewItems.data(); | - |
| 2405 | for (int i = pos + count; i < viewItems.count(); i++) | - |
| 2406 | if (items[i].parentItem >= pos) | - |
| 2407 | items[i].parentItem += count; | - |
| 2408 | } | - |
| 2409 | | - |
| 2410 | void QTreeViewPrivate::removeViewItems(int pos, int count) | - |
| 2411 | { | - |
| 2412 | QTreeView * const q = q_func(); | - |
| 2413 | (void)q; | - |
| 2414 | viewItems.remove(pos, count); | - |
| 2415 | QTreeViewItem *items = viewItems.data(); | - |
| 2416 | for (int i = pos; i < viewItems.count(); i++) | - |
| 2417 | if (items[i].parentItem >= pos) | - |
| 2418 | items[i].parentItem -= count; | - |
| 2419 | } | - |
| 2420 | void QTreeViewPrivate::collapse(int item, bool emitSignal) | - |
| 2421 | { | - |
| 2422 | QTreeView * const q = q_func(); | - |
| 2423 | | - |
| 2424 | if (item == -1 || expandedIndexes.isEmpty()) | - |
| 2425 | return; | - |
| 2426 | | - |
| 2427 | | - |
| 2428 | delayedAutoScroll.stop(); | - |
| 2429 | | - |
| 2430 | int total = viewItems.at(item).total; | - |
| 2431 | const QModelIndex &modelIndex = viewItems.at(item).index; | - |
| 2432 | if (!isPersistent(modelIndex)) | - |
| 2433 | return; | - |
| 2434 | QSet<QPersistentModelIndex>::iterator it = expandedIndexes.find(modelIndex); | - |
| 2435 | if (it == expandedIndexes.end() || viewItems.at(item).expanded == false) | - |
| 2436 | return; | - |
| 2437 | | - |
| 2438 | | - |
| 2439 | if (emitSignal && animationsEnabled) | - |
| 2440 | prepareAnimatedOperation(item, QVariantAnimation::Backward); | - |
| 2441 | | - |
| 2442 | | - |
| 2443 | | - |
| 2444 | if (state != QAbstractItemView::AnimatingState) | - |
| 2445 | stateBeforeAnimation = state; | - |
| 2446 | q->setState(QAbstractItemView::CollapsingState); | - |
| 2447 | expandedIndexes.erase(it); | - |
| 2448 | viewItems[item].expanded = false; | - |
| 2449 | int index = item; | - |
| 2450 | while (index > -1) { | - |
| 2451 | viewItems[index].total -= total; | - |
| 2452 | index = viewItems[index].parentItem; | - |
| 2453 | } | - |
| 2454 | removeViewItems(item + 1, total); | - |
| 2455 | q->setState(stateBeforeAnimation); | - |
| 2456 | | - |
| 2457 | if (emitSignal) { | - |
| 2458 | q->collapsed(modelIndex); | - |
| 2459 | | - |
| 2460 | if (animationsEnabled) | - |
| 2461 | beginAnimatedOperation(); | - |
| 2462 | | - |
| 2463 | } | - |
| 2464 | } | - |
| 2465 | | - |
| 2466 | | - |
| 2467 | void QTreeViewPrivate::prepareAnimatedOperation(int item, QVariantAnimation::Direction direction) | - |
| 2468 | { | - |
| 2469 | animatedOperation.item = item; | - |
| 2470 | animatedOperation.viewport = viewport; | - |
| 2471 | animatedOperation.setDirection(direction); | - |
| 2472 | | - |
| 2473 | int top = coordinateForItem(item) + itemHeight(item); | - |
| 2474 | QRect rect = viewport->rect(); | - |
| 2475 | rect.setTop(top); | - |
| 2476 | if (direction == QVariantAnimation::Backward) { | - |
| 2477 | const int limit = rect.height() * 2; | - |
| 2478 | int h = 0; | - |
| 2479 | int c = item + viewItems.at(item).total + 1; | - |
| 2480 | for (int i = item + 1; i < c && h < limit; ++i) | - |
| 2481 | h += itemHeight(i); | - |
| 2482 | rect.setHeight(h); | - |
| 2483 | animatedOperation.setEndValue(top + h); | - |
| 2484 | } | - |
| 2485 | animatedOperation.setStartValue(top); | - |
| 2486 | animatedOperation.before = renderTreeToPixmapForAnimation(rect); | - |
| 2487 | } | - |
| 2488 | | - |
| 2489 | void QTreeViewPrivate::beginAnimatedOperation() | - |
| 2490 | { | - |
| 2491 | QTreeView * const q = q_func(); | - |
| 2492 | | - |
| 2493 | QRect rect = viewport->rect(); | - |
| 2494 | rect.setTop(animatedOperation.top()); | - |
| 2495 | if (animatedOperation.direction() == QVariantAnimation::Forward) { | - |
| 2496 | const int limit = rect.height() * 2; | - |
| 2497 | int h = 0; | - |
| 2498 | int c = animatedOperation.item + viewItems.at(animatedOperation.item).total + 1; | - |
| 2499 | for (int i = animatedOperation.item + 1; i < c && h < limit; ++i) | - |
| 2500 | h += itemHeight(i); | - |
| 2501 | rect.setHeight(h); | - |
| 2502 | animatedOperation.setEndValue(animatedOperation.top() + h); | - |
| 2503 | } | - |
| 2504 | | - |
| 2505 | if (!rect.isEmpty()) { | - |
| 2506 | animatedOperation.after = renderTreeToPixmapForAnimation(rect); | - |
| 2507 | | - |
| 2508 | q->setState(QAbstractItemView::AnimatingState); | - |
| 2509 | animatedOperation.start(); | - |
| 2510 | } | - |
| 2511 | } | - |
| 2512 | | - |
| 2513 | void QTreeViewPrivate::drawAnimatedOperation(QPainter *painter) const | - |
| 2514 | { | - |
| 2515 | const int start = animatedOperation.startValue().toInt(), | - |
| 2516 | end = animatedOperation.endValue().toInt(), | - |
| 2517 | current = animatedOperation.currentValue().toInt(); | - |
| 2518 | bool collapsing = animatedOperation.direction() == QVariantAnimation::Backward; | - |
| 2519 | const QPixmap top = collapsing ? animatedOperation.before : animatedOperation.after; | - |
| 2520 | painter->drawPixmap(0, start, top, 0, end - current - 1, top.width(), top.height()); | - |
| 2521 | const QPixmap bottom = collapsing ? animatedOperation.after : animatedOperation.before; | - |
| 2522 | painter->drawPixmap(0, current, bottom); | - |
| 2523 | } | - |
| 2524 | | - |
| 2525 | QPixmap QTreeViewPrivate::renderTreeToPixmapForAnimation(const QRect &rect) const | - |
| 2526 | { | - |
| 2527 | const QTreeView * const q = q_func(); | - |
| 2528 | QPixmap pixmap(rect.size()); | - |
| 2529 | if (rect.size().isEmpty()) | - |
| 2530 | return pixmap; | - |
| 2531 | pixmap.fill(Qt::transparent); | - |
| 2532 | QPainter painter(&pixmap); | - |
| 2533 | painter.fillRect(QRect(QPoint(0,0), rect.size()), q->palette().base()); | - |
| 2534 | painter.translate(0, -rect.top()); | - |
| 2535 | q->drawTree(&painter, QRegion(rect)); | - |
| 2536 | painter.end(); | - |
| 2537 | | - |
| 2538 | | - |
| 2539 | QStyleOptionViewItem option = viewOptions(); | - |
| 2540 | for (QEditorIndexHash::const_iterator it = editorIndexHash.constBegin(); it != editorIndexHash.constEnd(); ++it) { | - |
| 2541 | QWidget *editor = it.key(); | - |
| 2542 | const QModelIndex &index = it.value(); | - |
| 2543 | option.rect = q->visualRect(index); | - |
| 2544 | if (option.rect.isValid()) { | - |
| 2545 | | - |
| 2546 | if (QAbstractItemDelegate *delegate = delegateForIndex(index)) | - |
| 2547 | delegate->updateEditorGeometry(editor, option, index); | - |
| 2548 | | - |
| 2549 | const QPoint pos = editor->pos(); | - |
| 2550 | if (rect.contains(pos)) { | - |
| 2551 | editor->render(&pixmap, pos - rect.topLeft()); | - |
| 2552 | | - |
| 2553 | | - |
| 2554 | editor->hide(); | - |
| 2555 | } | - |
| 2556 | } | - |
| 2557 | } | - |
| 2558 | | - |
| 2559 | | - |
| 2560 | return pixmap; | - |
| 2561 | } | - |
| 2562 | | - |
| 2563 | void QTreeViewPrivate::_q_endAnimatedOperation() | - |
| 2564 | { | - |
| 2565 | QTreeView * const q = q_func(); | - |
| 2566 | q->setState(stateBeforeAnimation); | - |
| 2567 | q->updateGeometries(); | - |
| 2568 | viewport->update(); | - |
| 2569 | } | - |
| 2570 | | - |
| 2571 | | - |
| 2572 | void QTreeViewPrivate::_q_modelAboutToBeReset() | - |
| 2573 | { | - |
| 2574 | viewItems.clear(); | - |
| 2575 | } | - |
| 2576 | | - |
| 2577 | void QTreeViewPrivate::_q_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end) | - |
| 2578 | { | - |
| 2579 | if (start <= 0 && 0 <= end) | - |
| 2580 | viewItems.clear(); | - |
| 2581 | QAbstractItemViewPrivate::_q_columnsAboutToBeRemoved(parent, start, end); | - |
| 2582 | } | - |
| 2583 | | - |
| 2584 | void QTreeViewPrivate::_q_columnsRemoved(const QModelIndex &parent, int start, int end) | - |
| 2585 | { | - |
| 2586 | if (start <= 0 && 0 <= end) | - |
| 2587 | doDelayedItemsLayout(); | - |
| 2588 | QAbstractItemViewPrivate::_q_columnsRemoved(parent, start, end); | - |
| 2589 | } | - |
| 2590 | void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninitialized) | - |
| 2591 | { | - |
| 2592 | QTreeView * const q = q_func(); | - |
| 2593 | QModelIndex current; | - |
| 2594 | QModelIndex parent = (i < 0) ? (QModelIndex)root : modelIndex(i); | - |
| 2595 | | - |
| 2596 | if (i>=0 && !parent.isValid()) { | - |
| 2597 | | - |
| 2598 | | - |
| 2599 | | - |
| 2600 | return; | - |
| 2601 | } | - |
| 2602 | | - |
| 2603 | int count = 0; | - |
| 2604 | if (model->hasChildren(parent)) { | - |
| 2605 | if (model->canFetchMore(parent)) | - |
| 2606 | model->fetchMore(parent); | - |
| 2607 | count = model->rowCount(parent); | - |
| 2608 | } | - |
| 2609 | | - |
| 2610 | bool expanding = true; | - |
| 2611 | if (i == -1) { | - |
| 2612 | if (uniformRowHeights) { | - |
| 2613 | QModelIndex index = model->index(0, 0, parent); | - |
| 2614 | defaultItemHeight = q->indexRowSizeHint(index); | - |
| 2615 | } | - |
| 2616 | viewItems.resize(count); | - |
| 2617 | afterIsUninitialized = true; | - |
| 2618 | } else if (viewItems[i].total != (uint)count) { | - |
| 2619 | if (!afterIsUninitialized) | - |
| 2620 | insertViewItems(i + 1, count, QTreeViewItem()); | - |
| 2621 | else if (count > 0) | - |
| 2622 | viewItems.resize(viewItems.count() + count); | - |
| 2623 | } else { | - |
| 2624 | expanding = false; | - |
| 2625 | } | - |
| 2626 | | - |
| 2627 | int first = i + 1; | - |
| 2628 | int level = (i >= 0 ? viewItems.at(i).level + 1 : 0); | - |
| 2629 | int hidden = 0; | - |
| 2630 | int last = 0; | - |
| 2631 | int children = 0; | - |
| 2632 | QTreeViewItem *item = 0; | - |
| 2633 | for (int j = first; j < first + count; ++j) { | - |
| 2634 | current = model->index(j - first, 0, parent); | - |
| 2635 | if (isRowHidden(current)) { | - |
| 2636 | ++hidden; | - |
| 2637 | last = j - hidden + children; | - |
| 2638 | } else { | - |
| 2639 | last = j - hidden + children; | - |
| 2640 | if (item) | - |
| 2641 | item->hasMoreSiblings = true; | - |
| 2642 | item = &viewItems[last]; | - |
| 2643 | item->index = current; | - |
| 2644 | item->parentItem = i; | - |
| 2645 | item->level = level; | - |
| 2646 | item->height = 0; | - |
| 2647 | item->spanning = q->isFirstColumnSpanned(current.row(), parent); | - |
| 2648 | item->expanded = false; | - |
| 2649 | item->total = 0; | - |
| 2650 | item->hasMoreSiblings = false; | - |
| 2651 | if (recursiveExpanding || isIndexExpanded(current)) { | - |
| 2652 | if (recursiveExpanding) | - |
| 2653 | expandedIndexes.insert(current); | - |
| 2654 | item->expanded = true; | - |
| 2655 | layout(last, recursiveExpanding, afterIsUninitialized); | - |
| 2656 | item = &viewItems[last]; | - |
| 2657 | children += item->total; | - |
| 2658 | item->hasChildren = item->total > 0; | - |
| 2659 | last = j - hidden + children; | - |
| 2660 | } else { | - |
| 2661 | item->hasChildren = hasVisibleChildren(current); | - |
| 2662 | } | - |
| 2663 | } | - |
| 2664 | } | - |
| 2665 | | - |
| 2666 | | - |
| 2667 | if (hidden > 0) { | - |
| 2668 | if (!afterIsUninitialized) | - |
| 2669 | removeViewItems(last + 1, hidden); | - |
| 2670 | else | - |
| 2671 | viewItems.resize(viewItems.size() - hidden); | - |
| 2672 | } | - |
| 2673 | | - |
| 2674 | if (!expanding) | - |
| 2675 | return; | - |
| 2676 | | - |
| 2677 | while (i > -1) { | - |
| 2678 | viewItems[i].total += count - hidden; | - |
| 2679 | i = viewItems[i].parentItem; | - |
| 2680 | } | - |
| 2681 | } | - |
| 2682 | | - |
| 2683 | int QTreeViewPrivate::pageUp(int i) const | - |
| 2684 | { | - |
| 2685 | int index = itemAtCoordinate(coordinateForItem(i) - viewport->height()); | - |
| 2686 | while (isItemHiddenOrDisabled(index)) | - |
| 2687 | index--; | - |
| 2688 | return index == -1 ? 0 : index; | - |
| 2689 | } | - |
| 2690 | | - |
| 2691 | int QTreeViewPrivate::pageDown(int i) const | - |
| 2692 | { | - |
| 2693 | int index = itemAtCoordinate(coordinateForItem(i) + viewport->height()); | - |
| 2694 | while (isItemHiddenOrDisabled(index)) | - |
| 2695 | index++; | - |
| 2696 | return index == -1 ? viewItems.count() - 1 : index; | - |
| 2697 | } | - |
| 2698 | | - |
| 2699 | int QTreeViewPrivate::indentationForItem(int item) const | - |
| 2700 | { | - |
| 2701 | if (item < 0 || item >= viewItems.count()) | - |
| 2702 | return 0; | - |
| 2703 | int level = viewItems.at(item).level; | - |
| 2704 | if (rootDecoration) | - |
| 2705 | ++level; | - |
| 2706 | return level * indent; | - |
| 2707 | } | - |
| 2708 | | - |
| 2709 | int QTreeViewPrivate::itemHeight(int item) const | - |
| 2710 | { | - |
| 2711 | if (uniformRowHeights) | - |
| 2712 | return defaultItemHeight; | - |
| 2713 | if (viewItems.isEmpty()) | - |
| 2714 | return 0; | - |
| 2715 | const QModelIndex &index = viewItems.at(item).index; | - |
| 2716 | if (!index.isValid()) | - |
| 2717 | return 0; | - |
| 2718 | int height = viewItems.at(item).height; | - |
| 2719 | if (height <= 0) { | - |
| 2720 | height = q_func()->indexRowSizeHint(index); | - |
| 2721 | viewItems[item].height = height; | - |
| 2722 | } | - |
| 2723 | return qMax(height, 0); | - |
| 2724 | } | - |
| 2725 | | - |
| 2726 | | - |
| 2727 | | - |
| 2728 | | - |
| 2729 | | - |
| 2730 | | - |
| 2731 | int QTreeViewPrivate::coordinateForItem(int item) const | - |
| 2732 | { | - |
| 2733 | if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) { | - |
| 2734 | if (uniformRowHeights) | - |
| 2735 | return (item * defaultItemHeight) - vbar->value(); | - |
| 2736 | | - |
| 2737 | int y = 0; | - |
| 2738 | for (int i = 0; i < viewItems.count(); ++i) { | - |
| 2739 | if (i == item) | - |
| 2740 | return y - vbar->value(); | - |
| 2741 | y += itemHeight(i); | - |
| 2742 | } | - |
| 2743 | } else { | - |
| 2744 | int topViewItemIndex = vbar->value(); | - |
| 2745 | if (uniformRowHeights) | - |
| 2746 | return defaultItemHeight * (item - topViewItemIndex); | - |
| 2747 | if (item >= topViewItemIndex) { | - |
| 2748 | | - |
| 2749 | | - |
| 2750 | int viewItemCoordinate = 0; | - |
| 2751 | int viewItemIndex = topViewItemIndex; | - |
| 2752 | while (viewItemIndex < viewItems.count()) { | - |
| 2753 | if (viewItemIndex == item) | - |
| 2754 | return viewItemCoordinate; | - |
| 2755 | viewItemCoordinate += itemHeight(viewItemIndex); | - |
| 2756 | ++viewItemIndex; | - |
| 2757 | } | - |
| 2758 | | - |
| 2759 | qt_noop(); | - |
| 2760 | return viewItemCoordinate; | - |
| 2761 | } else { | - |
| 2762 | | - |
| 2763 | int viewItemCoordinate = 0; | - |
| 2764 | for (int viewItemIndex = topViewItemIndex; viewItemIndex > 0; --viewItemIndex) { | - |
| 2765 | if (viewItemIndex == item) | - |
| 2766 | return viewItemCoordinate; | - |
| 2767 | viewItemCoordinate -= itemHeight(viewItemIndex - 1); | - |
| 2768 | } | - |
| 2769 | return viewItemCoordinate; | - |
| 2770 | } | - |
| 2771 | } | - |
| 2772 | return 0; | - |
| 2773 | } | - |
| 2774 | int QTreeViewPrivate::itemAtCoordinate(int coordinate) const | - |
| 2775 | { | - |
| 2776 | const int itemCount = viewItems.count(); | - |
| 2777 | if (itemCount == 0) | - |
| 2778 | return -1; | - |
| 2779 | if (uniformRowHeights && defaultItemHeight <= 0) | - |
| 2780 | return -1; | - |
| 2781 | if (verticalScrollMode == QAbstractItemView::ScrollPerPixel) { | - |
| 2782 | if (uniformRowHeights) { | - |
| 2783 | const int viewItemIndex = (coordinate + vbar->value()) / defaultItemHeight; | - |
| 2784 | return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex); | - |
| 2785 | } | - |
| 2786 | | - |
| 2787 | int viewItemCoordinate = 0; | - |
| 2788 | const int contentsCoordinate = coordinate + vbar->value(); | - |
| 2789 | for (int viewItemIndex = 0; viewItemIndex < viewItems.count(); ++viewItemIndex) { | - |
| 2790 | viewItemCoordinate += itemHeight(viewItemIndex); | - |
| 2791 | if (viewItemCoordinate >= contentsCoordinate) | - |
| 2792 | return (viewItemIndex >= itemCount ? -1 : viewItemIndex); | - |
| 2793 | } | - |
| 2794 | } else { | - |
| 2795 | int topViewItemIndex = vbar->value(); | - |
| 2796 | if (uniformRowHeights) { | - |
| 2797 | if (coordinate < 0) | - |
| 2798 | coordinate -= defaultItemHeight - 1; | - |
| 2799 | const int viewItemIndex = topViewItemIndex + (coordinate / defaultItemHeight); | - |
| 2800 | return ((viewItemIndex >= itemCount || viewItemIndex < 0) ? -1 : viewItemIndex); | - |
| 2801 | } | - |
| 2802 | if (coordinate >= 0) { | - |
| 2803 | | - |
| 2804 | int viewItemCoordinate = 0; | - |
| 2805 | for (int viewItemIndex = topViewItemIndex; viewItemIndex < viewItems.count(); ++viewItemIndex) { | - |
| 2806 | viewItemCoordinate += itemHeight(viewItemIndex); | - |
| 2807 | if (viewItemCoordinate > coordinate) | - |
| 2808 | return (viewItemIndex >= itemCount ? -1 : viewItemIndex); | - |
| 2809 | } | - |
| 2810 | } else { | - |
| 2811 | | - |
| 2812 | int viewItemCoordinate = 0; | - |
| 2813 | for (int viewItemIndex = topViewItemIndex; viewItemIndex >= 0; --viewItemIndex) { | - |
| 2814 | if (viewItemCoordinate <= coordinate) | - |
| 2815 | return (viewItemIndex >= itemCount ? -1 : viewItemIndex); | - |
| 2816 | viewItemCoordinate -= itemHeight(viewItemIndex); | - |
| 2817 | } | - |
| 2818 | } | - |
| 2819 | } | - |
| 2820 | return -1; | - |
| 2821 | } | - |
| 2822 | | - |
| 2823 | int QTreeViewPrivate::viewIndex(const QModelIndex &_index) const | - |
| 2824 | { | - |
| 2825 | if (!_index.isValid() || viewItems.isEmpty()) | - |
| 2826 | return -1; | - |
| 2827 | | - |
| 2828 | const int totalCount = viewItems.count(); | - |
| 2829 | const QModelIndex index = _index.sibling(_index.row(), 0); | - |
| 2830 | const int row = index.row(); | - |
| 2831 | const quintptr internalId = index.internalId(); | - |
| 2832 | | - |
| 2833 | | - |
| 2834 | int localCount = qMin(lastViewedItem - 1, totalCount - lastViewedItem); | - |
| 2835 | for (int i = 0; i < localCount; ++i) { | - |
| 2836 | const QModelIndex &idx1 = viewItems.at(lastViewedItem + i).index; | - |
| 2837 | if (idx1.row() == row && idx1.internalId() == internalId) { | - |
| 2838 | lastViewedItem = lastViewedItem + i; | - |
| 2839 | return lastViewedItem; | - |
| 2840 | } | - |
| 2841 | const QModelIndex &idx2 = viewItems.at(lastViewedItem - i - 1).index; | - |
| 2842 | if (idx2.row() == row && idx2.internalId() == internalId) { | - |
| 2843 | lastViewedItem = lastViewedItem - i - 1; | - |
| 2844 | return lastViewedItem; | - |
| 2845 | } | - |
| 2846 | } | - |
| 2847 | | - |
| 2848 | for (int j = qMax(0, lastViewedItem + localCount); j < totalCount; ++j) { | - |
| 2849 | const QModelIndex &idx = viewItems.at(j).index; | - |
| 2850 | if (idx.row() == row && idx.internalId() == internalId) { | - |
| 2851 | lastViewedItem = j; | - |
| 2852 | return j; | - |
| 2853 | } | - |
| 2854 | } | - |
| 2855 | for (int j = qMin(totalCount, lastViewedItem - localCount) - 1; j >= 0; --j) { | - |
| 2856 | const QModelIndex &idx = viewItems.at(j).index; | - |
| 2857 | if (idx.row() == row && idx.internalId() == internalId) { | - |
| 2858 | lastViewedItem = j; | - |
| 2859 | return j; | - |
| 2860 | } | - |
| 2861 | } | - |
| 2862 | | - |
| 2863 | | - |
| 2864 | return -1; | - |
| 2865 | } | - |
| 2866 | | - |
| 2867 | QModelIndex QTreeViewPrivate::modelIndex(int i, int column) const | - |
| 2868 | { | - |
| 2869 | if (i < 0 || i >= viewItems.count()) | - |
| 2870 | return QModelIndex(); | - |
| 2871 | | - |
| 2872 | QModelIndex ret = viewItems.at(i).index; | - |
| 2873 | if (column) | - |
| 2874 | ret = ret.sibling(ret.row(), column); | - |
| 2875 | return ret; | - |
| 2876 | } | - |
| 2877 | | - |
| 2878 | int QTreeViewPrivate::firstVisibleItem(int *offset) const | - |
| 2879 | { | - |
| 2880 | const int value = vbar->value(); | - |
| 2881 | if (verticalScrollMode == QAbstractItemView::ScrollPerItem) { | - |
| 2882 | if (offset) | - |
| 2883 | *offset = 0; | - |
| 2884 | return (value < 0 || value >= viewItems.count()) ? -1 : value; | - |
| 2885 | } | - |
| 2886 | | - |
| 2887 | if (uniformRowHeights) { | - |
| 2888 | if (!defaultItemHeight) | - |
| 2889 | return -1; | - |
| 2890 | | - |
| 2891 | if (offset) | - |
| 2892 | *offset = -(value % defaultItemHeight); | - |
| 2893 | return value / defaultItemHeight; | - |
| 2894 | } | - |
| 2895 | int y = 0; | - |
| 2896 | for (int i = 0; i < viewItems.count(); ++i) { | - |
| 2897 | y += itemHeight(i); | - |
| 2898 | if (y > value) { | - |
| 2899 | if (offset) | - |
| 2900 | *offset = y - value - itemHeight(i); | - |
| 2901 | return i; | - |
| 2902 | } | - |
| 2903 | } | - |
| 2904 | return -1; | - |
| 2905 | } | - |
| 2906 | | - |
| 2907 | int QTreeViewPrivate::columnAt(int x) const | - |
| 2908 | { | - |
| 2909 | return header->logicalIndexAt(x); | - |
| 2910 | } | - |
| 2911 | | - |
| 2912 | void QTreeViewPrivate::updateScrollBars() | - |
| 2913 | { | - |
| 2914 | QTreeView * const q = q_func(); | - |
| 2915 | QSize viewportSize = viewport->size(); | - |
| 2916 | if (!viewportSize.isValid()) | - |
| 2917 | viewportSize = QSize(0, 0); | - |
| 2918 | | - |
| 2919 | if (viewItems.isEmpty()) { | - |
| 2920 | q->doItemsLayout(); | - |
| 2921 | } | - |
| 2922 | | - |
| 2923 | int itemsInViewport = 0; | - |
| 2924 | if (uniformRowHeights) { | - |
| 2925 | if (defaultItemHeight <= 0) | - |
| 2926 | itemsInViewport = viewItems.count(); | - |
| 2927 | else | - |
| 2928 | itemsInViewport = viewportSize.height() / defaultItemHeight; | - |
| 2929 | } else { | - |
| 2930 | const int itemsCount = viewItems.count(); | - |
| 2931 | const int viewportHeight = viewportSize.height(); | - |
| 2932 | for (int height = 0, item = itemsCount - 1; item >= 0; --item) { | - |
| 2933 | height += itemHeight(item); | - |
| 2934 | if (height > viewportHeight) | - |
| 2935 | break; | - |
| 2936 | ++itemsInViewport; | - |
| 2937 | } | - |
| 2938 | } | - |
| 2939 | if (verticalScrollMode == QAbstractItemView::ScrollPerItem) { | - |
| 2940 | if (!viewItems.isEmpty()) | - |
| 2941 | itemsInViewport = qMax(1, itemsInViewport); | - |
| 2942 | vbar->setRange(0, viewItems.count() - itemsInViewport); | - |
| 2943 | vbar->setPageStep(itemsInViewport); | - |
| 2944 | vbar->setSingleStep(1); | - |
| 2945 | } else { | - |
| 2946 | int contentsHeight = 0; | - |
| 2947 | if (uniformRowHeights) { | - |
| 2948 | contentsHeight = defaultItemHeight * viewItems.count(); | - |
| 2949 | } else { | - |
| 2950 | for (int i = 0; i < viewItems.count(); ++i) | - |
| 2951 | contentsHeight += itemHeight(i); | - |
| 2952 | } | - |
| 2953 | vbar->setRange(0, contentsHeight - viewportSize.height()); | - |
| 2954 | vbar->setPageStep(viewportSize.height()); | - |
| 2955 | vbar->setSingleStep(qMax(viewportSize.height() / (itemsInViewport + 1), 2)); | - |
| 2956 | } | - |
| 2957 | | - |
| 2958 | const int columnCount = header->count(); | - |
| 2959 | const int viewportWidth = viewportSize.width(); | - |
| 2960 | int columnsInViewport = 0; | - |
| 2961 | for (int width = 0, column = columnCount - 1; column >= 0; --column) { | - |
| 2962 | int logical = header->logicalIndex(column); | - |
| 2963 | width += header->sectionSize(logical); | - |
| 2964 | if (width > viewportWidth) | - |
| 2965 | break; | - |
| 2966 | ++columnsInViewport; | - |
| 2967 | } | - |
| 2968 | if (columnCount > 0) | - |
| 2969 | columnsInViewport = qMax(1, columnsInViewport); | - |
| 2970 | if (horizontalScrollMode == QAbstractItemView::ScrollPerItem) { | - |
| 2971 | hbar->setRange(0, columnCount - columnsInViewport); | - |
| 2972 | hbar->setPageStep(columnsInViewport); | - |
| 2973 | hbar->setSingleStep(1); | - |
| 2974 | } else { | - |
| 2975 | const int horizontalLength = header->length(); | - |
| 2976 | const QSize maxSize = q->maximumViewportSize(); | - |
| 2977 | if (maxSize.width() >= horizontalLength && vbar->maximum() <= 0) | - |
| 2978 | viewportSize = maxSize; | - |
| 2979 | hbar->setPageStep(viewportSize.width()); | - |
| 2980 | hbar->setRange(0, qMax(horizontalLength - viewportSize.width(), 0)); | - |
| 2981 | hbar->setSingleStep(qMax(viewportSize.width() / (columnsInViewport + 1), 2)); | - |
| 2982 | } | - |
| 2983 | } | - |
| 2984 | | - |
| 2985 | int QTreeViewPrivate::itemDecorationAt(const QPoint &pos) const | - |
| 2986 | { | - |
| 2987 | executePostedLayout(); | - |
| 2988 | int x = pos.x(); | - |
| 2989 | int column = header->logicalIndexAt(x); | - |
| 2990 | if (column != 0) | - |
| 2991 | return -1; | - |
| 2992 | | - |
| 2993 | int viewItemIndex = itemAtCoordinate(pos.y()); | - |
| 2994 | QRect returning = itemDecorationRect(modelIndex(viewItemIndex)); | - |
| 2995 | if (!returning.contains(pos)) | - |
| 2996 | return -1; | - |
| 2997 | | - |
| 2998 | return viewItemIndex; | - |
| 2999 | } | - |
| 3000 | | - |
| 3001 | QRect QTreeViewPrivate::itemDecorationRect(const QModelIndex &index) const | - |
| 3002 | { | - |
| 3003 | const QTreeView * const q = q_func(); | - |
| 3004 | if (!rootDecoration && index.parent() == root) | - |
| 3005 | return QRect(); | - |
| 3006 | | - |
| 3007 | int viewItemIndex = viewIndex(index); | - |
| 3008 | if (viewItemIndex < 0 || !hasVisibleChildren(viewItems.at(viewItemIndex).index)) | - |
| 3009 | return QRect(); | - |
| 3010 | | - |
| 3011 | int itemIndentation = indentationForItem(viewItemIndex); | - |
| 3012 | int position = header->sectionViewportPosition(0); | - |
| 3013 | int size = header->sectionSize(0); | - |
| 3014 | | - |
| 3015 | QRect rect; | - |
| 3016 | if (q->isRightToLeft()) | - |
| 3017 | rect = QRect(position + size - itemIndentation, coordinateForItem(viewItemIndex), | - |
| 3018 | indent, itemHeight(viewItemIndex)); | - |
| 3019 | else | - |
| 3020 | rect = QRect(position + itemIndentation - indent, coordinateForItem(viewItemIndex), | - |
| 3021 | indent, itemHeight(viewItemIndex)); | - |
| 3022 | QStyleOption opt; | - |
| 3023 | opt.initFrom(q); | - |
| 3024 | opt.rect = rect; | - |
| 3025 | return q->style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, q); | - |
| 3026 | } | - |
| 3027 | | - |
| 3028 | QList<QPair<int, int> > QTreeViewPrivate::columnRanges(const QModelIndex &topIndex, | - |
| 3029 | const QModelIndex &bottomIndex) const | - |
| 3030 | { | - |
| 3031 | const int topVisual = header->visualIndex(topIndex.column()), | - |
| 3032 | bottomVisual = header->visualIndex(bottomIndex.column()); | - |
| 3033 | | - |
| 3034 | const int start = qMin(topVisual, bottomVisual); | - |
| 3035 | const int end = qMax(topVisual, bottomVisual); | - |
| 3036 | | - |
| 3037 | QList<int> logicalIndexes; | - |
| 3038 | | - |
| 3039 | | - |
| 3040 | for (int c = start; c <= end; c++) { | - |
| 3041 | const int logical = header->logicalIndex(c); | - |
| 3042 | if (!header->isSectionHidden(logical)) { | - |
| 3043 | logicalIndexes << logical; | - |
| 3044 | } | - |
| 3045 | } | - |
| 3046 | | - |
| 3047 | qSort(logicalIndexes.begin(), logicalIndexes.end()); | - |
| 3048 | | - |
| 3049 | QList<QPair<int, int> > ret; | - |
| 3050 | QPair<int, int> current; | - |
| 3051 | current.first = -2; | - |
| 3052 | current.second = -2; | - |
| 3053 | for(int i = 0; i < logicalIndexes.count(); ++i) { | - |
| 3054 | const int logicalColumn = logicalIndexes.at(i); | - |
| 3055 | if (current.second + 1 != logicalColumn) { | - |
| 3056 | if (current.first != -2) { | - |
| 3057 | | - |
| 3058 | ret += current; | - |
| 3059 | } | - |
| 3060 | | - |
| 3061 | current.first = current.second = logicalColumn; | - |
| 3062 | } else { | - |
| 3063 | current.second++; | - |
| 3064 | } | - |
| 3065 | } | - |
| 3066 | | - |
| 3067 | | - |
| 3068 | if (current.first != -2) { | - |
| 3069 | ret += current; | - |
| 3070 | } | - |
| 3071 | | - |
| 3072 | return ret; | - |
| 3073 | } | - |
| 3074 | | - |
| 3075 | void QTreeViewPrivate::select(const QModelIndex &topIndex, const QModelIndex &bottomIndex, | - |
| 3076 | QItemSelectionModel::SelectionFlags command) | - |
| 3077 | { | - |
| 3078 | QTreeView * const q = q_func(); | - |
| 3079 | QItemSelection selection; | - |
| 3080 | const int top = viewIndex(topIndex), | - |
| 3081 | bottom = viewIndex(bottomIndex); | - |
| 3082 | | - |
| 3083 | const QList< QPair<int, int> > colRanges = columnRanges(topIndex, bottomIndex); | - |
| 3084 | QList< QPair<int, int> >::const_iterator it; | - |
| 3085 | for (it = colRanges.begin(); it != colRanges.end(); ++it) { | - |
| 3086 | const int left = (*it).first, | - |
| 3087 | right = (*it).second; | - |
| 3088 | | - |
| 3089 | QModelIndex previous; | - |
| 3090 | QItemSelectionRange currentRange; | - |
| 3091 | QStack<QItemSelectionRange> rangeStack; | - |
| 3092 | for (int i = top; i <= bottom; ++i) { | - |
| 3093 | QModelIndex index = modelIndex(i); | - |
| 3094 | QModelIndex parent = index.parent(); | - |
| 3095 | QModelIndex previousParent = previous.parent(); | - |
| 3096 | if (previous.isValid() && parent == previousParent) { | - |
| 3097 | | - |
| 3098 | if (qAbs(previous.row() - index.row()) > 1) { | - |
| 3099 | | - |
| 3100 | if (currentRange.isValid()) { | - |
| 3101 | selection.append(currentRange); | - |
| 3102 | } | - |
| 3103 | | - |
| 3104 | currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right)); | - |
| 3105 | } else { | - |
| 3106 | QModelIndex tl = model->index(currentRange.top(), currentRange.left(), | - |
| 3107 | currentRange.parent()); | - |
| 3108 | currentRange = QItemSelectionRange(tl, index.sibling(index.row(), right)); | - |
| 3109 | } | - |
| 3110 | } else if (previous.isValid() && parent == model->index(previous.row(), 0, previousParent)) { | - |
| 3111 | | - |
| 3112 | rangeStack.push(currentRange); | - |
| 3113 | currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right)); | - |
| 3114 | } else { | - |
| 3115 | if (currentRange.isValid()) | - |
| 3116 | selection.append(currentRange); | - |
| 3117 | if (rangeStack.isEmpty()) { | - |
| 3118 | currentRange = QItemSelectionRange(index.sibling(index.row(), left), index.sibling(index.row(), right)); | - |
| 3119 | } else { | - |
| 3120 | currentRange = rangeStack.pop(); | - |
| 3121 | index = currentRange.bottomRight(); | - |
| 3122 | --i; | - |
| 3123 | } | - |
| 3124 | } | - |
| 3125 | previous = index; | - |
| 3126 | } | - |
| 3127 | if (currentRange.isValid()) | - |
| 3128 | selection.append(currentRange); | - |
| 3129 | for (int i = 0; i < rangeStack.count(); ++i) | - |
| 3130 | selection.append(rangeStack.at(i)); | - |
| 3131 | } | - |
| 3132 | q->selectionModel()->select(selection, command); | - |
| 3133 | } | - |
| 3134 | | - |
| 3135 | QPair<int,int> QTreeViewPrivate::startAndEndColumns(const QRect &rect) const | - |
| 3136 | { | - |
| 3137 | const QTreeView * const q = q_func(); | - |
| 3138 | int start = header->visualIndexAt(rect.left()); | - |
| 3139 | int end = header->visualIndexAt(rect.right()); | - |
| 3140 | if (q->isRightToLeft()) { | - |
| 3141 | start = (start == -1 ? header->count() - 1 : start); | - |
| 3142 | end = (end == -1 ? 0 : end); | - |
| 3143 | } else { | - |
| 3144 | start = (start == -1 ? 0 : start); | - |
| 3145 | end = (end == -1 ? header->count() - 1 : end); | - |
| 3146 | } | - |
| 3147 | return qMakePair<int,int>(qMin(start, end), qMax(start, end)); | - |
| 3148 | } | - |
| 3149 | | - |
| 3150 | bool QTreeViewPrivate::hasVisibleChildren(const QModelIndex& parent) const | - |
| 3151 | { | - |
| 3152 | const QTreeView * const q = q_func(); | - |
| 3153 | if (model->hasChildren(parent)) { | - |
| 3154 | if (hiddenIndexes.isEmpty()) | - |
| 3155 | return true; | - |
| 3156 | if (q->isIndexHidden(parent)) | - |
| 3157 | return false; | - |
| 3158 | int rowCount = model->rowCount(parent); | - |
| 3159 | for (int i = 0; i < rowCount; ++i) { | - |
| 3160 | if (!q->isRowHidden(i, parent)) | - |
| 3161 | return true; | - |
| 3162 | } | - |
| 3163 | if (rowCount == 0) | - |
| 3164 | return true; | - |
| 3165 | } | - |
| 3166 | return false; | - |
| 3167 | } | - |
| 3168 | | - |
| 3169 | void QTreeViewPrivate::_q_sortIndicatorChanged(int column, Qt::SortOrder order) | - |
| 3170 | { | - |
| 3171 | model->sort(column, order); | - |
| 3172 | } | - |
| 3173 | | - |
| 3174 | | - |
| 3175 | | - |
| 3176 | | - |
| 3177 | void QTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) | - |
| 3178 | { | - |
| 3179 | QAbstractItemView::currentChanged(current, previous); | - |
| 3180 | | - |
| 3181 | if (allColumnsShowFocus()) { | - |
| 3182 | if (previous.isValid()) { | - |
| 3183 | QRect previousRect = visualRect(previous); | - |
| 3184 | previousRect.setX(0); | - |
| 3185 | previousRect.setWidth(viewport()->width()); | - |
| 3186 | viewport()->update(previousRect); | - |
| 3187 | } | - |
| 3188 | if (current.isValid()) { | - |
| 3189 | QRect currentRect = visualRect(current); | - |
| 3190 | currentRect.setX(0); | - |
| 3191 | currentRect.setWidth(viewport()->width()); | - |
| 3192 | viewport()->update(currentRect); | - |
| 3193 | } | - |
| 3194 | } | - |
| 3195 | | - |
| 3196 | if (QAccessible::isActive() && current.isValid()) { | - |
| 3197 | int entry = (visualIndex(current) + (header()?1:0))*current.model()->columnCount()+current.column(); | - |
| 3198 | QAccessibleEvent event(this, QAccessible::Focus); | - |
| 3199 | event.setChild(entry); | - |
| 3200 | QAccessible::updateAccessibility(&event); | - |
| 3201 | } | - |
| 3202 | | - |
| 3203 | } | - |
| 3204 | | - |
| 3205 | | - |
| 3206 | | - |
| 3207 | | - |
| 3208 | void QTreeView::selectionChanged(const QItemSelection &selected, | - |
| 3209 | const QItemSelection &deselected) | - |
| 3210 | { | - |
| 3211 | QAbstractItemView::selectionChanged(selected, deselected); | - |
| 3212 | | - |
| 3213 | if (QAccessible::isActive()) { | - |
| 3214 | | - |
| 3215 | QModelIndex sel = selected.indexes().value(0); | - |
| 3216 | if (sel.isValid()) { | - |
| 3217 | int entry = (visualIndex(sel) + (header()?1:0))*sel.model()->columnCount()+sel.column(); | - |
| 3218 | qt_noop(); | - |
| 3219 | QAccessibleEvent event(this, QAccessible::Selection); | - |
| 3220 | event.setChild(entry); | - |
| 3221 | QAccessible::updateAccessibility(&event); | - |
| 3222 | } | - |
| 3223 | QModelIndex desel = deselected.indexes().value(0); | - |
| 3224 | if (desel.isValid()) { | - |
| 3225 | int entry = (visualIndex(desel) + (header()?1:0))*desel.model()->columnCount()+desel.column(); | - |
| 3226 | qt_noop(); | - |
| 3227 | QAccessibleEvent event(this, QAccessible::SelectionRemove); | - |
| 3228 | event.setChild(entry); | - |
| 3229 | QAccessible::updateAccessibility(&event); | - |
| 3230 | } | - |
| 3231 | } | - |
| 3232 | | - |
| 3233 | } | - |
| 3234 | | - |
| 3235 | int QTreeView::visualIndex(const QModelIndex &index) const | - |
| 3236 | { | - |
| 3237 | const QTreeViewPrivate * const d = d_func(); | - |
| 3238 | d->executePostedLayout(); | - |
| 3239 | return d->viewIndex(index); | - |
| 3240 | } | - |
| 3241 | | - |
| 3242 | | - |
| 3243 | | - |
| 3244 | | - |
| | |