summaryrefslogtreecommitdiffhomepage
path: root/options
diff options
context:
space:
mode:
Diffstat (limited to 'options')
-rw-r--r--options/tie.cpp40
-rw-r--r--options/tie.hpp1
-rw-r--r--options/value.hpp7
3 files changed, 46 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
diff --git a/options/tie.hpp b/options/tie.hpp
index 1745438f..93004e0f 100644
--- a/options/tie.hpp
+++ b/options/tie.hpp
@@ -49,6 +49,7 @@ tie_setting(value<t>& v, QComboBox* cb)
OTR_OPTIONS_EXPORT void tie_setting(value<int>& v, QComboBox* cb);
OTR_OPTIONS_EXPORT void tie_setting(value<QString>& v, QComboBox* cb);
+OTR_OPTIONS_EXPORT void tie_setting(value<QVariant>& v, QComboBox* cb);
OTR_OPTIONS_EXPORT void tie_setting(value<bool>& v, QCheckBox* cb);
OTR_OPTIONS_EXPORT void tie_setting(value<double>& v, QDoubleSpinBox* dsb);
OTR_OPTIONS_EXPORT void tie_setting(value<int>& v, QSpinBox* sb);
diff --git a/options/value.hpp b/options/value.hpp
index 4904c370..48f71d47 100644
--- a/options/value.hpp
+++ b/options/value.hpp
@@ -55,6 +55,7 @@ signals:
OPENTRACK_DEFINE_SIGNAL(const QString&);
OPENTRACK_DEFINE_SIGNAL(const slider_value&);
OPENTRACK_DEFINE_SIGNAL(const QPointF&);
+ OPENTRACK_DEFINE_SIGNAL(const QVariant&);
OPENTRACK_DEFINE_SIGNAL(const QList<double>&);
OPENTRACK_DEFINE_SIGNAL(const QList<float>&);
@@ -69,6 +70,11 @@ protected:
comparator cmp;
std::type_index type_index;
+ void store(const QVariant& datum)
+ {
+ b->store_kv(self_name, datum);
+ }
+
template<typename t>
void store(const t& datum)
{
@@ -82,6 +88,7 @@ public slots:
OPENTRACK_DEFINE_SLOT(const QString&)
OPENTRACK_DEFINE_SLOT(const slider_value&)
OPENTRACK_DEFINE_SLOT(const QPointF&)
+ OPENTRACK_DEFINE_SLOT(const QVariant&)
OPENTRACK_DEFINE_SLOT(const QList<double>&)
OPENTRACK_DEFINE_SLOT(const QList<float>&)