21 #include <QJsonObject>
28 QJsonValue keyValue(
const QJsonValue& parent_value,
const QString& key)
30 const QJsonObject& parent_object = parent_value.toObject();
31 return parent_object.value(key);
37 : m_to_json_accept(to_json_accept)
38 , m_from_json_accept(from_json_accept)
49 for (
const auto& x : data) {
54 result.append(
object);
66 auto persistent_data = std::make_unique<SessionItemData>();
68 for (
const auto& x :
object) {
70 throw std::runtime_error(
"JsonItemData::get_data() -> Invalid json object.");
75 persistent_data->setData(variant, role);
78 auto runtime_roles = data.
roles();
79 auto persistent_roles = persistent_data->roles();
81 std::set<int> roles(runtime_roles.begin(), runtime_roles.end());
82 roles.insert(persistent_roles.begin(), persistent_roles.end());
84 for (
auto role : roles) {
86 if (persistent_data->hasData(role))
87 data.
setData(persistent_data->data(role), role);
95 return std::make_unique<JsonItemDataConverter>();
103 auto accept_roles = [](
auto role) {
106 return std::make_unique<JsonItemDataConverter>(accept_roles, accept_roles);
bool isRoleFromJson(int role) const
Returns true if given role should be parsed from json object.
void from_json(const QJsonArray &object, SessionItemData &data) override
Updates existing data with JSON content.
JsonItemDataConverter(accept_strategy_t to_json_accept={}, accept_strategy_t from_json_accept={})
std::function< bool(int)> accept_strategy_t
bool isRoleToJson(int role) const
Returns true if given role should be saved in json object.
static std::unique_ptr< JsonItemDataConverterInterface > createProjectConverter()
Creates JSON data converter intended for project saving.
QJsonArray to_json(const SessionItemData &data) override
Converts SessionItemData to JSON;.
~JsonItemDataConverter() override
static std::unique_ptr< JsonItemDataConverterInterface > createCopyConverter()
Creates JSON data converter intended for simple data copying. Nothing is filtered out.
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
Default converter between supported variants and json objects.
Handles data roles for SessionItem.
std::vector< int > roles() const
bool setData(const Variant &value, int role)
Sets the data for given role.
const int DATA
main data role
const int IDENTIFIER
unique identifier
materialitems.h Collection of materials to populate MaterialModel.