From: Joel Holdsworth Date: Sat, 17 Jan 2015 21:58:20 +0000 (+0000) Subject: Renamed pv::binding::DeviceOptions and DecoderOptions to Device and Decoder X-Git-Tag: pulseview-0.3.0~245 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3cc9ad7b867853315473df611612c562d562ed8a;p=pulseview.git Renamed pv::binding::DeviceOptions and DecoderOptions to Device and Decoder --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c7785928..6848be50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,7 +147,7 @@ set(pulseview_SOURCES pv/storesession.cpp pv/util.cpp pv/binding/binding.cpp - pv/binding/deviceoptions.cpp + pv/binding/device.cpp pv/data/analog.cpp pv/data/analogsegment.cpp pv/data/logic.cpp @@ -203,7 +203,7 @@ set(pulseview_HEADERS pv/mainwindow.hpp pv/session.hpp pv/storesession.hpp - pv/binding/deviceoptions.hpp + pv/binding/device.hpp pv/dialogs/about.hpp pv/dialogs/connect.hpp pv/dialogs/storeprogress.hpp @@ -258,7 +258,7 @@ endif() if(ENABLE_DECODE) list(APPEND pulseview_SOURCES - pv/binding/decoderoptions.cpp + pv/binding/decoder.cpp pv/data/decoderstack.cpp pv/data/decode/annotation.cpp pv/data/decode/decoder.cpp diff --git a/pv/binding/decoder.cpp b/pv/binding/decoder.cpp new file mode 100644 index 00000000..dd571602 --- /dev/null +++ b/pv/binding/decoder.cpp @@ -0,0 +1,151 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "decoder.hpp" + +#include + +#include +#include +#include +#include +#include +#include + +using boost::none; +using std::make_pair; +using std::map; +using std::pair; +using std::shared_ptr; +using std::string; +using std::vector; + +using pv::prop::Double; +using pv::prop::Enum; +using pv::prop::Int; +using pv::prop::Property; +using pv::prop::String; + +namespace pv { +namespace binding { + +Decoder::Decoder( + shared_ptr decoder_stack, + shared_ptr decoder) : + decoder_stack_(decoder_stack), + decoder_(decoder) +{ + assert(decoder_); + + const srd_decoder *const dec = decoder_->decoder(); + assert(dec); + + for (GSList *l = dec->options; l; l = l->next) + { + const srd_decoder_option *const opt = + (srd_decoder_option*)l->data; + + const QString name = QString::fromUtf8(opt->desc); + + const Property::Getter get = [&, opt]() { + return getter(opt->id); }; + const Property::Setter set = [&, opt](Glib::VariantBase value) { + setter(opt->id, value); }; + + shared_ptr prop; + + if (opt->values) + 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, "", + 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)); + else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s"))) + prop = shared_ptr( + new String(name, get, set)); + else + continue; + + properties_.push_back(prop); + } +} + +shared_ptr Decoder::bind_enum( + const QString &name, const srd_decoder_option *option, + Property::Getter getter, Property::Setter setter) +{ + vector< pair > values; + for (GSList *l = option->values; l; l = l->next) { + Glib::VariantBase var = Glib::VariantBase((GVariant*)l->data, true); + values.push_back(make_pair(var, print_gvariant(var))); + } + + return shared_ptr(new Enum(name, values, getter, setter)); +} + +Glib::VariantBase Decoder::getter(const char *id) +{ + GVariant *val = NULL; + + assert(decoder_); + + // Get the value from the hash table if it is already present + const map& options = decoder_->options(); + const auto iter = options.find(id); + + if (iter != options.end()) + val = (*iter).second; + else + { + assert(decoder_->decoder()); + + // Get the default value if not + for (GSList *l = decoder_->decoder()->options; l; l = l->next) + { + const srd_decoder_option *const opt = + (srd_decoder_option*)l->data; + if (strcmp(opt->id, id) == 0) { + val = opt->def; + break; + } + } + } + + if (val) + return Glib::VariantBase(val, true); + else + return Glib::VariantBase(); +} + +void Decoder::setter(const char *id, Glib::VariantBase value) +{ + assert(decoder_); + decoder_->set_option(id, value.gobj()); + + assert(decoder_stack_); + decoder_stack_->begin_decode(); +} + +} // binding +} // pv diff --git a/pv/binding/decoder.hpp b/pv/binding/decoder.hpp new file mode 100644 index 00000000..48e5945b --- /dev/null +++ b/pv/binding/decoder.hpp @@ -0,0 +1,64 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PULSEVIEW_PV_BINDING_DECODER_H +#define PULSEVIEW_PV_BINDING_DECODER_H + +#include "binding.hpp" + +#include + +struct srd_decoder_option; + +namespace pv { + +namespace data { +class DecoderStack; +namespace decode { +class Decoder; +} +} + +namespace binding { + +class Decoder : public Binding +{ +public: + Decoder(std::shared_ptr decoder_stack, + std::shared_ptr decoder); + +private: + static std::shared_ptr bind_enum(const QString &name, + const srd_decoder_option *option, + prop::Property::Getter getter, prop::Property::Setter setter); + + Glib::VariantBase getter(const char *id); + + void setter(const char *id, Glib::VariantBase value); + +private: + std::shared_ptr decoder_stack_; + std::shared_ptr decoder_; +}; + +} // binding +} // pv + +#endif // PULSEVIEW_PV_BINDING_DECODER_H diff --git a/pv/binding/decoderoptions.cpp b/pv/binding/decoderoptions.cpp deleted file mode 100644 index fd7d918c..00000000 --- a/pv/binding/decoderoptions.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2013 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include "decoderoptions.hpp" - -#include - -#include -#include -#include -#include -#include -#include - -using boost::none; -using std::make_pair; -using std::map; -using std::pair; -using std::shared_ptr; -using std::string; -using std::vector; - -using pv::prop::Double; -using pv::prop::Enum; -using pv::prop::Int; -using pv::prop::Property; -using pv::prop::String; - -namespace pv { -namespace binding { - -DecoderOptions::DecoderOptions( - shared_ptr decoder_stack, - shared_ptr decoder) : - decoder_stack_(decoder_stack), - decoder_(decoder) -{ - assert(decoder_); - - const srd_decoder *const dec = decoder_->decoder(); - assert(dec); - - for (GSList *l = dec->options; l; l = l->next) - { - const srd_decoder_option *const opt = - (srd_decoder_option*)l->data; - - const QString name = QString::fromUtf8(opt->desc); - - const Property::Getter get = [&, opt]() { - return getter(opt->id); }; - const Property::Setter set = [&, opt](Glib::VariantBase value) { - setter(opt->id, value); }; - - shared_ptr prop; - - if (opt->values) - 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, "", - 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)); - else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s"))) - prop = shared_ptr( - new String(name, get, set)); - else - continue; - - properties_.push_back(prop); - } -} - -shared_ptr DecoderOptions::bind_enum( - const QString &name, const srd_decoder_option *option, - Property::Getter getter, Property::Setter setter) -{ - vector< pair > values; - for (GSList *l = option->values; l; l = l->next) { - Glib::VariantBase var = Glib::VariantBase((GVariant*)l->data, true); - values.push_back(make_pair(var, print_gvariant(var))); - } - - return shared_ptr(new Enum(name, values, getter, setter)); -} - -Glib::VariantBase DecoderOptions::getter(const char *id) -{ - GVariant *val = NULL; - - assert(decoder_); - - // Get the value from the hash table if it is already present - const map& options = decoder_->options(); - const auto iter = options.find(id); - - if (iter != options.end()) - val = (*iter).second; - else - { - assert(decoder_->decoder()); - - // Get the default value if not - for (GSList *l = decoder_->decoder()->options; l; l = l->next) - { - const srd_decoder_option *const opt = - (srd_decoder_option*)l->data; - if (strcmp(opt->id, id) == 0) { - val = opt->def; - break; - } - } - } - - if (val) - return Glib::VariantBase(val, true); - else - return Glib::VariantBase(); -} - -void DecoderOptions::setter(const char *id, Glib::VariantBase value) -{ - assert(decoder_); - decoder_->set_option(id, value.gobj()); - - assert(decoder_stack_); - decoder_stack_->begin_decode(); -} - -} // binding -} // pv diff --git a/pv/binding/decoderoptions.hpp b/pv/binding/decoderoptions.hpp deleted file mode 100644 index a2f7706d..00000000 --- a/pv/binding/decoderoptions.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2013 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef PULSEVIEW_PV_BINDING_DECODEROPTIONS_H -#define PULSEVIEW_PV_BINDING_DECODEROPTIONS_H - -#include "binding.hpp" - -#include - -struct srd_decoder_option; - -namespace pv { - -namespace data { -class DecoderStack; -namespace decode { -class Decoder; -} -} - -namespace binding { - -class DecoderOptions : public Binding -{ -public: - DecoderOptions(std::shared_ptr decoder_stack, - std::shared_ptr decoder); - -private: - static std::shared_ptr bind_enum(const QString &name, - const srd_decoder_option *option, - prop::Property::Getter getter, prop::Property::Setter setter); - - Glib::VariantBase getter(const char *id); - - void setter(const char *id, Glib::VariantBase value); - -private: - std::shared_ptr decoder_stack_; - std::shared_ptr decoder_; -}; - -} // binding -} // pv - -#endif // PULSEVIEW_PV_BINDING_DECODEROPTIONS_H diff --git a/pv/binding/device.cpp b/pv/binding/device.cpp new file mode 100644 index 00000000..224bc23a --- /dev/null +++ b/pv/binding/device.cpp @@ -0,0 +1,192 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include + +#include "device.hpp" + +#include +#include +#include +#include + +#include + +using boost::optional; +using std::function; +using std::make_pair; +using std::pair; +using std::shared_ptr; +using std::string; +using std::vector; + +using sigrok::Capability; +using sigrok::Configurable; +using sigrok::ConfigKey; +using sigrok::Error; + +using pv::prop::Bool; +using pv::prop::Double; +using pv::prop::Enum; +using pv::prop::Int; +using pv::prop::Property; + +namespace pv { +namespace binding { + +Device::Device(shared_ptr configurable) : + configurable_(configurable) +{ + assert(configurable); + + for (auto entry : configurable->config_keys(ConfigKey::DEVICE_OPTIONS)) { + auto key = entry.first; + auto capabilities = entry.second; + + Glib::VariantContainerBase gvar_list; + + if (!capabilities.count(Capability::GET) || + !capabilities.count(Capability::SET)) + continue; + + if (capabilities.count(Capability::LIST)) + gvar_list = configurable->config_list(key); + + string name_str; + try { + name_str = key->description(); + } catch (Error e) { + name_str = key->name(); + } + + const QString name = QString::fromStdString(name_str); + + const Property::Getter get = [&, key]() { + return configurable_->config_get(key); }; + const Property::Setter set = [&, key](Glib::VariantBase value) { + configurable_->config_set(key, value); + config_changed(); + }; + + switch (key->id()) + { + case SR_CONF_SAMPLERATE: + // Sample rate values are not bound because they are shown + // in the MainBar + break; + + case SR_CONF_CAPTURE_RATIO: + bind_int(name, "%", pair(0, 100), + get, set); + break; + + case SR_CONF_PATTERN_MODE: + case SR_CONF_BUFFERSIZE: + case SR_CONF_TRIGGER_SOURCE: + case SR_CONF_TRIGGER_SLOPE: + case SR_CONF_FILTER: + case SR_CONF_COUPLING: + case SR_CONF_CLOCK_EDGE: + bind_enum(name, gvar_list, get, set); + break; + + case SR_CONF_EXTERNAL_CLOCK: + case SR_CONF_RLE: + bind_bool(name, get, set); + break; + + case SR_CONF_TIMEBASE: + bind_enum(name, gvar_list, get, set, print_timebase); + break; + + case SR_CONF_VDIV: + bind_enum(name, gvar_list, get, set, print_vdiv); + break; + + case SR_CONF_VOLTAGE_THRESHOLD: + bind_enum(name, gvar_list, get, set, print_voltage_threshold); + break; + + default: + break; + } + } +} + +void Device::bind_bool(const QString &name, + Property::Getter getter, Property::Setter setter) +{ + assert(configurable_); + properties_.push_back(shared_ptr(new Bool( + name, getter, setter))); +} + +void Device::bind_enum(const QString &name, + Glib::VariantContainerBase gvar_list, Property::Getter getter, + Property::Setter setter, function printer) +{ + Glib::VariantBase gvar; + vector< pair > values; + + assert(configurable_); + + Glib::VariantIter iter(gvar_list); + while ((iter.next_value(gvar))) + values.push_back(make_pair(gvar, printer(gvar))); + + properties_.push_back(shared_ptr(new Enum(name, values, + getter, setter))); +} + +void Device::bind_int(const QString &name, QString suffix, + optional< std::pair > range, + Property::Getter getter, Property::Setter setter) +{ + assert(configurable_); + + properties_.push_back(shared_ptr(new Int(name, suffix, range, + getter, setter))); +} + +QString Device::print_timebase(Glib::VariantBase gvar) +{ + uint64_t p, q; + g_variant_get(gvar.gobj(), "(tt)", &p, &q); + return QString::fromUtf8(sr_period_string(p * q)); +} + +QString Device::print_vdiv(Glib::VariantBase gvar) +{ + uint64_t p, q; + g_variant_get(gvar.gobj(), "(tt)", &p, &q); + return QString::fromUtf8(sr_voltage_string(p, q)); +} + +QString Device::print_voltage_threshold(Glib::VariantBase gvar) +{ + gdouble lo, hi; + g_variant_get(gvar.gobj(), "(dd)", &lo, &hi); + return QString("L<%1V H>%2V").arg(lo, 0, 'f', 1).arg(hi, 0, 'f', 1); +} + +} // binding +} // pv diff --git a/pv/binding/device.hpp b/pv/binding/device.hpp new file mode 100644 index 00000000..2a4c5163 --- /dev/null +++ b/pv/binding/device.hpp @@ -0,0 +1,72 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PULSEVIEW_PV_BINDING_DEVICE_H +#define PULSEVIEW_PV_BINDING_DEVICE_H + +#include + +#include +#include + +#include "binding.hpp" + +#include + +namespace sigrok { + class Configurable; +} + +namespace pv { + +namespace binding { + +class Device : public QObject, public Binding +{ + Q_OBJECT + +public: + Device(std::shared_ptr configurable); + +Q_SIGNALS: + void config_changed(); + +private: + void bind_bool(const QString &name, + prop::Property::Getter getter, prop::Property::Setter setter); + void bind_enum(const QString &name, Glib::VariantContainerBase gvar_list, + prop::Property::Getter getter, prop::Property::Setter setter, + std::function printer = print_gvariant); + void bind_int(const QString &name, QString suffix, + boost::optional< std::pair > range, + prop::Property::Getter getter, prop::Property::Setter setter); + + static QString print_timebase(Glib::VariantBase gvar); + static QString print_vdiv(Glib::VariantBase gvar); + static QString print_voltage_threshold(Glib::VariantBase gvar); + +protected: + std::shared_ptr configurable_; +}; + +} // binding +} // pv + +#endif // PULSEVIEW_PV_BINDING_DEVICE_H diff --git a/pv/binding/deviceoptions.cpp b/pv/binding/deviceoptions.cpp deleted file mode 100644 index 8609e211..00000000 --- a/pv/binding/deviceoptions.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2012 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include - -#include "deviceoptions.hpp" - -#include -#include -#include -#include - -#include - -using boost::optional; -using std::function; -using std::make_pair; -using std::pair; -using std::shared_ptr; -using std::string; -using std::vector; - -using sigrok::Capability; -using sigrok::Configurable; -using sigrok::ConfigKey; -using sigrok::Error; - -using pv::prop::Bool; -using pv::prop::Double; -using pv::prop::Enum; -using pv::prop::Int; -using pv::prop::Property; - -namespace pv { -namespace binding { - -DeviceOptions::DeviceOptions(shared_ptr configurable) : - configurable_(configurable) -{ - assert(configurable); - - for (auto entry : configurable->config_keys(ConfigKey::DEVICE_OPTIONS)) { - auto key = entry.first; - auto capabilities = entry.second; - - Glib::VariantContainerBase gvar_list; - - if (!capabilities.count(Capability::GET) || - !capabilities.count(Capability::SET)) - continue; - - if (capabilities.count(Capability::LIST)) - gvar_list = configurable->config_list(key); - - string name_str; - try { - name_str = key->description(); - } catch (Error e) { - name_str = key->name(); - } - - const QString name = QString::fromStdString(name_str); - - const Property::Getter get = [&, key]() { - return configurable_->config_get(key); }; - const Property::Setter set = [&, key](Glib::VariantBase value) { - configurable_->config_set(key, value); - config_changed(); - }; - - switch (key->id()) - { - case SR_CONF_SAMPLERATE: - // Sample rate values are not bound because they are shown - // in the MainBar - break; - - case SR_CONF_CAPTURE_RATIO: - bind_int(name, "%", pair(0, 100), - get, set); - break; - - case SR_CONF_PATTERN_MODE: - case SR_CONF_BUFFERSIZE: - case SR_CONF_TRIGGER_SOURCE: - case SR_CONF_TRIGGER_SLOPE: - case SR_CONF_FILTER: - case SR_CONF_COUPLING: - case SR_CONF_CLOCK_EDGE: - bind_enum(name, gvar_list, get, set); - break; - - case SR_CONF_EXTERNAL_CLOCK: - case SR_CONF_RLE: - bind_bool(name, get, set); - break; - - case SR_CONF_TIMEBASE: - bind_enum(name, gvar_list, get, set, print_timebase); - break; - - case SR_CONF_VDIV: - bind_enum(name, gvar_list, get, set, print_vdiv); - break; - - case SR_CONF_VOLTAGE_THRESHOLD: - bind_enum(name, gvar_list, get, set, print_voltage_threshold); - break; - - default: - break; - } - } -} - -void DeviceOptions::bind_bool(const QString &name, - Property::Getter getter, Property::Setter setter) -{ - assert(configurable_); - properties_.push_back(shared_ptr(new Bool( - name, getter, setter))); -} - -void DeviceOptions::bind_enum(const QString &name, - Glib::VariantContainerBase gvar_list, Property::Getter getter, - Property::Setter setter, function printer) -{ - Glib::VariantBase gvar; - vector< pair > values; - - assert(configurable_); - - Glib::VariantIter iter(gvar_list); - while ((iter.next_value(gvar))) - values.push_back(make_pair(gvar, printer(gvar))); - - properties_.push_back(shared_ptr(new Enum(name, values, - getter, setter))); -} - -void DeviceOptions::bind_int(const QString &name, QString suffix, - optional< std::pair > range, - Property::Getter getter, Property::Setter setter) -{ - assert(configurable_); - - properties_.push_back(shared_ptr(new Int(name, suffix, range, - getter, setter))); -} - -QString DeviceOptions::print_timebase(Glib::VariantBase gvar) -{ - uint64_t p, q; - g_variant_get(gvar.gobj(), "(tt)", &p, &q); - return QString::fromUtf8(sr_period_string(p * q)); -} - -QString DeviceOptions::print_vdiv(Glib::VariantBase gvar) -{ - uint64_t p, q; - g_variant_get(gvar.gobj(), "(tt)", &p, &q); - return QString::fromUtf8(sr_voltage_string(p, q)); -} - -QString DeviceOptions::print_voltage_threshold(Glib::VariantBase gvar) -{ - gdouble lo, hi; - g_variant_get(gvar.gobj(), "(dd)", &lo, &hi); - return QString("L<%1V H>%2V").arg(lo, 0, 'f', 1).arg(hi, 0, 'f', 1); -} - -} // binding -} // pv diff --git a/pv/binding/deviceoptions.hpp b/pv/binding/deviceoptions.hpp deleted file mode 100644 index 9e913b06..00000000 --- a/pv/binding/deviceoptions.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2012 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef PULSEVIEW_PV_BINDING_DEVICEOPTIONS_H -#define PULSEVIEW_PV_BINDING_DEVICEOPTIONS_H - -#include - -#include -#include - -#include "binding.hpp" - -#include - -namespace sigrok { - class Configurable; -} - -namespace pv { - -namespace binding { - -class DeviceOptions : public QObject, public Binding -{ - Q_OBJECT - -public: - DeviceOptions(std::shared_ptr configurable); - -Q_SIGNALS: - void config_changed(); - -private: - void bind_bool(const QString &name, - prop::Property::Getter getter, prop::Property::Setter setter); - void bind_enum(const QString &name, Glib::VariantContainerBase gvar_list, - prop::Property::Getter getter, prop::Property::Setter setter, - std::function printer = print_gvariant); - void bind_int(const QString &name, QString suffix, - boost::optional< std::pair > range, - prop::Property::Getter getter, prop::Property::Setter setter); - - static QString print_timebase(Glib::VariantBase gvar); - static QString print_vdiv(Glib::VariantBase gvar); - static QString print_voltage_threshold(Glib::VariantBase gvar); - -protected: - std::shared_ptr configurable_; -}; - -} // binding -} // pv - -#endif // PULSEVIEW_PV_BINDING_DEVICEOPTIONS_H diff --git a/pv/popups/channels.cpp b/pv/popups/channels.cpp index c00863b0..61a8aee0 100644 --- a/pv/popups/channels.cpp +++ b/pv/popups/channels.cpp @@ -27,7 +27,7 @@ #include "channels.hpp" -#include +#include #include #include @@ -151,14 +151,14 @@ void Channels::set_all_channels(bool set) void Channels::populate_group(shared_ptr group, const vector< shared_ptr > sigs) { - using pv::binding::DeviceOptions; + using pv::binding::Device; // Only bind options if this is a group. We don't do it for general // options, because these properties are shown in the device config // popup. - shared_ptr binding; + shared_ptr binding; if (group) - binding = shared_ptr(new DeviceOptions(group)); + binding = shared_ptr(new Device(group)); // Create a title if the group is going to have any content if ((!sigs.empty() || (binding && !binding->properties().empty())) && diff --git a/pv/popups/channels.hpp b/pv/popups/channels.hpp index 61dc9e15..a0b0693f 100644 --- a/pv/popups/channels.hpp +++ b/pv/popups/channels.hpp @@ -44,7 +44,7 @@ namespace pv { class Session; namespace binding { -class DeviceOptions; +class Device; } namespace view { @@ -85,7 +85,7 @@ private: bool updating_channels_; - std::vector< std::shared_ptr > + std::vector< std::shared_ptr > group_bindings_; std::map< QCheckBox*, std::shared_ptr > check_box_signal_map_; diff --git a/pv/popups/deviceoptions.cpp b/pv/popups/deviceoptions.cpp index 06c9705f..fe795515 100644 --- a/pv/popups/deviceoptions.cpp +++ b/pv/popups/deviceoptions.cpp @@ -45,7 +45,7 @@ DeviceOptions::DeviceOptions(shared_ptr device, QWidget *parent) : layout_.addWidget(binding_.get_property_form(this, true)); } -pv::binding::DeviceOptions& DeviceOptions::binding() +pv::binding::Device& DeviceOptions::binding() { return binding_; } diff --git a/pv/popups/deviceoptions.hpp b/pv/popups/deviceoptions.hpp index 94ce7afd..f840e83f 100644 --- a/pv/popups/deviceoptions.hpp +++ b/pv/popups/deviceoptions.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include namespace sigrok { @@ -42,14 +42,14 @@ public: DeviceOptions(std::shared_ptr device, QWidget *parent); - pv::binding::DeviceOptions& binding(); + pv::binding::Device& binding(); private: std::shared_ptr device_; QVBoxLayout layout_; - pv::binding::DeviceOptions binding_; + pv::binding::Device binding_; }; } // namespace popups diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 91ffebe4..f423b21e 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -687,8 +687,8 @@ void DecodeTrace::create_decoder_form(int index, } // Add the options - shared_ptr binding( - new binding::DecoderOptions(decoder_stack_, dec)); + shared_ptr binding( + new binding::Decoder(decoder_stack_, dec)); binding->add_properties_to_form(decoder_form, true); bindings_.push_back(binding); diff --git a/pv/view/decodetrace.hpp b/pv/view/decodetrace.hpp index 863fb35e..ada01db7 100644 --- a/pv/view/decodetrace.hpp +++ b/pv/view/decodetrace.hpp @@ -29,7 +29,7 @@ #include -#include +#include #include struct srd_channel; @@ -191,7 +191,7 @@ private: uint64_t decode_start_, decode_end_; - std::list< std::shared_ptr > + std::list< std::shared_ptr > bindings_; std::list channel_selectors_; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 61b9c4d5..98b02999 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,7 +24,7 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/storesession.cpp ${PROJECT_SOURCE_DIR}/pv/util.cpp ${PROJECT_SOURCE_DIR}/pv/binding/binding.cpp - ${PROJECT_SOURCE_DIR}/pv/binding/deviceoptions.cpp + ${PROJECT_SOURCE_DIR}/pv/binding/device.cpp ${PROJECT_SOURCE_DIR}/pv/data/analog.cpp ${PROJECT_SOURCE_DIR}/pv/data/analogsegment.cpp ${PROJECT_SOURCE_DIR}/pv/data/logic.cpp @@ -74,7 +74,7 @@ set(pulseview_TEST_SOURCES set(pulseview_TEST_HEADERS ${PROJECT_SOURCE_DIR}/pv/session.hpp ${PROJECT_SOURCE_DIR}/pv/storesession.hpp - ${PROJECT_SOURCE_DIR}/pv/binding/deviceoptions.hpp + ${PROJECT_SOURCE_DIR}/pv/binding/device.hpp ${PROJECT_SOURCE_DIR}/pv/popups/channels.hpp ${PROJECT_SOURCE_DIR}/pv/popups/deviceoptions.hpp ${PROJECT_SOURCE_DIR}/pv/prop/bool.hpp @@ -109,7 +109,7 @@ set(pulseview_TEST_HEADERS if(ENABLE_DECODE) list(APPEND pulseview_TEST_SOURCES - ${PROJECT_SOURCE_DIR}/pv/binding/decoderoptions.cpp + ${PROJECT_SOURCE_DIR}/pv/binding/decoder.cpp ${PROJECT_SOURCE_DIR}/pv/data/decoderstack.cpp ${PROJECT_SOURCE_DIR}/pv/data/decode/annotation.cpp ${PROJECT_SOURCE_DIR}/pv/data/decode/decoder.cpp