mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 05:23:56 -07:00
VDS performance fixes (#5848)
* Block updates, don't validate cardInfo and use ItemModel instead of looped addItem. * Change to QVariant map directly. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
a35707ae18
commit
2fe639676b
1 changed files with 19 additions and 14 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,19 @@ void DeckPreviewWidget::updateBannerCardComboBox()
|
||||||
return a.first.toLower() < b.first.toLower();
|
return a.first.toLower() < b.first.toLower();
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const auto &pair : pairList) {
|
// This is *slightly* more performant than using addItem in a loop.
|
||||||
QVariantMap dataMap;
|
|
||||||
dataMap["name"] = pair.first;
|
|
||||||
dataMap["uuid"] = pair.second;
|
|
||||||
|
|
||||||
bannerCardComboBox->addItem(pair.first, dataMap);
|
QStandardItemModel *model = new QStandardItemModel(pairList.size(), 1, bannerCardComboBox);
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
for (const auto &pair : pairList) {
|
||||||
|
QStandardItem *item = new QStandardItem(pair.first);
|
||||||
|
item->setData(QVariant::fromValue(pair), 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,15 +255,16 @@ 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 */)
|
||||||
{
|
{
|
||||||
QVariantMap itemData = bannerCardComboBox->itemData(bannerCardComboBox->currentIndex()).toMap();
|
QVariant itemData = bannerCardComboBox->itemData(bannerCardComboBox->currentIndex());
|
||||||
deckLoader->setBannerCard(QPair<QString, QString>(itemData["name"].toString(), itemData["uuid"].toString()));
|
deckLoader->setBannerCard(QPair<QString, QString>(bannerCardComboBox->currentText(), itemData.toString()));
|
||||||
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath));
|
deckLoader->saveToFile(filePath, DeckLoader::getFormatFromName(filePath));
|
||||||
bannerCardDisplayWidget->setCard(CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
bannerCardDisplayWidget->setCard(CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
|
||||||
itemData["name"].toString(), itemData["uuid"].toString()));
|
bannerCardComboBox->currentText(), itemData.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
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