1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
|
/*
* This file is part of the xTuple ERP: PostBooks Edition, a free and
* open source Enterprise Resource Planning software suite,
* Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
* It is licensed to you under the Common Public Attribution License
* version 1.0, the full text of which (including xTuple-specific Exhibits)
* is available at www.xtuple.com/CPAL. By using this software, you agree
* to be bound by its terms.
*/
#include "qjsonobjectproto.h"
#if QT_VERSION < 0x050000
void setupQJsonObjectProto(QScriptEngine *engine)
{
// do nothing
}
#else
#include <QJsonObject>
QScriptValue QJsonObjectToScriptValue(QScriptEngine *engine, QJsonObject* const &in)
{
QScriptValue obj = engine->toScriptValue(in->toVariantMap());
return obj;
}
void QJsonObjectFromScriptValue(const QScriptValue &obj, QJsonObject* &out)
{
out = dynamic_cast<QJsonObject*>(obj.toQObject());
}
static QScriptValue fromVariantHash(QScriptContext *context, QScriptEngine *engine)
{
QJsonObject obj = QJsonObject::fromVariantHash(context->argument(0).toVariant().toHash());
return QJsonObjectToScriptValue(engine, &obj);
}
static QScriptValue fromVariantMap(QScriptContext *context, QScriptEngine *engine)
{
QJsonObject obj = QJsonObject::fromVariantMap(context->argument(0).toVariant().toMap());
return QJsonObjectToScriptValue(engine, &obj);
}
void setupQJsonObjectProto(QScriptEngine *engine)
{
qScriptRegisterMetaType(engine, QJsonObjectToScriptValue, QJsonObjectFromScriptValue);
QScriptValue proto = engine->newQObject(new QJsonObjectProto(engine));
engine->setDefaultPrototype(qMetaTypeId<QJsonObject*>(), proto);
QScriptValue constructor = engine->newFunction(constructQJsonObject, proto);
proto.setProperty("fromVariantHash", engine->newFunction(fromVariantHash));
proto.setProperty("fromVariantMap", engine->newFunction(fromVariantMap));
engine->globalObject().setProperty("QJsonObject", constructor);
}
QScriptValue constructQJsonObject(QScriptContext * context,
QScriptEngine *engine)
{
QJsonObject *obj = 0;
if (context->argumentCount() == 1 && context->argument(0).isVariant())
obj = new QJsonObject(context->argument(0).toVariant().toJsonObject());
else
obj = new QJsonObject();
return engine->toScriptValue(obj);
}
QJsonObjectProto::QJsonObjectProto(QObject *parent)
: QObject(parent)
{
}
QJsonObjectProto::~QJsonObjectProto()
{
}
#ifdef Use_QJsonObjectIterators
QJsonObject::iterator QJsonObjectProto::begin()
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->begin();
return QJsonObject::iterator();
}
QJsonObject::const_iterator QJsonObjectProto::begin() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->begin();
return QJsonObject::const_iterator();
}
QJsonObject::const_iterator QJsonObjectProto::constBegin() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->constBegin();
return QJsonObject::const_iterator();
}
QJsonObject::const_iterator QJsonObjectProto::constEnd() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->constEnd();
return QJsonObject::const_iterator();
}
QJsonObject::const_iterator QJsonObjectProto::constFind(const QString & key) const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->constFind(key);
return QJsonObject::const_iterator();
}
#endif
bool QJsonObjectProto::contains(const QString & key) const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->contains(key);
return false;
}
int QJsonObjectProto::count() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->count();
return 0;
}
bool QJsonObjectProto::empty() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->empty();
return false;
}
#ifdef Use_QJsonObjectIterators
QJsonObject::iterator QJsonObjectProto::end()
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->end();
return QJsonObject::iterator();
}
QJsonObject::const_iterator QJsonObjectProto::end() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->end();
return QJsonObject::const_iterator();
}
QJsonObject::iterator QJsonObjectProto::erase(QJsonObject::iterator it)
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->erase(it);
return QJsonObject::iterator();
}
QJsonObject::iterator QJsonObjectProto::find(const QString & key)
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->find(key);
return QJsonObject::iterator();
}
QJsonObject::const_iterator QJsonObjectProto::find(const QString & key) const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->find(key);
return QJsonObject::const_iterator();
}
QJsonObject::iterator QJsonObjectProto::insert(const QString & key, const QJsonValue & value)
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->insert(key, value);
return QJsonObject::iterator();
}
#endif
bool QJsonObjectProto::isEmpty() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->isEmpty();
return false;
}
QStringList QJsonObjectProto::keys() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->keys();
return QStringList();
}
int QJsonObjectProto::length() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->length();
return 0;
}
void QJsonObjectProto::remove(const QString & key)
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
item->remove(key);
}
int QJsonObjectProto::size() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->size();
return 0;
}
QJsonValue QJsonObjectProto::take(const QString & key)
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->take(key);
return QJsonValue();
}
QVariantHash QJsonObjectProto::toVariantHash() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->toVariantHash();
return QVariantHash();
}
QVariantMap QJsonObjectProto::toVariantMap() const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->toVariantMap();
return QVariantMap();
}
QJsonValue QJsonObjectProto::value(const QString & key) const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->value(key);
return QJsonValue();
}
bool QJsonObjectProto::operator!=(const QJsonObject & other) const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->operator!=(other);
return false;
}
QJsonObject &QJsonObjectProto::operator=(const QJsonObject & other)
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->operator=(other);
return *(new QJsonObject());
}
bool QJsonObjectProto::operator==(const QJsonObject & other) const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->operator==(other);
return false;
}
QJsonValue QJsonObjectProto::operator[](const QString & key) const
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->operator[](key);
return QJsonValue();
}
QJsonValueRef QJsonObjectProto::operator[](const QString & key)
{
QJsonObject *item = qscriptvalue_cast<QJsonObject*>(thisObject());
if (item)
return item->operator[](key);
return QJsonValueRef(new QJsonObject(), 0);
}
#endif
|