Display the total number of warnings of a player in the corresponding history tab title

This commit is contained in:
Olivier Teulière 2012-04-22 22:30:53 +02:00
parent a03eaab88a
commit 917c94fd5e
3 changed files with 29 additions and 0 deletions

View file

@ -82,6 +82,16 @@ void Player::removeLastTurn()
m_history.removeLastTurn();
}
unsigned Player::getWarningsNb() const
{
unsigned total = 0;
for (unsigned i = 0; i < m_history.getSize(); ++i)
{
total += m_history.getTurn(i).getWarningsNb();
}
return total;
}
wstring Player::toString() const
{
wstring res = L"Player ";

View file

@ -79,6 +79,9 @@ public:
/// Remove last turn
void removeLastTurn();
/// Return the total number of warnings received
unsigned getWarningsNb() const;
/**************************
* Accessors for the score of the player
**************************/

View file

@ -329,6 +329,22 @@ void HistoryTabWidget::setGame(const PublicGame *iGame)
void HistoryTabWidget::refresh()
{
// Display the number of warnings between parentheses
// (only if the player got at least one warning)
if (m_game != NULL)
{
for (unsigned int i = 0; i < m_game->getNbPlayers(); ++i)
{
const Player &player = m_game->getPlayer(i);
unsigned count = player.getWarningsNb();
if (count == 0)
setTabText(i + 1, qfw(player.getName()));
else
setTabText(i + 1, QString("%1 (%2)").arg(qfw(player.getName())).arg(count));
}
}
// Propagate the refresh to the history widgets (i.e. to the tab contents)
emit refreshSignal();
}