BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::AbstractItemCommand Class Referenceabstract

Abstract command interface to manipulate SessionItem in model context. More...

Inheritance diagram for ModelView::AbstractItemCommand:
[legend]

Classes

struct  AbstractItemCommandImpl
 

Public Member Functions

 AbstractItemCommand (const AbstractItemCommand &other)=delete
 
 AbstractItemCommand (SessionItem *receiver)
 
virtual ~AbstractItemCommand ()
 
std::string description () const
 Returns command description. More...
 
void execute ()
 Execute command. More...
 
bool isObsolete () const
 Returns whether the command is obsolete (which means that it shouldn't be kept in the stack). More...
 
AbstractItemCommandoperator= (const AbstractItemCommand &other)=delete
 
CommandResult result () const
 
void undo ()
 Undo command as it was before execution. More...
 

Protected Member Functions

SessionItemitemFromPath (const Path &path) const
 
SessionModelmodel () const
 
Path pathFromItem (SessionItem *item) const
 
void setDescription (const std::string &text)
 Sets command description. More...
 
void setObsolete (bool flag)
 Sets command obsolete flag. More...
 
void setResult (const CommandResult &command_result)
 

Private Member Functions

virtual void execute_command ()=0
 
virtual void undo_command ()=0
 

Private Attributes

std::unique_ptr< AbstractItemCommandImplp_impl
 

Detailed Description

Abstract command interface to manipulate SessionItem in model context.

Definition at line 31 of file abstractitemcommand.h.

Constructor & Destructor Documentation

◆ AbstractItemCommand() [1/2]

AbstractItemCommand::AbstractItemCommand ( SessionItem receiver)
explicit

Definition at line 40 of file abstractitemcommand.cpp.

41  : p_impl(std::make_unique<AbstractItemCommand::AbstractItemCommandImpl>(this))
42 {
43  if (!receiver)
44  throw std::runtime_error("Invalid item.");
45 
46  if (!receiver->model())
47  throw std::runtime_error("Item doesn't have a model");
48 
49  p_impl->m_model = receiver->model();
50 }
std::unique_ptr< AbstractItemCommandImpl > p_impl
SessionModel * model() const
Returns the model to which given item belongs to.

References ModelView::SessionItem::model(), and p_impl.

Here is the call graph for this function:

◆ ~AbstractItemCommand()

AbstractItemCommand::~AbstractItemCommand ( )
virtualdefault

◆ AbstractItemCommand() [2/2]

ModelView::AbstractItemCommand::AbstractItemCommand ( const AbstractItemCommand other)
delete

Member Function Documentation

◆ description()

std::string AbstractItemCommand::description ( ) const

Returns command description.

Definition at line 87 of file abstractitemcommand.cpp.

88 {
89  return p_impl->m_text;
90 }

References p_impl.

◆ execute()

void AbstractItemCommand::execute ( )

Execute command.

Definition at line 56 of file abstractitemcommand.cpp.

57 {
58  if (!p_impl->can_execute())
59  throw std::runtime_error("Can't execute the command. Wrong order.");
60 
62 
63  p_impl->set_after_execute();
64 }
virtual void execute_command()=0

References execute_command(), and p_impl.

Referenced by TEST_F().

Here is the call graph for this function:

◆ execute_command()

virtual void ModelView::AbstractItemCommand::execute_command ( )
privatepure virtual

◆ isObsolete()

bool AbstractItemCommand::isObsolete ( ) const

Returns whether the command is obsolete (which means that it shouldn't be kept in the stack).

Definition at line 80 of file abstractitemcommand.cpp.

81 {
82  return p_impl->m_isObsolete;
83 }

References p_impl.

Referenced by ModelView::AbstractItemCommand::AbstractItemCommandImpl::can_undo(), and TEST_F().

◆ itemFromPath()

SessionItem * AbstractItemCommand::itemFromPath ( const Path path) const
protected

Definition at line 116 of file abstractitemcommand.cpp.

117 {
118  return Utils::ItemFromPath(*p_impl->m_model, path);
119 }
MVVM_MODEL_EXPORT SessionItem * ItemFromPath(const SessionModel &moodel, const Path &path)
Returns item found in the model following given Path.
Definition: modelutils.cpp:36

References ModelView::Utils::ItemFromPath(), and p_impl.

Referenced by ModelView::CopyItemCommand::execute_command(), ModelView::InsertNewItemCommand::execute_command(), ModelView::MoveItemCommand::execute_command(), ModelView::RemoveItemCommand::execute_command(), ModelView::SetValueCommand::swap_values(), ModelView::CopyItemCommand::undo_command(), ModelView::InsertNewItemCommand::undo_command(), ModelView::MoveItemCommand::undo_command(), and ModelView::RemoveItemCommand::undo_command().

Here is the call graph for this function:

◆ model()

SessionModel * AbstractItemCommand::model ( ) const
protected

Definition at line 121 of file abstractitemcommand.cpp.

122 {
123  return p_impl->m_model;
124 }

References p_impl.

◆ operator=()

AbstractItemCommand& ModelView::AbstractItemCommand::operator= ( const AbstractItemCommand other)
delete

◆ pathFromItem()

Path AbstractItemCommand::pathFromItem ( SessionItem item) const
protected

Definition at line 111 of file abstractitemcommand.cpp.

112 {
113  return Utils::PathFromItem(item);
114 }
MVVM_MODEL_EXPORT Path PathFromItem(const SessionItem *item)
Constructs path to find given item. Item must belong to a model.
Definition: modelutils.cpp:22

References ModelView::Utils::PathFromItem().

Referenced by ModelView::CopyItemCommand::CopyItemCommand(), ModelView::InsertNewItemCommand::InsertNewItemCommand(), ModelView::MoveItemCommand::MoveItemCommand(), ModelView::RemoveItemCommand::RemoveItemCommand(), ModelView::SetValueCommand::SetValueCommand(), ModelView::MoveItemCommand::execute_command(), and ModelView::MoveItemCommand::undo_command().

Here is the call graph for this function:

◆ result()

CommandResult AbstractItemCommand::result ( ) const

Definition at line 92 of file abstractitemcommand.cpp.

93 {
94  return p_impl->m_result;
95 }

References p_impl.

Referenced by ModelView::CopyItemCommand::execute_command(), ModelView::SetValueCommand::swap_values(), and TEST_F().

◆ setDescription()

void AbstractItemCommand::setDescription ( const std::string &  text)
protected

◆ setObsolete()

void AbstractItemCommand::setObsolete ( bool  flag)
protected

◆ setResult()

◆ undo()

void AbstractItemCommand::undo ( )

Undo command as it was before execution.

Definition at line 68 of file abstractitemcommand.cpp.

69 {
70  if (!p_impl->can_undo())
71  throw std::runtime_error("Can't undo the command. Wrong order.");
72 
73  undo_command();
74 
75  p_impl->set_after_undo();
76 }

References p_impl, and undo_command().

Referenced by TEST_F().

Here is the call graph for this function:

◆ undo_command()

virtual void ModelView::AbstractItemCommand::undo_command ( )
privatepure virtual

Member Data Documentation

◆ p_impl

std::unique_ptr<AbstractItemCommandImpl> ModelView::AbstractItemCommand::p_impl
private

The documentation for this class was generated from the following files: