Merge pull request #5949 from ligfx/gamelistmodelupdategame

GameListModel: make UpdateGame update existing files as well
This commit is contained in:
Leo Lam 2017-08-22 21:39:29 +02:00 committed by GitHub
commit 788af71f30
2 changed files with 13 additions and 10 deletions

View file

@ -208,19 +208,22 @@ QSharedPointer<GameFile> GameListModel::GetGameFile(int index) const
return m_games[index];
}
void GameListModel::UpdateGame(QSharedPointer<GameFile> game)
void GameListModel::UpdateGame(const QSharedPointer<GameFile>& game)
{
QString path = game->GetFilePath();
int entry = FindGame(path);
if (entry < 0)
entry = m_games.size();
else
return;
beginInsertRows(QModelIndex(), entry, entry);
m_games.insert(entry, game);
int index = FindGame(path);
if (index < 0)
{
beginInsertRows(QModelIndex(), m_games.size(), m_games.size());
m_games.push_back(game);
endInsertRows();
}
else
{
m_games[index] = game;
emit dataChanged(createIndex(index, 0), createIndex(index + 1, columnCount(QModelIndex())));
}
}
void GameListModel::RemoveGame(const QString& path)

View file

@ -45,7 +45,7 @@ public:
NUM_COLS
};
void UpdateGame(QSharedPointer<GameFile> game);
void UpdateGame(const QSharedPointer<GameFile>& game);
void RemoveGame(const QString& path);
private: