mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
Clang-format (#3028)
* 1/3 Add .clang-format file and travis compilation check * 2/3 Run clang-format * 3/3 Fix compilation problems due to include reordering * 3bis/3 AfterControlStatement: false
This commit is contained in:
parent
8dbdd24c8e
commit
b29bd9e070
272 changed files with 13378 additions and 9535 deletions
|
|
@ -3,14 +3,25 @@
|
|||
#include "pixmapgenerator.h"
|
||||
#include "settingscache.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QIcon>
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
|
||||
enum GameListColumn {ROOM, CREATED, DESCRIPTION, CREATOR, GAME_TYPE, RESTRICTIONS, PLAYERS, SPECTATORS};
|
||||
enum GameListColumn
|
||||
{
|
||||
ROOM,
|
||||
CREATED,
|
||||
DESCRIPTION,
|
||||
CREATOR,
|
||||
GAME_TYPE,
|
||||
RESTRICTIONS,
|
||||
PLAYERS,
|
||||
SPECTATORS
|
||||
};
|
||||
|
||||
const QString GamesModel::getGameCreatedString(const int secs) const {
|
||||
const QString GamesModel::getGameCreatedString(const int secs) const
|
||||
{
|
||||
|
||||
QString ret;
|
||||
if (secs < SECS_PER_MIN * 2) // for first min we display "New"
|
||||
|
|
@ -48,7 +59,7 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
const ServerInfo_Game &g = gameList[index.row()];
|
||||
switch (index.column()) {
|
||||
case ROOM:
|
||||
case ROOM:
|
||||
return rooms.value(g.room_id());
|
||||
case CREATED: {
|
||||
QDateTime then;
|
||||
|
|
@ -56,113 +67,119 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
|||
int secs = then.secsTo(QDateTime::currentDateTime());
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole: return getGameCreatedString(secs);
|
||||
case SORT_ROLE: return QVariant(secs);
|
||||
case Qt::TextAlignmentRole: return Qt::AlignCenter;
|
||||
default: return QVariant();
|
||||
case Qt::DisplayRole:
|
||||
return getGameCreatedString(secs);
|
||||
case SORT_ROLE:
|
||||
return QVariant(secs);
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
case DESCRIPTION:
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return QString::fromStdString(g.description());
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case DESCRIPTION:
|
||||
switch (role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return QString::fromStdString(g.description());
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case CREATOR: {
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return QString::fromStdString(g.creator_info().name());
|
||||
case Qt::DecorationRole: {
|
||||
QPixmap avatarPixmap = UserLevelPixmapGenerator::generatePixmap(13, (UserLevelFlags)g.creator_info().user_level(), false, QString::fromStdString(g.creator_info().privlevel()));
|
||||
switch (role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return QString::fromStdString(g.creator_info().name());
|
||||
case Qt::DecorationRole: {
|
||||
QPixmap avatarPixmap = UserLevelPixmapGenerator::generatePixmap(
|
||||
13, (UserLevelFlags)g.creator_info().user_level(), false,
|
||||
QString::fromStdString(g.creator_info().privlevel()));
|
||||
return QIcon(avatarPixmap);
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
case GAME_TYPE:
|
||||
switch (role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole: {
|
||||
QStringList result;
|
||||
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 SORT_ROLE:
|
||||
case Qt::DisplayRole: {
|
||||
QStringList result;
|
||||
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 Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case RESTRICTIONS:
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole: {
|
||||
QStringList result;
|
||||
if (g.with_password())
|
||||
result.append(tr("password"));
|
||||
if (g.only_buddies())
|
||||
result.append(tr("buddies only"));
|
||||
if (g.only_registered())
|
||||
result.append(tr("reg. users only"));
|
||||
return result.join(", ");
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case Qt::DecorationRole:{
|
||||
return g.with_password() ? QIcon(LockPixmapGenerator::generatePixmap(13)) : QVariant();
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
case RESTRICTIONS:
|
||||
switch (role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole: {
|
||||
QStringList result;
|
||||
if (g.with_password())
|
||||
result.append(tr("password"));
|
||||
if (g.only_buddies())
|
||||
result.append(tr("buddies only"));
|
||||
if (g.only_registered())
|
||||
result.append(tr("reg. users only"));
|
||||
return result.join(", ");
|
||||
}
|
||||
case Qt::DecorationRole: {
|
||||
return g.with_password() ? QIcon(LockPixmapGenerator::generatePixmap(13)) : QVariant();
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
case PLAYERS:
|
||||
switch (role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case PLAYERS:
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole:
|
||||
return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case SPECTATORS:
|
||||
switch(role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole: {
|
||||
if (g.spectators_allowed()) {
|
||||
QString result;
|
||||
result.append(QString::number(g.spectators_count()));
|
||||
|
||||
if (g.spectators_can_chat() && g.spectators_omniscient())
|
||||
{
|
||||
result.append(" (").append(tr("can chat")).append(" & ").append(tr("see hands")).append(")");
|
||||
case SPECTATORS:
|
||||
switch (role) {
|
||||
case SORT_ROLE:
|
||||
case Qt::DisplayRole: {
|
||||
if (g.spectators_allowed()) {
|
||||
QString result;
|
||||
result.append(QString::number(g.spectators_count()));
|
||||
|
||||
if (g.spectators_can_chat() && g.spectators_omniscient()) {
|
||||
result.append(" (")
|
||||
.append(tr("can chat"))
|
||||
.append(" & ")
|
||||
.append(tr("see hands"))
|
||||
.append(")");
|
||||
} else if (g.spectators_can_chat()) {
|
||||
result.append(" (").append(tr("can chat")).append(")");
|
||||
} else if (g.spectators_omniscient()) {
|
||||
result.append(" (").append(tr("can see hands")).append(")");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else if (g.spectators_can_chat())
|
||||
{
|
||||
result.append(" (").append(tr("can chat")).append(")");
|
||||
}
|
||||
else if (g.spectators_omniscient())
|
||||
{
|
||||
result.append(" (").append(tr("can see hands")).append(")");
|
||||
}
|
||||
|
||||
return result;
|
||||
return QVariant(tr("not allowed"));
|
||||
}
|
||||
return QVariant(tr("not allowed"));
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignLeft;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
default: return QVariant();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,29 +188,36 @@ QVariant GamesModel::headerData(int section, Qt::Orientation /*orientation*/, in
|
|||
if ((role != Qt::DisplayRole) && (role != Qt::TextAlignmentRole))
|
||||
return QVariant();
|
||||
switch (section) {
|
||||
case ROOM: return tr("Room");
|
||||
case CREATED: {
|
||||
switch(role) {
|
||||
case Qt::DisplayRole:
|
||||
return tr("Age");
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter;
|
||||
case ROOM:
|
||||
return tr("Room");
|
||||
case CREATED: {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return tr("Age");
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter;
|
||||
}
|
||||
}
|
||||
}
|
||||
case DESCRIPTION: return tr("Description");
|
||||
case CREATOR: return tr("Creator");
|
||||
case GAME_TYPE: return tr("Type");
|
||||
case RESTRICTIONS: return tr("Restrictions");
|
||||
case PLAYERS: {
|
||||
switch(role) {
|
||||
case Qt::DisplayRole:
|
||||
return tr("Players");
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter;
|
||||
case DESCRIPTION:
|
||||
return tr("Description");
|
||||
case CREATOR:
|
||||
return tr("Creator");
|
||||
case GAME_TYPE:
|
||||
return tr("Type");
|
||||
case RESTRICTIONS:
|
||||
return tr("Restrictions");
|
||||
case PLAYERS: {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
return tr("Players");
|
||||
case Qt::TextAlignmentRole:
|
||||
return Qt::AlignCenter;
|
||||
}
|
||||
}
|
||||
}
|
||||
case SPECTATORS: return tr("Spectators");
|
||||
default: return QVariant();
|
||||
case SPECTATORS:
|
||||
return tr("Spectators");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -213,7 +237,7 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
|
|||
endRemoveRows();
|
||||
} else {
|
||||
gameList[i].MergeFrom(game);
|
||||
emit dataChanged(index(i, 0), index(i, NUM_COLS-1));
|
||||
emit dataChanged(index(i, 0), index(i, NUM_COLS - 1));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -226,19 +250,15 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
|
|||
}
|
||||
|
||||
GamesProxyModel::GamesProxyModel(QObject *parent, bool _ownUserIsRegistered)
|
||||
: QSortFilterProxyModel(parent),
|
||||
ownUserIsRegistered(_ownUserIsRegistered),
|
||||
showBuddiesOnlyGames(false),
|
||||
unavailableGamesVisible(false),
|
||||
showPasswordProtectedGames(true),
|
||||
maxPlayersFilterMin(-1),
|
||||
maxPlayersFilterMax(-1)
|
||||
: QSortFilterProxyModel(parent), ownUserIsRegistered(_ownUserIsRegistered), showBuddiesOnlyGames(false),
|
||||
unavailableGamesVisible(false), showPasswordProtectedGames(true), maxPlayersFilterMin(-1), maxPlayersFilterMax(-1)
|
||||
{
|
||||
setSortRole(GamesModel::SORT_ROLE);
|
||||
setDynamicSortFilter(true);
|
||||
}
|
||||
|
||||
void GamesProxyModel::setShowBuddiesOnlyGames(bool _showBuddiesOnlyGames) {
|
||||
void GamesProxyModel::setShowBuddiesOnlyGames(bool _showBuddiesOnlyGames)
|
||||
{
|
||||
showBuddiesOnlyGames = _showBuddiesOnlyGames;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
|
@ -306,7 +326,7 @@ void GamesProxyModel::loadFilterParameters(const QMap<int, QString> &allGameType
|
|||
QMapIterator<int, QString> gameTypesIterator(allGameTypes);
|
||||
while (gameTypesIterator.hasNext()) {
|
||||
gameTypesIterator.next();
|
||||
if (settingsCache->gameFilters().isGameTypeEnabled(gameTypesIterator.value())){
|
||||
if (settingsCache->gameFilters().isGameTypeEnabled(gameTypesIterator.value())) {
|
||||
gameTypeFilter.insert(gameTypesIterator.key());
|
||||
}
|
||||
}
|
||||
|
|
@ -320,19 +340,19 @@ void GamesProxyModel::saveFilterParameters(const QMap<int, QString> &allGameType
|
|||
settingsCache->gameFilters().setUnavailableGamesVisible(unavailableGamesVisible);
|
||||
settingsCache->gameFilters().setShowPasswordProtectedGames(showPasswordProtectedGames);
|
||||
settingsCache->gameFilters().setGameNameFilter(gameNameFilter);
|
||||
|
||||
|
||||
QMapIterator<int, QString> gameTypeIterator(allGameTypes);
|
||||
while (gameTypeIterator.hasNext()) {
|
||||
gameTypeIterator.next();
|
||||
bool enabled = gameTypeFilter.contains(gameTypeIterator.key());
|
||||
settingsCache->gameFilters().setGameTypeEnabled(gameTypeIterator.value(),enabled);
|
||||
settingsCache->gameFilters().setGameTypeEnabled(gameTypeIterator.value(), enabled);
|
||||
}
|
||||
|
||||
settingsCache->gameFilters().setMinPlayers(maxPlayersFilterMin);
|
||||
settingsCache->gameFilters().setMaxPlayers(maxPlayersFilterMax);
|
||||
}
|
||||
|
||||
bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourceParent*/) const
|
||||
bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||
{
|
||||
GamesModel *model = qobject_cast<GamesModel *>(sourceModel());
|
||||
if (!model)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue