From d759ded64dc3ef2a24a9c7985e662a7fdf29c97e Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Wed, 12 Jul 2023 21:14:10 +0200 Subject: [PATCH] Use FilterComboBox instead of regular QComboBox This required the following adjustments: Instead of having a dedicated entry indicating the empty selection the setPlaceholderText() mechanism is used. Thus the locations where the 1st entry was assumed to be the empty selection would have to be adjusted. Additional checks for the empty string / index -1 have been added. FindIdxInRagne() was adjusted to return -1 instead of 0 in case the given string was not found. Switched to index based singal instead of text based signal to be notified about selection changes. --- src/macro-core/macro-action-edit.cpp | 10 +++++-- src/macro-core/macro-action-edit.hpp | 4 +-- src/macro-core/macro-condition-edit.cpp | 9 ++++-- src/macro-core/macro-condition-edit.hpp | 3 +- src/macro-core/macro-selection.cpp | 19 ++++--------- src/macro-core/macro-selection.hpp | 5 ++-- src/utils/filter-selection.cpp | 30 ++++++++++---------- src/utils/filter-selection.hpp | 5 ++-- src/utils/item-selection-helpers.cpp | 5 ++-- src/utils/item-selection-helpers.hpp | 4 +-- src/utils/scene-item-selection.cpp | 37 +++++++++++++++---------- src/utils/scene-item-selection.hpp | 7 +++-- src/utils/scene-selection.cpp | 34 +++++++++++------------ src/utils/scene-selection.hpp | 7 ++--- src/utils/source-selection.cpp | 26 ++++++++--------- src/utils/source-selection.hpp | 8 ++---- src/utils/transition-selection.cpp | 5 ++-- src/utils/transition-selection.hpp | 5 ++-- src/utils/utility.cpp | 9 +++--- 19 files changed, 120 insertions(+), 112 deletions(-) diff --git a/src/macro-core/macro-action-edit.cpp b/src/macro-core/macro-action-edit.cpp index 54a56686..5475d32c 100644 --- a/src/macro-core/macro-action-edit.cpp +++ b/src/macro-core/macro-action-edit.cpp @@ -78,7 +78,7 @@ MacroActionEdit::MacroActionEdit(QWidget *parent, std::shared_ptr *entryData, const std::string &id) : MacroSegmentEdit(switcher->macroProperties._highlightActions, parent), - _actionSelection(new QComboBox()), + _actionSelection(new FilterComboBox()), _entryData(entryData) { QWidget::connect(_actionSelection, @@ -115,10 +115,14 @@ void MacroActionEdit::ActionSelectionChanged(const QString &text) return; } + std::string id = MacroActionFactory::GetIdByName(text); + if (id.empty()) { + return; + } + + HeaderInfoChanged(""); auto idx = _entryData->get()->GetIndex(); auto macro = _entryData->get()->GetMacro(); - std::string id = MacroActionFactory::GetIdByName(text); - HeaderInfoChanged(""); { std::lock_guard lock(switcher->m); _entryData->reset(); diff --git a/src/macro-core/macro-action-edit.hpp b/src/macro-core/macro-action-edit.hpp index 5cefd92b..4ba4cfcf 100644 --- a/src/macro-core/macro-action-edit.hpp +++ b/src/macro-core/macro-action-edit.hpp @@ -1,7 +1,7 @@ #pragma once #include "macro-action.hpp" +#include "filter-combo-box.hpp" -#include #include namespace advss { @@ -48,7 +48,7 @@ private slots: private: std::shared_ptr Data(); - QComboBox *_actionSelection; + FilterComboBox *_actionSelection; std::shared_ptr *_entryData; bool _loading = true; diff --git a/src/macro-core/macro-condition-edit.cpp b/src/macro-core/macro-condition-edit.cpp index ee8d7d1f..046eff76 100644 --- a/src/macro-core/macro-condition-edit.cpp +++ b/src/macro-core/macro-condition-edit.cpp @@ -182,7 +182,7 @@ MacroConditionEdit::MacroConditionEdit( : MacroSegmentEdit(switcher->macroProperties._highlightConditions, parent), _logicSelection(new QComboBox()), - _conditionSelection(new QComboBox()), + _conditionSelection(new FilterComboBox()), _dur(new DurationModifierEdit()), _entryData(entryData), _isRoot(root) @@ -295,13 +295,16 @@ void MacroConditionEdit::ConditionSelectionChanged(const QString &text) return; } - auto idx = _entryData->get()->GetIndex(); - auto macro = _entryData->get()->GetMacro(); std::string id = MacroConditionFactory::GetIdByName(text); + if (id.empty()) { + return; + } auto temp = DurationModifier(); _dur->SetValue(temp); HeaderInfoChanged(""); + auto idx = _entryData->get()->GetIndex(); + auto macro = _entryData->get()->GetMacro(); { auto lock = LockContext(); auto logic = (*_entryData)->GetLogicType(); diff --git a/src/macro-core/macro-condition-edit.hpp b/src/macro-core/macro-condition-edit.hpp index 68281d24..7e4cf88b 100644 --- a/src/macro-core/macro-condition-edit.hpp +++ b/src/macro-core/macro-condition-edit.hpp @@ -1,5 +1,6 @@ #pragma once #include "macro-condition.hpp" +#include "filter-combo-box.hpp" #include @@ -77,7 +78,7 @@ private: std::shared_ptr Data(); QComboBox *_logicSelection; - QComboBox *_conditionSelection; + FilterComboBox *_conditionSelection; DurationModifierEdit *_dur; std::shared_ptr *_entryData; diff --git a/src/macro-core/macro-selection.cpp b/src/macro-core/macro-selection.cpp index 24e8a62e..bbdbba13 100644 --- a/src/macro-core/macro-selection.cpp +++ b/src/macro-core/macro-selection.cpp @@ -8,18 +8,10 @@ namespace advss { -MacroSelection::MacroSelection(QWidget *parent) : QComboBox(parent) +MacroSelection::MacroSelection(QWidget *parent) + : FilterComboBox(parent, + obs_module_text("AdvSceneSwitcher.selectMacro")) { - addItem(obs_module_text("AdvSceneSwitcher.selectMacro")); - - QStandardItemModel *model = - qobject_cast(this->model()); - QModelIndex firstIndex = - model->index(0, modelColumn(), rootModelIndex()); - QStandardItem *firstItem = model->itemFromIndex(firstIndex); - firstItem->setSelectable(false); - firstItem->setEnabled(false); - for (const auto &m : switcher->macros) { if (m->IsGroup()) { continue; @@ -139,8 +131,9 @@ bool MacroSelectionDialog::AskForMacro(QWidget *parent, std::string ¯oName) if (dialog.exec() != DialogCode::Accepted) { return false; } - macroName = dialog._macroSelection->currentText().toUtf8().constData(); - if (macroName == obs_module_text("AdvSceneSwitcher.selectMacro")) { + macroName = dialog._macroSelection->currentText().toStdString(); + if (macroName == obs_module_text("AdvSceneSwitcher.selectMacro") || + macroName.empty()) { return false; } diff --git a/src/macro-core/macro-selection.hpp b/src/macro-core/macro-selection.hpp index 2cb9afdf..f9092d6a 100644 --- a/src/macro-core/macro-selection.hpp +++ b/src/macro-core/macro-selection.hpp @@ -1,5 +1,6 @@ #pragma once -#include +#include "filter-combo-box.hpp" + #include namespace advss { @@ -7,7 +8,7 @@ namespace advss { class Macro; class MacroRef; -class MacroSelection : public QComboBox { +class MacroSelection : public FilterComboBox { Q_OBJECT public: diff --git a/src/utils/filter-selection.cpp b/src/utils/filter-selection.cpp index 8719353f..f84a04ff 100644 --- a/src/utils/filter-selection.cpp +++ b/src/utils/filter-selection.cpp @@ -113,6 +113,9 @@ FilterSelection FilterSelectionWidget::CurrentSelection() FilterSelection s; const int idx = currentIndex(); const auto name = currentText(); + if (idx == -1 || name.isEmpty()) { + return s; + } if (idx < _variablesEndIdx) { s._type = FilterSelection::Type::VARIABLE; @@ -136,10 +139,6 @@ void FilterSelectionWidget::PopulateSelection() { const QSignalBlocker b(this); clear(); - AddSelectionEntry(this, - obs_module_text("AdvSceneSwitcher.selectFilter")); - insertSeparator(count()); - if (_addVariables) { const QStringList variables = GetVariablesNameList(); AddSelectionGroup(this, variables); @@ -151,18 +150,20 @@ void FilterSelectionWidget::PopulateSelection() // Remove last separator removeItem(count() - 1); - setCurrentIndex(0); + setCurrentIndex(-1); } FilterSelectionWidget::FilterSelectionWidget(QWidget *parent, SourceSelectionWidget *sources, bool addVariables) - : QComboBox(parent), _addVariables(addVariables) + : FilterComboBox(parent, + obs_module_text("AdvSceneSwitcher.selectFilter")), + _addVariables(addVariables) { setDuplicatesEnabled(true); - QWidget::connect(this, SIGNAL(currentTextChanged(const QString &)), - this, SLOT(SelectionChanged(const QString &))); + QWidget::connect(this, SIGNAL(currentIndexChanged(int)), this, + SLOT(SelectionChanged(int))); QWidget::connect(sources, SIGNAL(SourceChanged(const SourceSelection &)), this, SLOT(SourceChanged(const SourceSelection &))); @@ -184,12 +185,12 @@ void FilterSelectionWidget::SetFilter(const SourceSelection &source, _source = source; PopulateSelection(); - int idx = 0; + int idx = -1; switch (filter.GetType()) { case FilterSelection::Type::SOURCE: { if (_filterEndIdx == -1) { - idx = 0; + idx = -1; break; } idx = FindIdxInRagne(this, _variablesEndIdx, _filterEndIdx, @@ -198,14 +199,14 @@ void FilterSelectionWidget::SetFilter(const SourceSelection &source, } case FilterSelection::Type::VARIABLE: { if (_variablesEndIdx == -1) { - idx = 0; + idx = -1; break; } idx = FindIdxInRagne(this, _selectIdx, _variablesEndIdx, filter.ToString()); break; default: - idx = 0; + idx = -1; break; } } @@ -224,9 +225,10 @@ void FilterSelectionWidget::SourceChanged(const SourceSelection &source) emit FilterChanged(_currentSelection); } -void FilterSelectionWidget::SelectionChanged(const QString &) +void FilterSelectionWidget::SelectionChanged(int) { - emit FilterChanged(CurrentSelection()); + _currentSelection = CurrentSelection(); + emit FilterChanged(_currentSelection); } void FilterSelectionWidget::ItemAdd(const QString &) diff --git a/src/utils/filter-selection.hpp b/src/utils/filter-selection.hpp index 031fb212..e5878a6e 100644 --- a/src/utils/filter-selection.hpp +++ b/src/utils/filter-selection.hpp @@ -1,5 +1,6 @@ #pragma once #include "source-selection.hpp" +#include "filter-combo-box.hpp" namespace advss { @@ -33,7 +34,7 @@ private: friend class FilterSelectionWidget; }; -class FilterSelectionWidget : public QComboBox { +class FilterSelectionWidget : public FilterComboBox { Q_OBJECT public: @@ -47,7 +48,7 @@ signals: public slots: void SourceChanged(const SourceSelection &); private slots: - void SelectionChanged(const QString &name); + void SelectionChanged(int); void ItemAdd(const QString &name); void ItemRemove(const QString &name); void ItemRename(const QString &oldName, const QString &newName); diff --git a/src/utils/item-selection-helpers.cpp b/src/utils/item-selection-helpers.cpp index 2a392a11..6e939bfe 100644 --- a/src/utils/item-selection-helpers.cpp +++ b/src/utils/item-selection-helpers.cpp @@ -48,7 +48,7 @@ ItemSelection::ItemSelection(std::deque> &items, std::string_view select, std::string_view add, QWidget *parent) : QWidget(parent), - _selection(new QComboBox), + _selection(new FilterComboBox(this, obs_module_text(select.data()))), _modify(new QPushButton), _create(create), _askForSettings(callback), @@ -77,7 +77,6 @@ ItemSelection::ItemSelection(std::deque> &items, _selection->addItem(QString::fromStdString(i->_name)); } _selection->model()->sort(0); - AddSelectionEntry(_selection, obs_module_text(_selectStr.data())); _selection->insertSeparator(_selection->count()); _selection->addItem(obs_module_text(_addStr.data())); } @@ -230,7 +229,7 @@ void ItemSelection::RemoveItem(const QString &name) { const int idx = _selection->findText(name); if (idx == _selection->currentIndex()) { - _selection->setCurrentIndex(0); + _selection->setCurrentIndex(-1); } _selection->removeItem(idx); } diff --git a/src/utils/item-selection-helpers.hpp b/src/utils/item-selection-helpers.hpp index d89883c6..9e469aae 100644 --- a/src/utils/item-selection-helpers.hpp +++ b/src/utils/item-selection-helpers.hpp @@ -1,6 +1,6 @@ #pragma once +#include "filter-combo-box.hpp" -#include #include #include #include @@ -93,7 +93,7 @@ signals: protected: Item *GetCurrentItem(); - QComboBox *_selection; + FilterComboBox *_selection; QPushButton *_modify; CreateItemFunc _create; SettingsCallback _askForSettings; diff --git a/src/utils/scene-item-selection.cpp b/src/utils/scene-item-selection.cpp index e7d265f3..ea6d29b0 100644 --- a/src/utils/scene-item-selection.cpp +++ b/src/utils/scene-item-selection.cpp @@ -265,10 +265,6 @@ void SceneItemSelectionWidget::Reset() void SceneItemSelectionWidget::PopulateItemSelection() { _sceneItems->clear(); - AddSelectionEntry(_sceneItems, - obs_module_text("AdvSceneSwitcher.selectItem")); - _sceneItems->insertSeparator(_sceneItems->count()); - const QStringList variables = GetVariablesNameList(); AddSelectionGroup(_sceneItems, variables); _variablesEndIdx = _sceneItems->count(); @@ -276,7 +272,7 @@ void SceneItemSelectionWidget::PopulateItemSelection() const QStringList sceneItmes = GetSceneItemsList(_scene); AddSelectionGroup(_sceneItems, sceneItmes, false); _itemsEndIdx = _sceneItems->count(); - _sceneItems->setCurrentIndex(0); + _sceneItems->setCurrentIndex(-1); } SceneItemSelectionWidget::SceneItemSelectionWidget(QWidget *parent, @@ -284,7 +280,8 @@ SceneItemSelectionWidget::SceneItemSelectionWidget(QWidget *parent, Placeholder type) : QWidget(parent), _hasPlaceholderEntry(showAll), _placeholder(type) { - _sceneItems = new QComboBox(); + _sceneItems = new FilterComboBox( + this, obs_module_text("AdvSceneSwitcher.selectItem")); _idx = new QComboBox(); _sceneItems->setSizeAdjustPolicy(QComboBox::AdjustToContents); @@ -292,9 +289,8 @@ SceneItemSelectionWidget::SceneItemSelectionWidget(QWidget *parent, populateSceneItemSelection(_sceneItems); - QWidget::connect(_sceneItems, - SIGNAL(currentTextChanged(const QString &)), this, - SLOT(SelectionChanged(const QString &))); + QWidget::connect(_sceneItems, SIGNAL(currentIndexChanged(int)), this, + SLOT(SelectionChanged(int))); QWidget::connect(_idx, SIGNAL(currentIndexChanged(int)), this, SLOT(IdxChanged(int))); // Variables @@ -317,7 +313,7 @@ SceneItemSelectionWidget::SceneItemSelectionWidget(QWidget *parent, void SceneItemSelectionWidget::SetSceneItem(const SceneItemSelection &item) { - int itemIdx = 0; + int itemIdx = -1; switch (item._type) { case SceneItemSelection::Type::SOURCE: { int idx = item._idx; @@ -379,7 +375,7 @@ void SceneItemSelectionWidget::SetPlaceholderType(Placeholder t, { _placeholder = t; if (resetSelection) { - _sceneItems->setCurrentIndex(0); + _sceneItems->setCurrentIndex(-1); } else { auto count = _idx->count() - 1; const QSignalBlocker b(_idx); @@ -393,9 +389,12 @@ void SceneItemSelectionWidget::SceneChanged(const SceneSelection &s) adjustSize(); } -void SceneItemSelectionWidget::SelectionChanged(const QString &name) +SceneItemSelection SceneItemSelectionWidget::CurrentSelection() { SceneItemSelection s; + const int idx = _sceneItems->currentIndex(); + const auto name = _sceneItems->currentText(); + int sceneItemCount = getCountOfSceneItemOccurance(_scene, name.toStdString()); if (sceneItemCount > 1) { @@ -416,7 +415,10 @@ void SceneItemSelectionWidget::SelectionChanged(const QString &name) } } - const int idx = _sceneItems->currentIndex(); + if (idx == -1 || name.isEmpty()) { + return s; + } + if (idx < _variablesEndIdx) { s._type = SceneItemSelection::Type::VARIABLE; s._variable = GetWeakVariableByQString(name); @@ -425,8 +427,13 @@ void SceneItemSelectionWidget::SelectionChanged(const QString &name) s._sceneItem = GetWeakSourceByQString(name); } - _currentSelection = s; - emit SceneItemChanged(s); + return s; +} + +void SceneItemSelectionWidget::SelectionChanged(int) +{ + _currentSelection = CurrentSelection(); + emit SceneItemChanged(_currentSelection); } void SceneItemSelectionWidget::IdxChanged(int idx) diff --git a/src/utils/scene-item-selection.hpp b/src/utils/scene-item-selection.hpp index fccd85ad..a333e951 100644 --- a/src/utils/scene-item-selection.hpp +++ b/src/utils/scene-item-selection.hpp @@ -1,9 +1,9 @@ #pragma once #include "scene-selection.hpp" #include "variable.hpp" +#include "filter-combo-box.hpp" #include "utility.hpp" -#include #include namespace advss { @@ -57,7 +57,7 @@ signals: private slots: void SceneChanged(const SceneSelection &); - void SelectionChanged(const QString &name); + void SelectionChanged(int); void IdxChanged(int); void ItemAdd(const QString &name); void ItemRemove(const QString &name); @@ -65,10 +65,11 @@ private slots: private: void Reset(); + SceneItemSelection CurrentSelection(); void PopulateItemSelection(); void SetupIdxSelection(int); - QComboBox *_sceneItems; + FilterComboBox *_sceneItems; QComboBox *_idx; SceneSelection _scene; diff --git a/src/utils/scene-selection.cpp b/src/utils/scene-selection.cpp index c0340461..e879a476 100644 --- a/src/utils/scene-selection.cpp +++ b/src/utils/scene-selection.cpp @@ -178,6 +178,9 @@ SceneSelection SceneSelectionWidget::CurrentSelection() SceneSelection s; const int idx = currentIndex(); const auto name = currentText(); + if (idx == -1 || name.isEmpty()) { + return s; + } if (idx < _placeholderEndIdx) { if (IsCurrentSceneSelected(name)) { @@ -251,10 +254,6 @@ void SceneSelectionWidget::Reset() void SceneSelectionWidget::PopulateSelection() { clear(); - AddSelectionEntry(this, - obs_module_text("AdvSceneSwitcher.selectScene")); - insertSeparator(count()); - if (_current || _previous) { const QStringList order = getOrderList(_current, _previous, _preview); @@ -280,13 +279,14 @@ void SceneSelectionWidget::PopulateSelection() // Remove last separator removeItem(count() - 1); - setCurrentIndex(0); + setCurrentIndex(-1); } SceneSelectionWidget::SceneSelectionWidget(QWidget *parent, bool variables, bool sceneGroups, bool previous, bool current, bool preview) - : QComboBox(parent), + : FilterComboBox(parent, + obs_module_text("AdvSceneSwitcher.selectScene")), _current(current), _previous(previous), _preview(preview), @@ -296,8 +296,8 @@ SceneSelectionWidget::SceneSelectionWidget(QWidget *parent, bool variables, setDuplicatesEnabled(true); PopulateSelection(); - QWidget::connect(this, SIGNAL(currentTextChanged(const QString &)), - this, SLOT(SelectionChanged(const QString &))); + QWidget::connect(this, SIGNAL(currentIndexChanged(int)), this, + SLOT(SelectionChanged(int))); // Scene groups QWidget::connect(window(), SIGNAL(SceneGroupAdded(const QString &)), @@ -322,12 +322,12 @@ SceneSelectionWidget::SceneSelectionWidget(QWidget *parent, bool variables, void SceneSelectionWidget::SetScene(const SceneSelection &s) { - int idx = 0; + int idx = -1; switch (s.GetType()) { case SceneSelection::Type::SCENE: { if (_scenesEndIdx == -1) { - idx = 0; + idx = -1; break; } idx = FindIdxInRagne(this, _groupsEndIdx, _scenesEndIdx, @@ -336,7 +336,7 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s) } case SceneSelection::Type::GROUP: { if (_groupsEndIdx == -1) { - idx = 0; + idx = -1; break; } idx = FindIdxInRagne(this, _variablesEndIdx, _groupsEndIdx, @@ -345,7 +345,7 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s) } case SceneSelection::Type::PREVIOUS: { if (_placeholderEndIdx == -1) { - idx = 0; + idx = -1; break; } @@ -357,7 +357,7 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s) } case SceneSelection::Type::CURRENT: { if (_placeholderEndIdx == -1) { - idx = 0; + idx = -1; break; } @@ -368,7 +368,7 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s) } case SceneSelection::Type::PREVIEW: { if (_placeholderEndIdx == -1) { - idx = 0; + idx = -1; break; } @@ -379,14 +379,14 @@ void SceneSelectionWidget::SetScene(const SceneSelection &s) } case SceneSelection::Type::VARIABLE: { if (_variablesEndIdx == -1) { - idx = 0; + idx = -1; break; } idx = FindIdxInRagne(this, _placeholderEndIdx, _variablesEndIdx, s.ToString()); break; default: - idx = 0; + idx = -1; break; } } @@ -412,7 +412,7 @@ bool SceneSelectionWidget::IsPreviewSceneSelected(const QString &name) "AdvSceneSwitcher.selectPreviewScene"))); } -void SceneSelectionWidget::SelectionChanged(const QString &) +void SceneSelectionWidget::SelectionChanged(int) { _currentSelection = CurrentSelection(); emit SceneChanged(_currentSelection); diff --git a/src/utils/scene-selection.hpp b/src/utils/scene-selection.hpp index cf9727d4..5e00c3d4 100644 --- a/src/utils/scene-selection.hpp +++ b/src/utils/scene-selection.hpp @@ -1,10 +1,9 @@ #pragma once #include "scene-group.hpp" #include "variable.hpp" +#include "filter-combo-box.hpp" #include "utility.hpp" -#include - namespace advss { class SceneSelection { @@ -34,7 +33,7 @@ private: friend class SceneSelectionWidget; }; -class SceneSelectionWidget : public QComboBox { +class SceneSelectionWidget : public FilterComboBox { Q_OBJECT public: @@ -46,7 +45,7 @@ signals: void SceneChanged(const SceneSelection &); private slots: - void SelectionChanged(const QString &name); + void SelectionChanged(int); void ItemAdd(const QString &name); void ItemRemove(const QString &name); void ItemRename(const QString &oldName, const QString &newName); diff --git a/src/utils/source-selection.cpp b/src/utils/source-selection.cpp index 9d7aef25..0d79afb1 100644 --- a/src/utils/source-selection.cpp +++ b/src/utils/source-selection.cpp @@ -125,6 +125,9 @@ SourceSelection SourceSelectionWidget::CurrentSelection() SourceSelection s; const int idx = currentIndex(); const auto name = currentText(); + if (idx == -1 || name.isEmpty()) { + return s; + } if (idx < _variablesEndIdx) { s._type = SourceSelection::Type::VARIABLE; @@ -146,10 +149,6 @@ void SourceSelectionWidget::Reset() void SourceSelectionWidget::PopulateSelection() { clear(); - AddSelectionEntry(this, - obs_module_text("AdvSceneSwitcher.selectSource")); - insertSeparator(count()); - if (_addVariables) { const QStringList variables = GetVariablesNameList(); AddSelectionGroup(this, variables); @@ -161,21 +160,22 @@ void SourceSelectionWidget::PopulateSelection() // Remove last separator removeItem(count() - 1); - setCurrentIndex(0); + setCurrentIndex(-1); } SourceSelectionWidget::SourceSelectionWidget(QWidget *parent, const QStringList &sourceNames, bool addVariables) - : QComboBox(parent), + : FilterComboBox(parent, + obs_module_text("AdvSceneSwitcher.selectSource")), _addVariables(addVariables), _sourceNames(sourceNames) { setDuplicatesEnabled(true); PopulateSelection(); - QWidget::connect(this, SIGNAL(currentTextChanged(const QString &)), - this, SLOT(SelectionChanged(const QString &))); + QWidget::connect(this, SIGNAL(currentIndexChanged(int)), this, + SLOT(SelectionChanged(int))); // Variables QWidget::connect(window(), SIGNAL(VariableAdded(const QString &)), this, @@ -190,12 +190,12 @@ SourceSelectionWidget::SourceSelectionWidget(QWidget *parent, void SourceSelectionWidget::SetSource(const SourceSelection &s) { - int idx = 0; + int idx = -1; switch (s.GetType()) { case SourceSelection::Type::SOURCE: { if (_sourcesEndIdx == -1) { - idx = 0; + idx = -1; break; } idx = FindIdxInRagne(this, _variablesEndIdx, _sourcesEndIdx, @@ -204,14 +204,14 @@ void SourceSelectionWidget::SetSource(const SourceSelection &s) } case SourceSelection::Type::VARIABLE: { if (_variablesEndIdx == -1) { - idx = 0; + idx = -1; break; } idx = FindIdxInRagne(this, _selectIdx, _variablesEndIdx, s.ToString()); break; default: - idx = 0; + idx = -1; break; } } @@ -225,7 +225,7 @@ void SourceSelectionWidget::SetSourceNameList(const QStringList &list) Reset(); } -void SourceSelectionWidget::SelectionChanged(const QString &) +void SourceSelectionWidget::SelectionChanged(int) { _currentSelection = CurrentSelection(); emit SourceChanged(_currentSelection); diff --git a/src/utils/source-selection.hpp b/src/utils/source-selection.hpp index 198f8e2c..c0c055bc 100644 --- a/src/utils/source-selection.hpp +++ b/src/utils/source-selection.hpp @@ -1,10 +1,8 @@ #pragma once - #include "variable.hpp" +#include "filter-combo-box.hpp" #include "utility.hpp" -#include - namespace advss { class SourceSelection { @@ -35,7 +33,7 @@ private: friend class SourceSelectionWidget; }; -class SourceSelectionWidget : public QComboBox { +class SourceSelectionWidget : public FilterComboBox { Q_OBJECT public: @@ -47,7 +45,7 @@ signals: void SourceChanged(const SourceSelection &); private slots: - void SelectionChanged(const QString &name); + void SelectionChanged(int); void ItemAdd(const QString &name); void ItemRemove(const QString &name); void ItemRename(const QString &oldName, const QString &newName); diff --git a/src/utils/transition-selection.cpp b/src/utils/transition-selection.cpp index 1913083e..65bf1ab8 100644 --- a/src/utils/transition-selection.cpp +++ b/src/utils/transition-selection.cpp @@ -67,10 +67,11 @@ std::string TransitionSelection::ToString() const TransitionSelectionWidget::TransitionSelectionWidget(QWidget *parent, bool current, bool any) - : QComboBox(parent) + : FilterComboBox(parent, + obs_module_text("AdvSceneSwitcher.selectTransition")) { setDuplicatesEnabled(true); - PopulateTransitionSelection(this, current, any); + PopulateTransitionSelection(this, current, any, false); QWidget::connect(this, SIGNAL(currentTextChanged(const QString &)), this, SLOT(SelectionChanged(const QString &))); diff --git a/src/utils/transition-selection.hpp b/src/utils/transition-selection.hpp index a2bc5ac3..c0394283 100644 --- a/src/utils/transition-selection.hpp +++ b/src/utils/transition-selection.hpp @@ -1,8 +1,7 @@ #pragma once +#include "filter-combo-box.hpp" #include "utility.hpp" -#include - namespace advss { class TransitionSelection { @@ -28,7 +27,7 @@ private: friend class TransitionSelectionWidget; }; -class TransitionSelectionWidget : public QComboBox { +class TransitionSelectionWidget : public FilterComboBox { Q_OBJECT public: diff --git a/src/utils/utility.cpp b/src/utils/utility.cpp index 53fa5377..3f95f702 100644 --- a/src/utils/utility.cpp +++ b/src/utils/utility.cpp @@ -1149,19 +1149,18 @@ int FindIdxInRagne(QComboBox *list, int start, int stop, const std::string &value, Qt::MatchFlags flags) { if (value.empty()) { - return 0; + return -1; } auto model = list->model(); auto startIdx = model->index(start, 0); auto match = model->match(startIdx, Qt::DisplayRole, - QString::fromStdString(value), 1, - flags); + QString::fromStdString(value), 1, flags); if (match.isEmpty()) { - return 0; + return -1; } int foundIdx = match.first().row(); if (foundIdx > stop) { - return 0; + return -1; } return foundIdx; }