Run formatter on all our files (#6942)

This commit is contained in:
RickyRister 2026-05-26 15:11:38 -07:00 committed by GitHub
parent b3c89167c5
commit 1d5d3f2d38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 153 additions and 81 deletions

View file

@ -19,8 +19,9 @@ int CardSearchModel::rowCount(const QModelIndex &parent) const
QVariant CardSearchModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= searchResults.size())
if (!index.isValid() || index.row() >= searchResults.size()) {
return QVariant();
}
if (role == Qt::DisplayRole) {
return searchResults.at(index.row()).card->getName();
@ -34,8 +35,9 @@ void CardSearchModel::updateSearchResults(const QString &query)
beginResetModel();
searchResults.clear();
if (query.isEmpty() || !sourceModel)
if (query.isEmpty() || !sourceModel) {
return;
}
// Set the filter for the display model
sourceModel->setCardName(query);
@ -46,13 +48,15 @@ void CardSearchModel::updateSearchResults(const QString &query)
QModelIndex sourceIndex = sourceModel->mapToSource(modelIndex);
CardDatabaseModel *sourceDbModel = qobject_cast<CardDatabaseModel *>(sourceModel->sourceModel());
if (!sourceDbModel || !sourceIndex.isValid())
if (!sourceDbModel || !sourceIndex.isValid()) {
return;
}
CardInfoPtr card = sourceDbModel->getCard(sourceIndex.row());
if (!card)
if (!card) {
continue;
}
int distance = levenshteinDistance(query.toLower(), card->getName().toLower());
searchResults.append({card, distance});
@ -63,8 +67,9 @@ void CardSearchModel::updateSearchResults(const QString &query)
[](const SearchResult &a, const SearchResult &b) { return a.distance < b.distance; });
// Keep only the top 5 results
if (searchResults.size() > 10)
if (searchResults.size() > 10) {
searchResults = searchResults.mid(0, 10);
}
emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
emit layoutChanged();

View file

@ -75,12 +75,14 @@ bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelInd
// test for an exact match: isLeftType && leftString.size() == cardName.size()
// or an exclusive start match: isLeftType && !isRightType
if (isLeftType && (!isRightType || leftString.size() == cardName.size()))
if (isLeftType && (!isRightType || leftString.size() == cardName.size())) {
return true;
}
// same checks for the right string
if (isRightType && (!isLeftType || rightString.size() == cardName.size()))
if (isRightType && (!isLeftType || rightString.size() == cardName.size())) {
return false;
}
} else if (right.column() == CardDatabaseModel::PTColumn && left.column() == CardDatabaseModel::PTColumn) {
QStringList leftList = leftString.split("/");
QStringList rightList = rightString.split("/");
@ -172,8 +174,9 @@ bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex
{
CardInfoPtr info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken())) {
return false;
}
if (filterString != nullptr) {
if (filterTree != nullptr && !filterTree->acceptsCard(info)) {
@ -187,14 +190,17 @@ bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex
bool CardDatabaseDisplayModel::rowMatchesCardName(CardInfoPtr info) const
{
if (!cardName.isEmpty() && !info->getName().contains(cardName, Qt::CaseInsensitive))
if (!cardName.isEmpty() && !info->getName().contains(cardName, Qt::CaseInsensitive)) {
return false;
}
if (!cardNameSet.isEmpty() && !cardNameSet.contains(info->getName()))
if (!cardNameSet.isEmpty() && !cardNameSet.contains(info->getName())) {
return false;
}
if (filterTree != nullptr)
if (filterTree != nullptr) {
return filterTree->acceptsCard(info);
}
return true;
}
@ -208,8 +214,9 @@ void CardDatabaseDisplayModel::clearFilterAll()
cardText.clear();
cardTypes.clear();
cardColors.clear();
if (filterTree != nullptr)
if (filterTree != nullptr) {
filterTree->clear();
}
#if (QT_VERSION >= QT_VERSION_CHECK(6, 10, 0))
endFilterChange(QSortFilterProxyModel::Direction::Rows);
#else
@ -219,8 +226,9 @@ void CardDatabaseDisplayModel::clearFilterAll()
void CardDatabaseDisplayModel::setFilterTree(FilterTree *_filterTree)
{
if (this->filterTree != nullptr)
if (this->filterTree != nullptr) {
disconnect(this->filterTree, nullptr, this, nullptr);
}
this->filterTree = _filterTree;
connect(this->filterTree, &FilterTree::changed, this, &CardDatabaseDisplayModel::filterTreeChanged);

View file

@ -31,8 +31,9 @@ int CardDatabaseModel::columnCount(const QModelIndex & /*parent*/) const
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= cardList.size() || index.column() >= CARDDBMODEL_COLUMNS ||
(role != Qt::DisplayRole && role != SortRole))
(role != Qt::DisplayRole && role != SortRole)) {
return QVariant();
}
CardInfoPtr card = cardList.at(index.row());
switch (index.column()) {
@ -56,10 +57,12 @@ QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
if (role != Qt::DisplayRole) {
return QVariant();
if (orientation != Qt::Horizontal)
}
if (orientation != Qt::Horizontal) {
return QVariant();
}
switch (section) {
case NameColumn:
return QString(tr("Name"));
@ -81,21 +84,24 @@ QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation,
void CardDatabaseModel::cardInfoChanged(CardInfoPtr card)
{
const int row = cardList.indexOf(card);
if (row == -1)
if (row == -1) {
return;
}
emit dataChanged(index(row, 0), index(row, CARDDBMODEL_COLUMNS - 1));
}
bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfoPtr card)
{
if (!showOnlyCardsFromEnabledSets)
if (!showOnlyCardsFromEnabledSets) {
return true;
}
for (const auto &printings : card->getSets()) {
for (const auto &printing : printings) {
if (printing.getSet()->getEnabled())
if (printing.getSet()->getEnabled()) {
return true;
}
}
}

View file

@ -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));

View file

@ -89,12 +89,15 @@ static inline QString toString(Type t)
static inline Type fromString(const QString &s)
{
if (s == "Main Type")
if (s == "Main Type") {
return MAIN_TYPE;
if (s == "Mana Cost")
}
if (s == "Mana Cost") {
return MANA_COST;
if (s == "Colors")
}
if (s == "Colors") {
return COLOR;
}
return MAIN_TYPE; // default
}
} // namespace DeckListModelGroupCriteria
@ -427,8 +430,9 @@ private:
template <typename T> T getNode(const QModelIndex &index) const
{
if (!index.isValid())
if (!index.isValid()) {
return dynamic_cast<T>(root);
}
return dynamic_cast<T>(static_cast<AbstractDecklistNode *>(index.internalPointer()));
}

View file

@ -29,25 +29,29 @@ bool DeckListSortFilterProxyModel::lessThan(const QModelIndex &left, const QMode
QString ln = lNode->getName();
QString rn = rNode->getName();
int cmp = ln.localeAwareCompare(rn);
if (cmp != 0)
if (cmp != 0) {
return cmp < 0;
}
} else if (crit == "cmc") {
int lc = lInfo ? lInfo->getCmc().toInt() : 0;
int rc = rInfo ? rInfo->getCmc().toInt() : 0;
if (lc != rc)
if (lc != rc) {
return lc < rc;
}
} else if (crit == "colors") {
QString lr = lInfo ? lInfo->getColors() : QString();
QString rr = rInfo ? rInfo->getColors() : QString();
int cmp = lr.localeAwareCompare(rr);
if (cmp != 0)
if (cmp != 0) {
return cmp < 0;
}
} else if (crit == "maintype") {
QString lr = lInfo ? lInfo->getMainCardType() : QString();
QString rr = rInfo ? rInfo->getMainCardType() : QString();
int cmp = lr.localeAwareCompare(rr);
if (cmp != 0)
if (cmp != 0) {
return cmp < 0;
}
}
}