26 std::string generate_description(
const TagRow& tagrow);
37 throw std::runtime_error(
"MoveItemCommand() -> Error. Uninitialized target row");
46 check_input_data(item, new_parent);
54 throw std::runtime_error(
"MoveItemCommand::MoveItemCommand() -> Single property tag.");
57 throw std::runtime_error(
"MoveItemCommand::MoveItemCommand() -> Single property tag.");
59 if (item->
parent() == new_parent) {
61 throw std::runtime_error(
62 "MoveCommand::MoveCommand() -> move index exceeds number of items in a tag");
75 auto taken = current_parent->takeItem(
p_impl->target_tagrow);
76 target_parent->insertItem(taken,
p_impl->original_tagrow);
90 auto taken = original_parent->takeItem(
p_impl->original_tagrow);
93 throw std::runtime_error(
"MoveItemCommand::execute() -> Can't take an item.");
95 bool succeeded = target_parent->insertItem(taken,
p_impl->target_tagrow);
97 throw std::runtime_error(
"MoveItemCommand::execute() -> Can't insert item.");
107 if (!item || !item->
model())
108 throw std::runtime_error(
"MoveItemCommand::MoveItemCommand() -> Invalid input item");
110 if (!parent || !parent->
model())
111 throw std::runtime_error(
"MoveItemCommand::MoveItemCommand() -> Invalid parent item");
114 throw std::runtime_error(
115 "MoveItemCommand::MoveItemCommand() -> Items belong to different models");
118 throw std::runtime_error(
119 "MoveItemCommand::MoveItemCommand() -> Item doesn't have a parent");
122 std::string generate_description(
const TagRow& tagrow)
124 std::ostringstream ostr;
125 ostr <<
"Move item to tag '" << tagrow.
tag <<
"', row:" << tagrow.
row;
Abstract command interface to manipulate SessionItem in model context.
SessionItem * itemFromPath(const Path &path) const
void setDescription(const std::string &text)
Sets command description.
void setResult(const CommandResult &command_result)
Path pathFromItem(SessionItem *item) const
void undo_command() override
std::unique_ptr< MoveItemCommandImpl > p_impl
MoveItemCommand(SessionItem *item, SessionItem *new_parent, TagRow tagrow)
~MoveItemCommand() override
void execute_command() override
Supports navigation through SessionModel.
The main object representing an editable/displayable/serializable entity.
int itemCount(const std::string &tag) const
Returns number of items in given tag.
SessionItem * parent() const
Returns parent item. Will return nullptr if item doesn't have a parent.
SessionModel * model() const
Returns the model to which given item belongs to.
TagRow tagRow() const
Returns TagRow of this item under which it is accessible through its parent.
Aggregate to hold (tag, row) information for SessionModel.
MVVM_MODEL_EXPORT bool IsSinglePropertyTag(const SessionItem &item, const std::string &tag)
Returns true if given item has registered tag, and it belongs to single property.
materialitems.h Collection of materials to populate MaterialModel.
Path original_parent_path
MoveItemCommandImpl(TagRow tagrow)