mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-23 17:55:43 -05:00
Add ProfileSelectionWidget
Refreshes list of profiles when widget becomes visible to support widget caching.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include "macro-action-profile.hpp"
|
||||
#include "layout-helpers.hpp"
|
||||
#include "profile-helpers.hpp"
|
||||
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
@@ -55,20 +54,16 @@ std::shared_ptr<MacroAction> MacroActionProfile::Copy() const
|
||||
|
||||
MacroActionProfileEdit::MacroActionProfileEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroActionProfile> 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<std::string, QWidget *> 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()));
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#include "macro-action-edit.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include "profile-helpers.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -45,11 +44,10 @@ private slots:
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
protected:
|
||||
QComboBox *_profiles;
|
||||
std::shared_ptr<MacroActionProfile> _entryData;
|
||||
|
||||
private:
|
||||
ProfileSelectionWidget *_profiles;
|
||||
|
||||
std::shared_ptr<MacroActionProfile> _entryData;
|
||||
bool _loading = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "macro-condition-profile.hpp"
|
||||
#include "layout-helpers.hpp"
|
||||
#include "profile-helpers.hpp"
|
||||
|
||||
#include <obs-frontend-api.h>
|
||||
|
||||
@@ -43,22 +42,16 @@ std::string MacroConditionProfile::GetShortDesc() const
|
||||
MacroConditionProfileEdit::MacroConditionProfileEdit(
|
||||
QWidget *parent, std::shared_ptr<MacroConditionProfile> 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<std::string, QWidget *> 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()));
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#pragma once
|
||||
#include "macro-condition-edit.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
#include "profile-helpers.hpp"
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -47,11 +45,10 @@ private slots:
|
||||
signals:
|
||||
void HeaderInfoChanged(const QString &);
|
||||
|
||||
protected:
|
||||
QComboBox *_profiles;
|
||||
std::shared_ptr<MacroConditionProfile> _entryData;
|
||||
|
||||
private:
|
||||
ProfileSelectionWidget *_profiles;
|
||||
|
||||
std::shared_ptr<MacroConditionProfile> _entryData;
|
||||
bool _loading = true;
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <QComboBox>
|
||||
#include "filter-combo-box.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user