Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkForm.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 mitkForm_h
14 #define mitkForm_h
15 
16 #include <mitkFileSystem.h>
17 #include <MitkFormsExports.h>
18 
19 #include <memory>
20 #include <string>
21 #include <map>
22 #include <vector>
23 
24 #include <nlohmann/json_fwd.hpp>
25 
26 namespace mitk::Forms
27 {
28  class Question;
29 
41  {
42  public:
51  {
52  public:
58  explicit Section(const std::string& title = "", const std::string& description = "");
59 
63 
66  Section(Section&& other) noexcept;
67 
70  Section& operator=(Section&& other) noexcept;
71 
76  std::string GetTitle() const;
77 
82  void SetTitle(const std::string& title);
83 
88  std::string GetDescription() const;
89 
94  void SetDescription(const std::string& description);
95 
100  std::vector<Question*> GetQuestions() const;
101 
108  void AddQuestion(Question* question);
109 
110  private:
111  std::string m_Title;
112  std::string m_Description;
113  std::vector<std::unique_ptr<Question>> m_Questions;
114  };
115 
123  explicit Form(const std::string& title = "", const std::string& description = "");
124 
127  ~Form();
128 
131  Form(Form&& other) noexcept;
132 
135  Form& operator=(Form&& other) noexcept;
136 
143  Section& AddSection(const std::string& title = "", const std::string& description = "");
144 
149  int GetNumberOfSections() const;
150 
157  Section& GetSection(int index);
158 
165  const Section& GetSection(int index) const;
166 
171  std::string GetTitle() const;
172 
177  void SetTitle(const std::string& title);
178 
183  std::string GetDescription() const;
184 
189  void SetDescription(const std::string& description);
190 
195  std::vector<Question*> GetQuestions() const;
196 
203  void AddQuestion(Question* question);
204 
221  void AddSupplement(const std::string& key);
222 
231  bool SetSupplement(const std::string& key, const std::string& value);
232 
239  const std::map<std::string, std::string>& GetSupplements() const;
240 
243  std::vector<Section>::const_iterator begin() const;
244 
247  std::vector<Section>::const_iterator end() const;
248 
251  std::vector<Section>::iterator begin();
252 
255  std::vector<Section>::iterator end();
256 
257  private:
258  std::vector<Section> m_Sections;
259  std::map<std::string, std::string> m_Supplements;
260  };
261 
278  MITKFORMS_EXPORT void SubmitToCSV(const Form& form, const fs::path& csvPath);
279 
292  MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json& j, Form& f);
293 
301  MITKFORMS_EXPORT void to_json(nlohmann::ordered_json& j, const Form& f);
302 }
303 
304 #endif
#define MITKFORMS_EXPORT
A section within a Form, grouping related questions together.
Definition: mitkForm.h:51
std::vector< Question * > GetQuestions() const
Get all questions belonging to this section.
void AddQuestion(Question *question)
Add a question to this section.
Section(Section &&other) noexcept
Move constructor.
std::string GetTitle() const
Get the title of this section.
void SetDescription(const std::string &description)
Set the description of this section.
Section(const std::string &title="", const std::string &description="")
Construct a section with optional title and description.
void SetTitle(const std::string &title)
Set the title of this section.
Section & operator=(Section &&other) noexcept
Move assignment operator.
std::string GetDescription() const
Get the description of this section.
A form consisting of questions possibly divided into multiple sections/pages.
Definition: mitkForm.h:41
std::vector< Section >::iterator begin()
Get an iterator to the first section (for range-based for loops).
Section & GetSection(int index)
Get a section by its index.
std::vector< Section >::const_iterator begin() const
Get a const iterator to the first section (for range-based for loops).
std::vector< Question * > GetQuestions() const
Convenience method to get all questions from the first section.
void SetDescription(const std::string &description)
Convenience method to set the description of the first section (the form description).
Form(const std::string &title="", const std::string &description="")
Construct a form with an optional title and description for its first section.
const std::map< std::string, std::string > & GetSupplements() const
Get all supplements as a key-value map.
std::vector< Section >::const_iterator end() const
Get a const iterator past the last section (for range-based for loops).
~Form()
Destructor.
Section & AddSection(const std::string &title="", const std::string &description="")
Add a new section to the form.
void AddQuestion(Question *question)
Convenience method to add a question to the first section.
const Section & GetSection(int index) const
Get a section by its index (const overload).
bool SetSupplement(const std::string &key, const std::string &value)
Set the value of a certain existing supplement.
Form & operator=(Form &&other) noexcept
Move assignment operator.
void AddSupplement(const std::string &key)
Add extra data that is submitted together with the responses.
std::vector< Section >::iterator end()
Get an iterator past the last section (for range-based for loops).
std::string GetDescription() const
Convenience method to get the description of the first section (the form description).
void SetTitle(const std::string &title)
Convenience method to set the title of the first section (the form title).
Form(Form &&other) noexcept
Move constructor.
std::string GetTitle() const
Convenience method to get the title of the first section (the form title).
int GetNumberOfSections() const
Get the total number of sections in this form.
Abstract base class for all types of questions used in a Form.
Definition: mitkQuestion.h:38
Portability header that provides a unified namespace alias for the C++ filesystem library.
MITKFORMS_EXPORT void to_json(nlohmann::ordered_json &j, const CheckboxesQuestion &q)
Serialize a CheckboxesQuestion to JSON.
MITKFORMS_EXPORT void SubmitToCSV(const Form &form, const fs::path &csvPath)
Submit form responses to a CSV file.
MITKFORMS_EXPORT void from_json(const nlohmann::ordered_json &j, CheckboxesQuestion &q)
Deserialize a CheckboxesQuestion from JSON.