diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-03 20:09:18 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-03 20:09:18 +0200 |
commit | c14f07a865940de86b229b4eba0d3bbb9b13967c (patch) | |
tree | cbb9a5a522d5462fc342b208f05cd109a2c77ec4 /common/propertymapper.cpp | |
parent | 9d079a832ec9c70fccb3446843bd8d7579e3aafd (diff) | |
download | sink-c14f07a865940de86b229b4eba0d3bbb9b13967c.tar.gz sink-c14f07a865940de86b229b4eba0d3bbb9b13967c.zip |
Support for QByteArrayList
Diffstat (limited to 'common/propertymapper.cpp')
-rw-r--r-- | common/propertymapper.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp index ebe5cb3..130ba0b 100644 --- a/common/propertymapper.cpp +++ b/common/propertymapper.cpp | |||
@@ -48,6 +48,21 @@ flatbuffers::uoffset_t variantToProperty<QDateTime>(const QVariant &property, fl | |||
48 | } | 48 | } |
49 | 49 | ||
50 | template <> | 50 | template <> |
51 | flatbuffers::uoffset_t variantToProperty<QByteArrayList>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | ||
52 | { | ||
53 | if (property.isValid()) { | ||
54 | const auto list = property.value<QByteArrayList>(); | ||
55 | std::vector<flatbuffers::Offset<flatbuffers::String>> vector; | ||
56 | for (const auto value : list) { | ||
57 | auto offset = fbb.CreateString(value.toStdString()); | ||
58 | vector.push_back(offset); | ||
59 | } | ||
60 | return fbb.CreateVector(vector).o; | ||
61 | } | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | template <> | ||
51 | QVariant propertyToVariant<QString>(const flatbuffers::String *property) | 66 | QVariant propertyToVariant<QString>(const flatbuffers::String *property) |
52 | { | 67 | { |
53 | if (property) { | 68 | if (property) { |
@@ -78,6 +93,21 @@ QVariant propertyToVariant<QByteArray>(const flatbuffers::Vector<uint8_t> *prope | |||
78 | } | 93 | } |
79 | 94 | ||
80 | template <> | 95 | template <> |
96 | QVariant propertyToVariant<QByteArrayList>(const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *property) | ||
97 | { | ||
98 | if (property) { | ||
99 | QByteArrayList list; | ||
100 | for (auto it = property->begin(); it != property->end();) { | ||
101 | // We have to copy the memory, otherwise it would become eventually invalid | ||
102 | list << QString::fromStdString((*it)->c_str()).toUtf8(); | ||
103 | it.operator++(); | ||
104 | } | ||
105 | return QVariant::fromValue(list); | ||
106 | } | ||
107 | return QVariant(); | ||
108 | } | ||
109 | |||
110 | template <> | ||
81 | QVariant propertyToVariant<bool>(uint8_t property) | 111 | QVariant propertyToVariant<bool>(uint8_t property) |
82 | { | 112 | { |
83 | return static_cast<bool>(property); | 113 | return static_cast<bool>(property); |