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

A form consisting of questions possibly divided into multiple sections/pages. More...

#include <mitkForm.h>

Classes

class  Section
 A section within a Form, grouping related questions together. More...
 

Public Member Functions

 Form (const std::string &title="", const std::string &description="")
 Construct a form with an optional title and description for its first section. More...
 
 ~Form ()
 Destructor. More...
 
 Form (Form &&other) noexcept
 Move constructor. More...
 
Form & operator= (Form &&other) noexcept
 Move assignment operator. More...
 
Section & AddSection (const std::string &title="", const std::string &description="")
 Add a new section to the form. More...
 
int GetNumberOfSections () const
 Get the total number of sections in this form. More...
 
Section & GetSection (int index)
 Get a section by its index. More...
 
const Section & GetSection (int index) const
 Get a section by its index (const overload). More...
 
std::string GetTitle () const
 Convenience method to get the title of the first section (the form title). More...
 
void SetTitle (const std::string &title)
 Convenience method to set the title of the first section (the form title). More...
 
std::string GetDescription () const
 Convenience method to get the description of the first section (the form description). More...
 
void SetDescription (const std::string &description)
 Convenience method to set the description of the first section (the form description). More...
 
std::vector< Question * > GetQuestions () const
 Convenience method to get all questions from the first section. More...
 
void AddQuestion (Question *question)
 Convenience method to add a question to the first section. More...
 
void AddSupplement (const std::string &key)
 Add extra data that is submitted together with the responses. More...
 
bool SetSupplement (const std::string &key, const std::string &value)
 Set the value of a certain existing supplement. More...
 
const std::map< std::string, std::string > & GetSupplements () const
 Get all supplements as a key-value map. More...
 
std::vector< Section >::const_iterator begin () const
 Get a const iterator to the first section (for range-based for loops). More...
 
std::vector< Section >::const_iterator end () const
 Get a const iterator past the last section (for range-based for loops). More...
 
std::vector< Section >::iterator begin ()
 Get an iterator to the first section (for range-based for loops). More...
 
std::vector< Section >::iterator end ()
 Get an iterator past the last section (for range-based for loops). More...
 

Detailed Description

A form consisting of questions possibly divided into multiple sections/pages.

A form always has at least a single section, which is also used to define the form's general title and description. Helper methods like SetTitle() or SetDescription() can be used to conveniently set these properties of the first section.

Forms can be serialized to and deserialized from JSON and submitted to CSV files.

See also
Question, SubmitToCSV()

Definition at line 40 of file mitkForm.h.

Constructor & Destructor Documentation

◆ Form() [1/2]

mitk::Forms::Form::Form ( const std::string &  title = "",
const std::string &  description = "" 
)
explicit

Construct a form with an optional title and description for its first section.

A form always starts with at least one section.

Parameters
[in]titleThe form title (stored as the first section's title).
[in]descriptionThe form description (stored as the first section's description).

◆ ~Form()

mitk::Forms::Form::~Form ( )

Destructor.

◆ Form() [2/2]

mitk::Forms::Form::Form ( Form &&  other)
noexcept

Move constructor.

Member Function Documentation

◆ AddQuestion()

void mitk::Forms::Form::AddQuestion ( Question *  question)

Convenience method to add a question to the first section.

The first section takes ownership of the pointer.

Parameters
[in]questionA pointer to the question to add. Ownership is transferred.

◆ AddSection()

Section& mitk::Forms::Form::AddSection ( const std::string &  title = "",
const std::string &  description = "" 
)

Add a new section to the form.

Parameters
[in]titleThe title of the new section.
[in]descriptionThe description of the new section.
Returns
A reference to the newly added section.

◆ AddSupplement()

void mitk::Forms::Form::AddSupplement ( const std::string &  key)

Add extra data that is submitted together with the responses.

Supplements are a rudimentary and delicate feature to add extra data to submissions, i.e., extra columns for CSV submissions.

Supplements are key-value pairs supposed to be completely set up before the first submission. Afterwards, do not add any new supplements. Values of existing supplements can be safely modified, though.

If a supplement with the given key already exists, the call has no effect.

Parameters
[in]keyThe key (column header) for the supplement.
Note
Do not add new supplements after the first submission.
Submissions do not clear any supplements or their values.

◆ begin() [1/2]

std::vector<Section>::iterator mitk::Forms::Form::begin ( )

Get an iterator to the first section (for range-based for loops).

◆ begin() [2/2]

std::vector<Section>::const_iterator mitk::Forms::Form::begin ( ) const

Get a const iterator to the first section (for range-based for loops).

◆ end() [1/2]

std::vector<Section>::iterator mitk::Forms::Form::end ( )

Get an iterator past the last section (for range-based for loops).

◆ end() [2/2]

std::vector<Section>::const_iterator mitk::Forms::Form::end ( ) const

Get a const iterator past the last section (for range-based for loops).

◆ GetDescription()

std::string mitk::Forms::Form::GetDescription ( ) const

Convenience method to get the description of the first section (the form description).

Returns
The form description.

◆ GetNumberOfSections()

int mitk::Forms::Form::GetNumberOfSections ( ) const

Get the total number of sections in this form.

Returns
The number of sections (always at least 1).

◆ GetQuestions()

std::vector<Question*> mitk::Forms::Form::GetQuestions ( ) const

Convenience method to get all questions from the first section.

Returns
A vector of non-owning pointers to the questions in the first section.

◆ GetSection() [1/2]

Section& mitk::Forms::Form::GetSection ( int  index)

Get a section by its index.

Parameters
[in]indexThe zero-based section index.
Returns
A reference to the requested section.
Exceptions
std::out_of_rangeIf index is out of bounds.

◆ GetSection() [2/2]

const Section& mitk::Forms::Form::GetSection ( int  index) const

Get a section by its index (const overload).

Parameters
[in]indexThe zero-based section index.
Returns
A const reference to the requested section.
Exceptions
std::out_of_rangeIf index is out of bounds.

◆ GetSupplements()

const std::map<std::string, std::string>& mitk::Forms::Form::GetSupplements ( ) const

Get all supplements as a key-value map.

Returns
A const reference to the internal supplements map.
See also
AddSupplement(), SetSupplement()

◆ GetTitle()

std::string mitk::Forms::Form::GetTitle ( ) const

Convenience method to get the title of the first section (the form title).

Returns
The form title.

◆ operator=()

Form& mitk::Forms::Form::operator= ( Form &&  other)
noexcept

Move assignment operator.

◆ SetDescription()

void mitk::Forms::Form::SetDescription ( const std::string &  description)

Convenience method to set the description of the first section (the form description).

Parameters
[in]descriptionThe form description.

◆ SetSupplement()

bool mitk::Forms::Form::SetSupplement ( const std::string &  key,
const std::string &  value 
)

Set the value of a certain existing supplement.

Parameters
[in]keyThe key of the supplement to update.
[in]valueThe new value for the supplement.
Returns
true if the supplement exists and was updated, false otherwise.
See also
AddSupplement()

◆ SetTitle()

void mitk::Forms::Form::SetTitle ( const std::string &  title)

Convenience method to set the title of the first section (the form title).

Parameters
[in]titleThe form title.

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