Reintroduce some changes lost in the merge.

This commit is contained in:
Lukas Brübach 2024-11-06 09:31:44 +01:00
parent 502c901c06
commit c6a7b17d22
3 changed files with 55 additions and 26 deletions

View file

@ -79,24 +79,24 @@ int DeckListModel::rowCount(const QModelIndex &parent) const
int DeckListModel::columnCount(const QModelIndex & /*parent*/) const int DeckListModel::columnCount(const QModelIndex & /*parent*/) const
{ {
return 2; return 4;
} }
QVariant DeckListModel::data(const QModelIndex &index, int role) const QVariant DeckListModel::data(const QModelIndex &index, int role) const
{ {
// debugIndexInfo("data", index); // debugIndexInfo("data", index);
if (!index.isValid()) { if (!index.isValid()) {
return QVariant(); return {};
} }
if (index.column() >= columnCount()) { if (index.column() >= columnCount()) {
return QVariant(); return {};
} }
auto *temp = static_cast<AbstractDecklistNode *>(index.internalPointer()); auto *temp = static_cast<AbstractDecklistNode *>(index.internalPointer());
auto *card = dynamic_cast<DecklistModelCardNode *>(temp); auto *card = dynamic_cast<DecklistModelCardNode *>(temp);
if (card == nullptr) { if (card == nullptr) {
auto *node = dynamic_cast<InnerDecklistNode *>(temp); const auto *node = dynamic_cast<InnerDecklistNode *>(temp);
switch (role) { switch (role) {
case Qt::FontRole: { case Qt::FontRole: {
QFont f; QFont f;
@ -108,13 +108,19 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
switch (index.column()) { switch (index.column()) {
case 0: case 0:
return node->recursiveCount(true); return node->recursiveCount(true);
case 1: case 1: {
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
return node->getVisibleName(); return node->getVisibleName();
else
return node->getName(); return node->getName();
}
case 2: {
return node->getCardUuid();
}
case 3: {
return node->getCardCollectorNumber();
}
default: default:
return QVariant(); return {};
} }
} }
case Qt::BackgroundRole: { case Qt::BackgroundRole: {
@ -125,7 +131,7 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
return QBrush(QColor(0, 0, 0)); return QBrush(QColor(0, 0, 0));
} }
default: default:
return QVariant(); return {};
} }
} else { } else {
switch (role) { switch (role) {
@ -136,8 +142,12 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
return card->getNumber(); return card->getNumber();
case 1: case 1:
return card->getName(); return card->getName();
case 2:
return card->getCardUuid();
case 3:
return card->getCardCollectorNumber();
default: default:
return QVariant(); return {};
} }
} }
case Qt::BackgroundRole: { case Qt::BackgroundRole: {
@ -148,28 +158,32 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
return QBrush(QColor(0, 0, 0)); return QBrush(QColor(0, 0, 0));
} }
default: default:
return QVariant(); return {};
} }
} }
} }
QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant DeckListModel::headerData(const int section, const Qt::Orientation orientation, const int role) const
{ {
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal)) { if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal)) {
return QVariant(); return {};
} }
if (section >= columnCount()) { if (section >= columnCount()) {
return QVariant(); return {};
} }
switch (section) { switch (section) {
case 0: case 0:
return tr("Number"); return tr("Count");
case 1: case 1:
return tr("Card"); return tr("Card");
case 2:
return tr("Set");
case 3:
return tr("Number");
default: default:
return QVariant(); return {};
} }
} }
@ -215,7 +229,7 @@ void DeckListModel::emitRecursiveUpdates(const QModelIndex &index)
emitRecursiveUpdates(index.parent()); emitRecursiveUpdates(index.parent());
} }
bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int role) bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, const int role)
{ {
auto *node = getNode<DecklistModelCardNode *>(index); auto *node = getNode<DecklistModelCardNode *>(index);
if (!node || (role != Qt::EditRole)) { if (!node || (role != Qt::EditRole)) {
@ -229,6 +243,12 @@ bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int
case 1: case 1:
node->setName(value.toString()); node->setName(value.toString());
break; break;
case 2:
node->setCardSetCode(value.toString());
break;
case 3:
node->setCardCollectorNumber(value.toString());
break;
default: default:
return false; return false;
} }
@ -318,14 +338,16 @@ QModelIndex DeckListModel::findCard(const QString &cardName, const QString &zone
QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName, bool abAddAnyway) QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName, bool abAddAnyway)
{ {
CardInfoPtr info = CardDatabaseManager::getInstance()->getCard(cardName); CardInfoPtr cardInfo = CardDatabaseManager::getInstance()->getCard(cardName);
if (info == nullptr) { CardInfoPerSet cardInfoSet = CardDatabaseManager::getInstance()->getPreferredSetForCard(cardName);
if (cardInfo == nullptr) {
if (abAddAnyway) { if (abAddAnyway) {
// We need to keep this card added no matter what // We need to keep this card added no matter what
// This is usually called from tab_deck_editor // This is usually called from tab_deck_editor
// So we'll create a new CardInfo with the name // So we'll create a new CardInfo with the name
// and default values for all fields // and default values for all fields
info = CardInfo::newInstance(cardName); cardInfo = CardInfo::newInstance(cardName);
} else { } else {
return {}; return {};
} }
@ -333,18 +355,21 @@ QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneN
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root); InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
QString cardType = info->getMainCardType(); const QString cardType = cardInfo->getMainCardType();
InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode); InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode);
QModelIndex parentIndex = nodeToIndex(cardTypeNode); const QModelIndex parentIndex = nodeToIndex(cardTypeNode);
auto *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName)); auto *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName));
if (!cardNode) { if (!cardNode) {
DecklistCardNode *decklistCard = deckList->addCard(cardName, zoneName); auto *decklistCard = deckList->addCard(
beginInsertRows(parentIndex, cardTypeNode->size(), cardTypeNode->size()); cardInfo->getName(), zoneName, cardInfoSet.getProperty("uuid"), cardInfoSet.getProperty("num"));
beginInsertRows(parentIndex, static_cast<int>(cardTypeNode->size()), static_cast<int>(cardTypeNode->size()));
cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode); cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode);
endInsertRows(); endInsertRows();
} else { } else {
cardNode->setNumber(cardNode->getNumber() + 1); cardNode->setNumber(cardNode->getNumber() + 1);
cardNode->setCardSetCode(cardInfoSet.getProperty("uuid"));
cardNode->setCardCollectorNumber(cardInfoSet.getProperty("num"));
deckList->updateDeckHash(); deckList->updateDeckHash();
} }
sort(lastKnownColumn, lastKnownOrder); sort(lastKnownColumn, lastKnownOrder);

View file

@ -444,6 +444,10 @@ QList<CardInfoPtr> CardDatabase::getCards(const QStringList &cardNames) const
CardInfoPtr CardDatabase::getCardByNameAndUUID(const QString &cardName, const QString &uuid) const CardInfoPtr CardDatabase::getCardByNameAndUUID(const QString &cardName, const QString &uuid) const
{ {
auto info = getCard(cardName); auto info = getCard(cardName);
if (uuid.isNull() || uuid.isEmpty()) {
return info;
}
for (const auto &set : info->getSets()) { for (const auto &set : info->getSets()) {
if (set.getProperty("uuid") == uuid) { if (set.getProperty("uuid") == uuid) {
CardInfoPtr cardFromSpecificSet = info->clone(); CardInfoPtr cardFromSpecificSet = info->clone();

View file

@ -414,8 +414,6 @@ protected:
private: private:
CardInfoPtr getCardFromMap(const CardNameMap &cardMap, const QString &cardName) const; CardInfoPtr getCardFromMap(const CardNameMap &cardMap, const QString &cardName) const;
void checkUnknownSets(); void checkUnknownSets();
CardInfoPerSet getPreferredSetForCard(const QString &cardName);
QString getPreferredPrintingUUIDForCard(const QString &cardName);
void refreshCachedReverseRelatedCards(); void refreshCachedReverseRelatedCards();
QBasicMutex *reloadDatabaseMutex = new QBasicMutex(), *clearDatabaseMutex = new QBasicMutex(), QBasicMutex *reloadDatabaseMutex = new QBasicMutex(), *clearDatabaseMutex = new QBasicMutex(),
@ -432,6 +430,8 @@ public:
CardInfoPtr getCard(const QString &cardName) const; CardInfoPtr getCard(const QString &cardName) const;
QList<CardInfoPtr> getCards(const QStringList &cardNames) const; QList<CardInfoPtr> getCards(const QStringList &cardNames) const;
CardInfoPtr getCardByNameAndUUID(const QString &cardName, const QString &uuid) const; CardInfoPtr getCardByNameAndUUID(const QString &cardName, const QString &uuid) const;
CardInfoPerSet getPreferredSetForCard(const QString &cardName);
QString getPreferredPrintingUUIDForCard(const QString &cardName);
CardInfoPtr guessCard(const QString &cardName) const; CardInfoPtr guessCard(const QString &cardName) const;
/* /*