UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
combobox_ui.cpp
Go to the documentation of this file.
1#include "combobox_ui.hpp"
2#include "overload.hpp"
3
4ComboBoxUi::ComboBoxUi(QComboBox *box,
5 Settings *settings,
6 const std::string &opt,
7 std::function<std::vector<SettingItem>()> itemBuilder) :
8 WidgetUi(settings, opt),
9 box(box),
10 itemBuilder(std::move(itemBuilder)),
11 ignoreCallback(false)
12{
13 refresh();
16}
17
19 connect(box, Overload<int>::of(&QComboBox::activated),
21}
22
25
26 for(const auto &item : items){
27 for(const auto &opt : item.opts){
29 }
30 for(const auto &condClause : item.conditions){
31 for(const auto &condItem : condClause){
32 registerCallback(condItem.value.opt);
33 }
34 }
35 }
36
39}
40
42 const std::vector<std::vector<ConditionItem>> &conds,
43 Settings *settings)
44{
45 for(const auto &condClause : conds){
46 bool orRes = false;
47 for(const auto &condItem : condClause){
48 bool val = condItem.value.val == settings->getOption(condItem.value.opt).getValue();
49
50 //negate result if negation is true
51 val = val != condItem.negation;
52
53 if(val){
54 orRes = true;
55 break;
56 }
57 }
58 if(!orRes){
59 return false;
60 }
61 }
62
63 return true;
64}
65
67 int i;
68 bool found = false;
69 for(i = 0; i < box->count(); i++){
70 const SettingItem &item = box->itemData(i).value<SettingItem>();
71
72 found = true;
73 for(const auto &itemOpt : item.opts){
74 if(itemOpt.val != settings->getOption(itemOpt.opt).getValue()){
75 found = false;
76 break;
77 }
78 }
79
80 if(found)
81 break;
82 }
83
84 if(found){
85 box->setCurrentIndex(i);
86 } else {
87 itemSelected(0);
88 }
89}
90
91void ComboBoxUi::optChangeCallback(Option &opt, bool suboption){
92 if(suboption || ignoreCallback)
93 return;
94
95 if(opt.getName() != this->opt)
97
99}
100
104
106 box->clear();
107
108 for(const auto &i : items){
109 if(conditionsSatisfied(i.conditions, settings)){
110 box->addItem(QString::fromStdString(i.name),
111 QVariant::fromValue(i));
112 }
113 }
114}
115
117 const SettingItem &item = box->itemData(index).value<SettingItem>();
118
119 ignoreCallback = true;
120 for(const auto &option : item.opts){
121 settings->getOption(option.opt).setValue(option.val);
122 }
123 ignoreCallback = false;
124
125 emit changed();
126}
127
int void * val
QComboBox * box
std::vector< SettingItem > items
void updateUiState() override
bool ignoreCallback
void refresh() override
void selectOption()
void updateUiItems()
ComboBoxUi(QComboBox *box, Settings *settings, const std::string &opt, std::function< std::vector< SettingItem >()> itemBuilder)
std::function< std::vector< SettingItem >()> itemBuilder
void itemSelected(int index)
void optChangeCallback(Option &opt, bool suboption) override
void connectSignals() override
std::string getValue() const
Definition settings.cpp:26
virtual void setValue(const std::string &val, bool suppressCallback=false)
Definition settings.cpp:73
const Option & getOption(const std::string &opt) const
Definition settings.cpp:384
std::string opt
Definition widget_ui.hpp:34
void registerCallback()
Definition widget_ui.cpp:57
void changed()
Settings * settings
Definition widget_ui.hpp:33
static bool conditionsSatisfied(const std::vector< std::vector< ConditionItem > > &conds, Settings *settings)
QOverload< Args... > Overload
Definition overload.hpp:9
Definition hd-rum.c:27