From 5e3ab19940892f50172123f8b06d8b8075c62250 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Thu, 22 May 2025 21:38:07 +0200 Subject: [PATCH] Add ProfileSelectionWidget Refreshes list of profiles when widget becomes visible to support widget caching. --- plugins/base/macro-action-profile.cpp | 21 ++++++--------------- plugins/base/macro-action-profile.hpp | 10 ++++------ plugins/base/macro-condition-profile.cpp | 21 +++++---------------- plugins/base/macro-condition-profile.hpp | 11 ++++------- plugins/base/utils/profile-helpers.cpp | 19 +++++++++++++++++++ plugins/base/utils/profile-helpers.hpp | 13 ++++++++++++- 6 files changed, 50 insertions(+), 45 deletions(-) diff --git a/plugins/base/macro-action-profile.cpp b/plugins/base/macro-action-profile.cpp index 1b4bc0e7..d82813c4 100644 --- a/plugins/base/macro-action-profile.cpp +++ b/plugins/base/macro-action-profile.cpp @@ -1,6 +1,5 @@ #include "macro-action-profile.hpp" #include "layout-helpers.hpp" -#include "profile-helpers.hpp" #include @@ -55,20 +54,16 @@ std::shared_ptr MacroActionProfile::Copy() const MacroActionProfileEdit::MacroActionProfileEdit( QWidget *parent, std::shared_ptr entryData) - : QWidget(parent) + : QWidget(parent), + _profiles(new ProfileSelectionWidget(this)) { - _profiles = new QComboBox(); - PopulateProfileSelection(_profiles); QWidget::connect(_profiles, SIGNAL(currentTextChanged(const QString &)), this, SLOT(ProfileChanged(const QString &))); - QHBoxLayout *mainLayout = new QHBoxLayout; - std::unordered_map widgetPlaceholders = { - {"{{profiles}}", _profiles}, - }; + auto layout = new QHBoxLayout; PlaceWidgets(obs_module_text("AdvSceneSwitcher.action.profile.entry"), - mainLayout, widgetPlaceholders); - setLayout(mainLayout); + layout, {{"{{profiles}}", _profiles}}); + setLayout(layout); _entryData = entryData; UpdateEntryData(); @@ -86,11 +81,7 @@ void MacroActionProfileEdit::UpdateEntryData() void MacroActionProfileEdit::ProfileChanged(const QString &text) { - if (_loading || !_entryData) { - return; - } - - auto lock = LockContext(); + GUARD_LOADING_AND_LOCK(); _entryData->_profile = text.toStdString(); emit HeaderInfoChanged( QString::fromStdString(_entryData->GetShortDesc())); diff --git a/plugins/base/macro-action-profile.hpp b/plugins/base/macro-action-profile.hpp index 2e23eef7..c20ee10c 100644 --- a/plugins/base/macro-action-profile.hpp +++ b/plugins/base/macro-action-profile.hpp @@ -1,7 +1,6 @@ #pragma once #include "macro-action-edit.hpp" - -#include +#include "profile-helpers.hpp" namespace advss { @@ -45,11 +44,10 @@ private slots: signals: void HeaderInfoChanged(const QString &); -protected: - QComboBox *_profiles; - std::shared_ptr _entryData; - private: + ProfileSelectionWidget *_profiles; + + std::shared_ptr _entryData; bool _loading = true; }; diff --git a/plugins/base/macro-condition-profile.cpp b/plugins/base/macro-condition-profile.cpp index 41b0f2e5..1fe7fbd0 100644 --- a/plugins/base/macro-condition-profile.cpp +++ b/plugins/base/macro-condition-profile.cpp @@ -1,6 +1,5 @@ #include "macro-condition-profile.hpp" #include "layout-helpers.hpp" -#include "profile-helpers.hpp" #include @@ -43,22 +42,16 @@ std::string MacroConditionProfile::GetShortDesc() const MacroConditionProfileEdit::MacroConditionProfileEdit( QWidget *parent, std::shared_ptr entryData) : QWidget(parent), - _profiles(new QComboBox()) + _profiles(new ProfileSelectionWidget(this)) { - PopulateProfileSelection(_profiles); QWidget::connect(_profiles, SIGNAL(currentTextChanged(const QString &)), this, SLOT(ProfileChanged(const QString &))); - QHBoxLayout *mainLayout = new QHBoxLayout; - - std::unordered_map widgetPlaceholders = { - {"{{profiles}}", _profiles}, - }; - + auto layout = new QHBoxLayout; PlaceWidgets( obs_module_text("AdvSceneSwitcher.condition.profile.entry"), - mainLayout, widgetPlaceholders); - setLayout(mainLayout); + layout, {{"{{profiles}}", _profiles}}); + setLayout(layout); _entryData = entryData; UpdateEntryData(); @@ -67,11 +60,7 @@ MacroConditionProfileEdit::MacroConditionProfileEdit( void MacroConditionProfileEdit::ProfileChanged(const QString &text) { - if (_loading || !_entryData) { - return; - } - - auto lock = LockContext(); + GUARD_LOADING_AND_LOCK(); _entryData->_profile = text.toStdString(); emit HeaderInfoChanged( QString::fromStdString(_entryData->GetShortDesc())); diff --git a/plugins/base/macro-condition-profile.hpp b/plugins/base/macro-condition-profile.hpp index e2917d68..f6a9df8e 100644 --- a/plugins/base/macro-condition-profile.hpp +++ b/plugins/base/macro-condition-profile.hpp @@ -1,8 +1,6 @@ #pragma once #include "macro-condition-edit.hpp" - -#include -#include +#include "profile-helpers.hpp" namespace advss { @@ -47,11 +45,10 @@ private slots: signals: void HeaderInfoChanged(const QString &); -protected: - QComboBox *_profiles; - std::shared_ptr _entryData; - private: + ProfileSelectionWidget *_profiles; + + std::shared_ptr _entryData; bool _loading = true; }; diff --git a/plugins/base/utils/profile-helpers.cpp b/plugins/base/utils/profile-helpers.cpp index 73762c1b..007c0f33 100644 --- a/plugins/base/utils/profile-helpers.cpp +++ b/plugins/base/utils/profile-helpers.cpp @@ -30,4 +30,23 @@ std::string GetPathInProfileDir(const char *filePath) return result + "/" + filePath; } +ProfileSelectionWidget::ProfileSelectionWidget(QWidget *parent) + : FilterComboBox(parent) +{ + setEditable(true); + SetAllowUnmatchedSelection(true); + setMaxVisibleItems(20); + PopulateProfileSelection(this); +} + +void ProfileSelectionWidget::showEvent(QShowEvent *event) +{ + FilterComboBox::showEvent(event); + const QSignalBlocker b(this); + const auto text = currentText(); + clear(); + PopulateProfileSelection(this); + setCurrentText(text); +} + } // namespace advss diff --git a/plugins/base/utils/profile-helpers.hpp b/plugins/base/utils/profile-helpers.hpp index 3595047f..ac2ca328 100644 --- a/plugins/base/utils/profile-helpers.hpp +++ b/plugins/base/utils/profile-helpers.hpp @@ -1,5 +1,6 @@ #pragma once -#include +#include "filter-combo-box.hpp" + #include namespace advss { @@ -7,4 +8,14 @@ namespace advss { void PopulateProfileSelection(QComboBox *list); std::string GetPathInProfileDir(const char *filePath); +class ProfileSelectionWidget : public FilterComboBox { + Q_OBJECT + +public: + ProfileSelectionWidget(QWidget *parent); + +protected: + void showEvent(QShowEvent *event) override; +}; + } // namespace advss