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

Handles user actions applied to layer tree. More...

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

Classes

struct  LayerEditorActionsImpl
 

Public Member Functions

 LayerEditorActions (QObject *parent=nullptr)
 
 ~LayerEditorActions ()
 
void onAddLayer ()
 Adds layer after selected item. If more than one item is selected, adds after the last one. More...
 
void onAddMultiLayer ()
 
void onClone ()
 
void onMoveDown ()
 
void onMoveUp ()
 
void onRemove ()
 
void setModel (SampleModel *model)
 
void setSelectionModel (LayerSelectionModel *selection_model)
 

Private Attributes

std::unique_ptr< LayerEditorActionsImplp_impl
 

Detailed Description

Handles user actions applied to layer tree.

Belongs to LayerEditor.

Definition at line 30 of file layereditoractions.h.

Constructor & Destructor Documentation

◆ LayerEditorActions()

gui2::LayerEditorActions::LayerEditorActions ( QObject *  parent = nullptr)

Definition at line 53 of file layereditoractions.cpp.

54  : QObject(parent), p_impl(std::make_unique<LayerEditorActionsImpl>())
55 {
56 }
std::unique_ptr< LayerEditorActionsImpl > p_impl

◆ ~LayerEditorActions()

gui2::LayerEditorActions::~LayerEditorActions ( )
default

Member Function Documentation

◆ onAddLayer()

void gui2::LayerEditorActions::onAddLayer ( )

Adds layer after selected item. If more than one item is selected, adds after the last one.

Definition at line 65 of file layereditoractions.cpp.

66 {
67  if (!p_impl->sample_model)
68  return;
69 
70  auto [parent, tagrow] = p_impl->locateInsertPlace();
71  auto new_item = p_impl->sample_model->insertItem<LayerItem>(parent, tagrow);
72  p_impl->selection_model->selectItem(new_item);
73 }

References p_impl.

Referenced by gui2::LayerEditorToolBar::create_layer_menu().

◆ onAddMultiLayer()

void gui2::LayerEditorActions::onAddMultiLayer ( )

Definition at line 75 of file layereditoractions.cpp.

76 {
77  if (!p_impl->sample_model)
78  return;
79 
80  auto [parent, tagrow] = p_impl->locateInsertPlace();
81  auto multilayer = p_impl->sample_model->insertItem<MultiLayerItem>(parent, tagrow);
82  p_impl->sample_model->insertItem<LayerItem>(multilayer);
83  p_impl->sample_model->insertItem<LayerItem>(multilayer);
84  p_impl->selection_model->selectItem(multilayer);
85 }

References p_impl.

Referenced by gui2::LayerEditorToolBar::create_layer_menu().

◆ onClone()

void gui2::LayerEditorActions::onClone ( )

Definition at line 87 of file layereditoractions.cpp.

88 {
89  if (!p_impl->sample_model)
90  return;
91 
92  auto items = p_impl->selection_model->selectedItems();
93  if (items.empty())
94  return;
95 
96  std::vector<ModelView::SessionItem*> new_selection;
97  for (auto to_clone : items)
98  new_selection.push_back(p_impl->sample_model->copyItem(to_clone, to_clone->parent(),
99  to_clone->tagRow().next()));
100 
101  p_impl->selection_model->selectItems(new_selection);
102 }

References p_impl.

Referenced by gui2::LayerEditorToolBar::LayerEditorToolBar().

◆ onMoveDown()

void gui2::LayerEditorActions::onMoveDown ( )

Definition at line 132 of file layereditoractions.cpp.

133 {
134  auto selected = p_impl->selection_model->selectedItems();
135 
136  for (auto item : selected)
138 
139  p_impl->selection_model->selectItems(selected);
140 }
MVVM_MODEL_EXPORT void MoveDown(SessionItem *item)
Moves item down (increments row of the item). Works on children belonging to single tag.
Definition: modelutils.cpp:71

References ModelView::Utils::MoveDown(), and p_impl.

Referenced by gui2::LayerEditorToolBar::LayerEditorToolBar().

Here is the call graph for this function:

◆ onMoveUp()

void gui2::LayerEditorActions::onMoveUp ( )

Definition at line 122 of file layereditoractions.cpp.

123 {
124  auto selected = p_impl->selection_model->selectedItems();
125 
126  for (auto item : selected)
128 
129  p_impl->selection_model->selectItems(selected);
130 }
MVVM_MODEL_EXPORT void MoveUp(SessionItem *item)
Moves item up (decrements row of the item). Works on children belonging to single tag.
Definition: modelutils.cpp:63

References ModelView::Utils::MoveUp(), and p_impl.

Referenced by gui2::LayerEditorToolBar::LayerEditorToolBar().

Here is the call graph for this function:

◆ onRemove()

void gui2::LayerEditorActions::onRemove ( )

Definition at line 104 of file layereditoractions.cpp.

105 {
106  auto items = p_impl->selection_model->selectedItems();
107  if (items.empty())
108  return;
109 
110  auto prev_to_select = ModelView::Utils::FindPreviousSibling(items.front());
111  auto next_to_select = ModelView::Utils::FindNextSibling(items.back());
112 
113  for (auto item : items)
115  if (next_to_select) {
116  p_impl->selection_model->selectItem(next_to_select);
117  } else if (prev_to_select) {
118  p_impl->selection_model->selectItem(prev_to_select);
119  }
120 }
MVVM_MODEL_EXPORT SessionItem * FindNextSibling(SessionItem *item)
Returns next sibling with same tag.
Definition: itemutils.cpp:131
MVVM_MODEL_EXPORT SessionItem * FindPreviousSibling(SessionItem *item)
Returns previous sibling with same tag.
Definition: itemutils.cpp:140
MVVM_MODEL_EXPORT void DeleteItemFromModel(SessionItem *item)
Removes and deletes item from its model.
Definition: modelutils.cpp:54

References ModelView::Utils::DeleteItemFromModel(), ModelView::Utils::FindNextSibling(), ModelView::Utils::FindPreviousSibling(), and p_impl.

Referenced by gui2::LayerEditorToolBar::LayerEditorToolBar().

Here is the call graph for this function:

◆ setModel()

void gui2::LayerEditorActions::setModel ( SampleModel model)

Definition at line 58 of file layereditoractions.cpp.

59 {
60  p_impl->sample_model = model;
61 }

References p_impl.

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

◆ setSelectionModel()

void gui2::LayerEditorActions::setSelectionModel ( LayerSelectionModel selection_model)

Definition at line 142 of file layereditoractions.cpp.

143 {
144  p_impl->selection_model = selection_model;
145 }

References p_impl.

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

Member Data Documentation

◆ p_impl

std::unique_ptr<LayerEditorActionsImpl> gui2::LayerEditorActions::p_impl
private

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