BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
jsonitemdataconverter.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/serialization/jsonitemdataconverter.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_SERIALIZATION_JSONITEMDATACONVERTER_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_SERIALIZATION_JSONITEMDATACONVERTER_H
17 
19 #include <QString>
20 #include <functional>
21 #include <memory>
22 
23 class QJsonObject;
24 
25 namespace ModelView {
26 
27 class JsonVariantConverterInterface;
28 
29 //! Default converter of SessionItemData to/from json object.
30 
31 class MVVM_MODEL_EXPORT JsonItemDataConverter : public JsonItemDataConverterInterface {
32 public:
33  using accept_strategy_t = std::function<bool(int)>;
34 
35  JsonItemDataConverter(accept_strategy_t to_json_accept = {},
36  accept_strategy_t from_json_accept = {});
37 
39 
40  QJsonArray to_json(const SessionItemData& data) override;
41 
42  void from_json(const QJsonArray& object, SessionItemData& data) override;
43 
44  static std::unique_ptr<JsonItemDataConverterInterface> createCopyConverter();
45 
46  static std::unique_ptr<JsonItemDataConverterInterface> createProjectConverter();
47 
48 private:
49  bool isRoleToJson(int role) const;
50  bool isRoleFromJson(int role) const;
51 
52  accept_strategy_t m_to_json_accept; //!< callback to find whether to write role to json
53  accept_strategy_t m_from_json_accept; //!< callback to find whether to read role from json
54  std::unique_ptr<JsonVariantConverterInterface> m_variant_converter;
55 };
56 
57 } // namespace ModelView
58 
59 #endif // BORNAGAIN_MVVM_MODEL_MVVM_SERIALIZATION_JSONITEMDATACONVERTER_H
Base class for all converters of SessionItemData to/from JSON object.
Default converter of SessionItemData to/from json object.
std::function< bool(int)> accept_strategy_t
std::unique_ptr< JsonVariantConverterInterface > m_variant_converter
accept_strategy_t m_from_json_accept
callback to find whether to read role from json
accept_strategy_t m_to_json_accept
callback to find whether to write role to json
Handles data roles for SessionItem.
materialitems.h Collection of materials to populate MaterialModel.