BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
customlayertreeeditorfactory.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/layereditor/customlayertreeeditorfactory.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 
20 #include <QModelIndex>
21 #include <algorithm>
22 
23 using namespace ModelView;
24 
25 namespace gui2 {
26 
27 namespace {
28 //! Return list of possible choices for material properties in MaterialModel.
29 //! Use "undefined material" as a first item in a list.
30 std::vector<ModelView::ExternalProperty> get_choice_of_materials(MaterialModel* model)
31 {
32  std::vector<ModelView::ExternalProperty> result{ModelView::ExternalProperty::undefined()};
33  auto other_data = model->material_data();
34  std::copy(other_data.begin(), other_data.end(), std::back_inserter(result));
35  return result;
36 }
37 } // namespace
38 
39 CustomLayerTreeEditorFactory::~CustomLayerTreeEditorFactory() = default;
40 
41 CustomLayerTreeEditorFactory::CustomLayerTreeEditorFactory(ApplicationModels* models)
42  : m_models(models)
43 {
44 }
45 
46 std::unique_ptr<CustomEditor>
47 CustomLayerTreeEditorFactory::createEditor(const QModelIndex& index) const
48 {
49  auto value = index.data(Qt::EditRole);
50  if (Utils::IsExtPropertyVariant(value)) {
51  auto material_choice_callback = [this]() {
52  return get_choice_of_materials(m_models->materialModel());
53  };
54  return std::make_unique<ExternalPropertyComboEditor>(material_choice_callback);
55  } else {
57  }
58 }
59 
60 } // namespace gui2
Defines class CLASS?
std::unique_ptr< CustomEditor > createEditor(const QModelIndex &index) const override
Creates editor for given model index basing either on editorType() or specific variant name.
static ExternalProperty undefined()
Main class to holds all models of GUI session.
MaterialModel * materialModel()
std::unique_ptr< ModelView::CustomEditor > createEditor(const QModelIndex &index) const
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
MVVM_MODEL_EXPORT bool IsExtPropertyVariant(const Variant &variant)
Returns true in the case of ExternalProperty based variant.
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