summaryrefslogtreecommitdiffstats
path: root/common/propertymapper.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-03 20:09:18 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-03 20:09:18 +0200
commitc14f07a865940de86b229b4eba0d3bbb9b13967c (patch)
treecbb9a5a522d5462fc342b208f05cd109a2c77ec4 /common/propertymapper.cpp
parent9d079a832ec9c70fccb3446843bd8d7579e3aafd (diff)
downloadsink-c14f07a865940de86b229b4eba0d3bbb9b13967c.tar.gz
sink-c14f07a865940de86b229b4eba0d3bbb9b13967c.zip
Support for QByteArrayList
Diffstat (limited to 'common/propertymapper.cpp')
-rw-r--r--common/propertymapper.cpp30
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
50template <> 50template <>
51flatbuffers::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
65template <>
51QVariant propertyToVariant<QString>(const flatbuffers::String *property) 66QVariant 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
80template <> 95template <>
96QVariant 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
110template <>
81QVariant propertyToVariant<bool>(uint8_t property) 111QVariant propertyToVariant<bool>(uint8_t property)
82{ 112{
83 return static_cast<bool>(property); 113 return static_cast<bool>(property);