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>
00026 #include <Plasma/Service>
00027 #include <Plasma/ServiceJob>
00028
00029 using namespace Plasma;
00030
00031 Q_DECLARE_METATYPE(DataEngine*)
00032 Q_DECLARE_METATYPE(Service*)
00033 Q_DECLARE_METATYPE(ServiceJob*)
00034 Q_DECLARE_METATYPE(QVariant)
00035 Q_DECLARE_METATYPE(DataEngine::Dict)
00036 Q_DECLARE_METATYPE(DataEngine::Data)
00037
00038
00039 template <class M>
00040 QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map)
00041 {
00042 kDebug() << "qScriptValueFromMap called";
00043
00044 QScriptValue obj = eng->newObject();
00045 typename M::const_iterator begin = map.constBegin();
00046 typename M::const_iterator end = map.constEnd();
00047 typename M::const_iterator it;
00048 for (it = begin; it != end; ++it)
00049 obj.setProperty(it.key(), qScriptValueFromValue(eng, it.value()));
00050 return obj;
00051 }
00052
00053 template <class M>
00054 void qScriptValueToMap(const QScriptValue &value, M &map)
00055 {
00056 QScriptValueIterator it(value);
00057 while (it.hasNext()) {
00058 it.next();
00059 map[it.name()] = qscriptvalue_cast<typename M::mapped_type>(it.value());
00060 }
00061 }
00062
00063 template<typename T>
00064 int qScriptRegisterMapMetaType(
00065 QScriptEngine *engine,
00066 const QScriptValue &prototype = QScriptValue()
00067 #ifndef qdoc
00068 , T * = 0
00069 #endif
00070 )
00071 {
00072 return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap,
00073 qScriptValueToMap, prototype);
00074 }
00075
00076 #endif // BIND_DATAENGINE_H
00077