summaryrefslogtreecommitdiffstats
path: root/common/propertymapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/propertymapper.cpp')
-rw-r--r--common/propertymapper.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp
index c72cf31..dbf93a3 100644
--- a/common/propertymapper.cpp
+++ b/common/propertymapper.cpp
@@ -21,6 +21,7 @@
21 21
22#include "applicationdomaintype.h" 22#include "applicationdomaintype.h"
23#include <QDateTime> 23#include <QDateTime>
24#include <QDataStream>
24#include "mail_generated.h" 25#include "mail_generated.h"
25#include "contact_generated.h" 26#include "contact_generated.h"
26 27
@@ -57,7 +58,9 @@ template <>
57flatbuffers::uoffset_t variantToProperty<QByteArray>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) 58flatbuffers::uoffset_t variantToProperty<QByteArray>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
58{ 59{
59 if (property.isValid()) { 60 if (property.isValid()) {
60 return fbb.CreateString(property.toByteArray().toStdString()).o; 61 const auto ba = property.toByteArray();
62 const auto s = fbb.CreateString(ba.constData(), ba.size());
63 return s.o;
61 } 64 }
62 return 0; 65 return 0;
63} 66}
@@ -66,7 +69,10 @@ template <>
66flatbuffers::uoffset_t variantToProperty<QDateTime>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) 69flatbuffers::uoffset_t variantToProperty<QDateTime>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
67{ 70{
68 if (property.isValid()) { 71 if (property.isValid()) {
69 return fbb.CreateString(property.toDateTime().toString().toStdString()).o; 72 QByteArray ba;
73 QDataStream ds(&ba, QIODevice::WriteOnly);
74 ds << property.toDateTime();
75 return fbb.CreateString(ba.toStdString()).o;
70 } 76 }
71 return 0; 77 return 0;
72} 78}
@@ -131,7 +137,7 @@ QString propertyToString(const flatbuffers::String *property)
131{ 137{
132 if (property) { 138 if (property) {
133 // We have to copy the memory, otherwise it would become eventually invalid 139 // We have to copy the memory, otherwise it would become eventually invalid
134 return QString::fromStdString(property->c_str()); 140 return QString::fromStdString(property->str());
135 } 141 }
136 return QString(); 142 return QString();
137} 143}
@@ -141,7 +147,7 @@ QVariant propertyToVariant<QString>(const flatbuffers::String *property)
141{ 147{
142 if (property) { 148 if (property) {
143 // We have to copy the memory, otherwise it would become eventually invalid 149 // We have to copy the memory, otherwise it would become eventually invalid
144 return QString::fromStdString(property->c_str()); 150 return QString::fromStdString(property->str());
145 } 151 }
146 return QVariant(); 152 return QVariant();
147} 153}
@@ -151,7 +157,7 @@ QVariant propertyToVariant<Sink::ApplicationDomain::BLOB>(const flatbuffers::Str
151{ 157{
152 if (property) { 158 if (property) {
153 // We have to copy the memory, otherwise it would become eventually invalid 159 // We have to copy the memory, otherwise it would become eventually invalid
154 auto s = QString::fromStdString(property->c_str()); 160 auto s = QString::fromStdString(property->str());
155 auto ext = s.endsWith(":ext"); 161 auto ext = s.endsWith(":ext");
156 s.chop(4); 162 s.chop(4);
157 163
@@ -167,7 +173,7 @@ QVariant propertyToVariant<Sink::ApplicationDomain::Reference>(const flatbuffers
167{ 173{
168 if (property) { 174 if (property) {
169 // We have to copy the memory, otherwise it would become eventually invalid 175 // We have to copy the memory, otherwise it would become eventually invalid
170 return QVariant::fromValue(Sink::ApplicationDomain::Reference{QString::fromStdString(property->c_str()).toUtf8()}); 176 return QVariant::fromValue(Sink::ApplicationDomain::Reference{QString::fromStdString(property->str()).toUtf8()});
171 } 177 }
172 return QVariant(); 178 return QVariant();
173} 179}
@@ -177,7 +183,7 @@ QVariant propertyToVariant<QByteArray>(const flatbuffers::String *property)
177{ 183{
178 if (property) { 184 if (property) {
179 // We have to copy the memory, otherwise it would become eventually invalid 185 // We have to copy the memory, otherwise it would become eventually invalid
180 return QString::fromStdString(property->c_str()).toUtf8(); 186 return QByteArray(property->c_str(), property->Length());
181 } 187 }
182 return QVariant(); 188 return QVariant();
183} 189}
@@ -199,7 +205,7 @@ QVariant propertyToVariant<QByteArrayList>(const flatbuffers::Vector<flatbuffers
199 QByteArrayList list; 205 QByteArrayList list;
200 for (auto it = property->begin(); it != property->end();) { 206 for (auto it = property->begin(); it != property->end();) {
201 // We have to copy the memory, otherwise it would become eventually invalid 207 // We have to copy the memory, otherwise it would become eventually invalid
202 list << QString::fromStdString((*it)->c_str()).toUtf8(); 208 list << QString::fromStdString((*it)->str()).toUtf8();
203 it.operator++(); 209 it.operator++();
204 } 210 }
205 return QVariant::fromValue(list); 211 return QVariant::fromValue(list);
@@ -256,8 +262,11 @@ template <>
256QVariant propertyToVariant<QDateTime>(const flatbuffers::String *property) 262QVariant propertyToVariant<QDateTime>(const flatbuffers::String *property)
257{ 263{
258 if (property) { 264 if (property) {
259 // We have to copy the memory, otherwise it would become eventually invalid 265 auto ba = QByteArray::fromRawData(property->c_str(), property->size());
260 return QDateTime::fromString(QString::fromStdString(property->c_str())); 266 QDateTime dt;
267 QDataStream ds(&ba, QIODevice::ReadOnly);
268 ds >> dt;
269 return dt;
261 } 270 }
262 return QVariant(); 271 return QVariant();
263} 272}