PB: more client files compile

This commit is contained in:
Max-Wilhelm Bruker 2011-12-30 22:29:57 +01:00
parent d3b96b1a88
commit c4eb7ba6cf
18 changed files with 120 additions and 124 deletions

View file

@ -1,5 +1,6 @@
#include "gamesmodel.h"
#include "protocol_datastructures.h"
#include "pb/serverinfo_game.pb.h"
#include <QStringList>
GamesModel::GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent)
: QAbstractTableModel(parent), rooms(_rooms), gameTypes(_gameTypes)
@ -10,8 +11,6 @@ GamesModel::~GamesModel()
{
if (!gameList.isEmpty()) {
beginRemoveRows(QModelIndex(), 0, gameList.size() - 1);
for (int i = 0; i < gameList.size(); ++i)
delete gameList[i];
gameList.clear();
endRemoveRows();
}
@ -28,30 +27,29 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
if ((index.row() >= gameList.size()) || (index.column() >= columnCount()))
return QVariant();
ServerInfo_Game *g = gameList[index.row()];
const ServerInfo_Game &g = gameList[index.row()];
switch (index.column()) {
case 0: return g->getDescription();
case 1: return rooms.value(g->getRoomId());
case 2: return g->getCreatorInfo()->getName();
case 0: return QString::fromStdString(g.description());
case 1: return rooms.value(g.room_id());
case 2: return QString::fromStdString(g.creator_info().name());
case 3: {
QStringList result;
QList<GameTypeId *> gameTypeList = g->getGameTypes();
GameTypeMap gameTypeMap = gameTypes.value(g->getRoomId());
for (int i = 0; i < gameTypeList.size(); ++i)
result.append(gameTypeMap.value(gameTypeList[i]->getData()));
GameTypeMap gameTypeMap = gameTypes.value(g.room_id());
for (int i = g.game_types_size() - 1; i >= 0; --i)
result.append(gameTypeMap.value(g.game_types(i)));
return result.join(", ");
}
case 4: return g->getHasPassword() ? (g->getSpectatorsNeedPassword() ? tr("yes") : tr("yes, free for spectators")) : tr("no");
case 4: return g.with_password() ? (g.spectators_need_password() ? tr("yes") : tr("yes, free for spectators")) : tr("no");
case 5: {
QStringList result;
if (g->getOnlyBuddies())
if (g.only_buddies())
result.append(tr("buddies only"));
if (g->getOnlyRegistered())
if (g.only_registered())
result.append(tr("reg. users only"));
return result.join(", ");
}
case 6: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers());
case 7: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed"));
case 6: return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
case 7: return g.spectators_allowed() ? QVariant(g.spectators_count()) : QVariant(tr("not allowed"));
default: return QVariant();
}
}
@ -73,33 +71,27 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro
}
}
ServerInfo_Game *GamesModel::getGame(int row)
const ServerInfo_Game &GamesModel::getGame(int row)
{
Q_ASSERT(row < gameList.size());
return gameList[row];
}
void GamesModel::updateGameList(ServerInfo_Game *_game)
void GamesModel::updateGameList(const ServerInfo_Game &game)
{
QList<GameTypeId *> gameTypeList, oldGameTypeList = _game->getGameTypes();
for (int i = 0; i < oldGameTypeList.size(); ++i)
gameTypeList.append(new GameTypeId(oldGameTypeList[i]->getData()));
ServerInfo_Game *game = new ServerInfo_Game(_game->getRoomId(), _game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), _game->getStarted(), gameTypeList, new ServerInfo_User(_game->getCreatorInfo()), _game->getOnlyBuddies(), _game->getOnlyRegistered(), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount());
for (int i = 0; i < gameList.size(); i++)
if (gameList[i]->getGameId() == game->getGameId()) {
if (game->getPlayerCount() == 0) {
if (gameList[i].game_id() == game.game_id()) {
if (!game.has_player_count()) {
beginRemoveRows(QModelIndex(), i, i);
delete gameList.takeAt(i);
gameList.removeAt(i);
endRemoveRows();
} else {
delete gameList[i];
gameList[i] = game;
emit dataChanged(index(i, 0), index(i, 7));
}
return;
}
if (game->getPlayerCount() == 0)
if (game.player_count() <= 0)
return;
beginInsertRows(QModelIndex(), gameList.size(), gameList.size());
gameList.append(game);
@ -130,10 +122,10 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc
if (!model)
return false;
ServerInfo_Game *game = model->getGame(sourceRow);
if ((game->getPlayerCount() == game->getMaxPlayers()) && !fullGamesVisible)
const ServerInfo_Game &game = model->getGame(sourceRow);
if ((game.player_count() == game.max_players()) && !fullGamesVisible)
return false;
if (game->getStarted() && !runningGamesVisible)
if (game.started() && !runningGamesVisible)
return false;
return true;