Medical Imaging Interaction Toolkit  2024.06.99-ccaff7ce
Medical Imaging Interaction Toolkit
mitk::Forms::QuestionWithOtherOption Class Reference

Base class for questions with options that may also have a free text option. More...

#include <mitkQuestionWithOtherOption.h>

Inheritance diagram for mitk::Forms::QuestionWithOtherOption:
Collaboration diagram for mitk::Forms::QuestionWithOtherOption:

Public Member Functions

 QuestionWithOtherOption ()
 
 ~QuestionWithOtherOption () override
 
std::vector< std::string > GetResponsesAsStrings () const override
 Return the question's response(s) as strings. More...
 
void ClearResponses () override
 Clear the/all response(s). More...
 
bool IsComplete () const override
 Check if a question is considered to be answered completely. More...
 
bool HasOtherOption () const
 Query whether this question actually has an "Other" option. More...
 
void EnableOtherOption ()
 Switch on the "Other" option. More...
 
- Public Member Functions inherited from mitk::Forms::QuestionWithOptions
 ~QuestionWithOptions () override
 
size_t AddOption (const std::string &option)
 Add a non-exclusive option as possible answer to the question. More...
 
std::vector< std::string > GetOptions () const
 
- Public Member Functions inherited from mitk::Forms::Question
 Question ()
 
virtual ~Question ()
 
std::string GetQuestionText () const
 Get the literal question. More...
 
void SetQuestionText (const std::string &question)
 Set the literal question. More...
 
bool IsRequired () const
 Check whether a response to this question is required to complete a form. More...
 
void SetRequired (bool required=true)
 Set whether a resonse to this question is required to complete a form. More...
 
virtual std::string GetRequiredText () const
 Get the text that should be displayed to clearly mark a question as required. More...
 
virtual bool HasFileResponses () const
 Query whether the responses given to this question are file paths. More...
 
virtual std::vector< fs::path > SubmitFileResponses (const fs::path &basePath) const
 Attach response files to submission. More...
 
virtual std::string GetType () const =0
 Return the type of a question as string, e.g. "Multiple choice" or "Drop-down". More...
 
virtual QuestionCreateAnother () const =0
 Create a new instance of the derived question class type. More...
 
virtual void FromJSON (const nlohmann::ordered_json &j)=0
 Deserialize from JSON. More...
 
virtual void ToJSON (nlohmann::ordered_json &j) const =0
 Serialize to JSON. More...
 

Protected Member Functions

void SetResponse (size_t i) override
 Set one of the possible answer options as the single response. More...
 
void AddOtherResponse (const std::string &response)
 Add the free text given as "Other" option to the list of responses. More...
 
void RemoveOtherResponse ()
 Remove the "Other" response from the list of already given responses. More...
 
void SetOtherResponse (const std::string &response)
 Set the "Other" response as single exclusive response to this question. More...
 
- Protected Member Functions inherited from mitk::Forms::QuestionWithOptions
void AddResponse (size_t i)
 Add one of the possible answer options to the responses. More...
 
void RemoveResponse (size_t i)
 Remove one of the already given responses. More...
 

Detailed Description

Base class for questions with options that may also have a free text option.

This base class is an extension of QuestionWithOptions representing questions that may also have a free text option, typically labeled "Other" in forms/surveys.

Just like with QuestionWithOptions, depending on the exclusivity of the answer options, use using-declarations in derived classes to change the visibility of the respective protected member functions to public, i.e., SetOtherResponse() vs. AddOtherResponse() and RemoveOtherResponse().

Definition at line 31 of file mitkQuestionWithOtherOption.h.

Constructor & Destructor Documentation

◆ QuestionWithOtherOption()

mitk::Forms::QuestionWithOtherOption::QuestionWithOtherOption ( )

◆ ~QuestionWithOtherOption()

mitk::Forms::QuestionWithOtherOption::~QuestionWithOtherOption ( )
override

Member Function Documentation

◆ AddOtherResponse()

void mitk::Forms::QuestionWithOtherOption::AddOtherResponse ( const std::string &  response)
protected

Add the free text given as "Other" option to the list of responses.

Note
A question can only have a single "Other" response. Consequtive calls to this method will override the previously set "Other" response.

◆ ClearResponses()

void mitk::Forms::QuestionWithOtherOption::ClearResponses ( )
overridevirtual

Clear the/all response(s).

Reimplemented from mitk::Forms::QuestionWithOptions.

◆ EnableOtherOption()

void mitk::Forms::QuestionWithOtherOption::EnableOtherOption ( )

Switch on the "Other" option.

By default, a question does not have an "Other" option.

◆ GetResponsesAsStrings()

std::vector<std::string> mitk::Forms::QuestionWithOtherOption::GetResponsesAsStrings ( ) const
overridevirtual

Return the question's response(s) as strings.

This is the single common generic interface for retrieving responses from all types of questions. It is typically used to store responses in text-based formats like CSV.

It is implemented as vector since certain types of questions like a checkboxes question may support multiple responses. Otherwise, return a vector with a single element.

std::vector<std::string> RhetoricalQuestion::GetResponsesAsStrings() const
{
return { m_Response };
}

Reimplemented from mitk::Forms::QuestionWithOptions.

◆ HasOtherOption()

bool mitk::Forms::QuestionWithOtherOption::HasOtherOption ( ) const

Query whether this question actually has an "Other" option.

◆ IsComplete()

bool mitk::Forms::QuestionWithOtherOption::IsComplete ( ) const
overridevirtual

Check if a question is considered to be answered completely.

This method is typically called when IsRequired() returns true to determine whether the requirements are fulfilled.

Reimplemented from mitk::Forms::QuestionWithOptions.

◆ RemoveOtherResponse()

void mitk::Forms::QuestionWithOtherOption::RemoveOtherResponse ( )
protected

Remove the "Other" response from the list of already given responses.

◆ SetOtherResponse()

void mitk::Forms::QuestionWithOtherOption::SetOtherResponse ( const std::string &  response)
protected

Set the "Other" response as single exclusive response to this question.

◆ SetResponse()

void mitk::Forms::QuestionWithOtherOption::SetResponse ( size_t  i)
overrideprotectedvirtual

Set one of the possible answer options as the single response.

Note
This will remove any responses added by AddResponse().

Reimplemented from mitk::Forms::QuestionWithOptions.


The documentation for this class was generated from the following file: