34 auto factory_func = [parent]() {
37 return std::make_unique<InsertNewItemCommand>(factory_func, parent,
TagRow{tag, row});
50 auto command = create_command(model.
rootItem(),
"", 0);
55 EXPECT_EQ(std::get<SessionItem*>(command->result()), model.
rootItem()->
getItem(
"", 0));
56 EXPECT_EQ(command->isObsolete(),
false);
61 EXPECT_EQ(std::get<SessionItem*>(command->result()),
nullptr);
62 EXPECT_EQ(command->isObsolete(),
false);
67 EXPECT_EQ(std::get<SessionItem*>(command->result()), model.
rootItem()->
getItem(
"", 0));
68 EXPECT_EQ(command->isObsolete(),
false);
78 auto command1 = create_command(model.
rootItem(),
"", 0);
80 EXPECT_EQ(command1->isObsolete(),
false);
82 auto parent = std::get<SessionItem*>(command1->result());
84 EXPECT_EQ(parent->childrenCount(), 0);
87 auto command2 = create_command(parent,
"tag1", 0);
89 EXPECT_EQ(command2->isObsolete(),
false);
91 EXPECT_EQ(parent->childrenCount(), 1);
92 EXPECT_EQ(
Utils::ChildAt(parent, 0), std::get<SessionItem*>(command2->result()));
96 EXPECT_EQ(parent->childrenCount(), 0);
97 EXPECT_EQ(
nullptr, std::get<SessionItem*>(command2->result()));
98 EXPECT_EQ(command2->isObsolete(),
false);
107 auto command = create_command(model.
rootItem(),
"", 0);
111 EXPECT_THROW(command->execute(), std::runtime_error);
121 auto command = create_command(model.
rootItem(),
"", 0);
126 EXPECT_THROW(command->undo(), std::runtime_error);
138 auto factory_func = [parent]() {
144 EXPECT_NO_THROW(command1.execute());
145 EXPECT_FALSE(command1.isObsolete());
146 EXPECT_EQ(std::get<SessionItem*>(command1.result()), parent->getItem(
"radius"));
150 EXPECT_NO_THROW(command2.execute());
151 EXPECT_TRUE(command2.isObsolete());
152 EXPECT_EQ(std::get<SessionItem*>(command2.result()),
nullptr);
155 EXPECT_THROW(command2.undo(), std::runtime_error);
189 auto pool = std::make_shared<ItemPool>();
195 EXPECT_EQ(pool->size(), 1);
202 EXPECT_EQ(pool->size(), 2);
210 EXPECT_EQ(restored_item->identifier(), orig_identifier);
211 EXPECT_EQ(model.
findItem(orig_identifier), restored_item);
212 EXPECT_EQ(pool->item_for_key(orig_identifier), restored_item);
std::unique_ptr< InsertNewItemCommand > create_command(SessionItem *parent, std::string tag, int row)
~InsertNewItemCommandTest()
void undo()
Undo command as it was before execution.
void execute()
Execute command.
Complex item holding mixed SessionItem types (single properties and other CompountItems).
Command for unddo/redo to insert new item.
virtual std::unique_ptr< SessionItem > createItem(const model_type &modelType) const =0
The main object representing an editable/displayable/serializable entity.
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.
void registerTag(const TagInfo &tagInfo, bool set_as_default=false)
Registers tag to hold items under given name.
SessionModel * model() const
Returns the model to which given item belongs to.
int childrenCount() const
Returns total number of children in all tags.
std::vector< SessionItem * > children() const
Returns vector of children formed from all chidlren from all tags.
Main class to hold hierarchy of SessionItem objects.
SessionItem * findItem(const identifier_type &id)
Returns SessionItem for given identifier.
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.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
static TagInfo universalTag(std::string name, std::vector< std::string > modelTypes={})
Constructs universal tag intended for unlimited amount of various items.
static TagInfo propertyTag(std::string name, std::string model_type)
Constructs tag intended for single property.
Aggregate to hold (tag, row) information for SessionModel.
TEST_F(InsertNewItemCommandTest, insertNewItemCommand)
Insert new item through InsertNewItemCommand command.
const model_type PropertyType
const model_type BaseType
MVVM_MODEL_EXPORT SessionItem * ChildAt(const SessionItem *parent, int index)
Returns child at given index of parent.
materialitems.h Collection of materials to populate MaterialModel.