BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
importdataeditoractions.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file gui2/importdataview/importdataeditoractions.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 Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
22 #include "mvvm/model/itemutils.h"
26 
27 namespace {
28 template <typename T> std::vector<T*> itemsFromIndexList(const QModelIndexList& indices)
29 {
30  return ModelView::Utils::CastedItems<T>(ModelView::Utils::UniqueItemsFromIndex(indices));
31 }
32 
33 } // namespace
34 
35 namespace gui2 {
36 
38  : QObject(parent), m_dataModel(model)
39 {
40 }
41 
43 {
44  if (m_selectionModel)
45  disconnect(m_selectionModel, &DataSelectionModel::selectionChanged, this,
47 
48  m_selectionModel = selection_model;
49 
50  if (m_selectionModel)
51  connect(m_selectionModel, &DataSelectionModel::selectionChanged, this,
53 }
54 
56 {
57  return m_dataModel->undoStack() != nullptr;
58 }
59 
60 //! Create new canvas and append it to the end of canvas container.
61 
63 {
65 }
66 
67 //! Merge selected canvases. All graphs will appear below canvas selected first.
68 
70 {
71  if (isUndoEnabled())
72  undoStack()->beginMacro("onMergeCanvases");
73 
75 
76  if (isUndoEnabled())
77  undoStack()->endMacro();
78 }
79 
80 //! Delete currently selected items.
81 
83 {
84  if (isUndoEnabled())
85  undoStack()->beginMacro("onDeleteItem");
86 
87  for (auto canvas : m_selectionModel->selectedCanvas())
88  m_dataModel->removeCanvas(*canvas);
89 
90  for (auto graph : m_selectionModel->selectedGraphs())
91  m_dataModel->removeGraph(*graph);
92 
93  if (isUndoEnabled())
94  undoStack()->endMacro();
95 }
96 
98 {
99  if (!isUndoEnabled())
100  return;
101 
102  m_dataModel->undoStack()->undo();
103 }
104 
106 {
107  if (!isUndoEnabled())
108  return;
109 
110  m_dataModel->undoStack()->redo();
111 }
112 
114 {
115  if (isUndoEnabled())
116  undoStack()->beginMacro("onImportDialogRequest");
117 
119 
120  if (isUndoEnabled())
121  undoStack()->endMacro();
122 }
123 
124 //! Processes changed selection. Will change line style of selected graph from
125 //! solid to dashed line.
126 
127 void ImportDataEditorActions::onSelectionChanged(const QItemSelection& selected,
128  const QItemSelection& deselected)
129 {
130  auto selected_graphs = itemsFromIndexList<ModelView::GraphItem>(selected.indexes());
131  for (auto graph : selected_graphs)
132  graph->penItem()->setSelected(true);
133 
134  auto deselected_graphs = itemsFromIndexList<ModelView::GraphItem>(deselected.indexes());
135  for (auto graph : deselected_graphs)
136  graph->penItem()->setSelected(false);
137 }
138 
140 {
141  return m_dataModel->undoStack();
142 }
143 
144 } // namespace gui2
UndoStackInterface * undoStack() const
Returns command stack to perform undo/redo.
Interface class for undo/redo stack.
virtual void beginMacro(const std::string &name)=0
Custom selection model for data view model (AbstractViewModel).
std::vector< CanvasItem * > selectedCanvas() const
Returns vector of currently slected canvas.
std::vector< ModelView::GraphItem * > selectedGraphs() const
The model to store imported reflectometry data.
void removeCanvas(CanvasItem &canvas)
Remove canvas with all its graphs.
void mergeCanvases(const std::vector< CanvasItem * > &canvases)
Merge canvas from the vector.
void removeGraph(ModelView::GraphItem &graph)
Remove graph from the model. Underlying DataItem will be removed too.
ModelView::UndoStackInterface * undoStack() const
void setSelectionModel(DataSelectionModel *selection_model)
ImportDataEditorActions(ExperimentalDataModel *model, QObject *parent=nullptr)
void onAddCanvas()
Create new canvas and append it to the end of canvas container.
ExperimentalDataModel * m_dataModel
void onDeleteItem()
Delete currently selected items.
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Processes changed selection.
void onMergeCanvases()
Merge selected canvases. All graphs will appear below canvas selected first.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
MVVM_VIEWMODEL_EXPORT std::vector< SessionItem * > UniqueItemsFromIndex(const QModelIndexList &index_list)
Returns vector of underlying SessionItem's for given index list. Removes repetitions.
Based on Qt example "codeeditor" Copyright (C) 2016 The Qt Company Ltd.
Definition: app_constants.h:20
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?