23 #include <QJsonObject>
39 throw std::runtime_error(
"Error in JsonModelConverter: unknown converter mode");
53 throw std::runtime_error(
"JsonModel::to_json() -> Error. Model is not initialized.");
59 auto itemConverter = CreateConverter(model.
factory(),
m_mode);
62 itemArray.append(itemConverter->to_json(item));
72 throw std::runtime_error(
"JsonModel::json_to_model() -> Error. Model is not initialized.");
76 throw std::runtime_error(
"JsonModel::json_to_model() -> Error. Invalid json object.");
79 != QString::fromStdString(model.
modelType()))
80 throw std::runtime_error(
81 "JsonModel::json_to_model() -> Unexpected model type '" + model.
modelType()
85 auto itemConverter = CreateConverter(model.
factory(),
m_mode);
87 auto rebuild_root = [&json, &itemConverter](
auto parent) {
89 auto item = itemConverter->from_json(ref.toObject());
93 model.
clear(rebuild_root);
Interface class for all factories capable of producing SessionItem's.
~JsonModelConverter() override
JsonModelConverter(ConverterMode mode)
void from_json(const QJsonObject &json, SessionModel &model) const override
Reads json object and build the model.
QJsonObject to_json(const SessionModel &model) const override
Writes content of model into json.
std::vector< SessionItem * > children() const
Returns vector of children formed from all chidlren from all tags.
Main class to hold hierarchy of SessionItem objects.
std::string modelType() const
Returns model type.
const ItemFactoryInterface * factory() const
Returns item factory which can generate all items supported by this model.
SessionItem * rootItem() const
Returns root item of the model.
void clear(std::function< void(SessionItem *)> callback={})
Removes all items from the model.
static TagRow append(const std::string &tag_name={})
Returns TagRow corresponding to the append to tag_name.
materialitems.h Collection of materials to populate MaterialModel.
std::unique_ptr< JsonItemConverterInterface > CreateItemProjectConverter(const ItemFactoryInterface *item_factory)
Creates JSON item converter intended for saving on disk.
std::unique_ptr< JsonItemConverterInterface > CreateItemCopyConverter(const ItemFactoryInterface *item_factory)
Creates JSON item converter intended for item copying.
ConverterMode
Flags to define converter behavior on the way from SessionItem to JSON and back.
@ copy
full deep copying with item identifiers regenerated
@ project
selective copying for saving/loading the project (tags and data created by item, updated from JSON)
@ clone
full deep copying with item identifiers preserved
std::unique_ptr< JsonItemConverterInterface > CreateItemCloneConverter(const ItemFactoryInterface *item_factory)
Creates JSON item converter intended for item cloning.
std::string toString(PyObject *obj)
Converts PyObject into string, if possible, or throws exception.