Allow non-db cards to be moved around (#2960)
This commit is contained in:
parent
2abfd3b4a9
commit
b75882b6b9
3 changed files with 55 additions and 21 deletions
|
@ -264,11 +264,44 @@ QModelIndex DeckListModel::findCard(const QString &cardName, const QString &zone
|
|||
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);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
||||
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 cleanList();
|
||||
DeckLoader *getDeckList() const { return deckList; }
|
||||
|
|
|
@ -876,15 +876,16 @@ void TabDeckEditor::actSwapCard()
|
|||
return;
|
||||
const QString cardName = currentIndex.sibling(currentIndex.row(), 1).data().toString();
|
||||
const QModelIndex gparent = currentIndex.parent().parent();
|
||||
|
||||
if (!gparent.isValid())
|
||||
return;
|
||||
|
||||
const QString zoneName = gparent.sibling(gparent.row(), 1).data().toString();
|
||||
actDecrement();
|
||||
|
||||
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);
|
||||
|
||||
setModified(true);
|
||||
|
|
Loading…
Reference in a new issue