Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkQuestionWithOtherOption.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 mitkQuestionWithOtherOption_h
14 #define mitkQuestionWithOtherOption_h
15 
17 #include <optional>
18 
19 namespace mitk::Forms
20 {
32  {
33  public:
36 
37  std::vector<std::string> GetResponsesAsStrings() const override;
38  void ClearResponses() override;
39 
40  bool IsComplete() const override;
41 
44  bool HasOtherOption() const;
45 
51 
52  protected:
53  void SetResponse(size_t i) override;
54 
60  void AddOtherResponse(const std::string& response);
61 
65 
68  void SetOtherResponse(const std::string& response);
69 
70  private:
71  bool m_HasOtherOption;
72  std::optional<std::string> m_OtherResponse;
73  };
74 
75  MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json& j, QuestionWithOtherOption& q);
76  MITKFORMS_EXPORT void to_json(nlohmann::ordered_json& j, const QuestionWithOtherOption& q);
77 }
78 
79 #endif
#define MITKFORMS_EXPORT
Base class for questions with options to choose from as response.
Base class for questions with options that may also have a free text option.
void RemoveOtherResponse()
Remove the "Other" response from the list of already given responses.
bool IsComplete() const override
Check if a question is considered to be answered completely.
void SetOtherResponse(const std::string &response)
Set the "Other" response as single exclusive response to this question.
void AddOtherResponse(const std::string &response)
Add the free text given as "Other" option to the list of responses.
void ClearResponses() override
Clear the/all response(s).
bool HasOtherOption() const
Query whether this question actually has an "Other" option.
void SetResponse(size_t i) override
Set one of the possible answer options as the single response.
void EnableOtherOption()
Switch on the "Other" option.
std::vector< std::string > GetResponsesAsStrings() const override
Return the question's response(s) as strings.
MITKFORMS_EXPORT void to_json(nlohmann::ordered_json &j, const CheckboxesQuestion &q)
MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json &j, CheckboxesQuestion &q)