This commit is contained in:
Bryce! 2026-11-04 15:22:32 +01:00 • committed by GitHub
commit ee603a8954
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 10 deletions

View file

@ -21,12 +21,14 @@
#include <QCheckBox>
#include <QDebug>
#include <QHBoxLayout>
#include <QHideEvent>
#include <QList>
#include <QMap>
#include <QScrollArea>
#include <QScrollBar>
#include <QSharedPointer>
#include <QSizePolicy>
#include <QShowEvent>
#include <QString>
#include <QTimer>
#include <QVBoxLayout>
@ -54,6 +56,9 @@ PrintingSelector::PrintingSelector(QWidget *parent, AbstractTabDeckEditor *_deck
setLayout(layout);
widgetLoadingBufferTimer = new QTimer(this);
deckChangeTimer = new QTimer(this);
deckChangeTimer->setSingleShot(true);
connect(deckChangeTimer, &QTimer::timeout, this, &PrintingSelector::updateDisplay);
flowWidget = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
@ -122,9 +127,34 @@ void PrintingSelector::retranslateUi()
void PrintingSelector::printingsInDeckChanged()
{
if (SettingsCache::instance().cardsDisplay().getBumpSetsWithCardsInDeckToTop()) {
// Delay the update to avoid race conditions
QTimer::singleShot(100, this, &PrintingSelector::updateDisplay);
displayDirty = true;
if (isVisible()) {
// Coalesce deck changes while the model settles.
deckChangeTimer->start(100);
} else {
widgetLoadingBufferTimer->stop();
}
}
}
void PrintingSelector::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
if (displayDirty) {
updateDisplay();
}
}
void PrintingSelector::hideEvent(QHideEvent *event)
{
// A partially built batch must be rebuilt on reveal, not resumed with
// stale printing data after the selected card or deck changes.
if (widgetLoadingBufferTimer->isActive() || deckChangeTimer->isActive()) {
widgetLoadingBufferTimer->stop();
deckChangeTimer->stop();
displayDirty = true;
}
QWidget::hideEvent(event);
}
/**
@ -173,6 +203,8 @@ void PrintingSelector::updateCardAmounts()
*/
void PrintingSelector::updateDisplay()
{
deckChangeTimer->stop();
displayDirty = false;
widgetLoadingBufferTimer->stop();
widgetLoadingBufferTimer->deleteLater();
widgetLoadingBufferTimer = new QTimer(this);
@ -199,20 +231,18 @@ void PrintingSelector::updateDisplay()
*/
void PrintingSelector::setCard(const CardInfoPtr &newCard)
{
if (newCard.isNull()) {
selectedCard = newCard;
updateDisplay();
return;
}
// we don't need to redraw the widget if the card is the same
if (!selectedCard.isNull() && selectedCard->getName() == newCard->getName()) {
// Same-name cards may be different database snapshots after a reload.
if (selectedCard == newCard) {
return;
}
widgetLoadingBufferTimer->stop();
deckChangeTimer->stop();
selectedCard = newCard;
if (isVisible()) {
updateDisplay();
} else {
displayDirty = true;
}
flowWidget->setMinimumSizeToMaxSizeHint();
flowWidget->scrollArea->verticalScrollBar()->setValue(0);

View file

@ -18,6 +18,8 @@ class QCheckBox;
class QHBoxLayout;
class QString;
class QTimer;
class QShowEvent;
class QHideEvent;
class QVBoxLayout;
class SettingsButtonWidget;
template <class Key, class T> class QMap;
@ -47,6 +49,10 @@ public:
void setCard(const CardInfoPtr &newCard);
void getAllSetsForCurrentCard();
protected:
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
public slots:
void retranslateUi();
void updateDisplay();
@ -88,6 +94,8 @@ private:
DeckStateManager *deckStateManager;
CardInfoPtr selectedCard;
QTimer *widgetLoadingBufferTimer;
QTimer *deckChangeTimer;
bool displayDirty = false;
int currentIndex = 0;
};