Skip to content

Commit 2599b8d

Browse files
committed
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 6cdfb0a commit 2599b8d

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

UI/properties-view.cpp

Lines changed: 21 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 "slider-ignorewheel.hpp"
2930
#include "spinbox-ignorewheel.hpp"
@@ -2004,6 +2005,9 @@ void WidgetInfo::EditableListChanged()
20042005
OBSDataAutoRelease arrayItem = obs_data_create();
20052006
obs_data_set_string(arrayItem, "value",
20062007
QT_TO_UTF8(item->text()));
2008+
obs_data_set_string(
2009+
arrayItem, "uuid",
2010+
QT_TO_UTF8(item->data(Qt::UserRole).toString()));
20072011
obs_data_set_bool(arrayItem, "selected", item->isSelected());
20082012
obs_data_set_bool(arrayItem, "hidden", item->isHidden());
20092013
obs_data_array_push_back(array, arrayItem);
@@ -2274,7 +2278,11 @@ void WidgetInfo::EditListAddText()
22742278
if (text.isEmpty())
22752279
return;
22762280

2277-
list->addItem(text);
2281+
QListWidgetItem *item = new QListWidgetItem(text);
2282+
item->setData(Qt::UserRole,
2283+
QUuid::createUuid().toString(QUuid::WithoutBraces));
2284+
list->addItem(item);
2285+
22782286
EditableListChanged();
22792287
}
22802288

@@ -2299,7 +2307,13 @@ void WidgetInfo::EditListAddFiles()
22992307
if (files.count() == 0)
23002308
return;
23012309

2302-
list->addItems(files);
2310+
for (QString file : files) {
2311+
QListWidgetItem *item = new QListWidgetItem(file);
2312+
item->setData(Qt::UserRole, QUuid::createUuid().toString(
2313+
QUuid::WithoutBraces));
2314+
list->addItem(item);
2315+
}
2316+
23032317
EditableListChanged();
23042318
}
23052319

@@ -2323,7 +2337,11 @@ void WidgetInfo::EditListAddDir()
23232337
if (dir.isEmpty())
23242338
return;
23252339

2326-
list->addItem(dir);
2340+
QListWidgetItem *item = new QListWidgetItem(dir);
2341+
item->setData(Qt::UserRole,
2342+
QUuid::createUuid().toString(QUuid::WithoutBraces));
2343+
list->addItem(item);
2344+
23272345
EditableListChanged();
23282346
}
23292347

0 commit comments

Comments
 (0)