BornAgain
1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
|
Main class to hold hierarchy of SessionItem objects. More...
Public Member Functions | |
SessionModel (const SessionModel &other)=delete | |
SessionModel (std::string model_type={}, std::shared_ptr< ItemPool > pool={}) | |
Main c-tor. More... | |
virtual | ~SessionModel () |
void | clear (std::function< void(SessionItem *)> callback={}) |
Removes all items from the model. More... | |
SessionItem * | copyItem (const SessionItem *item, SessionItem *parent, const TagRow &tagrow={}) |
Copy item and insert it in parent's tag and row. Item could belong to any model/parent. More... | |
Variant | data (SessionItem *item, int role) const |
Returns the data for given item and role. More... | |
const ItemFactoryInterface * | factory () const |
Returns item factory which can generate all items supported by this model. More... | |
SessionItem * | findItem (const identifier_type &id) |
Returns SessionItem for given identifier. More... | |
template<typename T > | |
T * | insertItem (SessionItem *parent=nullptr, const TagRow &tagrow={}) |
Inserts item into given parent under given tagrow. More... | |
SessionItem * | insertNewItem (const model_type &modelType, SessionItem *parent=nullptr, const TagRow &tagrow={}) |
Insert new item using item's modelType. More... | |
ModelMapper * | mapper () |
Returns model mapper. Can be used to subscribe to various model's signal. More... | |
std::string | modelType () const |
Returns model type. More... | |
void | moveItem (SessionItem *item, SessionItem *new_parent, const TagRow &tagrow) |
Move item from it's current parent to a new parent under given tag and row. More... | |
SessionModel & | operator= (const SessionModel &other)=delete |
template<typename T > | |
void | registerItem (const std::string &label={}) |
Register used defined item to use with the model. More... | |
void | removeItem (SessionItem *parent, const TagRow &tagrow) |
Removes given row from parent. More... | |
SessionItem * | rootItem () const |
Returns root item of the model. More... | |
bool | setData (SessionItem *item, const Variant &value, int role) |
Sets the data for given item. More... | |
void | setItemCatalogue (std::unique_ptr< ItemCatalogue > catalogue) |
Sets brand new catalog of user-defined items. More... | |
void | setUndoRedoEnabled (bool value) |
Sets undo/redo either enabled or disabled. By default undo/redo is disabled. More... | |
template<typename T = SessionItem> | |
T * | topItem () const |
Returns top item of the given type. More... | |
template<typename T = SessionItem> | |
std::vector< T * > | topItems () const |
Returns top items of the given type. More... | |
UndoStackInterface * | undoStack () const |
Returns command stack to perform undo/redo. More... | |
Private Member Functions | |
SessionItem * | intern_insert (const item_factory_func_t &func, SessionItem *parent, const TagRow &tagrow) |
Insert new item into given parent using factory function provided. More... | |
void | intern_register (const model_type &modelType, const item_factory_func_t &func, const std::string &label) |
void | registerInPool (SessionItem *item) |
Registers item in pool. This will allow to find item pointer using its unique identifier. More... | |
void | unregisterFromPool (SessionItem *item) |
Unregister item from pool. More... | |
Private Attributes | |
std::unique_ptr< SessionModelImpl > | p_impl |
Friends | |
class | SessionItem |
Main class to hold hierarchy of SessionItem objects.
Definition at line 37 of file sessionmodel.h.
|
explicit |
Main c-tor.
Definition at line 66 of file sessionmodel.cpp.
References p_impl.
|
virtual |
|
delete |
void SessionModel::clear | ( | std::function< void(SessionItem *)> | callback = {} | ) |
Removes all items from the model.
If callback is provided, use it to rebuild content of root item (used while restoring the model from serialized content).
Definition at line 194 of file sessionmodel.cpp.
References ModelView::ModelMapper::callOnModelAboutToBeReset(), ModelView::ModelMapper::callOnModelReset(), ModelView::UndoStackInterface::clear(), mapper(), p_impl, rootItem(), and undoStack().
Referenced by gui2::SLDElementController::clearScene(), ModelView::JsonModelConverter::from_json(), and TEST_F().
SessionItem * SessionModel::copyItem | ( | const SessionItem * | item, |
SessionItem * | parent, | ||
const TagRow & | tagrow = {} |
||
) |
Copy item and insert it in parent's tag and row. Item could belong to any model/parent.
Definition at line 111 of file sessionmodel.cpp.
References p_impl.
Referenced by gui2::MaterialModel::cloneMaterial(), and TEST_F().
Variant SessionModel::data | ( | SessionItem * | item, |
int | role | ||
) | const |
Returns the data for given item and role.
Definition at line 119 of file sessionmodel.cpp.
References ModelView::SessionItem::data().
Referenced by gui2::ExperimentalDataModel::addGraph(), and TEST_F().
const ItemFactoryInterface * SessionModel::factory | ( | ) | const |
Returns item factory which can generate all items supported by this model.
Definition at line 161 of file sessionmodel.cpp.
References p_impl.
Referenced by InsertNewItemCommandTest::create_command(), ModelView::CreateItemBackupStrategy(), ModelView::CreateItemCopyStrategy(), ModelView::JsonModelConverter::from_json(), insertNewItem(), TEST_F(), and ModelView::JsonModelConverter::to_json().
SessionItem * SessionModel::findItem | ( | const identifier_type & | id | ) |
Returns SessionItem for given identifier.
Definition at line 168 of file sessionmodel.cpp.
References p_impl.
Referenced by gui2::DataViewModel::dropMimeData(), ModelView::LinkedItem::get(), gui2::ExperimentalScanItem::graphItem(), TEST_F(), gui2::SLDElementController::updateRoughnessFromView(), gui2::SLDElementController::updateSLDFromView(), gui2::SLDElementController::updateThicknessFromView(), and gui2::SLDElementController::updateToView().
T * SessionModel::insertItem | ( | SessionItem * | parent = nullptr , |
const TagRow & | tagrow = {} |
||
) |
Inserts item into given parent under given tagrow.
Definition at line 104 of file sessionmodel.h.
References intern_insert().
Referenced by ModelView::Data1DItem::setAxis(), TEST(), and TEST_F().
SessionItem * SessionModel::insertNewItem | ( | const model_type & | modelType, |
SessionItem * | parent = nullptr , |
||
const TagRow & | tagrow = {} |
||
) |
Insert new item using item's modelType.
Definition at line 86 of file sessionmodel.cpp.
References ModelView::ItemFactoryInterface::createItem(), factory(), intern_insert(), and modelType().
Referenced by TEST_F().
|
private |
Insert new item into given parent using factory function provided.
Definition at line 222 of file sessionmodel.cpp.
References p_impl.
Referenced by insertItem(), and insertNewItem().
|
private |
Definition at line 228 of file sessionmodel.cpp.
References modelType(), and p_impl.
Referenced by registerItem().
ModelMapper * SessionModel::mapper | ( | ) |
Returns model mapper. Can be used to subscribe to various model's signal.
Definition at line 147 of file sessionmodel.cpp.
References p_impl.
Referenced by MockWidgetForModel::~MockWidgetForModel(), clear(), gui2::SLDElementController::connectLayerModel(), gui2::SLDElementController::connectMaterialModel(), gui2::SLDElementController::connectSLDElementModel(), gui2::SLDElementController::disconnectLayerModel(), gui2::SLDElementController::disconnectMaterialModel(), gui2::SLDElementController::disconnectSLDElementModel(), MockWidgetForModel::setModel(), ModelView::ModelListenerBase::setOnAboutToRemoveItem(), ModelView::ModelListenerBase::setOnDataChange(), ModelView::ModelListenerBase::setOnItemInserted(), ModelView::ModelListenerBase::setOnItemRemoved(), ModelView::ModelListenerBase::setOnModelAboutToBeReset(), ModelView::ModelListenerBase::setOnModelDestroyed(), ModelView::ModelListenerBase::setOnModelReset(), and ModelView::ModelListenerBase::unsubscribe().
std::string SessionModel::modelType | ( | ) | const |
Returns model type.
Definition at line 133 of file sessionmodel.cpp.
References p_impl.
Referenced by ModelView::JsonModelConverter::from_json(), insertNewItem(), intern_register(), registerItem(), ModelView::ProjectUtils::SuggestFileName(), and ModelView::JsonModelConverter::to_json().
void SessionModel::moveItem | ( | SessionItem * | item, |
SessionItem * | new_parent, | ||
const TagRow & | tagrow | ||
) |
Move item from it's current parent to a new parent under given tag and row.
Old and new parents should belong to this model.
Definition at line 104 of file sessionmodel.cpp.
References p_impl.
Referenced by gui2::DataViewModel::dropMimeData(), gui2::ExperimentalDataModel::mergeCanvases(), ModelView::Utils::MoveDown(), ModelView::Utils::MoveUp(), and TEST_F().
|
delete |
|
private |
Registers item in pool. This will allow to find item pointer using its unique identifier.
Definition at line 207 of file sessionmodel.cpp.
References ModelView::SessionItem::activate(), and p_impl.
void SessionModel::registerItem | ( | const std::string & | label = {} | ) |
Register used defined item to use with the model.
It will become possible to undo/redo operations with this item, as well as serialize it to/from JSON.
Definition at line 135 of file sessionmodel.h.
References intern_register(), and modelType().
Referenced by TEST_F().
void SessionModel::removeItem | ( | SessionItem * | parent, |
const TagRow & | tagrow | ||
) |
Removes given row from parent.
Definition at line 96 of file sessionmodel.cpp.
References p_impl.
Referenced by ModelView::Utils::DeleteItemFromModel(), gui2::ExperimentalDataModel::mergeCanvases(), gui2::ExperimentalDataModel::removeCanvas(), gui2::ExperimentalDataModel::removeGraph(), TEST(), and TEST_F().
SessionItem * SessionModel::rootItem | ( | ) | const |
Returns root item of the model.
Definition at line 140 of file sessionmodel.cpp.
References p_impl.
Referenced by gui2::SLDElementController::buildSLD(), clear(), ViewModelControllerTest::create_controller(), ModelView::Utils::FindItems(), ModelView::JsonModelConverter::from_json(), gui2::ExperimentalDataModel::init_model(), ModelView::CommandService::insertNewItem(), ModelView::Utils::ItemFromPath(), gui2::MaterialModel::material_data(), ModelView::ItemMapper::ItemMapperImpl::nestlingDepth(), TEST(), TEST_F(), ModelView::JsonModelConverter::to_json(), topItems(), and ModelView::Utils::TopItems().
bool SessionModel::setData | ( | SessionItem * | item, |
const Variant & | value, | ||
int | role | ||
) |
Sets the data for given item.
Definition at line 126 of file sessionmodel.cpp.
References p_impl.
Referenced by ModelView::SessionItem::set_data_internal(), TEST(), and TEST_F().
void SessionModel::setItemCatalogue | ( | std::unique_ptr< ItemCatalogue > | catalogue | ) |
Sets brand new catalog of user-defined items.
They become available for undo/redo and serialization. Internally user catalog will be merged with the catalog of standard items.
Definition at line 176 of file sessionmodel.cpp.
References ModelView::CreateStandardItemCatalogue(), and p_impl.
Referenced by ToyItems::SampleModel::SampleModel(), gui2::SampleModel::SampleModel(), gui2::SLDElementModel::SLDElementModel(), gui2::ExperimentalDataModel::init_model(), and gui2::MaterialModel::init_model().
void SessionModel::setUndoRedoEnabled | ( | bool | value | ) |
Sets undo/redo either enabled or disabled. By default undo/redo is disabled.
Definition at line 186 of file sessionmodel.cpp.
References p_impl.
Referenced by gui2::ExperimentalDataModel::init_model(), and TEST_F().
T * SessionModel::topItem |
Returns top item of the given type.
If more than one item exists, return the first one. The top item is an item that is a child of an invisible root item.
Definition at line 126 of file sessionmodel.h.
Referenced by gui2::SimPlotController::onInstrumentChange(), gui2::QuickSimController::process_multilayer(), gui2::LayerEditorWidget::setModels(), gui2::InstrumentPropertyEditor::setModels(), gui2::QuickSimController::submit_specular_simulation(), and TEST_F().
std::vector< T * > SessionModel::topItems |
Returns top items of the given type.
The top item is an item that is a child of an invisible root item.
Definition at line 112 of file sessionmodel.h.
References rootItem().
Referenced by TEST_F().
UndoStackInterface * SessionModel::undoStack | ( | ) | const |
Returns command stack to perform undo/redo.
Definition at line 154 of file sessionmodel.cpp.
References p_impl.
Referenced by ModelView::Utils::BeginMacros(), clear(), ModelView::Utils::EndMacros(), gui2::ImportDataEditorActions::isUndoEnabled(), gui2::ImportDataEditorActions::onRedo(), gui2::ImportDataEditorActions::onUndo(), ModelView::Utils::Redo(), ModelView::SessionItem::set_data_internal(), TEST_F(), ModelView::Utils::Undo(), and gui2::ImportDataEditorActions::undoStack().
|
private |
|
friend |
Definition at line 90 of file sessionmodel.h.
|
private |
Definition at line 99 of file sessionmodel.h.
Referenced by SessionModel(), ~SessionModel(), clear(), copyItem(), factory(), findItem(), intern_insert(), intern_register(), mapper(), modelType(), moveItem(), registerInPool(), removeItem(), rootItem(), setData(), setItemCatalogue(), setUndoRedoEnabled(), undoStack(), and unregisterFromPool().