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; }
|
||||||
|
|
|
@ -132,7 +132,7 @@ void TabDeckEditor::createCardInfoDock()
|
||||||
cardInfoFrame->addWidget(cardInfo);
|
cardInfoFrame->addWidget(cardInfo);
|
||||||
|
|
||||||
cardInfoDock = new QDockWidget(this);
|
cardInfoDock = new QDockWidget(this);
|
||||||
cardInfoDock->setObjectName("cardInfoDock");
|
cardInfoDock->setObjectName("cardInfoDock");
|
||||||
|
|
||||||
cardInfoDock->setMinimumSize(QSize(200, 41));
|
cardInfoDock->setMinimumSize(QSize(200, 41));
|
||||||
cardInfoDock->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);
|
cardInfoDock->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);
|
||||||
|
@ -142,7 +142,7 @@ void TabDeckEditor::createCardInfoDock()
|
||||||
cardInfoDockContents->setLayout(cardInfoFrame);
|
cardInfoDockContents->setLayout(cardInfoFrame);
|
||||||
cardInfoDock->setWidget(cardInfoDockContents);
|
cardInfoDock->setWidget(cardInfoDockContents);
|
||||||
|
|
||||||
cardInfoDock->installEventFilter(this);
|
cardInfoDock->installEventFilter(this);
|
||||||
connect(cardInfoDock, SIGNAL(topLevelChanged(bool)), this, SLOT(dockTopLevelChanged(bool)));
|
connect(cardInfoDock, SIGNAL(topLevelChanged(bool)), this, SLOT(dockTopLevelChanged(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ void TabDeckEditor::createFiltersDock()
|
||||||
QWidget *filterDockContents = new QWidget(this);
|
QWidget *filterDockContents = new QWidget(this);
|
||||||
filterDockContents->setObjectName("filterDockContents");
|
filterDockContents->setObjectName("filterDockContents");
|
||||||
filterDockContents->setLayout(filterFrame);
|
filterDockContents->setLayout(filterFrame);
|
||||||
filterDock->setWidget(filterDockContents);
|
filterDock->setWidget(filterDockContents);
|
||||||
|
|
||||||
filterDock->installEventFilter(this);
|
filterDock->installEventFilter(this);
|
||||||
connect(filterDock, SIGNAL(topLevelChanged(bool)), this, SLOT(dockTopLevelChanged(bool)));
|
connect(filterDock, SIGNAL(topLevelChanged(bool)), this, SLOT(dockTopLevelChanged(bool)));
|
||||||
|
@ -331,7 +331,7 @@ void TabDeckEditor::createCentralFrame()
|
||||||
connect(&searchKeySignals, SIGNAL(onCtrlAltMinus()), this, SLOT(actDecrementCard()));
|
connect(&searchKeySignals, SIGNAL(onCtrlAltMinus()), this, SLOT(actDecrementCard()));
|
||||||
connect(&searchKeySignals, SIGNAL(onCtrlAltLBracket()), this, SLOT(actDecrementCardFromSideboard()));
|
connect(&searchKeySignals, SIGNAL(onCtrlAltLBracket()), this, SLOT(actDecrementCardFromSideboard()));
|
||||||
connect(&searchKeySignals, SIGNAL(onCtrlAltEnter()), this, SLOT(actAddCardToSideboard()));
|
connect(&searchKeySignals, SIGNAL(onCtrlAltEnter()), this, SLOT(actAddCardToSideboard()));
|
||||||
connect(&searchKeySignals, SIGNAL(onCtrlEnter()), this, SLOT(actAddCardToSideboard()));
|
connect(&searchKeySignals, SIGNAL(onCtrlEnter()), this, SLOT(actAddCardToSideboard()));
|
||||||
|
|
||||||
databaseModel = new CardDatabaseModel(db, true, this);
|
databaseModel = new CardDatabaseModel(db, true, this);
|
||||||
databaseModel->setObjectName("databaseModel");
|
databaseModel->setObjectName("databaseModel");
|
||||||
|
@ -521,7 +521,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
||||||
|
|
||||||
restartLayout();
|
restartLayout();
|
||||||
|
|
||||||
this->installEventFilter(this);
|
this->installEventFilter(this);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
connect(&settingsCache->shortcuts(), SIGNAL(shortCutchanged()),this,SLOT(refreshShortcuts()));
|
connect(&settingsCache->shortcuts(), SIGNAL(shortCutchanged()),this,SLOT(refreshShortcuts()));
|
||||||
|
@ -541,7 +541,7 @@ void TabDeckEditor::retranslateUi()
|
||||||
|
|
||||||
aClearFilterAll->setText(tr("&Clear all filters"));
|
aClearFilterAll->setText(tr("&Clear all filters"));
|
||||||
aClearFilterOne->setText(tr("Delete selected"));
|
aClearFilterOne->setText(tr("Delete selected"));
|
||||||
|
|
||||||
nameLabel->setText(tr("Deck &name:"));
|
nameLabel->setText(tr("Deck &name:"));
|
||||||
commentsLabel->setText(tr("&Comments:"));
|
commentsLabel->setText(tr("&Comments:"));
|
||||||
hashLabel1->setText(tr("Hash:"));
|
hashLabel1->setText(tr("Hash:"));
|
||||||
|
@ -560,7 +560,7 @@ void TabDeckEditor::retranslateUi()
|
||||||
aAnalyzeDeckTappedout->setText(tr("Analyze deck (tappedout.net)"));
|
aAnalyzeDeckTappedout->setText(tr("Analyze deck (tappedout.net)"));
|
||||||
|
|
||||||
aClose->setText(tr("&Close"));
|
aClose->setText(tr("&Close"));
|
||||||
|
|
||||||
aAddCard->setText(tr("Add card to &maindeck"));
|
aAddCard->setText(tr("Add card to &maindeck"));
|
||||||
aAddCardToSideboard->setText(tr("Add card to &sideboard"));
|
aAddCardToSideboard->setText(tr("Add card to &sideboard"));
|
||||||
|
|
||||||
|
@ -569,7 +569,7 @@ void TabDeckEditor::retranslateUi()
|
||||||
aIncrement->setText(tr("&Increment number"));
|
aIncrement->setText(tr("&Increment number"));
|
||||||
|
|
||||||
aDecrement->setText(tr("&Decrement number"));
|
aDecrement->setText(tr("&Decrement number"));
|
||||||
|
|
||||||
deckMenu->setTitle(tr("&Deck Editor"));
|
deckMenu->setTitle(tr("&Deck Editor"));
|
||||||
|
|
||||||
cardInfoDock->setWindowTitle(tr("Card Info"));
|
cardInfoDock->setWindowTitle(tr("Card Info"));
|
||||||
|
@ -682,7 +682,7 @@ void TabDeckEditor::actLoadDeck()
|
||||||
|
|
||||||
QString fileName = dialog.selectedFiles().at(0);
|
QString fileName = dialog.selectedFiles().at(0);
|
||||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
||||||
|
|
||||||
DeckLoader *l = new DeckLoader;
|
DeckLoader *l = new DeckLoader;
|
||||||
if (l->loadFromFile(fileName, fmt))
|
if (l->loadFromFile(fileName, fmt))
|
||||||
setDeck(l);
|
setDeck(l);
|
||||||
|
@ -705,11 +705,11 @@ bool TabDeckEditor::actSaveDeck()
|
||||||
Command_DeckUpload cmd;
|
Command_DeckUpload cmd;
|
||||||
cmd.set_deck_id(deck->getLastRemoteDeckId());
|
cmd.set_deck_id(deck->getLastRemoteDeckId());
|
||||||
cmd.set_deck_list(deck->writeToString_Native().toStdString());
|
cmd.set_deck_list(deck->writeToString_Native().toStdString());
|
||||||
|
|
||||||
PendingCommand *pend = AbstractClient::prepareSessionCommand(cmd);
|
PendingCommand *pend = AbstractClient::prepareSessionCommand(cmd);
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(saveDeckRemoteFinished(Response)));
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(saveDeckRemoteFinished(Response)));
|
||||||
tabSupervisor->getClient()->sendCommand(pend);
|
tabSupervisor->getClient()->sendCommand(pend);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (deck->getLastFileName().isEmpty())
|
} else if (deck->getLastFileName().isEmpty())
|
||||||
return actSaveDeckAs();
|
return actSaveDeckAs();
|
||||||
|
@ -748,11 +748,11 @@ void TabDeckEditor::actLoadDeckFromClipboard()
|
||||||
{
|
{
|
||||||
if (!confirmClose())
|
if (!confirmClose())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DlgLoadDeckFromClipboard dlg;
|
DlgLoadDeckFromClipboard dlg;
|
||||||
if (!dlg.exec())
|
if (!dlg.exec())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setDeck(dlg.getDeckList());
|
setDeck(dlg.getDeckList());
|
||||||
setModified(true);
|
setModified(true);
|
||||||
}
|
}
|
||||||
|
@ -848,7 +848,7 @@ CardInfo *TabDeckEditor::currentCardInfo() const
|
||||||
if (!currentIndex.isValid())
|
if (!currentIndex.isValid())
|
||||||
return NULL;
|
return NULL;
|
||||||
const QString cardName = currentIndex.sibling(currentIndex.row(), 0).data().toString();
|
const QString cardName = currentIndex.sibling(currentIndex.row(), 0).data().toString();
|
||||||
|
|
||||||
return db->getCard(cardName);
|
return db->getCard(cardName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -1036,7 +1037,7 @@ bool TabDeckEditor::eventFilter(QObject * o, QEvent * e)
|
||||||
aFilterDockVisible->setChecked(false);
|
aFilterDockVisible->setChecked(false);
|
||||||
aFilterDockFloating->setEnabled(false);
|
aFilterDockFloating->setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( o == this && e->type() == QEvent::Hide){
|
if( o == this && e->type() == QEvent::Hide){
|
||||||
settingsCache->layouts().setDeckEditorLayoutState(saveState());
|
settingsCache->layouts().setDeckEditorLayoutState(saveState());
|
||||||
settingsCache->layouts().setDeckEditorGeometry(saveGeometry());
|
settingsCache->layouts().setDeckEditorGeometry(saveGeometry());
|
||||||
|
|
Loading…
Reference in a new issue