27#include <QAbstractListModel>
31#include <unordered_map>
56 const std::vector<const Game*>&
games()
const
89 void setIcon(
const std::string& gameId,
const QIcon& icon);
95 using IsRunningFn = std::function<bool(
const std::string& gameId)>;
103 isRunning_ = std::move(accessor);
110 int rowCount(
const QModelIndex& parent = QModelIndex())
const override;
111 QVariant
data(
const QModelIndex& index,
int role = Qt::DisplayRole)
const override;
112 Qt::ItemFlags
flags(
const QModelIndex& index)
const override;
115 void rebuildIdIndex();
116 QVariant valueForRole(
const Game& game,
int role)
const;
118 std::vector<const Game*> games_;
119 std::unordered_map<std::string, int> idToRow_;
120 std::unordered_map<std::string, QIcon> icons_;
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
std::function< bool(const std::string &gameId)> IsRunningFn
int rowCount(const QModelIndex &parent=QModelIndex()) const override
~GameListModel() override
void setIsRunningAccessor(IsRunningFn accessor)
Install a callback the model queries to answer GameIsRunningRole.
const Game * gameAt(int row) const
Get the Game* at a given row. Returns nullptr if out of range.
void clear()
Clear all rows.
void updateRow(int row)
Emit dataChanged for a single row so the delegate repaints.
const std::vector< const Game * > & games() const
Get the raw game list (O(1)).
void updateGameById(const std::string &gameId)
Find the row for gameId and emit dataChanged for it. No-op if missing.
void setIcon(const std::string &gameId, const QIcon &icon)
Stash a pre-scaled QIcon for a given gameId.
void setGames(std::vector< const Game * > games)
Replace the model's game list in one shot.
GameListModel(QObject *parent=nullptr)
int rowForGameId(const std::string &gameId) const
O(1) gameId -> row lookup. Returns -1 if not found.
Qt::ItemFlags flags(const QModelIndex &index) const override
Complete representation of a game in the library.