17 #ifndef VARIANTCONVERTER_H
18 #define VARIANTCONVERTER_H
21 #include <QJsonObject>
113 if (value.
canConvert(QMetaType::QVariantMap)) {
137 if (value.
canConvert(QMetaType::QVariantList)) {
138 QVariantList floatList = value.
toList();
139 float x = floatList.size() >= 1 ? floatList[0].toFloat() : 0.0f;
140 float y = floatList.size() >= 2 ? floatList[1].toFloat() : 0.0f;
155 template <
typename T>
166 QVariantMap map = value.
toMap();
167 for (
auto it = map.cbegin(); it != map.cend(); ++it) {
168 convertedMap.
insert(it.key(), converter.fromVariant(it.value()));
181 for (
auto it = value.
cbegin(); it != value.
cend(); ++it) {
182 map.insert(it.key(), converter.
toVariant(it.value()));
195 template <
typename T>
207 convertedSet.
insert(converter.fromVariant(var));
219 list.reserve(value.
size());
221 for (
const T& val : value) {
228 #endif // VARIANTCONVERTER_H
bool canConvert(int targetTypeId) const
const_iterator cend() const
QList< QVariant > toList() const
QJsonObject fromVariantMap(const QVariantMap &map)
QMap< QString, T > fromVariant(const QVariant &value)
Returns value converted to a QMap.
Definition: VariantConverter.h:163
iterator insert(const T &value)
QVariant toVariant(const QMap< QString, T > &value)
Returns value converted to a QVariant of type QVariantMap.
Definition: VariantConverter.h:178
int fromVariant(const QVariant &value)
Returns value converted to an int.
Definition: VariantConverter.h:74
QString fromVariant(const QVariant &value)
Returns value converted to a QString.
Definition: VariantConverter.h:91
QJsonObject toJsonObject() const
int toInt(bool *ok) const
QVariant toVariant(const T &value)
Returns value converted as a QVariant.
Definition: VariantConverter.h:45
QJsonObject fromVariant(const QVariant &value)
Returns value converted to a QJsonObject.
Definition: VariantConverter.h:112
QSet< T > fromVariant(const QVariant &value)
Returns value converted to a QSet.
Definition: VariantConverter.h:203
Base template class for VariantConverter.
Definition: VariantConverter.h:36
const_iterator cbegin() const
QMap< QString, QVariant > toMap() const
QVariant toVariant(const QSet< T > &value)
Returns value converted to a QVariant of type QVariantList.
Definition: VariantConverter.h:217
QPointF fromVariant(const QVariant &value)
Returns value converted to a QPointF.
Definition: VariantConverter.h:136
iterator insert(const Key &key, const T &value)
Helper template class to convert QVariants to and from a specific type, for example, QPointFs.
Definition: VariantConverter.h:59