BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
projectchangecontroller.cpp
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/project/projectchangecontroller.cpp
6 //! @brief Implements 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 
18 
19 using namespace ModelView;
20 
22  std::vector<SessionModel*> m_models;
23  std::vector<std::unique_ptr<ModelHasChangedController>> change_controllers;
25  bool m_project_has_changed{false};
26 
27  ProjectChangedControllerImpl(const std::vector<SessionModel*>& models, callback_t callback)
28  : m_models(models), m_project_changed_callback(callback)
29  {
31  }
32 
34  {
35  auto on_model_changed = [this]() { onProjectHasChanged(); };
36  change_controllers.clear();
37  for (auto model : m_models)
38  change_controllers.emplace_back(
39  std::make_unique<ModelHasChangedController>(model, on_model_changed));
40  }
41 
42  bool hasChanged() const { return m_project_has_changed; }
43 
44  void resetChanged()
45  {
46  for (auto& controller : change_controllers)
47  controller->resetChanged();
48  m_project_has_changed = false;
49  }
50 
52  {
53  if (!m_project_has_changed) {
54  m_project_has_changed = true;
57  }
58  }
59 };
60 
61 ProjectChangedController::ProjectChangedController(const std::vector<SessionModel*>& models,
62  callback_t project_changed_callback)
63  : p_impl(std::make_unique<ProjectChangedControllerImpl>(models, project_changed_callback))
64 {
65 }
66 
68 
69 //! Returns true if the change in the models has been registered since the last call of
70 //! resetChanged.
71 
73 {
74  return p_impl->hasChanged();
75 }
76 
77 //! Reset controller to initial state, pretending that no changes has been registered.
78 
80 {
81  return p_impl->resetChanged();
82 }
bool hasChanged() const
Returns true if the change in the models has been registered since the last call of resetChanged.
ProjectChangedController(const std::vector< SessionModel * > &models, callback_t project_changed_callback={})
void resetChanged()
Reset controller to initial state, pretending that no changes has been registered.
std::unique_ptr< ProjectChangedControllerImpl > p_impl
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Definition: filesystem.h:81
Defines class CLASS?
Defines class CLASS?
ProjectChangedControllerImpl(const std::vector< SessionModel * > &models, callback_t callback)
std::vector< std::unique_ptr< ModelHasChangedController > > change_controllers