bool NestedListModel::append(const QScriptValue& valuemap) { if (!_root) { _root = new ModelNode; m_ownsRoot = true; } ModelNode *mn = new ModelNode; mn->setObjectValue(valuemap); _root->values << qVariantFromValue(mn); return true; }
bool NestedListModel::insert(int index, const QScriptValue& valuemap) { if (!_root) { _root = new ModelNode; m_ownsRoot = true; } ModelNode *mn = new ModelNode; mn->setObjectValue(valuemap); _root->values.insert(index,qVariantFromValue(mn)); return true; }
void ModelNode::setListValue(const QScriptValue& valuelist) { QScriptValueIterator it(valuelist); values.clear(); int size = valuelist.property(QLatin1String("length")).toInt32(); for (int i=0; i<size; i++) { ModelNode *value = new ModelNode; QScriptValue v = valuelist.property(i); if (v.isArray()) { value->isArray = true; value->setListValue(v); } else if (v.isObject()) { value->setObjectValue(v); } else { value->values << v.toVariant(); } values.append(qVariantFromValue(value)); } }
void NestedListModel::set(int index, const QScriptValue& valuemap, QList<int> *roles) { Q_ASSERT(index >=0 && index < count()); ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(index)); node->setObjectValue(valuemap); QScriptValueIterator it(valuemap); while (it.hasNext()) { it.next(); int r = roleStrings.indexOf(it.name()); if (r < 0) { r = roleStrings.count(); roleStrings << it.name(); } roles->append(r); } }