mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-03-21 17:55:21 -05:00
[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:
parent
0b4e7be596
commit
630c71f123
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user