Qt IOC Container 3.5


PropertyMapInjector.cpp

Go to the documentation of this file.
00001 #include "ReferenceInjector.h"
00002 #include "PropertyMapInjector.h"
00003 
00004 #include <QString>
00005 #include <QHash>
00006 #include <QtPlugin>
00007 
00008 using namespace qic;
00009 
00010 QVariant
00011 PropertyMapInjector::injectReference (QVariant & prop, ReferenceResolver * resolver, QHash <QString, QObject *> & injector_map)
00012 {
00013   QVariantMap map;
00014   QVariantMap src_map = prop.value<QVariantMap>();
00015   foreach (QString key, src_map.keys())
00016   {
00017     QVariant val = src_map.value(key);
00018     QString type(val.typeName());
00019     if (injector_map.contains(type))
00020     {
00021       QObject * injector_obj = injector_map[type];
00022       ReferenceInjector * injector = qobject_cast<ReferenceInjector *>(injector_obj);
00023       QVariant propVal = injector->injectReference( val, resolver, injector_map);
00024       map.insert(key, propVal);
00025     }
00026     else
00027     {
00028       map.insert(key, val);
00029     }
00030   }
00031   return QVariant::fromValue(map);
00032 }
00033 
00034 Q_EXPORT_PLUGIN2(map_injector, PropertyMapInjector)