| 559 | } |
| 560 | |
| 561 | void RDTreeView::copySelection() |
| 562 | { |
| 563 | QModelIndexList sel = selectionModel()->selectedRows(); |
| 564 | |
| 565 | std::sort(sel.begin(), sel.end(), CompareModelIndex); |
| 566 | |
| 567 | QVector<int> widths; |
| 568 | |
| 569 | ICaptureContext *ctx = getCaptureContext(this); |
| 570 | |
| 571 | int minDepth = INT_MAX; |
| 572 | int maxDepth = 0; |
| 573 | |
| 574 | // align the copied data so that each column is the same width |
| 575 | for(QModelIndex idx : sel) |
| 576 | { |
| 577 | int colCount = model()->columnCount(idx); |
| 578 | |
| 579 | widths.resize(qMax(widths.size(), colCount)); |
| 580 | |
| 581 | for(int i = 0; i < colCount; i++) |
| 582 | { |
| 583 | QVariant var = model()->data(model()->index(idx.row(), i, idx.parent())); |
| 584 | QString text = ctx ? RichResourceTextFormat(*ctx, var) : var.toString(); |
| 585 | widths[i] = qMax(widths[i], text.count()); |
| 586 | } |
| 587 | |
| 588 | int depth = GetDepth(model(), idx); |
| 589 | |
| 590 | minDepth = qMin(minDepth, depth); |
| 591 | maxDepth = qMax(maxDepth, depth); |
| 592 | } |
| 593 | |
| 594 | // add on two characters for every depth, for indent |
| 595 | for(int &i : widths) |
| 596 | i += 2 * (maxDepth - minDepth - 1); |
| 597 | |
| 598 | // only align up to 50 characters so one really long item doesn't mess up the whole thing |
| 599 | for(int &i : widths) |
| 600 | i = qMin(50, i); |
| 601 | |
| 602 | QString clipData; |
| 603 | for(QModelIndex idx : sel) |
| 604 | { |
| 605 | int colCount = model()->columnCount(idx); |
| 606 | |
| 607 | int depth = GetDepth(model(), idx); |
| 608 | |
| 609 | QString line; |
| 610 | |
| 611 | for(int i = 0; i < colCount; i++) |
| 612 | { |
| 613 | QString format = i == 0 ? QFormatStr("%1") : QFormatStr(" %1"); |
| 614 | |
| 615 | QVariant var = model()->data(model()->index(idx.row(), i, idx.parent())); |
| 616 | QString text = ctx ? RichResourceTextFormat(*ctx, var) : var.toString(); |
| 617 | |
| 618 | if(i == 0) |
no test coverage detected