From 7fef29dafbc351c1c4d2d24c1db49ccac7e178f6 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 6 Jun 2020 08:59:03 +0200 Subject: [PATCH] fix media delete button deleting wrong entry the mediaSwitches UI is sorted alphabetically while the switches data strucutre is not the previous implementation of the delete function was just using the index of the currently selected row to delete this index of the switches data structure the new implementation will try to find the correct entry and delete it --- src/media-switch.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/media-switch.cpp b/src/media-switch.cpp index 2b392f2c..92e8767a 100644 --- a/src/media-switch.cpp +++ b/src/media-switch.cpp @@ -73,17 +73,23 @@ void SceneSwitcher::on_mediaRemove_clicked() if (!item) return; - int idx = ui->mediaSwitches->currentRow(); - if (idx == -1) - return; - + string mediaStr = + item->data(Qt::UserRole).toString().toUtf8().constData(); { lock_guard lock(switcher->m); - auto &switches = switcher->mediaSwitches; - switches.erase(switches.begin() + idx); + + for (auto it = switches.begin(); it != switches.end(); ++it) { + auto &s = *it; + + if (s.mediaSwitchStr == mediaStr) { + switches.erase(it); + break; + } + } } - qDeleteAll(ui->mediaSwitches->selectedItems()); + + delete item; } void SwitcherData::checkMediaSwitch(bool &match, OBSWeakSource &scene,