Refactor CardSizeWidget: don't update setting directly (#5903)

This commit is contained in:
RickyRister 2025-05-06 18:31:01 -07:00 committed by GitHub
parent 5b9cb4fc8d
commit c4e42b94f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 9 deletions

View file

@ -34,14 +34,7 @@ CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *_flowWidget, int def
// Debounce setup
debounceTimer.setSingleShot(true);
connect(&debounceTimer, &QTimer::timeout, this, [this]() {
// Check the type of the parent widget
if (qobject_cast<PrintingSelector *>(parentWidget())) {
SettingsCache::instance().setPrintingSelectorCardSize(pendingValue);
} else if (qobject_cast<VisualDeckStorageWidget *>(parentWidget())) {
SettingsCache::instance().setVisualDeckStorageCardSize(pendingValue);
}
});
connect(&debounceTimer, &QTimer::timeout, this, [this] { emit cardSizeSettingUpdated(pendingValue); });
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardSizeWidget::updateCardSizeSetting);
}

View file

@ -17,9 +17,17 @@ public:
explicit CardSizeWidget(QWidget *parent, FlowWidget *flowWidget = nullptr, int defaultValue = 100);
[[nodiscard]] QSlider *getSlider() const;
public slots:
private slots:
void updateCardSizeSetting(int newValue);
signals:
/**
* Emitted when the slider value changes, but on a debounce timer.
* Any parents that care about saving the value to settings should use this signal to indicate when to save the new
* value to settings.
*/
void cardSizeSettingUpdated(int newValue);
private:
QWidget *parent;
FlowWidget *flowWidget;