From 961b75b58c655809581e0b39ad546b3742de5904 Mon Sep 17 00:00:00 2001 From: Andrew Story Date: Wed, 13 Apr 2022 04:52:25 -0500 Subject: [PATCH] libobs,UI: Issue appropriate signals on group / ungroup Due to the way the frontend works, the logic for inserting the row for the group in the UI was dropped since the new item_add message will insert one automatically since it forces a refresh of the scene items. The reliance on that implicit row insertion when grouping items is a bit of a code smell, although the alternative would be to add logic to disable handling the signal for that instant, which is probably a worse choice. --- UI/source-tree.cpp | 23 ++++++----------------- libobs/obs-scene.c | 11 +++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/UI/source-tree.cpp b/UI/source-tree.cpp index cb2ed3f4e..2eb445f70 100644 --- a/UI/source-tree.cpp +++ b/UI/source-tree.cpp @@ -967,28 +967,17 @@ void SourceTreeModel::GroupSelectedItems(QModelIndexList &indices) for (obs_sceneitem_t *item : item_order) obs_sceneitem_select(item, false); - int newIdx = indices[0].row(); - - beginInsertRows(QModelIndex(), newIdx, newIdx); - items.insert(newIdx, item); - endInsertRows(); - - for (int i = 0; i < indices.size(); i++) { - int fromIdx = indices[i].row() + 1; - int toIdx = newIdx + i + 1; - if (fromIdx != toIdx) { - beginMoveRows(QModelIndex(), fromIdx, fromIdx, - QModelIndex(), toIdx); - MoveItem(items, fromIdx, toIdx); - endMoveRows(); - } - } - hasGroups = true; st->UpdateWidgets(true); obs_sceneitem_select(item, true); + /* ----------------------------------------------------------------- */ + /* obs_scene_insert_group triggers a full refresh of scene items via */ + /* the item_add signal. No need to insert a row, just edit the one */ + /* that's created automatically. */ + + int newIdx = indices[0].row(); QMetaObject::invokeMethod(st, "NewGroupEdit", Qt::QueuedConnection, Q_ARG(int, newIdx)); } diff --git a/libobs/obs-scene.c b/libobs/obs-scene.c index 884d4699a..e53d11632 100644 --- a/libobs/obs-scene.c +++ b/libobs/obs-scene.c @@ -3332,6 +3332,15 @@ obs_sceneitem_t *obs_scene_insert_group(obs_scene_t *scene, const char *name, full_unlock(sub_scene); full_unlock(scene); + struct calldata params; + uint8_t stack[128]; + + calldata_init_fixed(¶ms, stack, sizeof(stack)); + calldata_set_ptr(¶ms, "scene", scene); + calldata_set_ptr(¶ms, "item", item); + signal_handler_signal(scene->source->context.signals, "item_add", + ¶ms); + /* ------------------------- */ return item; @@ -3397,6 +3406,8 @@ void obs_sceneitem_group_ungroup(obs_sceneitem_t *item) obs_sceneitem_t *first; obs_sceneitem_t *last; + signal_item_remove(item); + full_lock(scene); /* ------------------------- */