From: Uwe Hermann Date: Wed, 29 Mar 2017 22:57:33 +0000 (+0200) Subject: binding/prop: Add a description field. X-Git-Tag: pulseview-0.4.0~111 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=9a267f8dec48c9a28472c1a3bb146c624819e98b;p=pulseview.git binding/prop: Add a description field. The config key / option bindings only allowed for a single name so far. Add an additional description field, which can be used for longer descriptions of the config keys / options. Hook up the input/output format option descriptions. --- diff --git a/pv/binding/decoder.cpp b/pv/binding/decoder.cpp index b2b4e4f7..f2e2e1d5 100644 --- a/pv/binding/decoder.cpp +++ b/pv/binding/decoder.cpp @@ -72,16 +72,16 @@ Decoder::Decoder( shared_ptr prop; if (opt->values) - prop = bind_enum(name, opt, get, set); + prop = bind_enum(name, "", opt, get, set); else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("d"))) - prop = shared_ptr(new Double(name, 2, "", + prop = shared_ptr(new Double(name, "", 2, "", none, none, get, set)); else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x"))) prop = shared_ptr( - new Int(name, "", none, get, set)); + new Int(name, "", "", none, get, set)); else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s"))) prop = shared_ptr( - new String(name, get, set)); + new String(name, "", get, set)); else continue; @@ -90,7 +90,8 @@ Decoder::Decoder( } shared_ptr Decoder::bind_enum( - const QString &name, const srd_decoder_option *option, + const QString &name, const QString &desc, + const srd_decoder_option *option, Property::Getter getter, Property::Setter setter) { vector< pair > values; @@ -99,7 +100,7 @@ shared_ptr Decoder::bind_enum( values.push_back(make_pair(var, print_gvariant(var))); } - return shared_ptr(new Enum(name, values, getter, setter)); + return shared_ptr(new Enum(name, desc, values, getter, setter)); } Glib::VariantBase Decoder::getter(const char *id) diff --git a/pv/binding/decoder.hpp b/pv/binding/decoder.hpp index 044c0f65..bf670403 100644 --- a/pv/binding/decoder.hpp +++ b/pv/binding/decoder.hpp @@ -47,7 +47,7 @@ public: private: static shared_ptr bind_enum(const QString &name, - const srd_decoder_option *option, + const QString &desc, const srd_decoder_option *option, prop::Property::Getter getter, prop::Property::Setter setter); Glib::VariantBase getter(const char *id); diff --git a/pv/binding/device.cpp b/pv/binding/device.cpp index 3ebc9f9f..401644fd 100644 --- a/pv/binding/device.cpp +++ b/pv/binding/device.cpp @@ -89,7 +89,7 @@ Device::Device(shared_ptr configurable) : break; case SR_CONF_CAPTURE_RATIO: - bind_int(name, "%", pair(0, 100), + bind_int(name, "", "%", pair(0, 100), get, set); break; @@ -99,33 +99,33 @@ Device::Device(shared_ptr configurable) : case SR_CONF_TRIGGER_SLOPE: case SR_CONF_COUPLING: case SR_CONF_CLOCK_EDGE: - bind_enum(name, key, capabilities, get, set); + bind_enum(name, "", key, capabilities, get, set); break; case SR_CONF_FILTER: case SR_CONF_EXTERNAL_CLOCK: case SR_CONF_RLE: case SR_CONF_POWER_OFF: - bind_bool(name, get, set); + bind_bool(name, "", get, set); break; case SR_CONF_TIMEBASE: - bind_enum(name, key, capabilities, get, set, print_timebase); + bind_enum(name, "", key, capabilities, get, set, print_timebase); break; case SR_CONF_VDIV: - bind_enum(name, key, capabilities, get, set, print_vdiv); + bind_enum(name, "", key, capabilities, get, set, print_vdiv); break; case SR_CONF_VOLTAGE_THRESHOLD: - bind_enum(name, key, capabilities, get, set, print_voltage_threshold); + bind_enum(name, "", key, capabilities, get, set, print_voltage_threshold); break; case SR_CONF_PROBE_FACTOR: if (capabilities.count(Capability::LIST)) - bind_enum(name, key, capabilities, get, set, print_probe_factor); + bind_enum(name, "", key, capabilities, get, set, print_probe_factor); else - bind_int(name, "", pair(1, 500), get, set); + bind_int(name, "", "", pair(1, 500), get, set); break; default: @@ -134,15 +134,15 @@ Device::Device(shared_ptr configurable) : } } -void Device::bind_bool(const QString &name, +void Device::bind_bool(const QString &name, const QString &desc, Property::Getter getter, Property::Setter setter) { assert(configurable_); properties_.push_back(shared_ptr(new Bool( - name, getter, setter))); + name, desc, getter, setter))); } -void Device::bind_enum(const QString &name, +void Device::bind_enum(const QString &name, const QString &desc, const ConfigKey *key, set capabilities, Property::Getter getter, Property::Setter setter, function printer) @@ -159,18 +159,18 @@ void Device::bind_enum(const QString &name, while ((iter.next_value(gvar))) values.push_back(make_pair(gvar, printer(gvar))); - properties_.push_back(shared_ptr(new Enum(name, values, + properties_.push_back(shared_ptr(new Enum(name, desc, values, getter, setter))); } -void Device::bind_int(const QString &name, QString suffix, +void Device::bind_int(const QString &name, const QString &desc, QString suffix, optional< pair > range, Property::Getter getter, Property::Setter setter) { assert(configurable_); - properties_.push_back(shared_ptr(new Int(name, suffix, range, - getter, setter))); + properties_.push_back(shared_ptr(new Int(name, desc, suffix, + range, getter, setter))); } QString Device::print_timebase(Glib::VariantBase gvar) diff --git a/pv/binding/device.hpp b/pv/binding/device.hpp index 4c4d6f44..dcef9470 100644 --- a/pv/binding/device.hpp +++ b/pv/binding/device.hpp @@ -51,14 +51,14 @@ Q_SIGNALS: void config_changed(); private: - void bind_bool(const QString &name, + void bind_bool(const QString &name, const QString &desc, prop::Property::Getter getter, prop::Property::Setter setter); - void bind_enum(const QString &name, + void bind_enum(const QString &name, const QString &desc, const sigrok::ConfigKey *key, set capabilities, prop::Property::Getter getter, prop::Property::Setter setter, function printer = print_gvariant); - void bind_int(const QString &name, QString suffix, + void bind_int(const QString &name, const QString &desc, QString suffix, boost::optional< pair > range, prop::Property::Getter getter, prop::Property::Setter setter); diff --git a/pv/binding/inputoutput.cpp b/pv/binding/inputoutput.cpp index d13ba196..df9d3799 100644 --- a/pv/binding/inputoutput.cpp +++ b/pv/binding/inputoutput.cpp @@ -65,6 +65,7 @@ InputOutput::InputOutput( assert(opt); const QString name = QString::fromStdString(opt->name()); + const QString desc = QString::fromStdString(opt->description()); const VariantBase def_val = opt->default_value(); const vector values = opt->values(); @@ -78,20 +79,20 @@ InputOutput::InputOutput( shared_ptr prop; if (!opt->values().empty()) - prop = bind_enum(name, values, get, set); + prop = bind_enum(name, desc, values, get, set); else if (def_val.is_of_type(VariantType("b"))) - prop = shared_ptr(new Bool(name, get, set)); + prop = shared_ptr(new Bool(name, desc, get, set)); else if (def_val.is_of_type(VariantType("d"))) - prop = shared_ptr(new Double(name, 2, "", + prop = shared_ptr(new Double(name, desc, 2, "", none, none, get, set)); else if (def_val.is_of_type(VariantType("i")) || def_val.is_of_type(VariantType("t")) || def_val.is_of_type(VariantType("u"))) prop = shared_ptr( - new Int(name, "", none, get, set)); + new Int(name, desc, "", none, get, set)); else if (def_val.is_of_type(VariantType("s"))) prop = shared_ptr( - new String(name, get, set)); + new String(name, desc, get, set)); else continue; @@ -105,13 +106,13 @@ const map& InputOutput::options() const } shared_ptr InputOutput::bind_enum( - const QString &name, const vector &values, + const QString &name, const QString &desc, const vector &values, Property::Getter getter, Property::Setter setter) { vector< pair > enum_vals; for (VariantBase var : values) enum_vals.push_back(make_pair(var, print_gvariant(var))); - return shared_ptr(new Enum(name, enum_vals, getter, setter)); + return shared_ptr(new Enum(name, desc, enum_vals, getter, setter)); } } // namespace binding diff --git a/pv/binding/inputoutput.hpp b/pv/binding/inputoutput.hpp index 7aa90a16..acfb61cb 100644 --- a/pv/binding/inputoutput.hpp +++ b/pv/binding/inputoutput.hpp @@ -62,12 +62,13 @@ private: /** * A helper function to bind an option list to and enum property. * @param name the name of the property. + * @param name the description of the property. * @param values the list of values. * @param getter the getter that will read the values out of the map. * @param setter the setter that will set the values into the map. */ shared_ptr bind_enum(const QString &name, - const vector &values, + const QString &desc, const vector &values, prop::Property::Getter getter, prop::Property::Setter setter); private: diff --git a/pv/prop/bool.cpp b/pv/prop/bool.cpp index 2773eaae..aab5a723 100644 --- a/pv/prop/bool.cpp +++ b/pv/prop/bool.cpp @@ -26,8 +26,8 @@ namespace pv { namespace prop { -Bool::Bool(QString name, Getter getter, Setter setter) : - Property(name, getter, setter), +Bool::Bool(QString name, QString desc, Getter getter, Setter setter) : + Property(name, desc, getter, setter), check_box_(nullptr) { } diff --git a/pv/prop/bool.hpp b/pv/prop/bool.hpp index 619502de..ef0916f4 100644 --- a/pv/prop/bool.hpp +++ b/pv/prop/bool.hpp @@ -32,7 +32,7 @@ class Bool : public Property Q_OBJECT; public: - Bool(QString name, Getter getter, Setter setter); + Bool(QString name, QString desc, Getter getter, Setter setter); virtual ~Bool() = default; diff --git a/pv/prop/double.cpp b/pv/prop/double.cpp index 2e7f1d54..e1539a12 100644 --- a/pv/prop/double.cpp +++ b/pv/prop/double.cpp @@ -30,13 +30,14 @@ namespace pv { namespace prop { Double::Double(QString name, + QString desc, int decimals, QString suffix, optional< pair > range, optional step, Getter getter, Setter setter) : - Property(name, getter, setter), + Property(name, desc, getter, setter), decimals_(decimals), suffix_(suffix), range_(range), diff --git a/pv/prop/double.hpp b/pv/prop/double.hpp index 863648d8..4e18e956 100644 --- a/pv/prop/double.hpp +++ b/pv/prop/double.hpp @@ -38,7 +38,7 @@ class Double : public Property Q_OBJECT public: - Double(QString name, int decimals, QString suffix, + Double(QString name, QString desc, int decimals, QString suffix, boost::optional< pair > range, boost::optional step, Getter getter, diff --git a/pv/prop/enum.cpp b/pv/prop/enum.cpp index 7a4a7837..d5d571a9 100644 --- a/pv/prop/enum.cpp +++ b/pv/prop/enum.cpp @@ -29,10 +29,10 @@ using std::vector; namespace pv { namespace prop { -Enum::Enum(QString name, +Enum::Enum(QString name, QString desc, vector > values, Getter getter, Setter setter) : - Property(name, getter, setter), + Property(name, desc, getter, setter), values_(values), selector_(nullptr) { diff --git a/pv/prop/enum.hpp b/pv/prop/enum.hpp index a397913c..0193e238 100644 --- a/pv/prop/enum.hpp +++ b/pv/prop/enum.hpp @@ -42,7 +42,8 @@ class Enum : public Property Q_OBJECT; public: - Enum(QString name, vector > values, + Enum(QString name, QString desc, + vector > values, Getter getter, Setter setter); virtual ~Enum() = default; diff --git a/pv/prop/int.cpp b/pv/prop/int.cpp index f53d0966..98b23ba6 100644 --- a/pv/prop/int.cpp +++ b/pv/prop/int.cpp @@ -33,11 +33,12 @@ namespace pv { namespace prop { Int::Int(QString name, + QString desc, QString suffix, optional< pair > range, Getter getter, Setter setter) : - Property(name, getter, setter), + Property(name, desc, getter, setter), suffix_(suffix), range_(range), spin_box_(nullptr) diff --git a/pv/prop/int.hpp b/pv/prop/int.hpp index fabd8013..709e02e6 100644 --- a/pv/prop/int.hpp +++ b/pv/prop/int.hpp @@ -38,7 +38,7 @@ class Int : public Property Q_OBJECT; public: - Int(QString name, QString suffix, + Int(QString name, QString desc, QString suffix, boost::optional< pair > range, Getter getter, Setter setter); diff --git a/pv/prop/property.cpp b/pv/prop/property.cpp index 9bb99c2e..557c2a99 100644 --- a/pv/prop/property.cpp +++ b/pv/prop/property.cpp @@ -22,10 +22,11 @@ namespace pv { namespace prop { -Property::Property(QString name, Getter getter, Setter setter) : +Property::Property(QString name, QString desc, Getter getter, Setter setter) : getter_(getter), setter_(setter), - name_(name) + name_(name), + desc_(desc) { } @@ -34,6 +35,11 @@ const QString& Property::name() const return name_; } +const QString& Property::desc() const +{ + return desc_; +} + bool Property::labeled_widget() const { return false; diff --git a/pv/prop/property.hpp b/pv/prop/property.hpp index 765cbb50..322c6084 100644 --- a/pv/prop/property.hpp +++ b/pv/prop/property.hpp @@ -47,10 +47,11 @@ public: typedef function Setter; protected: - Property(QString name, Getter getter, Setter setter); + Property(QString name, QString desc, Getter getter, Setter setter); public: const QString& name() const; + const QString& desc() const; virtual QWidget* get_widget(QWidget *parent, bool auto_commit = false) = 0; @@ -64,6 +65,7 @@ protected: private: QString name_; + QString desc_; }; } // namespace prop diff --git a/pv/prop/string.cpp b/pv/prop/string.cpp index 23c7f913..96a83422 100644 --- a/pv/prop/string.cpp +++ b/pv/prop/string.cpp @@ -32,9 +32,10 @@ namespace pv { namespace prop { String::String(QString name, + QString desc, Getter getter, Setter setter) : - Property(name, getter, setter), + Property(name, desc, getter, setter), line_edit_(nullptr) { } diff --git a/pv/prop/string.hpp b/pv/prop/string.hpp index b75b3ae6..8ce8be61 100644 --- a/pv/prop/string.hpp +++ b/pv/prop/string.hpp @@ -32,7 +32,7 @@ class String : public Property Q_OBJECT; public: - String(QString name, Getter getter, Setter setter); + String(QString name, QString desc, Getter getter, Setter setter); QWidget* get_widget(QWidget *parent, bool auto_commit);