mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -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
|
|
@ -17,35 +17,39 @@ CardDatabaseModel::~CardDatabaseModel()
|
|||
{
|
||||
}
|
||||
|
||||
int CardDatabaseModel::rowCount(const QModelIndex &/*parent*/) const
|
||||
int CardDatabaseModel::rowCount(const QModelIndex & /*parent*/) const
|
||||
{
|
||||
return cardList.size();
|
||||
}
|
||||
|
||||
int CardDatabaseModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
int CardDatabaseModel::columnCount(const QModelIndex & /*parent*/) const
|
||||
{
|
||||
return CARDDBMODEL_COLUMNS;
|
||||
}
|
||||
|
||||
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() ||
|
||||
index.row() >= cardList.size() ||
|
||||
index.column() >= CARDDBMODEL_COLUMNS ||
|
||||
if (!index.isValid() || index.row() >= cardList.size() || index.column() >= CARDDBMODEL_COLUMNS ||
|
||||
(role != Qt::DisplayRole && role != SortRole))
|
||||
return QVariant();
|
||||
|
||||
CardInfo *card = cardList.at(index.row());
|
||||
switch (index.column()){
|
||||
case NameColumn: return card->getName();
|
||||
case SetListColumn: return card->getSetsNames();
|
||||
case ManaCostColumn: return role == SortRole ?
|
||||
QString("%1%2").arg(card->getCmc(), 4, QChar('0')).arg(card->getManaCost()) :
|
||||
card->getManaCost();
|
||||
case CardTypeColumn: return card->getCardType();
|
||||
case PTColumn: return card->getPowTough();
|
||||
case ColorColumn: return card->getColors().join("");
|
||||
default: return QVariant();
|
||||
switch (index.column()) {
|
||||
case NameColumn:
|
||||
return card->getName();
|
||||
case SetListColumn:
|
||||
return card->getSetsNames();
|
||||
case ManaCostColumn:
|
||||
return role == SortRole ? QString("%1%2").arg(card->getCmc(), 4, QChar('0')).arg(card->getManaCost())
|
||||
: card->getManaCost();
|
||||
case CardTypeColumn:
|
||||
return card->getCardType();
|
||||
case PTColumn:
|
||||
return card->getPowTough();
|
||||
case ColorColumn:
|
||||
return card->getColors().join("");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,13 +60,20 @@ QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation,
|
|||
if (orientation != Qt::Horizontal)
|
||||
return QVariant();
|
||||
switch (section) {
|
||||
case NameColumn: return QString(tr("Name"));
|
||||
case SetListColumn: return QString(tr("Sets"));
|
||||
case ManaCostColumn: return QString(tr("Mana cost"));
|
||||
case CardTypeColumn: return QString(tr("Card type"));
|
||||
case PTColumn: return QString(tr("P/T"));
|
||||
case ColorColumn: return QString(tr("Color(s)"));
|
||||
default: return QVariant();
|
||||
case NameColumn:
|
||||
return QString(tr("Name"));
|
||||
case SetListColumn:
|
||||
return QString(tr("Sets"));
|
||||
case ManaCostColumn:
|
||||
return QString(tr("Mana cost"));
|
||||
case CardTypeColumn:
|
||||
return QString(tr("Card type"));
|
||||
case PTColumn:
|
||||
return QString(tr("P/T"));
|
||||
case ColorColumn:
|
||||
return QString(tr("Color(s)"));
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,18 +82,17 @@ void CardDatabaseModel::cardInfoChanged(CardInfo *card)
|
|||
const int row = cardList.indexOf(card);
|
||||
if (row == -1)
|
||||
return;
|
||||
|
||||
|
||||
emit dataChanged(index(row, 0), index(row, CARDDBMODEL_COLUMNS - 1));
|
||||
}
|
||||
|
||||
bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfo *card)
|
||||
{
|
||||
if(!showOnlyCardsFromEnabledSets)
|
||||
if (!showOnlyCardsFromEnabledSets)
|
||||
return true;
|
||||
|
||||
foreach(CardSet * set, card->getSets())
|
||||
{
|
||||
if(set->getEnabled())
|
||||
foreach (CardSet *set, card->getSets()) {
|
||||
if (set->getEnabled())
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -92,24 +102,21 @@ bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfo *card)
|
|||
void CardDatabaseModel::cardDatabaseEnabledSetsChanged()
|
||||
{
|
||||
// remove all the cards no more present in at least one enabled set
|
||||
foreach(CardInfo * card, cardList)
|
||||
{
|
||||
if(!checkCardHasAtLeastOneEnabledSet(card))
|
||||
foreach (CardInfo *card, cardList) {
|
||||
if (!checkCardHasAtLeastOneEnabledSet(card))
|
||||
cardRemoved(card);
|
||||
}
|
||||
|
||||
// re-check all the card currently not shown, maybe their part of a newly-enabled set
|
||||
foreach(CardInfo * card, db->getCardList())
|
||||
{
|
||||
if(!cardList.contains(card))
|
||||
foreach (CardInfo *card, db->getCardList()) {
|
||||
if (!cardList.contains(card))
|
||||
cardAdded(card);
|
||||
}
|
||||
}
|
||||
|
||||
void CardDatabaseModel::cardAdded(CardInfo *card)
|
||||
{
|
||||
if(checkCardHasAtLeastOneEnabledSet(card))
|
||||
{
|
||||
if (checkCardHasAtLeastOneEnabledSet(card)) {
|
||||
// add the card if it's present in at least one enabled set
|
||||
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
|
||||
cardList.append(card);
|
||||
|
|
@ -123,16 +130,14 @@ void CardDatabaseModel::cardRemoved(CardInfo *card)
|
|||
const int row = cardList.indexOf(card);
|
||||
if (row == -1)
|
||||
return;
|
||||
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
disconnect(card, 0, this, 0);
|
||||
cardList.removeAt(row);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent),
|
||||
isToken(ShowAll)
|
||||
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent) : QSortFilterProxyModel(parent), isToken(ShowAll)
|
||||
{
|
||||
filterTree = NULL;
|
||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
|
@ -141,17 +146,17 @@ CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
|||
loadedRowCount = 0;
|
||||
}
|
||||
|
||||
bool CardDatabaseDisplayModel::canFetchMore(const QModelIndex & index) const
|
||||
bool CardDatabaseDisplayModel::canFetchMore(const QModelIndex &index) const
|
||||
{
|
||||
return loadedRowCount < sourceModel()->rowCount(index);
|
||||
}
|
||||
|
||||
void CardDatabaseDisplayModel::fetchMore(const QModelIndex & index)
|
||||
void CardDatabaseDisplayModel::fetchMore(const QModelIndex &index)
|
||||
{
|
||||
int remainder = sourceModel()->rowCount(index) - loadedRowCount;
|
||||
int itemsToFetch = qMin(100, remainder);
|
||||
|
||||
beginInsertRows(QModelIndex(), loadedRowCount, loadedRowCount+itemsToFetch-1);
|
||||
beginInsertRows(QModelIndex(), loadedRowCount, loadedRowCount + itemsToFetch - 1);
|
||||
|
||||
loadedRowCount += itemsToFetch;
|
||||
endInsertRows();
|
||||
|
|
@ -162,13 +167,13 @@ int CardDatabaseDisplayModel::rowCount(const QModelIndex &parent) const
|
|||
return qMin(QSortFilterProxyModel::rowCount(parent), loadedRowCount);
|
||||
}
|
||||
|
||||
bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelIndex &right) const {
|
||||
bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
{
|
||||
|
||||
QString leftString = sourceModel()->data(left, CardDatabaseModel::SortRole).toString();
|
||||
QString rightString = sourceModel()->data(right, CardDatabaseModel::SortRole).toString();
|
||||
|
||||
if (!cardName.isEmpty() && left.column() == CardDatabaseModel::NameColumn)
|
||||
{
|
||||
if (!cardName.isEmpty() && left.column() == CardDatabaseModel::NameColumn) {
|
||||
bool isLeftType = leftString.startsWith(cardName, Qt::CaseInsensitive);
|
||||
bool isRightType = rightString.startsWith(cardName, Qt::CaseInsensitive);
|
||||
|
||||
|
|
@ -180,20 +185,18 @@ bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelInd
|
|||
// same checks for the right string
|
||||
if (isRightType && (!isLeftType || rightString.size() == cardName.size()))
|
||||
return false;
|
||||
}
|
||||
else if (right.column() == CardDatabaseModel::PTColumn && left.column() == CardDatabaseModel::PTColumn) {
|
||||
} else if (right.column() == CardDatabaseModel::PTColumn && left.column() == CardDatabaseModel::PTColumn) {
|
||||
QStringList leftList = leftString.split("/");
|
||||
QStringList rightList = rightString.split("/");
|
||||
|
||||
if (leftList.size() == 2 && rightList.size() == 2) {
|
||||
|
||||
//cool, have both P/T in list now
|
||||
// cool, have both P/T in list now
|
||||
int lessThanNum = lessThanNumerically(leftList.at(0), rightList.at(0));
|
||||
if (lessThanNum != 0) {
|
||||
return lessThanNum < 0;
|
||||
}
|
||||
else {
|
||||
//power equal, check toughness
|
||||
} else {
|
||||
// power equal, check toughness
|
||||
return lessThanNumerically(leftList.at(1), rightList.at(1)) < 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -201,7 +204,8 @@ bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelInd
|
|||
return QString::localeAwareCompare(leftString, rightString) < 0;
|
||||
}
|
||||
|
||||
int CardDatabaseDisplayModel::lessThanNumerically(const QString &left, const QString&right) {
|
||||
int CardDatabaseDisplayModel::lessThanNumerically(const QString &left, const QString &right)
|
||||
{
|
||||
if (left == right) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -213,15 +217,13 @@ int CardDatabaseDisplayModel::lessThanNumerically(const QString &left, const QSt
|
|||
if (okLeft && okRight) {
|
||||
if (leftNum < rightNum) {
|
||||
return -1;
|
||||
}
|
||||
else if(leftNum > rightNum){
|
||||
} else if (leftNum > rightNum) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
//try and parsing again, for weird ones like "1+*"
|
||||
// try and parsing again, for weird ones like "1+*"
|
||||
QString leftAfterNum = "";
|
||||
QString rightAfterNum = "";
|
||||
if (!okLeft) {
|
||||
|
|
@ -249,42 +251,39 @@ int CardDatabaseDisplayModel::lessThanNumerically(const QString &left, const QSt
|
|||
}
|
||||
}
|
||||
if (okLeft && okRight) {
|
||||
|
||||
|
||||
if (leftNum != rightNum) {
|
||||
//both parsed as numbers, but different number
|
||||
// both parsed as numbers, but different number
|
||||
if (leftNum < rightNum) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//both parsed, same number, but at least one has something else
|
||||
//so compare the part after the number - prefer nothing
|
||||
} else {
|
||||
// both parsed, same number, but at least one has something else
|
||||
// so compare the part after the number - prefer nothing
|
||||
return QString::localeAwareCompare(leftAfterNum, rightAfterNum);
|
||||
}
|
||||
}
|
||||
else if (okLeft) {
|
||||
} else if (okLeft) {
|
||||
return -1;
|
||||
}
|
||||
else if (okRight) {
|
||||
} else if (okRight) {
|
||||
return 1;
|
||||
}
|
||||
//couldn't parse it, just return String comparison
|
||||
// couldn't parse it, just return String comparison
|
||||
return QString::localeAwareCompare(left, right);
|
||||
}
|
||||
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||
{
|
||||
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
||||
|
||||
|
||||
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
|
||||
return false;
|
||||
|
||||
return rowMatchesCardName(info);
|
||||
}
|
||||
|
||||
bool CardDatabaseDisplayModel::rowMatchesCardName(CardInfo const *info) const {
|
||||
bool CardDatabaseDisplayModel::rowMatchesCardName(CardInfo const *info) const
|
||||
{
|
||||
if (!cardName.isEmpty() && !info->getName().contains(cardName, Qt::CaseInsensitive))
|
||||
return false;
|
||||
|
||||
|
|
@ -323,10 +322,8 @@ void CardDatabaseDisplayModel::filterTreeChanged()
|
|||
invalidate();
|
||||
}
|
||||
|
||||
TokenDisplayModel::TokenDisplayModel(QObject *parent)
|
||||
: CardDatabaseDisplayModel(parent)
|
||||
TokenDisplayModel::TokenDisplayModel(QObject *parent) : CardDatabaseDisplayModel(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool TokenDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue