• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • structures
  • script
scriptutils.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Okteta Kasten Framework, made within the KDE community.
3  *
4  * Copyright 2010, 2012 Alex Richardson <alex.richardson@gmx.de>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) version 3, or any
10  * later version accepted by the membership of KDE e.V. (or its
11  * successor approved by the membership of KDE e.V.), which shall
12  * act as a proxy defined in Section 6 of version 3 of the license.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21  */
22 #include "scriptutils.h"
23 
24 #include <QScriptValueIterator>
25 #include <QScriptValue>
26 #include <QScriptString>
27 #include <QScriptContext>
28 #include <QScriptEngine>
29 
30 #include <KDebug>
31 
32 #include "../allprimitivetypes.h"
33 
34 QString ScriptUtils::qScriptValueToString(const QScriptValue& val)
35 {
36  if (!val.isValid())
37  return QLatin1String("invalid");
38  if (val.isUndefined())
39  return QLatin1String("undefined");
40  if (val.isNull())
41  return QLatin1String("null");
42 
43 
44  QString ret = val.toString();
45  if (!val.isQObject()) {
46  return ret;
47  }
48  ret += QLatin1String(" [");
49  QScriptValueIterator it(val);
50  bool first = true;
51  while (it.hasNext())
52  {
53  if (it.name().startsWith(QLatin1String("_")))
54  continue; // skip all names starting with _ like e.g. __proto__
55 
56  if (!first)
57  ret += QLatin1String(", ");
58  else
59  first = false;
60 
61  it.next();
62  QScriptValue loopValue = it.value();
63  if (!loopValue.isObject()) {
64  ret += it.name() + QLatin1String("=") + loopValue.toString();
65  }
66  else {
67  ret += it.name() + QLatin1String("=") + qScriptValueToString(loopValue);
68  }
69  }
70  return ret;
71 }
72 
73 void ScriptUtils::wrapAllPrimitiveTypes(QScriptValue& out,
74  AllPrimitiveTypes allPrim, PrimitiveDataType actualType)
75 {
76  out.setProperty(QLatin1String("type"), PrimitiveType::standardTypeName(actualType));
77  out.setProperty(QLatin1String("char"), QString(allPrim.value<quint8>() > 127
78  ? QChar::ReplacementCharacter : QChar(allPrim.value<qint8>(), 0)));
79  out.setProperty(QLatin1String("int8"), allPrim.value<qint8>());
80  out.setProperty(QLatin1String("uint8"), allPrim.value<quint8>());
81  out.setProperty(QLatin1String("int16"), allPrim.value<qint16>());
82  out.setProperty(QLatin1String("uint16"), allPrim.value<quint16>());
83  out.setProperty(QLatin1String("int32"), allPrim.value<qint32>());
84  out.setProperty(QLatin1String("uint32"), allPrim.value<quint32>());
85  out.setProperty(QLatin1String("int64"), QString::number(allPrim.value<qint64>()));
86  out.setProperty(QLatin1String("uint64"), QString::number(allPrim.value<quint64>()));
87  //QtScript has no support for 64 bit ints, add another value which contains the higher 32 bits
88  //XXX any better solution for this?
89  out.setProperty(QLatin1String("int64high32bits"), qint32(allPrim.value<qint64>() >> 32));
90  out.setProperty(QLatin1String("uint64high32bits"), quint32(allPrim.value<quint64>() >> 32));
91 
92  out.setProperty(QLatin1String("float"), allPrim.value<float>());
93  out.setProperty(QLatin1String("double"), allPrim.value<double>());
94 }
PrimitiveDataType
Definition: primitivedatatype.h:54
ScriptUtils::qScriptValueToString
QString qScriptValueToString(const QScriptValue &val)
Definition: scriptutils.cpp:34
PrimitiveType::standardTypeName
QString standardTypeName(PrimitiveDataType type)
Definition: primitivedatatype.cpp:76
AllPrimitiveTypes::value
T value() const
ScriptUtils::wrapAllPrimitiveTypes
void wrapAllPrimitiveTypes(QScriptValue &out, AllPrimitiveTypes allPrim, PrimitiveDataType actualType)
Definition: scriptutils.cpp:73
AllPrimitiveTypes
This union holds the value of one primitive datatype.
Definition: allprimitivetypes.h:70
scriptutils.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

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