| 50 | VisualGroup::VisualGroup(const VisualGroup* other) : view(other->view), text(other->text), collapsed(other->collapsed) {} |
| 51 | |
| 52 | void VisualGroup::update() |
| 53 | { |
| 54 | auto temp_items = items(); |
| 55 | auto itemsPerRow = view->itemsPerRow(); |
| 56 | |
| 57 | int numRows = qMax(1, qCeil((qreal)temp_items.size() / (qreal)itemsPerRow)); |
| 58 | rows = QVector<VisualRow>(numRows); |
| 59 | |
| 60 | int maxRowHeight = 0; |
| 61 | int positionInRow = 0; |
| 62 | int currentRow = 0; |
| 63 | int offsetFromTop = 0; |
| 64 | for (auto item : temp_items) { |
| 65 | if (positionInRow == itemsPerRow) { |
| 66 | rows[currentRow].height = maxRowHeight; |
| 67 | rows[currentRow].top = offsetFromTop; |
| 68 | currentRow++; |
| 69 | if (currentRow >= rows.size()) { |
| 70 | currentRow = rows.size() - 1; |
| 71 | } |
| 72 | offsetFromTop += maxRowHeight + 5; |
| 73 | positionInRow = 0; |
| 74 | maxRowHeight = 0; |
| 75 | } |
| 76 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 77 | QStyleOptionViewItem viewItemOption; |
| 78 | view->initViewItemOption(&viewItemOption); |
| 79 | #else |
| 80 | QStyleOptionViewItem viewItemOption = view->viewOptions(); |
| 81 | #endif |
| 82 | |
| 83 | auto itemHeight = view->itemDelegate()->sizeHint(viewItemOption, item).height(); |
| 84 | if (itemHeight > maxRowHeight) { |
| 85 | maxRowHeight = itemHeight; |
| 86 | } |
| 87 | rows[currentRow].items.append(item); |
| 88 | positionInRow++; |
| 89 | } |
| 90 | rows[currentRow].height = maxRowHeight; |
| 91 | rows[currentRow].top = offsetFromTop; |
| 92 | } |
| 93 | |
| 94 | QPair<int, int> VisualGroup::positionOf(const QModelIndex& index) const |
| 95 | { |
no test coverage detected