Allow non-db cards to be moved around (#2960)

This commit is contained in:
Zach H 2017-12-18 14:17:54 -05:00 committed by GitHub
parent 2abfd3b4a9
commit b75882b6b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 21 deletions

View file

@ -264,11 +264,44 @@ QModelIndex DeckListModel::findCard(const QString &cardName, const QString &zone
return nodeToIndex(cardNode); return nodeToIndex(cardNode);
} }
QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName) QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName, bool abAddAnyway)
{ {
CardInfo *info = db->getCard(cardName); CardInfo *info = db->getCard(cardName);
if (info == nullptr) 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
{
return QModelIndex(); return QModelIndex();
}
}
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root); InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);

View file

@ -44,7 +44,7 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role); bool setData(const QModelIndex &index, const QVariant &value, int role);
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
QModelIndex findCard(const QString &cardName, const QString &zoneName) const; QModelIndex findCard(const QString &cardName, const QString &zoneName) const;
QModelIndex addCard(const QString &cardName, const QString &zoneName); QModelIndex addCard(const QString &cardName, const QString &zoneName, bool abAddAnyway = false);
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
void cleanList(); void cleanList();
DeckLoader *getDeckList() const { return deckList; } DeckLoader *getDeckList() const { return deckList; }

View file

@ -876,15 +876,16 @@ void TabDeckEditor::actSwapCard()
return; return;
const QString cardName = currentIndex.sibling(currentIndex.row(), 1).data().toString(); const QString cardName = currentIndex.sibling(currentIndex.row(), 1).data().toString();
const QModelIndex gparent = currentIndex.parent().parent(); const QModelIndex gparent = currentIndex.parent().parent();
if (!gparent.isValid()) if (!gparent.isValid())
return; return;
const QString zoneName = gparent.sibling(gparent.row(), 1).data().toString(); const QString zoneName = gparent.sibling(gparent.row(), 1).data().toString();
actDecrement(); actDecrement();
const QString otherZoneName = zoneName == "Maindeck" ? DECK_ZONE_SIDE : DECK_ZONE_MAIN; const QString otherZoneName = zoneName == "Maindeck" ? DECK_ZONE_SIDE : DECK_ZONE_MAIN;
QModelIndex newCardIndex = deckModel->addCard(cardName, otherZoneName); // Third argument (true) says create the card no mater what, even if not in DB
QModelIndex newCardIndex = deckModel->addCard(cardName, otherZoneName, true);
recursiveExpand(newCardIndex); recursiveExpand(newCardIndex);
setModified(true); setModified(true);