Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::Forms::QuestionWithOptions Class Reference

Base class for questions with options to choose from as response. More...

#include <mitkQuestionWithOptions.h>

Inheritance diagram for mitk::Forms::QuestionWithOptions:
Collaboration diagram for mitk::Forms::QuestionWithOptions:

Public Member Functions

 ~QuestionWithOptions () override
 Virtual destructor. More...
 
std::vector< std::string > GetResponsesAsStrings () const override
 Return the selected options as strings. More...
 
void ClearResponses () override
 Clear all selected responses. More...
 
bool IsComplete () const override
 Check whether at least one option has been selected. More...
 
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
 Get all available options. More...
 
- Public Member Functions inherited from mitk::Forms::Question
 Question ()
 Default constructor. More...
 
virtual ~Question ()
 Virtual destructor. More...
 
std::string GetQuestionText () const
 Get the literal question text. More...
 
void SetQuestionText (const std::string &question)
 Set the literal question text. 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 response 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 Question * CreateAnother () 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 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...
 
virtual void SetResponse (size_t i)
 Set one of the possible answer options as the single response. More...
 

Detailed Description

Base class for questions with options to choose from as response.

This base class represents both, questions with mutually exclusive options as well as questions with multiple answer options. Derived classes should use using-declarations to change the visibility of the respective protected member functions to public, i.e., SetResponse() vs. AddResponse() and RemoveResponse().

Definition at line 28 of file mitkQuestionWithOptions.h.

Constructor & Destructor Documentation

◆ ~QuestionWithOptions()

mitk::Forms::QuestionWithOptions::~QuestionWithOptions ( )
override

Virtual destructor.

Member Function Documentation

◆ AddOption()

size_t mitk::Forms::QuestionWithOptions::AddOption ( const std::string &  option)

Add a non-exclusive option as possible answer to the question.

The option is appended to the list of already existing options.

Parameters
[in]optionThe option text.
Returns
The zero-based index of the newly added option.

◆ AddResponse()

void mitk::Forms::QuestionWithOptions::AddResponse ( size_t  i)
protected

Add one of the possible answer options to the responses.

Indexes to responses are inserted in ascending order.

Parameters
[in]iThe zero-based index of the option to add to responses.
See also
AddOption()

◆ ClearResponses()

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

Clear all selected responses.

Implements mitk::Forms::Question.

Reimplemented in mitk::Forms::QuestionWithOtherOption.

◆ GetOptions()

std::vector<std::string> mitk::Forms::QuestionWithOptions::GetOptions ( ) const

Get all available options.

Returns
A vector of option strings in the order they were added.

◆ GetResponsesAsStrings()

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

Return the selected options as strings.

The returned strings correspond to the option texts at the stored response indices, ordered in ascending index order.

Returns
A vector of selected option strings.

Implements mitk::Forms::Question.

Reimplemented in mitk::Forms::QuestionWithOtherOption.

◆ IsComplete()

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

Check whether at least one option has been selected.

Returns
true if at least one response index is stored, false otherwise.

Implements mitk::Forms::Question.

Reimplemented in mitk::Forms::QuestionWithOtherOption.

◆ RemoveResponse()

void mitk::Forms::QuestionWithOptions::RemoveResponse ( size_t  i)
protected

Remove one of the already given responses.

Parameters
[in]iThe zero-based index of the option to remove from responses.
See also
AddOption(), AddResponse()

◆ SetResponse()

virtual void mitk::Forms::QuestionWithOptions::SetResponse ( size_t  i)
protectedvirtual

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

Parameters
[in]iThe zero-based index of the option to set as sole response.
Note
This will remove any responses added by AddResponse().

Reimplemented in mitk::Forms::QuestionWithOtherOption.


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