コード例 #1
0
void QDeclarativePolylineMapItem::setPath(const QJSValue &value)
{
    if (!value.isArray())
        return;

    QList<QGeoCoordinate> pathList;
    quint32 length = value.property(QStringLiteral("length")).toUInt();
    for (quint32 i = 0; i < length; ++i) {
        bool ok;
        QGeoCoordinate c = parseCoordinate(value.property(i), &ok);

        if (!ok || !c.isValid()) {
            qmlInfo(this) << "Unsupported path type";
            return;
        }

        pathList.append(c);
    }

    if (path_ == pathList)
        return;

    path_ = pathList;

    geometry_.markSourceDirty();
    updateMapItem();
    emit pathChanged();
}
コード例 #2
0
/**
 * @internal
 * @brief QBsonConverter::mapValue converts alls simple values and redirects to
 * mapObject and mapArray methods. If a value can not converted an
 * empty bsonvalue is returned.
 *
 * @param jsValue jsValue to convert
 *
 * @return QBsonValue
 */
QBsonValue QBsonConverter::mapValue(const QJSValue &jsValue)
{
    if (jsValue.isBool()) {
        return QBsonValue(jsValue.toBool());
    }
    if (jsValue.isDate()) {
        return QBsonValue(jsValue.toDateTime());
    }
    if (jsValue.isString()) {
        return QBsonValue(jsValue.toString());
    }
    if (jsValue.isNumber()) {
        int vType = jsValue.toVariant().type();
        switch (vType) {
            case QVariant::Double:
                return QBsonValue(jsValue.toVariant().toDouble());
                break;
            case QVariant::Int:
                return QBsonValue(jsValue.toVariant().toInt());
                break;
        }
    }
    if (jsValue.isArray()) {
        return mapArray(jsValue);
    }
    if (jsValue.isObject()) {
        return mapObject(jsValue);
    }

    return QBsonValue();
}
コード例 #3
0
QJSValue THREEMatrix4::applyVector3Array(QJSValue floatArray, int offset, int length)
{
    if(!floatArray.isArray()) {
        qDebug().nospace() << "THREEMatrix4::" << __FUNCTION__
                           << " invalid parameter type for floatArray, expected JS array";
        return m_engine->newQObject(this);
    }

    static THREEVector3 v1(parent(), m_engine);
    QVariantList list = floatArray.toVariant().toList();

    if (offset < 0)
        offset = 0;

    if (length < 0 || length == 0)
        length = list.length();

    if (offset + length > list.length())
        length = list.length() - offset;

    for ( int i = 0, j = offset; i < length; i += 3, j += 3 ) {
        v1.m_x = float(floatArray.property(j).toNumber());
        v1.m_y = float(floatArray.property(j + 1).toNumber());
        v1.m_z = float(floatArray.property(j + 2).toNumber());

        v1._applyMatrix4( this );

        floatArray.setProperty(j, QJSValue(v1.m_x));
        floatArray.setProperty(j + 1, QJSValue(v1.m_y));
        floatArray.setProperty(j + 2, QJSValue(v1.m_z));
    }

    return floatArray;
}
コード例 #4
0
void QDeclarativeGeoRoute::setPath(const QJSValue &value)
{
    if (!value.isArray())
        return;

    QList<QGeoCoordinate> pathList;
    quint32 length = value.property(QStringLiteral("length")).toUInt();
    for (quint32 i = 0; i < length; ++i) {
        bool ok;
        QGeoCoordinate c = parseCoordinate(value.property(i), &ok);

        if (!ok || !c.isValid()) {
            qmlInfo(this) << "Unsupported path type";
            return;
        }

        pathList.append(c);
    }

    if (route_.path() == pathList)
        return;

    route_.setPath(pathList);

    emit pathChanged();
}
コード例 #5
0
QJsonValue QJsonConvert::jsonFromScriptValue(const QJSValue& jsval){
    if ( jsval.isArray() ){
        QJSValueIterator it(jsval);

        QJsonArray arr;
        while( it.hasNext() ){
            it.next();

            QJsonValue itJsonValue = jsonFromScriptValue(it.value());
            if( !itJsonValue.isNull() )
                arr.append(itJsonValue);
        }

        return QJsonValue(arr);
    } else if ( jsval.isObject() ){
        QJSValueIterator it(jsval);

        QJsonObject obj;
        while( it.hasNext() ){
            it.next();
            QJsonValue itJsonValue = jsonFromScriptValue(it.value());
            if( !itJsonValue.isNull() )
                obj[it.name()] = itJsonValue;
        }
        return QJsonValue(obj);
    } else  if ( jsval.isString() ){
        return QJsonValue(jsval.toString());
    } else if ( jsval.isBool() ){
        return QJsonValue(jsval.toString());
    } else if ( jsval.isNumber() ){
        return QJsonValue(jsval.toNumber() );
    }
    return QJsonValue();
}
コード例 #6
0
static QString qjsValueToString(const QJSValue &v)
{
  if (v.isArray()) {
    return QStringLiteral("<array>");
  } else if (v.isBool()) {
    return v.toBool() ? QStringLiteral("true") : QStringLiteral("false");
  } else if (v.isCallable()) {
    return QStringLiteral("<callable>");
  } else if (v.isDate()) {
    return v.toDateTime().toString();
  } else if (v.isError()) {
    return QStringLiteral("<error>");
  } else if (v.isNull()) {
    return QStringLiteral("<null>");
  } else if (v.isNumber()) {
    return QString::number(v.toNumber());
  } else if (v.isObject()) {
    return QStringLiteral("<object>");
  } else if (v.isQObject()) {
    return Util::displayString(v.toQObject());
  } else if (v.isRegExp()) {
    return QStringLiteral("<regexp>");
  } else if (v.isString()) {
    return v.toString();
  } else if (v.isUndefined()) {
    return QStringLiteral("<undefined>");
  } else if (v.isVariant()) {
    return VariantHandler::displayString(v.toVariant());
  }
  return QStringLiteral("<unknown QJSValue>");
}
コード例 #7
0
ファイル: jskitobjects.cpp プロジェクト: ecosprog/pebble
void JSKitXMLHttpRequest::send(const QJSValue &data)
{
    QByteArray byteData;

    if (data.isUndefined() || data.isNull()) {
        // Do nothing, byteData is empty.
    } else if (data.isString()) {
        byteData == data.toString().toUtf8();
    } else if (data.isObject()) {
        if (data.hasProperty("byteLength")) {
            // Looks like an ArrayView or an ArrayBufferView!
            QJSValue buffer = data.property("buffer");
            if (buffer.isUndefined()) {
                // We must assume we've been passed an ArrayBuffer directly
                buffer = data;
            }

            QJSValue array = data.property("_bytes");
            int byteLength = data.property("byteLength").toInt();

            if (array.isArray()) {
                byteData.reserve(byteLength);

                for (int i = 0; i < byteLength; i++) {
                    byteData.append(array.property(i).toInt());
                }

                qCDebug(l) << "passed an ArrayBufferView of" << byteData.length() << "bytes";
            } else {
                qCWarning(l) << "passed an unknown/invalid ArrayBuffer" << data.toString();
            }
        } else {
            qCWarning(l) << "passed an unknown object" << data.toString();
        }

    }

    QBuffer *buffer;
    if (!byteData.isEmpty()) {
        buffer = new QBuffer;
        buffer->setData(byteData);
    } else {
        buffer = 0;
    }

    qCDebug(l) << "sending" << _verb << "to" << _request.url() << "with" << QString::fromUtf8(byteData);
    _reply = _net->sendCustomRequest(_request, _verb.toLatin1(), buffer);

    connect(_reply, &QNetworkReply::finished,
            this, &JSKitXMLHttpRequest::handleReplyFinished);
    connect(_reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
            this, &JSKitXMLHttpRequest::handleReplyError);

    if (buffer) {
        // So that it gets deleted alongside the reply object.
        buffer->setParent(_reply);
    }
}
コード例 #8
0
ファイル: qtutil.cpp プロジェクト: raffber/capnqml
Option<Error> jsToJson(QJSValue value, JsonValue::Builder builder) {
    if (value.isArray()) {
        std::vector<QJSValue> arr;
        QJSValueIterator iter(value);
        while (iter.hasNext()) {
            iter.next();
            // dafuq!? why is this required
            if (!iter.hasNext()) {
                break;
            }
            arr.push_back(iter.value());
        }
        auto lst = builder.initArray(static_cast<unsigned int>(arr.size()));
        for (auto k = 0; k < arr.size(); ++k) {
            auto subvalue = lst[k];
            auto opt_err = jsToJson(arr[k], subvalue);
            if (opt_err.has()) {
                return opt_err;
            }
        }
        return Option<Error>();
    } if (value.isObject()) {
        std::vector<std::tuple<QString, QJSValue>> arr;
        QJSValueIterator iter(value);
        while (iter.hasNext()) {
            iter.next();
            arr.push_back(std::make_tuple(iter.name(), iter.value()));
        }
        auto lst = builder.initObject(static_cast<unsigned int>(arr.size()));
        for (auto k = 0; k < arr.size(); ++k) {
            auto value_builder = lst[k].initValue();
            const char *name = std::get<0>(arr[k]).toUtf8().constData();
            lst[k].setName(name);
            auto opt_err = jsToJson(std::get<1>(arr[k]), value_builder);
            if (opt_err.has()) {
                return opt_err;
            }
        }
        return Option<Error>();
    } if (value.isBool()) {
        builder.setBoolean(value.toBool());
        return Option<Error>();
    } if (value.isNumber()) {
        builder.setNumber(value.toNumber());
        return Option<Error>();
    } if (value.isString()) {
        const char *str = value.toString().toUtf8().constData();
        builder.setString(str);
        return Option<Error>();
    } if (value.isNull()) {
        builder.setNone();
        return Option<Error>();
    }
    auto tpname = toStdString(value.toVariant().typeName());
    Error err(Error::Kind::ClientSideError, "Invalid type: " + tpname);
    return err;
}
コード例 #9
0
void THREEMatrix3::setElements(QJSValue elementValue) {
    int numElements = 9;
    if (elementValue.isArray()) {
        // Handle JavaScript array
        QVariantList list = elementValue.toVariant().toList();
        if (list.count() >= numElements)
            fillFloatArrayFromVariantList(list, m_elements);
        return;
    }

    int dataLen = 0;
    uchar *data = getTypedArrayAsRawDataPtr(elementValue, dataLen,
                                            QV4::Heap::TypedArray::Float32Array);
    if (data && dataLen >= numElements) {
        // Handle Float32Array
        float *fdata = (float *) data;
        memcpy(m_elements, fdata, numElements);
    }
}
コード例 #10
0
void Decision::setWriteIns(QJSValue newWriteIns)
{
    if (newWriteIns.strictlyEquals(this->writeIns()))
        return;
    if (!newWriteIns.isArray()) {
        qDebug() << "Cannot set write-ins because it is not an array.";
        return;
    }

    auto writeInList = m_decision.initWriteIns(newWriteIns.property("length").toInt());
    QJSValueIterator itr(newWriteIns);
    for (::UnsignedContest::Contestant::Builder writeInBuilder : writeInList) {
        itr.next();
        writeInBuilder.setName(itr.value().property("name").toString().toStdString());
        writeInBuilder.setDescription(itr.value().property("description").toString().toStdString());
    }

    emit writeInsChanged();
}
コード例 #11
0
QVariantList DeclarativeDBusInterface::argumentsFromScriptValue(const QJSValue &arguments)
{
    QVariantList dbusArguments;

    if (arguments.isArray()) {
        QJSValueIterator it(arguments);
        while (it.hasNext()) {
            it.next();
            // Arrays carry the size as last value
            if (!it.hasNext())
                continue;
            dbusArguments.append(it.value().toVariant());
        }
    } else if (!arguments.isUndefined()) {
        dbusArguments.append(arguments.toVariant());
    }

    return dbusArguments;
}
コード例 #12
0
QJSValue THREEMatrix4::flattenToArrayOffset(QJSValue floatArray, int offset)
{
    if(!floatArray.isArray()) {
        qDebug().nospace() << "THREEMatrix4::" << __FUNCTION__
                           << " invalid parameter type for floatArray, expected JS array";
        return m_engine->newQObject(this);
    }

    if (offset < 0)
        offset = 0;

    int length = floatArray.toVariant().toList().length();

    float *te = m_elements;

    floatArray.setProperty(offset,te[0]);
    floatArray.setProperty(offset + 1, te[1]);
    floatArray.setProperty(offset + 2, te[2]);
    floatArray.setProperty(offset + 3, te[3]);

    floatArray.setProperty(offset + 4, te[4]);
    floatArray.setProperty(offset + 5, te[5]);
    floatArray.setProperty(offset + 6, te[6]);
    floatArray.setProperty(offset + 7, te[7]);

    floatArray.setProperty(offset + 8,  te[8]);
    floatArray.setProperty(offset + 9,  te[9]);
    floatArray.setProperty(offset + 10, te[10]);
    floatArray.setProperty(offset + 11, te[11]);

    floatArray.setProperty(offset + 12, te[12]);
    floatArray.setProperty(offset + 13, te[13]);
    floatArray.setProperty(offset + 14, te[14]);
    floatArray.setProperty(offset + 15, te[15]);

    return floatArray;
}
コード例 #13
0
ファイル: Intrinsics.cpp プロジェクト: johntyree/HsQML
extern "C" int hsqml_is_jval_array(HsQMLJValHandle* hndl)
{
    QJSValue* value = reinterpret_cast<QJSValue*>(hndl);
    return value->isArray();
}