game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
GameListModel Class Reference

#include <game_list_model.h>

Inheritance diagram for GameListModel:
Collaboration diagram for GameListModel:

Public Types

using IsRunningFn = std::function<bool(const std::string& gameId)>

Public Member Functions

 GameListModel (QObject *parent=nullptr)
 ~GameListModel () override
void clear ()
 Clear all rows.
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
Qt::ItemFlags flags (const QModelIndex &index) const override
const Game * gameAt (int row) const
 Get the Game* at a given row. Returns nullptr if out of range.
const std::vector< const Game * > & games () const
 Get the raw game list (O(1)).
int rowCount (const QModelIndex &parent=QModelIndex()) const override
int rowForGameId (const std::string &gameId) const
 O(1) gameId -> row lookup. Returns -1 if not found.
void setGames (std::vector< const Game * > games)
 Replace the model's game list in one shot.
void setIcon (const std::string &gameId, const QIcon &icon)
 Stash a pre-scaled QIcon for a given gameId.
void setIsRunningAccessor (IsRunningFn accessor)
 Install a callback the model queries to answer GameIsRunningRole.
void updateGameById (const std::string &gameId)
 Find the row for gameId and emit dataChanged for it. No-op if missing.
void updateRow (int row)
 Emit dataChanged for a single row so the delegate repaints.

Detailed Description

Definition at line 36 of file game_list_model.h.

Member Typedef Documentation

◆ IsRunningFn

using GameListModel::IsRunningFn = std::function<bool(const std::string& gameId)>

Definition at line 95 of file game_list_model.h.

Constructor & Destructor Documentation

◆ GameListModel()

GameListModel::GameListModel ( QObject * parent = nullptr)
explicit

Definition at line 17 of file game_list_model.cpp.

◆ ~GameListModel()

GameListModel::~GameListModel ( )
overridedefault

References games().

Member Function Documentation

◆ clear()

void GameListModel::clear ( )

Clear all rows.

Definition at line 33 of file game_list_model.cpp.

◆ data()

QVariant GameListModel::data ( const QModelIndex & index,
int role = Qt::DisplayRole ) const
override

Definition at line 119 of file game_list_model.cpp.

◆ flags()

Qt::ItemFlags GameListModel::flags ( const QModelIndex & index) const
override

Definition at line 112 of file game_list_model.cpp.

◆ gameAt()

const Game * GameListModel::gameAt ( int row) const

Get the Game* at a given row. Returns nullptr if out of range.

Definition at line 59 of file game_list_model.cpp.

◆ games()

const std::vector< const Game * > & GameListModel::games ( ) const
inline

Get the raw game list (O(1)).

Definition at line 56 of file game_list_model.h.

Referenced by ~GameListModel(), and setGames().

◆ rowCount()

int GameListModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
override

Definition at line 105 of file game_list_model.cpp.

◆ rowForGameId()

int GameListModel::rowForGameId ( const std::string & gameId) const

O(1) gameId -> row lookup. Returns -1 if not found.

Definition at line 53 of file game_list_model.cpp.

Referenced by setIcon(), and updateGameById().

◆ setGames()

void GameListModel::setGames ( std::vector< const Game * > games)

Replace the model's game list in one shot.

Triggers full reset. Game* pointers must remain valid until the next setGames() or clear().

Definition at line 25 of file game_list_model.cpp.

References games().

◆ setIcon()

void GameListModel::setIcon ( const std::string & gameId,
const QIcon & icon )

Stash a pre-scaled QIcon for a given gameId.

Returned via Qt::DecorationRole on the corresponding row. Takes no ownership — QIcon is implicitly shared.

Definition at line 89 of file game_list_model.cpp.

References rowForGameId().

◆ setIsRunningAccessor()

void GameListModel::setIsRunningAccessor ( IsRunningFn accessor)
inline

Install a callback the model queries to answer GameIsRunningRole.

Routing through a callback avoids a hard dependency on GameLaunchController in the model. The callback is invoked on the GUI thread during paint — keep it O(1) (map lookup).

Definition at line 101 of file game_list_model.h.

◆ updateGameById()

void GameListModel::updateGameById ( const std::string & gameId)

Find the row for gameId and emit dataChanged for it. No-op if missing.

Definition at line 78 of file game_list_model.cpp.

References rowForGameId(), and updateRow().

◆ updateRow()

void GameListModel::updateRow ( int row)

Emit dataChanged for a single row so the delegate repaints.

Use this when backing Game* data has changed but the row list hasn't.

Definition at line 70 of file game_list_model.cpp.

Referenced by updateGameById().


The documentation for this class was generated from the following files: