BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::LayerSelectionModel Class Reference

Custom selection model for layer view model (AbstractViewModel). More...

Inheritance diagram for gui2::LayerSelectionModel:
[legend]
Collaboration diagram for gui2::LayerSelectionModel:
[legend]

Public Member Functions

 LayerSelectionModel (ModelView::ViewModel *view_model, QObject *parent=nullptr)
 
 ~LayerSelectionModel ()=default
 
bool firstSelected () const
 Checks if the first row is presen in the selection. More...
 
bool lastSelected () const
 checks if the last row is present in the selection More...
 
std::vector< ModelView::SessionItem * > selectedItems () const
 Returns vector of selected layers or multilayers. More...
 
void selectItem (ModelView::SessionItem *item)
 Selects whole row corresponding to given item. More...
 
void selectItems (std::vector< ModelView::SessionItem * > items)
 Selects all rows corresponding to given items. More...
 
const ModelView::ViewModelviewModel () const
 Return the casted view model. More...
 

Detailed Description

Custom selection model for layer view model (AbstractViewModel).

Definition at line 33 of file layerselectionmodel.h.

Constructor & Destructor Documentation

◆ LayerSelectionModel()

gui2::LayerSelectionModel::LayerSelectionModel ( ModelView::ViewModel view_model,
QObject *  parent = nullptr 
)

Definition at line 23 of file layerselectionmodel.cpp.

24  : QItemSelectionModel(view_model, parent)
25 {
26  // FIXME cover with unit tests after implementing ViewItemSelectionModel
27  connect(view_model, &ModelView::ViewModel::modelAboutToBeReset, [this]() { clearSelection(); });
28 }

◆ ~LayerSelectionModel()

gui2::LayerSelectionModel::~LayerSelectionModel ( )
default

Member Function Documentation

◆ firstSelected()

bool gui2::LayerSelectionModel::firstSelected ( ) const

Checks if the first row is presen in the selection.

Definition at line 81 of file layerselectionmodel.cpp.

82 {
83  const QModelIndexList& selection = selectedRows();
84  for (const auto& index : selection) {
85  if (index.row() == 0)
86  return true;
87  }
88  return false;
89 }

Referenced by gui2::LayerEditor::selectionChanged().

◆ lastSelected()

bool gui2::LayerSelectionModel::lastSelected ( ) const

checks if the last row is present in the selection

Definition at line 92 of file layerselectionmodel.cpp.

93 {
94  const QModelIndexList& selection = selectedRows();
95  for (const auto& index : selection) {
96  if (index.row() == viewModel()->rowCount() - 1)
97  return true;
98  }
99  return false;
100 }
const ModelView::ViewModel * viewModel() const
Return the casted view model.

References viewModel().

Referenced by gui2::LayerEditor::selectionChanged().

Here is the call graph for this function:

◆ selectedItems()

std::vector< ModelView::SessionItem * > gui2::LayerSelectionModel::selectedItems ( ) const

Returns vector of selected layers or multilayers.

We assume, that there is a single line selection mode switched on, and that the columns contains property items related to either LayerItem or MultiLayerItem.

Definition at line 60 of file layerselectionmodel.cpp.

61 {
62  const QModelIndexList& selection = selectedRows();
63  if (selection.empty())
64  return {};
65 
66  std::vector<ModelView::SessionItem*> result;
67  for (const auto& index : selection)
68  if (auto item = viewModel()->sessionItemFromIndex(index); item)
69  result.push_back(item->parent());
70 
71  return result;
72 }

References viewModel().

Here is the call graph for this function:

◆ selectItem()

void gui2::LayerSelectionModel::selectItem ( ModelView::SessionItem item)

Selects whole row corresponding to given item.

Definition at line 51 of file layerselectionmodel.cpp.

52 {
53  selectItems({item});
54 }
void selectItems(std::vector< ModelView::SessionItem * > items)
Selects all rows corresponding to given items.

References selectItems().

Here is the call graph for this function:

◆ selectItems()

void gui2::LayerSelectionModel::selectItems ( std::vector< ModelView::SessionItem * >  items)

Selects all rows corresponding to given items.

Definition at line 32 of file layerselectionmodel.cpp.

33 {
34  QModelIndexList indexes;
35  for (auto item : items)
36  indexes << viewModel()->indexOfSessionItem(item->getItem(LayerItem::P_NAME));
37 
38  if (indexes.empty())
39  return;
40 
41  clearSelection();
42 
43  QItemSelection selection(indexes.front(), indexes.back());
44  auto flags = QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows;
45  select(selection, flags);
46  // setCurrentIndex(id, flags); What to do?
47 }
QModelIndexList indexOfSessionItem(const SessionItem *item) const
Returns list of model indices representing given SessionItem.
Definition: viewmodel.cpp:71
static const std::string P_NAME
Definition: sampleitems.h:41

References ModelView::ViewModel::indexOfSessionItem(), gui2::LayerItem::P_NAME, and viewModel().

Referenced by selectItem().

Here is the call graph for this function:

◆ viewModel()

const ModelView::ViewModel * gui2::LayerSelectionModel::viewModel ( ) const

Return the casted view model.

Definition at line 75 of file layerselectionmodel.cpp.

76 {
77  return static_cast<const ModelView::ViewModel*>(model());
78 }
Main class to represent content of SessionModel in Qt's trees and tables.
Definition: viewmodel.h:29

Referenced by lastSelected(), selectedItems(), and selectItems().


The documentation for this class was generated from the following files: