35 return std::make_unique<JsonItemCopyStrategy>(m_factory.get());
47 auto strategy = createCopyStrategy();
52 auto copy = strategy->createCopy(&item);
55 EXPECT_EQ(item.
data<QVariant>(),
copy->data<QVariant>());
63 auto strategy = createCopyStrategy();
66 auto property = item.
addProperty(
"thickness", 42.0);
68 auto copy = strategy->createCopy(&item);
71 EXPECT_EQ(
copy->getItem(
"thickness")->data<
double>(), property->data<
double>());
72 EXPECT_FALSE(
copy->getItem(
"thickness")->identifier() == property->identifier());
80 auto strategy = createCopyStrategy();
85 auto parent = std::make_unique<SessionItem>(
model_type);
86 parent->setDisplayName(
"parent_name");
89 child->setDisplayName(
"child_name");
93 auto parent_copy = strategy->createCopy(parent.get());
95 EXPECT_EQ(parent_copy->childrenCount(), 1);
96 EXPECT_EQ(parent_copy->modelType(),
model_type);
97 EXPECT_EQ(parent_copy->displayName(),
"parent_name");
98 EXPECT_EQ(parent_copy->itemTags()->defaultTag(),
"defaultTag");
99 EXPECT_EQ(parent_copy->model(),
nullptr);
100 EXPECT_FALSE(parent_copy->identifier() == parent->identifier());
103 auto child_copy = parent_copy->getItem(
"defaultTag");
104 EXPECT_EQ(child_copy->parent(), parent_copy.get());
105 EXPECT_EQ(child_copy->childrenCount(), 0);
106 EXPECT_EQ(child_copy->modelType(),
model_type);
107 EXPECT_EQ(child_copy->displayName(),
"child_name");
108 EXPECT_EQ(child_copy->itemTags()->defaultTag(),
"");
109 EXPECT_FALSE(child_copy->identifier() == child->identifier());
~JsonItemCopyStrategyTest()
JsonItemCopyStrategyTest()
std::unique_ptr< JsonItemCopyStrategy > createCopyStrategy()
std::unique_ptr< ItemFactory > m_factory
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(JsonItemCopyStrategyTest, propertyItem)
Saving/restoring PropertyItem.
const model_type BaseType
materialitems.h Collection of materials to populate MaterialModel.
@ copy
full deep copying with item identifiers regenerated
MVVM_MODEL_EXPORT std::unique_ptr< ItemCatalogue > CreateStandardItemCatalogue()
Creates a catalog of items supported by SessionModel out-of-the-box.