void NgfpReader::containerFromJson (const QJsonArray &j_container, Container *container, Project *project, Screen *screen) { for (int i = 0; i < j_container.size(); i++) { if (!j_container[i].isObject()) { last_warnings.append("Not a proper JSON object for element in .ngfp"); continue; } QJsonValue j_elemview = j_container[i]; QJsonValue j_type = j_elemview.toObject()["type"]; if (!j_type.isString()) { last_warnings.append(QString("No proper \"type\" key for element %1").arg(i)); continue; } QString elem_keyname = g_ngfpFindElemName(j_type.toString()); auto elem_data = ElemRegistrar::get(elem_keyname); auto elemview_fct = ElemViewRegistrar::get(elem_keyname); if (elem_data == nullptr || elem_data->fct == nullptr || elemview_fct == nullptr) { last_warnings.append(QString("Unable to create \"%1\" element. Incorrect keyname or " "factory").arg(elem_keyname)); continue; } Elem *elem = elem_data->fct->create(); ElemView *elemview = elemview_fct->create(elem); QObject::connect(elemview, &ElemView::needToRemoveElem, project, &Core::Project::onNeedToRemoveElem); elemViewFromJson(j_elemview.toObject(), elemview, project); modifySpecificElemView(j_elemview, elemview, project, screen); elem->behave(); // because attribute values have been just loaded from file project->addElem(elem); screen->space_showed = container->getLastSpace(); screen->endMoveNewElemView(elemview); elemview->updateBindingStyle(project->temp_getLayer()->getFields()); } }
void NgfpReader::elemViewFromJson (const QJsonObject &j_elemview, ElemView *elemview, Project *project) { Elem *elem = const_cast<Elem*>(elemview->getElem()); QString elem_keyname = elem->getKeyName(); QJsonObject j_attrs = j_elemview.value("attributes").toObject(); auto attrs = elem->getAttrs(); for (auto &attr: attrs) { QString attr_fb_keyname = attr->getKeyName(); QString attr_ngfp_keyname = NGFP_ATTR_KEYS.value(attr_fb_keyname, ""); QJsonValue j_attr = j_attrs.value(attr_ngfp_keyname); if (j_attr.isUndefined()) { last_warnings.append(QString("A key \"%1\" was not found in form.json for the \"%2\" " "elem. The default value is used") .arg(attr_fb_keyname).arg(elem_keyname)); continue; } attrFromJson(j_attr, attr); } elem->behave(); // in order to bind fields correctly next auto field_slots = elem->getFieldSlots().keys(); for (auto &field_slot: field_slots) { QString fs_ngfp_keyname = NGFP_FIELD_KEYS.value(field_slot, ""); QJsonValue j_attr = j_attrs.value(fs_ngfp_keyname); if (j_attr.isUndefined()) { last_warnings.append(QString("A key \"%1\" was not found in form.json for the \"%2\" " "elem. No field binding is used instead") .arg(fs_ngfp_keyname).arg(elem_keyname)); continue; } fieldSlotFromJson(j_attr.toString(""), project, elem, field_slot); } }