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

Took 25 minutes

Took 3 seconds

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-01-25 22:06:06 +01:00 committed by GitHub
parent 0b4e7be596
commit 630c71f123
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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);
}
}