BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskEditorActions Class Reference

Description

Defines actions for MaskEditor which are related to selected MaskItem (toggle mask value, lower/rize mask in the stack, delete mask). If more than one MaskItem is selected, action will be applied to the whole selection, if possible.

Definition at line 33 of file MaskEditorActions.h.

Inheritance diagram for MaskEditorActions:
[legend]
Collaboration diagram for MaskEditorActions:
[legend]

Public Slots

void onDeleteMaskAction ()
 
void onItemContextMenuRequest (const QPoint &point)
 Constructs MaskItem context menu following the request from MaskGraphicsScene or MaskEditorInfoPanel. More...
 

Signals

void propertyPanelRequest ()
 
void resetViewRequest ()
 
void savePlotRequest ()
 

Public Member Functions

 MaskEditorActions (QWidget *parent)
 
QAction * bringToFrontAction ()
 
QAction * sendToBackAction ()
 
void setModel (SessionModel *maskModel, const QModelIndex &rootIndex)
 
void setSelectionModel (QItemSelectionModel *selectionModel)
 
QList< QAction * > topToolbarActions ()
 

Private Slots

void onBringToFrontAction ()
 
void onSendToBackAction ()
 
void onToggleMaskValueAction ()
 Performs switch of mask value for all selected items (true -> false, false -> true) More...
 

Private Member Functions

void changeMaskStackingOrder (MaskEditorFlags::Stacking value)
 Lower mask one level down or rise one level up in the masks stack. More...
 
void initItemContextMenu (QMenu &menu)
 Init external context menu with currently defined actions. Triggered from MaskGraphicsScene of MaskEditorInfoPanel (QListView) More...
 
bool isBringToFrontPossible () const
 Returns true if at least one of MaskItems in the selection can be moved one level up (Naturally, it is always true, if selection contains more than one item. If selection contains only one item, the result will depend on position of item on the stack. Top item can't be moved up. Used to disable corresponding context menu line.) More...
 
bool isSendToBackPossible () const
 Returns true if at least one of MaskItems in the selection can be moved one level down. More...
 
void setAllActionsEnabled (bool value)
 

Private Attributes

QAction * m_bringToFrontAction
 
QAction * m_deleteMaskAction
 
SessionModelm_maskModel
 
QAction * m_resetViewAction
 
QModelIndex m_rootIndex
 
QAction * m_savePlotAction
 
QItemSelectionModel * m_selectionModel
 Index in the model corresponding to IntensityDataItem. More...
 
QAction * m_sendToBackAction
 
QAction * m_toggleMaskValueAction
 
QAction * m_togglePanelAction
 

Constructor & Destructor Documentation

◆ MaskEditorActions()

MaskEditorActions::MaskEditorActions ( QWidget *  parent)

Definition at line 23 of file MaskEditorActions.cpp.

24  : QObject(parent)
25  , m_toggleMaskValueAction(new QAction("Toggle mask value", parent))
26  , m_bringToFrontAction(new QAction("Rise mask up", parent))
27  , m_sendToBackAction(new QAction("Lower mask down", parent))
28  , m_deleteMaskAction(new QAction("Remove mask", parent))
29  , m_resetViewAction(new QAction(this))
30  , m_savePlotAction(new QAction(this))
31  , m_maskModel(nullptr)
32  , m_selectionModel(nullptr)
33 
34 {
35  connect(m_toggleMaskValueAction, &QAction::triggered, this,
37 
38  m_bringToFrontAction->setIcon(QIcon(":/Mask/images/maskeditor_bringtofront.svg"));
39  m_bringToFrontAction->setToolTip("Rise selected mask one level up (PgUp)");
40  m_bringToFrontAction->setShortcuts(QKeySequence::MoveToPreviousPage);
41  connect(m_bringToFrontAction, &QAction::triggered, this,
43 
44  m_sendToBackAction->setIcon(QIcon(":/Mask/images/maskeditor_sendtoback.svg"));
45  m_sendToBackAction->setToolTip("Lower selected mask one level down (PgDown)");
46  m_sendToBackAction->setShortcuts(QKeySequence::MoveToNextPage);
47  connect(m_sendToBackAction, &QAction::triggered, this, &MaskEditorActions::onSendToBackAction);
48 
49  m_deleteMaskAction->setToolTip("Remove selected mask (Del)");
50  m_deleteMaskAction->setShortcuts(QKeySequence::Delete);
51  parent->addAction(m_deleteMaskAction);
52  connect(m_deleteMaskAction, &QAction::triggered, this, &MaskEditorActions::onDeleteMaskAction);
53 
54  // Actions for top toolbar
55  m_resetViewAction->setText("Center view");
56  m_resetViewAction->setIcon(QIcon(":/images/camera-metering-center.svg"));
57  m_resetViewAction->setToolTip("Center View");
58  connect(m_resetViewAction, &QAction::triggered, this, &MaskEditorActions::resetViewRequest);
59 
60  m_savePlotAction->setText("Save");
61  m_savePlotAction->setIcon(QIcon(":/images/content-save-outline.svg"));
62  m_savePlotAction->setToolTip("Save Plot");
63  connect(m_savePlotAction, &QAction::triggered, this, &MaskEditorActions::savePlotRequest);
64 
66  connect(m_togglePanelAction, &QAction::triggered, this,
68 }
static QAction * createTogglePropertiesPanelAction(QObject *parent, QWidget *toggledWidget=nullptr)
Create "toggle properties panel" action.
QItemSelectionModel * m_selectionModel
Index in the model corresponding to IntensityDataItem.
QAction * m_toggleMaskValueAction
void propertyPanelRequest()
QAction * m_togglePanelAction
void onToggleMaskValueAction()
Performs switch of mask value for all selected items (true -> false, false -> true)
QAction * m_bringToFrontAction
QAction * m_sendToBackAction
QAction * m_deleteMaskAction
QAction * m_savePlotAction
SessionModel * m_maskModel
QAction * m_resetViewAction

References ActionFactory::createTogglePropertiesPanelAction(), m_bringToFrontAction, m_deleteMaskAction, m_resetViewAction, m_savePlotAction, m_sendToBackAction, m_toggleMaskValueAction, m_togglePanelAction, onBringToFrontAction(), onDeleteMaskAction(), onSendToBackAction(), onToggleMaskValueAction(), propertyPanelRequest(), resetViewRequest(), and savePlotRequest().

Here is the call graph for this function:

Member Function Documentation

◆ bringToFrontAction()

QAction * MaskEditorActions::bringToFrontAction ( )

Definition at line 86 of file MaskEditorActions.cpp.

87 {
88  return m_bringToFrontAction;
89 }

References m_bringToFrontAction.

Referenced by MaskEditorToolbar::setup_maskmodify_group().

◆ changeMaskStackingOrder()

void MaskEditorActions::changeMaskStackingOrder ( MaskEditorFlags::Stacking  value)
private

Lower mask one level down or rise one level up in the masks stack.

Definition at line 140 of file MaskEditorActions.cpp.

141 {
142  if (!m_maskModel || !m_selectionModel)
143  return;
144 
145  int change_in_row(0);
146  if (value == MaskEditorFlags::BRING_TO_FRONT)
147  change_in_row = -1;
148  if (value == MaskEditorFlags::SEND_TO_BACK)
149  change_in_row = 2;
150 
151  QModelIndexList indexes = m_selectionModel->selectedIndexes();
152 
153  for (auto itemIndex : indexes) {
154  if (SessionItem* item = m_maskModel->itemForIndex(itemIndex)) {
155  int new_row = itemIndex.row() + change_in_row;
156  if (new_row >= 0 && new_row <= m_maskModel->rowCount(m_rootIndex)) {
157  SessionItem* newItem =
159  m_selectionModel->select(m_maskModel->indexOfItem(newItem),
160  QItemSelectionModel::Select);
161  }
162  }
163  }
164 }
QModelIndex m_rootIndex
Base class for a GUI data item.
Definition: SessionItem.h:204
SessionItem * moveItem(SessionItem *item, SessionItem *new_parent=nullptr, int row=-1, const QString &tag="")
Move given parameterized item to the new_parent at given row. If new_parent is not defined,...
SessionItem * itemForIndex(const QModelIndex &index) const
QModelIndex indexOfItem(SessionItem *item) const

References MaskEditorFlags::BRING_TO_FRONT, SessionModel::indexOfItem(), SessionModel::itemForIndex(), m_maskModel, m_rootIndex, m_selectionModel, SessionModel::moveItem(), and MaskEditorFlags::SEND_TO_BACK.

Referenced by onBringToFrontAction(), and onSendToBackAction().

Here is the call graph for this function:

◆ initItemContextMenu()

void MaskEditorActions::initItemContextMenu ( QMenu &  menu)
private

Init external context menu with currently defined actions. Triggered from MaskGraphicsScene of MaskEditorInfoPanel (QListView)

Definition at line 202 of file MaskEditorActions.cpp.

203 {
204  if (!m_rootIndex.isValid())
205  return;
206 
207  ASSERT(m_maskModel);
208  ASSERT(m_selectionModel);
209 
210  if (m_selectionModel->selectedIndexes().isEmpty())
211  setAllActionsEnabled(false);
212 
215 
216  menu.addAction(m_toggleMaskValueAction);
217  menu.addAction(m_bringToFrontAction);
218  menu.addAction(m_sendToBackAction);
219  menu.addSeparator();
220  menu.addAction(m_deleteMaskAction);
221 }
bool isSendToBackPossible() const
Returns true if at least one of MaskItems in the selection can be moved one level down.
void setAllActionsEnabled(bool value)
bool isBringToFrontPossible() const
Returns true if at least one of MaskItems in the selection can be moved one level up (Naturally,...

References isBringToFrontPossible(), isSendToBackPossible(), m_bringToFrontAction, m_deleteMaskAction, m_maskModel, m_rootIndex, m_selectionModel, m_sendToBackAction, m_toggleMaskValueAction, and setAllActionsEnabled().

Referenced by onItemContextMenuRequest().

Here is the call graph for this function:

◆ isBringToFrontPossible()

bool MaskEditorActions::isBringToFrontPossible ( ) const
private

Returns true if at least one of MaskItems in the selection can be moved one level up (Naturally, it is always true, if selection contains more than one item. If selection contains only one item, the result will depend on position of item on the stack. Top item can't be moved up. Used to disable corresponding context menu line.)

Definition at line 170 of file MaskEditorActions.cpp.

171 {
172  bool result(false);
173  QModelIndexList indexes = m_selectionModel->selectedIndexes();
174  if (indexes.size() == 1 && indexes.front().row() != 0)
175  result = true;
176  return result;
177 }

References m_selectionModel.

Referenced by initItemContextMenu().

◆ isSendToBackPossible()

bool MaskEditorActions::isSendToBackPossible ( ) const
private

Returns true if at least one of MaskItems in the selection can be moved one level down.

Definition at line 180 of file MaskEditorActions.cpp.

181 {
182  bool result(false);
183  QModelIndexList indexes = m_selectionModel->selectedIndexes();
184  if (indexes.size() == 1) {
185  SessionItem* item = m_maskModel->itemForIndex(indexes.front());
186  if (indexes.front().row() != item->parentItem()->numberOfChildren() - 1)
187  result = true;
188  }
189  return result;
190 }
int numberOfChildren() const
Returns total number of children.
Definition: SessionItem.cpp:88
SessionItem * parentItem() const
Returns parent of this item.
Definition: SessionItem.cpp:67

References SessionModel::itemForIndex(), m_maskModel, m_selectionModel, SessionItem::numberOfChildren(), and SessionItem::parentItem().

Referenced by initItemContextMenu().

Here is the call graph for this function:

◆ onBringToFrontAction

void MaskEditorActions::onBringToFrontAction ( )
privateslot

Definition at line 129 of file MaskEditorActions.cpp.

130 {
132 }
void changeMaskStackingOrder(MaskEditorFlags::Stacking value)
Lower mask one level down or rise one level up in the masks stack.

References MaskEditorFlags::BRING_TO_FRONT, and changeMaskStackingOrder().

Referenced by MaskEditorActions().

Here is the call graph for this function:

◆ onDeleteMaskAction

void MaskEditorActions::onDeleteMaskAction ( )
slot

Definition at line 106 of file MaskEditorActions.cpp.

107 {
108  ASSERT(m_maskModel);
109  ASSERT(m_selectionModel);
110 
111  QModelIndexList indexes = m_selectionModel->selectedIndexes();
112  while (!indexes.empty()) {
113  m_maskModel->removeRows(indexes.back().row(), 1, indexes.back().parent());
114  indexes = m_selectionModel->selectedIndexes();
115  }
116 }
bool removeRows(int row, int count, const QModelIndex &parent) override

References m_maskModel, m_selectionModel, and SessionModel::removeRows().

Referenced by MaskEditorActions(), and MaskEditor::setup_connections().

Here is the call graph for this function:

◆ onItemContextMenuRequest

void MaskEditorActions::onItemContextMenuRequest ( const QPoint &  point)
slot

Constructs MaskItem context menu following the request from MaskGraphicsScene or MaskEditorInfoPanel.

Definition at line 98 of file MaskEditorActions.cpp.

99 {
100  QMenu menu;
101  initItemContextMenu(menu);
102  menu.exec(point);
103  setAllActionsEnabled(true);
104 }
void initItemContextMenu(QMenu &menu)
Init external context menu with currently defined actions. Triggered from MaskGraphicsScene of MaskEd...

References initItemContextMenu(), and setAllActionsEnabled().

Referenced by MaskEditor::setup_connections().

Here is the call graph for this function:

◆ onSendToBackAction

void MaskEditorActions::onSendToBackAction ( )
privateslot

Definition at line 134 of file MaskEditorActions.cpp.

References changeMaskStackingOrder(), and MaskEditorFlags::SEND_TO_BACK.

Referenced by MaskEditorActions().

Here is the call graph for this function:

◆ onToggleMaskValueAction

void MaskEditorActions::onToggleMaskValueAction ( )
privateslot

Performs switch of mask value for all selected items (true -> false, false -> true)

Definition at line 119 of file MaskEditorActions.cpp.

120 {
121  ASSERT(m_maskModel);
122  ASSERT(m_selectionModel);
123  for (auto itemIndex : m_selectionModel->selectedIndexes()) {
124  if (auto* item = dynamic_cast<MaskItem*>(m_maskModel->itemForIndex(itemIndex)))
125  item->setMaskValue(!item->maskValue());
126  }
127 }
A base class for all mask items.
Definition: MaskItems.h:27

References SessionModel::itemForIndex(), m_maskModel, and m_selectionModel.

Referenced by MaskEditorActions().

Here is the call graph for this function:

◆ propertyPanelRequest

void MaskEditorActions::propertyPanelRequest ( )
signal

◆ resetViewRequest

void MaskEditorActions::resetViewRequest ( )
signal

◆ savePlotRequest

void MaskEditorActions::savePlotRequest ( )
signal

◆ sendToBackAction()

QAction * MaskEditorActions::sendToBackAction ( )

Definition at line 81 of file MaskEditorActions.cpp.

82 {
83  return m_sendToBackAction;
84 }

References m_sendToBackAction.

Referenced by MaskEditorToolbar::setup_maskmodify_group().

◆ setAllActionsEnabled()

void MaskEditorActions::setAllActionsEnabled ( bool  value)
private

Definition at line 192 of file MaskEditorActions.cpp.

193 {
194  m_sendToBackAction->setEnabled(value);
195  m_bringToFrontAction->setEnabled(value);
196  m_toggleMaskValueAction->setEnabled(value);
197  m_deleteMaskAction->setEnabled(value);
198 }

References m_bringToFrontAction, m_deleteMaskAction, m_sendToBackAction, and m_toggleMaskValueAction.

Referenced by initItemContextMenu(), and onItemContextMenuRequest().

◆ setModel()

void MaskEditorActions::setModel ( SessionModel maskModel,
const QModelIndex &  rootIndex 
)

Definition at line 70 of file MaskEditorActions.cpp.

71 {
72  m_maskModel = maskModel;
73  m_rootIndex = rootIndex;
74 }

References m_maskModel, and m_rootIndex.

Referenced by MaskEditor::setMaskContext().

◆ setSelectionModel()

void MaskEditorActions::setSelectionModel ( QItemSelectionModel *  selectionModel)

Definition at line 76 of file MaskEditorActions.cpp.

77 {
78  m_selectionModel = selectionModel;
79 }

References m_selectionModel.

Referenced by MaskEditor::setMaskContext().

◆ topToolbarActions()

QList< QAction * > MaskEditorActions::topToolbarActions ( )

Definition at line 91 of file MaskEditorActions.cpp.

92 {
93  return QList<QAction*>() << m_resetViewAction << m_togglePanelAction;
94 }

References m_resetViewAction, and m_togglePanelAction.

Referenced by MaskEditor::topToolbarActions().

Member Data Documentation

◆ m_bringToFrontAction

QAction* MaskEditorActions::m_bringToFrontAction
private

◆ m_deleteMaskAction

QAction* MaskEditorActions::m_deleteMaskAction
private

◆ m_maskModel

◆ m_resetViewAction

QAction* MaskEditorActions::m_resetViewAction
private

Definition at line 72 of file MaskEditorActions.h.

Referenced by MaskEditorActions(), and topToolbarActions().

◆ m_rootIndex

QModelIndex MaskEditorActions::m_rootIndex
private

Definition at line 77 of file MaskEditorActions.h.

Referenced by changeMaskStackingOrder(), initItemContextMenu(), and setModel().

◆ m_savePlotAction

QAction* MaskEditorActions::m_savePlotAction
private

Definition at line 73 of file MaskEditorActions.h.

Referenced by MaskEditorActions().

◆ m_selectionModel

QItemSelectionModel* MaskEditorActions::m_selectionModel
private

◆ m_sendToBackAction

QAction* MaskEditorActions::m_sendToBackAction
private

◆ m_toggleMaskValueAction

QAction* MaskEditorActions::m_toggleMaskValueAction
private

◆ m_togglePanelAction

QAction* MaskEditorActions::m_togglePanelAction
private

Definition at line 74 of file MaskEditorActions.h.

Referenced by MaskEditorActions(), and topToolbarActions().


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