Skip to content

Commit

Permalink
Remove obsolete SessionItem::insertItem in a few places
Browse files Browse the repository at this point in the history
  • Loading branch information
gpospelov committed Feb 17, 2021
1 parent 34ce9d1 commit d9273fd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
14 changes: 14 additions & 0 deletions source/libmvvm_model/mvvm/commands/insertnewitemcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ void InsertNewItemCommand::undo_command()

void InsertNewItemCommand::execute_command()
{
// auto parent = itemFromPath(p_impl->item_path);
// if (auto child = parent->insertItem(p_impl->factory_func(), p_impl->tagrow); child) {
// // here we restore original identifier to get exactly same item on consequitive
// undo/redo if (!p_impl->initial_identifier.empty())
// child->setData(QVariant::fromValue(p_impl->initial_identifier),
// ItemDataRole::IDENTIFIER,
// /*direct*/ true);
// setDescription(generate_description(child->modelType(), p_impl->tagrow));
// setResult(child);
// }
// else {
// setObsolete(true);
// }

auto parent = itemFromPath(p_impl->item_path);
auto child = p_impl->factory_func().release();
// here we restore original identifier to get exactly same item on consequitive undo/redo
Expand Down
3 changes: 1 addition & 2 deletions source/libmvvm_model/mvvm/commands/removeitemcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ void RemoveItemCommand::execute_command()
if (auto child = parent->takeItem(p_impl->tagrow); child) {
p_impl->backup_strategy->saveItem(child.get());
setResult(true);
}
else {
} else {
setResult(false);
setObsolete(true);
}
Expand Down
16 changes: 5 additions & 11 deletions tests/testmodel/compounditem.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ TEST_F(CompoundItemTest, itemAccess)
parent.registerTag(TagInfo::universalTag(tag));

// inserting two children
auto property = new PropertyItem;
parent.insertItem(property, {tag, 0});

auto property = parent.insertItem<PropertyItem>({tag, 0});
EXPECT_TRUE(parent.item<PropertyItem>(tag) == property);
EXPECT_THROW(parent.item<CompoundItem>(tag), std::runtime_error);
}
Expand All @@ -196,10 +194,8 @@ TEST_F(CompoundItemTest, itemVectorAccess)
parent.registerTag(TagInfo::universalTag(tag));

// inserting two children
auto property1 = new PropertyItem;
auto property2 = new PropertyItem;
parent.insertItem(property1, TagRow::append(tag));
parent.insertItem(property2, TagRow::append(tag));
auto property1 = parent.insertItem<PropertyItem>(TagRow::append(tag));
auto property2 = parent.insertItem<PropertyItem>(TagRow::append(tag));

auto items = parent.items<PropertyItem>(tag);
std::vector<PropertyItem*> expected = {property1, property2};
Expand All @@ -218,10 +214,8 @@ TEST_F(CompoundItemTest, displayNameIndexAddition)
parent.registerTag(TagInfo::universalTag(tag));

// inserting two children
auto child0 = new CompoundItem;
parent.insertItem(child0, TagRow::append(tag));
auto child1 = new CompoundItem;
parent.insertItem(child1, TagRow::append(tag));
auto child0 = parent.insertItem<CompoundItem>(TagRow::append(tag));
auto child1 = parent.insertItem<CompoundItem>(TagRow::append(tag));

// Default display names of items of the same type should have indices
EXPECT_EQ(child0->displayName(), Constants::CompoundItemType + "0");
Expand Down

0 comments on commit d9273fd

Please sign in to comment.