From: Joel Holdsworth Date: Mon, 10 Mar 2014 23:46:09 +0000 (+0100) Subject: Addded support for decoder options with a values list X-Git-Tag: pulseview-0.2.0~23 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=182d2f5dbe8b631b24949e5b111762009d1eeefa;p=pulseview.git Addded support for decoder options with a values list --- diff --git a/pv/prop/binding/decoderoptions.cpp b/pv/prop/binding/decoderoptions.cpp index 8738300e..d9904852 100644 --- a/pv/prop/binding/decoderoptions.cpp +++ b/pv/prop/binding/decoderoptions.cpp @@ -28,14 +28,18 @@ #include #include +#include #include #include using boost::bind; using boost::none; using boost::shared_ptr; +using std::make_pair; using std::map; +using std::pair; using std::string; +using std::vector; namespace pv { namespace prop { @@ -66,7 +70,9 @@ DecoderOptions::DecoderOptions( shared_ptr prop; - if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x"))) + if (opt->values) + prop = bind_enum(name, opt, getter, setter); + else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x"))) prop = shared_ptr( new Int(name, "", none, getter, setter)); else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s"))) @@ -79,6 +85,20 @@ DecoderOptions::DecoderOptions( } } +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) { + GVariant *const var = (GVariant*)l->data; + assert(var); + values.push_back(make_pair(var, print_gvariant(var))); + } + + return shared_ptr(new Enum(name, values, getter, setter)); +} + GVariant* DecoderOptions::getter(const char *id) { GVariant *val = NULL; diff --git a/pv/prop/binding/decoderoptions.h b/pv/prop/binding/decoderoptions.h index c08f1017..6dec9c2e 100644 --- a/pv/prop/binding/decoderoptions.h +++ b/pv/prop/binding/decoderoptions.h @@ -23,6 +23,10 @@ #include "binding.h" +#include + +struct srd_decoder_option; + namespace pv { namespace data { @@ -42,6 +46,10 @@ public: boost::shared_ptr decoder); private: + static boost::shared_ptr bind_enum(const QString &name, + const srd_decoder_option *option, + Property::Getter getter, Property::Setter setter); + GVariant* getter(const char *id); void setter(const char *id, GVariant *value); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 98d8619c..0aeb0bc2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -62,6 +62,7 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/device/file.cpp ${PROJECT_SOURCE_DIR}/pv/device/inputfile.cpp ${PROJECT_SOURCE_DIR}/pv/device/sessionfile.cpp + ${PROJECT_SOURCE_DIR}/pv/prop/enum.cpp ${PROJECT_SOURCE_DIR}/pv/prop/int.cpp ${PROJECT_SOURCE_DIR}/pv/prop/property.cpp ${PROJECT_SOURCE_DIR}/pv/prop/string.cpp @@ -93,6 +94,7 @@ set(pulseview_TEST_SOURCES set(pulseview_TEST_HEADERS ${PROJECT_SOURCE_DIR}/pv/sigsession.h ${PROJECT_SOURCE_DIR}/pv/device/devinst.h + ${PROJECT_SOURCE_DIR}/pv/prop/enum.h ${PROJECT_SOURCE_DIR}/pv/prop/int.h ${PROJECT_SOURCE_DIR}/pv/prop/property.h ${PROJECT_SOURCE_DIR}/pv/prop/string.h