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