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