| 33 | } |
| 34 | |
| 35 | void VisualGroup::update() |
| 36 | { |
| 37 | auto temp_items = items(); |
| 38 | auto itemsPerRow = view->itemsPerRow(); |
| 39 | |
| 40 | int numRows = qMax(1, qCeil((qreal)temp_items.size() / (qreal)itemsPerRow)); |
| 41 | rows = QVector<VisualRow>(numRows); |
| 42 | |
| 43 | int maxRowHeight = 0; |
| 44 | int positionInRow = 0; |
| 45 | int currentRow = 0; |
| 46 | int offsetFromTop = 0; |
| 47 | for (auto item: temp_items) |
| 48 | { |
| 49 | if(positionInRow == itemsPerRow) |
| 50 | { |
| 51 | rows[currentRow].height = maxRowHeight; |
| 52 | rows[currentRow].top = offsetFromTop; |
| 53 | currentRow ++; |
| 54 | offsetFromTop += maxRowHeight + 5; |
| 55 | positionInRow = 0; |
| 56 | maxRowHeight = 0; |
| 57 | } |
| 58 | auto itemHeight = view->itemDelegate()->sizeHint(view->viewOptions(), item).height(); |
| 59 | if(itemHeight > maxRowHeight) |
| 60 | { |
| 61 | maxRowHeight = itemHeight; |
| 62 | } |
| 63 | rows[currentRow].items.append(item); |
| 64 | positionInRow++; |
| 65 | } |
| 66 | rows[currentRow].height = maxRowHeight; |
| 67 | rows[currentRow].top = offsetFromTop; |
| 68 | } |
| 69 | |
| 70 | QPair<int, int> VisualGroup::positionOf(const QModelIndex &index) const |
| 71 | { |
no test coverage detected