BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
modelhaschangedcontroller.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/modelhaschangedcontroller.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 
16 
17 using namespace ModelView;
18 
19 //! Constructor of ModelHasChangedController.
20 //! Acccept 'model' to listen, and a 'callback' to report about changes in a model.
21 
23  : ModelListener(model), m_callback(callback)
24 {
25  setOnDataChange([this](auto, auto) { process_change(); });
26  setOnItemInserted([this](auto, auto) { process_change(); });
27  setOnItemRemoved([this](auto, auto) { process_change(); });
28  setOnModelReset([this](auto) { process_change(); });
29 }
30 
31 //! Returns true if the model was changed since last call of resetChanged.
32 
34 {
35  return m_has_changed;
36 }
37 
38 //! Reset has_changed flag.
39 
41 {
42  m_has_changed = false;
43 }
44 
45 //! Sets 'has_changed' flag and reports back to client.
46 
48 {
49  m_has_changed = true;
50  if (m_callback)
51  m_callback();
52 }
void process_change()
Sets 'has_changed' flag and reports back to client.
ModelHasChangedController(SessionModel *model, callback_t callback={})
Constructor of ModelHasChangedController.
bool hasChanged() const
Returns true if the model was changed since last call of resetChanged.
void setOnItemRemoved(Callbacks::item_tagrow_t f, Callbacks::slot_t client={}) override
Sets callback to be notified on item remove.
void setOnItemInserted(Callbacks::item_tagrow_t f, Callbacks::slot_t client={}) override
Sets callback to be notified on item insert.
void setOnDataChange(Callbacks::item_int_t f, Callbacks::slot_t client={}) override
Sets callback to be notified on item's data change.
void setOnModelReset(Callbacks::model_t f, Callbacks::slot_t client={}) override
Sets the callback to be notified after model was fully reset (root item recreated).
Templated class for all objects willing to listen for changes in concrete SessionModel.
Definition: modellistener.h:26
Main class to hold hierarchy of SessionItem objects.
Definition: sessionmodel.h:37
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.