Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
GamesModel Class Reference

Model storing all available games for display in a QTreeView or QTableView. More...

#include <games_model.h>

Inheritance diagram for GamesModel:
[legend]
Collaboration diagram for GamesModel:
[legend]

Public Member Functions

 GamesModel (const QMap< int, QString > &_rooms, const QMap< int, GameTypeMap > &_gameTypes, QObject *parent=nullptr)
 Constructs a GamesModel.
int rowCount (const QModelIndex &parent=QModelIndex()) const override
int columnCount (const QModelIndex &=QModelIndex()) const override
QVariant data (const QModelIndex &index, int role) const override
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
const ServerInfo_Game & getGame (int row)
 Returns a reference to a specific game by row index.
void updateGameList (const ServerInfo_Game &game)
 Updates the game list with a new or updated game.
int roomColIndex ()
 Returns the index of the room column.
int startTimeColIndex ()
 Returns the index of the start time column.
const QMap< int, GameTypeMap > & getGameTypes ()
 Returns the map of game types per room.

Static Public Member Functions

static const QString getGameCreatedString (const int secs)
 Formats the game creation time into a human-readable string.

Static Public Attributes

static const int SORT_ROLE = Qt::UserRole + 1

Private Attributes

QList< ServerInfo_Game > gameList
QMap< int, QString > rooms
QMap< int, GameTypeMapgameTypes

Static Private Attributes

static const int NUM_COLS = 8

Detailed Description

Model storing all available games for display in a QTreeView or QTableView.

Provides access to game information, supports sorting by different columns, and updates when new game data is received from the server.

Constructor & Destructor Documentation

◆ GamesModel()

GamesModel::GamesModel ( const QMap< int, QString > & _rooms,
const QMap< int, GameTypeMap > & _gameTypes,
QObject * parent = nullptr )

Constructs a GamesModel.

Parameters
_roomsMapping of room IDs to room names.
_gameTypesMapping of room IDs to their available game types.
parentParent QObject.

Member Function Documentation

◆ columnCount()

int GamesModel::columnCount ( const QModelIndex & = QModelIndex()) const
inlinenodiscardoverride
Here is the caller graph for this function:

◆ data()

QVariant GamesModel::data ( const QModelIndex & index,
int role ) const
nodiscardoverride
Here is the call graph for this function:

◆ getGame()

const ServerInfo_Game & GamesModel::getGame ( int row)

Returns a reference to a specific game by row index.

Parameters
rowRow index in the table.
Returns
Reference to the ServerInfo_Game at the given row.

◆ getGameCreatedString()

const QString GamesModel::getGameCreatedString ( const int secs)
static

Formats the game creation time into a human-readable string.

Parameters
secsNumber of seconds since the game started.
Returns
Short string representing game age (e.g., "new", ">5 min", ">2 hr").
Here is the caller graph for this function:

◆ getGameTypes()

const QMap< int, GameTypeMap > & GamesModel::getGameTypes ( )
inline

Returns the map of game types per room.

◆ headerData()

QVariant GamesModel::headerData ( int section,
Qt::Orientation orientation,
int role = Qt::DisplayRole ) const
nodiscardoverride

◆ roomColIndex()

int GamesModel::roomColIndex ( )
inline

Returns the index of the room column.

◆ rowCount()

int GamesModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
inlinenodiscardoverride

◆ startTimeColIndex()

int GamesModel::startTimeColIndex ( )
inline

Returns the index of the start time column.

◆ updateGameList()

void GamesModel::updateGameList ( const ServerInfo_Game & game)

Updates the game list with a new or updated game.

Parameters
gameThe ServerInfo_Game object to add or update.

Member Data Documentation

◆ gameList

QList<ServerInfo_Game> GamesModel::gameList
private

List of games currently displayed.

◆ gameTypes

QMap<int, GameTypeMap> GamesModel::gameTypes
private

Map of room IDs to available game types.

◆ NUM_COLS

const int GamesModel::NUM_COLS = 8
staticprivate

Number of columns in the table.

◆ rooms

QMap<int, QString> GamesModel::rooms
private

Map of room IDs to room names.

◆ SORT_ROLE

const int GamesModel::SORT_ROLE = Qt::UserRole + 1
static

Role used for sorting.


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