Exemple #1
0
QMap<QString, QVariant> KJSEmbed::convertArrayToMap(KJS::ExecState *exec, KJS::JSValue *value)
{
    QMap<QString, QVariant> returnMap;
    KJS::JSObject *obj = value->toObject(exec);
    KJS::PropertyNameArray lst;
    obj->getPropertyNames(exec, lst);
    KJS::PropertyNameArrayIterator idx = lst.begin();
    for (; idx != lst.end(); idx++) {
        KJS::Identifier id = *idx;
        KJS::JSValue *val  = obj->get(exec, id);
        returnMap[toQString(id)] = convertToVariant(exec, val);
    }
    return returnMap;
}
Exemple #2
0
QModelIndex KJSObjectModel::index(int row, int column, const QModelIndex &parent ) const
{
    KJS::JSObject *parentInstance = 0;
    Node *childItem = 0;
    KJS::ExecState *exec = m_js->globalExec();

    if (!parent.isValid())
    {
        if (m_root)
            parentInstance = m_root;
        else
            return QModelIndex();
    }
    else
        parentInstance = static_cast<Node*>(parent.internalPointer())->instance;
    int idx = 0;
    KJS::PropertyNameArray props;
    parentInstance->getPropertyNames(exec, props);
    for( KJS::PropertyNameArrayIterator ref = props.begin(); ref != props.end(); ref++)
    {
        if( idx == row)
        {
                childItem = new Node;
                childItem->name = ref->ascii(); //### M.O.: this is wrong, can be unicode.
                childItem->instance = parentInstance->get( exec,
                        childItem->name.constData() )->toObject(exec);
                childItem->parent = static_cast<Node*>(parent.internalPointer());
                break;
        }
        ++idx;
    }
    if (childItem)
        return createIndex(row, column, childItem);

    return QModelIndex();
}