mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-09 15:54: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
|
|
@ -1,17 +1,17 @@
|
|||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QFont>
|
||||
#include <QBrush>
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
#include <QPrinter>
|
||||
#include <QTextTable>
|
||||
#include <QProgressDialog>
|
||||
#include "main.h"
|
||||
#include "decklistmodel.h"
|
||||
#include "carddatabase.h"
|
||||
#include "settingscache.h"
|
||||
#include "deck_loader.h"
|
||||
#include "main.h"
|
||||
#include "settingscache.h"
|
||||
#include <QBrush>
|
||||
#include <QFile>
|
||||
#include <QFont>
|
||||
#include <QPrinter>
|
||||
#include <QProgressDialog>
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
#include <QTextStream>
|
||||
#include <QTextTable>
|
||||
|
||||
DeckListModel::DeckListModel(QObject *parent)
|
||||
: QAbstractItemModel(parent), lastKnownColumn(1), lastKnownOrder(Qt::AscendingOrder)
|
||||
|
|
@ -35,18 +35,15 @@ void DeckListModel::rebuildTree()
|
|||
|
||||
InnerDecklistNode *listRoot = deckList->getRoot();
|
||||
|
||||
for (int i = 0; i < listRoot->size(); i++)
|
||||
{
|
||||
for (int i = 0; i < listRoot->size(); i++) {
|
||||
auto *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||
auto *node = new InnerDecklistNode(currentZone->getName(), root);
|
||||
|
||||
for (int j = 0; j < currentZone->size(); j++)
|
||||
{
|
||||
for (int j = 0; j < currentZone->size(); j++) {
|
||||
auto *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||
|
||||
// TODO: better sanity checking
|
||||
if (currentCard == nullptr)
|
||||
{
|
||||
if (currentCard == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +52,7 @@ void DeckListModel::rebuildTree()
|
|||
|
||||
auto *cardTypeNode = dynamic_cast<InnerDecklistNode *>(node->findChild(cardType));
|
||||
|
||||
if (!cardTypeNode)
|
||||
{
|
||||
if (!cardTypeNode) {
|
||||
cardTypeNode = new InnerDecklistNode(cardType, node);
|
||||
}
|
||||
|
||||
|
|
@ -69,54 +65,44 @@ void DeckListModel::rebuildTree()
|
|||
|
||||
int DeckListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
//debugIndexInfo("rowCount", parent);
|
||||
// debugIndexInfo("rowCount", parent);
|
||||
auto *node = getNode<InnerDecklistNode *>(parent);
|
||||
if (node)
|
||||
{
|
||||
if (node) {
|
||||
return node->size();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int DeckListModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
int DeckListModel::columnCount(const QModelIndex & /*parent*/) const
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
//debugIndexInfo("data", index);
|
||||
if (!index.isValid())
|
||||
{
|
||||
// debugIndexInfo("data", index);
|
||||
if (!index.isValid()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (index.column() >= columnCount())
|
||||
{
|
||||
if (index.column() >= columnCount()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
auto *temp = static_cast<AbstractDecklistNode *>(index.internalPointer());
|
||||
auto *card = dynamic_cast<DecklistModelCardNode *>(temp);
|
||||
if (card == nullptr)
|
||||
{
|
||||
if (card == nullptr) {
|
||||
auto *node = dynamic_cast<InnerDecklistNode *>(temp);
|
||||
switch (role)
|
||||
{
|
||||
case Qt::FontRole:
|
||||
{
|
||||
switch (role) {
|
||||
case Qt::FontRole: {
|
||||
QFont f;
|
||||
f.setBold(true);
|
||||
return f;
|
||||
}
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
{
|
||||
switch (index.column())
|
||||
{
|
||||
case Qt::EditRole: {
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
return node->recursiveCount(true);
|
||||
case 1:
|
||||
|
|
@ -125,40 +111,35 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
}
|
||||
case Qt::BackgroundRole:
|
||||
{
|
||||
case Qt::BackgroundRole: {
|
||||
int color = 90 + 60 * node->depth();
|
||||
return QBrush(QColor(color, 255, color));
|
||||
}
|
||||
case Qt::ForegroundRole:
|
||||
{
|
||||
return QBrush(QColor(0 ,0 ,0));
|
||||
case Qt::ForegroundRole: {
|
||||
return QBrush(QColor(0, 0, 0));
|
||||
}
|
||||
default: return QVariant();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (role)
|
||||
{
|
||||
} else {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
{
|
||||
switch (index.column())
|
||||
{
|
||||
case 0: return card->getNumber();
|
||||
case 1: return card->getName();
|
||||
default: return QVariant();
|
||||
case Qt::EditRole: {
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
return card->getNumber();
|
||||
case 1:
|
||||
return card->getName();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
case Qt::BackgroundRole:
|
||||
{
|
||||
case Qt::BackgroundRole: {
|
||||
int color = 255 - (index.row() % 2) * 30;
|
||||
return QBrush(QColor(color, color, color));
|
||||
}
|
||||
case Qt::ForegroundRole:
|
||||
{
|
||||
return QBrush(QColor(0 ,0 ,0));
|
||||
case Qt::ForegroundRole: {
|
||||
return QBrush(QColor(0, 0, 0));
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
|
|
@ -168,41 +149,38 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
||||
{
|
||||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal)) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (section >= columnCount())
|
||||
{
|
||||
if (section >= columnCount()) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
switch (section)
|
||||
{
|
||||
case 0: return tr("Number");
|
||||
case 1: return tr("Card");
|
||||
default: return QVariant();
|
||||
switch (section) {
|
||||
case 0:
|
||||
return tr("Number");
|
||||
case 1:
|
||||
return tr("Card");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex DeckListModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
//debugIndexInfo("index", parent);
|
||||
if (!hasIndex(row, column, parent))
|
||||
{
|
||||
// debugIndexInfo("index", parent);
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto *parentNode = getNode<InnerDecklistNode *>(parent);
|
||||
return row >= parentNode->size() ? QModelIndex() : createIndex(row, column, parentNode->at(row));
|
||||
|
||||
}
|
||||
|
||||
QModelIndex DeckListModel::parent(const QModelIndex &ind) const
|
||||
{
|
||||
if (!ind.isValid())
|
||||
{
|
||||
if (!ind.isValid()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -211,8 +189,7 @@ QModelIndex DeckListModel::parent(const QModelIndex &ind) const
|
|||
|
||||
Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -224,8 +201,7 @@ Qt::ItemFlags DeckListModel::flags(const QModelIndex &index) const
|
|||
|
||||
void DeckListModel::emitRecursiveUpdates(const QModelIndex &index)
|
||||
{
|
||||
if (!index.isValid())
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -236,16 +212,19 @@ void DeckListModel::emitRecursiveUpdates(const QModelIndex &index)
|
|||
bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
auto *node = getNode<DecklistModelCardNode *>(index);
|
||||
if (!node || (role != Qt::EditRole))
|
||||
{
|
||||
if (!node || (role != Qt::EditRole)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case 0: node->setNumber(value.toInt()); break;
|
||||
case 1: node->setName(value.toString()); break;
|
||||
default: return false;
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
node->setNumber(value.toInt());
|
||||
break;
|
||||
case 1:
|
||||
node->setName(value.toString());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
emitRecursiveUpdates(index);
|
||||
|
|
@ -256,34 +235,27 @@ bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||
bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
auto *node = getNode<InnerDecklistNode *>(parent);
|
||||
if (!node)
|
||||
{
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (row + count > node->size())
|
||||
{
|
||||
if (row + count > node->size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
for (int i = 0; i < count; i++) {
|
||||
AbstractDecklistNode *toDelete = node->takeAt(row);
|
||||
if (auto *temp = dynamic_cast<DecklistModelCardNode *>(toDelete))
|
||||
{
|
||||
if (auto *temp = dynamic_cast<DecklistModelCardNode *>(toDelete)) {
|
||||
deckList->deleteNode(temp->getDataNode());
|
||||
}
|
||||
delete toDelete;
|
||||
}
|
||||
endRemoveRows();
|
||||
|
||||
if (node->empty() && (node != root))
|
||||
{
|
||||
if (node->empty() && (node != root)) {
|
||||
removeRows(parent.row(), 1, parent.parent());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
emitRecursiveUpdates(parent);
|
||||
}
|
||||
|
||||
|
|
@ -293,8 +265,7 @@ bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
|
|||
InnerDecklistNode *DeckListModel::createNodeIfNeeded(const QString &name, InnerDecklistNode *parent)
|
||||
{
|
||||
auto *newNode = dynamic_cast<InnerDecklistNode *>(parent->findChild(name));
|
||||
if (!newNode)
|
||||
{
|
||||
if (!newNode) {
|
||||
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
|
||||
newNode = new InnerDecklistNode(name, parent);
|
||||
endInsertRows();
|
||||
|
|
@ -309,21 +280,18 @@ DecklistModelCardNode *DeckListModel::findCardNode(const QString &cardName, cons
|
|||
QString cardType;
|
||||
|
||||
zoneNode = dynamic_cast<InnerDecklistNode *>(root->findChild(zoneName));
|
||||
if (!zoneNode)
|
||||
{
|
||||
if (!zoneNode) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
info = db->getCard(cardName);
|
||||
if (!info)
|
||||
{
|
||||
if (!info) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cardType = info->getMainCardType();
|
||||
typeNode = dynamic_cast<InnerDecklistNode *>(zoneNode->findChild(cardType));
|
||||
if (!typeNode)
|
||||
{
|
||||
if (!typeNode) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
@ -335,8 +303,7 @@ QModelIndex DeckListModel::findCard(const QString &cardName, const QString &zone
|
|||
DecklistModelCardNode *cardNode;
|
||||
|
||||
cardNode = findCardNode(cardName, zoneName);
|
||||
if (!cardNode)
|
||||
{
|
||||
if (!cardNode) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -346,38 +313,16 @@ QModelIndex DeckListModel::findCard(const QString &cardName, const QString &zone
|
|||
QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName, bool abAddAnyway)
|
||||
{
|
||||
CardInfo *info = db->getCard(cardName);
|
||||
if (info == nullptr)
|
||||
{
|
||||
if (abAddAnyway)
|
||||
{
|
||||
if (info == nullptr) {
|
||||
if (abAddAnyway) {
|
||||
// We need to keep this card added no matter what
|
||||
// This is usually called from tab_deck_editor
|
||||
// So we'll create a new CardInfo with the name
|
||||
// and default values for all fields
|
||||
info = new CardInfo(
|
||||
cardName,
|
||||
false,
|
||||
nullptr,
|
||||
nullptr,
|
||||
"unknown",
|
||||
nullptr,
|
||||
nullptr,
|
||||
QStringList(),
|
||||
QList<CardRelation *>(),
|
||||
QList<CardRelation *>(),
|
||||
false,
|
||||
0,
|
||||
false,
|
||||
0,
|
||||
SetList(),
|
||||
QStringMap(),
|
||||
MuidMap(),
|
||||
QStringMap(),
|
||||
QStringMap()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
info = new CardInfo(cardName, false, nullptr, nullptr, "unknown", nullptr, nullptr, QStringList(),
|
||||
QList<CardRelation *>(), QList<CardRelation *>(), false, 0, false, 0, SetList(),
|
||||
QStringMap(), MuidMap(), QStringMap(), QStringMap());
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
@ -389,15 +334,12 @@ QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneN
|
|||
|
||||
QModelIndex parentIndex = nodeToIndex(cardTypeNode);
|
||||
auto *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName));
|
||||
if (!cardNode)
|
||||
{
|
||||
if (!cardNode) {
|
||||
DecklistCardNode *decklistCard = deckList->addCard(cardName, zoneName);
|
||||
beginInsertRows(parentIndex, cardTypeNode->size(), cardTypeNode->size());
|
||||
cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode);
|
||||
endInsertRows();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
cardNode->setNumber(cardNode->getNumber() + 1);
|
||||
deckList->updateDeckHash();
|
||||
}
|
||||
|
|
@ -408,8 +350,7 @@ QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneN
|
|||
|
||||
QModelIndex DeckListModel::nodeToIndex(AbstractDecklistNode *node) const
|
||||
{
|
||||
if (node == nullptr || node == root)
|
||||
{
|
||||
if (node == nullptr || node == root) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -420,17 +361,15 @@ void DeckListModel::sortHelper(InnerDecklistNode *node, Qt::SortOrder order)
|
|||
{
|
||||
// Sort children of node and save the information needed to
|
||||
// update the list of persistent indexes.
|
||||
QVector<QPair<int, int> > sortResult = node->sort(order);
|
||||
QVector<QPair<int, int>> sortResult = node->sort(order);
|
||||
|
||||
QModelIndexList from, to;
|
||||
int columns = columnCount();
|
||||
for (int i = sortResult.size() - 1; i >= 0; --i)
|
||||
{
|
||||
for (int i = sortResult.size() - 1; i >= 0; --i) {
|
||||
const int fromRow = sortResult[i].first;
|
||||
const int toRow = sortResult[i].second;
|
||||
AbstractDecklistNode *temp = node->at(toRow);
|
||||
for (int j = 0; j < columns; ++j)
|
||||
{
|
||||
for (int j = 0; j < columns; ++j) {
|
||||
from << createIndex(fromRow, j, temp);
|
||||
to << createIndex(toRow, j, temp);
|
||||
}
|
||||
|
|
@ -438,11 +377,9 @@ void DeckListModel::sortHelper(InnerDecklistNode *node, Qt::SortOrder order)
|
|||
changePersistentIndexList(from, to);
|
||||
|
||||
// Recursion
|
||||
for (int i = node->size() - 1; i >= 0; --i)
|
||||
{
|
||||
for (int i = node->size() - 1; i >= 0; --i) {
|
||||
auto *subNode = dynamic_cast<InnerDecklistNode *>(node->at(i));
|
||||
if (subNode)
|
||||
{
|
||||
if (subNode) {
|
||||
sortHelper(subNode, order);
|
||||
}
|
||||
}
|
||||
|
|
@ -455,8 +392,7 @@ void DeckListModel::sort(int column, Qt::SortOrder order)
|
|||
|
||||
emit layoutAboutToBeChanged();
|
||||
DeckSortMethod sortMethod;
|
||||
switch(column)
|
||||
{
|
||||
switch (column) {
|
||||
case 0:
|
||||
sortMethod = ByNumber;
|
||||
break;
|
||||
|
|
@ -490,8 +426,7 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
|
|||
{
|
||||
const int totalColumns = 2;
|
||||
|
||||
if (node->height() == 1)
|
||||
{
|
||||
if (node->height() == 1) {
|
||||
QTextBlockFormat blockFormat;
|
||||
QTextCharFormat charFormat;
|
||||
charFormat.setFontPointSize(11);
|
||||
|
|
@ -502,9 +437,8 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
|
|||
tableFormat.setCellPadding(0);
|
||||
tableFormat.setCellSpacing(0);
|
||||
tableFormat.setBorder(0);
|
||||
QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
|
||||
for (int i = 0; i < node->size(); i++)
|
||||
{
|
||||
QTextTable *table = cursor->insertTable(node->size() + 1, totalColumns, tableFormat);
|
||||
for (int i = 0; i < node->size(); i++) {
|
||||
auto *card = dynamic_cast<AbstractDecklistCardNode *>(node->at(i));
|
||||
|
||||
QTextCharFormat cellCharFormat;
|
||||
|
|
@ -519,11 +453,8 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
|
|||
cell.setFormat(cellCharFormat);
|
||||
cellCursor = cell.firstCursorPosition();
|
||||
cellCursor.insertText(card->getName());
|
||||
|
||||
}
|
||||
}
|
||||
else if (node->height() == 2)
|
||||
{
|
||||
} else if (node->height() == 2) {
|
||||
QTextBlockFormat blockFormat;
|
||||
QTextCharFormat charFormat;
|
||||
charFormat.setFontPointSize(14);
|
||||
|
|
@ -536,15 +467,13 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
|
|||
tableFormat.setCellSpacing(0);
|
||||
tableFormat.setBorder(0);
|
||||
QVector<QTextLength> constraints;
|
||||
for (int i = 0; i < totalColumns; i++)
|
||||
{
|
||||
for (int i = 0; i < totalColumns; i++) {
|
||||
constraints << QTextLength(QTextLength::PercentageLength, 100.0 / totalColumns);
|
||||
}
|
||||
tableFormat.setColumnWidthConstraints(constraints);
|
||||
|
||||
QTextTable *table = cursor->insertTable(1, totalColumns, tableFormat);
|
||||
for (int i = 0; i < node->size(); i++)
|
||||
{
|
||||
for (int i = 0; i < node->size(); i++) {
|
||||
QTextCursor cellCursor = table->cellAt(0, (i * totalColumns) / node->size()).lastCursorPosition();
|
||||
printDeckListNode(&cellCursor, dynamic_cast<InnerDecklistNode *>(node->at(i)));
|
||||
}
|
||||
|
|
@ -576,10 +505,9 @@ void DeckListModel::printDeckList(QPrinter *printer)
|
|||
cursor.insertText(deckList->getComments());
|
||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||
|
||||
for (int i = 0; i < root->size(); i++)
|
||||
{
|
||||
for (int i = 0; i < root->size(); i++) {
|
||||
cursor.insertHtml("<br><img src=theme:hr.jpg>");
|
||||
//cursor.insertHtml("<hr>");
|
||||
// cursor.insertHtml("<hr>");
|
||||
cursor.insertBlock(headerBlockFormat, headerCharFormat);
|
||||
|
||||
printDeckListNode(&cursor, dynamic_cast<InnerDecklistNode *>(root->at(i)));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue