From 68226786a26a6324c5d63ad853cc740568c50824 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:49:54 -0800 Subject: [PATCH] don't redraw PrintingSelector's FlowWidget unless cards actually changed (#5392) --- .../printing_selector/printing_selector.cpp | 18 ++++++++++++++---- .../printing_selector/printing_selector.h | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.cpp b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.cpp index 33f76ada7..9943b9403 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.cpp +++ b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.cpp @@ -57,10 +57,14 @@ PrintingSelector::PrintingSelector(QWidget *parent, layout->addWidget(cardSelectionBar); // Connect deck model data change signal to update display - connect(deckModel, &DeckListModel::dataChanged, this, [this]() { - // Delay the update to avoid race conditions - QTimer::singleShot(100, this, &PrintingSelector::updateDisplay); - }); + connect(deckModel, &DeckListModel::rowsInserted, this, &PrintingSelector::printingsInDeckChanged); + connect(deckModel, &DeckListModel::rowsRemoved, this, &PrintingSelector::printingsInDeckChanged); +} + +void PrintingSelector::printingsInDeckChanged() +{ + // Delay the update to avoid race conditions + QTimer::singleShot(100, this, &PrintingSelector::updateDisplay); } /** @@ -89,6 +93,12 @@ void PrintingSelector::setCard(const CardInfoPtr &newCard, const QString &_curre if (newCard.isNull()) { return; } + + // we don't need to redraw the widget if the card is the same + if (!selectedCard.isNull() && selectedCard->getName() == newCard->getName()) { + return; + } + selectedCard = newCard; currentZone = _currentZone; if (isVisible()) { diff --git a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.h b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.h index 1e9b01b29..547d4dbef 100644 --- a/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.h +++ b/cockatrice/src/client/ui/widgets/printing_selector/printing_selector.h @@ -37,6 +37,9 @@ public slots: void toggleVisibilityCardSizeSlider(bool _state); void toggleVisibilityNavigationButtons(bool _state); +private slots: + void printingsInDeckChanged(); + private: QVBoxLayout *layout; PrintingSelectorViewOptionsToolbarWidget *viewOptionsToolbar;