BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
itemmanager.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/model/itemmanager.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 
15 #include "mvvm/model/itemmanager.h"
17 #include "mvvm/model/itemfactory.h"
18 #include "mvvm/model/itempool.h"
19 #include "mvvm/model/sessionitem.h"
20 
21 namespace {
22 std::unique_ptr<ModelView::ItemFactory> DefaultItemFactory()
23 {
24  return std::make_unique<ModelView::ItemFactory>(ModelView::CreateStandardItemCatalogue());
25 }
26 } // namespace
27 
28 using namespace ModelView;
29 
30 ItemManager::ItemManager() : m_item_factory(DefaultItemFactory()) {}
31 
32 void ItemManager::setItemFactory(std::unique_ptr<ItemFactoryInterface> factory)
33 {
34  m_item_factory = std::move(factory);
35 }
36 
37 void ItemManager::setItemPool(std::shared_ptr<ItemPool> pool)
38 {
39  m_item_pool = std::move(pool);
40 }
41 
42 ItemManager::~ItemManager() = default;
43 
44 std::unique_ptr<SessionItem> ItemManager::createItem(const model_type& modelType) const
45 {
46  return m_item_factory->createItem(modelType);
47 }
48 
49 std::unique_ptr<SessionItem> ItemManager::createRootItem() const
50 {
51  return std::make_unique<SessionItem>();
52 }
53 
55 {
56  return m_item_pool ? m_item_pool->item_for_key(id) : nullptr;
57 }
58 
60 {
61  return m_item_pool ? m_item_pool->key_for_item(item) : identifier_type();
62 }
63 
65 {
66  return m_item_pool.get();
67 }
68 
70 {
71  return m_item_pool.get();
72 }
73 
75 {
76  if (m_item_pool)
77  m_item_pool->register_item(item, item->identifier());
78 }
79 
81 {
82  if (m_item_pool)
83  m_item_pool->unregister_item(item);
84 }
85 
87 {
88  return m_item_factory.get();
89 }
90 
92 {
93  return const_cast<ItemFactoryInterface*>(static_cast<const ItemManager*>(this)->factory());
94 }
Interface class for all factories capable of producing SessionItem's.
Manages item creation/registration for SessionModel.
Definition: itemmanager.h:30
void registerInPool(SessionItem *item)
Definition: itemmanager.cpp:74
void unregisterFromPool(SessionItem *item)
Definition: itemmanager.cpp:80
void setItemPool(std::shared_ptr< ItemPool > pool)
Definition: itemmanager.cpp:37
identifier_type findIdentifier(const SessionItem *item) const
Definition: itemmanager.cpp:59
const ItemFactoryInterface * factory() const
Definition: itemmanager.cpp:86
std::unique_ptr< SessionItem > createItem(const model_type &modelType={}) const
Definition: itemmanager.cpp:44
SessionItem * findItem(const identifier_type &id) const
Definition: itemmanager.cpp:54
void setItemFactory(std::unique_ptr< ItemFactoryInterface > factory)
Definition: itemmanager.cpp:32
std::shared_ptr< ItemPool > m_item_pool
Definition: itemmanager.h:57
std::unique_ptr< SessionItem > createRootItem() const
Definition: itemmanager.cpp:49
std::unique_ptr< ItemFactoryInterface > m_item_factory
Definition: itemmanager.h:58
const ItemPool * itemPool() const
Definition: itemmanager.cpp:64
Provides registration of SessionItem pointers and their unique identifiers in global memory pool.
Definition: itempool.h:29
The main object representing an editable/displayable/serializable entity.
Definition: sessionitem.h:38
std::string identifier() const
Returns unique identifier.
Definition: sessionitem.cpp:87
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
std::string identifier_type
Definition: types.h:22
MVVM_MODEL_EXPORT std::unique_ptr< ItemCatalogue > CreateStandardItemCatalogue()
Creates a catalog of items supported by SessionModel out-of-the-box.
std::string model_type
Definition: types.h:23
Defines class CLASS?