BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
materialpropertycontroller.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/model/materialpropertycontroller.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 Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 #include "gui2/model/sampleitems.h"
18 #include "gui2/model/samplemodel.h"
20 #include "mvvm/model/modelutils.h"
21 
22 using namespace ModelView;
23 
24 namespace gui2 {
25 
27  SampleModel* sample_model)
28  : ModelListener(material_model), m_sample_model(sample_model)
29 {
30  setOnDataChange([this](auto, auto) { update_all(); });
31  setOnItemInserted([this](auto, auto) { update_all(); });
32  setOnItemRemoved([this](auto, auto) { update_all(); });
33  setOnModelReset([this](auto) { update_all(); });
34 
35  update_all();
36 }
37 
38 //! Updates all material properties in LayerItems to get new material colors and labels.
39 
41 {
42  for (auto layer : Utils::FindItems<LayerItem>(m_sample_model)) {
43  auto property = layer->property<ExternalProperty>(LayerItem::P_MATERIAL);
44  auto updated = model()->material_property(property.identifier());
45  if (property != updated)
46  layer->setProperty(LayerItem::P_MATERIAL, updated);
47  }
48 }
49 
50 } // namespace gui2
MaterialPropertyController(QObject *parent=nullptr)
Property to carry text, color and identifier.
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
static const std::string P_MATERIAL
Definition: sampleitems.h:42
Model to hold MaterialItems.
Definition: materialmodel.h:35
void update_all()
Updates all material properties in LayerItems to get new material colors and labels.
Model to hold layers and multi-layers.
Definition: samplemodel.h:24
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?
Defines class CLASS?