/* * Copyright (C) 2015 Christian Mollekopf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "propertymapper.h" #include template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) { if (property.isValid()) { return fbb.CreateString(property.toString().toStdString()).o; } return 0; } template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) { if (property.isValid()) { return fbb.CreateString(property.toByteArray().toStdString()).o; } return 0; } template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) { if (property.isValid()) { return fbb.CreateString(property.toDateTime().toString().toStdString()).o; } return 0; } template <> QVariant propertyToVariant(const flatbuffers::String *property) { if (property) { //We have to copy the memory, otherwise it would become eventually invalid return QString::fromStdString(property->c_str()); } return QVariant(); } template <> QVariant propertyToVariant(const flatbuffers::String *property) { if (property) { //We have to copy the memory, otherwise it would become eventually invalid return QString::fromStdString(property->c_str()).toUtf8(); } return QVariant(); } template <> QVariant propertyToVariant(const flatbuffers::Vector *property) { if (property) { //We have to copy the memory, otherwise it would become eventually invalid return QByteArray(reinterpret_cast(property->Data()), property->Length()); } return QVariant(); } template <> QVariant propertyToVariant(uint8_t property) { return static_cast(property); } template <> QVariant propertyToVariant(const flatbuffers::String *property) { if (property) { //We have to copy the memory, otherwise it would become eventually invalid return QDateTime::fromString(QString::fromStdString(property->c_str())); } return QVariant(); }