• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaCore

  • sources
  • kde-4.12
  • kde-runtime
  • plasma
  • declarativeimports
  • core
dataenginebindings_p.h
Go to the documentation of this file.
1 /*
2  * Copyright 2007 Richard J. Moore <rich@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License version 2 as
6  * published by the Free Software Foundation
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details
12  *
13  * You should have received a copy of the GNU Library General Public
14  * License along with this program; if not, write to the
15  * Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef DATAENGINEBIND_H
20 #define DATAENGINEBIND_H
21 
22 #include <QScriptEngine>
23 #include <QScriptValue>
24 #include <QScriptValueIterator>
25 #include <kdebug.h>
26 
27 #include <plasma/dataengine.h>
28 #include <plasma/service.h>
29 #include <plasma/servicejob.h>
30 
31 Q_DECLARE_METATYPE(Plasma::DataEngine::Dict)
32 Q_DECLARE_METATYPE(Plasma::DataEngine::Data)
33 
34 template <class M>
35 QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map)
36 {
37  //kDebug() << "qScriptValueFromMap called";
38  QScriptValue obj = eng->newObject();
39  typename M::const_iterator begin = map.constBegin();
40  typename M::const_iterator end = map.constEnd();
41  typename M::const_iterator it;
42  for (it = begin; it != end; ++it) {
43  if (it.value().type() == QVariant::Hash) {
44  obj.setProperty(it.key(), qScriptValueFromMap(eng, it.value().toHash()));
45  } else if (it.value().type() == QVariant::Map) {
46  obj.setProperty(it.key(), qScriptValueFromMap(eng, it.value().toMap()));
47  } else {
48  obj.setProperty(it.key(), qScriptValueFromValue(eng, it.value()));
49  }
50  }
51 
52  return obj;
53 }
54 
55 template <class M>
56 void qScriptValueToMap(const QScriptValue &value, M &map)
57 {
58  //kDebug() << "qScriptValueToMap called";
59  QScriptValueIterator it(value);
60  while (it.hasNext()) {
61  it.next();
62  map[it.name()] = qscriptvalue_cast<typename M::mapped_type>(it.value());
63  }
64 }
65 
66 template<typename T>
67 int qScriptRegisterMapMetaType(
68  QScriptEngine *engine,
69  const QScriptValue &prototype = QScriptValue()
70 #ifndef qdoc
71  , T * /* dummy */ = 0
72 #endif
73 )
74 {
75  return qScriptRegisterMetaType<T>(engine, qScriptValueFromMap, qScriptValueToMap, prototype);
76 }
77 
78 void registerDataEngineMetaTypes(QScriptEngine *engine);
79 
80 #endif // DATAENGINE_H
81 
qScriptRegisterMapMetaType
int qScriptRegisterMapMetaType(QScriptEngine *engine, const QScriptValue &prototype=QScriptValue(), T *=0)
Definition: dataenginebindings_p.h:67
qScriptValueToMap
void qScriptValueToMap(const QScriptValue &value, M &map)
Definition: dataenginebindings_p.h:56
qScriptValueFromMap
QScriptValue qScriptValueFromMap(QScriptEngine *eng, const M &map)
Definition: dataenginebindings_p.h:35
registerDataEngineMetaTypes
void registerDataEngineMetaTypes(QScriptEngine *engine)
Definition: dataenginebindings.cpp:57
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:02:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaCore

Skip menu "PlasmaCore"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal