Plasma
bind_dataengine.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef BIND_DATAENGINE_H
00020 #define BIND_DATAENGINE_H
00021
00022 #include <QtScript/QtScript>
00023 #include <KDebug>
00024
00025 #include <plasma/dataengine.h>
00026
00027 using namespace Plasma;
00028
00029 Q_DECLARE_METATYPE(DataEngine*)
00030 Q_DECLARE_METATYPE(QVariant)
00031 Q_DECLARE_METATYPE(DataEngine::Dict)
00032 Q_DECLARE_METATYPE(DataEngine::Data)
00033
00034 template <class M>
00035 QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map)
00036 {
00037 kDebug() << "qScriptValueFromMap called";
00038
00039 QScriptValue obj = eng->newObject();
00040 typename M::const_iterator begin = map.begin();
00041 typename M::const_iterator end = map.end();
00042 typename M::const_iterator it;
00043 for (it = begin; it != end; ++it)
00044 obj.setProperty(it.key(), qScriptValueFromValue(eng, it.value()));
00045 return obj;
00046 }
00047
00048 template <class M>
00049 void qScriptValueToMap(const QScriptValue &value, M &map)
00050 {
00051 QScriptValueIterator it(value);
00052 while (it.hasNext()) {
00053 it.next();
00054 map[it.name()] = qscriptvalue_cast<typename M::mapped_type>(it.value());
00055 }
00056 }
00057
00058 template<typename T>
00059 int qScriptRegisterMapMetaType(
00060 QScriptEngine *engine,
00061 const QScriptValue &prototype = QScriptValue()
00062 #ifndef qdoc
00063 , T * = 0
00064 #endif
00065 )
00066 {
00067 return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap,
00068 qScriptValueToMap, prototype);
00069 }
00070
00071 #endif // BIND_DATAENGINE_H
00072