Skip to content

Commit 8d02eef

Browse files
PatTheMavCodeYan01
authored andcommitted
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.
1 parent e8f87e4 commit 8d02eef

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

shared/properties-view/properties-view.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <QGroupBox>
2525
#include <QObject>
2626
#include <QDesktopServices>
27+
#include <QUuid>
2728
#include "double-slider.hpp"
2829
#include "spinbox-ignorewheel.hpp"
2930
#include "properties-view.hpp"
@@ -740,6 +741,14 @@ void OBSPropertiesView::AddEditableList(obs_property_t *prop,
740741
QListWidgetItem *const list_item = list->item((int)i);
741742
list_item->setSelected(obs_data_get_bool(item, "selected"));
742743
list_item->setHidden(obs_data_get_bool(item, "hidden"));
744+
QString uuid = QT_UTF8(obs_data_get_string(item, "uuid"));
745+
/* for backwards compatibility */
746+
if (uuid.isEmpty()) {
747+
uuid = QUuid::createUuid().toString(
748+
QUuid::WithoutBraces);
749+
obs_data_set_string(item, "uuid", uuid.toUtf8());
750+
}
751+
list_item->setData(Qt::UserRole, uuid);
743752
}
744753

745754
WidgetInfo *info = new WidgetInfo(this, prop, list);
@@ -2024,6 +2033,9 @@ void WidgetInfo::EditableListChanged()
20242033
OBSDataAutoRelease arrayItem = obs_data_create();
20252034
obs_data_set_string(arrayItem, "value",
20262035
QT_TO_UTF8(item->text()));
2036+
obs_data_set_string(
2037+
arrayItem, "uuid",
2038+
QT_TO_UTF8(item->data(Qt::UserRole).toString()));
20272039
obs_data_set_bool(arrayItem, "selected", item->isSelected());
20282040
obs_data_set_bool(arrayItem, "hidden", item->isHidden());
20292041
obs_data_array_push_back(array, arrayItem);
@@ -2293,7 +2305,11 @@ void WidgetInfo::EditListAddText()
22932305
if (text.isEmpty())
22942306
return;
22952307

2296-
list->addItem(text);
2308+
QListWidgetItem *item = new QListWidgetItem(text);
2309+
item->setData(Qt::UserRole,
2310+
QUuid::createUuid().toString(QUuid::WithoutBraces));
2311+
list->addItem(item);
2312+
22972313
EditableListChanged();
22982314
}
22992315

@@ -2318,7 +2334,13 @@ void WidgetInfo::EditListAddFiles()
23182334
if (files.count() == 0)
23192335
return;
23202336

2321-
list->addItems(files);
2337+
for (QString file : files) {
2338+
QListWidgetItem *item = new QListWidgetItem(file);
2339+
item->setData(Qt::UserRole, QUuid::createUuid().toString(
2340+
QUuid::WithoutBraces));
2341+
list->addItem(item);
2342+
}
2343+
23222344
EditableListChanged();
23232345
}
23242346

@@ -2341,7 +2363,11 @@ void WidgetInfo::EditListAddDir()
23412363
if (dir.isEmpty())
23422364
return;
23432365

2344-
list->addItem(dir);
2366+
QListWidgetItem *item = new QListWidgetItem(dir);
2367+
item->setData(Qt::UserRole,
2368+
QUuid::createUuid().toString(QUuid::WithoutBraces));
2369+
list->addItem(item);
2370+
23452371
EditableListChanged();
23462372
}
23472373

0 commit comments

Comments
 (0)