| 270 | } |
| 271 | |
| 272 | void 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 | |
| 323 | void mitk::Forms::to_json(nlohmann::ordered_json& j, const Form& f) |
| 324 | { |
nothing calls this directly
no test coverage detected