mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
Run formatter on all our files (#6942)
This commit is contained in:
parent
b3c89167c5
commit
1d5d3f2d38
19 changed files with 153 additions and 81 deletions
|
|
@ -6,8 +6,9 @@ SetsModel::SetsModel(CardDatabase *_db, QObject *parent) : QAbstractTableModel(p
|
|||
{
|
||||
sets.sortByKey();
|
||||
for (const CardSetPtr &set : sets) {
|
||||
if (set->getEnabled())
|
||||
if (set->getEnabled()) {
|
||||
enabledSets.insert(set);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -15,16 +16,18 @@ SetsModel::~SetsModel() = default;
|
|||
|
||||
int SetsModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
if (parent.isValid()) {
|
||||
return 0;
|
||||
else
|
||||
} else {
|
||||
return sets.size();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant SetsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid() || (index.column() >= NUM_COLS) || (index.row() >= rowCount()))
|
||||
if (!index.isValid() || (index.column() >= NUM_COLS) || (index.row() >= rowCount())) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
CardSetPtr set = sets[index.row()];
|
||||
|
||||
|
|
@ -40,8 +43,9 @@ QVariant SetsModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
}
|
||||
|
||||
if (role != Qt::DisplayRole && role != SortRole)
|
||||
if (role != Qt::DisplayRole && role != SortRole) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
switch (index.column()) {
|
||||
case SortKeyCol:
|
||||
|
|
@ -72,8 +76,9 @@ bool SetsModel::setData(const QModelIndex &index, const QVariant &value, int rol
|
|||
|
||||
QVariant SetsModel::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();
|
||||
}
|
||||
switch (section) {
|
||||
case SortKeyCol:
|
||||
return QString("Key"); /* no tr() for translations needed, column just used for sorting --> hidden */
|
||||
|
|
@ -97,13 +102,15 @@ QVariant SetsModel::headerData(int section, Qt::Orientation orientation, int rol
|
|||
|
||||
Qt::ItemFlags SetsModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
if (!index.isValid()) {
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
|
||||
Qt::ItemFlags flags = QAbstractTableModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||
|
||||
if (index.column() == EnabledCol)
|
||||
if (index.column() == EnabledCol) {
|
||||
flags |= Qt::ItemIsUserCheckable;
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
|
@ -115,8 +122,9 @@ Qt::DropActions SetsModel::supportedDropActions() const
|
|||
|
||||
QMimeData *SetsModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
if (indexes.isEmpty())
|
||||
if (indexes.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SetsMimeData *result = new SetsMimeData(indexes[0].row());
|
||||
return qobject_cast<QMimeData *>(result);
|
||||
|
|
@ -128,16 +136,19 @@ bool SetsModel::dropMimeData(const QMimeData *data,
|
|||
int /*column*/,
|
||||
const QModelIndex &parent)
|
||||
{
|
||||
if (action != Qt::MoveAction)
|
||||
if (action != Qt::MoveAction) {
|
||||
return false;
|
||||
}
|
||||
if (row == -1) {
|
||||
if (!parent.isValid())
|
||||
if (!parent.isValid()) {
|
||||
return false;
|
||||
}
|
||||
row = parent.row();
|
||||
}
|
||||
int oldRow = qobject_cast<const SetsMimeData *>(data)->getOldRow();
|
||||
if (oldRow < row)
|
||||
if (oldRow < row) {
|
||||
row--;
|
||||
}
|
||||
|
||||
swapRows(oldRow, row);
|
||||
|
||||
|
|
@ -148,10 +159,11 @@ void SetsModel::toggleRow(int row, bool enable)
|
|||
{
|
||||
CardSetPtr temp = sets.at(row);
|
||||
|
||||
if (enable)
|
||||
if (enable) {
|
||||
enabledSets.insert(temp);
|
||||
else
|
||||
} else {
|
||||
enabledSets.remove(temp);
|
||||
}
|
||||
|
||||
emit dataChanged(index(row, EnabledCol), index(row, EnabledCol));
|
||||
}
|
||||
|
|
@ -160,13 +172,15 @@ void SetsModel::toggleRow(int row)
|
|||
{
|
||||
CardSetPtr tmp = sets.at(row);
|
||||
|
||||
if (tmp == nullptr)
|
||||
if (tmp == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabledSets.contains(tmp))
|
||||
if (enabledSets.contains(tmp)) {
|
||||
enabledSets.remove(tmp);
|
||||
else
|
||||
} else {
|
||||
enabledSets.insert(tmp);
|
||||
}
|
||||
|
||||
emit dataChanged(index(row, EnabledCol), index(row, EnabledCol));
|
||||
}
|
||||
|
|
@ -175,9 +189,11 @@ void SetsModel::toggleAll(bool enabled)
|
|||
{
|
||||
enabledSets.clear();
|
||||
|
||||
if (enabled)
|
||||
for (CardSetPtr set : sets)
|
||||
if (enabled) {
|
||||
for (CardSetPtr set : sets) {
|
||||
enabledSets.insert(set);
|
||||
}
|
||||
}
|
||||
|
||||
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||
}
|
||||
|
|
@ -208,8 +224,9 @@ void SetsModel::sort(int column, Qt::SortOrder order)
|
|||
int numRows = rowCount();
|
||||
int row;
|
||||
|
||||
for (row = 0; row < numRows; ++row)
|
||||
for (row = 0; row < numRows; ++row) {
|
||||
setMap.insert(index(row, column).data(SetsModel::SortRole).toString(), sets.at(row));
|
||||
}
|
||||
|
||||
QList<CardSetPtr> tmp = setMap.values();
|
||||
sets.clear();
|
||||
|
|
@ -253,8 +270,9 @@ void SetsModel::restore(CardDatabase *db)
|
|||
// enabled sets
|
||||
enabledSets.clear();
|
||||
for (const CardSetPtr &set : sets) {
|
||||
if (set->getEnabled())
|
||||
if (set->getEnabled()) {
|
||||
enabledSets.insert(set);
|
||||
}
|
||||
}
|
||||
|
||||
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue