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.
This commit is contained in:
WarmUpTill 2024-03-31 15:58:31 +02:00 committed by WarmUpTill
parent 4e3a062084
commit e19f4ddf7c

View File

@ -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> &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> &item) {
return item.get() == variable;
}),
variables.end());
VariableSignalManager::Instance()->Remove(name);
}
}