mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
Refactor banner card ComboBox (#5947)
This commit is contained in:
parent
b270562a44
commit
46643065ef
2 changed files with 8 additions and 13 deletions
|
|
@ -303,11 +303,7 @@ void DeckEditorDeckDockWidget::updateBannerCardComboBox()
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const auto &pair : pairList) {
|
for (const auto &pair : pairList) {
|
||||||
QVariantMap dataMap;
|
bannerCardComboBox->addItem(pair.first, QVariant::fromValue(pair));
|
||||||
dataMap["name"] = pair.first;
|
|
||||||
dataMap["uuid"] = pair.second;
|
|
||||||
|
|
||||||
bannerCardComboBox->addItem(pair.first, dataMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to restore the previous selection by finding the currentText
|
// Try to restore the previous selection by finding the currentText
|
||||||
|
|
@ -315,7 +311,7 @@ void DeckEditorDeckDockWidget::updateBannerCardComboBox()
|
||||||
if (restoredIndex != -1) {
|
if (restoredIndex != -1) {
|
||||||
bannerCardComboBox->setCurrentIndex(restoredIndex);
|
bannerCardComboBox->setCurrentIndex(restoredIndex);
|
||||||
if (deckModel->getDeckList()->getBannerCard().second !=
|
if (deckModel->getDeckList()->getBannerCard().second !=
|
||||||
bannerCardComboBox->itemData(bannerCardComboBox->currentIndex()).toMap()["uuid"].toString()) {
|
bannerCardComboBox->currentData().value<QPair<QString, QString>>().second) {
|
||||||
setBannerCard(restoredIndex);
|
setBannerCard(restoredIndex);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -335,9 +331,8 @@ void DeckEditorDeckDockWidget::updateBannerCardComboBox()
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::setBannerCard(int /* changedIndex */)
|
void DeckEditorDeckDockWidget::setBannerCard(int /* changedIndex */)
|
||||||
{
|
{
|
||||||
QVariantMap itemData = bannerCardComboBox->itemData(bannerCardComboBox->currentIndex()).toMap();
|
auto cardAndId = bannerCardComboBox->currentData().value<QPair<QString, QString>>();
|
||||||
deckModel->getDeckList()->setBannerCard(
|
deckModel->getDeckList()->setBannerCard(cardAndId);
|
||||||
QPair<QString, QString>(itemData["name"].toString(), itemData["uuid"].toString()));
|
|
||||||
emit deckModified();
|
emit deckModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -282,11 +282,11 @@ void DeckPreviewWidget::updateBannerCardComboBox()
|
||||||
|
|
||||||
void DeckPreviewWidget::setBannerCard(int /* changedIndex */)
|
void DeckPreviewWidget::setBannerCard(int /* changedIndex */)
|
||||||
{
|
{
|
||||||
QVariant itemData = bannerCardComboBox->itemData(bannerCardComboBox->currentIndex());
|
auto nameAndId = bannerCardComboBox->currentData().value<QPair<QString, QString>>();
|
||||||
deckLoader->setBannerCard(QPair<QString, QString>(bannerCardComboBox->currentText(), itemData.toString()));
|
deckLoader->setBannerCard(nameAndId);
|
||||||
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath));
|
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath));
|
||||||
bannerCardDisplayWidget->setCard(CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
bannerCardDisplayWidget->setCard(
|
||||||
bannerCardComboBox->currentText(), itemData.toString()));
|
CardDatabaseManager::getInstance()->getCardByNameAndProviderId(nameAndId.first, nameAndId.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckPreviewWidget::imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
void DeckPreviewWidget::imageClickedEvent(QMouseEvent *event, DeckPreviewCardPictureWidget *instance)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue