From 38ad3ba18fc27846e122bd56f589ccb34c4578e2 Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Mon, 14 Dec 2020 15:40:15 +0100 Subject: [PATCH] UI: Add deferred function to update context bar With the queued connection in d68484e7, the "Deselect" signal for sources which are being deleted is never fired, as the object is gone by the time the queued signal is processed. This results in the context bar not updating. This commit adds a new UpdateContextBarDeferred function, allowing queuing of only the context bar update instead of the whole signal handler. --- UI/source-tree.cpp | 10 ++++------ UI/window-basic-main.cpp | 6 ++++++ UI/window-basic-main.hpp | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/UI/source-tree.cpp b/UI/source-tree.cpp index fb6718d4fb4b52..46f5c247ddbe8a 100644 --- a/UI/source-tree.cpp +++ b/UI/source-tree.cpp @@ -227,8 +227,7 @@ void SourceTreeItem::ReconnectSignals() (obs_sceneitem_t *)calldata_ptr(cd, "item"); if (curItem == this_->sceneitem) - QMetaObject::invokeMethod(this_, "Select", - Qt::QueuedConnection); + QMetaObject::invokeMethod(this_, "Select"); }; auto itemDeselect = [](void *data, calldata_t *cd) { @@ -238,8 +237,7 @@ void SourceTreeItem::ReconnectSignals() (obs_sceneitem_t *)calldata_ptr(cd, "item"); if (curItem == this_->sceneitem) - QMetaObject::invokeMethod(this_, "Deselect", - Qt::QueuedConnection); + QMetaObject::invokeMethod(this_, "Deselect"); }; auto reorderGroup = [](void *data, calldata_t *) { @@ -538,13 +536,13 @@ void SourceTreeItem::ExpandClicked(bool checked) void SourceTreeItem::Select() { tree->SelectItem(sceneitem, true); - OBSBasic::Get()->UpdateContextBar(); + OBSBasic::Get()->UpdateContextBarDeferred(); } void SourceTreeItem::Deselect() { tree->SelectItem(sceneitem, false); - OBSBasic::Get()->UpdateContextBar(); + OBSBasic::Get()->UpdateContextBarDeferred(); } /* ========================================================================= */ diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 16a7276407a6d8..6ea33d713c49e5 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -2948,6 +2948,12 @@ static bool is_network_media_source(obs_source_t *source, const char *id) return !is_local_file; } +void OBSBasic::UpdateContextBarDeferred(bool force) +{ + QMetaObject::invokeMethod(this, "UpdateContextBar", + Qt::QueuedConnection, Q_ARG(bool, force)); +} + void OBSBasic::UpdateContextBar(bool force) { if (!ui->contextContainer->isVisible() && !force) diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 42bd8e6287c38a..4f0ad6b3a14ecb 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -1024,6 +1024,7 @@ public slots: void ClearContextBar(); void UpdateContextBar(bool force = false); + void UpdateContextBarDeferred(bool force = false); public: explicit OBSBasic(QWidget *parent = 0);