summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-04-29 16:18:21 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-04-29 16:18:21 +0200
commitc4942d72935cacc150815f2f5221c71fc3f05bc1 (patch)
treec3d910986d8467a2c9e9a5451b7ef05930beeb50
parentc231d6a2ba35281f57024a195e50db6640a6413d (diff)
options/tie: allow for binding with a format string
-rw-r--r--options/options.hpp2
-rw-r--r--options/tie.cpp2
-rw-r--r--options/tie.hpp11
3 files changed, 13 insertions, 2 deletions
diff --git a/options/options.hpp b/options/options.hpp
index c1eed97c..0528b0d9 100644
--- a/options/options.hpp
+++ b/options/options.hpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2016 Stanislaw Halik
+/* Copyright (c) 2013-2017 Stanislaw Halik
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
diff --git a/options/tie.cpp b/options/tie.cpp
index ce0e5a35..934871a9 100644
--- a/options/tie.cpp
+++ b/options/tie.cpp
@@ -103,7 +103,7 @@ OTR_OPTIONS_EXPORT void tie_setting(value<QString>& v, QLineEdit* le)
OTR_OPTIONS_EXPORT void tie_setting(value<QString>& v, QLabel* lb)
{
lb->setText(v);
- base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.DIRECT_CONNTYPE);
+ base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.SAFE_CONNTYPE);
}
OTR_OPTIONS_EXPORT void tie_setting(value<int>& v, QTabWidget* t)
diff --git a/options/tie.hpp b/options/tie.hpp
index 93004e0f..a3b5a19f 100644
--- a/options/tie.hpp
+++ b/options/tie.hpp
@@ -47,6 +47,17 @@ tie_setting(value<t>& v, QComboBox* cb)
v.SAFE_CONNTYPE);
}
+template<typename t, typename... xs>
+void tie_setting(value<t>& v, QLabel* lb, const QString& format, const xs&... args)
+{
+ auto closure = [=](const t& x) { lb->setText(format.arg(x, args...)); };
+
+ closure(v());
+ base_value::connect(&v, static_cast<void(base_value::*)(const t&) const>(&base_value::valueChanged),
+ lb, closure,
+ v.SAFE_CONNTYPE);
+}
+
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);