BornAgain
1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
|
Base class for all view models to show content of SessionModel in Qt views. More...
Classes | |
struct | ViewModelBaseImpl |
Public Member Functions | |
ViewModelBase (QObject *parent=nullptr) | |
~ViewModelBase () override | |
void | appendRow (ViewItem *parent, std::vector< std::unique_ptr< ViewItem >> items) |
Appends row of items to given parent. More... | |
void | clearRows (ViewItem *parent) |
int | columnCount (const QModelIndex &parent=QModelIndex()) const override |
QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const override |
Qt::ItemFlags | flags (const QModelIndex &index) const override |
Returns the item flags for the given index. More... | |
QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const override |
QModelIndex | indexFromItem (const ViewItem *item) const |
Returns the QModelIndex associated with the given item. More... | |
void | insertRow (ViewItem *parent, int row, std::vector< std::unique_ptr< ViewItem >> items) |
Insert a row of items at index 'row' to given parent. More... | |
ViewItem * | itemFromIndex (const QModelIndex &index) const |
Returns a pointer to the RefViewItem associated with the given index. More... | |
QModelIndex | parent (const QModelIndex &child) const override |
void | removeRow (ViewItem *parent, int row) |
ViewItem * | rootItem () const |
Returns a pointer to invisible root item. More... | |
int | rowCount (const QModelIndex &parent=QModelIndex()) const override |
bool | setData (const QModelIndex &index, const QVariant &value, int role) override |
Private Member Functions | |
void | setRootViewItem (std::unique_ptr< ViewItem > root_item) |
Sets new root item. Previous item will be deleted, model will be reset. More... | |
Private Attributes | |
std::unique_ptr< ViewModelBaseImpl > | p_impl |
Friends | |
class | ViewModelController |
Base class for all view models to show content of SessionModel in Qt views.
ViewModelBase is made of ViewItems, where each ViewItem represents some concrete data role of SessionItem. ViewModelBase doesn't have own logic and needs ViewModelController to listen for SessionModel changes.
Definition at line 31 of file viewmodelbase.h.
|
explicit |
Definition at line 32 of file viewmodelbase.cpp.
References setRootViewItem().
|
overridedefault |
void ViewModelBase::appendRow | ( | ViewItem * | parent, |
std::vector< std::unique_ptr< ViewItem >> | items | ||
) |
Appends row of items to given parent.
Definition at line 165 of file viewmodelbase.cpp.
References insertRow(), and parent().
Referenced by ModelView::ViewModelController::ViewModelControllerImpl::iterate(), and TEST_F().
void ViewModelBase::clearRows | ( | ViewItem * | parent | ) |
Definition at line 135 of file viewmodelbase.cpp.
References indexFromItem(), p_impl, and parent().
Referenced by ModelView::ViewModelController::ViewModelControllerImpl::remove_children_of_view(), and TEST_F().
|
override |
Definition at line 70 of file viewmodelbase.cpp.
References ModelView::ViewItem::columnCount(), itemFromIndex(), parent(), and rootItem().
Referenced by index(), and TEST_F().
|
override |
Definition at line 76 of file viewmodelbase.cpp.
References index(), itemFromIndex(), and rootItem().
Referenced by gui2::DataViewModel::canDropMimeData(), gui2::DataViewModel::dropMimeData(), ModelView::ViewModel::headerData(), and TEST_F().
|
override |
Returns the item flags for the given index.
Definition at line 172 of file viewmodelbase.cpp.
References index(), and itemFromIndex().
Referenced by gui2::DataViewModel::flags(), and TEST_F().
|
override |
Definition at line 42 of file viewmodelbase.cpp.
References columnCount(), itemFromIndex(), parent(), rootItem(), and rowCount().
Referenced by data(), gui2::DataViewModel::flags(), flags(), itemFromIndex(), ModelView::ViewModel::sessionItemFromIndex(), setData(), TEST_F(), and ModelView::ViewModel::viewItemFromIndex().
QModelIndex ViewModelBase::indexFromItem | ( | const ViewItem * | item | ) | const |
Returns the QModelIndex associated with the given item.
Definition at line 117 of file viewmodelbase.cpp.
References ModelView::ViewItem::column(), ModelView::ViewItem::parent(), and ModelView::ViewItem::row().
Referenced by clearRows(), ModelView::ViewModel::indexOfSessionItem(), insertRow(), ModelView::ViewModelBase::ViewModelBaseImpl::item_belongs_to_model(), removeRow(), and TEST_F().
void ViewModelBase::insertRow | ( | ViewItem * | parent, |
int | row, | ||
std::vector< std::unique_ptr< ViewItem >> | items | ||
) |
Insert a row of items at index 'row' to given parent.
Definition at line 151 of file viewmodelbase.cpp.
References indexFromItem(), p_impl, and parent().
Referenced by appendRow(), ModelView::ViewModelController::ViewModelControllerImpl::insert_view(), and TEST_F().
ViewItem * ViewModelBase::itemFromIndex | ( | const QModelIndex & | index | ) | const |
Returns a pointer to the RefViewItem associated with the given index.
If index is invalid, returns nullptr.
Definition at line 110 of file viewmodelbase.cpp.
References index().
Referenced by columnCount(), data(), ModelView::ViewModelController::ViewModelControllerImpl::findViews(), flags(), index(), parent(), rowCount(), ModelView::ViewModel::sessionItemFromIndex(), setData(), TEST_F(), and ModelView::ViewModel::viewItemFromIndex().
|
override |
Definition at line 52 of file viewmodelbase.cpp.
References itemFromIndex(), and rootItem().
Referenced by appendRow(), gui2::DataViewModel::canDropMimeData(), clearRows(), columnCount(), gui2::DataViewModel::dropMimeData(), index(), insertRow(), removeRow(), rowCount(), and TEST_F().
void ViewModelBase::removeRow | ( | ViewItem * | parent, |
int | row | ||
) |
Definition at line 124 of file viewmodelbase.cpp.
References indexFromItem(), p_impl, and parent().
Referenced by ModelView::ViewModelController::ViewModelControllerImpl::remove_row_of_views(), and TEST_F().
ViewItem * ViewModelBase::rootItem | ( | ) | const |
Returns a pointer to invisible root item.
Definition at line 102 of file viewmodelbase.cpp.
References p_impl.
Referenced by ModelView::ViewModel::ViewModel(), columnCount(), data(), ModelView::ViewModelController::ViewModelControllerImpl::findViews(), index(), ModelView::ViewModelController::ViewModelControllerImpl::init_view_model(), ModelView::ViewModelBase::ViewModelBaseImpl::item_belongs_to_model(), parent(), rowCount(), and TEST_F().
|
override |
Definition at line 64 of file viewmodelbase.cpp.
References itemFromIndex(), parent(), rootItem(), and ModelView::ViewItem::rowCount().
Referenced by index(), and TEST_F().
|
override |
Definition at line 85 of file viewmodelbase.cpp.
References index(), and itemFromIndex().
Referenced by TEST_F().
|
private |
Sets new root item. Previous item will be deleted, model will be reset.
Definition at line 182 of file viewmodelbase.cpp.
References p_impl.
Referenced by ViewModelBase(), and ModelView::ViewModelController::ViewModelControllerImpl::setRootSessionItemIntern().
|
friend |
Definition at line 68 of file viewmodelbase.h.
|
private |
Definition at line 70 of file viewmodelbase.h.
Referenced by clearRows(), insertRow(), removeRow(), rootItem(), and setRootViewItem().