35 return std::make_unique<JsonItemBackupStrategy>(m_factory.get());
47 auto strategy = createBackupStrategy();
52 strategy->saveItem(&item);
53 auto restored = strategy->restoreItem();
55 EXPECT_EQ(item.
modelType(), restored->modelType());
56 EXPECT_EQ(item.
identifier(), restored->identifier());
57 EXPECT_EQ(item.
data<QVariant>(), restored->data<QVariant>());
64 auto strategy = createBackupStrategy();
67 auto property = item.
addProperty(
"thickness", 42.0);
69 strategy->saveItem(&item);
70 auto restored = strategy->restoreItem();
72 EXPECT_EQ(item.
modelType(), restored->modelType());
73 EXPECT_EQ(item.
identifier(), restored->identifier());
74 EXPECT_EQ(restored->getItem(
"thickness")->data<
double>(), property->data<
double>());
75 EXPECT_EQ(restored->getItem(
"thickness")->identifier(), property->identifier());
82 auto strategy = createBackupStrategy();
87 auto parent = std::make_unique<SessionItem>(
model_type);
88 parent->setDisplayName(
"parent_name");
91 child->setDisplayName(
"child_name");
95 strategy->saveItem(parent.get());
96 auto reco_parent = strategy->restoreItem();
98 EXPECT_EQ(reco_parent->childrenCount(), 1);
99 EXPECT_EQ(reco_parent->modelType(),
model_type);
100 EXPECT_EQ(reco_parent->displayName(),
"parent_name");
101 EXPECT_EQ(reco_parent->identifier(), parent->identifier());
102 EXPECT_EQ(reco_parent->itemTags()->defaultTag(),
"defaultTag");
103 EXPECT_EQ(reco_parent->model(),
nullptr);
106 auto reco_child = reco_parent->getItem(
"defaultTag");
107 EXPECT_EQ(reco_child->parent(), reco_parent.get());
108 EXPECT_EQ(reco_child->childrenCount(), 0);
109 EXPECT_EQ(reco_child->modelType(),
model_type);
110 EXPECT_EQ(reco_child->displayName(),
"child_name");
111 EXPECT_EQ(reco_child->identifier(), child->identifier());
112 EXPECT_EQ(reco_child->itemTags()->defaultTag(),
"");
std::unique_ptr< JsonItemBackupStrategy > createBackupStrategy()
std::unique_ptr< ItemFactory > m_factory
JsonItemBackupStrategyTest()
~JsonItemBackupStrategyTest()
Complex item holding mixed SessionItem types (single properties and other CompountItems).
T * addProperty(const std::string &name)
Adds property item of given type.
Item to carry concrete editable entity (e.g.
The main object representing an editable/displayable/serializable entity.
std::string identifier() const
Returns unique identifier.
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
model_type modelType() const
Returns item's model type.
static TagInfo universalTag(std::string name, std::vector< std::string > modelTypes={})
Constructs universal tag intended for unlimited amount of various items.
static TagRow append(const std::string &tag_name={})
Returns TagRow corresponding to the append to tag_name.
TEST_F(JsonItemBackupStrategyTest, propertyItem)
Saving/restoring PropertyItem.
const model_type BaseType
materialitems.h Collection of materials to populate MaterialModel.
MVVM_MODEL_EXPORT std::unique_ptr< ItemCatalogue > CreateStandardItemCatalogue()
Creates a catalog of items supported by SessionModel out-of-the-box.