mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Block updates, don't validate cardInfo and use ItemModel instead of looped addItem.
This commit is contained in:
parent
adaa31b34d
commit
b960e9edbf
1 changed files with 16 additions and 7 deletions
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
#include <QStandardItemModel>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
DeckPreviewWidget::DeckPreviewWidget(QWidget *_parent,
|
DeckPreviewWidget::DeckPreviewWidget(QWidget *_parent,
|
||||||
|
|
@ -27,6 +28,8 @@ DeckPreviewWidget::DeckPreviewWidget(QWidget *_parent,
|
||||||
deckLoader = new DeckLoader();
|
deckLoader = new DeckLoader();
|
||||||
deckLoader->setParent(this);
|
deckLoader->setParent(this);
|
||||||
connect(deckLoader, &DeckLoader::loadFinished, this, &DeckPreviewWidget::initializeUi);
|
connect(deckLoader, &DeckLoader::loadFinished, this, &DeckPreviewWidget::initializeUi);
|
||||||
|
/* TODO: We shouldn't update the tags on *every* deck load, since it's kinda expensive. We should instead count how
|
||||||
|
many deck loads have finished already and if we've loaded all decks and THEN load all the tags at once. */
|
||||||
connect(deckLoader, &DeckLoader::loadFinished, visualDeckStorageWidget->tagFilterWidget,
|
connect(deckLoader, &DeckLoader::loadFinished, visualDeckStorageWidget->tagFilterWidget,
|
||||||
&VisualDeckStorageTagFilterWidget::refreshTags);
|
&VisualDeckStorageTagFilterWidget::refreshTags);
|
||||||
deckLoader->loadFromFileAsync(filePath, DeckLoader::getFormatFromName(filePath), false);
|
deckLoader->loadFromFileAsync(filePath, DeckLoader::getFormatFromName(filePath), false);
|
||||||
|
|
@ -194,6 +197,7 @@ void DeckPreviewWidget::updateBannerCardComboBox()
|
||||||
|
|
||||||
// Block signals temporarily
|
// Block signals temporarily
|
||||||
bool wasBlocked = bannerCardComboBox->blockSignals(true);
|
bool wasBlocked = bannerCardComboBox->blockSignals(true);
|
||||||
|
bannerCardComboBox->setUpdatesEnabled(false);
|
||||||
|
|
||||||
// Clear the existing items in the combo box
|
// Clear the existing items in the combo box
|
||||||
bannerCardComboBox->clear();
|
bannerCardComboBox->clear();
|
||||||
|
|
@ -209,12 +213,7 @@ void DeckPreviewWidget::updateBannerCardComboBox()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||||
CardInfoPtr info = CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
bannerCardSet.insert(QPair<QString, QString>(currentCard->getName(), currentCard->getCardProviderId()));
|
||||||
currentCard->getName(), currentCard->getCardProviderId());
|
|
||||||
if (info) {
|
|
||||||
bannerCardSet.insert(
|
|
||||||
QPair<QString, QString>(currentCard->getName(), currentCard->getCardProviderId()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -226,14 +225,23 @@ void DeckPreviewWidget::updateBannerCardComboBox()
|
||||||
return a.first.toLower() < b.first.toLower();
|
return a.first.toLower() < b.first.toLower();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// This is *slightly* more performant than using addItem in a loop.
|
||||||
|
|
||||||
|
QStandardItemModel *model = new QStandardItemModel(pairList.size(), 1, bannerCardComboBox);
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
for (const auto &pair : pairList) {
|
for (const auto &pair : pairList) {
|
||||||
QVariantMap dataMap;
|
QVariantMap dataMap;
|
||||||
dataMap["name"] = pair.first;
|
dataMap["name"] = pair.first;
|
||||||
dataMap["uuid"] = pair.second;
|
dataMap["uuid"] = pair.second;
|
||||||
|
|
||||||
bannerCardComboBox->addItem(pair.first, dataMap);
|
QStandardItem *item = new QStandardItem(pair.first);
|
||||||
|
item->setData(dataMap, Qt::UserRole);
|
||||||
|
model->setItem(row++, 0, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bannerCardComboBox->setModel(model);
|
||||||
|
|
||||||
// Try to restore the previous selection by finding the currentText
|
// Try to restore the previous selection by finding the currentText
|
||||||
int restoredIndex = bannerCardComboBox->findText(currentText);
|
int restoredIndex = bannerCardComboBox->findText(currentText);
|
||||||
if (restoredIndex != -1) {
|
if (restoredIndex != -1) {
|
||||||
|
|
@ -251,6 +259,7 @@ void DeckPreviewWidget::updateBannerCardComboBox()
|
||||||
|
|
||||||
// Restore the previous signal blocking state
|
// Restore the previous signal blocking state
|
||||||
bannerCardComboBox->blockSignals(wasBlocked);
|
bannerCardComboBox->blockSignals(wasBlocked);
|
||||||
|
bannerCardComboBox->setUpdatesEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckPreviewWidget::setBannerCard(int /* changedIndex */)
|
void DeckPreviewWidget::setBannerCard(int /* changedIndex */)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue