]> sigrok.org Git - pulseview.git/commitdiff
Addded support for decoder options with a values list
authorJoel Holdsworth <redacted>
Mon, 10 Mar 2014 23:46:09 +0000 (00:46 +0100)
committerJoel Holdsworth <redacted>
Thu, 13 Mar 2014 17:00:33 +0000 (17:00 +0000)
pv/prop/binding/decoderoptions.cpp
pv/prop/binding/decoderoptions.h
test/CMakeLists.txt

index 8738300ee9550007486c2b81f2fee1749f0293c5..d9904852ca645e21f6b4b4d447a200860e301d94 100644 (file)
 
 #include <pv/data/decoderstack.h>
 #include <pv/data/decode/decoder.h>
+#include <pv/prop/enum.h>
 #include <pv/prop/int.h>
 #include <pv/prop/string.h>
 
 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<Property> 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<Property>(
                                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<Property> DecoderOptions::bind_enum(
+       const QString &name, const srd_decoder_option *option,
+       Property::Getter getter, Property::Setter setter)
+{
+       vector< pair<GVariant*, QString> > 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<Property>(new Enum(name, values, getter, setter));
+}
+
 GVariant* DecoderOptions::getter(const char *id)
 {
        GVariant *val = NULL;
index c08f1017fb2a822106f21a603f7be76768d66050..6dec9c2ec5bd9d4a2ba5938c7191d3b767dbe30d 100644 (file)
 
 #include "binding.h"
 
+#include <pv/prop/property.h>
+
+struct srd_decoder_option;
+
 namespace pv {
 
 namespace data {
@@ -42,6 +46,10 @@ public:
                boost::shared_ptr<pv::data::decode::Decoder> decoder);
 
 private:
+       static boost::shared_ptr<Property> 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);
index 98d8619c0b13c7515d23dbca751751e7b6d9d14b..0aeb0bc2dcba10787cbd7747679931fe034f74e7 100644 (file)
@@ -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