mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2025-01-08 09:18:43 +00:00
Revert back to model reset for updating the computer list
It's possible that multiple changes occur in parallel, so we can't rely on receiving them one at a time
even if the callbacks are synchronized. Handling this substantially complicates the logic such that
it's not really worth doing individual insertions and deletions anymore.
This reverts 94d821a4a9
and replaces it with a solution
that is basically the old code except that it properly handles changes to the structure of the list.
This commit is contained in:
parent
9de0c215ba
commit
0735f164a8
1 changed files with 7 additions and 24 deletions
|
@ -188,34 +188,17 @@ void ComputerModel::handleComputerStateChanged(NvComputer* computer)
|
|||
{
|
||||
QVector<NvComputer*> newComputerList = m_ComputerManager->getComputers();
|
||||
|
||||
// Check if this PC was added or moved
|
||||
int newListIndex = newComputerList.indexOf(computer);
|
||||
int oldListIndex = m_Computers.indexOf(computer);
|
||||
if (newListIndex != oldListIndex) {
|
||||
// We should never learn of a removal in this callback
|
||||
Q_ASSERT(newListIndex != -1);
|
||||
|
||||
// If the PC was present in the old list, remove it to reinsert it.
|
||||
if (oldListIndex != -1) {
|
||||
beginRemoveRows(QModelIndex(), oldListIndex, oldListIndex);
|
||||
m_Computers.remove(oldListIndex);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
// Insert the PC in the new location
|
||||
beginInsertRows(QModelIndex(), newListIndex, newListIndex);
|
||||
m_Computers.insert(newListIndex, computer);
|
||||
endInsertRows();
|
||||
// Reset the model if the structural layout of the list has changed
|
||||
if (m_Computers != newComputerList) {
|
||||
beginResetModel();
|
||||
m_Computers = newComputerList;
|
||||
endResetModel();
|
||||
}
|
||||
else {
|
||||
Q_ASSERT(oldListIndex != -1);
|
||||
|
||||
// Let the view know that this specific computer changed
|
||||
emit dataChanged(createIndex(newListIndex, 0), createIndex(newListIndex, 0));
|
||||
int index = m_Computers.indexOf(computer);
|
||||
emit dataChanged(createIndex(index, 0), createIndex(index, 0));
|
||||
}
|
||||
|
||||
// The old and new vectors should be equivalent
|
||||
Q_ASSERT(newComputerList == m_Computers);
|
||||
}
|
||||
|
||||
#include "computermodel.moc"
|
||||
|
|
Loading…
Reference in a new issue