25 #include <QJsonObject>
45 std::unique_ptr<SessionItem>
create_item(
const QJsonObject& json)
48 : std::unique_ptr<SessionItem>();
62 if (array.size() != container.
itemCount())
63 throw std::runtime_error(
"Error in JsonItemContainerConverter: size is different");
65 for (
const auto obj : array)
81 if (!container.
empty())
82 throw std::runtime_error(
83 "Error in JsonItemContainerConverter: container is not empty.");
106 throw std::runtime_error(
"Error in JsonItemContainerConverter: can't convert json");
123 QJsonArray itemArray;
124 for (
auto item : container)
125 itemArray.append(
p_impl->create_json(*item));
141 throw std::runtime_error(
"Error in JsonItemContainerConverter: given JSON can't represent "
142 "SessionItemContainer.");
148 throw std::runtime_error(
"Error in JsonItemContainerConverter: attempt to update "
149 "container from JSON representing another container.");
151 if (container.
empty())
152 p_impl->populate_container(json, container);
154 p_impl->update_container(json, container);
void from_json(const QJsonObject &json, SessionItemContainer &container)
Reconstructs SessionItemContainer from the content of JSON object.
~JsonItemContainerConverter()
std::unique_ptr< JsonItemContainerConverterImpl > p_impl
QJsonObject to_json(const SessionItemContainer &container)
JsonItemContainerConverter(ConverterCallbacks callbacks)
Holds collection of SessionItem objects related to the same tag.
bool insertItem(SessionItem *item, int index)
Inserts item in a vector of children at given index, returns true in the case of success.
int itemCount() const
Returns number of items in given tag.
SessionItem * itemAt(int index) const
Returns item at given index. Returns nullptr if index is invalid.
The main object representing an editable/displayable/serializable entity.
Holds info about single tag for SessionItem.
MVVM_MODEL_EXPORT bool IsCompatibleSinglePropertyTag(const SessionItemContainer &container, const TagInfo &taginfo)
Returns true if given TagInfo is a single property tag which is compatible with given container.
MVVM_MODEL_EXPORT bool IsCompatibleUniversalTag(const SessionItemContainer &container, const TagInfo &taginfo)
Returns true if given TagInfo is compatible with given container.
MVVM_MODEL_EXPORT bool IsCompatibleGroupTag(const SessionItemContainer &container, const TagInfo &taginfo)
Returns true if given TagInfo is a tag from GroupItem which is compatible with given container.
materialitems.h Collection of materials to populate MaterialModel.
void update_items(const QJsonObject &json, SessionItemContainer &container)
Update container from json content.
void populate_container(const QJsonObject &json, SessionItemContainer &container)
Populates container with content reconstructed from JSON object. Container must be empty.
void create_items(const QJsonObject &json, SessionItemContainer &container)
ConverterCallbacks m_converter_callbacks
void update_item(const QJsonObject &json, SessionItem *item)
QJsonObject create_json(const SessionItem &item)
JsonItemContainerConverterImpl(ConverterCallbacks callbacks={})
std::unique_ptr< SessionItem > create_item(const QJsonObject &json)
std::unique_ptr< JsonTagInfoConverterInterface > m_taginfo_converter
void update_container(const QJsonObject &json, SessionItemContainer &container)
Update container with content reconstructed from JSON object.
Provides necessary callbacks to convert SessionItem to JSON and back.
update_item_t m_update_item
creates new SessionItem from JSON object
create_item_t m_create_item
creates JSON object from session item
create_json_t m_create_json