From e19f4ddf7cef3b2166589ec2b6722671f347b1e1 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sun, 31 Mar 2024 15:58:31 +0200 Subject: [PATCH] Fix variable deletion via variable tab not updating variable selections The order of operations was incorrect. First the signal that a variable was removed was propagated before the variable was actually selected. So e.g. scene item selections would receive the signal that a variable was deleted but when repopulating the scene item selection the variable still exists resulting in the list of available entries not to change. --- lib/variables/variable-tab.cpp | 39 ++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/variables/variable-tab.cpp b/lib/variables/variable-tab.cpp index 0e5ae71a..3b6bd453 100644 --- a/lib/variables/variable-tab.cpp +++ b/lib/variables/variable-tab.cpp @@ -277,6 +277,25 @@ void AdvSceneSwitcher::OpenSettingsForSelectedVariable() } } +static void removeVariablesWithNames(const QStringList &varNames) +{ + for (const auto &name : varNames) { + auto variable = GetVariableByQString(name); + if (!variable) { + continue; + } + + auto &variables = GetVariables(); + variables.erase( + std::remove_if( + variables.begin(), variables.end(), + [variable](const std::shared_ptr &item) { + return item.get() == variable; + }), + variables.end()); + } +} + void AdvSceneSwitcher::RemoveSelectedVariables() { auto selectedRows = ui->variables->selectionModel()->selectedRows(); @@ -309,25 +328,13 @@ void AdvSceneSwitcher::RemoveSelectedVariables() } } - for (const auto &name : varNames) { - VariableSignalManager::Instance()->Remove(name); + { + auto lock = LockContext(); + removeVariablesWithNames(varNames); } - auto lock = LockContext(); for (const auto &name : varNames) { - auto variable = GetVariableByQString(name); - if (!variable) { - continue; - } - - auto &variables = GetVariables(); - variables.erase( - std::remove_if( - variables.begin(), variables.end(), - [variable](const std::shared_ptr &item) { - return item.get() == variable; - }), - variables.end()); + VariableSignalManager::Instance()->Remove(name); } }