BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
abstractitemcommand.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/commands/abstractitemcommand.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_COMMANDS_ABSTRACTITEMCOMMAND_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_COMMANDS_ABSTRACTITEMCOMMAND_H
17 
19 #include "mvvm/model_export.h"
20 #include <memory>
21 #include <string>
22 
23 namespace ModelView {
24 
25 class SessionItem;
26 class SessionModel;
27 class Path;
28 
29 //! Abstract command interface to manipulate SessionItem in model context.
30 
31 class MVVM_MODEL_EXPORT AbstractItemCommand {
32 public:
33  explicit AbstractItemCommand(SessionItem* receiver);
35 
36  AbstractItemCommand(const AbstractItemCommand& other) = delete;
38 
39  void execute();
40 
41  void undo();
42 
43  bool isObsolete() const;
44 
45  std::string description() const;
46 
47  CommandResult result() const;
48 
49 protected:
50  void setObsolete(bool flag);
51  void setDescription(const std::string& text);
52  Path pathFromItem(SessionItem* item) const;
53  SessionItem* itemFromPath(const Path& path) const;
54  SessionModel* model() const;
55  void setResult(const CommandResult& command_result);
56 
57 private:
58  virtual void execute_command() = 0;
59  virtual void undo_command() = 0;
60 
62  std::unique_ptr<AbstractItemCommandImpl> p_impl;
63 };
64 
65 } // namespace ModelView
66 
67 #endif // BORNAGAIN_MVVM_MODEL_MVVM_COMMANDS_ABSTRACTITEMCOMMAND_H
Abstract command interface to manipulate SessionItem in model context.
virtual void execute_command()=0
AbstractItemCommand(const AbstractItemCommand &other)=delete
std::unique_ptr< AbstractItemCommandImpl > p_impl
AbstractItemCommand & operator=(const AbstractItemCommand &other)=delete
Supports navigation through SessionModel.
Definition: path.h:35
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
std::variant< bool, ModelView::SessionItem * > CommandResult
Results of command execution.
Definition: commandresult.h:25