MCPcopy Create free account
hub / github.com/MITK/MITK / from_json

Method from_json

Modules/Forms/src/mitkForm.cpp:272–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

270}
271
272void mitk::Forms::from_json(const nlohmann::ordered_json& j, Form& f)
273{
274 if (!j.contains("FileFormat") || j["FileFormat"] != "MITK Form")
275 mitkThrow() << "Expected \"FileFormat\" field to be \"MITK Form\"!";
276
277 if (!j.contains("Version") || j["Version"] != 1)
278 mitkThrow() << "Expected \"Version\" field to be 1!";;
279
280 const auto* questionFactory = IQuestionFactory::GetInstance();
281
282 if (j.contains("Sections"))
283 {
284 bool isFirstSection = true;
285
286 for (const auto& jSection : j["Sections"])
287 {
288 std::string title;
289 std::string description;
290
291 if (jSection.contains("Title"))
292 title = jSection["Title"];
293
294 if (jSection.contains("Description"))
295 description = jSection["Description"];
296
297 auto& section = isFirstSection
298 ? f.GetSection(0)
299 : f.AddSection(title, description);
300
301 if (isFirstSection)
302 {
303 section.SetTitle(title);
304 section.SetDescription(description);
305
306 isFirstSection = false;
307 }
308
309 if (jSection.contains("Questions"))
310 {
311 for (const auto& jQuestion : jSection["Questions"])
312 {
313 auto question = questionFactory->Create(jQuestion["Type"]);
314 question->FromJSON(jQuestion);
315
316 section.AddQuestion(question);
317 }
318 }
319 }
320 }
321}
322
323void mitk::Forms::to_json(nlohmann::ordered_json& j, const Form& f)
324{

Callers

nothing calls this directly

Calls 6

containsMethod · 0.80
AddQuestionMethod · 0.80
SetTitleMethod · 0.45
SetDescriptionMethod · 0.45
CreateMethod · 0.45
FromJSONMethod · 0.45

Tested by

no test coverage detected