mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-07 09:05:57 -05:00
Add "all" option in filter selection
This commit is contained in:
@@ -65,31 +65,56 @@ void FilterSelection::LoadFallback(obs_data_t *obj,
|
||||
_filterName = obs_data_get_string(obj, name);
|
||||
}
|
||||
|
||||
OBSWeakSource FilterSelection::GetFilter(const SourceSelection &source) const
|
||||
static std::vector<OBSWeakSource> getFiltersOfSource(OBSWeakSource source)
|
||||
{
|
||||
if (!source) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto enumFilters = [](obs_source_t *, obs_source_t *filter, void *ptr) {
|
||||
auto filters =
|
||||
reinterpret_cast<std::vector<OBSWeakSource> *>(ptr);
|
||||
OBSWeakSourceAutoRelease weakFilter =
|
||||
obs_source_get_weak_source(filter);
|
||||
filters->emplace_back(weakFilter);
|
||||
};
|
||||
|
||||
std::vector<OBSWeakSource> filters;
|
||||
OBSSourceAutoRelease s = obs_weak_source_get_source(source);
|
||||
obs_source_enum_filters(s, enumFilters, &filters);
|
||||
return filters;
|
||||
}
|
||||
|
||||
std::vector<OBSWeakSource>
|
||||
FilterSelection::GetFilters(const SourceSelection &source) const
|
||||
{
|
||||
switch (_type) {
|
||||
case Type::ALL:
|
||||
return getFiltersOfSource(source.GetSource());
|
||||
case Type::SOURCE:
|
||||
return GetWeakFilterByName(
|
||||
return {GetWeakFilterByName(
|
||||
source.GetSource(),
|
||||
_filter ? GetWeakSourceName(_filter).c_str()
|
||||
: _filterName.c_str());
|
||||
: _filterName.c_str())};
|
||||
case Type::VARIABLE: {
|
||||
auto var = _variable.lock();
|
||||
if (!var) {
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
return GetWeakFilterByName(source.GetSource(),
|
||||
var->Value().c_str());
|
||||
return {GetWeakFilterByName(source.GetSource(),
|
||||
var->Value().c_str())};
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string FilterSelection::ToString(bool resolve) const
|
||||
{
|
||||
switch (_type) {
|
||||
case Type::ALL:
|
||||
return obs_module_text("AdvSceneSwitcher.filterSelection.all");
|
||||
case Type::SOURCE:
|
||||
return _filter ? GetWeakSourceName(_filter) : _filterName;
|
||||
case Type::VARIABLE: {
|
||||
@@ -117,7 +142,9 @@ FilterSelection FilterSelectionWidget::CurrentSelection()
|
||||
return s;
|
||||
}
|
||||
|
||||
if (idx < _variablesEndIdx) {
|
||||
if (idx < _allEndIdx) {
|
||||
s._type = FilterSelection::Type::ALL;
|
||||
} else if (idx < _variablesEndIdx) {
|
||||
s._type = FilterSelection::Type::VARIABLE;
|
||||
s._variable = GetWeakVariableByQString(name);
|
||||
} else if (idx < _filterEndIdx) {
|
||||
@@ -139,6 +166,12 @@ void FilterSelectionWidget::PopulateSelection()
|
||||
{
|
||||
const QSignalBlocker b(this);
|
||||
clear();
|
||||
|
||||
AddSelectionGroup(
|
||||
this,
|
||||
{obs_module_text("AdvSceneSwitcher.filterSelection.all")});
|
||||
_allEndIdx = count();
|
||||
|
||||
if (_addVariables) {
|
||||
const QStringList variables = GetVariablesNameList();
|
||||
AddSelectionGroup(this, variables);
|
||||
@@ -188,6 +221,10 @@ void FilterSelectionWidget::SetFilter(const SourceSelection &source,
|
||||
int idx = -1;
|
||||
|
||||
switch (filter.GetType()) {
|
||||
case FilterSelection::Type::ALL:
|
||||
idx = findText(obs_module_text(
|
||||
"AdvSceneSwitcher.filterSelection.all"));
|
||||
break;
|
||||
case FilterSelection::Type::SOURCE: {
|
||||
if (_filterEndIdx == -1) {
|
||||
idx = -1;
|
||||
|
||||
@@ -13,15 +13,17 @@ public:
|
||||
enum class Type {
|
||||
SOURCE,
|
||||
VARIABLE,
|
||||
ALL,
|
||||
};
|
||||
|
||||
Type GetType() const { return _type; }
|
||||
OBSWeakSource GetFilter(const SourceSelection &source) const;
|
||||
std::vector<OBSWeakSource>
|
||||
GetFilters(const SourceSelection &source) const;
|
||||
std::string ToString(bool resolve = false) const;
|
||||
|
||||
private:
|
||||
// TODO: Remove in future version
|
||||
// Used for backwards compatability to older settings versions
|
||||
// Used for backwards compatibility to older settings versions
|
||||
void LoadFallback(obs_data_t *obj, const SourceSelection &source,
|
||||
const char *name);
|
||||
|
||||
@@ -65,9 +67,11 @@ private:
|
||||
|
||||
// Order of entries
|
||||
// 1. "select entry" entry
|
||||
// 2. Variables
|
||||
// 3. Regular filters
|
||||
// 2. All filters
|
||||
// 3. Variables
|
||||
// 4. Regular filters
|
||||
const int _selectIdx = 0;
|
||||
int _allEndIdx = -1;
|
||||
int _variablesEndIdx = -1;
|
||||
int _filterEndIdx = -1;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user