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);
|
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)
|
||||||
return QModelIndex();
|
{
|
||||||
|
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);
|
InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
DeckListModel(QObject *parent = 0);
|
DeckListModel(QObject *parent = 0);
|
||||||
~DeckListModel();
|
~DeckListModel();
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
@ -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; }
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue