Medical Imaging Interaction Toolkit  2026.06.00
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 {
38  {
39  public:
45 
48  virtual ~Question();
49 
54  std::string GetQuestionText() const;
55 
60  void SetQuestionText(const std::string& question);
61 
66  bool IsRequired() const;
67 
74  void SetRequired(bool required = true);
75 
88  virtual std::string GetRequiredText() const;
89 
99  virtual bool HasFileResponses() const;
100 
115  virtual std::vector<fs::path> SubmitFileResponses(const fs::path& basePath) const;
116 
149  virtual std::string GetType() const = 0;
150 
165  virtual Question* CreateAnother() const = 0;
166 
184  virtual std::vector<std::string> GetResponsesAsStrings() const = 0;
185 
190  virtual void ClearResponses() = 0;
191 
199  virtual bool IsComplete() const = 0;
200 
221  virtual void FromJSON(const nlohmann::ordered_json& j) = 0;
222 
243  virtual void ToJSON(nlohmann::ordered_json& j) const = 0;
244 
247  private:
248  std::string m_QuestionText;
249  bool m_IsRequired;
250  };
251 
277  MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json& j, Question& q);
278 
304  MITKFORMS_EXPORT void to_json(nlohmann::ordered_json& j, const Question& q);
305 }
306 
307 #endif
#define MITKFORMS_EXPORT
Abstract base class for all types of questions used in a Form.
Definition: mitkQuestion.h:38
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 ~Question()
Virtual destructor.
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.
Question()
Default constructor.
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 text.
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 response to this question is required to complete a form.
std::string GetQuestionText() const
Get the literal question text.
virtual std::vector< fs::path > SubmitFileResponses(const fs::path &basePath) const
Attach response files to submission.
Portability header that provides a unified namespace alias for the C++ filesystem library.
MITKFORMS_EXPORT void to_json(nlohmann::ordered_json &j, const CheckboxesQuestion &q)
Serialize a CheckboxesQuestion to JSON.
MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json &j, CheckboxesQuestion &q)
Deserialize a CheckboxesQuestion from JSON.