From 20488afdd164c29a83b1a76788cde209494be1ae Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Thu, 12 Jun 2025 21:07:23 +0200 Subject: [PATCH] Fix tempvars being reset across macros for cached widgets --- lib/advanced-scene-switcher.hpp | 3 ++- lib/macro/macro-segment.cpp | 4 ++-- lib/utils/temp-variable.cpp | 34 +++++++++++++++++++-------------- lib/utils/temp-variable.hpp | 4 ++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/advanced-scene-switcher.hpp b/lib/advanced-scene-switcher.hpp index 51158b5e..33d5d149 100644 --- a/lib/advanced-scene-switcher.hpp +++ b/lib/advanced-scene-switcher.hpp @@ -11,6 +11,7 @@ namespace advss { class MacroActionEdit; class MacroConditionEdit; +class MacroSegment; class Duration; class SequenceWidget; struct SceneGroup; @@ -192,7 +193,7 @@ signals: void MacroRemoved(const QString &name); void MacroRenamed(const QString &oldName, const QString &newName); void MacroSegmentOrderChanged(); - void SegmentTempVarsChanged(); + void SegmentTempVarsChanged(MacroSegment *); void HighlightMacrosChanged(bool value); void ConnectionAdded(const QString &); diff --git a/lib/macro/macro-segment.cpp b/lib/macro/macro-segment.cpp index 82390f11..b8c7526b 100644 --- a/lib/macro/macro-segment.cpp +++ b/lib/macro/macro-segment.cpp @@ -107,7 +107,7 @@ void MacroSegment::SetupTempVars() void MacroSegment::ClearAvailableTempvars() { _tempVariables.clear(); - NotifyUIAboutTempVarChange(); + NotifyUIAboutTempVarChange(this); } static std::shared_ptr @@ -149,7 +149,7 @@ void MacroSegment::AddTempvar(const std::string &id, const std::string &name, TempVariable var(id, name, description, sharedSegment); _tempVariables.emplace_back(std::move(var)); - NotifyUIAboutTempVarChange(); + NotifyUIAboutTempVarChange(this); } void MacroSegment::SetTempVarValue(const std::string &id, diff --git a/lib/utils/temp-variable.cpp b/lib/utils/temp-variable.cpp index ff2087c1..c39478f0 100644 --- a/lib/utils/temp-variable.cpp +++ b/lib/utils/temp-variable.cpp @@ -274,8 +274,9 @@ TempVariableSelection::TempVariableSelection(QWidget *parent) SLOT(HighlightChanged(int))); QWidget::connect(window(), SIGNAL(MacroSegmentOrderChanged()), this, SLOT(MacroSegmentsChanged())); - QWidget::connect(window(), SIGNAL(SegmentTempVarsChanged()), this, - SLOT(SegmentTempVarsChanged())); + QWidget::connect(window(), + SIGNAL(SegmentTempVarsChanged(MacroSegment *)), this, + SLOT(SegmentTempVarsChanged(MacroSegment *))); auto layout = new QHBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); @@ -314,9 +315,15 @@ void TempVariableSelection::MacroSegmentsChanged() SetVariable(currentSelection); } -void TempVariableSelection::SegmentTempVarsChanged() +void TempVariableSelection::SegmentTempVarsChanged(MacroSegment *segment) { - MacroSegmentsChanged(); + const auto currentSegment = GetSegment(); + const auto currentMacro = currentSegment ? currentSegment->GetMacro() + : nullptr; + const auto changeMacro = segment ? segment->GetMacro() : nullptr; + if (currentMacro == changeMacro) { + MacroSegmentsChanged(); + } } void TempVariableSelection::HighlightChanged(int idx) @@ -427,13 +434,11 @@ QString TempVariableSelection::SetupInfoLabel() MacroSegment *TempVariableSelection::GetSegment() const { const QWidget *widget = this; - { - while (widget) { - if (qobject_cast(widget)) { - break; - } - widget = widget->parentWidget(); + while (widget) { + if (qobject_cast(widget)) { + break; } + widget = widget->parentWidget(); } if (!widget) { return nullptr; @@ -442,17 +447,18 @@ MacroSegment *TempVariableSelection::GetSegment() const return segmentWidget->Data().get(); } -void NotifyUIAboutTempVarChange() +void NotifyUIAboutTempVarChange(MacroSegment *segment) { obs_queue_task( OBS_TASK_UI, - [](void *) { + [](void *segment) { if (!SettingsWindowIsOpened()) { return; } - AdvSceneSwitcher::window->SegmentTempVarsChanged(); + AdvSceneSwitcher::window->SegmentTempVarsChanged( + (MacroSegment *)segment); }, - nullptr, false); + segment, false); } } // namespace advss diff --git a/lib/utils/temp-variable.hpp b/lib/utils/temp-variable.hpp index 109cce51..d5ac8f3a 100644 --- a/lib/utils/temp-variable.hpp +++ b/lib/utils/temp-variable.hpp @@ -88,7 +88,7 @@ public: private slots: void SelectionIdxChanged(int); void MacroSegmentsChanged(); - void SegmentTempVarsChanged(); + void SegmentTempVarsChanged(MacroSegment *); void HighlightChanged(int); signals: @@ -104,6 +104,6 @@ private: AutoUpdateTooltipLabel *_info; }; -void NotifyUIAboutTempVarChange(); +void NotifyUIAboutTempVarChange(MacroSegment *); } // namespace advss