From 573d5719d84bad1695160d684241de62e4faf885 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 16 Jul 2018 18:57:17 -0700 Subject: [PATCH] UI: Fix signals for sub-items of groups Because sub-items of groups can no longer reroute their signals to the parent scenes of groups, delegates removal handling to SourceTreeItem instead of OBSBasic. --- UI/source-tree.cpp | 39 ++++++++++++++++++++++++++++++++++++++- UI/source-tree.hpp | 5 +++-- UI/window-basic-main.cpp | 29 ----------------------------- UI/window-basic-main.hpp | 2 -- 4 files changed, 41 insertions(+), 34 deletions(-) diff --git a/UI/source-tree.cpp b/UI/source-tree.cpp index 29b0c9c57..87443bc06 100644 --- a/UI/source-tree.cpp +++ b/UI/source-tree.cpp @@ -112,7 +112,13 @@ void SourceTreeItem::ReconnectSignals() obs_sceneitem_t *curItem = (obs_sceneitem_t*)calldata_ptr(cd, "item"); - if (!curItem || curItem == this_->sceneitem) { + if (curItem == this_->sceneitem) { + QMetaObject::invokeMethod(this_->tree, + "Remove", + Q_ARG(OBSSceneItem, curItem)); + curItem = nullptr; + } + if (!curItem) { this_->DisconnectSignals(); this_->sceneitem = nullptr; } @@ -130,6 +136,12 @@ void SourceTreeItem::ReconnectSignals() Q_ARG(bool, visible)); }; + auto reorderGroup = [] (void *data, calldata_t*) + { + SourceTreeItem *this_ = reinterpret_cast(data); + QMetaObject::invokeMethod(this_->tree, "ReorderItems"); + }; + obs_scene_t *scene = obs_sceneitem_get_scene(sceneitem); obs_source_t *sceneSource = obs_scene_get_source(scene); signal_handler_t *signal = obs_source_get_signal_handler(sceneSource); @@ -138,6 +150,14 @@ void SourceTreeItem::ReconnectSignals() itemRemoveSignal.Connect(signal, "item_remove", removeItem, this); visibleSignal.Connect(signal, "item_visible", itemVisible, this); + if (obs_sceneitem_is_group(sceneitem)) { + obs_source_t *source = obs_sceneitem_get_source(sceneitem); + signal = obs_source_get_signal_handler(source); + + groupReorderSignal.Connect(signal, "reorder", reorderGroup, + this); + } + /* --------------------------------------------------------- */ auto renamed = [] (void *data, calldata_t *cd) @@ -1274,6 +1294,23 @@ bool SourceTree::GroupedItemsSelected() const return false; } +void SourceTree::Remove(OBSSceneItem item) +{ + OBSBasic *main = reinterpret_cast(App()->GetMainWindow()); + GetStm()->Remove(item); + main->SaveProject(); + + if (!main->SavingDisabled()) { + obs_scene_t *scene = obs_sceneitem_get_scene(item); + obs_source_t *sceneSource = obs_scene_get_source(scene); + obs_source_t *itemSource = obs_sceneitem_get_source(item); + blog(LOG_INFO, "User Removed source '%s' (%s) from scene '%s'", + obs_source_get_name(itemSource), + obs_source_get_id(itemSource), + obs_source_get_name(sceneSource)); + } +} + void SourceTree::GroupSelectedItems() { QModelIndexList indices = selectedIndexes(); diff --git a/UI/source-tree.hpp b/UI/source-tree.hpp index c1326d4d0..a5c441f09 100644 --- a/UI/source-tree.hpp +++ b/UI/source-tree.hpp @@ -62,6 +62,7 @@ private: OBSSceneItem sceneitem; OBSSignal sceneRemoveSignal; OBSSignal itemRemoveSignal; + OBSSignal groupReorderSignal; OBSSignal visibleSignal; OBSSignal renameSignal; OBSSignal removeSignal; @@ -143,11 +144,9 @@ public: explicit SourceTree(QWidget *parent = nullptr); inline bool IgnoreReorder() const {return ignoreReorder;} - inline void ReorderItems() {GetStm()->ReorderItems();} inline void Clear() {GetStm()->Clear();} inline void Add(obs_sceneitem_t *item) {GetStm()->Add(item);} - inline void Remove(obs_sceneitem_t *item) {GetStm()->Remove(item);} inline OBSSceneItem Get(int idx) {return GetStm()->Get(idx);} inline QString GetNewGroupName() {return GetStm()->GetNewGroupName();} @@ -158,6 +157,8 @@ public: bool GroupedItemsSelected() const; public slots: + inline void ReorderItems() {GetStm()->ReorderItems();} + void Remove(OBSSceneItem item); void GroupSelectedItems(); void UngroupSelectedGroups(); void AddGroup(); diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 2b7b4fdfa..9165a4714 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -2137,8 +2137,6 @@ void OBSBasic::AddScene(OBSSource source) container.handlers.assign({ std::make_shared(handler, "item_add", OBSBasic::SceneItemAdded, this), - std::make_shared(handler, "item_remove", - OBSBasic::SceneItemRemoved, this), std::make_shared(handler, "item_select", OBSBasic::SceneItemSelected, this), std::make_shared(handler, "item_deselect", @@ -2236,23 +2234,6 @@ void OBSBasic::AddSceneItem(OBSSceneItem item) } } -void OBSBasic::RemoveSceneItem(OBSSceneItem item) -{ - ui->sources->Remove(item); - - SaveProject(); - - if (!disableSaving) { - obs_scene_t *scene = obs_sceneitem_get_scene(item); - obs_source_t *sceneSource = obs_scene_get_source(scene); - obs_source_t *itemSource = obs_sceneitem_get_source(item); - blog(LOG_INFO, "User Removed source '%s' (%s) from scene '%s'", - obs_source_get_name(itemSource), - obs_source_get_id(itemSource), - obs_source_get_name(sceneSource)); - } -} - void OBSBasic::UpdateSceneSelection(OBSSource source) { if (source) { @@ -2853,16 +2834,6 @@ void OBSBasic::SceneItemAdded(void *data, calldata_t *params) Q_ARG(OBSSceneItem, OBSSceneItem(item))); } -void OBSBasic::SceneItemRemoved(void *data, calldata_t *params) -{ - OBSBasic *window = static_cast(data); - - obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item"); - - QMetaObject::invokeMethod(window, "RemoveSceneItem", - Q_ARG(OBSSceneItem, OBSSceneItem(item))); -} - void OBSBasic::SceneItemSelected(void *data, calldata_t *params) { OBSBasic *window = static_cast(data); diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 2041e475d..c2c9997bd 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -416,7 +416,6 @@ public slots: private slots: void AddSceneItem(OBSSceneItem item); - void RemoveSceneItem(OBSSceneItem item); void AddScene(OBSSource source); void RemoveScene(OBSSource source); void RenameSources(OBSSource source, QString newName, QString prevName); @@ -473,7 +472,6 @@ private: /* OBS Callbacks */ static void SceneReordered(void *data, calldata_t *params); static void SceneItemAdded(void *data, calldata_t *params); - static void SceneItemRemoved(void *data, calldata_t *params); static void SceneItemSelected(void *data, calldata_t *params); static void SceneItemDeselected(void *data, calldata_t *params); static void SourceCreated(void *data, calldata_t *params);