Medical Imaging Interaction Toolkit
2024.12.99-0da743f6
Medical Imaging Interaction Toolkit
|
A Question whose possible responses are represented by a discrete linear scale. More...
#include <mitkLinearScaleQuestion.h>
Public Member Functions | |
LinearScaleQuestion () | |
~LinearScaleQuestion () override | |
std::string | GetType () const override |
Return the type of a question as string, e.g. "Multiple choice" or "Drop-down". More... | |
Question * | CreateAnother () const override |
Create a new instance of the derived question class type. More... | |
void | FromJSON (const nlohmann::ordered_json &j) override |
Deserialize from JSON. More... | |
void | ToJSON (nlohmann::ordered_json &j) const override |
Serialize to JSON. More... | |
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... | |
std::optional< int > | GetResponse () const |
void | SetResponse (int response) |
std::pair< int, int > | GetRange () const |
void | SetRange (const std::pair< int, int > &range) |
Set the allowed range of numbers for a valid response. More... | |
std::pair< std::string, std::string > | GetRangeLabels () const |
void | SetRangeLabels (const std::pair< std::string, std::string > &labels) |
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... | |
A Question whose possible responses are represented by a discrete linear scale.
The question can have a single response, which is one of the numbers within the allowed range. The range must start with 0 or 1 and end with any number between 2 and 10 (1 to 5 by default).
Definition at line 28 of file mitkLinearScaleQuestion.h.
mitk::Forms::LinearScaleQuestion::LinearScaleQuestion | ( | ) |
|
override |
|
overridevirtual |
Clear the/all response(s).
Implements mitk::Forms::Question.
|
overridevirtual |
Create a new instance of the derived question class type.
This method is mainly used by IQuestionFactory to create new instances from registered prototype instances based on a type string.
Implements mitk::Forms::Question.
|
overridevirtual |
Deserialize from JSON.
Polymorphism and the use of base class pointers make it necessary to implement serialization through member functions. Using the pure native approach of the "JSON for Modern C++" library via free functions would lead to partially serialized instances of derived classes.
The actual implementation can and should still be located in a corresponding from_json() free function but we also need the indirection through this member function.
Implements mitk::Forms::Question.
std::pair<int, int> mitk::Forms::LinearScaleQuestion::GetRange | ( | ) | const |
std::pair<std::string, std::string> mitk::Forms::LinearScaleQuestion::GetRangeLabels | ( | ) | const |
std::optional<int> mitk::Forms::LinearScaleQuestion::GetResponse | ( | ) | 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.
Implements mitk::Forms::Question.
|
overridevirtual |
Return the type of a question as string, e.g. "Multiple choice" or "Drop-down".
This method is essential for the deserialization of questions into their correct type, resp. derived class. The type string is used by IQuestionFactory to look up a registered prototype instance of a certain type to create another instance of it.
The type string does not have to match the class name or follow any other convention except for it must be unique amongst all question types. Prefer natural language like in the examples above in case it is used in a user interface to display a question's type.
Implements mitk::Forms::Question.
|
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.
Implements mitk::Forms::Question.
void mitk::Forms::LinearScaleQuestion::SetRange | ( | const std::pair< int, int > & | range | ) |
Set the allowed range of numbers for a valid response.
A valid range must start with 0 or 1 and end with any number between 2 and 10 (1 to 5 by default).
Exception | Invalid range. |
void mitk::Forms::LinearScaleQuestion::SetRangeLabels | ( | const std::pair< std::string, std::string > & | labels | ) |
void mitk::Forms::LinearScaleQuestion::SetResponse | ( | int | response | ) |
|
overridevirtual |
Serialize to JSON.
Polymorphism and the use of base class pointers make it necessary to implement serialization through member functions. Using the pure native approach of the "JSON for Modern C++" library via free functions would lead to partially serialized instances of derived classes.
The actual implementation can and should still be located in a corresponding to_json() free function but we also need the indirection through this member function.
Implements mitk::Forms::Question.