Medical Imaging Interaction Toolkit  2026.06.00
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:
39 
43 
49  std::vector<std::string> GetResponsesAsStrings() const override;
50 
53  void ClearResponses() override;
54 
59  bool IsComplete() const override;
60 
65  bool HasOtherOption() const;
66 
72 
73  protected:
78  void SetResponse(size_t i) override;
79 
90  void AddOtherResponse(const std::string& response);
91 
95 
106  void SetOtherResponse(const std::string& response);
107 
108  private:
109  bool m_HasOtherOption;
110  std::optional<std::string> m_OtherResponse;
111  };
112 
123  MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json& j, QuestionWithOtherOption& q);
124 
134  MITKFORMS_EXPORT void to_json(nlohmann::ordered_json& j, const QuestionWithOtherOption& q);
135 }
136 
137 #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 whether at least one response (regular or "Other") has been given.
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 all selected responses, including the "Other" response.
bool HasOtherOption() const
Query whether this question actually has an "Other" option.
void SetResponse(size_t i) override
Set a regular option as the single response and clear any "Other" response.
void EnableOtherOption()
Switch on the "Other" option.
~QuestionWithOtherOption() override
Virtual destructor.
std::vector< std::string > GetResponsesAsStrings() const override
Return all selected responses as strings, including the "Other" response if set.
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.