diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-03-30 15:32:53 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-04-06 04:21:36 +0200 |
commit | 91ca7726d4af5e86a2d5d10ec56685be22b0face (patch) | |
tree | 5271aa690ec30cbfdf61332614b0b055aea9e4ee /options/tie.cpp | |
parent | e4d5b49d74a749b6ac9fc741c5e9942095073cdb (diff) |
options: allow tie combobox to qvariant
Diffstat (limited to 'options/tie.cpp')
-rw-r--r-- | options/tie.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/options/tie.cpp b/options/tie.cpp index 7a78237f..ce0e5a35 100644 --- a/options/tie.cpp +++ b/options/tie.cpp @@ -26,6 +26,44 @@ OTR_OPTIONS_EXPORT void tie_setting(value<QString>& v, QComboBox* cb) base_value::connect(&v, SIGNAL(valueChanged(QString)), cb, SLOT(setCurrentText(QString)), v.SAFE_CONNTYPE); } +OTR_OPTIONS_EXPORT void tie_setting(value<QVariant>& v, QComboBox* cb) +{ + auto set_idx = [cb](const QVariant& var) { + const int sz = cb->count(); + int idx = -1; + + for (int k = 0; k < sz; k++) + { + if (cb->itemData(k) == var) + { + idx = k; + break; + } + } + cb->setCurrentIndex(idx); + return idx; + }; + + const int idx = set_idx(v); + + if (idx != -1) + v = cb->itemData(idx); + else + v = QVariant(QVariant::Invalid); + + base_value::connect(cb, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + &v, [cb, &v](int idx) { + v = cb->itemData(idx); + }, v.DIRECT_CONNTYPE); + base_value::connect(&v, static_cast<void(base_value::*)(const QVariant&) const>(&base_value::valueChanged), + cb, + [cb, set_idx](const QVariant& var) { + run_in_thread_sync(cb, [&]() { + set_idx(var); + }); + }, v.DIRECT_CONNTYPE); +} + OTR_OPTIONS_EXPORT void tie_setting(value<bool>& v, QCheckBox* cb) { cb->setChecked(v); @@ -116,6 +154,4 @@ OTR_OPTIONS_EXPORT void tie_setting(value<slider_value>& v, QSlider* w) v.DIRECT_CONNTYPE); } - - } // ns options |