]> sigrok.org Git - pulseview.git/commitdiff
binding/prop: Add a description field.
authorUwe Hermann <redacted>
Wed, 29 Mar 2017 22:57:33 +0000 (00:57 +0200)
committerUwe Hermann <redacted>
Thu, 30 Mar 2017 17:57:06 +0000 (19:57 +0200)
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.

18 files changed:
pv/binding/decoder.cpp
pv/binding/decoder.hpp
pv/binding/device.cpp
pv/binding/device.hpp
pv/binding/inputoutput.cpp
pv/binding/inputoutput.hpp
pv/prop/bool.cpp
pv/prop/bool.hpp
pv/prop/double.cpp
pv/prop/double.hpp
pv/prop/enum.cpp
pv/prop/enum.hpp
pv/prop/int.cpp
pv/prop/int.hpp
pv/prop/property.cpp
pv/prop/property.hpp
pv/prop/string.cpp
pv/prop/string.hpp

index b2b4e4f7e6728198713a67e8042b71b5e4ce0c8f..f2e2e1d579f46eabe7b67104de3a103a6647055a 100644 (file)
@@ -72,16 +72,16 @@ Decoder::Decoder(
                shared_ptr<Property> 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<Property>(new Double(name, 2, "",
+                       prop = shared_ptr<Property>(new Double(name, "", 2, "",
                                none, none, get, set));
                else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x")))
                        prop = shared_ptr<Property>(
-                               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<Property>(
-                               new String(name, get, set));
+                               new String(name, "", get, set));
                else
                        continue;
 
@@ -90,7 +90,8 @@ Decoder::Decoder(
 }
 
 shared_ptr<Property> 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<Glib::VariantBase, QString> > values;
@@ -99,7 +100,7 @@ shared_ptr<Property> Decoder::bind_enum(
                values.push_back(make_pair(var, print_gvariant(var)));
        }
 
-       return shared_ptr<Property>(new Enum(name, values, getter, setter));
+       return shared_ptr<Property>(new Enum(name, desc, values, getter, setter));
 }
 
 Glib::VariantBase Decoder::getter(const char *id)
index 044c0f652dcd7eab29dc9bb7a655da49171cbd03..bf670403dee317f486c5d43ab093eb74932288fa 100644 (file)
@@ -47,7 +47,7 @@ public:
 
 private:
        static shared_ptr<prop::Property> 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);
index 3ebc9f9f41839b67d0d6fac1b8cb4d26f7b5ff33..401644fd0672fa616c5c21586f619590e8b1cff1 100644 (file)
@@ -89,7 +89,7 @@ Device::Device(shared_ptr<sigrok::Configurable> configurable) :
                        break;
 
                case SR_CONF_CAPTURE_RATIO:
-                       bind_int(name, "%", pair<int64_t, int64_t>(0, 100),
+                       bind_int(name, "", "%", pair<int64_t, int64_t>(0, 100),
                                get, set);
                        break;
 
@@ -99,33 +99,33 @@ Device::Device(shared_ptr<sigrok::Configurable> 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<int64_t, int64_t>(1, 500), get, set);
+                               bind_int(name, "", "", pair<int64_t, int64_t>(1, 500), get, set);
                        break;
 
                default:
@@ -134,15 +134,15 @@ Device::Device(shared_ptr<sigrok::Configurable> 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<Property>(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<const Capability *> capabilities,
        Property::Getter getter,
        Property::Setter setter, function<QString (Glib::VariantBase)> 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<Property>(new Enum(name, values,
+       properties_.push_back(shared_ptr<Property>(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<int64_t, int64_t> > range,
        Property::Getter getter, Property::Setter setter)
 {
        assert(configurable_);
 
-       properties_.push_back(shared_ptr<Property>(new Int(name, suffix, range,
-               getter, setter)));
+       properties_.push_back(shared_ptr<Property>(new Int(name, desc, suffix,
+               range, getter, setter)));
 }
 
 QString Device::print_timebase(Glib::VariantBase gvar)
index 4c4d6f44dcf5ab8d3d678d7f78229b0e9b9ee5c4..dcef9470cc12e091565871486d1ef3d6a8799053 100644 (file)
@@ -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<const sigrok::Capability *> capabilities,
                prop::Property::Getter getter, prop::Property::Setter setter,
                function<QString (Glib::VariantBase)> 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<int64_t, int64_t> > range,
                prop::Property::Getter getter, prop::Property::Setter setter);
 
index d13ba196e3674ea29b46be4ca3b122bbb38f8f72..df9d3799eb287ccfdb78682d077236aed95cff5f 100644 (file)
@@ -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<VariantBase> values = opt->values();
 
@@ -78,20 +79,20 @@ InputOutput::InputOutput(
                shared_ptr<Property> 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<Property>(new Bool(name, get, set));
+                       prop = shared_ptr<Property>(new Bool(name, desc, get, set));
                else if (def_val.is_of_type(VariantType("d")))
-                       prop = shared_ptr<Property>(new Double(name, 2, "",
+                       prop = shared_ptr<Property>(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<Property>(
-                               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<Property>(
-                               new String(name, get, set));
+                               new String(name, desc, get, set));
                else
                        continue;
 
@@ -105,13 +106,13 @@ const map<string, VariantBase>& InputOutput::options() const
 }
 
 shared_ptr<Property> InputOutput::bind_enum(
-       const QString &name, const vector<VariantBase> &values,
+       const QString &name, const QString &desc, const vector<VariantBase> &values,
        Property::Getter getter, Property::Setter setter)
 {
        vector< pair<VariantBase, QString> > enum_vals;
        for (VariantBase var : values)
                enum_vals.push_back(make_pair(var, print_gvariant(var)));
-       return shared_ptr<Property>(new Enum(name, enum_vals, getter, setter));
+       return shared_ptr<Property>(new Enum(name, desc, enum_vals, getter, setter));
 }
 
 } // namespace binding
index 7aa90a16f9e7fe37e0125c493cd1c75f8da28483..acfb61cb6b401ceaaa4b839088cb0b36803b6387 100644 (file)
@@ -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<prop::Property> bind_enum(const QString &name,
-               const vector<Glib::VariantBase> &values,
+               const QString &desc, const vector<Glib::VariantBase> &values,
                prop::Property::Getter getter, prop::Property::Setter setter);
 
 private:
index 2773eaae708ebdefbdc4906ee063400180d5395c..aab5a723c862343feee4c89db918e2b43403f956 100644 (file)
@@ -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)
 {
 }
index 619502dec5fe50cb436b091465192eb8d958c7f2..ef0916f48523a533d228296549138cd786eb7c29 100644 (file)
@@ -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;
 
index 2e7f1d542038eb959739ea0d8d06a6a28e116513..e1539a127d63dccd9830673a21d66bd07e343f69 100644 (file)
@@ -30,13 +30,14 @@ namespace pv {
 namespace prop {
 
 Double::Double(QString name,
+       QString desc,
        int decimals,
        QString suffix,
        optional< pair<double, double> > range,
        optional<double> step,
        Getter getter,
        Setter setter) :
-       Property(name, getter, setter),
+       Property(name, desc, getter, setter),
        decimals_(decimals),
        suffix_(suffix),
        range_(range),
index 863648d834b89dc6713578933184e735fd79045f..4e18e9563ff0adc9c05dc076fb5b57e8cf952409 100644 (file)
@@ -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<double, double> > range,
                boost::optional<double> step,
                Getter getter,
index 7a4a7837ff0e319cd8cd23535321386311f0283d..d5d571a9ec487396b921cdae5b45855bb7bbabde 100644 (file)
@@ -29,10 +29,10 @@ using std::vector;
 namespace pv {
 namespace prop {
 
-Enum::Enum(QString name,
+Enum::Enum(QString name, QString desc,
        vector<pair<Glib::VariantBase, QString> > values,
        Getter getter, Setter setter) :
-       Property(name, getter, setter),
+       Property(name, desc, getter, setter),
        values_(values),
        selector_(nullptr)
 {
index a397913c72c44ec8ac0782c991ab335179da79d4..0193e238d562b224828bc98ac70b49c105b63dd0 100644 (file)
@@ -42,7 +42,8 @@ class Enum : public Property
        Q_OBJECT;
 
 public:
-       Enum(QString name, vector<pair<Glib::VariantBase, QString> > values,
+       Enum(QString name, QString desc,
+               vector<pair<Glib::VariantBase, QString> > values,
                Getter getter, Setter setter);
 
        virtual ~Enum() = default;
index f53d09666daf90f23e3d14e5a5f286946eb4ec2f..98b23ba6386401adc172817e188178bb8d0d4f78 100644 (file)
@@ -33,11 +33,12 @@ namespace pv {
 namespace prop {
 
 Int::Int(QString name,
+       QString desc,
        QString suffix,
        optional< pair<int64_t, int64_t> > range,
        Getter getter,
        Setter setter) :
-       Property(name, getter, setter),
+       Property(name, desc, getter, setter),
        suffix_(suffix),
        range_(range),
        spin_box_(nullptr)
index fabd801324d7941c2fa7171d97f941c6cc0abb13..709e02e635eda56ee1f195cd4b9f76733c32b560 100644 (file)
@@ -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<int64_t, int64_t> > range,
                Getter getter, Setter setter);
 
index 9bb99c2e75b22102cb5c1c23721a7c3c9b0b7f37..557c2a996d7b766bfedfd046a093315f017d65ae 100644 (file)
 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;
index 765cbb50d8bb7e629a6ee1164507ccd9cd9b1ae3..322c608490c775803eeebe00b189a1140c3ba3c1 100644 (file)
@@ -47,10 +47,11 @@ public:
        typedef function<void (Glib::VariantBase)> 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
index 23c7f91321d567bbc59c31bad53b139cd8f1728a..96a83422e0a3e2a026336845ac20c72c876e7d35 100644 (file)
@@ -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)
 {
 }
index b75b3ae65ab909803479d0e71a10c6c2d3c7ef27..8ce8be61ef6312f67842b9b4981d5e0d29a0895c 100644 (file)
@@ -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);