mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 11:01:29 -07:00
Run formatter on all our files (#6942)
This commit is contained in:
@@ -61,24 +61,30 @@ inline QString expandPattern(const QString &pattern,
|
|||||||
QString result = pattern;
|
QString result = pattern;
|
||||||
|
|
||||||
auto replaceIfPresent = [&](const QString &token, const QString &value) -> bool {
|
auto replaceIfPresent = [&](const QString &token, const QString &value) -> bool {
|
||||||
if (!result.contains(token))
|
if (!result.contains(token)) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (value.isEmpty())
|
if (value.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
result.replace(token, value);
|
result.replace(token, value);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!replaceIfPresent("{name}", name))
|
if (!replaceIfPresent("{name}", name)) {
|
||||||
return {};
|
return {};
|
||||||
if (!replaceIfPresent("{set}", set))
|
}
|
||||||
|
if (!replaceIfPresent("{set}", set)) {
|
||||||
return {};
|
return {};
|
||||||
if (!replaceIfPresent("{collector}", collector))
|
}
|
||||||
|
if (!replaceIfPresent("{collector}", collector)) {
|
||||||
return {};
|
return {};
|
||||||
if (!replaceIfPresent("{providerId}", providerId))
|
}
|
||||||
|
if (!replaceIfPresent("{providerId}", providerId)) {
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -96,8 +102,9 @@ generateImportVariants(const QString &name, const QString &set, const QString &c
|
|||||||
pattern.replace("_", sep);
|
pattern.replace("_", sep);
|
||||||
|
|
||||||
QString v = expandPattern(pattern, name, set, collector, providerId);
|
QString v = expandPattern(pattern, name, set, collector, providerId);
|
||||||
if (!v.isEmpty())
|
if (!v.isEmpty()) {
|
||||||
variants << v;
|
variants << v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ CardPictureLoaderWorker::CardPictureLoaderWorker()
|
|||||||
static_cast<qint64>(SettingsCache::instance().getNetworkCacheSizeInMB()));
|
static_cast<qint64>(SettingsCache::instance().getNetworkCacheSizeInMB()));
|
||||||
|
|
||||||
connect(&SettingsCache::instance(), &SettingsCache::networkCacheSizeChanged, cache, [this](int newSizeInMB) {
|
connect(&SettingsCache::instance(), &SettingsCache::networkCacheSizeChanged, cache, [this](int newSizeInMB) {
|
||||||
if (cache)
|
if (cache) {
|
||||||
cache->setMaximumCacheSize(1024L * 1024L * static_cast<qint64>(newSizeInMB));
|
cache->setMaximumCacheSize(1024L * 1024L * static_cast<qint64>(newSizeInMB));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
networkManager->setCache(cache);
|
networkManager->setCache(cache);
|
||||||
|
|||||||
@@ -70,8 +70,9 @@ bool FlowLayout::hasHeightForWidth() const
|
|||||||
*/
|
*/
|
||||||
int FlowLayout::heightForWidth(const int width) const
|
int FlowLayout::heightForWidth(const int width) const
|
||||||
{
|
{
|
||||||
if (flowDirection != Qt::Horizontal)
|
if (flowDirection != Qt::Horizontal) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int totalHeight = 0;
|
int totalHeight = 0;
|
||||||
int rowUsedWidth = 0;
|
int rowUsedWidth = 0;
|
||||||
@@ -181,8 +182,9 @@ int FlowLayout::layoutAllRows(const int originX, const int originY, const int av
|
|||||||
*/
|
*/
|
||||||
void FlowLayout::layoutSingleRow(const QVector<QLayoutItem *> &rowItems, int x, const int y, const int availableWidth)
|
void FlowLayout::layoutSingleRow(const QVector<QLayoutItem *> &rowItems, int x, const int y, const int availableWidth)
|
||||||
{
|
{
|
||||||
if (rowItems.isEmpty())
|
if (rowItems.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// ── Pass 1: measure fixed width and count expanding items ────────────────
|
// ── Pass 1: measure fixed width and count expanding items ────────────────
|
||||||
int fixedWidth = 0;
|
int fixedWidth = 0;
|
||||||
@@ -211,12 +213,14 @@ void FlowLayout::layoutSingleRow(const QVector<QLayoutItem *> &rowItems, int x,
|
|||||||
|
|
||||||
// ── Pass 2: place items ──────────────────────────────────────────────────
|
// ── Pass 2: place items ──────────────────────────────────────────────────
|
||||||
for (QLayoutItem *item : rowItems) {
|
for (QLayoutItem *item : rowItems) {
|
||||||
if (!item || item->isEmpty())
|
if (!item || item->isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QWidget *widget = item->widget();
|
QWidget *widget = item->widget();
|
||||||
if (!widget)
|
if (!widget) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const QSizePolicy::Policy hPolicy = widget->sizePolicy().horizontalPolicy();
|
const QSizePolicy::Policy hPolicy = widget->sizePolicy().horizontalPolicy();
|
||||||
const QSize maxSize = widget->maximumSize();
|
const QSize maxSize = widget->maximumSize();
|
||||||
|
|||||||
@@ -108,8 +108,9 @@ void FlowWidget::clearLayout()
|
|||||||
if (flowLayout) {
|
if (flowLayout) {
|
||||||
QLayoutItem *item;
|
QLayoutItem *item;
|
||||||
while ((item = flowLayout->takeAt(0))) {
|
while ((item = flowLayout->takeAt(0))) {
|
||||||
if (item->widget())
|
if (item->widget()) {
|
||||||
item->widget()->deleteLater();
|
item->widget()->deleteLater();
|
||||||
|
}
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ public:
|
|||||||
QJsonObject getOracleCard() const
|
QJsonObject getOracleCard() const
|
||||||
{
|
{
|
||||||
return oracleCard;
|
return oracleCard;
|
||||||
};
|
}
|
||||||
|
|
||||||
QString getCollectorNumber() const
|
QString getCollectorNumber() const
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ public:
|
|||||||
ArchidektApiResponseCard getCard() const
|
ArchidektApiResponseCard getCard() const
|
||||||
{
|
{
|
||||||
return card;
|
return card;
|
||||||
};
|
}
|
||||||
|
|
||||||
QList<Category> getCategories() const
|
QList<Category> getCategories() const
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -27,7 +27,7 @@ public:
|
|||||||
QVector<ArchidektApiResponseCardEntry> getCards() const
|
QVector<ArchidektApiResponseCardEntry> getCards() const
|
||||||
{
|
{
|
||||||
return cards;
|
return cards;
|
||||||
};
|
}
|
||||||
|
|
||||||
QVector<ArchidektApiResponseDeckCategory> getCategories() const
|
QVector<ArchidektApiResponseDeckCategory> getCategories() const
|
||||||
{
|
{
|
||||||
@@ -37,7 +37,7 @@ public:
|
|||||||
QString getDeckName() const
|
QString getDeckName() const
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
};
|
}
|
||||||
|
|
||||||
int getDeckFormat() const
|
int getDeckFormat() const
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-1
@@ -174,7 +174,8 @@ void VisualDatabaseDisplayFilterToolbarWidget::updateCompactMode(int availableWi
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (auto *btn : filterButtons) {
|
for (auto *btn : filterButtons) {
|
||||||
if (btn->isCompact() != compact) // only act on transitions
|
if (btn->isCompact() != compact) { // only act on transitions
|
||||||
btn->setCompact(compact);
|
btn->setCompact(compact);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,20 +251,27 @@ static void setupParserRules()
|
|||||||
const auto arg = std::any_cast<int>(sv[1]);
|
const auto arg = std::any_cast<int>(sv[1]);
|
||||||
const auto op = std::any_cast<QString>(sv[0]);
|
const auto op = std::any_cast<QString>(sv[0]);
|
||||||
|
|
||||||
if (op == ">")
|
if (op == ">") {
|
||||||
return [=](const int s) { return s > arg; };
|
return [=](const int s) { return s > arg; };
|
||||||
if (op == ">=")
|
}
|
||||||
|
if (op == ">=") {
|
||||||
return [=](const int s) { return s >= arg; };
|
return [=](const int s) { return s >= arg; };
|
||||||
if (op == "<")
|
}
|
||||||
|
if (op == "<") {
|
||||||
return [=](const int s) { return s < arg; };
|
return [=](const int s) { return s < arg; };
|
||||||
if (op == "<=")
|
}
|
||||||
|
if (op == "<=") {
|
||||||
return [=](const int s) { return s <= arg; };
|
return [=](const int s) { return s <= arg; };
|
||||||
if (op == "=")
|
}
|
||||||
|
if (op == "=") {
|
||||||
return [=](const int s) { return s == arg; };
|
return [=](const int s) { return s == arg; };
|
||||||
if (op == ":")
|
}
|
||||||
|
if (op == ":") {
|
||||||
return [=](const int s) { return s == arg; };
|
return [=](const int s) { return s == arg; };
|
||||||
if (op == "!=")
|
}
|
||||||
|
if (op == "!=") {
|
||||||
return [=](const int s) { return s != arg; };
|
return [=](const int s) { return s != arg; };
|
||||||
|
}
|
||||||
return [](int) { return false; };
|
return [](int) { return false; };
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -315,8 +322,9 @@ static void setupParserRules()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parts.contains("c") && match.length() == 0)
|
if (parts.contains("c") && match.length() == 0) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
auto containsColor = [&parts](const QString &s) { return parts.contains(s); };
|
auto containsColor = [&parts](const QString &s) { return parts.contains(s); };
|
||||||
return std::any_of(match.begin(), match.end(), containsColor);
|
return std::any_of(match.begin(), match.end(), containsColor);
|
||||||
|
|||||||
@@ -205,8 +205,9 @@ bool FilterItem::acceptColor(const CardInfoPtr info) const
|
|||||||
*/
|
*/
|
||||||
int match_count = 0;
|
int match_count = 0;
|
||||||
for (auto &it : converted_term) {
|
for (auto &it : converted_term) {
|
||||||
if (info->getColors().contains(it, Qt::CaseInsensitive))
|
if (info->getColors().contains(it, Qt::CaseInsensitive)) {
|
||||||
match_count++;
|
match_count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return match_count == converted_term.length();
|
return match_count == converted_term.length();
|
||||||
@@ -542,12 +543,14 @@ void FilterTree::removeFilter(const CardFilter *toRemove)
|
|||||||
{
|
{
|
||||||
for (int i = childNodes.size() - 1; i >= 0; --i) {
|
for (int i = childNodes.size() - 1; i >= 0; --i) {
|
||||||
auto *logicMap = dynamic_cast<LogicMap *>(childNodes.at(i));
|
auto *logicMap = dynamic_cast<LogicMap *>(childNodes.at(i));
|
||||||
if (!logicMap || logicMap->attr != toRemove->attr())
|
if (!logicMap || logicMap->attr != toRemove->attr()) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
FilterItemList *typeList = logicMap->typeList(toRemove->type());
|
FilterItemList *typeList = logicMap->typeList(toRemove->type());
|
||||||
if (!typeList)
|
if (!typeList) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int termIdx = typeList->termIndex(toRemove->term());
|
int termIdx = typeList->termIndex(toRemove->term());
|
||||||
if (termIdx != -1) {
|
if (termIdx != -1) {
|
||||||
|
|||||||
+2
-1
@@ -6,7 +6,8 @@
|
|||||||
class ICardSetPriorityController
|
class ICardSetPriorityController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct SetSaveData {
|
struct SetSaveData
|
||||||
|
{
|
||||||
QString shortName;
|
QString shortName;
|
||||||
unsigned int sortKey;
|
unsigned int sortKey;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
|||||||
+3
-2
@@ -29,8 +29,9 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveSets(const QVector<SetSaveData> & /* data */) override {
|
void saveSets(const QVector<SetSaveData> & /* data */) override
|
||||||
};
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COCKATRICE_NOOP_CARD_SET_PRIORITY_CONTROLLER_H
|
#endif // COCKATRICE_NOOP_CARD_SET_PRIORITY_CONTROLLER_H
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ int CardSearchModel::rowCount(const QModelIndex &parent) const
|
|||||||
|
|
||||||
QVariant CardSearchModel::data(const QModelIndex &index, int role) 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();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
return searchResults.at(index.row()).card->getName();
|
return searchResults.at(index.row()).card->getName();
|
||||||
@@ -34,8 +35,9 @@ void CardSearchModel::updateSearchResults(const QString &query)
|
|||||||
beginResetModel();
|
beginResetModel();
|
||||||
searchResults.clear();
|
searchResults.clear();
|
||||||
|
|
||||||
if (query.isEmpty() || !sourceModel)
|
if (query.isEmpty() || !sourceModel) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the filter for the display model
|
// Set the filter for the display model
|
||||||
sourceModel->setCardName(query);
|
sourceModel->setCardName(query);
|
||||||
@@ -46,13 +48,15 @@ void CardSearchModel::updateSearchResults(const QString &query)
|
|||||||
QModelIndex sourceIndex = sourceModel->mapToSource(modelIndex);
|
QModelIndex sourceIndex = sourceModel->mapToSource(modelIndex);
|
||||||
CardDatabaseModel *sourceDbModel = qobject_cast<CardDatabaseModel *>(sourceModel->sourceModel());
|
CardDatabaseModel *sourceDbModel = qobject_cast<CardDatabaseModel *>(sourceModel->sourceModel());
|
||||||
|
|
||||||
if (!sourceDbModel || !sourceIndex.isValid())
|
if (!sourceDbModel || !sourceIndex.isValid()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CardInfoPtr card = sourceDbModel->getCard(sourceIndex.row());
|
CardInfoPtr card = sourceDbModel->getCard(sourceIndex.row());
|
||||||
|
|
||||||
if (!card)
|
if (!card) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int distance = levenshteinDistance(query.toLower(), card->getName().toLower());
|
int distance = levenshteinDistance(query.toLower(), card->getName().toLower());
|
||||||
searchResults.append({card, distance});
|
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; });
|
[](const SearchResult &a, const SearchResult &b) { return a.distance < b.distance; });
|
||||||
|
|
||||||
// Keep only the top 5 results
|
// Keep only the top 5 results
|
||||||
if (searchResults.size() > 10)
|
if (searchResults.size() > 10) {
|
||||||
searchResults = searchResults.mid(0, 10);
|
searchResults = searchResults.mid(0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
|
|||||||
@@ -75,12 +75,14 @@ bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelInd
|
|||||||
|
|
||||||
// test for an exact match: isLeftType && leftString.size() == cardName.size()
|
// test for an exact match: isLeftType && leftString.size() == cardName.size()
|
||||||
// or an exclusive start match: isLeftType && !isRightType
|
// or an exclusive start match: isLeftType && !isRightType
|
||||||
if (isLeftType && (!isRightType || leftString.size() == cardName.size()))
|
if (isLeftType && (!isRightType || leftString.size() == cardName.size())) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// same checks for the right string
|
// same checks for the right string
|
||||||
if (isRightType && (!isLeftType || rightString.size() == cardName.size()))
|
if (isRightType && (!isLeftType || rightString.size() == cardName.size())) {
|
||||||
return false;
|
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 leftList = leftString.split("/");
|
||||||
QStringList rightList = rightString.split("/");
|
QStringList rightList = rightString.split("/");
|
||||||
@@ -172,8 +174,9 @@ bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex
|
|||||||
{
|
{
|
||||||
CardInfoPtr info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
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;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (filterString != nullptr) {
|
if (filterString != nullptr) {
|
||||||
if (filterTree != nullptr && !filterTree->acceptsCard(info)) {
|
if (filterTree != nullptr && !filterTree->acceptsCard(info)) {
|
||||||
@@ -187,14 +190,17 @@ bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex
|
|||||||
|
|
||||||
bool CardDatabaseDisplayModel::rowMatchesCardName(CardInfoPtr info) const
|
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;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!cardNameSet.isEmpty() && !cardNameSet.contains(info->getName()))
|
if (!cardNameSet.isEmpty() && !cardNameSet.contains(info->getName())) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (filterTree != nullptr)
|
if (filterTree != nullptr) {
|
||||||
return filterTree->acceptsCard(info);
|
return filterTree->acceptsCard(info);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -208,8 +214,9 @@ void CardDatabaseDisplayModel::clearFilterAll()
|
|||||||
cardText.clear();
|
cardText.clear();
|
||||||
cardTypes.clear();
|
cardTypes.clear();
|
||||||
cardColors.clear();
|
cardColors.clear();
|
||||||
if (filterTree != nullptr)
|
if (filterTree != nullptr) {
|
||||||
filterTree->clear();
|
filterTree->clear();
|
||||||
|
}
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 10, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 10, 0))
|
||||||
endFilterChange(QSortFilterProxyModel::Direction::Rows);
|
endFilterChange(QSortFilterProxyModel::Direction::Rows);
|
||||||
#else
|
#else
|
||||||
@@ -219,8 +226,9 @@ void CardDatabaseDisplayModel::clearFilterAll()
|
|||||||
|
|
||||||
void CardDatabaseDisplayModel::setFilterTree(FilterTree *_filterTree)
|
void CardDatabaseDisplayModel::setFilterTree(FilterTree *_filterTree)
|
||||||
{
|
{
|
||||||
if (this->filterTree != nullptr)
|
if (this->filterTree != nullptr) {
|
||||||
disconnect(this->filterTree, nullptr, this, nullptr);
|
disconnect(this->filterTree, nullptr, this, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
this->filterTree = _filterTree;
|
this->filterTree = _filterTree;
|
||||||
connect(this->filterTree, &FilterTree::changed, this, &CardDatabaseDisplayModel::filterTreeChanged);
|
connect(this->filterTree, &FilterTree::changed, this, &CardDatabaseDisplayModel::filterTreeChanged);
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ int CardDatabaseModel::columnCount(const QModelIndex & /*parent*/) const
|
|||||||
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
|
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))
|
(role != Qt::DisplayRole && role != SortRole)) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
CardInfoPtr card = cardList.at(index.row());
|
CardInfoPtr card = cardList.at(index.row());
|
||||||
switch (index.column()) {
|
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
|
QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (role != Qt::DisplayRole)
|
if (role != Qt::DisplayRole) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
if (orientation != Qt::Horizontal)
|
}
|
||||||
|
if (orientation != Qt::Horizontal) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
}
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case NameColumn:
|
case NameColumn:
|
||||||
return QString(tr("Name"));
|
return QString(tr("Name"));
|
||||||
@@ -81,21 +84,24 @@ QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
void CardDatabaseModel::cardInfoChanged(CardInfoPtr card)
|
void CardDatabaseModel::cardInfoChanged(CardInfoPtr card)
|
||||||
{
|
{
|
||||||
const int row = cardList.indexOf(card);
|
const int row = cardList.indexOf(card);
|
||||||
if (row == -1)
|
if (row == -1) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
emit dataChanged(index(row, 0), index(row, CARDDBMODEL_COLUMNS - 1));
|
emit dataChanged(index(row, 0), index(row, CARDDBMODEL_COLUMNS - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfoPtr card)
|
bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfoPtr card)
|
||||||
{
|
{
|
||||||
if (!showOnlyCardsFromEnabledSets)
|
if (!showOnlyCardsFromEnabledSets) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &printings : card->getSets()) {
|
for (const auto &printings : card->getSets()) {
|
||||||
for (const auto &printing : printings) {
|
for (const auto &printing : printings) {
|
||||||
if (printing.getSet()->getEnabled())
|
if (printing.getSet()->getEnabled()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ SetsModel::SetsModel(CardDatabase *_db, QObject *parent) : QAbstractTableModel(p
|
|||||||
{
|
{
|
||||||
sets.sortByKey();
|
sets.sortByKey();
|
||||||
for (const CardSetPtr &set : sets) {
|
for (const CardSetPtr &set : sets) {
|
||||||
if (set->getEnabled())
|
if (set->getEnabled()) {
|
||||||
enabledSets.insert(set);
|
enabledSets.insert(set);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,16 +16,18 @@ SetsModel::~SetsModel() = default;
|
|||||||
|
|
||||||
int SetsModel::rowCount(const QModelIndex &parent) const
|
int SetsModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid()) {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
} else {
|
||||||
return sets.size();
|
return sets.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SetsModel::data(const QModelIndex &index, int role) const
|
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();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
CardSetPtr set = sets[index.row()];
|
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();
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case SortKeyCol:
|
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
|
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();
|
return QVariant();
|
||||||
|
}
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case SortKeyCol:
|
case SortKeyCol:
|
||||||
return QString("Key"); /* no tr() for translations needed, column just used for sorting --> hidden */
|
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
|
Qt::ItemFlags SetsModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid()) {
|
||||||
return Qt::NoItemFlags;
|
return Qt::NoItemFlags;
|
||||||
|
}
|
||||||
|
|
||||||
Qt::ItemFlags flags = QAbstractTableModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
Qt::ItemFlags flags = QAbstractTableModel::flags(index) | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||||
|
|
||||||
if (index.column() == EnabledCol)
|
if (index.column() == EnabledCol) {
|
||||||
flags |= Qt::ItemIsUserCheckable;
|
flags |= Qt::ItemIsUserCheckable;
|
||||||
|
}
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
@@ -115,8 +122,9 @@ Qt::DropActions SetsModel::supportedDropActions() const
|
|||||||
|
|
||||||
QMimeData *SetsModel::mimeData(const QModelIndexList &indexes) const
|
QMimeData *SetsModel::mimeData(const QModelIndexList &indexes) const
|
||||||
{
|
{
|
||||||
if (indexes.isEmpty())
|
if (indexes.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
SetsMimeData *result = new SetsMimeData(indexes[0].row());
|
SetsMimeData *result = new SetsMimeData(indexes[0].row());
|
||||||
return qobject_cast<QMimeData *>(result);
|
return qobject_cast<QMimeData *>(result);
|
||||||
@@ -128,16 +136,19 @@ bool SetsModel::dropMimeData(const QMimeData *data,
|
|||||||
int /*column*/,
|
int /*column*/,
|
||||||
const QModelIndex &parent)
|
const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
if (action != Qt::MoveAction)
|
if (action != Qt::MoveAction) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (row == -1) {
|
if (row == -1) {
|
||||||
if (!parent.isValid())
|
if (!parent.isValid()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
row = parent.row();
|
row = parent.row();
|
||||||
}
|
}
|
||||||
int oldRow = qobject_cast<const SetsMimeData *>(data)->getOldRow();
|
int oldRow = qobject_cast<const SetsMimeData *>(data)->getOldRow();
|
||||||
if (oldRow < row)
|
if (oldRow < row) {
|
||||||
row--;
|
row--;
|
||||||
|
}
|
||||||
|
|
||||||
swapRows(oldRow, row);
|
swapRows(oldRow, row);
|
||||||
|
|
||||||
@@ -148,10 +159,11 @@ void SetsModel::toggleRow(int row, bool enable)
|
|||||||
{
|
{
|
||||||
CardSetPtr temp = sets.at(row);
|
CardSetPtr temp = sets.at(row);
|
||||||
|
|
||||||
if (enable)
|
if (enable) {
|
||||||
enabledSets.insert(temp);
|
enabledSets.insert(temp);
|
||||||
else
|
} else {
|
||||||
enabledSets.remove(temp);
|
enabledSets.remove(temp);
|
||||||
|
}
|
||||||
|
|
||||||
emit dataChanged(index(row, EnabledCol), index(row, EnabledCol));
|
emit dataChanged(index(row, EnabledCol), index(row, EnabledCol));
|
||||||
}
|
}
|
||||||
@@ -160,13 +172,15 @@ void SetsModel::toggleRow(int row)
|
|||||||
{
|
{
|
||||||
CardSetPtr tmp = sets.at(row);
|
CardSetPtr tmp = sets.at(row);
|
||||||
|
|
||||||
if (tmp == nullptr)
|
if (tmp == nullptr) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (enabledSets.contains(tmp))
|
if (enabledSets.contains(tmp)) {
|
||||||
enabledSets.remove(tmp);
|
enabledSets.remove(tmp);
|
||||||
else
|
} else {
|
||||||
enabledSets.insert(tmp);
|
enabledSets.insert(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
emit dataChanged(index(row, EnabledCol), index(row, EnabledCol));
|
emit dataChanged(index(row, EnabledCol), index(row, EnabledCol));
|
||||||
}
|
}
|
||||||
@@ -175,9 +189,11 @@ void SetsModel::toggleAll(bool enabled)
|
|||||||
{
|
{
|
||||||
enabledSets.clear();
|
enabledSets.clear();
|
||||||
|
|
||||||
if (enabled)
|
if (enabled) {
|
||||||
for (CardSetPtr set : sets)
|
for (CardSetPtr set : sets) {
|
||||||
enabledSets.insert(set);
|
enabledSets.insert(set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
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 numRows = rowCount();
|
||||||
int row;
|
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));
|
setMap.insert(index(row, column).data(SetsModel::SortRole).toString(), sets.at(row));
|
||||||
|
}
|
||||||
|
|
||||||
QList<CardSetPtr> tmp = setMap.values();
|
QList<CardSetPtr> tmp = setMap.values();
|
||||||
sets.clear();
|
sets.clear();
|
||||||
@@ -253,8 +270,9 @@ void SetsModel::restore(CardDatabase *db)
|
|||||||
// enabled sets
|
// enabled sets
|
||||||
enabledSets.clear();
|
enabledSets.clear();
|
||||||
for (const CardSetPtr &set : sets) {
|
for (const CardSetPtr &set : sets) {
|
||||||
if (set->getEnabled())
|
if (set->getEnabled()) {
|
||||||
enabledSets.insert(set);
|
enabledSets.insert(set);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1));
|
||||||
|
|||||||
@@ -89,12 +89,15 @@ static inline QString toString(Type t)
|
|||||||
|
|
||||||
static inline Type fromString(const QString &s)
|
static inline Type fromString(const QString &s)
|
||||||
{
|
{
|
||||||
if (s == "Main Type")
|
if (s == "Main Type") {
|
||||||
return MAIN_TYPE;
|
return MAIN_TYPE;
|
||||||
if (s == "Mana Cost")
|
}
|
||||||
|
if (s == "Mana Cost") {
|
||||||
return MANA_COST;
|
return MANA_COST;
|
||||||
if (s == "Colors")
|
}
|
||||||
|
if (s == "Colors") {
|
||||||
return COLOR;
|
return COLOR;
|
||||||
|
}
|
||||||
return MAIN_TYPE; // default
|
return MAIN_TYPE; // default
|
||||||
}
|
}
|
||||||
} // namespace DeckListModelGroupCriteria
|
} // namespace DeckListModelGroupCriteria
|
||||||
@@ -427,8 +430,9 @@ private:
|
|||||||
|
|
||||||
template <typename T> T getNode(const QModelIndex &index) const
|
template <typename T> T getNode(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid()) {
|
||||||
return dynamic_cast<T>(root);
|
return dynamic_cast<T>(root);
|
||||||
|
}
|
||||||
return dynamic_cast<T>(static_cast<AbstractDecklistNode *>(index.internalPointer()));
|
return dynamic_cast<T>(static_cast<AbstractDecklistNode *>(index.internalPointer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -29,25 +29,29 @@ bool DeckListSortFilterProxyModel::lessThan(const QModelIndex &left, const QMode
|
|||||||
QString ln = lNode->getName();
|
QString ln = lNode->getName();
|
||||||
QString rn = rNode->getName();
|
QString rn = rNode->getName();
|
||||||
int cmp = ln.localeAwareCompare(rn);
|
int cmp = ln.localeAwareCompare(rn);
|
||||||
if (cmp != 0)
|
if (cmp != 0) {
|
||||||
return cmp < 0;
|
return cmp < 0;
|
||||||
|
}
|
||||||
} else if (crit == "cmc") {
|
} else if (crit == "cmc") {
|
||||||
int lc = lInfo ? lInfo->getCmc().toInt() : 0;
|
int lc = lInfo ? lInfo->getCmc().toInt() : 0;
|
||||||
int rc = rInfo ? rInfo->getCmc().toInt() : 0;
|
int rc = rInfo ? rInfo->getCmc().toInt() : 0;
|
||||||
if (lc != rc)
|
if (lc != rc) {
|
||||||
return lc < rc;
|
return lc < rc;
|
||||||
|
}
|
||||||
} else if (crit == "colors") {
|
} else if (crit == "colors") {
|
||||||
QString lr = lInfo ? lInfo->getColors() : QString();
|
QString lr = lInfo ? lInfo->getColors() : QString();
|
||||||
QString rr = rInfo ? rInfo->getColors() : QString();
|
QString rr = rInfo ? rInfo->getColors() : QString();
|
||||||
int cmp = lr.localeAwareCompare(rr);
|
int cmp = lr.localeAwareCompare(rr);
|
||||||
if (cmp != 0)
|
if (cmp != 0) {
|
||||||
return cmp < 0;
|
return cmp < 0;
|
||||||
|
}
|
||||||
} else if (crit == "maintype") {
|
} else if (crit == "maintype") {
|
||||||
QString lr = lInfo ? lInfo->getMainCardType() : QString();
|
QString lr = lInfo ? lInfo->getMainCardType() : QString();
|
||||||
QString rr = rInfo ? rInfo->getMainCardType() : QString();
|
QString rr = rInfo ? rInfo->getMainCardType() : QString();
|
||||||
int cmp = lr.localeAwareCompare(rr);
|
int cmp = lr.localeAwareCompare(rr);
|
||||||
if (cmp != 0)
|
if (cmp != 0) {
|
||||||
return cmp < 0;
|
return cmp < 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ protected:
|
|||||||
inline OracleWizard *wizard()
|
inline OracleWizard *wizard()
|
||||||
{
|
{
|
||||||
return (OracleWizard *)QWizardPage::wizard();
|
return (OracleWizard *)QWizardPage::wizard();
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SimpleDownloadFilePage : public OracleWizardPage
|
class SimpleDownloadFilePage : public OracleWizardPage
|
||||||
|
|||||||
Reference in New Issue
Block a user