[VDE] Insert at correct index onDataChanged() instead of just appending.

Took 25 minutes

Took 3 seconds
This commit is contained in:
Lukas Brübach 2026-01-24 12:24:26 +01:00
parent ffc55aff10
commit 26e1217d0a

View file

@ -325,11 +325,22 @@ void CardGroupDisplayWidget::onDataChanged(const QModelIndex &topLeft,
indexToWidgetMap.remove(persistent);
}
} else {
// Add new widgets
int toAdd = newAmount - currentWidgetCount;
int insertBase = 0;
// Count widgets belonging to rows before this one
for (int r = 0; r < row; ++r) {
QModelIndex prevIdx = deckListModel->index(r, 0, trackedIndex);
QPersistentModelIndex prevPersistent(prevIdx);
if (indexToWidgetMap.contains(prevPersistent)) {
insertBase += indexToWidgetMap.value(prevPersistent).size();
}
}
// Insert after existing copies of this card
for (int i = 0; i < toAdd; ++i) {
addToLayout(constructWidgetForIndex(persistent));
insertIntoLayout(constructWidgetForIndex(persistent), insertBase + currentWidgetCount + i);
}
}