BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::JsonTagInfoConverter Class Reference

Default converter between TagInfo and json object. More...

Inheritance diagram for ModelView::JsonTagInfoConverter:
[legend]
Collaboration diagram for ModelView::JsonTagInfoConverter:
[legend]

Public Member Functions

TagInfo from_json (const QJsonObject &object) override
 
bool isTagInfo (const QJsonObject &object)
 Returns true if given json object represents TagInfo object. More...
 
QJsonObject to_json (const TagInfo &tag) override
 

Static Public Attributes

static const QString maxKey = "max"
 
static const QString minKey = "min"
 
static const QString modelsKey = "models"
 
static const QString nameKey = "name"
 

Detailed Description

Default converter between TagInfo and json object.

Definition at line 25 of file jsontaginfoconverter.h.

Member Function Documentation

◆ from_json()

TagInfo JsonTagInfoConverter::from_json ( const QJsonObject &  object)
overridevirtual

Implements ModelView::JsonTagInfoConverterInterface.

Definition at line 49 of file jsontaginfoconverter.cpp.

50 {
51  if (!isTagInfo(object))
52  throw std::runtime_error("JsonTagInfo::get_tags() -> Invalid json object.");
53 
54  auto name = object[nameKey].toString().toStdString();
55  auto min = object[minKey].toInt();
56  auto max = object[maxKey].toInt();
57  std::vector<std::string> models;
58  for (const auto ref : object[modelsKey].toArray())
59  models.push_back(ref.toString().toStdString());
60 
61  return TagInfo(name, min, max, models);
62 }
bool isTagInfo(const QJsonObject &object)
Returns true if given json object represents TagInfo object.
Holds info about single tag for SessionItem.
Definition: taginfo.h:28
QString const & name(EShape k)
Definition: particles.cpp:21

References isTagInfo(), maxKey, minKey, modelsKey, RealSpace::Particles::name(), and nameKey.

Referenced by TEST_F().

Here is the call graph for this function:

◆ isTagInfo()

bool JsonTagInfoConverter::isTagInfo ( const QJsonObject &  object)

Returns true if given json object represents TagInfo object.

Definition at line 66 of file jsontaginfoconverter.cpp.

67 {
68  static const QStringList expected = expected_taginfo_keys();
69 
70  if (object.keys() != expected)
71  return false;
72 
73  if (!object[modelsKey].isArray())
74  return false;
75 
76  return true;
77 }

References modelsKey.

Referenced by from_json(), and TEST_F().

◆ to_json()

QJsonObject JsonTagInfoConverter::to_json ( const TagInfo tag)
overridevirtual

Implements ModelView::JsonTagInfoConverterInterface.

Definition at line 35 of file jsontaginfoconverter.cpp.

36 {
37  QJsonObject result;
38  result[nameKey] = QString::fromStdString(tag.name());
39  result[minKey] = tag.min();
40  result[maxKey] = tag.max();
41  QJsonArray str_array;
42  for (const auto& str : tag.modelTypes())
43  str_array.append(QString::fromStdString(str));
44  result[modelsKey] = str_array;
45 
46  return result;
47 }
std::string name() const
Definition: taginfo.cpp:45
int max() const
Definition: taginfo.cpp:55
std::vector< std::string > modelTypes() const
Definition: taginfo.cpp:60
int min() const
Definition: taginfo.cpp:50

References ModelView::TagInfo::max(), maxKey, ModelView::TagInfo::min(), minKey, modelsKey, ModelView::TagInfo::modelTypes(), ModelView::TagInfo::name(), and nameKey.

Referenced by TEST_F().

Here is the call graph for this function:

Member Data Documentation

◆ maxKey

const QString ModelView::JsonTagInfoConverter::maxKey = "max"
inlinestatic

Definition at line 29 of file jsontaginfoconverter.h.

Referenced by from_json(), TEST_F(), and to_json().

◆ minKey

const QString ModelView::JsonTagInfoConverter::minKey = "min"
inlinestatic

Definition at line 28 of file jsontaginfoconverter.h.

Referenced by from_json(), TEST_F(), and to_json().

◆ modelsKey

const QString ModelView::JsonTagInfoConverter::modelsKey = "models"
inlinestatic

Definition at line 30 of file jsontaginfoconverter.h.

Referenced by from_json(), isTagInfo(), TEST_F(), and to_json().

◆ nameKey

const QString ModelView::JsonTagInfoConverter::nameKey = "name"
inlinestatic

Definition at line 27 of file jsontaginfoconverter.h.

Referenced by from_json(), TEST_F(), and to_json().


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