From 8d02eef159ce1b76a9ad41aad5f51bd725fdfc62 Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Tue, 4 Jul 2023 17:47:16 +0200 Subject: [PATCH] UI: Add UUID to file-based list widgets to uniquely identify items List widgets are currently used as playlists in source properties, but only contain the file paths and no other identifying information. This can lead to files being added multiple times, so when changes to list order occurs, plugins cannot uniquely identify which duplicate item was actually changed (because they're only identified by the path). By adding a UUID to the user data role of a list item, an additional unique information is added that allows plugins to de-duplicate list items. --- shared/properties-view/properties-view.cpp | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/shared/properties-view/properties-view.cpp b/shared/properties-view/properties-view.cpp index ad861ea7ee52d3..c71cbaab801db2 100644 --- a/shared/properties-view/properties-view.cpp +++ b/shared/properties-view/properties-view.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "double-slider.hpp" #include "spinbox-ignorewheel.hpp" #include "properties-view.hpp" @@ -740,6 +741,14 @@ void OBSPropertiesView::AddEditableList(obs_property_t *prop, QListWidgetItem *const list_item = list->item((int)i); list_item->setSelected(obs_data_get_bool(item, "selected")); list_item->setHidden(obs_data_get_bool(item, "hidden")); + QString uuid = QT_UTF8(obs_data_get_string(item, "uuid")); + /* for backwards compatibility */ + if (uuid.isEmpty()) { + uuid = QUuid::createUuid().toString( + QUuid::WithoutBraces); + obs_data_set_string(item, "uuid", uuid.toUtf8()); + } + list_item->setData(Qt::UserRole, uuid); } WidgetInfo *info = new WidgetInfo(this, prop, list); @@ -2024,6 +2033,9 @@ void WidgetInfo::EditableListChanged() OBSDataAutoRelease arrayItem = obs_data_create(); obs_data_set_string(arrayItem, "value", QT_TO_UTF8(item->text())); + obs_data_set_string( + arrayItem, "uuid", + QT_TO_UTF8(item->data(Qt::UserRole).toString())); obs_data_set_bool(arrayItem, "selected", item->isSelected()); obs_data_set_bool(arrayItem, "hidden", item->isHidden()); obs_data_array_push_back(array, arrayItem); @@ -2293,7 +2305,11 @@ void WidgetInfo::EditListAddText() if (text.isEmpty()) return; - list->addItem(text); + QListWidgetItem *item = new QListWidgetItem(text); + item->setData(Qt::UserRole, + QUuid::createUuid().toString(QUuid::WithoutBraces)); + list->addItem(item); + EditableListChanged(); } @@ -2318,7 +2334,13 @@ void WidgetInfo::EditListAddFiles() if (files.count() == 0) return; - list->addItems(files); + for (QString file : files) { + QListWidgetItem *item = new QListWidgetItem(file); + item->setData(Qt::UserRole, QUuid::createUuid().toString( + QUuid::WithoutBraces)); + list->addItem(item); + } + EditableListChanged(); } @@ -2341,7 +2363,11 @@ void WidgetInfo::EditListAddDir() if (dir.isEmpty()) return; - list->addItem(dir); + QListWidgetItem *item = new QListWidgetItem(dir); + item->setData(Qt::UserRole, + QUuid::createUuid().toString(QUuid::WithoutBraces)); + list->addItem(item); + EditableListChanged(); }