C++: Added conversion/constructor between QVariantMap and SmartAPI Map
[smartapi.git] / Common / C++ / SmartAPI / smartapi / model / Map.cpp
index 0709a1aa451df81f094e73042fbf8e535af64242..aee15ef77b272ce4519a4a3deff18c1607254071 100755 (executable)
@@ -20,10 +20,41 @@ Map::Map(Map* m) : Obj(m)
        setType(RESOURCE__MAP);
 }
 
+Map::Map(QVariantMap m)
+{
+       QMapIterator<QString, QVariant> i(m);
+       while (i.hasNext()) {
+               i.next();
+               if (i.value().type() == QMetaType::QVariantMap) {
+                       insert(i.key(), new Variant(new Map(i.value().toMap())));
+               } else {
+                       insert(i.key(), new Variant(i.value()));
+               }
+       }
+       setType(RESOURCE__MAP);
+}
+
 Map::~Map()
 {
 }
 
+QVariantMap Map::toVariantMap()
+{
+       QVariantMap m;
+       QMapIterator<QString, Variant*> i(mMap);
+       while (i.hasNext()) {
+               i.next();
+               QVariant v = i.value()->getValue();
+               if (i.value()->getType() == SMARTAPIVARIANT::MAP) {
+                       Map* mv = (Map*)v.value<void*>();
+                       m.insert(i.key(), mv->toVariantMap());
+               } else {
+                       m.insert(i.key(), v);
+               }
+       }
+       return m;
+}
+
 void Map::clearReferences(QSet<GraphItem*>* trash)
 {
        QList<QString> keys = mMap.keys();