Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkQuestion.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkQuestion_h
14 #define mitkQuestion_h
15 
16 #include <mitkFileSystem.h>
17 #include <MitkFormsExports.h>
18 
19 #include <string>
20 #include <vector>
21 
22 #include <nlohmann/json_fwd.hpp>
23 
24 namespace mitk::Forms
25 {
32  {
33  public:
35  virtual ~Question();
36 
39  std::string GetQuestionText() const;
40 
43  void SetQuestionText(const std::string& question);
44 
47  bool IsRequired() const;
48 
53  void SetRequired(bool required = true);
54 
63  virtual std::string GetRequiredText() const;
64 
72  virtual bool HasFileResponses() const;
73 
83  virtual std::vector<fs::path> SubmitFileResponses(const fs::path& basePath) const;
84 
117  virtual std::string GetType() const = 0;
118 
133  virtual Question* CreateAnother() const = 0;
134 
150  virtual std::vector<std::string> GetResponsesAsStrings() const = 0;
151 
154  virtual void ClearResponses() = 0;
155 
161  virtual bool IsComplete() const = 0;
162 
181  virtual void FromJSON(const nlohmann::ordered_json& j) = 0;
182 
201  virtual void ToJSON(nlohmann::ordered_json& j) const = 0;
202 
205  private:
206  std::string m_QuestionText;
207  bool m_IsRequired;
208  };
209 
232  MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json& j, Question& q);
233 
256  MITKFORMS_EXPORT void to_json(nlohmann::ordered_json& j, const Question& q);
257 }
258 
259 #endif
#define MITKFORMS_EXPORT
Abstract base class for all types of questions used in a Form.
Definition: mitkQuestion.h:32
virtual void ClearResponses()=0
Clear the/all response(s).
virtual bool HasFileResponses() const
Query whether the responses given to this question are file paths.
virtual Question * CreateAnother() const =0
Create a new instance of the derived question class type.
virtual void FromJSON(const nlohmann::ordered_json &j)=0
Deserialize from JSON.
virtual std::string GetRequiredText() const
Get the text that should be displayed to clearly mark a question as required.
bool IsRequired() const
Check whether a response to this question is required to complete a form.
virtual bool IsComplete() const =0
Check if a question is considered to be answered completely.
virtual std::vector< std::string > GetResponsesAsStrings() const =0
Return the question's response(s) as strings.
virtual void ToJSON(nlohmann::ordered_json &j) const =0
Serialize to JSON.
void SetQuestionText(const std::string &question)
Set the literal question.
virtual std::string GetType() const =0
Return the type of a question as string, e.g. "Multiple choice" or "Drop-down".
void SetRequired(bool required=true)
Set whether a resonse to this question is required to complete a form.
std::string GetQuestionText() const
Get the literal question.
virtual std::vector< fs::path > SubmitFileResponses(const fs::path &basePath) const
Attach response files to submission.
MITKFORMS_EXPORT void to_json(nlohmann::ordered_json &j, const CheckboxesQuestion &q)
MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json &j, CheckboxesQuestion &q)